Skip to content

Commit 9b7d22a

Browse files
committed
Add session ticket fragmentation
1 parent e8056ef commit 9b7d22a

1 file changed

Lines changed: 16 additions & 51 deletions

File tree

src/internal.c

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -38959,7 +38959,14 @@ static int AddPSKtoPreMasterSecret(WOLFSSL* ssl)
3895938959
#endif
3896038960

3896138961
if (certDer != NULL && certDerSz > 0 &&
38962-
certDerSz <= MAX_TICKET_PEER_CERT_SZ) {
38962+
certDerSz <= MAX_TICKET_PEER_CERT_SZ &&
38963+
#ifdef HAVE_MAX_FRAGMENT
38964+
/* We don't support fragmentation in
38965+
* SendTls13NewSessionTicket yet. */
38966+
(!IsAtLeastTLSv1_3(ssl->version) ||
38967+
ssl->max_fragment == MAX_RECORD_SIZE)
38968+
#endif
38969+
) {
3896338970
c16toa((word16)certDerSz, it->peerCertLen);
3896438971
XMEMCPY(it->peerCert, certDer, certDerSz);
3896538972
peerCertSz = (word16)certDerSz;
@@ -39744,6 +39751,7 @@ static int AddPSKtoPreMasterSecret(WOLFSSL* ssl)
3974439751
int sendSz;
3974539752
word32 length = SESSION_HINT_SZ + LENGTH_SZ;
3974639753
word32 idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ;
39754+
word32 headerSz = 0;
3974739755

3974839756
WOLFSSL_START(WC_FUNC_TICKET_SEND);
3974939757
WOLFSSL_ENTER("SendTicket");
@@ -39770,20 +39778,13 @@ static int AddPSKtoPreMasterSecret(WOLFSSL* ssl)
3977039778
idx += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA;
3977139779
#endif
3977239780
}
39781+
headerSz = idx;
3977339782

39774-
if (IsEncryptionOn(ssl, 1) && ssl->options.handShakeDone)
39775-
sendSz += cipherExtraData(ssl);
39776-
39777-
/* Set this in case CheckAvailableSize returns a WANT_WRITE so that state
39778-
* is not advanced yet */
39779-
ssl->options.buildingMsg = 1;
39780-
39781-
/* check for available size */
39782-
if ((ret = CheckAvailableSize(ssl, sendSz)) != 0)
39783-
return ret;
39783+
output = (byte*)XMALLOC(sendSz, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
39784+
if (output == NULL)
39785+
return MEMORY_E;
3978439786

3978539787
/* get output buffer */
39786-
output = GetOutputBuffer(ssl);
3978739788
AddHeaders(output, length, session_ticket, ssl);
3978839789

3978939790
/* hint */
@@ -39798,45 +39799,9 @@ static int AddPSKtoPreMasterSecret(WOLFSSL* ssl)
3979839799
XMEMCPY(output + idx, ssl->session->ticket, ssl->session->ticketLen);
3979939800
idx += ssl->session->ticketLen;
3980039801

39801-
if (IsEncryptionOn(ssl, 1) && ssl->options.handShakeDone) {
39802-
byte* input;
39803-
int inputSz = (int)idx; /* build msg adds rec hdr */
39804-
int recordHeaderSz = RECORD_HEADER_SZ;
39805-
39806-
if (ssl->options.dtls)
39807-
recordHeaderSz += DTLS_RECORD_EXTRA;
39808-
inputSz -= recordHeaderSz;
39809-
input = (byte*)XMALLOC(inputSz, ssl->heap, DYNAMIC_TYPE_IN_BUFFER);
39810-
if (input == NULL)
39811-
return MEMORY_E;
39812-
39813-
XMEMCPY(input, output + recordHeaderSz, inputSz);
39814-
sendSz = BuildMessage(ssl, output, sendSz, input, inputSz,
39815-
handshake, 1, 0, 0, CUR_ORDER);
39816-
XFREE(input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER);
39817-
39818-
if (sendSz < 0)
39819-
return sendSz;
39820-
}
39821-
else {
39822-
#ifdef WOLFSSL_DTLS
39823-
if (ssl->options.dtls) {
39824-
if ((ret = DtlsMsgPoolSave(ssl, output, (word32)sendSz, session_ticket)) != 0)
39825-
return ret;
39826-
39827-
DtlsSEQIncrement(ssl, CUR_ORDER);
39828-
}
39829-
#endif
39830-
ret = HashOutput(ssl, output, sendSz, 0);
39831-
if (ret != 0)
39832-
return ret;
39833-
}
39834-
39835-
ssl->buffers.outputBuffer.length += sendSz;
39836-
ssl->options.buildingMsg = 0;
39837-
39838-
if (!ssl->options.groupMessages)
39839-
ret = SendBuffered(ssl);
39802+
ret = SendHandshakeMsg(ssl, output, idx - headerSz, session_ticket,
39803+
"Session Ticket");
39804+
XFREE(output, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
3984039805

3984139806
WOLFSSL_LEAVE("SendTicket", ret);
3984239807
WOLFSSL_END(WC_FUNC_TICKET_SEND);

0 commit comments

Comments
 (0)