@@ -23860,6 +23860,7 @@ static int BuildCertificateStatus(WOLFSSL* ssl, byte type, buffer* status,
2386023860 byte* output = NULL;
2386123861 word32 idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ;
2386223862 word32 length = ENUM_LEN;
23863+ word32 headerSz= idx;
2386323864 int sendSz = 0;
2386423865 int ret = 0;
2386523866 int i = 0;
@@ -23879,88 +23880,42 @@ static int BuildCertificateStatus(WOLFSSL* ssl, byte type, buffer* status,
2387923880 default:
2388023881 return 0;
2388123882 }
23883+ #ifdef WOLFSSL_DTLS
23884+ if (ssl->options.dtls) {
23885+ headerSz = idx = DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ;
23886+ sendSz = idx + length;
2388223887
23888+ } else
23889+ #endif
2388323890 sendSz = (int)(idx + length);
2388423891
2388523892 if (ssl->keys.encryptionOn)
2388623893 sendSz += MAX_MSG_EXTRA;
2388723894
23888- /* Set this in case CheckAvailableSize returns a WANT_WRITE so that state
23889- * is not advanced yet */
23890- ssl->options.buildingMsg = 1;
23891-
23892- if ((ret = CheckAvailableSize(ssl, sendSz)) == 0) {
23893- output = GetOutputBuffer(ssl);
23894-
23895- AddHeaders(output, length, certificate_status, ssl);
23896-
23897- output[idx++] = type;
23898-
23899- if (type == WOLFSSL_CSR2_OCSP_MULTI) {
23900- c32to24(length - (ENUM_LEN + OPAQUE24_LEN), output + idx);
23901- idx += OPAQUE24_LEN;
23902- }
23903-
23904- for (i = 0; i < count; i++) {
23905- c32to24(status[i].length, output + idx);
23906- idx += OPAQUE24_LEN;
23907-
23908- XMEMCPY(output + idx, status[i].buffer, status[i].length);
23909- idx += status[i].length;
23910- }
23911-
23912- if (IsEncryptionOn(ssl, 1)) {
23913- byte* input;
23914- int inputSz = (int)idx; /* build msg adds rec hdr */
23915- int recordHeaderSz = RECORD_HEADER_SZ;
23895+ output =(byte*)XMALLOC(sendSz, ssl->heap, DYNAMIC_TYPE_OCSP);
23896+ if (output == NULL)
23897+ return MEMORY_E;
2391623898
23917- if (ssl->options.dtls)
23918- recordHeaderSz += DTLS_RECORD_EXTRA;
23919- inputSz -= recordHeaderSz;
23920- input = (byte*)XMALLOC(inputSz, ssl->heap, DYNAMIC_TYPE_IN_BUFFER);
23921- if (input == NULL)
23922- return MEMORY_E;
23899+ AddHeaders(output, length, certificate_status, ssl);
2392323900
23924- XMEMCPY(input, output + recordHeaderSz, inputSz);
23925- #ifdef WOLFSSL_DTLS
23926- ret = DtlsMsgPoolSave(ssl, input, (word32)inputSz, certificate_status);
23927- #endif
23928- if (ret == 0)
23929- sendSz = BuildMessage(ssl, output, sendSz, input, inputSz,
23930- handshake, 1, 0, 0, CUR_ORDER);
23931- XFREE(input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER);
23901+ output[idx++] = type;
2393223902
23933- if (sendSz < 0)
23934- ret = sendSz;
23935- }
23936- else {
23937- #ifdef WOLFSSL_DTLS
23938- if (ret == 0 && IsDtlsNotSctpMode(ssl))
23939- ret = DtlsMsgPoolSave(ssl, output, (word32)sendSz, certificate_status);
23940- if (ret == 0 && ssl->options.dtls)
23941- DtlsSEQIncrement(ssl, CUR_ORDER);
23942- #endif
23943- ret = HashOutput(ssl, output, sendSz, 0);
23944- }
23903+ if (type == WOLFSSL_CSR2_OCSP_MULTI) {
23904+ c32to24(length - (ENUM_LEN + OPAQUE24_LEN), output + idx);
23905+ idx += OPAQUE24_LEN;
23906+ }
2394523907
23946- #if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA)
23947- if (ret == 0 && ssl->hsInfoOn)
23948- AddPacketName(ssl, "CertificateStatus");
23949- if (ret == 0 && ssl->toInfoOn) {
23950- ret = AddPacketInfo(ssl, "CertificateStatus", handshake, output,
23951- sendSz, WRITE_PROTO, 0, ssl->heap);
23952- if (ret != 0)
23953- return ret;
23954- }
23955- #endif
23908+ for (i = 0; i < count; i++) {
23909+ c32to24(status[i].length, output + idx);
23910+ idx += OPAQUE24_LEN;
2395623911
23957- if (ret == 0) {
23958- ssl->options.buildingMsg = 0;
23959- ssl->buffers.outputBuffer.length += sendSz;
23960- if (!ssl->options.groupMessages)
23961- ret = SendBuffered(ssl);
23962- }
23912+ XMEMCPY(output + idx, status[i].buffer, status[i].length);
23913+ idx += status[i].length;
2396323914 }
23915+ /* Send Message. Handled message fragmentation in the function if needed */
23916+ ret = SendHandshakeMsg(ssl, output, (sendSz - headerSz), certificate_status,
23917+ "Certificate Status");
23918+ XFREE(output, ssl->heap, DYNAMIC_TYPE_OCSP);
2396423919
2396523920 WOLFSSL_LEAVE("BuildCertificateStatus", ret);
2396623921 return ret;
0 commit comments