Skip to content

Commit 39a6ace

Browse files
Remove WOLFSSL_CERT_REJECT_TRAILING. Reject certs with trailing data by default, allow opt-out via WOLFSSL_NO_ASN_STRICT.
1 parent 8cf7f09 commit 39a6ace

5 files changed

Lines changed: 12 additions & 23 deletions

File tree

.wolfssl_known_macro_extras

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,6 @@ WOLFSSL_CAAM_BLACK_KEY_AESCCM
747747
WOLFSSL_CAAM_BLACK_KEY_SM
748748
WOLFSSL_CAAM_NO_BLACK_KEY
749749
WOLFSSL_CALLBACKS
750-
WOLFSSL_CERT_REJECT_TRAILING
751750
WOLFSSL_CHECK_DESKEY
752751
WOLFSSL_CHECK_MEM_ZERO
753752
WOLFSSL_CHIBIOS

src/internal.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14307,19 +14307,17 @@ int CopyDecodedToX509(WOLFSSL_X509* x509, DecodedCert* dCert)
1430714307
/* if der contains original source buffer then store for potential
1430814308
* retrieval */
1430914309
if (dCert->source != NULL && dCert->maxIdx > 0) {
14310-
word32 derCertSz = dCert->maxIdx;
14311-
#ifdef WOLFSSL_CERT_REJECT_TRAILING
1431214310
/* Store only the certificate itself, bounded by the end of its outer
1431314311
* SEQUENCE (dCert->srcIdx), never any trailing bytes that may follow in
1431414312
* the source buffer. This keeps wolfSSL_i2d_X509 / wolfSSL_X509_get_der
1431514313
* / wolfSSL_X509_digest canonical - they operate on derCert - even on
1431614314
* builds/paths that do not reject trailing data (e.g.
1431714315
* WOLFSSL_NO_ASN_STRICT). It removes only bytes after the certificate,
1431814316
* so the signed certificate bytes are preserved verbatim. */
14317+
word32 derCertSz = dCert->maxIdx;
1431914318
if ((dCert->srcIdx > 0) && (dCert->srcIdx < derCertSz)) {
1432014319
derCertSz = dCert->srcIdx;
1432114320
}
14322-
#endif
1432314321
if (AllocDer(&x509->derCert, derCertSz, CERT_TYPE, x509->heap) == 0) {
1432414322
XMEMCPY(x509->derCert->buffer, dCert->source, derCertSz);
1432514323
}
@@ -14657,14 +14655,12 @@ int CopyDecodedAcertToX509(WOLFSSL_X509_ACERT* x509, DecodedAcert* dAcert)
1465714655
/* if der contains original source buffer then store for potential
1465814656
* retrieval */
1465914657
if (dAcert->source != NULL && dAcert->maxIdx > 0) {
14660-
word32 derCertSz = dAcert->maxIdx;
14661-
#ifdef WOLFSSL_CERT_REJECT_TRAILING
1466214658
/* Bound to the end of the attribute certificate's outer SEQUENCE so no
1466314659
* trailing bytes after it are ever re-emitted by i2d / get_der. */
14660+
word32 derCertSz = dAcert->maxIdx;
1466414661
if ((dAcert->srcIdx > 0) && (dAcert->srcIdx < derCertSz)) {
1466514662
derCertSz = dAcert->srcIdx;
1466614663
}
14667-
#endif
1466814664
if (AllocDer(&x509->derCert, derCertSz, CERT_TYPE, x509->heap) == 0) {
1466914665
XMEMCPY(x509->derCert->buffer, dAcert->source, derCertSz);
1467014666
}

src/x509.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6179,10 +6179,9 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
61796179
InitDecodedCert(cert, der->buffer, der->length, NULL);
61806180
/* For TRUSTED_CERT_TYPE the DER buffer holds the certificate
61816181
* followed by auxiliary trust info. ParseCertRelative() recognizes
6182-
* the type: it parses only the certificate and treats it as
6183-
* CERT_TYPE for verification (and, under WOLFSSL_CERT_REJECT_TRAILING,
6184-
* permits the trailing aux data). The DER is trimmed to the
6185-
* certificate below. */
6182+
* the type: it parses only the certificate, permits the trailing
6183+
* aux data, and treats it as CERT_TYPE for verification. The DER is
6184+
* trimmed to the certificate below. */
61866185
ret = ParseCertRelative(cert, type, 0, NULL, NULL);
61876186
if (ret == 0) {
61886187
/* For TRUSTED_CERT_TYPE, truncate the DER buffer to exclude

wolfcrypt/src/asn.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22229,7 +22229,7 @@ static int DecodeCertInternal(DecodedCert* cert, int verify, int* criticalExt,
2222922229
}
2223022230
}
2223122231

22232-
#ifdef WOLFSSL_CERT_REJECT_TRAILING
22232+
#ifndef WOLFSSL_NO_ASN_STRICT
2223322233
/* Reject trailing data after the certificate's outer SEQUENCE.
2223422234
*
2223522235
* The template parser (GetASN_Items) only verifies that constructed items
@@ -22256,7 +22256,7 @@ static int DecodeCertInternal(DecodedCert* cert, int verify, int* criticalExt,
2225622256
WOLFSSL_ERROR_VERBOSE(ASN_PARSE_E);
2225722257
ret = ASN_PARSE_E;
2225822258
}
22259-
#endif /* WOLFSSL_CERT_REJECT_TRAILING */
22259+
#endif /* !WOLFSSL_NO_ASN_STRICT */
2226022260

2226122261
if ((ret == 0) && (!done) && (badDate != 0)) {
2226222262
/* Parsed whole certificate fine but return any date errors. */
@@ -23479,16 +23479,13 @@ int ParseCertRelative(DecodedCert* cert, int type, int verify, void* cm,
2347923479
}
2348023480

2348123481
/* TRUSTED CERTIFICATE blobs (RFC/OpenSSL "TRUSTED CERTIFICATE") carry
23482-
* auxiliary trust data after the certificate. Parse only the certificate
23483-
* prefix and treat it as a normal certificate for all verification /
23484-
* path-length logic below. Doing this here (rather than in a single caller)
23485-
* means any caller of wc_ParseCert()/ParseCertRelative() that passes
23486-
* TRUSTED_CERT_TYPE gets the correct, consistent behavior. */
23482+
* auxiliary trust data after the certificate. Permit that trailing data and
23483+
* parse only the certificate prefix; treat it as a normal certificate for
23484+
* all verification/path-length logic below. Doing this here (rather than in
23485+
* a single caller) means any caller of wc_ParseCert()/ParseCertRelative()
23486+
* that passes TRUSTED_CERT_TYPE gets the correct, consistent behavior. */
2348723487
if (type == TRUSTED_CERT_TYPE) {
23488-
#ifdef WOLFSSL_CERT_REJECT_TRAILING
23489-
/* Opt out of the trailing-data rejection for the aux trust info. */
2349023488
cert->allowTrailing = 1;
23491-
#endif
2349223489
type = CERT_TYPE;
2349323490
}
2349423491

wolfssl/wolfcrypt/asn.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,12 +2072,10 @@ struct DecodedCert {
20722072

20732073
/* Option Bits */
20742074
WC_BITFIELD subjectCNStored:1; /* have we saved a copy we own */
2075-
#ifdef WOLFSSL_CERT_REJECT_TRAILING
20762075
WC_BITFIELD allowTrailing:1; /* permit data after the cert's outer
20772076
* SEQUENCE. Used internally for the
20782077
* TRUSTED CERTIFICATE auxiliary trust
20792078
* info. */
2080-
#endif
20812079
WC_BITFIELD extSubjKeyIdSet:1; /* Set when the SKID was read from cert */
20822080
WC_BITFIELD extAuthKeyIdSet:1; /* Set when the AKID was read from cert */
20832081
#ifndef IGNORE_NAME_CONSTRAINTS

0 commit comments

Comments
 (0)