Skip to content

Commit 2445fe8

Browse files
rework get max fragment length
1 parent 2caee1c commit 2445fe8

5 files changed

Lines changed: 32 additions & 12 deletions

File tree

src/internal.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7605,9 +7605,6 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
76057605
"err = %d", ret);
76067606
return MEMORY_E;
76077607
}
7608-
#ifdef HAVE_MAX_FRAGMENT
7609-
ssl->session->maxFragmentSz = ssl->max_fragment;
7610-
#endif /* HAVE_MAX_FRAGMENT */
76117608
#ifdef HAVE_SESSION_TICKET
76127609
ssl->options.noTicketTls12 = ctx->noTicketTls12;
76137610
#endif

src/ssl_sess.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ uint8_t wolfSSL_SESSION_get_max_fragment_length(WOLFSSL_SESSION* session)
754754
return 0;
755755
}
756756

757-
return session->maxFragmentSz;
757+
return session->mfl;
758758
}
759759

760760

src/tls.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,6 +2988,8 @@ static int TLSX_MFL_Parse(WOLFSSL* ssl, const byte* input, word16 length,
29882988
WOLFSSL_ERROR_VERBOSE(UNKNOWN_MAX_FRAG_LEN_E);
29892989
return UNKNOWN_MAX_FRAG_LEN_E;
29902990
}
2991+
if (ssl->session != NULL)
2992+
ssl->session->mfl = *input;
29912993

29922994
#ifndef NO_WOLFSSL_SERVER
29932995
if (isRequest) {

tests/api.c

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11307,6 +11307,31 @@ static int test_wolfSSL_UseMaxFragment(void)
1130711307

1130811308
wolfSSL_free(ssl);
1130911309
wolfSSL_CTX_free(ctx);
11310+
11311+
#if defined(OPENSSL_EXTRA) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
11312+
/* check negotiated max fragment size */
11313+
{
11314+
WOLFSSL *ssl_c = NULL;
11315+
WOLFSSL *ssl_s = NULL;
11316+
struct test_memio_ctx test_ctx;
11317+
WOLFSSL_CTX *ctx_c = NULL;
11318+
WOLFSSL_CTX *ctx_s = NULL;
11319+
11320+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
11321+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
11322+
wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
11323+
ExpectIntEQ(wolfSSL_UseMaxFragment(ssl_c, WOLFSSL_MFL_2_8),
11324+
WOLFSSL_SUCCESS);
11325+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
11326+
ExpectIntEQ(SSL_SESSION_get_max_fragment_length(
11327+
wolfSSL_get_session(ssl_c)), WOLFSSL_MFL_2_8);
11328+
11329+
wolfSSL_free(ssl_c);
11330+
wolfSSL_free(ssl_s);
11331+
wolfSSL_CTX_free(ctx_c);
11332+
wolfSSL_CTX_free(ctx_s);
11333+
}
11334+
#endif
1131011335
#endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
1131111336
#endif
1131211337
return EXPECT_RESULT();
@@ -47946,6 +47971,7 @@ static int test_wolfSSL_CTX_sess_set_remove_cb(void)
4794647971
/* Both should have been allocated */
4794747972
ExpectIntEQ(clientSessRemCountMalloc, 1);
4794847973
ExpectIntEQ(serverSessRemCountMalloc, 1);
47974+
4794947975
/* This should not be called yet. Session wasn't evicted from cache yet. */
4795047976
ExpectIntEQ(clientSessRemCountFree, 0);
4795147977
#if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
@@ -47972,13 +47998,6 @@ static int test_wolfSSL_CTX_sess_set_remove_cb(void)
4797247998
ExpectIntEQ(SSL_CTX_remove_session(serverSessCtx, serverSess), 0);
4797347999
ExpectNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx));
4797448000
ExpectIntEQ(serverSessRemCountFree, 1);
47975-
47976-
/* check on the max fragment size */
47977-
#ifdef HAVE_MAX_FRAGMENT
47978-
ExpectIntEQ(SSL_SESSION_get_max_fragment_length(serverSess),
47979-
MAX_RECORD_SIZE);
47980-
#endif
47981-
4798248001
/* Need to free the references that we kept */
4798348002
SSL_CTX_free(serverSessCtx);
4798448003
SSL_SESSION_free(serverSess);
@@ -67062,6 +67081,7 @@ static int test_wolfSSL_dtls_stateless_maxfrag(void)
6706267081
/* CH without cookie shouldn't change state */
6706367082
ExpectIntEQ(ssl_s->max_fragment, max_fragment);
6706467083
ExpectIntNE(test_ctx.c_len, 0);
67084+
6706567085
/* consume HRR from buffer */
6706667086
test_ctx.c_len = 0;
6706767087
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);

wolfssl/internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4434,7 +4434,8 @@ struct WOLFSSL_SESSION {
44344434
WOLFSSL_CRYPTO_EX_DATA ex_data;
44354435
#endif
44364436
#ifdef OPENSSL_EXTRA
4437-
word32 maxFragmentSz;
4437+
byte mfl; /* max fragment length negotiated i.e.
4438+
* WOLFSSL_MFL_2_8 (6) */
44384439
#endif
44394440
byte isSetup:1;
44404441
};

0 commit comments

Comments
 (0)