Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions certs/crl/extra-crls/akid_zero_octets.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Certificate Revocation List (CRL):
Version 2 (0x1)
Signature Algorithm: sha256WithRSAEncryption
Issuer: CN=wolfSSL AKID Zero Octets CA
Last Update: Nov 18 15:40:41 2026 GMT
Next Update: Nov 15 15:40:41 2036 GMT
CRL extensions:
X509v3 Authority Key Identifier:
00:01:00:03:04:05:06:00
X509v3 CRL Number:
1
No Revoked Certificates.
Signature Algorithm: sha256WithRSAEncryption
Signature Value:
be:8e:9b:0d:c7:c2:62:c8:de:20:6b:b6:d6:a9:44:71:ac:c9:
51:8a:86:57:c9:be:80:ff:eb:87:a0:06:1e:76:79:a5:40:08:
6b:74:9d:e7:58:e8:1c:15:11:d1:00:8d:5c:19:d9:0c:a9:e7:
70:ba:d4:c1:8b:42:29:ef:58:84:31:63:a5:c2:67:6a:4d:d5:
10:a0:4e:4a:35:ad:3f:83:65:8d:14:73:db:88:ec:ef:38:4b:
60:a4:eb:af:2e:de:12:b6:cc:9d:d0:62:c2:03:c7:a9:f2:b4:
1a:84:99:a3:0f:ee:52:6e:05:07:ac:df:ce:7b:c6:d6:5d:3a:
42:0c:dd:e4:79:6c:f7:50:b7:8d:41:90:d0:bd:6a:c3:c4:65:
38:e5:4c:da:dd:6f:c7:ea:37:50:fa:a3:41:3d:f4:b4:1c:87:
a2:d4:c3:5b:1a:7a:a9:f6:89:b3:fd:08:f5:1e:8f:05:09:f9:
f1:e3:c4:06:77:9e:d3:20:d2:61:32:ec:91:b3:00:ad:ed:37:
22:58:c4:52:3b:6c:32:02:88:9c:ca:73:b0:93:f2:0d:c7:1e:
74:e9:44:5a:21:0e:fc:1a:2b:cc:c4:ad:66:81:eb:d0:4a:a9:
2d:e5:f3:9f:b3:b5:f0:af:bc:1a:09:8d:1a:77:8d:3b:99:db:
09:7d:32:29
-----BEGIN X509 CRL-----
MIIBkzB9AgEBMA0GCSqGSIb3DQEBCwUAMCYxJDAiBgNVBAMMG3dvbGZTU0wgQUtJ
RCBaZXJvIE9jdGV0cyBDQRcNMjYxMTE4MTU0MDQxWhcNMzYxMTE1MTU0MDQxWqAj
MCEwEwYDVR0jBAwwCoAIAAEAAwQFBgAwCgYDVR0UBAMCAQEwDQYJKoZIhvcNAQEL
BQADggEBAL6Omw3HwmLI3iBrttapRHGsyVGKhlfJvoD/64egBh52eaVACGt0nedY
6BwVEdEAjVwZ2Qyp53C61MGLQinvWIQxY6XCZ2pN1RCgTko1rT+DZY0Uc9uI7O84
S2Ck668u3hK2zJ3QYsIDx6nytBqEmaMP7lJuBQes3857xtZdOkIM3eR5bPdQt41B
kNC9asPEZTjlTNrdb8fqN1D6o0E99LQch6LUw1saeqn2ibP9CPUejwUJ+fHjxAZ3
ntMg0mEy7JGzAK3tNyJYxFI7bDICiJzKc7CT8g3HHnTpRFohDvwaK8zErWaB69BK
qS3l85+ztfCvvBoJjRp3jTuZ2wl9Mik=
-----END X509 CRL-----
38 changes: 38 additions & 0 deletions certs/crl/gencrls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,42 @@ check_result $?
mv tmp crl_reason.pem
cp blank.index.txt demoCA/index.txt

# CRL whose 8 octet authority key id has leading, interior and trailing zeros
echo "Step 40 zero octet authority key id CRL"
cat > akid.cnf <<'EOF'
[ ca ]
default_ca = CA_default
[ CA_default ]
database = ./demoCA/index.txt
crlnumber = ./crlnumber
default_md = sha256
crl_extensions = crl_ext
[ crl_ext ]
authorityKeyIdentifier = keyid:always
[ req ]
distinguished_name = dn
prompt = no
[ dn ]
CN = wolfSSL AKID Zero Octets CA
[ akid_ca ]
basicConstraints = critical,CA:true
keyUsage = critical,cRLSign,keyCertSign
subjectKeyIdentifier = 00:01:00:03:04:05:06:00
EOF
echo "01" > crlnumber
openssl req -new -x509 -config akid.cnf -extensions akid_ca \
-key ../ca-key.pem -days 3650 -out akid-ca.pem
check_result $?
openssl ca -config akid.cnf -gencrl -crldays 3650 -keyfile ../ca-key.pem \
-cert akid-ca.pem -out extra-crls/akid_zero_octets.pem
check_result $?

