@@ -1577,6 +1577,60 @@ int test_DecodeCertExtensions_dup_certpol(void)
15771577 return EXPECT_RESULT ();
15781578}
15791579
1580+ /* RFC 5280 4.2.1.4 defines certificatePolicies as SEQUENCE SIZE (1..MAX) OF
1581+ * PolicyInformation, so an empty SEQUENCE must be rejected instead of being
1582+ * accepted as zero policies. */
1583+ int test_DecodeCertExtensions_empty_certpol (void )
1584+ {
1585+ EXPECT_DECLS ;
1586+ #if (defined(WOLFSSL_SEP ) || defined(WOLFSSL_CERT_EXT )) && \
1587+ !defined(NO_CERTS ) && !defined(NO_ASN )
1588+ /* certificatePolicies extnValue carrying no PolicyInformation. */
1589+ static const byte emptyPolicy [] = {
1590+ 0x30 , 0x00 /* certificatePolicies SEQUENCE */
1591+ };
1592+ DecodedCert cert ;
1593+ int isUnknown = 0 ;
1594+
1595+ wc_InitDecodedCert (& cert , emptyPolicy , (word32 )sizeof (emptyPolicy ), NULL );
1596+
1597+ ExpectIntEQ (DecodeExtensionType (emptyPolicy , (word32 )sizeof (emptyPolicy ),
1598+ CERT_POLICY_OID , 0 , & cert , & isUnknown ),
1599+ WC_NO_ERR_TRACE (ASN_PARSE_E ));
1600+
1601+ wc_FreeDecodedCert (& cert );
1602+ #endif
1603+ return EXPECT_RESULT ();
1604+ }
1605+
1606+ /* Trailing bytes after the last PolicyInformation must be rejected rather than
1607+ * skipped. */
1608+ int test_DecodeCertExtensions_certpol_trailing_junk (void )
1609+ {
1610+ EXPECT_DECLS ;
1611+ #if (defined(WOLFSSL_SEP ) || defined(WOLFSSL_CERT_EXT )) && \
1612+ !defined(NO_CERTS ) && !defined(NO_ASN )
1613+ /* One valid PolicyInformation followed by two bytes that are not one. */
1614+ static const byte trailingJunk [] = {
1615+ 0x30 , 0x09 , /* certificatePolicies SEQUENCE */
1616+ 0x30 , 0x05 , /* PolicyInformation SEQUENCE */
1617+ 0x06 , 0x03 , 0x2A , 0x03 , 0x04 ,/* policyIdentifier OID 1.2.3.4 */
1618+ 0x00 , 0x00 /* trailing junk */
1619+ };
1620+ DecodedCert cert ;
1621+ int isUnknown = 0 ;
1622+
1623+ wc_InitDecodedCert (& cert , trailingJunk , (word32 )sizeof (trailingJunk ), NULL );
1624+
1625+ ExpectIntEQ (DecodeExtensionType (trailingJunk , (word32 )sizeof (trailingJunk ),
1626+ CERT_POLICY_OID , 0 , & cert , & isUnknown ),
1627+ WC_NO_ERR_TRACE (ASN_PARSE_E ));
1628+
1629+ wc_FreeDecodedCert (& cert );
1630+ #endif
1631+ return EXPECT_RESULT ();
1632+ }
1633+
15801634int test_ParseCert_SM3wSM2_short_pubkey (void )
15811635{
15821636 EXPECT_DECLS ;
0 commit comments