" an explicit nsCertType designation t = 'client' | 'server'.\n"
"--x509-track x : Save peer X509 attribute x in environment for use by\n"
" plugins and management interface.\n"
-#if defined(ENABLE_CRYPTO_OPENSSL) && OPENSSL_VERSION_NUMBER >= 0x10001000
+#ifdef HAVE_EKM
"--keying-material-exporter label len : Save Exported Keying Material (RFC5705)\n"
" of len bytes (min. 16 bytes) using label in environment for use by plugins.\n"
#endif
options->use_peer_id = true;
options->peer_id = atoi(p[1]);
}
-#if defined(ENABLE_CRYPTO_OPENSSL) && OPENSSL_VERSION_NUMBER >= 0x10001000
+#ifdef HAVE_EKM
else if (streq(p[0], "keying-material-exporter") && p[1] && p[2])
{
int ekm_length = positive_atoi(p[2]);
return ctx->initialised;
}
+#ifdef HAVE_EKM
+int mbedtls_ssl_export_keys_cb(void *p_expkey, const unsigned char *ms,
+ const unsigned char *kb, size_t maclen,
+ size_t keylen, size_t ivlen,
+ const unsigned char client_random[32],
+ const unsigned char server_random[32],
+ mbedtls_tls_prf_types tls_prf_type)
+{
+ struct tls_session *session = p_expkey;
+ struct key_state_ssl *ks_ssl = &session->key[KS_PRIMARY].ks_ssl;
+ unsigned char client_server_random[64];
+
+ ks_ssl->exported_key_material = gc_malloc(session->opt->ekm_size,
+ true, NULL);
+
+ memcpy(client_server_random, client_random, 32);
+ memcpy(client_server_random + 32, server_random, 32);
+
+ const size_t ms_len = sizeof(ks_ssl->ctx->session->master);
+ int ret = mbedtls_ssl_tls_prf(
+ tls_prf_type, ms, ms_len, session->opt->ekm_label,
+ client_server_random, sizeof(client_server_random),
+ ks_ssl->exported_key_material, session->opt->ekm_size);
+
+ if (!mbed_ok(ret))
+ {
+ secure_memzero(ks_ssl->exported_key_material, session->opt->ekm_size);
+ }
+
+ secure_memzero(client_server_random, sizeof(client_server_random));
+
+ return ret;
+}
+#endif /* HAVE_EKM */
+
void
key_state_export_keying_material(struct key_state_ssl *ssl,
struct tls_session *session)
{
+ if (ssl->exported_key_material)
+ {
+ unsigned int size = session->opt->ekm_size;
+ struct gc_arena gc = gc_new();
+ unsigned int len = (size * 2) + 2;
+
+ const char *key = format_hex_ex(ssl->exported_key_material,
+ size, len, 0, NULL, &gc);
+ setenv_str(session->opt->es, "exported_keying_material", key);
+
+ dmsg(D_TLS_DEBUG_MED, "%s: exported keying material: %s",
+ __func__, key);
+ gc_free(&gc);
+ }
}
+
bool
tls_ctx_set_options(struct tls_root_ctx *ctx, unsigned int ssl_flags)
{
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)
+ const struct tls_root_ctx *ssl_ctx, bool is_server,
+ struct tls_session *session)
{
ASSERT(NULL != ssl_ctx);
ASSERT(ks_ssl);
}
}
+#if MBEDTLS_VERSION_NUMBER >= 0x02120000
+ /* Initialize keying material exporter */
+ if (session->opt->ekm_size)
+ {
+ mbedtls_ssl_conf_export_keys_ext_cb(&ks_ssl->ssl_config,
+ mbedtls_ssl_export_keys_cb, session);
+ }
+#endif
+
/* Initialise SSL context */
ALLOC_OBJ_CLEAR(ks_ssl->ctx, mbedtls_ssl_context);
mbedtls_ssl_init(ks_ssl->ctx);
{
if (ks_ssl)
{
+ free(ks_ssl->exported_key_material);
+
if (ks_ssl->ctx)
{
mbedtls_ssl_free(ks_ssl->ctx);
#undef ENABLE_DEF_AUTH
#endif
-/* Enable mbed TLS RNG prediction resistance support */
#ifdef ENABLE_CRYPTO_MBEDTLS
+#include <mbedtls/version.h>
#define ENABLE_PREDICTION_RESISTANCE
#endif /* ENABLE_CRYPTO_MBEDTLS */
+#ifdef ENABLE_CRYPTO_OPENSSL
+#include <openssl/opensslv.h>
+#endif /* ENABLE_CRYPTO_OPENSSL */
+
/*
* Enable packet filter?
*/
#define ENABLE_CRYPTOAPI
#endif
+/*
+ * Do we support RFC 5705 keying material exporters?
+ */
+#if (defined(ENABLE_CRYPTO_MBEDTLS) && MBEDTLS_VERSION_NUMBER >= 0x02120000) || \
+ (defined(ENABLE_CRYPTO_OPENSSL) && OPENSSL_VERSION_NUMBER >= 0x10001000)
+#define HAVE_EKM
+#endif
+
/*
* Is poll available on this platform?
*/