From 234705a80cf3be8c95bc4f4671362b93caa95731 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Tue, 18 Aug 2020 16:54:40 +0200 Subject: [PATCH 1/2] Change buffer in wolfSSL_dtls_import to be const --- src/internal.c | 12 ++++++------ src/ssl.c | 2 +- wolfssl/internal.h | 4 ++-- wolfssl/ssl.h | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/internal.c b/src/internal.c index 17c6c0cf7..74974966f 100644 --- a/src/internal.c +++ b/src/internal.c @@ -629,7 +629,7 @@ static int ExportKeyState(WOLFSSL* ssl, byte* exp, word32 len, byte ver, return idx; } -static int ImportCipherSpecState(WOLFSSL* ssl, byte* exp, word32 len, byte ver) +static int ImportCipherSpecState(WOLFSSL* ssl, const byte* exp, word32 len, byte ver) { word32 idx = 0; CipherSpecs* specs; @@ -666,7 +666,7 @@ static int ImportCipherSpecState(WOLFSSL* ssl, byte* exp, word32 len, byte ver) } -static int ImportKeyState(WOLFSSL* ssl, byte* exp, word32 len, byte ver) +static int ImportKeyState(WOLFSSL* ssl, const byte* exp, word32 len, byte ver) { word32 idx = 0; byte sz; @@ -962,7 +962,7 @@ static int dtls_export_new(WOLFSSL* ssl, byte* exp, word32 len, byte ver) /* copy items from Export struct to Options struct * On success returns size of buffer used on failure returns a negative value */ -static int dtls_export_load(WOLFSSL* ssl, byte* exp, word32 len, byte ver) +static int dtls_export_load(WOLFSSL* ssl, const byte* exp, word32 len, byte ver) { int idx = 0; Options* options = &ssl->options; @@ -1144,7 +1144,7 @@ static int ExportPeerInfo(WOLFSSL* ssl, byte* exp, word32 len, byte ver) #endif /* !WOLFSSL_SESSION_EXPORT_NOPEER */ -static int ImportPeerInfo(WOLFSSL* ssl, byte* buf, word32 len, byte ver) +static int ImportPeerInfo(WOLFSSL* ssl, const byte* buf, word32 len, byte ver) { word16 idx = 0; word16 ipSz; @@ -1346,7 +1346,7 @@ int wolfSSL_dtls_export_internal(WOLFSSL* ssl, byte* buf, word32 sz) /* On success return amount of buffer consumed */ -int wolfSSL_dtls_import_state_internal(WOLFSSL* ssl, byte* buf, word32 sz) +int wolfSSL_dtls_import_state_internal(WOLFSSL* ssl, const byte* buf, word32 sz) { word32 idx = 0; word16 length = 0; @@ -1418,7 +1418,7 @@ int wolfSSL_dtls_import_state_internal(WOLFSSL* ssl, byte* buf, word32 sz) /* On success return amount of buffer consumed */ -int wolfSSL_dtls_import_internal(WOLFSSL* ssl, byte* buf, word32 sz) +int wolfSSL_dtls_import_internal(WOLFSSL* ssl, const byte* buf, word32 sz) { word32 idx = 0; word16 length = 0; diff --git a/src/ssl.c b/src/ssl.c index bb6b101fc..af83322cb 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -191,7 +191,7 @@ byte tsip_rootCAverified( ); #ifdef WOLFSSL_SESSION_EXPORT #ifdef WOLFSSL_DTLS -int wolfSSL_dtls_import(WOLFSSL* ssl, unsigned char* buf, unsigned int sz) +int wolfSSL_dtls_import(WOLFSSL* ssl, const unsigned char* buf, unsigned int sz) { WOLFSSL_ENTER("wolfSSL_session_import"); diff --git a/wolfssl/internal.h b/wolfssl/internal.h index 608806304..277ec9ce0 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -1629,14 +1629,14 @@ WOLFSSL_LOCAL ProtocolVersion MakeTLSv1_3(void); WOLFSSL_LOCAL ProtocolVersion MakeDTLSv1_2(void); #ifdef WOLFSSL_SESSION_EXPORT - WOLFSSL_LOCAL int wolfSSL_dtls_import_internal(WOLFSSL* ssl, byte* buf, + 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); WOLFSSL_LOCAL int wolfSSL_dtls_export_state_internal(WOLFSSL* ssl, byte* buf, word32 sz); WOLFSSL_LOCAL int wolfSSL_dtls_import_state_internal(WOLFSSL* ssl, - byte* buf, word32 sz); + const byte* buf, word32 sz); WOLFSSL_LOCAL int wolfSSL_send_session(WOLFSSL* ssl); #endif #endif diff --git a/wolfssl/ssl.h b/wolfssl/ssl.h index 26fe814d4..72f90111e 100644 --- a/wolfssl/ssl.h +++ b/wolfssl/ssl.h @@ -743,7 +743,7 @@ typedef int (*wc_dtls_export)(WOLFSSL* ssl, #define WOLFSSL_DTLS_EXPORT_TYPES #endif /* WOLFSSL_DTLS_EXPORT_TYPES */ -WOLFSSL_API int wolfSSL_dtls_import(WOLFSSL* ssl, unsigned char* buf, +WOLFSSL_API int wolfSSL_dtls_import(WOLFSSL* ssl, const unsigned char* buf, unsigned int sz); WOLFSSL_API int wolfSSL_CTX_dtls_set_export(WOLFSSL_CTX* ctx, wc_dtls_export func); From b9527600f4178101c7814c14c09d0fe0b72f5b1a Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Mon, 14 Sep 2020 09:22:47 +0200 Subject: [PATCH 2/2] Return size of consumed buffer --- src/internal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal.c b/src/internal.c index 74974966f..fa4d5d57d 100644 --- a/src/internal.c +++ b/src/internal.c @@ -1413,7 +1413,7 @@ int wolfSSL_dtls_import_state_internal(WOLFSSL* ssl, const byte* buf, word32 sz) idx += ret; WOLFSSL_LEAVE("wolfSSL_dtls_import_state_internal", ret); - return ret; + return idx; }