Skip to content

Commit 2a11654

Browse files
add parsing over optional PKCS8 attributes
1 parent 1c8767b commit 2a11654

4 files changed

Lines changed: 15 additions & 2 deletions

File tree

certs/ca-key-pkcs8-attribute.der

1.21 KB
Binary file not shown.

certs/include.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ EXTRA_DIST += \
66
certs/ca-cert-chain.der \
77
certs/ca-cert.pem \
88
certs/ca-key.pem \
9+
certs/ca-key-pkcs8-attribute.der \
910
certs/client-cert.pem \
1011
certs/client-keyEnc.pem \
1112
certs/client-key.pem \

tests/api.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74549,6 +74549,7 @@ static int test_wc_GetPkcs8TraditionalOffset(void)
7454974549
int derSz = 0;
7455074550
word32 inOutIdx;
7455174551
const char* path = "./certs/server-keyPkcs8.der";
74552+
const char* pathAttributes = "./certs/ca-key-pkcs8-attribute.der";
7455274553
XFILE file = XBADFILE;
7455374554
byte der[2048];
7455474555

@@ -74577,6 +74578,16 @@ static int test_wc_GetPkcs8TraditionalOffset(void)
7457774578
inOutIdx = 0;
7457874579
ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
7457974580
WC_NO_ERR_TRACE(ASN_PARSE_E));
74581+
74582+
/* test parsing with attributes */
74583+
ExpectTrue((file = XFOPEN(pathAttributes, "rb")) != XBADFILE);
74584+
ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), file), 0);
74585+
if (file != XBADFILE)
74586+
XFCLOSE(file);
74587+
74588+
inOutIdx = 0;
74589+
ExpectIntGT(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx,
74590+
(word32)derSz), 0);
7458074591
#endif /* NO_ASN */
7458174592
return EXPECT_RESULT();
7458274593
}

wolfcrypt/src/asn.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6882,8 +6882,9 @@ static const ASNItem pkcs8KeyASN[] = {
68826882
/* PKEY_ALGO_PARAM_SEQ */ { 2, ASN_SEQUENCE, 1, 0, 1 },
68836883
#endif
68846884
/* PKEY_DATA */ { 1, ASN_OCTET_STRING, 0, 0, 0 },
6885-
/* attributes [0] Attributes OPTIONAL */
6886-
/* [[2: publicKey [1] PublicKey OPTIONAL ]] */
6885+
/* OPTIONAL Attributes IMPLICIT [0] */
6886+
{ 1, ASN_CONTEXT_SPECIFIC | 0, 1, 0, 1 },
6887+
/* [[2: publicKey [1] PublicKey OPTIONAL ]] */
68876888
};
68886889
enum {
68896890
PKCS8KEYASN_IDX_SEQ = 0,

0 commit comments

Comments
 (0)