@@ -1495,6 +1495,58 @@ int test_DecodeAltNames_length_underflow(void)
14951495 return EXPECT_RESULT ();
14961496}
14971497
1498+ int test_ParseCert_SM3wSM2_short_pubkey (void )
1499+ {
1500+ EXPECT_DECLS ;
1501+
1502+ #if !defined(NO_CERTS ) && !defined(NO_ASN ) && !defined(NO_SKID ) && \
1503+ defined(WOLFSSL_SM2 ) && defined(WOLFSSL_SM3 )
1504+ /* Malformed cert: the SubjectPublicKeyInfo is an id-ecPublicKey key on the
1505+ * sm2p256v1 curve with only a 4-byte public key body, whole SPKI is 30
1506+ * bytes with no subjectKeyIdentifier extension and SKID derived from the
1507+ * key. */
1508+ static const byte sm2ShortKeyCert [] = {
1509+ 0x30 , 0x81 , 0xa7 ,
1510+ 0x30 , 0x56 ,
1511+ 0xa0 , 0x03 , 0x02 , 0x01 , 0x02 ,
1512+ 0x02 , 0x01 , 0x01 ,
1513+ 0x30 , 0x0a , 0x06 , 0x08 ,
1514+ 0x2a , 0x81 , 0x1c , 0xcf , 0x55 , 0x01 , 0x83 , 0x75 ,
1515+ 0x30 , 0x00 ,
1516+ 0x30 , 0x1e ,
1517+ 0x17 , 0x0d , 0x32 , 0x35 , 0x31 , 0x31 , 0x31 , 0x33 ,
1518+ 0x32 , 0x30 , 0x34 , 0x31 , 0x32 , 0x31 , 0x5a ,
1519+ 0x17 , 0x0d , 0x32 , 0x38 , 0x30 , 0x38 , 0x30 , 0x39 ,
1520+ 0x32 , 0x30 , 0x34 , 0x31 , 0x32 , 0x31 , 0x5a ,
1521+ 0x30 , 0x00 ,
1522+ 0x30 , 0x1c ,
1523+ 0x30 , 0x13 ,
1524+ 0x06 , 0x07 , 0x2a , 0x86 , 0x48 , 0xce , 0x3d , 0x02 , 0x01 ,
1525+ 0x06 , 0x08 , 0x2a , 0x81 , 0x1c , 0xcf , 0x55 , 0x01 , 0x82 , 0x2d ,
1526+ 0x03 , 0x05 , 0x00 , 0x04 , 0x11 , 0x22 , 0x33 ,
1527+ 0x30 , 0x0a , 0x06 , 0x08 ,
1528+ 0x2a , 0x81 , 0x1c , 0xcf , 0x55 , 0x01 , 0x83 , 0x75 ,
1529+ 0x03 , 0x41 , 0x00 ,
1530+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
1531+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
1532+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
1533+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
1534+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
1535+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
1536+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
1537+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00
1538+ };
1539+ DecodedCert cert ;
1540+
1541+ wc_InitDecodedCert (& cert , sm2ShortKeyCert , (word32 )sizeof (sm2ShortKeyCert ),
1542+ NULL );
1543+ ExpectIntEQ (wc_ParseCert (& cert , CERT_TYPE , NO_VERIFY , NULL ),
1544+ WC_NO_ERR_TRACE (BUFFER_E ));
1545+ wc_FreeDecodedCert (& cert );
1546+ #endif
1547+ return EXPECT_RESULT ();
1548+ }
1549+
14981550int test_SerialNumber0_RootCA (void )
14991551{
15001552 EXPECT_DECLS ;
0 commit comments