From abfcda8750a76d4a47630593c45c9c40399e261f Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Mon, 21 Aug 2023 17:31:31 +0200 Subject: [PATCH] Decode the key usage extension as LE not BE --- wolfcrypt/src/asn.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 6184f2e88..a4b92c17d 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -19247,14 +19247,24 @@ static int DecodeKeyUsage(const byte* input, word32 sz, DecodedCert* cert) #else ASNGetData dataASN[keyUsageASN_Length]; word32 idx = 0; + byte keyUsage[OPAQUE16_LEN]; + word32 keyUsageSz = sizeof(keyUsage); + int ret; WOLFSSL_ENTER("DecodeKeyUsage"); /* Clear dynamic data and set where to store extended key usage. */ XMEMSET(dataASN, 0, sizeof(dataASN)); - GetASN_Int16Bit(&dataASN[KEYUSAGEASN_IDX_STR], &cert->extKeyUsage); + GetASN_Buffer(&dataASN[KEYUSAGEASN_IDX_STR], keyUsage, &keyUsageSz); /* Parse key usage. */ - return GetASN_Items(keyUsageASN, dataASN, keyUsageASN_Length, 0, input, + ret = GetASN_Items(keyUsageASN, dataASN, keyUsageASN_Length, 0, input, &idx, sz); + if (ret == 0) { + /* Decode the bit string number as LE */ + cert->extKeyUsage = (word16)(keyUsage[0]); + if (keyUsageSz == 2) + cert->extKeyUsage |= (word16)(keyUsage[1] << 8); + } + return ret; #endif /* WOLFSSL_ASN_TEMPLATE */ }