# metadata
echo "Step 41"
openssl crl -in extra-crls/akid_zero_octets.pem -text > tmp
check_result $?
mv tmp extra-crls/akid_zero_octets.pem
rm -f akid.cnf akid-ca.pem
cp blank.index.txt demoCA/index.txt

exit 0
3 changes: 2 additions & 1 deletion certs/crl/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ EXTRA_DIST += \
certs/crl/extra-crls/crlnum_57oct.pem \
certs/crl/extra-crls/crlnum_64oct.pem \
certs/crl/extra-crls/claim-root.pem \
certs/crl/extra-crls/crl_critical_entry.pem
certs/crl/extra-crls/crl_critical_entry.pem \
certs/crl/extra-crls/akid_zero_octets.pem

# Intermediate cert CRL's
EXTRA_DIST += \
Expand Down
14 changes: 13 additions & 1 deletion src/crl.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,15 @@ static int InitCRL_Entry(CRL_Entry* crle, DecodedCRL* dcrl, const byte* buff,
XMEMCPY(crle->signature, dcrl->signature, crle->signatureSz);
#ifndef NO_SKID
crle->extAuthKeyIdSet = dcrl->extAuthKeyIdSet;
if (crle->extAuthKeyIdSet)
if (crle->extAuthKeyIdSet) {
XMEMCPY(crle->extAuthKeyId, dcrl->extAuthKeyId, KEYID_SIZE);
/* Key id lies within the TBS, keep its position for printing. */
if (dcrl->extAuthKeyIdRawIdx >= dcrl->certBegin) {
crle->extAuthKeyIdRawIdx =
dcrl->extAuthKeyIdRawIdx - dcrl->certBegin;
crle->extAuthKeyIdRawSz = dcrl->extAuthKeyIdRawSz;
}
}
#endif
}
else {
Expand Down Expand Up @@ -3200,6 +3207,11 @@ int wolfSSL_X509_CRL_sign(WOLFSSL_X509_CRL* crl, WOLFSSL_EVP_PKEY* pkey,
entry->signature = newSignature;
entry->signatureSz = newSignatureSz;
entry->signatureOID = newSignatureOid;
#if !defined(NO_SKID) && !defined(NO_ASN)
/* Re-encoded TBS has no authority key id extension. */
entry->extAuthKeyIdRawIdx = 0;
entry->extAuthKeyIdRawSz = 0;
#endif
}
else {
if (newToBeSigned != NULL) {
Expand Down
22 changes: 18 additions & 4 deletions src/x509.c
Original file line number Diff line number Diff line change
Expand Up @@ -10802,12 +10802,26 @@ static int X509CRLPrintExtensions(WOLFSSL_BIO* bio, WOLFSSL_X509_CRL* crl,

#if !defined(NO_SKID)
if (ret == 0 && crl->crlList->extAuthKeyIdSet &&
crl->crlList->extAuthKeyId[0] != 0) {
crl->crlList->extAuthKeyIdRawSz > 0) {
word32 i;
char val[5];
int valSz = 5;
const byte* keyId = NULL;
word32 keyIdSz = crl->crlList->extAuthKeyIdRawSz;

/* extAuthKeyId is a normalized lookup key; print the encoded id. */
if (crl->crlList->toBeSigned == NULL ||
crl->crlList->extAuthKeyIdRawIdx > crl->crlList->tbsSz ||
keyIdSz > crl->crlList->tbsSz -
crl->crlList->extAuthKeyIdRawIdx) {
ret = WOLFSSL_FAILURE;
}
else {
keyId = crl->crlList->toBeSigned +
crl->crlList->extAuthKeyIdRawIdx;
}

if (XSNPRINTF(tmp, MAX_WIDTH, "%*s%s", indent + 4, "",
if (ret == 0 && XSNPRINTF(tmp, MAX_WIDTH, "%*s%s", indent + 4, "",
"X509v3 Authority Key Identifier:") >= MAX_WIDTH) {
ret = WOLFSSL_FAILURE;
}
Expand All @@ -10827,7 +10841,7 @@ static int X509CRLPrintExtensions(WOLFSSL_BIO* bio, WOLFSSL_X509_CRL* crl,
}


for (i = 0; i < XSTRLEN((char*)crl->crlList->extAuthKeyId); i++) {
for (i = 0; ret == 0 && i < keyIdSz; i++) {
/* check if buffer is almost full */
if (ret == 0 && XSTRLEN(tmp) >= sizeof(tmp) - valSz) {
if (wolfSSL_BIO_write(bio, tmp, (int)XSTRLEN(tmp)) <= 0) {
Expand All @@ -10836,7 +10850,7 @@ static int X509CRLPrintExtensions(WOLFSSL_BIO* bio, WOLFSSL_X509_CRL* crl,
tmp[0] = '\0';
}
if (ret == 0 && XSNPRINTF(val, (size_t)valSz, ":%02X",
crl->crlList->extAuthKeyId[i]) >= valSz) {
keyId[i]) >= valSz) {
WOLFSSL_MSG("buffer overrun");
ret = WOLFSSL_FAILURE;
}
Expand Down
43 changes: 43 additions & 0 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -35092,8 +35092,51 @@ static int test_wolfSSL_X509_CRL_print(void)
ExpectNull(XSTRSTR(buf, "a\r\nb"));

X509_NAME_free(name);
X509_CRL_free(crl);
crl = NULL;
BIO_free(bio);
bio = NULL;

#ifndef NO_SKID
/* The encoded key id is printed whatever the internal KEYID_SIZE. An
* 8 octet id with leading, interior and trailing zeros. */
ExpectTrue((fp = XFOPEN("./certs/crl/extra-crls/akid_zero_octets.pem",
Comment thread
embhorn marked this conversation as resolved.
Resolved
"rb")) != XBADFILE);
ExpectNotNull(crl = (X509_CRL*)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
NULL, NULL));
if (fp != XBADFILE) {
XFCLOSE(fp);
fp = XBADFILE;
}

ExpectNotNull(bio = BIO_new(BIO_s_mem()));
ExpectIntEQ(X509_CRL_print(bio, crl), SSL_SUCCESS);
ExpectIntGT(test_bio_mem_to_str(bio, buf, (int)sizeof(buf)), 0);
ExpectNotNull(XSTRSTR(buf, "keyid:00:01:00:03:04:05:06:00\n"));

X509_CRL_free(crl);
crl = NULL;
BIO_free(bio);
bio = NULL;

#if defined(HAVE_ECC) && !defined(NO_SHA256)
/* 20 octet id with no zero octets. */
ExpectTrue((fp = XFOPEN("./certs/crl/caEccCrl.pem", "rb")) != XBADFILE);
ExpectNotNull(crl = (X509_CRL*)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
NULL, NULL));
if (fp != XBADFILE)
XFCLOSE(fp);

ExpectNotNull(bio = BIO_new(BIO_s_mem()));
ExpectIntEQ(X509_CRL_print(bio, crl), SSL_SUCCESS);
ExpectIntGT(test_bio_mem_to_str(bio, buf, (int)sizeof(buf)), 0);
ExpectNotNull(XSTRSTR(buf, "keyid:56:8E:9A:C3:F0:42:DE:18:B9:45:55:"
"6E:F9:93:CF:EA:C3:F3:A5:21\n"));

X509_CRL_free(crl);
BIO_free(bio);
#endif /* HAVE_ECC && !NO_SHA256 */
#endif /* !NO_SKID */
#endif
return EXPECT_RESULT();
}
Expand Down
13 changes: 10 additions & 3 deletions wolfcrypt/src/asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -4737,7 +4737,8 @@ static int DecodeBasicOcspResponse(byte* source, word32* ioIndex,
#if defined(HAVE_CRL) && !defined(WOLFCRYPT_ONLY)
static int GetRevoked(RevokedCert* rcert, const byte* buff, word32* idx, DecodedCRL* dcrl, word32 maxIdx);
#ifndef NO_SKID
static int ParseCRL_AuthKeyIdExt(const byte* input, int sz, DecodedCRL* dcrl);
static int ParseCRL_AuthKeyIdExt(const byte* input, word32 inputIdx, int sz,
Comment thread
embhorn marked this conversation as resolved.
Resolved
DecodedCRL* dcrl);
#endif
static int ParseCRL_Extensions(DecodedCRL* dcrl, const byte* buf, word32* inOutIdx, word32 sz);
#endif
Expand Down Expand Up @@ -39866,7 +39867,8 @@ static int PaseCRL_CheckSignature(DecodedCRL* dcrl, const byte* sigParams,

#ifndef NO_SKID
#ifdef WOLFSSL_ASN_TEMPLATE
static int ParseCRL_AuthKeyIdExt(const byte* input, int sz, DecodedCRL* dcrl)
static int ParseCRL_AuthKeyIdExt(const byte* input, word32 inputIdx, int sz,
DecodedCRL* dcrl)
{
DECL_ASNGETDATA(dataASN, authKeyIdASN_Length);
int ret = 0;
Expand All @@ -39888,6 +39890,10 @@ static int ParseCRL_AuthKeyIdExt(const byte* input, int sz, DecodedCRL* dcrl)
}
else {
dcrl->extAuthKeyIdSet = 1;
dcrl->extAuthKeyIdRawIdx = inputIdx + (word32)
(dataASN[AUTHKEYIDASN_IDX_KEYID].data.ref.data - input);
dcrl->extAuthKeyIdRawSz =
dataASN[AUTHKEYIDASN_IDX_KEYID].data.ref.length;

/* Get the hash or hash of the hash if wrong size. */
ret = GetHashId(dataASN[AUTHKEYIDASN_IDX_KEYID].data.ref.data,
Expand Down Expand Up @@ -39969,7 +39975,8 @@ static int ParseCRL_Extensions(DecodedCRL* dcrl, const byte* buf, word32 idx,
#ifndef NO_SKID
/* Parse Authority Key Id extension.
* idx is at start of OCTET_STRING data. */
ret = ParseCRL_AuthKeyIdExt(buf + localIdx, length, dcrl);
ret = ParseCRL_AuthKeyIdExt(buf + localIdx, localIdx,
length, dcrl);
if (ret != 0) {
WOLFSSL_MSG("\tcouldn't parse AuthKeyId extension");
}
Expand Down
7 changes: 5 additions & 2 deletions wolfcrypt/src/asn_orig.c
Original file line number Diff line number Diff line change
Expand Up @@ -9605,7 +9605,8 @@ static int ParseCRL_CertList(RevokedCert* rcert, DecodedCRL* dcrl,
}

#ifndef NO_SKID
static int ParseCRL_AuthKeyIdExt(const byte* input, int sz, DecodedCRL* dcrl)
static int ParseCRL_AuthKeyIdExt(const byte* input, word32 inputIdx, int sz,
DecodedCRL* dcrl)
{
word32 idx = 0;
int length = 0, ret = 0;
Expand Down Expand Up @@ -9633,6 +9634,8 @@ static int ParseCRL_AuthKeyIdExt(const byte* input, int sz, DecodedCRL* dcrl)
}

dcrl->extAuthKeyIdSet = 1;
dcrl->extAuthKeyIdRawIdx = inputIdx + idx;
dcrl->extAuthKeyIdRawSz = (word32)length;

/* Get the hash or hash of the hash if wrong size. */
ret = GetHashId(input + idx, length, dcrl->extAuthKeyId,
Expand Down Expand Up @@ -9717,7 +9720,7 @@ static int ParseCRL_Extensions(DecodedCRL* dcrl, const byte* buf,

if (oid == AUTH_KEY_OID) {
#ifndef NO_SKID
ret = ParseCRL_AuthKeyIdExt(buf + idx, length, dcrl);
ret = ParseCRL_AuthKeyIdExt(buf + idx, idx, length, dcrl);
if (ret < 0) {
WOLFSSL_MSG("\tcouldn't parse AuthKeyId extension");
return ret;
Expand Down
2 changes: 2 additions & 0 deletions wolfssl/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2836,6 +2836,8 @@ struct CRL_Entry {
#endif
word32 signatureOID;
#if !defined(NO_SKID) && !defined(NO_ASN)
word32 extAuthKeyIdRawIdx; /* offset of encoded key id in toBeSigned */
word32 extAuthKeyIdRawSz; /* length of encoded key id */
byte extAuthKeyId[KEYID_SIZE];
byte extAuthKeyIdSet:1; /* Auth key identifier set indicator */
#endif
Expand Down
2 changes: 2 additions & 0 deletions wolfssl/wolfcrypt/asn.h
Original file line number Diff line number Diff line change
Expand Up @@ -3355,6 +3355,8 @@ struct DecodedCRL {
void* heap;
#ifndef NO_SKID
byte extAuthKeyId[SIGNER_DIGEST_SIZE]; /* Authority Key ID */
word32 extAuthKeyIdRawIdx; /* offset of encoded key id in CRL */
Comment thread
embhorn marked this conversation as resolved.
Resolved
word32 extAuthKeyIdRawSz; /* length of encoded key id */
WC_BITFIELD extAuthKeyIdSet:1; /* Auth key identifier set indicator */
#endif
WC_BITFIELD crlNumberSet:1; /* CRL number set indicator */
Expand Down
Loading