2020-07-12 14:21:40 +02:00
|
|
|
module openssl
|
|
|
|
|
2020-12-05 20:27:16 +01:00
|
|
|
// On Linux, prefer a localy built openssl, because it is
|
2020-07-12 14:21:40 +02:00
|
|
|
// much more likely for it to be newer, than the system
|
|
|
|
// openssl from libssl-dev. If there is no local openssl,
|
|
|
|
// the next flag is harmless, since it will still use the
|
|
|
|
// (older) system openssl.
|
2021-05-20 08:17:44 +02:00
|
|
|
#flag linux -I/usr/local/include/openssl -L/usr/local/lib
|
2020-08-22 00:50:38 +02:00
|
|
|
#flag windows -l libssl -l libcrypto
|
2021-05-16 10:28:36 +02:00
|
|
|
#flag -lssl -lcrypto
|
|
|
|
#flag linux -ldl -lpthread
|
2020-07-12 14:21:40 +02:00
|
|
|
// MacPorts
|
|
|
|
#flag darwin -I/opt/local/include
|
|
|
|
#flag darwin -L/opt/local/lib
|
|
|
|
// Brew
|
|
|
|
#flag darwin -I/usr/local/opt/openssl/include
|
|
|
|
#flag darwin -L/usr/local/opt/openssl/lib
|
2020-12-05 20:27:16 +01:00
|
|
|
// Brew arm64
|
2020-12-28 00:32:35 +01:00
|
|
|
#flag darwin -I /opt/homebrew/opt/openssl/include
|
|
|
|
#flag darwin -L /opt/homebrew/opt/openssl/lib
|
2020-12-05 20:27:16 +01:00
|
|
|
//
|
2020-10-17 18:30:47 +02:00
|
|
|
#include <openssl/rand.h> # Please install OpenSSL development headers
|
2020-07-12 14:21:40 +02:00
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#include <openssl/err.h>
|
2021-02-21 16:03:25 +01:00
|
|
|
|
2020-12-05 20:27:16 +01:00
|
|
|
pub struct C.SSL {
|
|
|
|
}
|
2020-07-12 14:21:40 +02:00
|
|
|
|
2020-12-05 20:27:16 +01:00
|
|
|
pub struct SSL_CTX {
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct SSL {
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct SSL_METHOD {
|
|
|
|
}
|
2020-07-12 14:21:40 +02:00
|
|
|
|
2021-06-21 18:23:57 +02:00
|
|
|
pub struct OPENSSL_INIT_SETTINGS {
|
|
|
|
}
|
|
|
|
|
2021-03-05 15:41:11 +01:00
|
|
|
fn C.BIO_new_ssl_connect(ctx &C.SSL_CTX) &C.BIO
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-06-13 22:53:38 +02:00
|
|
|
fn C.BIO_set_conn_hostname(b &C.BIO, name &char) int
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-03-05 15:41:11 +01:00
|
|
|
// there are actually 2 macros for BIO_get_ssl
|
|
|
|
// fn C.BIO_get_ssl(bp &C.BIO, ssl charptr, c int)
|
|
|
|
// fn C.BIO_get_ssl(bp &C.BIO, sslp charptr)
|
|
|
|
fn C.BIO_get_ssl(bp &C.BIO, vargs ...voidptr)
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-03-05 15:41:11 +01:00
|
|
|
fn C.BIO_do_connect(b &C.BIO) int
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-03-05 15:41:11 +01:00
|
|
|
fn C.BIO_do_handshake(b &C.BIO) int
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-06-13 22:53:38 +02:00
|
|
|
fn C.BIO_puts(b &C.BIO, buf &char)
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-03-05 15:41:11 +01:00
|
|
|
fn C.BIO_read(b &C.BIO, buf voidptr, len int) int
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-03-05 15:41:11 +01:00
|
|
|
fn C.BIO_free_all(a &C.BIO)
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-03-05 15:41:11 +01:00
|
|
|
fn C.SSL_CTX_new(method &C.SSL_METHOD) &C.SSL_CTX
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-03-05 15:41:11 +01:00
|
|
|
fn C.SSL_CTX_set_options(ctx &C.SSL_CTX, options int)
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-03-05 15:41:11 +01:00
|
|
|
fn C.SSL_CTX_set_verify_depth(s &C.SSL_CTX, depth int)
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-06-13 22:53:38 +02:00
|
|
|
fn C.SSL_CTX_load_verify_locations(ctx &C.SSL_CTX, ca_file &char, ca_path &char) int
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-03-05 15:41:11 +01:00
|
|
|
fn C.SSL_CTX_free(ctx &C.SSL_CTX)
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-02-21 16:03:25 +01:00
|
|
|
fn C.SSL_new(&C.SSL_CTX) &C.SSL
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-03-05 15:41:11 +01:00
|
|
|
fn C.SSL_set_fd(ssl &C.SSL, fd int) int
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-02-21 16:03:25 +01:00
|
|
|
fn C.SSL_connect(&C.SSL) int
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-06-13 22:53:38 +02:00
|
|
|
fn C.SSL_set_cipher_list(ctx &SSL, str &char) int
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-03-05 15:41:11 +01:00
|
|
|
fn C.SSL_get_peer_certificate(ssl &SSL) &C.X509
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2020-11-21 14:45:45 +01:00
|
|
|
fn C.ERR_clear_error()
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-03-05 15:41:11 +01:00
|
|
|
fn C.SSL_get_error(ssl &C.SSL, ret int) int
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-03-05 15:41:11 +01:00
|
|
|
fn C.SSL_get_verify_result(ssl &SSL) int
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-06-13 22:53:38 +02:00
|
|
|
fn C.SSL_set_tlsext_host_name(s &SSL, name &char) int
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-02-21 16:03:25 +01:00
|
|
|
fn C.SSL_shutdown(&C.SSL) int
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-02-21 16:03:25 +01:00
|
|
|
fn C.SSL_free(&C.SSL)
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-02-21 16:03:25 +01:00
|
|
|
fn C.SSL_write(ssl &C.SSL, buf voidptr, buflen int) int
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-02-21 16:03:25 +01:00
|
|
|
fn C.SSL_read(ssl &C.SSL, buf voidptr, buflen int) int
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2020-07-12 14:21:40 +02:00
|
|
|
fn C.SSL_load_error_strings()
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2021-02-21 16:03:25 +01:00
|
|
|
fn C.SSL_library_init() int
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2020-07-12 14:21:40 +02:00
|
|
|
fn C.SSLv23_client_method() &C.SSL_METHOD
|
2020-12-05 20:27:16 +01:00
|
|
|
|
2020-12-11 01:04:12 +01:00
|
|
|
fn C.TLS_method() voidptr
|
|
|
|
|
2020-07-12 14:21:40 +02:00
|
|
|
fn C.TLSv1_2_method() voidptr
|
|
|
|
|
2021-06-21 18:23:57 +02:00
|
|
|
fn C.OPENSSL_init_ssl(opts u64, settings &OPENSSL_INIT_SETTINGS) int
|
|
|
|
|
2020-07-12 14:21:40 +02:00
|
|
|
fn init() {
|
2021-06-21 18:23:57 +02:00
|
|
|
$if ssl_pre_1_1_version ? {
|
|
|
|
// OPENSSL_VERSION_NUMBER < 0x10100000L
|
|
|
|
C.SSL_load_error_strings()
|
|
|
|
C.SSL_library_init()
|
|
|
|
} $else {
|
|
|
|
C.OPENSSL_init_ssl(C.OPENSSL_INIT_LOAD_SSL_STRINGS, 0)
|
|
|
|
}
|
2020-07-12 14:21:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub const (
|
|
|
|
is_used = 1
|
|
|
|
)
|