Skip to content

Commit 293719c

Browse files
committed
ocsp: search CA by key hash instead of ext key id
1 parent 4d837e7 commit 293719c

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

src/ssl.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5102,6 +5102,36 @@ Signer* GetCA(void* vp, byte* hash)
51025102
return ret;
51035103
}
51045104

5105+
#if defined(HAVE_OCSP)
5106+
Signer* GetCAByKeyHash(void* vp, const byte* keyHash)
5107+
{
5108+
WOLFSSL_CERT_MANAGER* cm = (WOLFSSL_CERT_MANAGER*)vp;
5109+
Signer* ret = NULL;
5110+
Signer* signers;
5111+
int row;
5112+
5113+
if (cm == NULL || keyHash == NULL)
5114+
return NULL;
5115+
5116+
if (wc_LockMutex(&cm->caLock) != 0)
5117+
return NULL;
5118+
5119+
/* Unfortunately we need to look through the entire table */
5120+
for (row = 0; row < CA_TABLE_SIZE && ret == NULL; row++) {
5121+
for (signers = cm->caTable[row]; signers != NULL;
5122+
signers = signers->next) {
5123+
if (XMEMCMP(signers->subjectKeyHash, keyHash, KEYID_SIZE)
5124+
== 0) {
5125+
ret = signers;
5126+
break;
5127+
}
5128+
}
5129+
}
5130+
5131+
wc_UnLockMutex(&cm->caLock);
5132+
return ret;
5133+
}
5134+
#endif
51055135
#ifdef WOLFSSL_AKID_NAME
51065136
Signer* GetCAByAKID(void* vp, const byte* issuer, word32 issuerSz,
51075137
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
@@ -6460,6 +6460,9 @@ WOLFSSL_LOCAL WC_RNG* WOLFSSL_RSA_GetRNG(WOLFSSL_RSA *rsa, WC_RNG **tmpRNG,
64606460
WOLFSSL_LOCAL Signer* GetCAByAKID(void* vp, const byte* issuer,
64616461
word32 issuerSz, const byte* serial, word32 serialSz);
64626462
#endif
6463+
#ifdef HAVE_OCSP
6464+
WOLFSSL_LOCAL Signer* GetCAByKeyHash(void* vp, const byte* keyHash);
6465+
#endif
64636466
#if !defined(NO_SKID) && !defined(GetCAByName)
64646467
WOLFSSL_LOCAL Signer* GetCAByName(void* cm, byte* hash);
64656468
#endif

0 commit comments

Comments
 (0)