@@ -774,6 +774,63 @@ int test_ocsp_certid_dup(void)
774774}
775775#endif
776776
777+ int test_ocsp_resp_find_status_serial_prefix (void )
778+ {
779+ EXPECT_DECLS ;
780+ #if defined(HAVE_OCSP ) && defined(OPENSSL_EXTRA ) && !defined(NO_SHA )
781+ OcspResponse response ;
782+ OcspEntry single ;
783+ CertStatus responseStatus ;
784+ OcspEntry requestedId ;
785+ CertStatus requestedStatus ;
786+ int status ;
787+
788+ XMEMSET (& response , 0 , sizeof (response ));
789+ XMEMSET (& single , 0 , sizeof (single ));
790+ XMEMSET (& responseStatus , 0 , sizeof (responseStatus ));
791+ XMEMSET (& requestedId , 0 , sizeof (requestedId ));
792+ XMEMSET (& requestedStatus , 0 , sizeof (requestedStatus ));
793+
794+ single .status = & responseStatus ;
795+ requestedId .status = & requestedStatus ;
796+ response .single = & single ;
797+
798+ /* Matching issuer name and key hashes on both sides. */
799+ XMEMSET (single .issuerHash , 0x41 , OCSP_DIGEST_SIZE );
800+ XMEMSET (single .issuerKeyHash , 0x42 , OCSP_DIGEST_SIZE );
801+ XMEMCPY (requestedId .issuerHash , single .issuerHash , OCSP_DIGEST_SIZE );
802+ XMEMCPY (requestedId .issuerKeyHash , single .issuerKeyHash , OCSP_DIGEST_SIZE );
803+
804+ /* Response carries a CERT_GOOD status for serial 01:02 (2 bytes). */
805+ responseStatus .serial [0 ] = 0x01 ;
806+ responseStatus .serial [1 ] = 0x02 ;
807+ responseStatus .serialSz = 2 ;
808+ responseStatus .status = CERT_GOOD ;
809+
810+ /* Sanity check: an exact serial match must be found and report CERT_GOOD. */
811+ requestedStatus .serial [0 ] = 0x01 ;
812+ requestedStatus .serial [1 ] = 0x02 ;
813+ requestedStatus .serialSz = 2 ;
814+ status = -1 ;
815+ ExpectIntEQ (wolfSSL_OCSP_resp_find_status (& response , & requestedId , & status ,
816+ NULL , NULL , NULL , NULL ), WOLFSSL_SUCCESS );
817+ ExpectIntEQ (status , CERT_GOOD );
818+
819+ /* Request serial 01:02:03 (3 bytes) shares the 01:02 prefix of the
820+ * response serial.
821+ * The lookup must not bind the good response to this longer and
822+ * differing serial. */
823+ requestedStatus .serial [0 ] = 0x01 ;
824+ requestedStatus .serial [1 ] = 0x02 ;
825+ requestedStatus .serial [2 ] = 0x03 ;
826+ requestedStatus .serialSz = 3 ;
827+ status = -1 ;
828+ ExpectIntEQ (wolfSSL_OCSP_resp_find_status (& response , & requestedId , & status ,
829+ NULL , NULL , NULL , NULL ), WOLFSSL_FAILURE );
830+ #endif
831+ return EXPECT_RESULT ();
832+ }
833+
777834#if defined(HAVE_OCSP ) && defined(WOLFSSL_CERT_SETUP_CB ) && \
778835 defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES ) && !defined(NO_RSA ) && \
779836 (defined(HAVE_CERTIFICATE_STATUS_REQUEST ) || \
0 commit comments