mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-31 11:17:29 +02:00
Merge pull request #4061 from JacobBarthelmeh/sessionExport
This commit is contained in:
@ -6013,10 +6013,6 @@ AC_ARG_ENABLE([sessionexport],
|
||||
if test "$ENABLED_SESSIONEXPORT" = "yes" ||
|
||||
test "$ENABLED_SESSIONEXPORT" = "nopeer"
|
||||
then
|
||||
if test "$ENABLED_DTLS" = "no"
|
||||
then
|
||||
AC_MSG_ERROR([Only DTLS supported with session export])
|
||||
fi
|
||||
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SESSION_EXPORT"
|
||||
|
||||
if test "$ENABLED_SESSIONEXPORT" = "nopeer"
|
||||
|
@ -568,6 +568,27 @@ WOLFSSL_API int wolfSSL_use_old_poly(WOLFSSL*, int);
|
||||
WOLFSSL_API int wolfSSL_dtls_import(WOLFSSL* ssl, unsigned char* buf,
|
||||
unsigned int sz);
|
||||
|
||||
|
||||
/*!
|
||||
\brief Used to import a serialized TLS session. This function is for
|
||||
importing the state of the connection.
|
||||
WARNING: buf contains sensitive information about the state and is best to
|
||||
be encrypted before storing if stored.
|
||||
Additional debug info can be displayed with the macro
|
||||
WOLFSSL_SESSION_EXPORT_DEBUG defined.
|
||||
|
||||
\return the number of bytes read from buffer 'buf'
|
||||
|
||||
\param ssl WOLFSSL structure to import the session into
|
||||
\param buf serialized session
|
||||
\param sz size of buffer 'buf'
|
||||
|
||||
\sa wolfSSL_dtls_import
|
||||
\sa wolfSSL_tls_export
|
||||
*/
|
||||
WOLFSSL_API int wolfSSL_tls_import(WOLFSSL* ssl, const unsigned char* buf,
|
||||
unsigned int sz);
|
||||
|
||||
/*!
|
||||
\brief The wolfSSL_CTX_dtls_set_export() function is used to set
|
||||
the callback function for exporting a session. It is allowed to
|
||||
@ -680,6 +701,28 @@ WOLFSSL_API int wolfSSL_dtls_set_export(WOLFSSL* ssl, wc_dtls_export func);
|
||||
WOLFSSL_API int wolfSSL_dtls_export(WOLFSSL* ssl, unsigned char* buf,
|
||||
unsigned int* sz);
|
||||
|
||||
/*!
|
||||
\brief Used to export a serialized TLS session. This function is for
|
||||
importing a serialized state of the connection.
|
||||
In most cases wolfSSL_get_session should be used instead of
|
||||
wolfSSL_tls_export.
|
||||
Additional debug info can be displayed with the macro
|
||||
WOLFSSL_SESSION_EXPORT_DEBUG defined.
|
||||
WARNING: buf contains sensitive information about the state and is best to
|
||||
be encrypted before storing if stored.
|
||||
|
||||
\return the number of bytes written into buffer 'buf'
|
||||
|
||||
\param ssl WOLFSSL structure to export the session from
|
||||
\param buf output of serialized session
|
||||
\param sz size in bytes set in 'buf'
|
||||
|
||||
\sa wolfSSL_dtls_import
|
||||
\sa wolfSSL_tls_import
|
||||
*/
|
||||
WOLFSSL_API int wolfSSL_tls_export(WOLFSSL* ssl, unsigned char* buf,
|
||||
unsigned int* sz);
|
||||
|
||||
/*!
|
||||
\brief This function is used to set aside static memory for a CTX. Memory
|
||||
set aside is then used for the CTX’s lifetime and for any SSL objects
|
||||
|
814
src/internal.c
814
src/internal.c
File diff suppressed because it is too large
Load Diff
45
src/ssl.c
45
src/ssl.c
@ -239,6 +239,41 @@ byte tsip_rootCAverified( );
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SESSION_EXPORT
|
||||
/* Used to import a serialized TLS session.
|
||||
* WARNING: buf contains sensitive information about the state and is best to be
|
||||
* encrypted before storing if stored.
|
||||
*
|
||||
* @param ssl WOLFSSL structure to import the session into
|
||||
* @param buf serialized session
|
||||
* @param sz size of buffer 'buf'
|
||||
* @return the number of bytes read from buffer 'buf'
|
||||
*/
|
||||
int wolfSSL_tls_import(WOLFSSL* ssl, const unsigned char* buf, unsigned int sz)
|
||||
{
|
||||
if (ssl == NULL || buf == NULL) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
return wolfSSL_session_import_internal(ssl, buf, sz, WOLFSSL_EXPORT_TLS);
|
||||
}
|
||||
|
||||
|
||||
/* Used to export a serialized TLS session.
|
||||
* WARNING: buf contains sensitive information about the state and is best to be
|
||||
* encrypted before storing if stored.
|
||||
*
|
||||
* @param ssl WOLFSSL structure to export the session from
|
||||
* @param buf output of serialized session
|
||||
* @param sz size in bytes set in 'buf'
|
||||
* @return the number of bytes written into buffer 'buf'
|
||||
*/
|
||||
int wolfSSL_tls_export(WOLFSSL* ssl, unsigned char* buf, unsigned int* sz)
|
||||
{
|
||||
if (ssl == NULL || sz == NULL) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
return wolfSSL_session_export_internal(ssl, buf, sz, WOLFSSL_EXPORT_TLS);
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_DTLS
|
||||
int wolfSSL_dtls_import(WOLFSSL* ssl, const unsigned char* buf, unsigned int sz)
|
||||
{
|
||||
@ -249,7 +284,7 @@ int wolfSSL_dtls_import(WOLFSSL* ssl, const unsigned char* buf, unsigned int sz)
|
||||
}
|
||||
|
||||
/* sanity checks on buffer and protocol are done in internal function */
|
||||
return wolfSSL_dtls_import_internal(ssl, buf, sz);
|
||||
return wolfSSL_session_import_internal(ssl, buf, sz, WOLFSSL_EXPORT_DTLS);
|
||||
}
|
||||
|
||||
|
||||
@ -319,7 +354,7 @@ int wolfSSL_dtls_export(WOLFSSL* ssl, unsigned char* buf, unsigned int* sz)
|
||||
}
|
||||
|
||||
/* copy over keys, options, and dtls state struct */
|
||||
return wolfSSL_dtls_export_internal(ssl, buf, *sz);
|
||||
return wolfSSL_session_export_internal(ssl, buf, sz, WOLFSSL_EXPORT_DTLS);
|
||||
}
|
||||
|
||||
|
||||
@ -363,7 +398,7 @@ int wolfSSL_send_session(WOLFSSL* ssl)
|
||||
{
|
||||
int ret;
|
||||
byte* buf;
|
||||
word16 bufSz = MAX_EXPORT_BUFFER;
|
||||
word32 bufSz = MAX_EXPORT_BUFFER;
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_send_session");
|
||||
|
||||
@ -384,7 +419,7 @@ int wolfSSL_send_session(WOLFSSL* ssl)
|
||||
}
|
||||
|
||||
/* copy over keys, options, and dtls state struct */
|
||||
ret = wolfSSL_dtls_export_internal(ssl, buf, bufSz);
|
||||
ret = wolfSSL_session_export_internal(ssl, buf, &bufSz, WOLFSSL_EXPORT_DTLS);
|
||||
if (ret < 0) {
|
||||
XFREE(buf, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
return ret;
|
||||
@ -14329,7 +14364,7 @@ int wolfSSL_DTLS_SetCookieSecret(WOLFSSL* ssl,
|
||||
}
|
||||
#endif /* WOLFSSL_ASYNC_CRYPT && HAVE_SECURE_RENEGOTIATION */
|
||||
|
||||
#ifdef WOLFSSL_SESSION_EXPORT
|
||||
#if defined(WOLFSSL_SESSION_EXPORT) && defined(WOLFSSL_DTLS)
|
||||
if (ssl->dtls_export) {
|
||||
if ((ssl->error = wolfSSL_send_session(ssl)) != 0) {
|
||||
WOLFSSL_MSG("Export DTLS session error");
|
||||
|
79
src/wolfio.c
79
src/wolfio.c
@ -477,25 +477,18 @@ int EmbedGenerateCookie(WOLFSSL* ssl, byte *buf, int sz, void *ctx)
|
||||
|
||||
return sz;
|
||||
}
|
||||
#endif /* WOLFSSL_DTLS */
|
||||
|
||||
#ifdef WOLFSSL_SESSION_EXPORT
|
||||
|
||||
/* get the peer information in human readable form (ip, port, family)
|
||||
* default function assumes BSD sockets
|
||||
* can be overridden with wolfSSL_CTX_SetIOGetPeer
|
||||
*/
|
||||
int EmbedGetPeer(WOLFSSL* ssl, char* ip, int* ipSz,
|
||||
#ifdef WOLFSSL_DTLS
|
||||
static int EmbedGetPeerDTLS(WOLFSSL* ssl, char* ip, int* ipSz,
|
||||
unsigned short* port, int* fam)
|
||||
{
|
||||
SOCKADDR_S peer;
|
||||
word32 peerSz;
|
||||
int ret;
|
||||
|
||||
if (ssl == NULL || ip == NULL || ipSz == NULL ||
|
||||
port == NULL || fam == NULL) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
/* get peer information stored in ssl struct */
|
||||
peerSz = sizeof(SOCKADDR_S);
|
||||
if ((ret = wolfSSL_dtls_get_peer(ssl, (void*)&peer, &peerSz))
|
||||
@ -536,18 +529,14 @@ int EmbedGenerateCookie(WOLFSSL* ssl, byte *buf, int sz, void *ctx)
|
||||
return WOLFSSL_SUCCESS;
|
||||
}
|
||||
|
||||
/* set the peer information in human readable form (ip, port, family)
|
||||
* default function assumes BSD sockets
|
||||
* can be overridden with wolfSSL_CTX_SetIOSetPeer
|
||||
*/
|
||||
int EmbedSetPeer(WOLFSSL* ssl, char* ip, int ipSz,
|
||||
static int EmbedSetPeerDTLS(WOLFSSL* ssl, char* ip, int ipSz,
|
||||
unsigned short port, int fam)
|
||||
{
|
||||
int ret;
|
||||
SOCKADDR_S addr;
|
||||
|
||||
/* sanity checks on arguments */
|
||||
if (ssl == NULL || ip == NULL || ipSz < 0 || ipSz > DTLS_EXPORT_IP) {
|
||||
if (ssl == NULL || ip == NULL || ipSz < 0 || ipSz > MAX_EXPORT_IP) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
@ -594,8 +583,62 @@ int EmbedGenerateCookie(WOLFSSL* ssl, byte *buf, int sz, void *ctx)
|
||||
|
||||
return WOLFSSL_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* get the peer information in human readable form (ip, port, family)
|
||||
* default function assumes BSD sockets
|
||||
* can be overridden with wolfSSL_CTX_SetIOGetPeer
|
||||
*/
|
||||
int EmbedGetPeer(WOLFSSL* ssl, char* ip, int* ipSz,
|
||||
unsigned short* port, int* fam)
|
||||
{
|
||||
if (ssl == NULL || ip == NULL || ipSz == NULL ||
|
||||
port == NULL || fam == NULL) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
if (ssl->options.dtls) {
|
||||
#ifdef WOLFSSL_DTLS
|
||||
return EmbedGetPeerDTLS(ssl, ip, ipSz, port, fam);
|
||||
#else
|
||||
return NOT_COMPILED_IN;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
*port = wolfSSL_get_fd(ssl);
|
||||
ip[0] = '\0';
|
||||
*ipSz = 0;
|
||||
*fam = 0;
|
||||
return WOLFSSL_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/* set the peer information in human readable form (ip, port, family)
|
||||
* default function assumes BSD sockets
|
||||
* can be overridden with wolfSSL_CTX_SetIOSetPeer
|
||||
*/
|
||||
int EmbedSetPeer(WOLFSSL* ssl, char* ip, int ipSz,
|
||||
unsigned short port, int fam)
|
||||
{
|
||||
/* sanity checks on arguments */
|
||||
if (ssl == NULL || ip == NULL || ipSz < 0 || ipSz > MAX_EXPORT_IP) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
if (ssl->options.dtls) {
|
||||
#ifdef WOLFSSL_DTLS
|
||||
return EmbedSetPeerDTLS(ssl, ip, ipSz, port, fam);
|
||||
#else
|
||||
return NOT_COMPILED_IN;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
wolfSSL_set_fd(ssl, port);
|
||||
(void)fam;
|
||||
return WOLFSSL_SUCCESS;
|
||||
}
|
||||
}
|
||||
#endif /* WOLFSSL_SESSION_EXPORT */
|
||||
#endif /* WOLFSSL_DTLS */
|
||||
|
||||
#ifdef WOLFSSL_LINUXKM
|
||||
static int linuxkm_send(struct socket *socket, void *buf, int size,
|
||||
@ -1772,6 +1815,7 @@ void* wolfSSL_GetCookieCtx(WOLFSSL* ssl)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif /* WOLFSSL_DTLS */
|
||||
|
||||
#ifdef WOLFSSL_SESSION_EXPORT
|
||||
|
||||
@ -1789,7 +1833,6 @@ void wolfSSL_CTX_SetIOSetPeer(WOLFSSL_CTX* ctx, CallbackSetPeer cb)
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SESSION_EXPORT */
|
||||
#endif /* WOLFSSL_DTLS */
|
||||
|
||||
|
||||
#ifdef HAVE_NETX
|
||||
|
448
tests/api.c
448
tests/api.c
@ -3644,11 +3644,12 @@ static void test_wolfSSL_EVP_CIPHER_CTX(void)
|
||||
#ifdef HAVE_IO_TESTS_DEPENDENCIES
|
||||
|
||||
#ifdef WOLFSSL_SESSION_EXPORT
|
||||
#ifdef WOLFSSL_DTLS
|
||||
/* set up function for sending session information */
|
||||
static int test_export(WOLFSSL* inSsl, byte* buf, word32 sz, void* userCtx)
|
||||
{
|
||||
WOLFSSL_CTX* ctx;
|
||||
WOLFSSL* ssl;
|
||||
WOLFSSL_CTX* ctx = NULL;
|
||||
WOLFSSL* ssl = NULL;
|
||||
|
||||
AssertNotNull(inSsl);
|
||||
AssertNotNull(buf);
|
||||
@ -3668,6 +3669,7 @@ static int test_export(WOLFSSL* inSsl, byte* buf, word32 sz, void* userCtx)
|
||||
(void)userCtx;
|
||||
return WOLFSSL_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* returns negative value on fail and positive (including 0) on success */
|
||||
static int nonblocking_accept_read(void* args, WOLFSSL* ssl, SOCKET_T* sockfd)
|
||||
@ -4820,7 +4822,8 @@ done:
|
||||
|
||||
|
||||
/* SNI / ALPN / session export helper functions */
|
||||
#if defined(HAVE_SNI) || defined(HAVE_ALPN) || defined(WOLFSSL_SESSION_EXPORT)
|
||||
#if defined(HAVE_SNI) || defined(HAVE_ALPN) ||\
|
||||
(defined(WOLFSSL_SESSION_EXPORT) && defined(WOLFSSL_DTLS))
|
||||
|
||||
static THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args)
|
||||
{
|
||||
@ -4860,7 +4863,7 @@ static THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args)
|
||||
#ifdef WOLFSSL_ENCRYPTED_KEYS
|
||||
wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
|
||||
#endif
|
||||
#ifdef WOLFSSL_SESSION_EXPORT
|
||||
#if defined(WOLFSSL_SESSION_EXPORT) && defined(WOLFSSL_DTLS)
|
||||
AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_dtls_set_export(ctx, test_export));
|
||||
#endif
|
||||
|
||||
@ -4935,7 +4938,8 @@ static THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args)
|
||||
}
|
||||
|
||||
AssertIntEQ(len, wolfSSL_write(ssl, msg, len));
|
||||
#if defined(WOLFSSL_SESSION_EXPORT) && !defined(HAVE_IO_POOL)
|
||||
#if defined(WOLFSSL_SESSION_EXPORT) && !defined(HAVE_IO_POOL) && \
|
||||
defined(WOLFSSL_DTLS)
|
||||
if (wolfSSL_dtls(ssl)) {
|
||||
byte* import;
|
||||
word32 sz;
|
||||
@ -5651,6 +5655,439 @@ static void test_wolfSSL_dtls_export(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12)
|
||||
#ifdef WOLFSSL_TLS13
|
||||
static const byte canned_client_tls13_session[] = {
|
||||
0xA7, 0xA4, 0x01, 0x18, 0x00, 0x41, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
|
||||
0x00, 0x80, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x01,
|
||||
0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
|
||||
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
|
||||
0x01, 0x0A, 0x0F, 0x10, 0x01, 0x02, 0x09, 0x00,
|
||||
0x05, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00,
|
||||
0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00,
|
||||
0x11, 0x01, 0x01, 0x00, 0x20, 0x84, 0x4F, 0x18,
|
||||
0xD8, 0xC1, 0x24, 0xD8, 0xBB, 0x17, 0x9E, 0x31,
|
||||
0xA3, 0xF8, 0xA7, 0x3C, 0xBA, 0xEC, 0xFA, 0xB4,
|
||||
0x7F, 0xC5, 0x78, 0xEB, 0x6D, 0xE3, 0x2B, 0x7B,
|
||||
0x94, 0xBE, 0x20, 0x11, 0x7E, 0x17, 0x10, 0xA7,
|
||||
0x10, 0x19, 0xEC, 0x62, 0xCC, 0xBE, 0xF5, 0x01,
|
||||
0x35, 0x3C, 0xEA, 0xEF, 0x44, 0x3C, 0x40, 0xA2,
|
||||
0xBC, 0x18, 0x43, 0xA1, 0xA1, 0x65, 0x5C, 0x48,
|
||||
0xE2, 0xF9, 0x38, 0xEB, 0x11, 0x10, 0x72, 0x7C,
|
||||
0x78, 0x22, 0x13, 0x3B, 0x19, 0x40, 0xF0, 0x73,
|
||||
0xBE, 0x96, 0x14, 0x78, 0x26, 0xB9, 0x6B, 0x2E,
|
||||
0x72, 0x22, 0x0D, 0x90, 0x94, 0xDD, 0x78, 0x77,
|
||||
0xFC, 0x0C, 0x2E, 0x63, 0x6E, 0xF0, 0x0C, 0x35,
|
||||
0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0, 0x6F,
|
||||
0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A, 0xA0,
|
||||
0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
|
||||
0x35, 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0,
|
||||
0x6F, 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A,
|
||||
0xA0, 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06,
|
||||
0x00, 0x10, 0x00, 0x10, 0x00, 0x0C, 0x00, 0x10,
|
||||
0x00, 0x10, 0x07, 0x02, 0x04, 0x00, 0x00, 0x20,
|
||||
0x28, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x03
|
||||
};
|
||||
|
||||
static const byte canned_server_tls13_session[] = {
|
||||
0xA7, 0xA4, 0x01, 0x18, 0x00, 0x41, 0x01, 0x00,
|
||||
0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
|
||||
0x00, 0x80, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
|
||||
0x01, 0x0A, 0x0F, 0x10, 0x01, 0x02, 0x00, 0x0F,
|
||||
0x05, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00,
|
||||
0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00,
|
||||
0x11, 0x01, 0x01, 0x00, 0x20, 0x84, 0x4F, 0x18,
|
||||
0xD8, 0xC1, 0x24, 0xD8, 0xBB, 0x17, 0x9E, 0x31,
|
||||
0xA3, 0xF8, 0xA7, 0x3C, 0xBA, 0xEC, 0xFA, 0xB4,
|
||||
0x7F, 0xC5, 0x78, 0xEB, 0x6D, 0xE3, 0x2B, 0x7B,
|
||||
0x94, 0xBE, 0x20, 0x11, 0x7E, 0x17, 0x10, 0xA7,
|
||||
0x10, 0x19, 0xEC, 0x62, 0xCC, 0xBE, 0xF5, 0x01,
|
||||
0x35, 0x3C, 0xEA, 0xEF, 0x44, 0x3C, 0x40, 0xA2,
|
||||
0xBC, 0x18, 0x43, 0xA1, 0xA1, 0x65, 0x5C, 0x48,
|
||||
0xE2, 0xF9, 0x38, 0xEB, 0x11, 0x10, 0x72, 0x7C,
|
||||
0x78, 0x22, 0x13, 0x3B, 0x19, 0x40, 0xF0, 0x73,
|
||||
0xBE, 0x96, 0x14, 0x78, 0x26, 0xB9, 0x6B, 0x2E,
|
||||
0x72, 0x22, 0x0D, 0x90, 0x94, 0xDD, 0x78, 0x77,
|
||||
0xFC, 0x0C, 0x2E, 0x63, 0x6E, 0xF0, 0x0C, 0x35,
|
||||
0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0, 0x6F,
|
||||
0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A, 0xA0,
|
||||
0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
|
||||
0xD3, 0xB7, 0xEE, 0x3A, 0xA0, 0x8E, 0xA1, 0x4D,
|
||||
0xC3, 0x2E, 0x5E, 0x06, 0x35, 0x41, 0xCD, 0xF3,
|
||||
0x49, 0x31, 0x08, 0xD0, 0x6F, 0x02, 0x3D, 0xC1,
|
||||
0x00, 0x10, 0x00, 0x10, 0x00, 0x0C, 0x00, 0x10,
|
||||
0x00, 0x10, 0x07, 0x02, 0x04, 0x00, 0x00, 0x20,
|
||||
0x28, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x04
|
||||
};
|
||||
#endif /* WOLFSSL_TLS13 */
|
||||
|
||||
static const byte canned_client_session[] = {
|
||||
0xA7, 0xA4, 0x01, 0x40, 0x00, 0x41, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00,
|
||||
0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x01,
|
||||
0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
|
||||
0x27, 0x0A, 0x0D, 0x10, 0x01, 0x01, 0x0A, 0x00,
|
||||
0x05, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03, 0x00,
|
||||
0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00,
|
||||
0x0A, 0x01, 0x01, 0x00, 0x20, 0x69, 0x11, 0x6D,
|
||||
0x97, 0x15, 0x6E, 0x52, 0x27, 0xD6, 0x1D, 0x1D,
|
||||
0xF5, 0x0D, 0x59, 0xA5, 0xAC, 0x2E, 0x8C, 0x0E,
|
||||
0xCB, 0x26, 0x1E, 0xE2, 0xCE, 0xBB, 0xCE, 0xE1,
|
||||
0x7D, 0xD7, 0xEF, 0xA5, 0x44, 0x80, 0x2A, 0xDE,
|
||||
0xBB, 0x75, 0xB0, 0x1D, 0x75, 0x17, 0x20, 0x4C,
|
||||
0x08, 0x05, 0x1B, 0xBA, 0x60, 0x1F, 0x6C, 0x91,
|
||||
0x8C, 0xAA, 0xBB, 0xE5, 0xA3, 0x0B, 0x12, 0x3E,
|
||||
0xC0, 0x35, 0x43, 0x1D, 0xE2, 0x10, 0xE2, 0x02,
|
||||
0x92, 0x4B, 0x8F, 0x05, 0xA9, 0x4B, 0xCC, 0x90,
|
||||
0xC3, 0x0E, 0xC2, 0x0F, 0xE9, 0x33, 0x85, 0x9B,
|
||||
0x3C, 0x19, 0x21, 0xD5, 0x62, 0xE5, 0xE1, 0x17,
|
||||
0x8F, 0x8C, 0x19, 0x52, 0xD8, 0x59, 0x10, 0x2D,
|
||||
0x20, 0x6F, 0xBA, 0xC1, 0x1C, 0xD1, 0x82, 0xC7,
|
||||
0x32, 0x1B, 0xBB, 0xCC, 0x30, 0x03, 0xD7, 0x3A,
|
||||
0xC8, 0x18, 0xED, 0x58, 0xC8, 0x11, 0xFE, 0x71,
|
||||
0x9C, 0x71, 0xD8, 0x6B, 0xE0, 0x25, 0x64, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
|
||||
0x00, 0x00, 0x06, 0x01, 0x04, 0x08, 0x01, 0x20,
|
||||
0x28, 0x00, 0x09, 0xE1, 0x50, 0x70, 0x02, 0x2F,
|
||||
0x7E, 0xDA, 0xBD, 0x40, 0xC5, 0x58, 0x87, 0xCE,
|
||||
0x43, 0xF3, 0xC5, 0x8F, 0xA1, 0x59, 0x93, 0xEF,
|
||||
0x7E, 0xD3, 0xD0, 0xB5, 0x87, 0x1D, 0x81, 0x54,
|
||||
0x14, 0x63, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x03
|
||||
};
|
||||
|
||||
|
||||
static const byte canned_server_session[] = {
|
||||
0xA7, 0xA4, 0x01, 0x40, 0x00, 0x41, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00,
|
||||
0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
|
||||
0x27, 0x08, 0x0F, 0x10, 0x01, 0x01, 0x00, 0x11,
|
||||
0x05, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03, 0x00,
|
||||
0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
|
||||
0x0A, 0x01, 0x01, 0x00, 0x20, 0x69, 0x11, 0x6D,
|
||||
0x97, 0x15, 0x6E, 0x52, 0x27, 0xD6, 0x1D, 0x1D,
|
||||
0xF5, 0x0D, 0x59, 0xA5, 0xAC, 0x2E, 0x8C, 0x0E,
|
||||
0xCB, 0x26, 0x1E, 0xE2, 0xCE, 0xBB, 0xCE, 0xE1,
|
||||
0x7D, 0xD7, 0xEF, 0xA5, 0x44, 0x80, 0x2A, 0xDE,
|
||||
0xBB, 0x75, 0xB0, 0x1D, 0x75, 0x17, 0x20, 0x4C,
|
||||
0x08, 0x05, 0x1B, 0xBA, 0x60, 0x1F, 0x6C, 0x91,
|
||||
0x8C, 0xAA, 0xBB, 0xE5, 0xA3, 0x0B, 0x12, 0x3E,
|
||||
0xC0, 0x35, 0x43, 0x1D, 0xE2, 0x10, 0xE2, 0x02,
|
||||
0x92, 0x4B, 0x8F, 0x05, 0xA9, 0x4B, 0xCC, 0x90,
|
||||
0xC3, 0x0E, 0xC2, 0x0F, 0xE9, 0x33, 0x85, 0x9B,
|
||||
0x3C, 0x19, 0x21, 0xD5, 0x62, 0xE5, 0xE1, 0x17,
|
||||
0x8F, 0x8C, 0x19, 0x52, 0xD8, 0x59, 0x10, 0x2D,
|
||||
0x20, 0x6F, 0xBA, 0xC1, 0x1C, 0xD1, 0x82, 0xC7,
|
||||
0x32, 0x1B, 0xBB, 0xCC, 0x30, 0x03, 0xD7, 0x3A,
|
||||
0xC8, 0x18, 0xED, 0x58, 0xC8, 0x11, 0xFE, 0x71,
|
||||
0x9C, 0x71, 0xD8, 0x6B, 0xE0, 0x25, 0x64, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
|
||||
0x00, 0x00, 0x06, 0x01, 0x04, 0x08, 0x01, 0x20,
|
||||
0x28, 0x00, 0xC5, 0x8F, 0xA1, 0x59, 0x93, 0xEF,
|
||||
0x7E, 0xD3, 0xD0, 0xB5, 0x87, 0x1D, 0x81, 0x54,
|
||||
0x14, 0x63, 0x09, 0xE1, 0x50, 0x70, 0x02, 0x2F,
|
||||
0x7E, 0xDA, 0xBD, 0x40, 0xC5, 0x58, 0x87, 0xCE,
|
||||
0x43, 0xF3, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x04
|
||||
};
|
||||
|
||||
|
||||
static THREAD_RETURN WOLFSSL_THREAD tls_export_server(void* args)
|
||||
{
|
||||
SOCKET_T sockfd = 0;
|
||||
SOCKET_T clientfd = 0;
|
||||
word16 port;
|
||||
|
||||
callback_functions* cbf;
|
||||
WOLFSSL_CTX* ctx = 0;
|
||||
WOLFSSL* ssl = 0;
|
||||
|
||||
char msg[] = "I hear you fa shizzle!";
|
||||
char input[1024];
|
||||
int idx;
|
||||
|
||||
#ifdef WOLFSSL_TIRTOS
|
||||
fdOpenSession(Task_self());
|
||||
#endif
|
||||
|
||||
((func_args*)args)->return_code = TEST_FAIL;
|
||||
cbf = ((func_args*)args)->callbacks;
|
||||
|
||||
{
|
||||
WOLFSSL_METHOD* method = NULL;
|
||||
if (cbf != NULL && cbf->method != NULL) {
|
||||
method = cbf->method();
|
||||
}
|
||||
else {
|
||||
method = wolfTLSv1_2_server_method();
|
||||
}
|
||||
ctx = wolfSSL_CTX_new(method);
|
||||
}
|
||||
if (ctx == NULL) {
|
||||
goto done;
|
||||
}
|
||||
wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256");
|
||||
|
||||
#if defined(USE_WINDOWS_API)
|
||||
port = ((func_args*)args)->signal->port;
|
||||
#elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
|
||||
!defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
|
||||
/* Let tcp_listen assign port */
|
||||
port = 0;
|
||||
#else
|
||||
/* Use default port */
|
||||
port = wolfSSLPort;
|
||||
#endif
|
||||
|
||||
/* do it here to detect failure */
|
||||
tcp_accept(&sockfd, &clientfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
|
||||
CloseSocket(sockfd);
|
||||
|
||||
/* call ctx setup callback */
|
||||
if (cbf != NULL && cbf->ctx_ready != NULL) {
|
||||
cbf->ctx_ready(ctx);
|
||||
}
|
||||
|
||||
ssl = wolfSSL_new(ctx);
|
||||
if (ssl == NULL) {
|
||||
goto done;
|
||||
}
|
||||
wolfSSL_set_fd(ssl, clientfd);
|
||||
|
||||
/* call ssl setup callback */
|
||||
if (cbf != NULL && cbf->ssl_ready != NULL) {
|
||||
cbf->ssl_ready(ssl);
|
||||
}
|
||||
idx = wolfSSL_read(ssl, input, sizeof(input)-1);
|
||||
if (idx > 0) {
|
||||
input[idx] = '\0';
|
||||
printf("Client message export/import: %s\n", input);
|
||||
}
|
||||
else {
|
||||
printf("ret = %d error = %d\n", idx, wolfSSL_get_error(ssl, idx));
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
|
||||
/*err_sys("SSL_write failed");*/
|
||||
#ifdef WOLFSSL_TIRTOS
|
||||
return;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_TIRTOS
|
||||
Task_yield();
|
||||
#endif
|
||||
|
||||
((func_args*)args)->return_code = TEST_SUCCESS;
|
||||
|
||||
done:
|
||||
wolfSSL_shutdown(ssl);
|
||||
wolfSSL_free(ssl);
|
||||
wolfSSL_CTX_free(ctx);
|
||||
|
||||
CloseSocket(clientfd);
|
||||
|
||||
#ifdef WOLFSSL_TIRTOS
|
||||
fdCloseSession(Task_self());
|
||||
#endif
|
||||
|
||||
#if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
|
||||
&& defined(HAVE_THREAD_LS)
|
||||
wc_ecc_fp_free(); /* free per thread cache */
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SESSION_TICKET) && \
|
||||
((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
|
||||
#if defined(OPENSSL_EXTRA) && defined(HAVE_AESGCM)
|
||||
OpenSSLTicketCleanup();
|
||||
#elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
|
||||
TicketCleanup();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef WOLFSSL_TIRTOS
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static void load_tls12_canned_server(WOLFSSL* ssl)
|
||||
{
|
||||
int clientfd = wolfSSL_get_fd(ssl);
|
||||
AssertIntEQ(wolfSSL_tls_import(ssl, canned_server_session,
|
||||
sizeof(canned_server_session)), sizeof(canned_server_session));
|
||||
wolfSSL_set_fd(ssl, clientfd);
|
||||
}
|
||||
|
||||
|
||||
#ifdef WOLFSSL_TLS13
|
||||
static void load_tls13_canned_server(WOLFSSL* ssl)
|
||||
{
|
||||
int clientfd = wolfSSL_get_fd(ssl);
|
||||
AssertIntEQ(wolfSSL_tls_import(ssl, canned_server_tls13_session,
|
||||
sizeof(canned_server_tls13_session)),
|
||||
sizeof(canned_server_tls13_session));
|
||||
wolfSSL_set_fd(ssl, clientfd);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* v is for version WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
|
||||
static void test_wolfSSL_tls_export_run(int v)
|
||||
{
|
||||
SOCKET_T sockfd = 0;
|
||||
WOLFSSL_CTX* ctx = 0;
|
||||
WOLFSSL* ssl = 0;
|
||||
char msg[64] = "hello wolfssl!";
|
||||
char reply[1024];
|
||||
word32 replySz;
|
||||
int msgSz = (int)XSTRLEN(msg);
|
||||
const byte* clientSession = NULL;
|
||||
int clientSessionSz = 0;
|
||||
|
||||
tcp_ready ready;
|
||||
func_args server_args;
|
||||
THREAD_TYPE serverThread;
|
||||
callback_functions server_cbf;
|
||||
|
||||
#ifdef WOLFSSL_TIRTOS
|
||||
fdOpenSession(Task_self());
|
||||
#endif
|
||||
|
||||
InitTcpReady(&ready);
|
||||
|
||||
#if defined(USE_WINDOWS_API)
|
||||
/* use RNG to get random port if using windows */
|
||||
ready.port = GetRandomPort();
|
||||
#endif
|
||||
|
||||
XMEMSET(&server_args, 0, sizeof(func_args));
|
||||
XMEMSET(&server_cbf, 0, sizeof(callback_functions));
|
||||
switch (v) {
|
||||
case WOLFSSL_TLSV1_2:
|
||||
server_cbf.method = wolfTLSv1_2_server_method;
|
||||
server_cbf.ssl_ready = load_tls12_canned_server;
|
||||
|
||||
/* setup the client side */
|
||||
AssertNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
|
||||
wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256");
|
||||
clientSession = canned_client_session;
|
||||
clientSessionSz = sizeof(canned_client_session);
|
||||
break;
|
||||
#ifdef WOLFSSL_TLS13
|
||||
case WOLFSSL_TLSV1_3:
|
||||
server_cbf.method = wolfTLSv1_3_server_method;
|
||||
server_cbf.ssl_ready = load_tls13_canned_server;
|
||||
|
||||
/* setup the client side */
|
||||
AssertNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
|
||||
clientSession = canned_client_tls13_session;
|
||||
clientSessionSz = sizeof(canned_client_tls13_session);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
server_args.callbacks = &server_cbf;
|
||||
server_args.signal = &ready;
|
||||
|
||||
start_thread(tls_export_server, &server_args, &serverThread);
|
||||
wait_tcp_ready(&server_args);
|
||||
|
||||
|
||||
#ifdef WOLFSSL_TIRTOS
|
||||
fdOpenSession(Task_self());
|
||||
#endif
|
||||
|
||||
AssertNotNull(ssl = wolfSSL_new(ctx));
|
||||
tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl);
|
||||
AssertIntEQ(wolfSSL_tls_import(ssl, clientSession, clientSessionSz),
|
||||
clientSessionSz);
|
||||
replySz = sizeof(reply);
|
||||
AssertIntGT(wolfSSL_tls_export(ssl, (byte*)reply, &replySz), 0);
|
||||
#if !defined(NO_PSK) && defined(HAVE_ANON)
|
||||
/* index 20 has is setting if PSK was on and 49 is if anon is allowed */
|
||||
AssertIntEQ(XMEMCMP(reply, clientSession, replySz), 0);
|
||||
#endif
|
||||
wolfSSL_set_fd(ssl, sockfd);
|
||||
|
||||
AssertIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
|
||||
AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)-1), 0);
|
||||
|
||||
wolfSSL_free(ssl);
|
||||
wolfSSL_CTX_free(ctx);
|
||||
|
||||
CloseSocket(sockfd);
|
||||
|
||||
#ifdef WOLFSSL_TIRTOS
|
||||
fdCloseSession(Task_self());
|
||||
#endif
|
||||
|
||||
#if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
|
||||
&& defined(HAVE_THREAD_LS)
|
||||
wc_ecc_fp_free(); /* free per thread cache */
|
||||
#endif
|
||||
|
||||
join_thread(serverThread);
|
||||
|
||||
AssertIntEQ(server_args.return_code, TEST_SUCCESS);
|
||||
FreeTcpReady(&ready);
|
||||
|
||||
#ifdef WOLFSSL_TIRTOS
|
||||
fdOpenSession(Task_self());
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
static void test_wolfSSL_tls_export(void)
|
||||
{
|
||||
#if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12)
|
||||
printf(testingFmt, "wolfSSL_tls_export()");
|
||||
test_wolfSSL_tls_export_run(WOLFSSL_TLSV1_2);
|
||||
#ifdef WOLFSSL_TLS13
|
||||
test_wolfSSL_tls_export_run(WOLFSSL_TLSV1_3);
|
||||
#endif
|
||||
printf(resultFmt, passed);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*
|
||||
| TLS extensions tests
|
||||
*----------------------------------------------------------------------------*/
|
||||
@ -49395,6 +49832,7 @@ void ApiTest(void)
|
||||
#endif
|
||||
test_wolfSSL_CTX_verifyDepth_ServerClient();
|
||||
test_wolfSSL_dtls_export();
|
||||
test_wolfSSL_tls_export();
|
||||
#endif
|
||||
AssertIntEQ(test_wolfSSL_SetMinVersion(), WOLFSSL_SUCCESS);
|
||||
AssertIntEQ(test_wolfSSL_CTX_SetMinVersion(), WOLFSSL_SUCCESS);
|
||||
|
@ -1323,23 +1323,32 @@ enum Misc {
|
||||
DTLS_POOL_SZ = 255,/* allowed number of list items in TX pool */
|
||||
DTLS_EXPORT_PRO = 165,/* wolfSSL protocol for serialized session */
|
||||
DTLS_EXPORT_STATE_PRO = 166,/* wolfSSL protocol for serialized state */
|
||||
DTLS_EXPORT_VERSION = 4, /* wolfSSL version for serialized session */
|
||||
TLS_EXPORT_PRO = 167,/* wolfSSL protocol for serialized TLS */
|
||||
DTLS_EXPORT_OPT_SZ = 61, /* amount of bytes used from Options */
|
||||
DTLS_EXPORT_VERSION_3 = 3, /* wolfSSL version before TLS 1.3 addition */
|
||||
TLS_EXPORT_OPT_SZ = 65, /* amount of bytes used from Options */
|
||||
DTLS_EXPORT_OPT_SZ_3 = 60, /* amount of bytes used from Options */
|
||||
DTLS_EXPORT_KEY_SZ = 325 + (DTLS_SEQ_SZ * 2),
|
||||
/* max amount of bytes used from Keys */
|
||||
DTLS_EXPORT_MIN_KEY_SZ = 85 + (DTLS_SEQ_SZ * 2),
|
||||
/* min amount of bytes used from Keys */
|
||||
DTLS_EXPORT_SPC_SZ = 16, /* amount of bytes used from CipherSpecs */
|
||||
DTLS_EXPORT_LEN = 2, /* 2 bytes for length and protocol */
|
||||
DTLS_EXPORT_IP = 46, /* max ip size IPv4 mapped IPv6 */
|
||||
WOLFSSL_EXPORT_TLS = 1,
|
||||
WOLFSSL_EXPORT_DTLS = 0,
|
||||
#ifndef WOLFSSL_EXPORT_SPC_SZ
|
||||
WOLFSSL_EXPORT_SPC_SZ = 16, /* amount of bytes used from CipherSpecs */
|
||||
#endif
|
||||
WOLFSSL_EXPORT_LEN = 2, /* 2 bytes for length and protocol */
|
||||
WOLFSSL_EXPORT_VERSION = 4, /* wolfSSL version for serialized session */
|
||||
|
||||
/* older export versions supported */
|
||||
WOLFSSL_EXPORT_VERSION_3 = 3, /* wolfSSL version before TLS 1.3 addition */
|
||||
|
||||
MAX_EXPORT_IP = 46, /* max ip size IPv4 mapped IPv6 */
|
||||
DTLS_MTU_ADDITIONAL_READ_BUFFER = WOLFSSL_DTLS_MTU_ADDITIONAL_READ_BUFFER,
|
||||
/* Additional bytes to read so that
|
||||
* we can work with a peer that has
|
||||
* a slightly different MTU than us. */
|
||||
MAX_EXPORT_BUFFER = 514, /* max size of buffer for exporting */
|
||||
MAX_EXPORT_STATE_BUFFER = (DTLS_EXPORT_MIN_KEY_SZ) + (3 * DTLS_EXPORT_LEN),
|
||||
MAX_EXPORT_STATE_BUFFER = (DTLS_EXPORT_MIN_KEY_SZ) + (3 * WOLFSSL_EXPORT_LEN),
|
||||
/* max size of buffer for exporting state */
|
||||
FINISHED_LABEL_SZ = 15, /* TLS finished label size */
|
||||
TLS_FINISHED_SZ = 12, /* TLS has a shorter size */
|
||||
@ -1654,17 +1663,19 @@ WOLFSSL_LOCAL ProtocolVersion MakeTLSv1_3(void);
|
||||
WOLFSSL_LOCAL ProtocolVersion MakeDTLSv1(void);
|
||||
WOLFSSL_LOCAL ProtocolVersion MakeDTLSv1_2(void);
|
||||
|
||||
#ifdef WOLFSSL_SESSION_EXPORT
|
||||
WOLFSSL_LOCAL int wolfSSL_dtls_import_internal(WOLFSSL* ssl, const byte* buf,
|
||||
word32 sz);
|
||||
WOLFSSL_LOCAL int wolfSSL_dtls_export_internal(WOLFSSL* ssl, byte* buf,
|
||||
word32 sz);
|
||||
#endif
|
||||
#ifdef WOLFSSL_SESSION_EXPORT
|
||||
WOLFSSL_LOCAL int wolfSSL_session_export_internal(WOLFSSL* ssl, byte* buf,
|
||||
word32* sz, int type);
|
||||
WOLFSSL_LOCAL int wolfSSL_session_import_internal(WOLFSSL* ssl, const byte* buf,
|
||||
word32 sz, int type);
|
||||
#ifdef WOLFSSL_DTLS
|
||||
WOLFSSL_LOCAL int wolfSSL_dtls_export_state_internal(WOLFSSL* ssl,
|
||||
byte* buf, word32 sz);
|
||||
WOLFSSL_LOCAL int wolfSSL_dtls_import_state_internal(WOLFSSL* ssl,
|
||||
const byte* buf, word32 sz);
|
||||
WOLFSSL_LOCAL int wolfSSL_send_session(WOLFSSL* ssl);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct WOLFSSL_BY_DIR_HASH {
|
||||
@ -2844,12 +2855,14 @@ struct WOLFSSL_CTX {
|
||||
CallbackIOSend CBIOSend;
|
||||
#ifdef WOLFSSL_DTLS
|
||||
CallbackGenCookie CBIOCookie; /* gen cookie callback */
|
||||
#endif /* WOLFSSL_DTLS */
|
||||
#ifdef WOLFSSL_SESSION_EXPORT
|
||||
#ifdef WOLFSSL_DTLS
|
||||
wc_dtls_export dtls_export; /* export function for DTLS session */
|
||||
#endif
|
||||
CallbackGetPeer CBGetPeer;
|
||||
CallbackSetPeer CBSetPeer;
|
||||
#endif
|
||||
#endif /* WOLFSSL_DTLS */
|
||||
VerifyCallback verifyCallback; /* cert verification callback */
|
||||
#ifdef OPENSSL_ALL
|
||||
CertVerifyCallback verifyCertCb;
|
||||
|
@ -901,6 +901,11 @@ WOLFSSL_ABI WOLFSSL_API WOLFSSL_METHOD *wolfTLSv1_2_client_method(void);
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SESSION_EXPORT
|
||||
WOLFSSL_API int wolfSSL_tls_import(WOLFSSL* ssl, const unsigned char* buf,
|
||||
unsigned int sz);
|
||||
WOLFSSL_API int wolfSSL_tls_export(WOLFSSL* ssl, unsigned char* buf,
|
||||
unsigned int* sz);
|
||||
|
||||
#ifdef WOLFSSL_DTLS
|
||||
|
||||
#ifndef WOLFSSL_DTLS_EXPORT_TYPES
|
||||
@ -2967,24 +2972,25 @@ enum {
|
||||
WOLFSSL_TLS_HMAC_INNER_SZ = 13 /* SEQ_SZ + ENUM + VERSION_SZ + LEN_SZ */
|
||||
};
|
||||
|
||||
/* for GetBulkCipher and internal use */
|
||||
/* for GetBulkCipher and internal use
|
||||
* using explicit values to assist with serialization of a TLS session */
|
||||
enum BulkCipherAlgorithm {
|
||||
wolfssl_cipher_null,
|
||||
wolfssl_rc4,
|
||||
wolfssl_rc2,
|
||||
wolfssl_des,
|
||||
wolfssl_triple_des, /* leading 3 (3des) not valid identifier */
|
||||
wolfssl_des40,
|
||||
wolfssl_cipher_null = 0,
|
||||
wolfssl_rc4 = 1,
|
||||
wolfssl_rc2 = 2,
|
||||
wolfssl_des = 3,
|
||||
wolfssl_triple_des = 4,
|
||||
wolfssl_des40 = 5,
|
||||
wolfssl_aes = 6,
|
||||
wolfssl_aes_gcm = 7,
|
||||
wolfssl_aes_ccm = 8,
|
||||
wolfssl_chacha = 9,
|
||||
wolfssl_camellia = 10,
|
||||
wolfssl_hc128 = 11,
|
||||
wolfssl_rabbit = 12,
|
||||
#ifdef HAVE_IDEA
|
||||
wolfssl_idea,
|
||||
wolfssl_idea = 13
|
||||
#endif
|
||||
wolfssl_aes,
|
||||
wolfssl_aes_gcm,
|
||||
wolfssl_aes_ccm,
|
||||
wolfssl_chacha,
|
||||
wolfssl_camellia,
|
||||
wolfssl_hc128, /* wolfSSL extensions */
|
||||
wolfssl_rabbit
|
||||
};
|
||||
|
||||
|
||||
|
@ -429,12 +429,6 @@ WOLFSSL_API int BioReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx);
|
||||
WOLFSSL_API int EmbedReceiveFromMcast(WOLFSSL* ssl,
|
||||
char* buf, int sz, void*);
|
||||
#endif /* WOLFSSL_MULTICAST */
|
||||
#ifdef WOLFSSL_SESSION_EXPORT
|
||||
WOLFSSL_API int EmbedGetPeer(WOLFSSL* ssl, char* ip, int* ipSz,
|
||||
unsigned short* port, int* fam);
|
||||
WOLFSSL_API int EmbedSetPeer(WOLFSSL* ssl, char* ip, int ipSz,
|
||||
unsigned short port, int fam);
|
||||
#endif /* WOLFSSL_SESSION_EXPORT */
|
||||
#endif /* WOLFSSL_DTLS */
|
||||
#endif /* USE_WOLFSSL_IO */
|
||||
|
||||
@ -593,16 +587,20 @@ WOLFSSL_API void wolfSSL_SetIOWriteFlags(WOLFSSL* ssl, int flags);
|
||||
WOLFSSL_API void wolfSSL_SetCookieCtx(WOLFSSL* ssl, void *ctx);
|
||||
WOLFSSL_API void* wolfSSL_GetCookieCtx(WOLFSSL* ssl);
|
||||
|
||||
#ifdef WOLFSSL_SESSION_EXPORT
|
||||
typedef int (*CallbackGetPeer)(WOLFSSL* ssl, char* ip, int* ipSz,
|
||||
unsigned short* port, int* fam);
|
||||
typedef int (*CallbackSetPeer)(WOLFSSL* ssl, char* ip, int ipSz,
|
||||
unsigned short port, int fam);
|
||||
|
||||
WOLFSSL_API void wolfSSL_CTX_SetIOGetPeer(WOLFSSL_CTX*, CallbackGetPeer);
|
||||
WOLFSSL_API void wolfSSL_CTX_SetIOSetPeer(WOLFSSL_CTX*, CallbackSetPeer);
|
||||
#endif /* WOLFSSL_SESSION_EXPORT */
|
||||
#endif
|
||||
#ifdef WOLFSSL_SESSION_EXPORT
|
||||
typedef int (*CallbackGetPeer)(WOLFSSL* ssl, char* ip, int* ipSz,
|
||||
unsigned short* port, int* fam);
|
||||
typedef int (*CallbackSetPeer)(WOLFSSL* ssl, char* ip, int ipSz,
|
||||
unsigned short port, int fam);
|
||||
|
||||
WOLFSSL_API void wolfSSL_CTX_SetIOGetPeer(WOLFSSL_CTX*, CallbackGetPeer);
|
||||
WOLFSSL_API void wolfSSL_CTX_SetIOSetPeer(WOLFSSL_CTX*, CallbackSetPeer);
|
||||
WOLFSSL_API int EmbedGetPeer(WOLFSSL* ssl, char* ip, int* ipSz,
|
||||
unsigned short* port, int* fam);
|
||||
WOLFSSL_API int EmbedSetPeer(WOLFSSL* ssl, char* ip, int ipSz,
|
||||
unsigned short port, int fam);
|
||||
#endif /* WOLFSSL_SESSION_EXPORT */
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user