2020-07-12 15:21:40 +03:00
|
|
|
module openssl
|
|
|
|
|
2020-12-05 22:27:16 +03:00
|
|
|
// On Linux, prefer a localy built openssl, because it is
|
2020-07-12 15:21:40 +03:00
|
|
|
// much more likely for it to be newer, than the system
|
|
|
|
// openssl from libssl-dev. If there is no local openssl,
|
2021-12-08 11:50:24 +03:00
|
|
|
// the next #pkgconfig flag is harmless, since it will still
|
|
|
|
// use the (older) system openssl.
|
|
|
|
#flag linux -I/usr/local/include/openssl
|
2021-12-07 23:11:47 +03:00
|
|
|
#flag linux -L/usr/local/lib
|
2021-12-08 11:50:24 +03:00
|
|
|
$if $pkgconfig('openssl') {
|
|
|
|
#pkgconfig openssl
|
|
|
|
}
|
|
|
|
|
2020-08-22 01:50:38 +03:00
|
|
|
#flag windows -l libssl -l libcrypto
|
2021-05-16 11:28:36 +03:00
|
|
|
#flag -lssl -lcrypto
|
|
|
|
#flag linux -ldl -lpthread
|
2020-07-12 15:21:40 +03: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 22:27:16 +03:00
|
|
|
// Brew arm64
|
2020-12-28 02:32:35 +03:00
|
|
|
#flag darwin -I /opt/homebrew/opt/openssl/include
|
|
|
|
#flag darwin -L /opt/homebrew/opt/openssl/lib
|
2022-03-30 10:15:52 +03:00
|
|
|
// Procursus
|
|
|
|
#flag darwin -I/opt/procursus/include
|
|
|
|
#flag darwin -L/opt/procursus/lib
|
2020-12-05 22:27:16 +03:00
|
|
|
//
|
2020-10-17 19:30:47 +03:00
|
|
|
#include <openssl/rand.h> # Please install OpenSSL development headers
|
2020-07-12 15:21:40 +03:00
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#include <openssl/err.h>
|
2021-02-21 18:03:25 +03:00
|
|
|
|
2021-09-28 09:20:49 +03:00
|
|
|
[typedef]
|
2022-09-22 16:50:34 +03:00
|
|
|
struct C.SSL {
|
2021-06-21 19:23:57 +03:00
|
|
|
}
|
|
|
|
|
2021-03-05 17:41:11 +03:00
|
|
|
fn C.BIO_new_ssl_connect(ctx &C.SSL_CTX) &C.BIO
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-06-13 23:53:38 +03:00
|
|
|
fn C.BIO_set_conn_hostname(b &C.BIO, name &char) int
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-03-05 17:41:11 +03: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 22:27:16 +03:00
|
|
|
|
2021-03-05 17:41:11 +03:00
|
|
|
fn C.BIO_do_connect(b &C.BIO) int
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-03-05 17:41:11 +03:00
|
|
|
fn C.BIO_do_handshake(b &C.BIO) int
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-06-13 23:53:38 +03:00
|
|
|
fn C.BIO_puts(b &C.BIO, buf &char)
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-03-05 17:41:11 +03:00
|
|
|
fn C.BIO_read(b &C.BIO, buf voidptr, len int) int
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-03-05 17:41:11 +03:00
|
|
|
fn C.BIO_free_all(a &C.BIO)
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-03-05 17:41:11 +03:00
|
|
|
fn C.SSL_CTX_new(method &C.SSL_METHOD) &C.SSL_CTX
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-03-05 17:41:11 +03:00
|
|
|
fn C.SSL_CTX_set_options(ctx &C.SSL_CTX, options int)
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-03-05 17:41:11 +03:00
|
|
|
fn C.SSL_CTX_set_verify_depth(s &C.SSL_CTX, depth int)
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-09-01 01:43:35 +03:00
|
|
|
fn C.SSL_CTX_load_verify_locations(ctx &C.SSL_CTX, const_file &char, ca_path &char) int
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-03-05 17:41:11 +03:00
|
|
|
fn C.SSL_CTX_free(ctx &C.SSL_CTX)
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-09-01 01:43:35 +03:00
|
|
|
fn C.SSL_CTX_use_certificate_file(ctx &C.SSL_CTX, const_file &char, file_type int) int
|
|
|
|
|
|
|
|
fn C.SSL_CTX_use_PrivateKey_file(ctx &C.SSL_CTX, const_file &char, file_type int) int
|
|
|
|
|
2021-02-21 18:03:25 +03:00
|
|
|
fn C.SSL_new(&C.SSL_CTX) &C.SSL
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-03-05 17:41:11 +03:00
|
|
|
fn C.SSL_set_fd(ssl &C.SSL, fd int) int
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-02-21 18:03:25 +03:00
|
|
|
fn C.SSL_connect(&C.SSL) int
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2022-09-22 16:50:34 +03:00
|
|
|
fn C.SSL_do_handshake(&C.SSL) int
|
|
|
|
|
2021-06-13 23:53:38 +03:00
|
|
|
fn C.SSL_set_cipher_list(ctx &SSL, str &char) int
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-03-05 17:41:11 +03:00
|
|
|
fn C.SSL_get_peer_certificate(ssl &SSL) &C.X509
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-09-01 01:43:35 +03:00
|
|
|
fn C.X509_free(const_cert &C.X509)
|
|
|
|
|
2020-11-21 16:45:45 +03:00
|
|
|
fn C.ERR_clear_error()
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-03-05 17:41:11 +03:00
|
|
|
fn C.SSL_get_error(ssl &C.SSL, ret int) int
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-03-05 17:41:11 +03:00
|
|
|
fn C.SSL_get_verify_result(ssl &SSL) int
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-06-13 23:53:38 +03:00
|
|
|
fn C.SSL_set_tlsext_host_name(s &SSL, name &char) int
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-02-21 18:03:25 +03:00
|
|
|
fn C.SSL_shutdown(&C.SSL) int
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-02-21 18:03:25 +03:00
|
|
|
fn C.SSL_free(&C.SSL)
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-02-21 18:03:25 +03:00
|
|
|
fn C.SSL_write(ssl &C.SSL, buf voidptr, buflen int) int
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-02-21 18:03:25 +03:00
|
|
|
fn C.SSL_read(ssl &C.SSL, buf voidptr, buflen int) int
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2020-07-12 15:21:40 +03:00
|
|
|
fn C.SSL_load_error_strings()
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2021-02-21 18:03:25 +03:00
|
|
|
fn C.SSL_library_init() int
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2020-07-12 15:21:40 +03:00
|
|
|
fn C.SSLv23_client_method() &C.SSL_METHOD
|
2020-12-05 22:27:16 +03:00
|
|
|
|
2020-12-11 03:04:12 +03:00
|
|
|
fn C.TLS_method() voidptr
|
|
|
|
|
2020-07-12 15:21:40 +03:00
|
|
|
fn C.TLSv1_2_method() voidptr
|
|
|
|
|
2021-06-21 19:23:57 +03:00
|
|
|
fn C.OPENSSL_init_ssl(opts u64, settings &OPENSSL_INIT_SETTINGS) int
|
|
|
|
|
2020-07-12 15:21:40 +03:00
|
|
|
fn init() {
|
2021-06-21 19:23:57 +03: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 15:21:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub const (
|
|
|
|
is_used = 1
|
|
|
|
)
|