37#if defined(ENABLE_CRYPTO_MBEDTLS)
51#include <mbedtls/debug.h>
52#include <mbedtls/error.h>
53#include <mbedtls/version.h>
55#if MBEDTLS_VERSION_NUMBER >= 0x02040000
56 #include <mbedtls/net_sockets.h>
58 #include <mbedtls/net.h>
61#include <mbedtls/oid.h>
62#include <mbedtls/pem.h>
64static const mbedtls_x509_crt_profile openvpn_x509_crt_profile_legacy =
67 MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA1 )
68 |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_RIPEMD160 )
69 |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA224 )
70 |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA256 )
71 |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA384 )
72 |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA512 ),
78static const mbedtls_x509_crt_profile openvpn_x509_crt_profile_preferred =
81 MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA224 )
82 |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA256 )
83 |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA384 )
84 |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA512 ),
90#define openvpn_x509_crt_profile_suiteb mbedtls_x509_crt_profile_suiteb;
113 ctx->
endpoint = MBEDTLS_SSL_IS_SERVER;
126 ctx->
endpoint = MBEDTLS_SSL_IS_CLIENT;
138 mbedtls_x509_crt_free(ctx->
ca_chain);
144 mbedtls_dhm_free(ctx->
dhm_ctx);
147 mbedtls_x509_crl_free(ctx->
crl);
150#if defined(ENABLE_PKCS11)
154 if (ctx->pkcs11_cert)
156 pkcs11h_certificate_freeCertificate(ctx->pkcs11_cert);
177#ifdef HAVE_EXPORT_KEYING_MATERIAL
179#if HAVE_MBEDTLS_SSL_CONF_EXPORT_KEYS_EXT_CB
189mbedtls_ssl_export_keys_cb(
void *p_expkey,
const unsigned char *ms,
190 const unsigned char *kb,
size_t maclen,
191 size_t keylen,
size_t ivlen,
192 const unsigned char client_random[32],
193 const unsigned char server_random[32],
194 mbedtls_tls_prf_types tls_prf_type)
200 static_assert(
sizeof(ks_ssl->
ctx->session->master)
201 ==
sizeof(cache->master_secret),
"master size mismatch");
203 memcpy(cache->client_server_random, client_random, 32);
204 memcpy(cache->client_server_random + 32, server_random, 32);
205 memcpy(cache->master_secret, ms,
sizeof(cache->master_secret));
206 cache->tls_prf_type = tls_prf_type;
210#elif HAVE_MBEDTLS_SSL_SET_EXPORT_KEYS_CB
223mbedtls_ssl_export_keys_cb(
void *p_expkey,
224 mbedtls_ssl_key_export_type type,
225 const unsigned char *secret,
227 const unsigned char client_random[32],
228 const unsigned char server_random[32],
229 mbedtls_tls_prf_types tls_prf_type)
233 if (type != MBEDTLS_SSL_KEY_EXPORT_TLS12_MASTER_SECRET)
244 if (secret_len !=
sizeof(cache->master_secret))
247 "ERROR: Incorrect TLS 1.2 master secret length: Got %zu, expected %zu",
248 secret_len,
sizeof(cache->master_secret));
251 memcpy(cache->client_server_random, client_random, 32);
252 memcpy(cache->client_server_random + 32, server_random, 32);
253 memcpy(cache->master_secret, secret,
sizeof(cache->master_secret));
254 cache->tls_prf_type = tls_prf_type;
260 const char *label,
size_t label_size,
261 void *ekm,
size_t ekm_size)
263 ASSERT(strlen(label) == label_size);
269 if (cache->tls_prf_type == MBEDTLS_SSL_TLS_PRF_NONE)
274 int ret = mbedtls_ssl_tls_prf(cache->tls_prf_type, cache->master_secret,
275 sizeof(cache->master_secret),
276 label, cache->client_server_random,
277 sizeof(cache->client_server_random),
293 const char *label,
size_t label_size,
294 void *ekm,
size_t ekm_size)
308tls_translate_cipher_name(
const char *cipher_name)
318 if (0 != strcmp(cipher_name, pair->
iana_name))
336 msg(
M_WARN,
"mbed TLS does not support setting tls-ciphersuites. "
337 "Ignoring TLS 1.3 cipher list: %s", ciphers);
343 char *tmp_ciphers, *tmp_ciphers_orig, *token;
360 tmp_ciphers_orig = tmp_ciphers =
string_alloc(ciphers, NULL);
362 token = strtok(tmp_ciphers, ":");
366 tls_translate_cipher_name(token));
371 token = strtok(NULL,
":");
373 free(tmp_ciphers_orig);
379 if (!profile || 0 == strcmp(profile,
"legacy")
380 || 0 == strcmp(profile,
"insecure"))
384 else if (0 == strcmp(profile,
"preferred"))
388 else if (0 == strcmp(profile,
"suiteb"))
394 msg(
M_FATAL,
"ERROR: Invalid cert profile: %s", profile);
413 while ((token =
strsep(&tmp_groups, ":")))
415 const mbedtls_ecp_curve_info *ci =
416 mbedtls_ecp_curve_info_from_name(token);
419 msg(
M_WARN,
"Warning unknown curve/group specified: %s", token);
446 if (mbedtls_x509_time_is_future(&ctx->
crt_chain->valid_from))
448 msg(
M_WARN,
"WARNING: Your certificate is not yet valid!");
451 if (mbedtls_x509_time_is_past(&ctx->
crt_chain->valid_to))
453 msg(
M_WARN,
"WARNING: Your certificate has expired!");
464 (
const unsigned char *) dh_file,
465 strlen(dh_file) + 1)))
467 msg(
M_FATAL,
"Cannot read inline DH parameters");
474 msg(
M_FATAL,
"Cannot read DH parameters from file %s", dh_file);
486 if (NULL != curve_name)
488 msg(
M_WARN,
"WARNING: mbed TLS builds do not support specifying an "
489 "ECDH curve with --ecdh-curve, using default curves. Use "
490 "--tls-groups to specify curves.");
496 bool pkcs12_file_inline,
bool load_ca_file)
498 msg(
M_FATAL,
"PKCS #12 files not yet supported for mbed TLS.");
502#ifdef ENABLE_CRYPTOAPI
506 msg(
M_FATAL,
"Windows CryptoAPI not yet supported for mbed TLS.");
524 (
const unsigned char *)cert_file,
525 strlen(cert_file) + 1)))
527 msg(
M_FATAL,
"Cannot load inline certificate file");
534 msg(
M_FATAL,
"Cannot load certificate file %s", cert_file);
541 bool priv_key_inline)
554 (
const unsigned char *) priv_key_file,
555 strlen(priv_key_file) + 1, NULL, 0,
556 mbedtls_ctr_drbg_random,
559 if (MBEDTLS_ERR_PK_PASSWORD_REQUIRED ==
status)
564 (
const unsigned char *) priv_key_file,
565 strlen(priv_key_file) + 1,
568 mbedtls_ctr_drbg_random,
577 mbedtls_ctr_drbg_random,
579 if (MBEDTLS_ERR_PK_PASSWORD_REQUIRED ==
status)
585 mbedtls_ctr_drbg_random,
591#ifdef ENABLE_MANAGEMENT
597 msg(
M_WARN,
"Cannot load private key file %s",
604 mbedtls_ctr_drbg_random,
607 msg(
M_WARN,
"Private key does not match the certificate");
633external_pkcs1_sign(
void *ctx_voidptr,
634 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng,
635#
if MBEDTLS_VERSION_NUMBER < 0x03020100
638 mbedtls_md_type_t md_alg,
unsigned int hashlen,
const unsigned char *
hash,
643 uint8_t *to_sign = NULL;
644 size_t asn_len = 0, oid_size = 0;
645 const char *oid = NULL;
649 return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
652#if MBEDTLS_VERSION_NUMBER < 0x03020100
653 if (MBEDTLS_RSA_PRIVATE != mode)
655 return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
665 if (md_alg != MBEDTLS_MD_NONE)
667 const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type( md_alg );
670 return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
673 if (!
mbed_ok(mbedtls_oid_get_oid_by_md( md_alg, &oid, &oid_size )))
675 return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
678 hashlen = mbedtls_md_get_size( md_info );
679 asn_len = 10 + oid_size;
682 if ((SIZE_MAX - hashlen) < asn_len
685 return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
689 uint8_t *p = to_sign;
690 if (md_alg != MBEDTLS_MD_NONE)
701 *p++ = MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
702 *p++ = (
unsigned char) ( 0x08 + oid_size + hashlen );
703 *p++ = MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
704 *p++ = (
unsigned char) ( 0x04 + oid_size );
705 *p++ = MBEDTLS_ASN1_OID;
706 *p++ = oid_size & 0xFF;
707 memcpy( p, oid, oid_size );
709 *p++ = MBEDTLS_ASN1_NULL;
711 *p++ = MBEDTLS_ASN1_OCTET_STRING;
715 ASSERT(asn_len == p - to_sign);
719 memcpy(p,
hash, hashlen);
722 if (!ctx->
sign(ctx->
sign_ctx, to_sign, asn_len + hashlen, sig,
725 rv = MBEDTLS_ERR_RSA_PRIVATE_FAILED;
737external_key_len(
void *vctx)
752 msg(
M_WARN,
"ERROR: external key requires a certificate.");
756 if (mbedtls_pk_get_type(&ctx->
crt_chain->pk) != MBEDTLS_PK_RSA)
758 msg(
M_WARN,
"ERROR: external key with mbed TLS requires a "
759 "certificate with an RSA key.");
769 NULL, external_pkcs1_sign, external_key_len)))
777#ifdef ENABLE_MANAGEMENT
780management_sign_func(
void *
sign_ctx,
const void *src,
size_t src_len,
781 void *dst,
size_t dst_len)
784 char *src_b64 = NULL;
785 char *dst_b64 = NULL;
797 "RSA_PKCS1_PADDING")))
825 bool ca_inline,
const char *ca_path,
bool tls_server)
829 msg(
M_FATAL,
"ERROR: mbed TLS cannot handle the capath directive");
832 if (ca_file && ca_inline)
835 (
const unsigned char *) ca_file,
836 strlen(ca_file) + 1)))
838 msg(
M_FATAL,
"Cannot load inline CA certificates");
846 msg(
M_FATAL,
"Cannot load CA certificate file %s", ca_file);
853 bool extra_certs_inline)
862 if (extra_certs_inline)
865 (
const unsigned char *) extra_certs_file,
866 strlen(extra_certs_file) + 1)))
868 msg(
M_FATAL,
"Cannot load inline extra-certs file");
873 if (!
mbed_ok(mbedtls_x509_crt_parse_file(ctx->
crt_chain, extra_certs_file)))
875 msg(
M_FATAL,
"Cannot load extra-certs file: %s", extra_certs_file);
907 buf_free_entry(cur_block);
913endless_buf_read(
endless_buffer *in,
unsigned char *out,
size_t out_len )
919 return MBEDTLS_ERR_SSL_WANT_READ;
922 while (in->
first_block != NULL && read_len < out_len)
925 if (block_len <= out_len - read_len)
928 memcpy(out + read_len, cur_entry->data + in->
data_start,
931 read_len += block_len;
941 buf_free_entry(cur_entry);
956endless_buf_write(
endless_buffer *out,
const unsigned char *in,
size_t len )
959 if (NULL == new_block)
961 return MBEDTLS_ERR_NET_SEND_FAILED;
964 new_block->data = malloc(len);
965 if (NULL == new_block->data)
968 return MBEDTLS_ERR_NET_SEND_FAILED;
971 new_block->length = len;
972 new_block->next_block = NULL;
974 memcpy(new_block->data, in, len);
992ssl_bio_read(
void *ctx,
unsigned char *out,
size_t out_len)
995 return endless_buf_read(&my_ctx->
in, out, out_len);
999ssl_bio_write(
void *ctx,
const unsigned char *in,
size_t in_len)
1002 return endless_buf_write(&my_ctx->
out, in, in_len);
1006my_debug(
void *ctx,
int level,
const char *file,
int line,
1010 msg(my_loglevel,
"mbed TLS msg (%s:%d): %s", file, line, str);
1019 static char old_sha256_hash[32] = {0};
1020 unsigned char sha256_hash[32] = {0};
1025 mbedtls_x509_crt *cert = ctx->
crt_chain;
1027 if (!
md_full(
"SHA256", cert->tbs.p, cert->tbs.len, sha256_hash))
1029 msg(
M_WARN,
"WARNING: failed to personalise random");
1032 if (0 != memcmp(old_sha256_hash, sha256_hash,
sizeof(sha256_hash)))
1036 msg(
M_WARN,
"WARNING: failed to personalise random, could not update CTR_DRBG");
1038 memcpy(old_sha256_hash, sha256_hash,
sizeof(old_sha256_hash));
1046#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
1049 #error "mbedtls is compiled without support for TLS 1.2."
1061tls_version_to_ssl_version(
int tls_ver)
1065#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
1070#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
1076 msg(
M_FATAL,
"%s: invalid or unsupported TLS version %d", __func__, tls_ver);
1087 if (ctx->
crl == NULL)
1091 mbedtls_x509_crl_free(ctx->
crl);
1095 if (!
mbed_ok(mbedtls_x509_crl_parse(ctx->
crl,
1096 (
const unsigned char *)crl_file,
1097 strlen(crl_file) + 1)))
1099 msg(
M_WARN,
"CRL: cannot parse inline CRL");
1105 if (!
mbed_ok(mbedtls_x509_crl_parse_file(ctx->
crl, crl_file)))
1107 msg(
M_WARN,
"CRL: cannot read CRL from file %s", crl_file);
1114 mbedtls_x509_crl_free(ctx->
crl);
1130 MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT);
1131#ifdef MBEDTLS_DEBUG_C
1138 mbedtls_debug_set_threshold(3);
1142 mbedtls_debug_set_threshold(2);
1145 mbedtls_ssl_conf_dbg(ks_ssl->
ssl_config, my_debug, NULL);
1146 mbedtls_ssl_conf_rng(ks_ssl->
ssl_config, mbedtls_ctr_drbg_random,
1164#if defined(MBEDTLS_SSL_RENEGOTIATION)
1165 mbedtls_ssl_conf_renegotiation(ks_ssl->
ssl_config, MBEDTLS_SSL_RENEGOTIATION_DISABLED);
1172#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
1173 mbedtls_ssl_conf_cbc_record_splitting(ks_ssl->
ssl_config,
1174 MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED);
1190 mbedtls_ssl_conf_authmode(ks_ssl->
ssl_config, MBEDTLS_SSL_VERIFY_OPTIONAL);
1194 mbedtls_ssl_conf_authmode(ks_ssl->
ssl_config, MBEDTLS_SSL_VERIFY_REQUIRED);
1203 const int configured_tls_version_min =
1212 version = tls_version_to_ssl_version(configured_tls_version_min);
1220 const int configured_tls_version_max =
1228 version = tls_version_to_ssl_version(configured_tls_version_max);
1239#if HAVE_MBEDTLS_SSL_CONF_EXPORT_KEYS_EXT_CB
1241 mbedtls_ssl_conf_export_keys_ext_cb(ks_ssl->
ssl_config,
1242 mbedtls_ssl_export_keys_cb,
session);
1247 mbedtls_ssl_init(ks_ssl->
ctx);
1250#if HAVE_MBEDTLS_SSL_SET_EXPORT_KEYS_CB
1252 mbedtls_ssl_set_export_keys_cb(ks_ssl->
ctx, mbedtls_ssl_export_keys_cb,
session);
1257 mbedtls_ssl_set_bio(ks_ssl->
ctx, ks_ssl->
bio_ctx, ssl_bio_write,
1258 ssl_bio_read, NULL);
1265 mbedtls_ssl_send_alert_message(ks_ssl->
ctx, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
1266 MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY);
1278 mbedtls_ssl_free(ks_ssl->
ctx);
1331 retval = mbedtls_ssl_write(ks->
ctx, data, len);
1336 if (MBEDTLS_ERR_SSL_WANT_WRITE == retval || MBEDTLS_ERR_SSL_WANT_READ == retval)
1341 "TLS ERROR: write tls_write_plaintext_const error");
1348 "TLS ERROR: write tls_write_plaintext_const incomplete %d/%d",
1387 if (MBEDTLS_ERR_SSL_WANT_WRITE == retval || MBEDTLS_ERR_SSL_WANT_READ == retval)
1432 if (MBEDTLS_ERR_SSL_WANT_WRITE == retval || MBEDTLS_ERR_SSL_WANT_READ == retval)
1437 "TLS ERROR: write tls_write_ciphertext error");
1441 if (retval != buf->
len)
1443 msg(
D_TLS_ERRORS,
"TLS ERROR: write tls_write_ciphertext incomplete %d/%d",
1479 retval = mbedtls_ssl_read(ks->
ctx,
BPTR(buf), len);
1484 if (MBEDTLS_ERR_SSL_WANT_WRITE == retval || MBEDTLS_ERR_SSL_WANT_READ == retval)
1519 const mbedtls_x509_crt *cert;
1524 snprintf(s1,
sizeof(s1),
"%s %s, cipher %s",
1526 mbedtls_ssl_get_version(ks_ssl->
ctx),
1527 mbedtls_ssl_get_ciphersuite(ks_ssl->
ctx));
1529 cert = mbedtls_ssl_get_peer_cert(ks_ssl->
ctx);
1532 snprintf(s2,
sizeof(s2),
", %u bit key",
1533 (
unsigned int) mbedtls_pk_get_bitlen(&cert->pk));
1541 const char *tls_cert_profile,
1550 const int *ciphers = mbedtls_ssl_list_ciphersuites();
1556 if (tls_ctx.allowed_ciphers)
1558 ciphers = tls_ctx.allowed_ciphers;
1561 while (*ciphers != 0)
1563 printf(
"%s\n", mbedtls_ssl_get_ciphersuite_name(*ciphers));
1572 const mbedtls_ecp_curve_info *pcurve = mbedtls_ecp_curve_list();
1576 msg(
M_FATAL,
"Cannot retrieve curve list from mbed TLS");
1580 printf(
"Available Elliptic curves, listed in order of preference:\n\n");
1581 while (MBEDTLS_ECP_DP_NONE != pcurve->grp_id)
1583 printf(
"%s\n", pcurve->name);
1591 static char mbedtls_version[30];
1592 unsigned int pv = mbedtls_version_get_number();
1593 snprintf(mbedtls_version,
sizeof(mbedtls_version),
"mbed TLS %d.%d.%d",
1594 (pv>>24)&0xff, (pv>>16)&0xff, (pv>>8)&0xff );
1595 return mbedtls_version;
char * string_alloc(const char *str, struct gc_arena *gc)
#define ALLOC_ARRAY_CLEAR(dptr, type, n)
static int buf_forward_capacity(const struct buffer *buf)
static void secure_memzero(void *data, size_t len)
Securely zeroise memory.
static void gc_free(struct gc_arena *a)
#define ALLOC_OBJ_CLEAR(dptr, type)
static struct gc_arena gc_new(void)
char * strsep(char **stringp, const char *delim)
const char * print_key_filename(const char *str, bool is_inline)
To be used when printing a string that may contain inline data.
int md_full(const char *mdname, const uint8_t *src, int src_len, uint8_t *dst)
Calculates the message digest for the given buffer.
mbedtls_ctr_drbg_context * rand_ctx_get(void)
Returns a singleton instance of the mbed TLS random number generator.
#define mbed_ok(errval)
Check errval and log on error.
bool mbed_log_err(unsigned int flags, int errval, const char *prefix)
Log the supplied mbed TLS error, prefixed by supplied prefix.
#define D_HANDSHAKE_VERBOSE
#define KS_PRIMARY
Primary key state index.
int key_state_read_plaintext(struct key_state_ssl *ks_ssl, struct buffer *buf)
Extract plaintext data from the TLS module.
int key_state_write_ciphertext(struct key_state_ssl *ks_ssl, struct buffer *buf)
Insert a ciphertext buffer into the TLS module.
int key_state_read_ciphertext(struct key_state_ssl *ks_ssl, struct buffer *buf)
Extract ciphertext data from the TLS module.
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.
int key_state_write_plaintext(struct key_state_ssl *ks_ssl, struct buffer *buf)
Insert a plaintext buffer into the TLS module.
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 SERVICE_STATUS status
void management_auth_failure(struct management *man, const char *type, const char *reason)
char * management_query_pk_sig(struct management *man, const char *b64_data, const char *algorithm)
mbedtls compatibility stub.
static int mbedtls_compat_pk_parse_key(mbedtls_pk_context *ctx, const unsigned char *key, size_t keylen, const unsigned char *pwd, size_t pwdlen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
mbedtls_ssl_protocol_version
@ MBEDTLS_SSL_VERSION_TLS1_2
@ MBEDTLS_SSL_VERSION_TLS1_3
@ MBEDTLS_SSL_VERSION_UNKNOWN
static void mbedtls_compat_psa_crypto_init(void)
static mbedtls_compat_group_id mbedtls_compat_get_group_id(const mbedtls_ecp_curve_info *curve_info)
static int mbedtls_compat_ctr_drbg_update(mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t add_len)
static int mbedtls_compat_pk_check_pair(const mbedtls_pk_context *pub, const mbedtls_pk_context *prv, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
static void mbedtls_ssl_conf_groups(mbedtls_ssl_config *conf, mbedtls_compat_group_id *groups)
static size_t mbedtls_dhm_get_bitlen(const mbedtls_dhm_context *ctx)
static void mbedtls_ssl_conf_max_tls_version(mbedtls_ssl_config *conf, mbedtls_ssl_protocol_version tls_version)
mbedtls_ecp_group_id mbedtls_compat_group_id
static void mbedtls_ssl_conf_min_tls_version(mbedtls_ssl_config *conf, mbedtls_ssl_protocol_version tls_version)
static int mbedtls_compat_pk_parse_keyfile(mbedtls_pk_context *ctx, const char *path, const char *password, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
static void perf_push(int type)
#define PERF_BIO_READ_PLAINTEXT
#define PERF_BIO_WRITE_CIPHERTEXT
static void perf_pop(void)
#define PERF_BIO_READ_CIPHERTEXT
#define PERF_BIO_WRITE_PLAINTEXT
PKCS #11 SSL library-specific backend.
int openvpn_base64_decode(const char *str, void *data, int size)
int openvpn_base64_encode(const void *data, int size, char **str)
static struct user_pass passbuf
int pem_password_callback(char *buf, int size, int rwflag, void *u)
Callback to retrieve the user's password.
void load_xkey_provider(void)
Load ovpn.xkey provider used for external key signing.
Control Channel SSL library backend module.
void tls_ctx_set_tls_groups(struct tls_root_ctx *ctx, const char *groups)
Set the (elliptic curve) group allowed for signatures and key exchange.
void tls_ctx_free(struct tls_root_ctx *ctx)
Frees the library-specific TLSv1 context.
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...
bool key_state_export_keying_material(struct tls_session *session, const char *label, size_t label_size, void *ekm, size_t ekm_size)
Keying Material Exporters [RFC 5705] allows additional keying material to be derived from existing TL...
void show_available_tls_ciphers_list(const char *cipher_list, const char *tls_cert_profile, bool tls13)
Show the TLS ciphers that are available for us to use in the library depending on the TLS version.
void tls_ctx_server_new(struct tls_root_ctx *ctx)
Initialise a library-specific TLS context for a server.
void show_available_curves(void)
Show the available elliptic curves in the crypto library.
void key_state_ssl_free(struct key_state_ssl *ks_ssl)
Free the SSL channel part of the given key state.
int tls_ctx_load_priv_file(struct tls_root_ctx *ctx, const char *priv_key_file, bool priv_key_file_inline)
Load private key file into the given TLS context.
void key_state_ssl_shutdown(struct key_state_ssl *ks_ssl)
Sets a TLS session to be shutdown state, so the TLS library will generate a shutdown alert.
void tls_ctx_load_extra_certs(struct tls_root_ctx *ctx, const char *extra_certs_file, bool extra_certs_file_inline)
Load extra certificate authority certificates from the given file or path.
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 ...
void tls_ctx_restrict_ciphers_tls13(struct tls_root_ctx *ctx, const char *ciphers)
Restrict the list of ciphers that can be used within the TLS context for TLS 1.3 and higher.
int tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file, bool 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.
bool tls_ctx_initialised(struct tls_root_ctx *ctx)
Checks whether the given TLS context is initialised.
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.
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.
void tls_init_lib(void)
Perform any static initialisation necessary by the library.
void print_details(struct key_state_ssl *ks_ssl, const char *prefix)
Print a one line summary of SSL/TLS session handshake.
int tls_version_max(void)
Return the maximum TLS version (as a TLS_VER_x constant) supported by current SSL implementation.
void backend_tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file, bool crl_inline)
Reload the Certificate Revocation List for the SSL channel.
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 for TLS 1.2 and below.
void tls_ctx_load_ca(struct tls_root_ctx *ctx, const char *ca_file, bool ca_file_inline, const char *ca_path, bool tls_server)
Load certificate authority certificates from the given file or path.
void tls_ctx_set_cert_profile(struct tls_root_ctx *ctx, const char *profile)
Set the TLS certificate profile.
int tls_ctx_use_management_external_key(struct tls_root_ctx *ctx)
Tell the management interface to load the given certificate and the external private key matching the...
void tls_ctx_load_cryptoapi(struct tls_root_ctx *ctx, const char *cryptoapi_cert)
Use Windows cryptoapi for key and cert, and add to library-specific TLS context.
bool tls_ctx_set_options(struct tls_root_ctx *ctx, unsigned int ssl_flags)
Set any library specific options.
void tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file, bool dh_file_inline)
Load Diffie Hellman Parameters, and load them into the library-specific TLS context.
void tls_ctx_client_new(struct tls_root_ctx *ctx)
Initialises a library-specific TLS context for a client.
void tls_ctx_load_cert_file(struct tls_root_ctx *ctx, const char *cert_file, bool cert_file_inline)
Load certificate file into the given TLS context.
Control Channel Common Data Structures.
#define SSLF_TLS_VERSION_MAX_SHIFT
#define UP_TYPE_PRIVATE_KEY
#define SSLF_CLIENT_CERT_OPTIONAL
#define SSLF_CLIENT_CERT_NOT_REQUIRED
#define SSLF_TLS_DEBUG_ENABLED
#define SSLF_TLS_VERSION_MAX_MASK
#define SSLF_TLS_VERSION_MIN_SHIFT
#define SSLF_TLS_VERSION_MIN_MASK
int tls_ctx_use_external_signing_func(struct tls_root_ctx *ctx, external_sign_func sign_func, void *sign_ctx)
Call the supplied signing function to create a TLS signature during the TLS handshake.
bool(* external_sign_func)(void *sign_ctx, const void *src, size_t src_size, void *dst, size_t dst_size)
External signing function prototype.
int get_num_elements(const char *string, char delimiter)
Returns the occurrences of 'delimiter' in a string +1 This is typically used to find out the number e...
const tls_cipher_name_pair * tls_get_cipher_name_pair(const char *cipher_name, size_t len)
Control Channel Verification Module mbed TLS backend.
buffer_entry * next_block
Wrapper structure for dynamically allocated memory.
int len
Length in bytes of the actual content within the allocated memory.
buffer_entry * first_block
buffer_entry * last_block
Context used by external_pkcs1_sign()
Garbage collection arena used to keep track of dynamically allocated memory.
mbedtls_ssl_config * ssl_config
mbedTLS global ssl config
mbedtls_ssl_context * ctx
mbedTLS connection context
struct tls_key_cache tls_key_cache
Get a tls_cipher_name_pair containing OpenSSL and IANA names for supplied TLS cipher name.
const char * openssl_name
Structure that wraps the TLS context.
mbedtls_x509_crl * crl
Certificate Revocation List.
mbedtls_x509_crt * crt_chain
Local Certificate chain.
mbedtls_x509_crt * ca_chain
CA chain for remote verification.
mbedtls_compat_group_id * groups
List of allowed groups for this connection.
int * allowed_ciphers
List of allowed ciphers for this connection.
mbedtls_dhm_context * dhm_ctx
Diffie-Helmann-Merkle context.
mbedtls_x509_crt_profile cert_profile
Allowed certificate types.
bool initialised
True if the context has been initialised.
int endpoint
Whether or not this is a server or a client.
struct external_context external_key
External key context.
mbedtls_pk_context * priv_key
Local private key.
Security parameter state of a single session within a VPN tunnel.
static int cleanup(void **state)