@@ -1376,8 +1376,9 @@ WOLFSSL_OCSP_ONEREQ* wolfSSL_OCSP_request_add0_id(OcspRequest *req,
13761376 /* Keep to free */
13771377 req -> cid = (void * )cid ;
13781378
1379- XMEMCPY (req -> issuerHash , cid -> issuerHash , KEYID_SIZE );
1380- XMEMCPY (req -> issuerKeyHash , cid -> issuerKeyHash , KEYID_SIZE );
1379+ XMEMCPY (req -> issuerHash , cid -> issuerHash , WC_MAX_DIGEST_SIZE );
1380+ XMEMCPY (req -> issuerKeyHash , cid -> issuerKeyHash , WC_MAX_DIGEST_SIZE );
1381+ req -> hashAlg = (int )cid -> hashAlgoOID ;
13811382 if (cid -> status -> serialSz > req -> serialSz ) {
13821383 XFREE (req -> serial , req -> heap , DYNAMIC_TYPE_OCSP );
13831384 req -> serial = (byte * )XMALLOC ((size_t )cid -> status -> serialSz ,
@@ -2293,8 +2294,23 @@ int wc_OcspResponder_AddCA(OcspResponder* responder,
22932294
22942295 /* Extract necessary info from decoded cert */
22952296 XMEMCPY (ca -> subject , decoded -> subject , WC_ASN_NAME_MAX );
2296- XMEMCPY (ca -> issuerHash , decoded -> subjectHash , KEYID_SIZE );
2297- XMEMCPY (ca -> issuerKeyHash , decoded -> subjectKeyHash , KEYID_SIZE );
2297+ if (decoded -> subjectRawForHash == NULL ||
2298+ decoded -> subjectRawForHashLen <= 0 ) {
2299+ ret = BAD_FUNC_ARG ;
2300+ goto out ;
2301+ }
2302+ ret = AsnHashesHash (& ca -> issuerHashes , decoded -> subjectRawForHash ,
2303+ (word32 )decoded -> subjectRawForHashLen );
2304+ if (ret != 0 )
2305+ goto out ;
2306+ if (decoded -> publicKeyForHash == NULL || decoded -> pubKeyForHashSize == 0 ) {
2307+ ret = BAD_FUNC_ARG ;
2308+ goto out ;
2309+ }
2310+ ret = AsnHashesHash (& ca -> issuerKeyHash , decoded -> publicKeyForHash ,
2311+ decoded -> pubKeyForHashSize );
2312+ if (ret != 0 )
2313+ goto out ;
22982314 keyOID = decoded -> keyOID ;
22992315
23002316 /* Store raw certificate DER if sendCerts is enabled */
@@ -2359,13 +2375,20 @@ int wc_OcspResponder_AddCA(OcspResponder* responder,
23592375/* Find CA by comparing cert DER */
23602376/* Find CA by issuer hashes from request */
23612377static OcspResponderCa * FindCaByHashes (OcspResponder * responder ,
2362- const byte * issuerHash , const byte * issuerKeyHash )
2378+ const byte * issuerHash , const byte * issuerKeyHash , int hashAlg )
23632379{
23642380 OcspResponderCa * ca = responder -> caList ;
23652381
23662382 while (ca != NULL ) {
2367- if (XMEMCMP (ca -> issuerHash , issuerHash , KEYID_SIZE ) == 0 &&
2368- XMEMCMP (ca -> issuerKeyHash , issuerKeyHash , KEYID_SIZE ) == 0 ) {
2383+ int hashSz = 0 ;
2384+ const byte * caIssuerHash = AsnHashesGetHash (& ca -> issuerHashes ,
2385+ hashAlg , & hashSz );
2386+ const byte * caKeyHash = AsnHashesGetHash (& ca -> issuerKeyHash ,
2387+ hashAlg , & hashSz );
2388+
2389+ if (caIssuerHash != NULL && caKeyHash != NULL && hashSz > 0 &&
2390+ XMEMCMP (caIssuerHash , issuerHash , (size_t )hashSz ) == 0 &&
2391+ XMEMCMP (caKeyHash , issuerKeyHash , (size_t )hashSz ) == 0 ) {
23692392 return ca ;
23702393 }
23712394 ca = ca -> next ;
@@ -2514,8 +2537,10 @@ static int OcspResponse_WriteResponse(OcspResponder* responder, byte* response,
25142537 RsaKey * rsaKey = NULL ;
25152538 ecc_key * eccKey = NULL ;
25162539 int respInited = 0 ;
2517-
2518- wc_static_assert ((int )KEYID_SIZE == (int )WC_SHA_DIGEST_SIZE );
2540+ int hashSz = 0 ;
2541+ const byte * caIssuerHash = NULL ;
2542+ const byte * caKeyHash = NULL ;
2543+ int hashAlg = -1 ;
25192544
25202545 WOLFSSL_ENTER ("OcspResponse_WriteResponse" );
25212546
@@ -2579,13 +2604,25 @@ static int OcspResponse_WriteResponse(OcspResponder* responder, byte* response,
25792604 resp .nonceSz = req -> nonceSz ;
25802605 }
25812606
2582- /* Only support sha-1 hashes for now */
2583- entry .hashAlgoOID = SHAh ;
2584- XMEMCPY (entry .issuerHash , ca -> issuerHash , KEYID_SIZE );
2585- XMEMCPY (entry .issuerKeyHash , ca -> issuerKeyHash , KEYID_SIZE );
2607+ /* Echo the hash algorithm from the request */
2608+ if (req == NULL ) {
2609+ hashAlg = SHAh ; /* Fall back to SHA-1 as its required for OCSP */
2610+ }
2611+ else {
2612+ hashAlg = req -> hashAlg ;
2613+ }
2614+ caIssuerHash = AsnHashesGetHash (& ca -> issuerHashes , hashAlg , & hashSz );
2615+ caKeyHash = AsnHashesGetHash (& ca -> issuerKeyHash , hashAlg , & hashSz );
2616+ if (caIssuerHash == NULL || caKeyHash == NULL || hashSz <= 0 ) {
2617+ ret = ASN_SIG_HASH_E ;
2618+ goto out ;
2619+ }
2620+ entry .hashAlgoOID = (word32 )hashAlg ;
2621+ XMEMCPY (entry .issuerHash , caIssuerHash , (size_t )hashSz );
2622+ XMEMCPY (entry .issuerKeyHash , caKeyHash , (size_t )hashSz );
25862623
25872624 resp .responderIdType = OCSP_RESPONDER_ID_KEY ;
2588- XMEMCPY (resp .responderId .keyHash , ca -> issuerKeyHash , KEYID_SIZE );
2625+ XMEMCPY (resp .responderId .keyHash , ca -> issuerKeyHash . sha , KEYID_SIZE );
25892626
25902627 /* TODO allow user to set algo */
25912628 if (ca -> keyType == RSAk ) {
@@ -2640,7 +2677,8 @@ int wc_OcspResponder_WriteResponse(OcspResponder* responder,
26402677 reqInited = 1 ;
26412678
26422679 /* Find the CA by issuer hashes */
2643- ca = FindCaByHashes (responder , req .issuerHash , req .issuerKeyHash );
2680+ ca = FindCaByHashes (responder , req .issuerHash , req .issuerKeyHash ,
2681+ req .hashAlg );
26442682 if (ca == NULL ) {
26452683 WOLFSSL_MSG ("No matching CA found for request" );
26462684 ret = ASN_NO_SIGNER_E ;
0 commit comments