@@ -552,10 +552,13 @@ _contact_ocsp_responder (OCSP_CERTID *id, X509 *peer)
552
552
((stapled_response) ? MONGOC_ERROR (__VA_ARGS__) \
553
553
: MONGOC_DEBUG (__VA_ARGS__))
554
554
555
+ #define X509_CHECK_SUCCESS 1
556
+ #define OCSP_VERIFY_SUCCESS 1
557
+
555
558
int
556
559
_mongoc_ocsp_tlsext_status_cb (SSL * ssl , void * arg )
557
560
{
558
- enum { ERROR = -1 , REVOKED , SUCCESS } ret ;
561
+ enum { OCSP_CB_ERROR = -1 , OCSP_CB_REVOKED , OCSP_CB_SUCCESS } ret ;
559
562
bool stapled_response = true;
560
563
OCSP_RESPONSE * resp = NULL ;
561
564
OCSP_BASICRESP * basic = NULL ;
@@ -570,32 +573,32 @@ _mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
570
573
* next_update = NULL ;
571
574
572
575
if (opts -> weak_cert_validation ) {
573
- return SUCCESS ;
576
+ return OCSP_CB_SUCCESS ;
574
577
}
575
578
576
579
if (!(peer = SSL_get_peer_certificate (ssl ))) {
577
580
MONGOC_ERROR ("No certificate was presented by the peer" );
578
- ret = ERROR ;
581
+ ret = OCSP_CB_ERROR ;
579
582
GOTO (done );
580
583
}
581
584
582
585
/* Get a STACK_OF(X509) certs forming the cert chain of the peer, including
583
586
* the peer's cert */
584
587
if (!(cert_chain = SSL_get0_verified_chain (ssl ))) {
585
588
MONGOC_ERROR ("No certificate was presented by the peer" );
586
- ret = REVOKED ;
589
+ ret = OCSP_CB_REVOKED ;
587
590
GOTO (done );
588
591
}
589
592
590
593
if (!(issuer = _get_issuer (peer , cert_chain ))) {
591
594
MONGOC_ERROR ("Could not get issuer from peer cert" );
592
- ret = ERROR ;
595
+ ret = OCSP_CB_ERROR ;
593
596
GOTO (done );
594
597
}
595
598
596
599
if (!(id = OCSP_cert_to_id (NULL /* SHA1 */ , peer , issuer ))) {
597
600
MONGOC_ERROR ("Could not obtain a valid OCSP_CERTID for peer" );
598
- ret = ERROR ;
601
+ ret = OCSP_CB_ERROR ;
599
602
GOTO (done );
600
603
}
601
604
@@ -606,21 +609,21 @@ _mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
606
609
/* obtain an OCSP_RESPONSE object from the OCSP response */
607
610
if (!d2i_OCSP_RESPONSE (& resp , & r , len )) {
608
611
MONGOC_ERROR ("Failed to parse OCSP response" );
609
- ret = ERROR ;
612
+ ret = OCSP_CB_ERROR ;
610
613
GOTO (done );
611
614
}
612
615
} else {
613
616
MONGOC_DEBUG ("Server does not contain a stapled response" );
614
617
bool must_staple = X509_get_ext_d2i (peer , NID_tlsfeature , 0 , 0 ) != NULL ;
615
618
if (must_staple ) {
616
619
MONGOC_ERROR ("Server must contain a stapled response" );
617
- ret = REVOKED ;
620
+ ret = OCSP_CB_REVOKED ;
618
621
GOTO (done );
619
622
}
620
623
621
624
if (!(resp = _contact_ocsp_responder (id , peer ))) {
622
625
MONGOC_DEBUG ("Soft-fail: No OCSP responder could be reached" );
623
- ret = SUCCESS ;
626
+ ret = OCSP_CB_SUCCESS ;
624
627
GOTO (done );
625
628
}
626
629
}
@@ -632,7 +635,7 @@ _mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
632
635
SOFT_FAIL ("OCSP response error %d %s" ,
633
636
status ,
634
637
OCSP_response_status_str (status ));
635
- ret = ERROR ;
638
+ ret = OCSP_CB_ERROR ;
636
639
GOTO (done );
637
640
}
638
641
@@ -643,7 +646,7 @@ _mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
643
646
basic = OCSP_response_get1_basic (resp );
644
647
if (!basic ) {
645
648
SOFT_FAIL ("Could not find BasicOCSPResponse: %s" , ERR_STR );
646
- ret = ERROR ;
649
+ ret = OCSP_CB_ERROR ;
647
650
GOTO (done );
648
651
}
649
652
@@ -658,9 +661,9 @@ _mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
658
661
* 3. Finally, the function validates the signer cert, constructing the
659
662
* validation path via the untrusted cert chain.
660
663
*/
661
- if (SUCCESS != OCSP_basic_verify (basic , cert_chain , store , 0 )) {
664
+ if (OCSP_basic_verify (basic , cert_chain , store , 0 ) != OCSP_VERIFY_SUCCESS ) {
662
665
SOFT_FAIL ("OCSP response failed verification: %s" , ERR_STR );
663
- ret = ERROR ;
666
+ ret = OCSP_CB_ERROR ;
664
667
GOTO (done );
665
668
}
666
669
@@ -673,14 +676,14 @@ _mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
673
676
& this_update ,
674
677
& next_update )) {
675
678
SOFT_FAIL ("No OCSP response found for the peer certificate" );
676
- ret = ERROR ;
679
+ ret = OCSP_CB_ERROR ;
677
680
GOTO (done );
678
681
}
679
682
680
683
/* checks the validity of this_update and next_update values */
681
684
if (!OCSP_check_validity (this_update , next_update , 0L , -1L )) {
682
685
SOFT_FAIL ("OCSP response has expired: %s" , ERR_STR );
683
- ret = ERROR ;
686
+ ret = OCSP_CB_ERROR ;
684
687
GOTO (done );
685
688
}
686
689
@@ -693,7 +696,7 @@ _mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
693
696
case V_OCSP_CERTSTATUS_REVOKED :
694
697
MONGOC_ERROR ("OCSP Certificate Status: Revoked. Reason: %s" ,
695
698
OCSP_crl_reason_str (reason ));
696
- ret = REVOKED ;
699
+ ret = OCSP_CB_REVOKED ;
697
700
GOTO (done );
698
701
699
702
default :
@@ -703,16 +706,16 @@ _mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
703
706
704
707
/* Validate hostname matches cert */
705
708
if (!opts -> allow_invalid_hostname &&
706
- X509_check_host (peer , opts -> host , 0 , 0 , NULL ) != SUCCESS &&
707
- X509_check_ip_asc (peer , opts -> host , 0 ) != SUCCESS ) {
708
- ret = REVOKED ;
709
+ X509_check_host (peer , opts -> host , 0 , 0 , NULL ) != X509_CHECK_SUCCESS &&
710
+ X509_check_ip_asc (peer , opts -> host , 0 ) != X509_CHECK_SUCCESS ) {
711
+ ret = OCSP_CB_REVOKED ;
709
712
GOTO (done );
710
713
}
711
714
712
- ret = SUCCESS ;
715
+ ret = OCSP_CB_SUCCESS ;
713
716
done :
714
- if (ret == ERROR && !stapled_response ) {
715
- ret = SUCCESS ;
717
+ if (ret == OCSP_CB_ERROR && !stapled_response ) {
718
+ ret = OCSP_CB_SUCCESS ;
716
719
}
717
720
if (basic )
718
721
OCSP_BASICRESP_free (basic );
0 commit comments