Skip to content

Commit 2a075c5

Browse files
committed
Remove FIPS guards in GetASN_BitString length check
1 parent f12bb50 commit 2a075c5

4 files changed

Lines changed: 7 additions & 92 deletions

File tree

tests/api/test_asn.c

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -920,76 +920,3 @@ int test_wc_DecodeRsaPssParams(void)
920920
#endif /* WC_RSA_PSS && !NO_RSA && !NO_ASN */
921921
return EXPECT_RESULT();
922922
}
923-
924-
int test_wc_DecodeObjectId(void)
925-
{
926-
EXPECT_DECLS;
927-
928-
#if defined(HAVE_OID_DECODING) || defined(WOLFSSL_ASN_PRINT)
929-
{
930-
/* OID 1.2.840.113549.1.1.11 (sha256WithRSAEncryption)
931-
* DER encoding: 2a 86 48 86 f7 0d 01 01 0b
932-
* First byte 0x2a = 42 => arc0 = 42/40 = 1, arc1 = 42%40 = 2
933-
* Remaining arcs: 840, 113549, 1, 1, 11
934-
*/
935-
static const byte oid_sha256rsa[] = {
936-
0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b
937-
};
938-
word16 out[MAX_OID_SZ];
939-
word32 outSz;
940-
941-
/* Test 1: Normal decode */
942-
outSz = MAX_OID_SZ;
943-
ExpectIntEQ(DecodeObjectId(oid_sha256rsa, sizeof(oid_sha256rsa),
944-
out, &outSz), 0);
945-
ExpectIntEQ((int)outSz, 7);
946-
ExpectIntEQ(out[0], 1);
947-
ExpectIntEQ(out[1], 2);
948-
ExpectIntEQ(out[2], 840);
949-
ExpectIntEQ(out[3], (word16)113549); /* truncated to word16 */
950-
ExpectIntEQ(out[4], 1);
951-
ExpectIntEQ(out[5], 1);
952-
ExpectIntEQ(out[6], 11);
953-
954-
/* Test 2: NULL args */
955-
outSz = MAX_OID_SZ;
956-
ExpectIntEQ(DecodeObjectId(NULL, sizeof(oid_sha256rsa), out, &outSz),
957-
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
958-
ExpectIntEQ(DecodeObjectId(oid_sha256rsa, sizeof(oid_sha256rsa),
959-
out, NULL),
960-
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
961-
962-
/* Test 3 (Bug 1): outSz=1 must return BUFFER_E, not OOB write.
963-
* The first OID byte decodes into two arcs, so outSz must be >= 2. */
964-
outSz = 1;
965-
ExpectIntEQ(DecodeObjectId(oid_sha256rsa, sizeof(oid_sha256rsa),
966-
out, &outSz),
967-
WC_NO_ERR_TRACE(BUFFER_E));
968-
969-
/* Test 4: outSz=0 must also return BUFFER_E */
970-
outSz = 0;
971-
ExpectIntEQ(DecodeObjectId(oid_sha256rsa, sizeof(oid_sha256rsa),
972-
out, &outSz),
973-
WC_NO_ERR_TRACE(BUFFER_E));
974-
975-
/* Test 5: outSz=2 is enough for a single-byte OID (two arcs) */
976-
{
977-
static const byte oid_one_byte[] = { 0x2a }; /* 1.2 */
978-
outSz = 2;
979-
ExpectIntEQ(DecodeObjectId(oid_one_byte, sizeof(oid_one_byte),
980-
out, &outSz), 0);
981-
ExpectIntEQ((int)outSz, 2);
982-
ExpectIntEQ(out[0], 1);
983-
ExpectIntEQ(out[1], 2);
984-
}
985-
986-
/* Test 6: Buffer too small for later arcs */
987-
outSz = 3; /* only room for 3 arcs, but OID has 7 */
988-
ExpectIntEQ(DecodeObjectId(oid_sha256rsa, sizeof(oid_sha256rsa),
989-
out, &outSz),
990-
WC_NO_ERR_TRACE(BUFFER_E));
991-
}
992-
#endif /* HAVE_OID_DECODING || WOLFSSL_ASN_PRINT */
993-
994-
return EXPECT_RESULT();
995-
}

tests/api/test_asn.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ int test_GetSetShortInt(void);
2929
int test_wc_IndexSequenceOf(void);
3030
int test_wolfssl_local_MatchBaseName(void);
3131
int test_wc_DecodeRsaPssParams(void);
32-
int test_wc_DecodeObjectId(void);
3332

3433
#define TEST_ASN_DECLS \
3534
TEST_DECL_GROUP("asn", test_SetAsymKeyDer), \
3635
TEST_DECL_GROUP("asn", test_GetSetShortInt), \
3736
TEST_DECL_GROUP("asn", test_wc_IndexSequenceOf), \
3837
TEST_DECL_GROUP("asn", test_wolfssl_local_MatchBaseName), \
39-
TEST_DECL_GROUP("asn", test_wc_DecodeRsaPssParams), \
40-
TEST_DECL_GROUP("asn", test_wc_DecodeObjectId)
38+
TEST_DECL_GROUP("asn", test_wc_DecodeRsaPssParams)
4139

4240
#endif /* WOLFCRYPT_TEST_ASN_H */

wolfcrypt/src/asn.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,16 +1245,13 @@ static int GetASN_Integer(const byte* input, word32 idx, int length,
12451245
*/
12461246
int GetASN_BitString(const byte* input, word32 idx, int length)
12471247
{
1248-
#if (!defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)) || \
1249-
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
12501248
/* Check contents consist of one or more octets. */
12511249
if (length == 0) {
12521250
#ifdef WOLFSSL_DEBUG_ASN_TEMPLATE
12531251
WOLFSSL_MSG("Zero length BIT STRING not allowed");
12541252
#endif
12551253
return ASN_PARSE_E;
12561254
}
1257-
#endif
12581255
/* Ensure unused bits value is valid range. */
12591256
if (input[idx] > 7) {
12601257
#ifdef WOLFSSL_DEBUG_ASN_TEMPLATE
@@ -6808,18 +6805,15 @@ int DecodeObjectId(const byte* in, word32 inSz, word16* out, word32* outSz)
68086805
t = (t << 7) | (in[x] & 0x7F);
68096806
cnt++;
68106807
if (!(in[x] & 0x80)) {
6808+
if (y >= (int)*outSz) {
6809+
return BUFFER_E;
6810+
}
68116811
if (y == 0) {
6812-
if ((int)*outSz < 2) {
6813-
return BUFFER_E;
6814-
}
68156812
out[0] = (word16)(t / 40);
68166813
out[1] = (word16)(t % 40);
68176814
y = 2;
68186815
}
68196816
else {
6820-
if (y >= (int)*outSz) {
6821-
return BUFFER_E;
6822-
}
68236817
out[y++] = (word16)t;
68246818
}
68256819
t = 0; /* reset tmp */
@@ -6916,7 +6910,7 @@ static int DumpOID(const byte* oidData, word32 oidSz, word32 oid,
69166910
#ifdef HAVE_OID_DECODING
69176911
{
69186912
word16 decOid[MAX_OID_SZ];
6919-
word32 decOidSz = MAX_OID_SZ;
6913+
word32 decOidSz = sizeof(decOid);
69206914
/* Decode the OID into dotted form. */
69216915
ret = DecodeObjectId(oidData, oidSz, decOid, &decOidSz);
69226916
if (ret == 0) {
@@ -24063,7 +24057,7 @@ static int DecodeCertExtensions(DecodedCert* cert)
2406324057
if (isUnknownExt && (cert->unknownExtCallback != NULL ||
2406424058
cert->unknownExtCallbackEx != NULL)) {
2406524059
word16 decOid[MAX_OID_SZ];
24066-
word32 decOidSz = MAX_OID_SZ;
24060+
word32 decOidSz = sizeof(decOid);
2406724061
ret = DecodeObjectId(
2406824062
dataASN[CERTEXTASN_IDX_OID].data.oid.data,
2406924063
dataASN[CERTEXTASN_IDX_OID].data.oid.length,

wolfssl/wolfcrypt/asn.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,10 +2247,6 @@ typedef enum MimeStatus
22472247
#define SetAlgoID wc_SetAlgoID
22482248
#define SetAsymKeyDer wc_SetAsymKeyDer
22492249
#define CalcHashId wc_CalcHashId
2250-
#if defined(HAVE_OID_DECODING) || defined(WOLFSSL_ASN_PRINT) || \
2251-
defined(OPENSSL_ALL)
2252-
#define DecodeObjectId wc_DecodeObjectId
2253-
#endif
22542250
#if defined(WOLFSSL_AKID_NAME) && !defined(GetCAByAKID)
22552251
/* GetCAByAKID() has two implementations, a full implementation in
22562252
* src/ssl.c, and a dummy implementation in wolfcrypt/src/asn.c for
@@ -2488,7 +2484,7 @@ WOLFSSL_LOCAL word32 wc_oid_sum(const byte* input, int length);
24882484
#endif
24892485
#if defined(HAVE_OID_DECODING) || defined(WOLFSSL_ASN_PRINT) || \
24902486
defined(OPENSSL_ALL)
2491-
WOLFSSL_TEST_VIS int DecodeObjectId(const byte* in, word32 inSz,
2487+
WOLFSSL_LOCAL int DecodeObjectId(const byte* in, word32 inSz,
24922488
word16* out, word32* outSz);
24932489
#endif
24942490
WOLFSSL_LOCAL int GetASNObjectId(const byte* input, word32* inOutIdx, int* len,

0 commit comments

Comments
 (0)