Skip to content

Commit 9f6a75c

Browse files
authored
Merge pull request #7934 from rizlik/ocsp-get-ca-keyhash-fix
ocsp: search CA by key hash instead of ext key id
2 parents a3fea48 + 6114691 commit 9f6a75c

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

src/ssl.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5127,6 +5127,42 @@ Signer* GetCA(void* vp, byte* hash)
51275127
return ret;
51285128
}
51295129

5130+
#if defined(HAVE_OCSP)
5131+
Signer* GetCAByKeyHash(void* vp, const byte* keyHash)
5132+
{
5133+
WOLFSSL_CERT_MANAGER* cm = (WOLFSSL_CERT_MANAGER*)vp;
5134+
Signer* ret = NULL;
5135+
Signer* signers;
5136+
int row;
5137+
5138+
if (cm == NULL || keyHash == NULL)
5139+
return NULL;
5140+
5141+
/* try lookup using keyHash as subjKeyID first */
5142+
ret = GetCA(vp, (byte*)keyHash);
5143+
if (ret != NULL && XMEMCMP(ret->subjectKeyHash, keyHash, KEYID_SIZE) == 0) {
5144+
return ret;
5145+
}
5146+
5147+
/* if we can't find the cert, we have to scan the full table */
5148+
if (wc_LockMutex(&cm->caLock) != 0)
5149+
return NULL;
5150+
5151+
/* Unfortunately we need to look through the entire table */
5152+
for (row = 0; row < CA_TABLE_SIZE && ret == NULL; row++) {
5153+
for (signers = cm->caTable[row]; signers != NULL;
5154+
signers = signers->next) {
5155+
if (XMEMCMP(signers->subjectKeyHash, keyHash, KEYID_SIZE) == 0) {
5156+
ret = signers;
5157+
break;
5158+
}
5159+
}
5160+
}
5161+
5162+
wc_UnLockMutex(&cm->caLock);
5163+
return ret;
5164+
}
5165+
#endif
51305166
#ifdef WOLFSSL_AKID_NAME
51315167
Signer* GetCAByAKID(void* vp, const byte* issuer, word32 issuerSz,
51325168
const byte* serial, word32 serialSz)

wolfcrypt/src/asn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36770,7 +36770,7 @@ static int DecodeBasicOcspResponse(byte* source, word32* ioIndex,
3677036770
int sigValid = -1;
3677136771

3677236772
#ifndef NO_SKID
36773-
ca = GetCA(cm, resp->single->issuerKeyHash);
36773+
ca = GetCAByKeyHash(cm, resp->single->issuerKeyHash);
3677436774
#else
3677536775
ca = GetCA(cm, resp->single->issuerHash);
3677636776
#endif
@@ -36911,7 +36911,7 @@ static int DecodeBasicOcspResponse(byte* source, word32* ioIndex,
3691136911

3691236912
/* Response didn't have a certificate - lookup CA. */
3691336913
#ifndef NO_SKID
36914-
ca = GetCA(cm, resp->single->issuerKeyHash);
36914+
ca = GetCAByKeyHash(cm, resp->single->issuerKeyHash);
3691536915
#else
3691636916
ca = GetCA(cm, resp->single->issuerHash);
3691736917
#endif

wolfssl/internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6466,6 +6466,9 @@ WOLFSSL_LOCAL WC_RNG* WOLFSSL_RSA_GetRNG(WOLFSSL_RSA *rsa, WC_RNG **tmpRNG,
64666466
WOLFSSL_LOCAL Signer* GetCAByAKID(void* vp, const byte* issuer,
64676467
word32 issuerSz, const byte* serial, word32 serialSz);
64686468
#endif
6469+
#ifdef HAVE_OCSP
6470+
WOLFSSL_LOCAL Signer* GetCAByKeyHash(void* vp, const byte* keyHash);
6471+
#endif
64696472
#if !defined(NO_SKID) && !defined(GetCAByName)
64706473
WOLFSSL_LOCAL Signer* GetCAByName(void* cm, byte* hash);
64716474
#endif

0 commit comments

Comments
 (0)