diff --git a/README.md b/README.md index 7ef43ed..f9d0f56 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,11 @@ Mapped so far: get_ciphersuite_id - ssl_session: init, free; save and load return `MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE` +- ssl_conf: max_frag_len, with `MBEDTLS_SSL_MAX_FRAGMENT_LENGTH`; ssl: + get_max_out_record_payload, and export_keying_material with + `MBEDTLS_SSL_KEYING_MATERIAL_EXPORT`. The two macros need wolfSSL's + `HAVE_MAX_FRAGMENT` and `HAVE_KEYING_MATERIAL`, which wolfPSA's + `user_settings.h` defines. Known differences from Mbed TLS: @@ -202,6 +207,14 @@ Known differences from Mbed TLS: - A server resumes sessions from wolfSSL's session cache, where Mbed TLS needs `mbedtls_ssl_conf_session_cache`. A server that verifies client certificates reports `MBEDTLS_X509_BADCERT_MISSING` for a resumed session. +- `mbedtls_ssl_export_keying_material` takes shorter inputs, as wolfSSL's + key derivation limits them: in TLS 1.2 a label of at most 64 bytes, or 62 + for the label and context together; in TLS 1.3 a label of at most 53 + bytes (69 with a SHA-256 cipher suite) and a context of at most 65535. + Longer ones return `MBEDTLS_ERR_SSL_BAD_INPUT_DATA`, as do labels that + start with one of the TLS 1.2 key schedule's, such as `master secret`. +- In TLS 1.3, a server sends records of at most the max fragment length its + client asks for. Mbed TLS uses the extension in TLS 1.2 only. - wolfSSL keeps the intermediate CAs of a chain that verifies, for the config's later handshakes. A peer that then leaves them out still verifies, where Mbed TLS reports `NOT_TRUSTED`. diff --git a/src/mbedtls/ssl.c b/src/mbedtls/ssl.c index 25ee76d..3b93434 100644 --- a/src/mbedtls/ssl.c +++ b/src/mbedtls/ssl.c @@ -534,6 +534,27 @@ void mbedtls_ssl_conf_max_tls_version(mbedtls_ssl_config* conf, } } +#ifdef MBEDTLS_SSL_MAX_FRAGMENT_LENGTH +/* By RFC 6066 code, which wolfSSL_UseMaxFragment() takes too */ +static const int mbedMflLens[] = { MAX_RECORD_SIZE, 512, 1024, 2048, 4096 }; +wc_static_assert(XELEM_CNT(mbedMflLens) == MBEDTLS_SSL_MAX_FRAG_LEN_INVALID); +wc_static_assert(MBEDTLS_SSL_MAX_FRAG_LEN_512 == WOLFSSL_MFL_2_9 && + MBEDTLS_SSL_MAX_FRAG_LEN_4096 == WOLFSSL_MFL_2_12); + +int mbedtls_ssl_conf_max_frag_len(mbedtls_ssl_config* conf, + unsigned char mfl_code) +{ + WOLFSSL_ENTER("mbedtls_ssl_conf_max_frag_len"); + + if (conf == NULL || mfl_code >= MBEDTLS_SSL_MAX_FRAG_LEN_INVALID) { + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA; + } + conf->mfl_code = mfl_code; + conf->changes++; + return 0; +} +#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ + /* Not copied: the list must stay valid while conf is in use */ void mbedtls_ssl_conf_ciphersuites(mbedtls_ssl_config* conf, const int* ciphersuites) @@ -799,6 +820,23 @@ static int MbedSetSuites(WOLFSSL* ssl, const int* ids) MBEDTLS_ERR_SSL_BAD_INPUT_DATA); } +/* A server uses the max fragment length its client asks for */ +static int MbedSetMaxFrag(WOLFSSL* ssl, const mbedtls_ssl_config* conf) +{ + int ret = 0; + +#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) && defined(MBEDTLS_SSL_CLI_C) + if (conf->endpoint == MBEDTLS_SSL_IS_CLIENT && + conf->mfl_code != MBEDTLS_SSL_MAX_FRAG_LEN_NONE) { + ret = MbedRet(wolfSSL_UseMaxFragment(ssl, conf->mfl_code), + MBEDTLS_ERR_SSL_BAD_INPUT_DATA); + } +#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH && MBEDTLS_SSL_CLI_C */ + (void)ssl; + (void)conf; + return ret; +} + /* Replaces the WOLFSSL with a new one from the config, with this context's * callbacks, host name and session. Leaves none on failure. */ static int MbedSslNew(mbedtls_ssl_context* ssl) @@ -830,6 +868,10 @@ static int MbedSslNew(mbedtls_ssl_context* ssl) wolfSSL_SetIOReadCtx(ssl->ssl, ssl); wolfSSL_SetIOWriteCtx(ssl->ssl, ssl); wolfSSL_SetCertCbCtx(ssl->ssl, ssl); +#ifdef MBEDTLS_SSL_KEYING_MATERIAL_EXPORT + /* The randoms and secrets wolfSSL exports keys from */ + wolfSSL_KeepArrays(ssl->ssl); +#endif /* MBEDTLS_SSL_KEYING_MATERIAL_EXPORT */ ret = MbedSetVersion(ssl->ssl, ssl->conf); } if (ret == 0) { @@ -838,6 +880,9 @@ static int MbedSslNew(mbedtls_ssl_context* ssl) if (ret == 0) { ret = MbedSetHostname(ssl->ssl, ssl->hostname); } + if (ret == 0) { + ret = MbedSetMaxFrag(ssl->ssl, ssl->conf); + } if (ret == 0 && session != NULL) { /* One that expired since gets a full handshake, as in Mbed TLS */ (void)wolfSSL_set_session(ssl->ssl, session); @@ -1099,22 +1144,47 @@ int mbedtls_ssl_read(mbedtls_ssl_context* ssl, unsigned char* buf, size_t len) return (ret == MBEDTLS_ERR_SSL_CONN_EOF) ? 0 : ret; } +/* As in Mbed TLS, the handshake first, then one record of the size it set */ int mbedtls_ssl_write(mbedtls_ssl_context* ssl, const unsigned char* buf, size_t len) { + int max; int ret; WOLFSSL_ENTER("mbedtls_ssl_write"); - ret = MbedSslStart(ssl); + ret = mbedtls_ssl_is_handshake_over(ssl) ? 0 : mbedtls_ssl_handshake(ssl); if (ret != 0) { return ret; } - /* As in Mbed TLS, at most one record */ - ret = wolfSSL_write(ssl->ssl, buf, MbedIoLen(len, MAX_RECORD_SIZE)); + max = mbedtls_ssl_get_max_out_record_payload(ssl); + if (len > (size_t)max && + ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) { + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA; + } + ret = wolfSSL_write(ssl->ssl, buf, MbedIoLen(len, max)); return (ret > 0) ? ret : MbedSslErr(ssl, ret); } +/* The configured max fragment length, or the negotiated one if smaller */ +int mbedtls_ssl_get_max_out_record_payload(const mbedtls_ssl_context* ssl) +{ + int max = MAX_RECORD_SIZE; + int negotiated; + + WOLFSSL_ENTER("mbedtls_ssl_get_max_out_record_payload"); + + if (ssl == NULL || ssl->conf == NULL) { + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA; + } +#ifdef MBEDTLS_SSL_MAX_FRAGMENT_LENGTH + max = mbedMflLens[ssl->conf->mfl_code]; +#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ + /* An error until the handshake is done */ + negotiated = wolfSSL_GetMaxOutputSize(ssl->ssl); + return (negotiated > 0 && negotiated < max) ? negotiated : max; +} + /* Mbed TLS sends close_notify without waiting for the peer's reply */ int mbedtls_ssl_close_notify(mbedtls_ssl_context* ssl) { @@ -1133,6 +1203,24 @@ int mbedtls_ssl_close_notify(mbedtls_ssl_context* ssl) return MbedSslErr(ssl, ret); } +#ifdef MBEDTLS_SSL_KEYING_MATERIAL_EXPORT +/* wolfSSL checks the rest: handshake done, label and context lengths */ +int mbedtls_ssl_export_keying_material(mbedtls_ssl_context* ssl, + uint8_t* out, const size_t key_len, const char* label, + const size_t label_len, const unsigned char* context, + const size_t context_len, const int use_context) +{ + WOLFSSL_ENTER("mbedtls_ssl_export_keying_material"); + + if (ssl == NULL || key_len > MBEDTLS_SSL_EXPORT_MAX_KEY_LEN) { + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA; + } + return MbedRet(wolfSSL_export_keying_material(ssl->ssl, out, key_len, + label, label_len, context, context_len, use_context), + MBEDTLS_ERR_SSL_BAD_INPUT_DATA); +} +#endif /* MBEDTLS_SSL_KEYING_MATERIAL_EXPORT */ + void mbedtls_ssl_session_init(mbedtls_ssl_session* session) { WOLFSSL_ENTER("mbedtls_ssl_session_init"); diff --git a/test/mbedtls_compat/ssl_test.c b/test/mbedtls_compat/ssl_test.c index 06e1029..2b20b33 100644 --- a/test/mbedtls_compat/ssl_test.c +++ b/test/mbedtls_compat/ssl_test.c @@ -633,6 +633,209 @@ static int LargeLength(void) return ok; } +#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) || \ + defined(MBEDTLS_SSL_KEYING_MATERIAL_EXPORT) +/* A server, and a client that offers only version and does not verify */ +static int PeersVersion(mbedtls_ssl_protocol_version version) +{ + int ok = PeerNew(&cli, MBEDTLS_SSL_IS_CLIENT, MBEDTLS_SSL_VERIFY_NONE, 0, + NULL) == 0 && + PeerNew(&srv, MBEDTLS_SSL_IS_SERVER, MBEDTLS_SSL_VERIFY_NONE, 0, + NULL) == 0; + + if (ok) { + mbedtls_ssl_conf_min_tls_version(&cli.conf, version); + mbedtls_ssl_conf_max_tls_version(&cli.conf, version); + } + return ok; +} + +static int Connected(void) +{ + int s; + + return Handshake(&s) == 0 && s == 0; +} +#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH || + MBEDTLS_SSL_KEYING_MATERIAL_EXPORT */ + +#ifdef MBEDTLS_SSL_MAX_FRAGMENT_LENGTH +/* Each end's code, and the most data per record each then sends, TLS 1.2 */ +static const struct { + unsigned char cliCode; + unsigned char srvCode; + int cliMax; + int srvMax; +} maxFrags[] = { + { MBEDTLS_SSL_MAX_FRAG_LEN_NONE, MBEDTLS_SSL_MAX_FRAG_LEN_NONE, + RECORD_SZ, RECORD_SZ }, + /* The server takes the length its client asks for */ + { MBEDTLS_SSL_MAX_FRAG_LEN_512, MBEDTLS_SSL_MAX_FRAG_LEN_NONE, 512, 512 }, + /* and limits what it sends to its own */ + { MBEDTLS_SSL_MAX_FRAG_LEN_NONE, MBEDTLS_SSL_MAX_FRAG_LEN_1024, + RECORD_SZ, 1024 }, + { MBEDTLS_SSL_MAX_FRAG_LEN_2048, MBEDTLS_SSL_MAX_FRAG_LEN_4096, + 2048, 2048 }, + { MBEDTLS_SSL_MAX_FRAG_LEN_4096, MBEDTLS_SSL_MAX_FRAG_LEN_512, 4096, 512 } +}; + +/* One record each way. Each write sends one record of at most the max. */ +static int SendMax(Peer* from, Peer* to, int max) +{ + static unsigned char buf[RECORD_SZ + 1]; + + return mbedtls_ssl_get_max_out_record_payload(&from->ssl) == max && + mbedtls_ssl_write(&from->ssl, buf, sizeof(buf)) == max && + mbedtls_ssl_read(&to->ssl, buf, sizeof(buf)) == max && + mbedtls_ssl_get_bytes_avail(&to->ssl) == 0; +} + +static int MaxFragLen(void) +{ + size_t i; + int ok = 1; + + for (i = 0; ok && i < sizeof(maxFrags) / sizeof(maxFrags[0]); i++) { + ok = PeersVersion(MBEDTLS_SSL_VERSION_TLS1_2) && + mbedtls_ssl_conf_max_frag_len(&cli.conf, maxFrags[i].cliCode) == + 0 && + mbedtls_ssl_conf_max_frag_len(&srv.conf, maxFrags[i].srvCode) == + 0 && + Connected() && + SendMax(&cli, &srv, maxFrags[i].cliMax) && + SendMax(&srv, &cli, maxFrags[i].srvMax); + PeerFree(&cli); + PeerFree(&srv); + } + return ok; +} + +/* The server's first write completes the handshake, then uses its result */ +static int MaxFragLenWriteFirst(void) +{ + static unsigned char buf[RECORD_SZ + 1]; + int c = MBEDTLS_ERR_SSL_WANT_READ; + int w = MBEDTLS_ERR_SSL_WANT_READ; + int i; + int ok = PeersVersion(MBEDTLS_SSL_VERSION_TLS1_2) && + mbedtls_ssl_conf_max_frag_len(&cli.conf, + MBEDTLS_SSL_MAX_FRAG_LEN_512) == 0; + + for (i = 0; ok && i < MAX_STEPS && Waiting(w); i++) { + if (Waiting(c)) { + c = mbedtls_ssl_handshake(&cli.ssl); + } + w = mbedtls_ssl_write(&srv.ssl, buf, sizeof(buf)); + } + ok = ok && w == 512 && mbedtls_ssl_handshake(&cli.ssl) == 0 && + mbedtls_ssl_read(&cli.ssl, buf, sizeof(buf)) == 512 && + mbedtls_ssl_get_bytes_avail(&cli.ssl) == 0; + PeerFree(&cli); + PeerFree(&srv); + return ok; +} + +static int MaxFragLenInvalid(void) +{ + int ok; + + PeerInit(&cli, MBEDTLS_SSL_IS_CLIENT); + ok = mbedtls_ssl_conf_max_frag_len(NULL, MBEDTLS_SSL_MAX_FRAG_LEN_512) == + MBEDTLS_ERR_SSL_BAD_INPUT_DATA && + mbedtls_ssl_conf_max_frag_len(&cli.conf, + MBEDTLS_SSL_MAX_FRAG_LEN_INVALID) == + MBEDTLS_ERR_SSL_BAD_INPUT_DATA && + mbedtls_ssl_get_max_out_record_payload(NULL) == + MBEDTLS_ERR_SSL_BAD_INPUT_DATA; + PeerFree(&cli); + return ok; +} +#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ + +#ifdef MBEDTLS_SSL_KEYING_MATERIAL_EXPORT +#define EXPORT_SZ 24 + +/* An export by each end, which must match */ +static int ExportBoth(unsigned char* key, size_t keyLen, const char* label, + const unsigned char* context, size_t contextLen, int useContext) +{ + static unsigned char srvKey[MBEDTLS_SSL_EXPORT_MAX_KEY_LEN]; + size_t labelLen = strlen(label); + + return mbedtls_ssl_export_keying_material(&cli.ssl, key, keyLen, label, + labelLen, context, contextLen, useContext) == 0 && + mbedtls_ssl_export_keying_material(&srv.ssl, srvKey, keyLen, label, + labelLen, context, contextLen, useContext) == 0 && + memcmp(key, srvKey, keyLen) == 0; +} + +/* TLS 1.2 tells no context from an empty one, TLS 1.3 does not */ +static int ExportVersion(mbedtls_ssl_protocol_version version) +{ + static const unsigned char context[] = "context"; + static unsigned char large[MBEDTLS_SSL_EXPORT_MAX_KEY_LEN]; + unsigned char key[EXPORT_SZ]; + unsigned char other[EXPORT_SZ]; + unsigned char noContext[EXPORT_SZ]; + int ok = PeersVersion(version) && + mbedtls_ssl_export_keying_material(&cli.ssl, key, sizeof(key), + "label", 5, NULL, 0, 0) == MBEDTLS_ERR_SSL_BAD_INPUT_DATA && + Connected() && + ExportBoth(key, sizeof(key), "label", context, sizeof(context), 1) && + ExportBoth(other, sizeof(other), "label2", context, sizeof(context), + 1) && + memcmp(key, other, sizeof(key)) != 0 && + ExportBoth(other, sizeof(other), "label", context, 1, 1) && + memcmp(key, other, sizeof(key)) != 0 && + ExportBoth(other, sizeof(other), "label", NULL, 0, 1) && + ExportBoth(noContext, sizeof(noContext), "label", context, + sizeof(context), 0) && + (memcmp(other, noContext, sizeof(other)) == 0) == + (version == MBEDTLS_SSL_VERSION_TLS1_3) && + ExportBoth(large, sizeof(large), "label", NULL, 0, 0) && + mbedtls_ssl_export_keying_material(&cli.ssl, large, + sizeof(large) + 1, "label", 5, NULL, 0, 0) == + MBEDTLS_ERR_SSL_BAD_INPUT_DATA; + + PeerFree(&cli); + PeerFree(&srv); + return ok; +} + +static int ExportTls12(void) +{ + return ExportVersion(MBEDTLS_SSL_VERSION_TLS1_2); +} + +static int ExportTls13(void) +{ + return ExportVersion(MBEDTLS_SSL_VERSION_TLS1_3); +} + +/* Mbed TLS's limits: TLS 1.2 context and TLS 1.3 label lengths */ +static int ExportLimits(void) +{ + static unsigned char input[65536]; + unsigned char key[EXPORT_SZ]; + int ok = mbedtls_ssl_export_keying_material(NULL, key, sizeof(key), + "label", 5, NULL, 0, 0) == MBEDTLS_ERR_SSL_BAD_INPUT_DATA && + PeersVersion(MBEDTLS_SSL_VERSION_TLS1_2) && Connected() && + mbedtls_ssl_export_keying_material(&cli.ssl, key, sizeof(key), + "label", 5, input, sizeof(input), 1) == + MBEDTLS_ERR_SSL_BAD_INPUT_DATA; + + PeerFree(&cli); + PeerFree(&srv); + ok = ok && PeersVersion(MBEDTLS_SSL_VERSION_TLS1_3) && Connected() && + mbedtls_ssl_export_keying_material(&cli.ssl, key, sizeof(key), + (const char*)input, 250, NULL, 0, 0) == + MBEDTLS_ERR_SSL_BAD_INPUT_DATA; + PeerFree(&cli); + PeerFree(&srv); + return ok; +} +#endif /* MBEDTLS_SSL_KEYING_MATERIAL_EXPORT */ + /* The tests below change the config between mbedtls_ssl_setup and the * handshake, which Mbed TLS reads the config in */ @@ -1208,6 +1411,17 @@ static const struct { { "close_notify", ReadCloseNotify }, { "BIO errors", BioErrors }, { "length over INT_MAX", LargeLength }, +#ifdef MBEDTLS_SSL_MAX_FRAGMENT_LENGTH + { "max fragment length", MaxFragLen }, + { "max fragment length, write before the handshake", + MaxFragLenWriteFirst }, + { "max fragment length, bad input", MaxFragLenInvalid }, +#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ +#ifdef MBEDTLS_SSL_KEYING_MATERIAL_EXPORT + { "key export, TLS 1.2", ExportTls12 }, + { "key export, TLS 1.3", ExportTls13 }, + { "key export, input limits", ExportLimits }, +#endif /* MBEDTLS_SSL_KEYING_MATERIAL_EXPORT */ { "client certificate set after setup", ClientCertAfterSetup }, { "server certificate replaced after setup", ServerCertReplaced }, { "cipher suites set after setup", SuitesAfterSetup }, diff --git a/tools/psa_want_probe.c b/tools/psa_want_probe.c index a1abfbe..82352b7 100644 --- a/tools/psa_want_probe.c +++ b/tools/psa_want_probe.c @@ -294,5 +294,11 @@ __WPSA_EMIT__MBEDTLS_SSL_PROTO_TLS1_2 #if defined(WOLFSSL_TLS13) __WPSA_EMIT__MBEDTLS_SSL_PROTO_TLS1_3 #endif +#if defined(HAVE_MAX_FRAGMENT) +__WPSA_EMIT__MBEDTLS_SSL_MAX_FRAGMENT_LENGTH +#endif /* HAVE_MAX_FRAGMENT */ +#if defined(HAVE_KEYING_MATERIAL) +__WPSA_EMIT__MBEDTLS_SSL_KEYING_MATERIAL_EXPORT +#endif /* HAVE_KEYING_MATERIAL */ #endif #endif diff --git a/user_settings.h b/user_settings.h index a6c89d7..5d6b193 100644 --- a/user_settings.h +++ b/user_settings.h @@ -155,6 +155,9 @@ #define NO_DES3_TLS_SUITES #define NO_PSK #define NO_DH +/* Max fragment length and key export, on by default in Mbed TLS */ +#define HAVE_MAX_FRAGMENT +#define HAVE_KEYING_MATERIAL /* mbedtls_ssl_conf_ciphersuites() takes cipher suite IDs */ #define WOLFSSL_SET_CIPHER_BYTES /* An IP address host name is checked against the certificate's IP SANs */ diff --git a/wolfpsa/mbedtls_compat/mbedtls/ssl.h b/wolfpsa/mbedtls_compat/mbedtls/ssl.h index 102ca38..fa824a2 100644 --- a/wolfpsa/mbedtls_compat/mbedtls/ssl.h +++ b/wolfpsa/mbedtls_compat/mbedtls/ssl.h @@ -46,6 +46,12 @@ #define MBEDTLS_SSL_VERIFY_NONE 0 #define MBEDTLS_SSL_VERIFY_REQUIRED 2 #define MBEDTLS_SSL_MAX_HOST_NAME_LEN 255 +#define MBEDTLS_SSL_MAX_FRAG_LEN_NONE 0 +#define MBEDTLS_SSL_MAX_FRAG_LEN_512 1 +#define MBEDTLS_SSL_MAX_FRAG_LEN_1024 2 +#define MBEDTLS_SSL_MAX_FRAG_LEN_2048 3 +#define MBEDTLS_SSL_MAX_FRAG_LEN_4096 4 +#define MBEDTLS_SSL_MAX_FRAG_LEN_INVALID 5 #define MBEDTLS_ERR_SSL_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME -0x5D80 #define MBEDTLS_ERR_SSL_BAD_CONFIG -0x5E80 @@ -94,6 +100,7 @@ typedef struct mbedtls_ssl_config { int transport; mbedtls_ssl_protocol_version min_tls_version; mbedtls_ssl_protocol_version max_tls_version; + unsigned char mfl_code; /* MBEDTLS_SSL_MAX_FRAG_LEN_* */ const int* ciphersuites; /* the application's, NULL for the default */ mbedtls_x509_crt* ca_chain; /* the application's */ mbedtls_x509_crl* ca_crl; /* not supported, an error when set */ @@ -143,6 +150,10 @@ void mbedtls_ssl_conf_min_tls_version(mbedtls_ssl_config* conf, mbedtls_ssl_protocol_version tls_version); void mbedtls_ssl_conf_max_tls_version(mbedtls_ssl_config* conf, mbedtls_ssl_protocol_version tls_version); +#ifdef MBEDTLS_SSL_MAX_FRAGMENT_LENGTH +int mbedtls_ssl_conf_max_frag_len(mbedtls_ssl_config* conf, + unsigned char mfl_code); +#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ void mbedtls_ssl_conf_ciphersuites(mbedtls_ssl_config* conf, const int* ciphersuites); void mbedtls_ssl_conf_cert_profile(mbedtls_ssl_config* conf, @@ -197,8 +208,18 @@ size_t mbedtls_ssl_get_bytes_avail(const mbedtls_ssl_context* ssl); int mbedtls_ssl_read(mbedtls_ssl_context* ssl, unsigned char* buf, size_t len); int mbedtls_ssl_write(mbedtls_ssl_context* ssl, const unsigned char* buf, size_t len); +int mbedtls_ssl_get_max_out_record_payload(const mbedtls_ssl_context* ssl); int mbedtls_ssl_close_notify(mbedtls_ssl_context* ssl); +#ifdef MBEDTLS_SSL_KEYING_MATERIAL_EXPORT +#define MBEDTLS_SSL_EXPORT_MAX_KEY_LEN 8160 + +int mbedtls_ssl_export_keying_material(mbedtls_ssl_context* ssl, + uint8_t* out, const size_t key_len, const char* label, + const size_t label_len, const unsigned char* context, + const size_t context_len, const int use_context); +#endif /* MBEDTLS_SSL_KEYING_MATERIAL_EXPORT */ + static inline void mbedtls_ssl_set_user_data_p(mbedtls_ssl_context* ssl, void* p) {