@@ -39147,6 +39147,9 @@ static int ParseCRL_Extensions(DecodedCRL* dcrl, const byte* buf, word32 idx,
39147
39147
{
39148
39148
DECL_ASNGETDATA(dataASN, certExtASN_Length);
39149
39149
int ret = 0;
39150
+ /* Track if we've seen these extensions already */
39151
+ word32 seenAuthKey = 0;
39152
+ word32 seenCrlNum = 0;
39150
39153
39151
39154
ALLOC_ASNGETDATA(dataASN, certExtASN_Length, ret, dcrl->heap);
39152
39155
@@ -39168,47 +39171,64 @@ static int ParseCRL_Extensions(DecodedCRL* dcrl, const byte* buf, word32 idx,
39168
39171
/* Length of extension data. */
39169
39172
int length = (int)dataASN[CERTEXTASN_IDX_VAL].length;
39170
39173
39171
- if (oid == AUTH_KEY_OID) {
39172
- #ifndef NO_SKID
39173
- /* Parse Authority Key Id extension.
39174
- * idx is at start of OCTET_STRING data. */
39175
- ret = ParseCRL_AuthKeyIdExt(buf + idx, length, dcrl);
39176
- if (ret != 0) {
39177
- WOLFSSL_MSG("\tcouldn't parse AuthKeyId extension");
39178
- }
39179
- #endif
39174
+ /* Check for duplicate extension */
39175
+ if ((oid == AUTH_KEY_OID && seenAuthKey) ||
39176
+ (oid == CRL_NUMBER_OID && seenCrlNum)) {
39177
+ WOLFSSL_MSG("Duplicate CRL extension found");
39178
+ ret = ASN_PARSE_E;
39180
39179
}
39181
- else if (oid == CRL_NUMBER_OID) {
39182
- #ifdef WOLFSSL_SMALL_STACK
39183
- mp_int* m = (mp_int*)XMALLOC(sizeof(*m), NULL,
39184
- DYNAMIC_TYPE_BIGINT);
39185
- if (m == NULL) {
39186
- ret = MEMORY_E;
39187
- }
39188
- #else
39189
- mp_int m[1];
39190
- #endif
39191
39180
39192
- if (ret == 0) {
39193
- if (mp_init(m) != MP_OKAY) {
39194
- ret = MP_INIT_E;
39181
+ /* Track this extension if no duplicate found */
39182
+ if (ret == 0) {
39183
+ if (oid == AUTH_KEY_OID)
39184
+ seenAuthKey = 1;
39185
+ else if (oid == CRL_NUMBER_OID)
39186
+ seenCrlNum = 1;
39187
+ }
39188
+
39189
+ if (ret == 0) {
39190
+ if (oid == AUTH_KEY_OID) {
39191
+ #ifndef NO_SKID
39192
+ /* Parse Authority Key Id extension.
39193
+ * idx is at start of OCTET_STRING data. */
39194
+ ret = ParseCRL_AuthKeyIdExt(buf + idx, length, dcrl);
39195
+ if (ret != 0) {
39196
+ WOLFSSL_MSG("\tcouldn't parse AuthKeyId extension");
39195
39197
}
39198
+ #endif
39196
39199
}
39197
- if (ret == 0) {
39198
- ret = GetInt(m, buf, &idx, maxIdx);
39199
- }
39200
- if (ret == 0) {
39201
- dcrl->crlNumber = (int)m->dp[0];
39202
- }
39200
+ else if (oid == CRL_NUMBER_OID) {
39201
+ #ifdef WOLFSSL_SMALL_STACK
39202
+ mp_int* m = (mp_int*)XMALLOC(sizeof(*m), NULL,
39203
+ DYNAMIC_TYPE_BIGINT);
39204
+ if (m == NULL) {
39205
+ ret = MEMORY_E;
39206
+ }
39207
+ #else
39208
+ mp_int m[1];
39209
+ #endif
39203
39210
39204
- mp_free(m);
39205
- #ifdef WOLFSSL_SMALL_STACK
39206
- XFREE(m, NULL, DYNAMIC_TYPE_BIGINT);
39207
- #endif
39211
+ if (ret == 0) {
39212
+ if (mp_init(m) != MP_OKAY) {
39213
+ ret = MP_INIT_E;
39214
+ }
39215
+ }
39216
+ if (ret == 0) {
39217
+ ret = GetInt(m, buf, &idx, maxIdx);
39218
+ }
39219
+ if (ret == 0) {
39220
+ dcrl->crlNumber = (int)m->dp[0];
39221
+ }
39222
+
39223
+ mp_free(m);
39224
+ #ifdef WOLFSSL_SMALL_STACK
39225
+ XFREE(m, NULL, DYNAMIC_TYPE_BIGINT);
39226
+ #endif
39227
+ }
39228
+ /* TODO: check criticality */
39229
+ /* Move index on to next extension. */
39230
+ idx += (word32)length;
39208
39231
}
39209
- /* TODO: check criticality */
39210
- /* Move index on to next extension. */
39211
- idx += (word32)length;
39212
39232
}
39213
39233
}
39214
39234
0 commit comments