@@ -23844,6 +23844,7 @@ static int BuildCertificateStatus(WOLFSSL* ssl, byte type, buffer* status,
2384423844 byte* output = NULL;
2384523845 word32 idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ;
2384623846 word32 length = ENUM_LEN;
23847+ word32 headerSz= idx;
2384723848 int sendSz = 0;
2384823849 int ret = 0;
2384923850 int i = 0;
@@ -23863,88 +23864,42 @@ static int BuildCertificateStatus(WOLFSSL* ssl, byte type, buffer* status,
2386323864 default:
2386423865 return 0;
2386523866 }
23867+ #ifdef WOLFSSL_DTLS
23868+ if (ssl->options.dtls) {
23869+ headerSz = idx = DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ;
23870+ sendSz = idx + length;
2386623871
23872+ } else
23873+ #endif
2386723874 sendSz = (int)(idx + length);
2386823875
2386923876 if (ssl->keys.encryptionOn)
2387023877 sendSz += MAX_MSG_EXTRA;
2387123878
23872- /* Set this in case CheckAvailableSize returns a WANT_WRITE so that state
23873- * is not advanced yet */
23874- ssl->options.buildingMsg = 1;
23875-
23876- if ((ret = CheckAvailableSize(ssl, sendSz)) == 0) {
23877- output = GetOutputBuffer(ssl);
23878-
23879- AddHeaders(output, length, certificate_status, ssl);
23880-
23881- output[idx++] = type;
23882-
23883- if (type == WOLFSSL_CSR2_OCSP_MULTI) {
23884- c32to24(length - (ENUM_LEN + OPAQUE24_LEN), output + idx);
23885- idx += OPAQUE24_LEN;
23886- }
23887-
23888- for (i = 0; i < count; i++) {
23889- c32to24(status[i].length, output + idx);
23890- idx += OPAQUE24_LEN;
23891-
23892- XMEMCPY(output + idx, status[i].buffer, status[i].length);
23893- idx += status[i].length;
23894- }
23895-
23896- if (IsEncryptionOn(ssl, 1)) {
23897- byte* input;
23898- int inputSz = (int)idx; /* build msg adds rec hdr */
23899- int recordHeaderSz = RECORD_HEADER_SZ;
23879+ output =(byte*)XMALLOC(sendSz, ssl->heap, DYNAMIC_TYPE_OCSP);
23880+ if (output == NULL)
23881+ return MEMORY_E;
2390023882
23901- if (ssl->options.dtls)
23902- recordHeaderSz += DTLS_RECORD_EXTRA;
23903- inputSz -= recordHeaderSz;
23904- input = (byte*)XMALLOC(inputSz, ssl->heap, DYNAMIC_TYPE_IN_BUFFER);
23905- if (input == NULL)
23906- return MEMORY_E;
23883+ AddHeaders(output, length, certificate_status, ssl);
2390723884
23908- XMEMCPY(input, output + recordHeaderSz, inputSz);
23909- #ifdef WOLFSSL_DTLS
23910- ret = DtlsMsgPoolSave(ssl, input, (word32)inputSz, certificate_status);
23911- #endif
23912- if (ret == 0)
23913- sendSz = BuildMessage(ssl, output, sendSz, input, inputSz,
23914- handshake, 1, 0, 0, CUR_ORDER);
23915- XFREE(input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER);
23885+ output[idx++] = type;
2391623886
23917- if (sendSz < 0)
23918- ret = sendSz;
23919- }
23920- else {
23921- #ifdef WOLFSSL_DTLS
23922- if (ret == 0 && IsDtlsNotSctpMode(ssl))
23923- ret = DtlsMsgPoolSave(ssl, output, (word32)sendSz, certificate_status);
23924- if (ret == 0 && ssl->options.dtls)
23925- DtlsSEQIncrement(ssl, CUR_ORDER);
23926- #endif
23927- ret = HashOutput(ssl, output, sendSz, 0);
23928- }
23887+ if (type == WOLFSSL_CSR2_OCSP_MULTI) {
23888+ c32to24(length - (ENUM_LEN + OPAQUE24_LEN), output + idx);
23889+ idx += OPAQUE24_LEN;
23890+ }
2392923891
23930- #if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA)
23931- if (ret == 0 && ssl->hsInfoOn)
23932- AddPacketName(ssl, "CertificateStatus");
23933- if (ret == 0 && ssl->toInfoOn) {
23934- ret = AddPacketInfo(ssl, "CertificateStatus", handshake, output,
23935- sendSz, WRITE_PROTO, 0, ssl->heap);
23936- if (ret != 0)
23937- return ret;
23938- }
23939- #endif
23892+ for (i = 0; i < count; i++) {
23893+ c32to24(status[i].length, output + idx);
23894+ idx += OPAQUE24_LEN;
2394023895
23941- if (ret == 0) {
23942- ssl->options.buildingMsg = 0;
23943- ssl->buffers.outputBuffer.length += sendSz;
23944- if (!ssl->options.groupMessages)
23945- ret = SendBuffered(ssl);
23946- }
23896+ XMEMCPY(output + idx, status[i].buffer, status[i].length);
23897+ idx += status[i].length;
2394723898 }
23899+ /* Send Message. Handled message fragmentation in the function if needed */
23900+ ret = SendHandshakeMsg(ssl, output, (sendSz - headerSz), certificate_status,
23901+ "Certificate Status");
23902+ XFREE(output, ssl->heap, DYNAMIC_TYPE_OCSP);
2394823903
2394923904 WOLFSSL_LEAVE("BuildCertificateStatus", ret);
2395023905 return ret;
0 commit comments