Skip to content

Commit 8bff24c

Browse files
Allow SubjectInfoAccess extension without id-ad-caRepository entry
Previously parsing a SubjectInfoAccess certificate containing a SubjectInfoAccess extension that did not contain an id-ad-caRepository resulted in an error.
1 parent d00a137 commit 8bff24c

6 files changed

Lines changed: 164 additions & 18 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ linuxkm/patches/src
249249
linuxkm/libwolfssl-user-build
250250
linuxkm/linuxkm-fips-hash
251251
*.nds
252+
/certs/.rnd
252253

253254
# Generated during FreeBSD kernel module build.
254255
bsdkm/export_syms

certs/renewcerts.sh

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
# aia/ca-issuers-cert.pem
3939
# aia/multi-aia-cert.pem
4040
# aia/overflow-aia-cert.pem
41+
# sia/timestamping-sia-cert.pem
4142
# updates the following crls:
4243
# crl/cliCrl.pem
4344
# crl/crl.pem
@@ -354,6 +355,31 @@ run_renewcerts(){
354355
echo "End of section"
355356
echo "---------------------------------------------------------------------"
356357
############################################################
358+
########## update SIA test certs ###########################
359+
############################################################
360+
echo "Updating SIA test certs"
361+
echo ""
362+
mkdir -p sia
363+
364+
# Cert with a subjectInfoAccess extension that does not contain an
365+
# id-ad-caRepository entry. RFC 5280 4.2.2.2 only requires the SIA
366+
# sequence be non-empty; it does not mandate any specific access method.
367+
echo "Updating sia/timestamping-sia-cert.pem"
368+
echo ""
369+
openssl req -new -newkey rsa:2048 -nodes -keyout sia/timestamping-sia-key.pem -subj "/CN=wolfssl-sia-timestamping-test" -out sia/timestamping-sia-cert.csr
370+
check_result $? "Step SIA-1"
371+
372+
openssl x509 -req -in sia/timestamping-sia-cert.csr -days 3650 -extfile wolfssl.cnf -extensions sia_timestamping -signkey sia/timestamping-sia-key.pem -out sia/timestamping-sia-cert.pem
373+
check_result $? "Step SIA-2"
374+
rm sia/timestamping-sia-cert.csr
375+
376+
openssl x509 -in sia/timestamping-sia-cert.pem -text > tmp.pem
377+
check_result $? "Step SIA-3"
378+
mv tmp.pem sia/timestamping-sia-cert.pem
379+
rm sia/timestamping-sia-key.pem
380+
echo "End of section"
381+
echo "---------------------------------------------------------------------"
382+
############################################################
357383
########## update the self-signed ca-cert-chain.der ########
358384
############################################################
359385
echo "Updating ca-cert-chain.der"
@@ -1048,8 +1074,8 @@ EOF
10481074
##################### THE EXECUTABLE BODY #####################################
10491075
###############################################################################
10501076

1051-
#start in root.
1052-
cd ../ || exit 1
1077+
#start in root, regardless of the caller's working directory.
1078+
cd "$(dirname "${BASH_SOURCE[0]}")/.." || exit 1
10531079

10541080
if [ ! -z "$1" ]; then
10551081
echo "No arguments expected"
@@ -1065,6 +1091,7 @@ touch certs/.rnd || exit 1
10651091

10661092
run_renewcerts
10671093
cd ../ || exit 1
1068-
rm ./certs/wolfssl.cnf
1094+
rm -f ./certs/wolfssl.cnf
1095+
rm -f certs/.rnd
10691096

10701097
exit 0

certs/renewcerts/wolfssl.cnf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,15 @@ OCSP;URI.6=http://127.0.0.1:22226
360360
OCSP;URI.7=http://127.0.0.1:22227
361361
OCSP;URI.8=http://127.0.0.1:22228
362362

363+
# SIA test cert: subjectInfoAccess present but without id-ad-caRepository.
364+
[ sia_timestamping ]
365+
subjectKeyIdentifier=hash
366+
basicConstraints=CA:false
367+
subjectInfoAccess=@sia_timestamping_info
368+
369+
[ sia_timestamping_info ]
370+
timeStamping;URI.0=http://example.com/tsa
371+
363372
#tsa default
364373
[ tsa ]
365374
default_tsa = tsa_config1
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
Certificate:
2+
Data:
3+
Version: 3 (0x2)
4+
Serial Number:
5+
74:60:0d:21:cd:a1:31:68:9f:54:85:93:7e:2e:80:e5:4f:c3:2a:1a
6+
Signature Algorithm: sha256WithRSAEncryption
7+
Issuer: CN=wolfssl-sia-timestamping-test
8+
Validity
9+
Not Before: Apr 30 19:19:06 2026 GMT
10+
Not After : Apr 27 19:19:06 2036 GMT
11+
Subject: CN=wolfssl-sia-timestamping-test
12+
Subject Public Key Info:
13+
Public Key Algorithm: rsaEncryption
14+
Public-Key: (2048 bit)
15+
Modulus:
16+
00:a1:60:e1:c3:1b:0d:ff:21:da:6b:a7:eb:36:bb:
17+
cb:b6:6f:ed:29:91:f5:46:23:0d:a2:f7:7e:8f:05:
18+
c8:1a:df:e7:74:cf:a6:1f:64:8d:21:5c:14:41:4f:
19+
a7:c2:67:46:53:e3:fd:11:cc:db:55:12:42:4e:37:
20+
d8:2f:22:5c:94:83:bc:7c:0a:c4:e0:86:61:17:e1:
21+
d0:f5:36:97:40:77:f4:a4:a7:47:94:34:73:6f:06:
22+
1f:fa:43:ff:25:57:3f:65:8b:fb:26:40:bc:a5:3e:
23+
ef:04:59:a6:4c:1a:a0:2c:43:f6:b2:2b:11:e3:09:
24+
d5:c5:a0:59:5d:97:12:ae:c7:b9:03:b8:57:d3:21:
25+
45:e2:07:e3:66:60:45:d6:b2:ca:a5:06:75:85:ef:
26+
c9:fc:9b:c9:3e:8a:f9:27:0b:93:d1:f9:57:90:d4:
27+
1c:b3:6e:40:8a:c4:c9:05:16:7c:aa:eb:c9:09:7a:
28+
67:3a:cf:6b:b4:ea:19:e4:70:47:23:5b:a7:e4:eb:
29+
6c:25:07:a6:46:03:4f:10:18:12:aa:c0:15:9b:6f:
30+
79:bb:0c:d0:7b:9a:66:e8:71:b0:c9:5c:0d:bb:89:
31+
4b:1c:36:e0:ce:6e:aa:e4:1b:07:b7:f6:80:c0:07:
32+
3b:16:a5:22:b8:20:4d:03:2e:ca:cc:54:f5:06:cf:
33+
70:71
34+
Exponent: 65537 (0x10001)
35+
X509v3 extensions:
36+
X509v3 Subject Key Identifier:
37+
F5:6A:74:86:5F:56:54:64:F6:29:D0:5F:38:74:04:C1:13:81:61:EE
38+
X509v3 Basic Constraints:
39+
CA:FALSE
40+
Subject Information Access:
41+
Time Stamping - URI:http://example.com/tsa
42+
Signature Algorithm: sha256WithRSAEncryption
43+
Signature Value:
44+
99:4f:71:53:6a:44:f1:cc:61:86:5d:11:70:1a:c4:1c:e7:42:
45+
cc:15:eb:6c:5a:1f:cf:ab:2a:a6:61:10:41:e7:96:21:c8:e4:
46+
06:78:ef:0c:49:e8:0a:2a:7b:51:a9:76:29:fb:2f:51:0a:b0:
47+
b7:a6:bb:08:cd:44:14:7f:e1:2d:fe:84:7d:72:87:d6:32:06:
48+
96:58:2b:98:cf:67:02:53:35:01:81:7d:e5:45:87:8b:db:3f:
49+
90:e6:a8:45:19:3d:55:fd:9d:cf:d9:51:2a:b0:e2:60:a7:f7:
50+
c9:e8:80:7e:98:20:10:74:78:e0:fb:45:e5:a1:e4:e8:2d:73:
51+
e2:fe:07:57:aa:6a:42:9d:00:03:bf:99:51:6a:e1:2d:5a:7b:
52+
24:2d:f5:07:05:2e:63:54:86:1b:2e:dc:77:10:42:80:9e:c6:
53+
ef:2e:c3:3f:e9:99:03:9f:d4:2a:21:69:47:04:bb:b5:b0:e0:
54+
79:4d:0c:f8:e4:42:58:90:95:25:6b:d9:1f:76:10:9d:b3:2d:
55+
da:13:d3:55:af:b3:0c:8a:db:02:c5:76:d5:92:c1:a6:3e:fe:
56+
0a:14:ef:5d:a7:72:4f:4f:3a:ae:0b:75:7d:e8:99:c4:82:d6:
57+
ad:ce:4e:4f:86:e6:5f:2e:ea:e2:63:3a:0a:bb:47:8e:a1:da:
58+
b5:45:5c:0f
59+
-----BEGIN CERTIFICATE-----
60+
MIIDPjCCAiagAwIBAgIUdGANIc2hMWifVIWTfi6A5U/DKhowDQYJKoZIhvcNAQEL
61+
BQAwKDEmMCQGA1UEAwwdd29sZnNzbC1zaWEtdGltZXN0YW1waW5nLXRlc3QwHhcN
62+
MjYwNDMwMTkxOTA2WhcNMzYwNDI3MTkxOTA2WjAoMSYwJAYDVQQDDB13b2xmc3Ns
63+
LXNpYS10aW1lc3RhbXBpbmctdGVzdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC
64+
AQoCggEBAKFg4cMbDf8h2mun6za7y7Zv7SmR9UYjDaL3fo8FyBrf53TPph9kjSFc
65+
FEFPp8JnRlPj/RHM21USQk432C8iXJSDvHwKxOCGYRfh0PU2l0B39KSnR5Q0c28G
66+
H/pD/yVXP2WL+yZAvKU+7wRZpkwaoCxD9rIrEeMJ1cWgWV2XEq7HuQO4V9MhReIH
67+
42ZgRdayyqUGdYXvyfybyT6K+ScLk9H5V5DUHLNuQIrEyQUWfKrryQl6ZzrPa7Tq
68+
GeRwRyNbp+TrbCUHpkYDTxAYEqrAFZtvebsM0HuaZuhxsMlcDbuJSxw24M5uquQb
69+
B7f2gMAHOxalIrggTQMuysxU9QbPcHECAwEAAaNgMF4wHQYDVR0OBBYEFPVqdIZf
70+
VlRk9inQXzh0BMETgWHuMAkGA1UdEwQCMAAwMgYIKwYBBQUHAQsEJjAkMCIGCCsG
71+
AQUFBwMIhhZodHRwOi8vZXhhbXBsZS5jb20vdHNhMA0GCSqGSIb3DQEBCwUAA4IB
72+
AQCZT3FTakTxzGGGXRFwGsQc50LMFetsWh/PqyqmYRBB55YhyOQGeO8MSegKKntR
73+
qXYp+y9RCrC3prsIzUQUf+Et/oR9cofWMgaWWCuYz2cCUzUBgX3lRYeL2z+Q5qhF
74+
GT1V/Z3P2VEqsOJgp/fJ6IB+mCAQdHjg+0XloeToLXPi/gdXqmpCnQADv5lRauEt
75+
WnskLfUHBS5jVIYbLtx3EEKAnsbvLsM/6ZkDn9QqIWlHBLu1sOB5TQz45EJYkJUl
76+
a9kfdhCdsy3aE9NVr7MMitsCxXbVksGmPv4KFO9dp3JPTzquC3V96JnEgtatzk5P
77+
huZfLuriYzoKu0eOodq1RVwP
78+
-----END CERTIFICATE-----

tests/api.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21215,6 +21215,44 @@ static int test_wolfSSL_X509_get1_aia_overflow(void)
2121521215
return EXPECT_RESULT();
2121621216
}
2121721217

