Skip to content

Commit 8458b5e

Browse files
Merge pull request #9053 from rlm2002/sessionTickets
update wolfSSL_get_SessionTicket to be able to return ticket length
2 parents 22b221a + a725f4d commit 8458b5e

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

doc/dox_comments/header_files/ssl.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11971,11 +11971,13 @@ int wolfSSL_CTX_UseSessionTicket(WOLFSSL_CTX* ctx);
1197111971
\ingroup IO
1197211972
1197311973
\brief This function copies the ticket member of the Session structure to
11974-
the buffer.
11974+
the buffer. If buf is NULL and bufSz is non-NULL, bufSz will be set to the
11975+
ticket length.
1197511976
1197611977
\return SSL_SUCCESS returned if the function executed without error.
11977-
\return BAD_FUNC_ARG returned if one of the arguments was NULL or if the
11978-
bufSz argument was 0.
11978+
\return BAD_FUNC_ARG returned if ssl or bufSz is NULL, or if bufSz
11979+
is non-NULL and buf is NULL
11980+
1197911981
1198011982
\param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
1198111983
\param buf a byte pointer representing the memory buffer.

src/ssl.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4292,7 +4292,15 @@ int wolfSSL_CTX_UseSessionTicket(WOLFSSL_CTX* ctx)
42924292

42934293
int wolfSSL_get_SessionTicket(WOLFSSL* ssl, byte* buf, word32* bufSz)
42944294
{
4295-
if (ssl == NULL || buf == NULL || bufSz == NULL || *bufSz == 0)
4295+
if (ssl == NULL || bufSz == NULL)
4296+
return BAD_FUNC_ARG;
4297+
4298+
if (*bufSz == 0 && buf == NULL) {
4299+
*bufSz = ssl->session->ticketLen;
4300+
return LENGTH_ONLY_E;
4301+
}
4302+
4303+
if (buf == NULL)
42964304
return BAD_FUNC_ARG;
42974305

42984306
if (ssl->session->ticketLen <= *bufSz) {

tests/api.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27863,13 +27863,18 @@ static int test_wolfSSL_SESSION(void)
2786327863
const char* ticket = "This is a session ticket";
2786427864
char buf[64] = {0};
2786527865
word32 bufSz = (word32)sizeof(buf);
27866+
word32 retSz = 0;
2786627867

2786727868
ExpectIntEQ(WOLFSSL_SUCCESS,
2786827869
wolfSSL_set_SessionTicket(ssl, (byte *)ticket,
2786927870
(word32)XSTRLEN(ticket)));
2787027871
ExpectIntEQ(WOLFSSL_SUCCESS,
2787127872
wolfSSL_get_SessionTicket(ssl, (byte *)buf, &bufSz));
2787227873
ExpectStrEQ(ticket, buf);
27874+
27875+
/* return ticket length if buffer parameter is null */
27876+
wolfSSL_get_SessionTicket(ssl, NULL, &retSz);
27877+
ExpectIntEQ(bufSz, retSz);
2787327878
}
2787427879
#endif
2787527880

0 commit comments

Comments
 (0)