31 #elif defined(_MSC_VER) 37 #if defined(ENABLE_CRYPTO) && defined(ENABLE_CRYPTO_OPENSSL) 49 #ifdef ENABLE_CRYPTOAPI 55 #include <openssl/err.h> 56 #include <openssl/pkcs12.h> 57 #include <openssl/x509.h> 58 #include <openssl/crypto.h> 60 #include <openssl/ec.h> 76 SSL_load_error_strings();
78 OpenSSL_add_all_algorithms();
80 mydata_index = SSL_get_ex_new_index(0,
"struct session *", NULL, NULL, NULL);
104 ctx->
ctx = SSL_CTX_new(SSLv23_server_method());
106 if (ctx->
ctx == NULL)
117 ctx->
ctx = SSL_CTX_new(SSLv23_client_method());
119 if (ctx->
ctx == NULL)
129 if (NULL != ctx->
ctx)
131 SSL_CTX_free(ctx->
ctx);
140 return NULL != ctx->
ctx;
149 #if (OPENSSL_VERSION_NUMBER >= 0x10001000) 152 unsigned char *ekm = (
unsigned char *)
gc_malloc(size,
true, &gc);
154 if (SSL_export_keying_material(ssl->
ssl, ekm, size,
157 unsigned int len = (size * 2) + 2;
167 msg(
M_WARN,
"WARNING: Export keying material failed!");
179 #ifndef INFO_CALLBACK_SSL_CONST 180 #define INFO_CALLBACK_SSL_CONST const 185 if (where & SSL_CB_LOOP)
188 where & SSL_ST_CONNECT ?
"connect" :
189 where &SSL_ST_ACCEPT ?
"accept" :
190 "undefined", SSL_state_string_long(s));
192 else if (where & SSL_CB_ALERT)
195 where & SSL_CB_READ ?
"read" :
"write",
196 SSL_alert_type_string_long(ret),
197 SSL_alert_desc_string_long(ret));
209 #if defined(SSL_OP_NO_TLSv1_2) 211 #elif defined(SSL_OP_NO_TLSv1_1) 224 int flags = SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
228 long sslopt = SSL_OP_SINGLE_DH_USE | SSL_OP_NO_TICKET | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3;
230 const int tls_ver_min =
242 sslopt |= SSL_OP_NO_TLSv1;
244 #ifdef SSL_OP_NO_TLSv1_1 247 sslopt |= SSL_OP_NO_TLSv1_1;
250 #ifdef SSL_OP_NO_TLSv1_2 253 sslopt |= SSL_OP_NO_TLSv1_2;
256 #ifdef SSL_OP_CIPHER_SERVER_PREFERENCE 257 sslopt |= SSL_OP_CIPHER_SERVER_PREFERENCE;
259 sslopt |= SSL_OP_NO_COMPRESSION;
260 SSL_CTX_set_options(ctx->
ctx, sslopt);
263 #ifdef SSL_MODE_RELEASE_BUFFERS 264 SSL_CTX_set_mode(ctx->
ctx, SSL_MODE_RELEASE_BUFFERS);
266 SSL_CTX_set_session_cache_mode(ctx->
ctx, SSL_SESS_CACHE_OFF);
277 flags = SSL_VERIFY_PEER;
291 if (!SSL_CTX_set_cipher_list(ctx->
ctx,
309 size_t begin_of_cipher, end_of_cipher;
311 const char *current_cipher;
312 size_t current_cipher_len;
316 char openssl_ciphers[4096];
317 size_t openssl_ciphers_len = 0;
318 openssl_ciphers[0] =
'\0';
323 begin_of_cipher = end_of_cipher = 0;
324 for (; begin_of_cipher < strlen(ciphers); begin_of_cipher = end_of_cipher)
326 end_of_cipher += strcspn(&ciphers[begin_of_cipher],
":");
329 if (NULL == cipher_pair)
332 current_cipher = &ciphers[begin_of_cipher];
333 current_cipher_len = end_of_cipher - begin_of_cipher;
338 msg(
D_LOW,
"No valid translation found for TLS cipher '%.*s'",
345 current_cipher_len = strlen(current_cipher);
347 if (end_of_cipher - begin_of_cipher == current_cipher_len
348 && 0 != memcmp(&ciphers[begin_of_cipher], cipher_pair->
iana_name,
349 end_of_cipher - begin_of_cipher))
357 if ((SIZE_MAX - openssl_ciphers_len) < current_cipher_len
358 || ((
sizeof(openssl_ciphers)-1) < openssl_ciphers_len + current_cipher_len))
361 "Failed to set restricted TLS cipher list, too long (>%d).",
362 (
int)
sizeof(openssl_ciphers)-1);
366 memcpy(&openssl_ciphers[openssl_ciphers_len], current_cipher, current_cipher_len);
367 openssl_ciphers_len += current_cipher_len;
368 openssl_ciphers[openssl_ciphers_len] =
':';
369 openssl_ciphers_len++;
374 if (openssl_ciphers_len > 0)
376 openssl_ciphers[openssl_ciphers_len-1] =
'\0';
380 if (!SSL_CTX_set_cipher_list(ctx->
ctx, openssl_ciphers))
382 crypto_msg(
M_FATAL,
"Failed to set restricted TLS cipher list: %s", openssl_ciphers);
394 #if OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(LIBRESSL_VERSION_NUMBER) 396 cert = SSL_CTX_get0_certificate(ctx->
ctx);
399 SSL *ssl = SSL_new(ctx->
ctx);
400 cert = SSL_get_certificate(ssl);
408 ret = X509_cmp_time(X509_get_notBefore(cert), NULL);
415 msg(
M_WARN,
"WARNING: Your certificate is not yet valid!");
418 ret = X509_cmp_time(X509_get_notAfter(cert), NULL);
425 msg(
M_WARN,
"WARNING: Your certificate has expired!");
429 #if OPENSSL_VERSION_NUMBER < 0x10002000L || defined(LIBRESSL_VERSION_NUMBER) 437 const char *dh_file_inline
447 if (!(bio = BIO_new_mem_buf((
char *)dh_file_inline, -1)))
455 if (!(bio = BIO_new_file(dh_file,
"r")))
461 dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
468 if (!SSL_CTX_set_tmp_dh(ctx->
ctx, dh))
483 #ifndef OPENSSL_NO_EC 486 const char *sname = NULL;
489 SSL_CTX_set_options(ctx->
ctx, SSL_OP_SINGLE_ECDH_USE);
491 if (curve_name != NULL)
494 msg(
D_TLS_DEBUG,
"Using user specified ECDH curve (%s)", curve_name);
495 nid = OBJ_sn2nid(curve_name);
499 #if OPENSSL_VERSION_NUMBER >= 0x10002000L 502 SSL_CTX_set_ecdh_auto(ctx->
ctx, 1);
506 EC_KEY *eckey = NULL;
507 const EC_GROUP *ecgrp = NULL;
508 EVP_PKEY *pkey = NULL;
511 SSL *ssl = SSL_new(ctx->
ctx);
516 pkey = SSL_get_privatekey(ssl);
521 if (pkey != NULL && (eckey = EVP_PKEY_get1_EC_KEY(pkey)) != NULL
522 && (ecgrp = EC_KEY_get0_group(eckey)) != NULL)
524 nid = EC_GROUP_get_curve_name(ecgrp);
530 sname = OBJ_nid2sn(nid);
537 if (NID_undef == nid || NULL == (ecdh = EC_KEY_new_by_curve_name(nid)))
540 ecdh = EC_KEY_new_by_curve_name(NID_secp384r1);
541 const char *
source = (NULL == curve_name) ?
542 "extract curve from certificate" :
"use supplied curve";
544 "Failed to %s (%s), using secp384r1 instead.", source, sname);
545 sname = OBJ_nid2sn(NID_secp384r1);
548 if (!SSL_CTX_set_tmp_ecdh(ctx->
ctx, ecdh))
557 msg(
M_DEBUG,
"Your OpenSSL library was built without elliptic curve support." 558 " Skipping ECDH parameter loading.");
564 const char *pkcs12_file_inline,
580 BIO *b64 = BIO_new(BIO_f_base64());
581 BIO *bio = BIO_new_mem_buf((
void *) pkcs12_file_inline,
582 (
int) strlen(pkcs12_file_inline));
585 p12 = d2i_PKCS12_bio(b64, NULL);
600 p12 = d2i_PKCS12_fp(fp, NULL);
609 if (!PKCS12_parse(p12,
"", &pkey, &cert, &ca))
614 if (!PKCS12_parse(p12, password, &pkey, &cert, &ca))
616 #ifdef ENABLE_MANAGEMENT 617 if (
management && (ERR_GET_REASON(ERR_peek_error()) == PKCS12_R_MAC_VERIFY_FAILURE))
629 if (!SSL_CTX_use_certificate(ctx->
ctx, cert))
635 if (!SSL_CTX_use_PrivateKey(ctx->
ctx, pkey))
641 if (!SSL_CTX_check_private_key(ctx->
ctx))
653 if (ca && sk_X509_num(ca))
655 for (i = 0; i < sk_X509_num(ca); i++)
657 X509_STORE *cert_store = SSL_CTX_get_cert_store(ctx->
ctx);
658 if (!X509_STORE_add_cert(cert_store,sk_X509_value(ca, i)))
660 crypto_msg(
M_FATAL,
"Cannot add certificate to certificate chain (X509_STORE_add_cert)");
662 if (!SSL_CTX_add_client_CA(ctx->
ctx, sk_X509_value(ca, i)))
664 crypto_msg(
M_FATAL,
"Cannot add certificate to client CA list (SSL_CTX_add_client_CA)");
676 if (ca && sk_X509_num(ca))
678 for (i = 0; i < sk_X509_num(ca); i++)
680 if (!SSL_CTX_add_extra_chain_cert(ctx->
ctx,sk_X509_value(ca, i)))
682 crypto_msg(
M_FATAL,
"Cannot add extra certificate to chain (SSL_CTX_add_extra_chain_cert)");
690 #ifdef ENABLE_CRYPTOAPI 699 crypto_msg(
M_FATAL,
"Cannot load certificate \"%s\" from Microsoft Certificate Store", cryptoapi_cert);
711 if (!PEM_read_bio_X509(bio, &cert, NULL, NULL))
719 if (SSL_CTX_add_extra_chain_cert(ctx->
ctx, cert) != 1)
729 const char *cert_file,
const char *cert_file_inline, X509 **x509
735 bool inline_file =
false;
745 if (inline_file && cert_file_inline)
747 in = BIO_new_mem_buf((
char *)cert_file_inline, -1);
751 in = BIO_new_file(cert_file,
"r");
756 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE, ERR_R_SYS_LIB);
760 x = PEM_read_bio_X509(in, NULL,
765 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE, ERR_R_PEM_LIB);
769 ret = SSL_CTX_use_certificate(ctx->
ctx, x);
804 const char *cert_file_inline)
811 const char *priv_key_file_inline
814 SSL_CTX *ssl_ctx = NULL;
816 EVP_PKEY *pkey = NULL;
825 in = BIO_new_mem_buf((
char *)priv_key_file_inline, -1);
829 in = BIO_new_file(priv_key_file,
"r");
837 pkey = PEM_read_bio_PrivateKey(in, NULL,
845 if (!SSL_CTX_use_PrivateKey(ssl_ctx, pkey))
847 #ifdef ENABLE_MANAGEMENT 848 if (
management && (ERR_GET_REASON(ERR_peek_error()) == EVP_R_BAD_DECRYPT))
858 if (!SSL_CTX_check_private_key(ssl_ctx))
878 const char *crl_inline)
880 X509_CRL *crl = NULL;
883 X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx->
ctx);
892 STACK_OF(X509_OBJECT) *objs = X509_STORE_get0_objects(store);
893 for (
int i = 0; i < sk_X509_OBJECT_num(objs); i++)
895 X509_OBJECT *obj = sk_X509_OBJECT_value(objs, i);
899 sk_X509_OBJECT_delete(objs, i);
904 X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL);
908 in = BIO_new_mem_buf((
char *)crl_inline, -1);
912 in = BIO_new_file(crl_file,
"r");
917 msg(
M_WARN,
"CRL: cannot read: %s", crl_file);
921 crl = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL);
924 msg(
M_WARN,
"CRL: cannot read CRL from file %s", crl_file);
928 if (!X509_STORE_add_crl(store, crl))
930 msg(
M_WARN,
"CRL: cannot add %s to store", crl_file);
940 #ifdef MANAGMENT_EXTERNAL_KEY 944 rsa_pub_enc(
int flen,
const unsigned char *from,
unsigned char *to, RSA *rsa,
int padding)
952 rsa_pub_dec(
int flen,
const unsigned char *from,
unsigned char *to, RSA *rsa,
int padding)
960 rsa_priv_dec(
int flen,
const unsigned char *from,
unsigned char *to, RSA *rsa,
int padding)
973 const RSA_METHOD *meth = RSA_get_method(rsa);
980 rsa_priv_enc(
int flen,
const unsigned char *from,
unsigned char *to, RSA *rsa,
int padding)
984 char *out_b64 = NULL;
988 if (padding != RSA_PKCS1_PADDING)
1011 len = RSA_size(rsa);
1034 const char *cert_file,
const char *cert_file_inline)
1038 RSA_METHOD *rsa_meth;
1048 rsa_meth =
RSA_meth_new(
"OpenVPN external private key RSA Method",
1049 RSA_METHOD_FLAG_NO_CHECK);
1063 SSLerr(SSL_F_SSL_USE_PRIVATEKEY, ERR_R_MALLOC_FAILURE);
1080 const BIGNUM *n = NULL;
1081 const BIGNUM *e = NULL;
1085 if (!RSA_set_method(rsa, rsa_meth))
1091 if (!SSL_CTX_use_RSAPrivateKey(ctx->
ctx, rsa))
1125 return X509_NAME_cmp(*a, *b);
1130 const char *ca_file_inline,
1131 const char *ca_path,
bool tls_server
1134 STACK_OF(X509_INFO) *info_stack = NULL;
1135 STACK_OF(X509_NAME) *cert_names = NULL;
1136 X509_LOOKUP *lookup = NULL;
1137 X509_STORE *store = NULL;
1138 X509_NAME *xn = NULL;
1140 int i, added = 0, prev = 0;
1144 store = SSL_CTX_get_cert_store(ctx->
ctx);
1155 in = BIO_new_mem_buf((
char *)ca_file_inline, -1);
1159 in = BIO_new_file(ca_file,
"r");
1164 info_stack = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL);
1169 for (i = 0; i < sk_X509_INFO_num(info_stack); i++)
1171 X509_INFO *info = sk_X509_INFO_value(info_stack, i);
1174 X509_STORE_add_crl(store, info->crl);
1177 if (tls_server && !info->x509)
1184 X509_STORE_add_cert(store, info->x509);
1193 if (cert_names == NULL)
1202 xn = X509_get_subject_name(info->x509);
1209 if (sk_X509_NAME_find(cert_names, xn) == -1)
1211 xn = X509_NAME_dup(xn);
1216 sk_X509_NAME_push(cert_names, xn);
1222 int cnum = sk_X509_NAME_num(cert_names);
1223 if (cnum != (prev + 1))
1226 "Cannot load CA certificate file %s (entry %d did not validate)",
1227 np(ca_file), added);
1233 sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
1238 SSL_CTX_set_client_CA_list(ctx->
ctx, cert_names);
1244 "Cannot load CA certificate file %s (no entries were read)",
1250 int cnum = sk_X509_NAME_num(cert_names);
1254 "of %d entries were valid X509 names)",
1255 np(ca_file), cnum, added);
1268 lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir());
1269 if (lookup && X509_LOOKUP_add_dir(lookup, ca_path, X509_FILETYPE_PEM))
1271 msg(
M_WARN,
"WARNING: experimental option --capath %s", ca_path);
1277 X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL);
1283 const char *extra_certs_file_inline
1287 if (!strcmp(extra_certs_file,
INLINE_FILE_TAG) && extra_certs_file_inline)
1289 in = BIO_new_mem_buf((
char *)extra_certs_file_inline, -1);
1293 in = BIO_new_file(extra_certs_file,
"r");
1321 #warning BIO_DEBUG defined 1324 static bool biofp_toggle;
1325 static time_t biofp_last_open;
1326 static const int biofp_reopen_interval = 600;
1341 const time_t current = time(NULL);
1342 const pid_t pid = getpid();
1344 if (biofp_last_open + biofp_reopen_interval < current)
1352 biofp = fopen(fn,
"w");
1354 biofp_last_open = time(NULL);
1360 bio_debug_data(
const char *mode, BIO *bio,
const uint8_t *buf,
int len,
const char *desc)
1366 fprintf(biofp,
"BIO_%s %s time=%lld bio=" ptr_format " len=%d data=%s\n",
1367 mode, desc, (
long long)time(NULL), (
ptr_type)bio, len,
format_hex(buf, len, 0, &gc));
1374 bio_debug_oc(
const char *mode, BIO *bio)
1377 fprintf(biofp,
"BIO %s time=%lld bio=" ptr_format "\n",
1378 mode, (
long long)time(NULL), (
ptr_type)bio);
1393 ret = BIO_new(type);
1419 bio_debug_data(
"write", bio, data, size, desc);
1421 i = BIO_write(bio, data, size);
1425 if (BIO_should_retry(bio))
1490 i = BIO_read(bio,
BPTR(buf), len);
1495 bio_debug_data(
"read", bio,
BPTR(buf), i, desc);
1499 if (BIO_should_retry(bio))
1532 ks_ssl->
ssl = SSL_new(ssl_ctx->
ctx);
1547 bio_debug_oc(
"open ssl_bio", ks_ssl->
ssl_bio);
1548 bio_debug_oc(
"open ct_in", ks_ssl->
ct_in);
1549 bio_debug_oc(
"open ct_out", ks_ssl->
ct_out);
1554 SSL_set_accept_state(ks_ssl->
ssl);
1558 SSL_set_connect_state(ks_ssl->
ssl);
1562 BIO_set_ssl(ks_ssl->
ssl_bio, ks_ssl->
ssl, BIO_NOCLOSE);
1571 bio_debug_oc(
"close ssl_bio", ks_ssl->
ssl_bio);
1572 bio_debug_oc(
"close ct_in", ks_ssl->
ct_in);
1573 bio_debug_oc(
"close ct_out", ks_ssl->
ct_out);
1575 BIO_free_all(ks_ssl->
ssl_bio);
1576 SSL_free(ks_ssl->
ssl);
1586 #ifdef ENABLE_CRYPTO_OPENSSL 1590 "tls_write_plaintext");
1621 ret =
bio_read(ks_ssl->
ct_out, buf, maxlen,
"tls_read_ciphertext");
1667 const SSL_CIPHER *ciph;
1673 ciph = SSL_get_current_cipher(ks_ssl->
ssl);
1676 SSL_get_version(ks_ssl->
ssl),
1677 SSL_CIPHER_get_version(ciph),
1678 SSL_CIPHER_get_name(ciph));
1679 cert = SSL_get_peer_certificate(ks_ssl->
ssl);
1682 EVP_PKEY *pkey = X509_get_pubkey(cert);
1697 #ifndef OPENSSL_NO_EC 1701 const EC_GROUP *group = EC_KEY_get0_group(ec);
1704 int nid = EC_GROUP_get_curve_name(group);
1705 if (nid == 0 || (curve = OBJ_nid2sn(nid)) == NULL)
1707 curve =
"Error getting curve name";
1715 EVP_PKEY_free(pkey);
1729 const char *cipher_name;
1733 tls_ctx.
ctx = SSL_CTX_new(SSLv23_method());
1739 ssl = SSL_new(tls_ctx.
ctx);
1747 printf(
"Available TLS Ciphers,\n");
1748 printf(
"listed in order of preference:\n\n");
1749 while ((cipher_name = SSL_get_cipher_list(ssl, priority++)))
1756 printf(
"%s (No IANA name known to OpenVPN, use OpenSSL name.)\n", cipher_name);
1767 SSL_CTX_free(tls_ctx.
ctx);
1777 #ifndef OPENSSL_NO_EC 1778 EC_builtin_curve *curves = NULL;
1782 crv_len = EC_get_builtin_curves(NULL, 0);
1784 if (EC_get_builtin_curves(curves, crv_len))
1786 printf(
"Available Elliptic curves:\n");
1787 for (n = 0; n < crv_len; n++)
1790 sname = OBJ_nid2sn(curves[n].nid);
1796 printf(
"%s\n", sname);
1805 msg(
M_WARN,
"Your OpenSSL library was built without elliptic curve support. " 1806 "No curves available.");
1815 const char *cipher_name;
1817 ctx = SSL_CTX_new(SSLv23_method());
1828 cipher_name = SSL_get_cipher_list(ssl, 0);
1838 return SSLeay_version(SSLEAY_VERSION);
#define INFO_CALLBACK_SSL_CONST
void print_details(struct key_state_ssl *ks_ssl, const char *prefix)
static int rsa_priv_dec(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding)
static void strncpynt(char *dest, const char *src, size_t maxlen)
static void * SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX *ctx)
Fetch the default password callback user data from the SSL context.
void tls_ctx_load_cryptoapi(struct tls_root_ctx *ctx, const char *cryptoapi_cert)
int openvpn_base64_encode(const void *data, int size, char **str)
int key_state_write_plaintext_const(struct key_state_ssl *ks_ssl, const uint8_t *data, int len)
Insert plaintext data into the TLS module.
static int EVP_PKEY_id(const EVP_PKEY *pkey)
Get the PKEY type.
static pem_password_cb * SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx)
Fetch the default password callback from the SSL context.
static DSA * EVP_PKEY_get0_DSA(EVP_PKEY *pkey)
Get the DSA object of a public key.
static void gc_free(struct gc_arena *a)
#define PERF_BIO_WRITE_CIPHERTEXT
void management_auth_failure(struct management *man, const char *type, const char *reason)
static void tls_ctx_add_extra_certs(struct tls_root_ctx *ctx, BIO *bio)
static int rsa_pub_enc(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding)
int pem_password_callback(char *buf, int size, int rwflag, void *u)
Callback to retrieve the user's password.
static int RSA_meth_set_priv_dec(RSA_METHOD *meth, int(*priv_dec)(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding))
Set the private decoding function of an RSA_METHOD object.
int tls_ctx_load_priv_file(struct tls_root_ctx *ctx, const char *priv_key_file, const char *priv_key_file_inline)
Load private key file into the given TLS context.
static BIO * getbio(BIO_METHOD *type, const char *desc)
static int RSA_meth_set0_app_data(RSA_METHOD *meth, void *app_data)
Set the application data of an RSA_METHOD object.
bool tls_ctx_initialised(struct tls_root_ctx *ctx)
Checks whether the given TLS context is initialised.
static void perf_pop(void)
#define crypto_msg(flags,...)
Retrieve any OpenSSL errors, then print the supplied error message.
static void perf_push(int type)
static char * format_hex(const uint8_t *data, int size, int maxoutput, struct gc_arena *gc)
int tls_ctx_use_external_private_key(struct tls_root_ctx *ctx, const char *cert_file, const char *cert_file_inline)
#define PERF_BIO_READ_PLAINTEXT
static int RSA_meth_set_priv_enc(RSA_METHOD *meth, int(*priv_enc)(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding))
Set the private encoding function of an RSA_METHOD object.
static int RSA_meth_set_pub_dec(RSA_METHOD *meth, int(*pub_dec)(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding))
Set the public decoding function of an RSA_METHOD object.
int key_state_write_plaintext(struct key_state_ssl *ks_ssl, struct buffer *buf)
Insert a plaintext buffer into the TLS module.
static EC_KEY * EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)
Get the EC_KEY object of a public key.
#define ALLOC_ARRAY(dptr, type, n)
void setenv_str(struct env_set *es, const char *name, const char *value)
static void RSA_get0_key(const RSA *rsa, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
Get the RSA parameters.
static int RSA_bits(const RSA *rsa)
Number of significant RSA bits.
#define SSLF_CLIENT_CERT_NOT_REQUIRED
int SSL_CTX_use_CryptoAPI_certificate(SSL_CTX *ssl_ctx, const char *cert_prop)
void tls_ctx_free(struct tls_root_ctx *ctx)
Frees the library-specific TLSv1 context.
void tls_clear_error(void)
Clear the underlying SSL library's error state.
static void RSA_meth_free(RSA_METHOD *meth)
Free an existing RSA_METHOD object.
static void X509_OBJECT_free(X509_OBJECT *obj)
Destroy a X509 object.
int len
Length in bytes of the actual content within the allocated memory.
static int rsa_priv_enc(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding)
static void bio_write_post(const int status, struct buffer *buf)
void tls_ctx_set_options(struct tls_root_ctx *ctx, unsigned int ssl_flags)
Set any library specific options.
bool openvpn_snprintf(char *str, size_t size, const char *format,...)
static EVP_PKEY * X509_get0_pubkey(const X509 *x)
Get the public key from a X509 certificate.
#define SSLF_TLS_VERSION_MAX_SHIFT
static const char * np(const char *str)
void show_available_curves(void)
#define PERF_BIO_READ_CIPHERTEXT
static struct gc_arena gc_new(void)
static int RSA_meth_set_pub_enc(RSA_METHOD *meth, int(*pub_enc)(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding))
Set the public encoding function of an RSA_METHOD object.
void get_highest_preference_tls_cipher(char *buf, int size)
#define SSLF_TLS_VERSION_MIN_MASK
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
void tls_ctx_load_cert_file(struct tls_root_ctx *ctx, const char *cert_file, const char *cert_file_inline)
Use Windows cryptoapi for key and cert, and add to library-specific TLS context.
#define PERF_BIO_WRITE_PLAINTEXT
int tls_version_max(void)
Return the maximum TLS version (as a TLS_VER_x constant) supported by current SSL implementation...
static RSA * EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
Get the RSA object of a public key.
static STACK_OF(X509_OBJECT) *X509_STORE_get0_objects(X509_STORE *store)
Fetch the X509 object stack from the X509 store.
int key_state_read_plaintext(struct key_state_ssl *ks_ssl, struct buffer *buf, int maxlen)
Extract plaintext data from the TLS module.
static RSA_METHOD * RSA_meth_new(const char *name, int flags)
Allocate a new RSA method object.
static SERVICE_STATUS status
int verify_callback(void *session_obj, mbedtls_x509_crt *cert, int cert_depth, uint32_t *flags)
Verify that the remote OpenVPN peer's certificate allows setting up a VPN tunnel. ...
static int buf_forward_capacity(const struct buffer *buf)
void key_state_export_keying_material(struct key_state_ssl *ssl, struct tls_session *session)
Keying Material Exporters [RFC 5705] allows additional keying material to be derived from existing TL...
void tls_init_lib(void)
Perform any static initialisation necessary by the library.
const char * get_ssl_library_version(void)
return a pointer to a static memory area containing the name and version number of the SSL library in...
void show_available_tls_ciphers(const char *cipher_list)
char * format_hex_ex(const uint8_t *data, int size, int maxoutput, unsigned int space_break_flags, const char *separator, struct gc_arena *gc)
Get a tls_cipher_name_pair containing OpenSSL and IANA names for supplied TLS cipher name...
#define D_HANDSHAKE_VERBOSE
int tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file, const char *pkcs12_file_inline, bool load_ca_file)
Load PKCS #12 file for key, cert and (optionally) CA certs, and add to library-specific TLS context...
static int rsa_pub_dec(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding)
void key_state_ssl_free(struct key_state_ssl *ks_ssl)
Free the SSL channel part of the given key state.
void tls_ctx_server_new(struct tls_root_ctx *ctx)
Initialise a library-specific TLS context for a server.
static int DSA_bits(const DSA *dsa)
Number of significant DSA bits.
static int sk_x509_name_cmp(const X509_NAME *const *a, const X509_NAME *const *b)
void tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
Restrict the list of ciphers that can be used within the TLS context.
Structure that wraps the TLS context.
#define SSLF_CLIENT_CERT_OPTIONAL
static void check_malloc_return(const void *p)
void backend_tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file, const char *crl_inline)
Reload the Certificate Revocation List for the SSL channel.
Security parameter state of a single session within a VPN tunnel.
#define VALGRIND_MAKE_READABLE(addr, len)
void tls_ctx_check_cert_time(const struct tls_root_ctx *ctx)
Check our certificate notBefore and notAfter fields, and warn if the cert is either not yet valid or ...
Wrapper structure for dynamically allocated memory.
int mydata_index
Allocate space in SSL objects in which to store a struct tls_session pointer back to parent...
#define SHOW_TLS_CIPHER_LIST_WARNING
void tls_ctx_load_ca(struct tls_root_ctx *ctx, const char *ca_file, const char *ca_file_inline, const char *ca_path, bool tls_server)
Load certificate authority certificates from the given file or path.
static void info_callback(INFO_CALLBACK_SSL_CONST SSL *s, int where, int ret)
int key_state_write_ciphertext(struct key_state_ssl *ks_ssl, struct buffer *buf)
Insert a ciphertext buffer into the TLS module.
static int constrain_int(int x, int min, int max)
static void tls_ctx_load_cert_file_and_copy(struct tls_root_ctx *ctx, const char *cert_file, const char *cert_file_inline, X509 **x509)
static int RSA_set0_key(RSA *rsa, BIGNUM *n, BIGNUM *e, BIGNUM *d)
Set the RSA parameters.
Garbage collection arena used to keep track of dynamically allocated memory.
void tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file, const char *dh_file_inline)
Load Diffie Hellman Parameters, and load them into the library-specific TLS context.
const char * openssl_name
void tls_ctx_client_new(struct tls_root_ctx *ctx)
Initialises a library-specific TLS context for a client.
void key_state_ssl_init(struct key_state_ssl *ks_ssl, const struct tls_root_ctx *ssl_ctx, bool is_server, struct tls_session *session)
Initialise the SSL channel part of the given key state.
void tls_free_lib(void)
Free any global SSL library-specific data structures.
#define UP_TYPE_PRIVATE_KEY
static int openvpn_extkey_rsa_finish(RSA *rsa)
int key_state_read_ciphertext(struct key_state_ssl *ks_ssl, struct buffer *buf, int maxlen)
Extract ciphertext data from the TLS module.
#define SSLF_TLS_VERSION_MAX_MASK
static int RSA_meth_set_init(RSA_METHOD *meth, int(*init)(RSA *rsa))
Set the init function of an RSA_METHOD object.
#define RSA_F_RSA_OSSL_PRIVATE_ENCRYPT
static int bio_write(BIO *bio, const uint8_t *data, int size, const char *desc)
#define SSLF_TLS_VERSION_MIN_SHIFT
char * management_query_rsa_sig(struct management *man, const char *b64_data)
void setenv_del(struct env_set *es, const char *name)
const tls_cipher_name_pair * tls_get_cipher_name_pair(const char *cipher_name, size_t len)
static int EC_GROUP_order_bits(const EC_GROUP *group)
Gets the number of bits of the order of an EC_GROUP.
void tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, const char *curve_name)
Load Elliptic Curve Parameters, and load them into the library-specific TLS context.
int openvpn_base64_decode(const char *str, void *data, int size)
static void RSA_set_flags(RSA *rsa, int flags)
Set the RSA flags.
void tls_ctx_load_extra_certs(struct tls_root_ctx *ctx, const char *extra_certs_file, const char *extra_certs_file_inline)
Load extra certificate authority certificates from the given file or path.
static int X509_OBJECT_get_type(const X509_OBJECT *obj)
Get the type of an X509 object.
Container for unidirectional cipher and HMAC key material.
static int RSA_meth_set_finish(RSA_METHOD *meth, int(*finish)(RSA *rsa))
Set the finish function of an RSA_METHOD object.
static int bio_read(BIO *bio, struct buffer *buf, int maxlen, const char *desc)