21218+
/* Parse a certificate whose subjectInfoAccess extension is present but does
21219+
* not contain an id-ad-caRepository entry. RFC 5280 4.2.2.2 only requires
21220+
* the SIA sequence be non-empty; previously wolfSSL incorrectly rejected
21221+
* such certificates with ASN_PARSE_E. */
21222+
static int test_wolfSSL_SubjectInfoAccess_no_caRepository(void)
21223+
{
21224+
EXPECT_DECLS;
21225+
#if defined(WOLFSSL_SUBJ_INFO_ACC) && !defined(NO_RSA) && \
21226+
!defined(NO_FILESYSTEM) && defined(WOLFSSL_PEM_TO_DER)
21227+
const char* siaCert = "./certs/sia/timestamping-sia-cert.pem";
21228+
byte* pemBuf = NULL;
21229+
size_t pemSz = 0;
21230+
byte* derBuf = NULL;
21231+
word32 derSz = 0;
21232+
DecodedCert cert;
21233+
21234+
ExpectIntEQ(load_file(siaCert, &pemBuf, &pemSz), 0);
21235+
derSz = (word32)pemSz; /* DER will be smaller than PEM */
21236+
ExpectNotNull(derBuf = (byte*)malloc(derSz));
21237+
ExpectIntGE(wc_CertPemToDer(pemBuf, (int)pemSz, derBuf, (int)derSz,
21238+
CERT_TYPE), 0);
21239+
21240+
wc_InitDecodedCert(&cert, derBuf, derSz, NULL);
21241+
ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL), 0);
21242+
21243+
/* SIA was present and decoded successfully. */
21244+
ExpectIntEQ(cert.extSubjInfoAccSet, 1);
21245+
/* No id-ad-caRepository entry exists in this cert's SIA. */
21246+
ExpectNull(cert.extSubjInfoAccCaRepo);
21247+
ExpectIntEQ((int)cert.extSubjInfoAccCaRepoSz, 0);
21248+
21249+
wc_FreeDecodedCert(&cert);
21250+
free(derBuf);
21251+
XFREE(pemBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
21252+
#endif
21253+
return EXPECT_RESULT();
21254+
}
21255+
2121821256
static int test_no_op_functions(void)
2121921257
{
2122021258
EXPECT_DECLS;
@@ -37318,6 +37356,7 @@ TEST_CASE testCases[] = {
3731837356
TEST_DECL(test_wolfSSL_X509_get1_ca_issuers),
3731937357
TEST_DECL(test_wolfSSL_X509_get1_aia_multi),
3732037358
TEST_DECL(test_wolfSSL_X509_get1_aia_overflow),
37359+
TEST_DECL(test_wolfSSL_SubjectInfoAccess_no_caRepository),
3732137360

3732237361
TEST_DECL(test_wolfSSL_PEM_read),
3732337362

wolfcrypt/src/asn.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19775,7 +19775,6 @@ static int DecodeSubjInfoAcc(const byte* input, word32 sz, DecodedCert* cert)
1977519775
{
1977619776
word32 idx = 0;
1977719777
int length = 0;
19778-
int ret = 0;
1977919778

1978019779
WOLFSSL_ENTER("DecodeSubjInfoAcc");
1978119780

@@ -19796,12 +19795,11 @@ static int DecodeSubjInfoAcc(const byte* input, word32 sz, DecodedCert* cert)
1979619795
return ASN_PARSE_E;
1979719796
}
1979819797

19799-
/* Per fpkx-x509-cert-profile-common... section 5.3.
19800-
* [The] subjectInfoAccess extension must contain at least one
19801-
* instance of the id-ad-caRepository access method containing a
19802-
* publicly accessible HTTP URI which returns as certs-only
19803-
* CMS.
19804-
*/
19798+
/* RFC 5280 specifies that at least one entry must be present but does not
19799+
* specify any particular OID must be present. For certificates following
19800+
* fpki-x509-cert-profile-common, we extract the id-ad-caRepository caRepo
19801+
* entry to cert->extSubjInfoAccCaRepo / cert->extSubjInfoAccCaRepoSz for
19802+
* convenient user access. */
1980519803

1980619804
while (idx < (word32)sz) {
1980719805
word32 oid = 0;
@@ -19831,14 +19829,8 @@ static int DecodeSubjInfoAcc(const byte* input, word32 sz, DecodedCert* cert)
1983119829
idx += (word32)length;
1983219830
}
1983319831

19834-
if (cert->extSubjInfoAccCaRepo == NULL ||
19835-
cert->extSubjInfoAccCaRepoSz == 0) {
19836-
WOLFSSL_MSG("SubjectInfoAccess missing an URL.");
19837-
ret = ASN_PARSE_E;
19838-
}
19839-
19840-
WOLFSSL_LEAVE("DecodeSubjInfoAcc", ret);
19841-
return ret;
19832+
WOLFSSL_LEAVE("DecodeSubjInfoAcc", 0);
19833+
return 0;
1984219834
}
1984319835
#endif /* WOLFSSL_SUBJ_INFO_ACC */
1984419836

0 commit comments

Comments
 (0)