Skip to content

Commit 11a8746

Browse files
committed
CDRIVER-3602 prefix enum constants in OCSP callback
Also use specific constants for OCSP and X509 function return values.
1 parent c339080 commit 11a8746

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

src/libmongoc/src/mongoc/mongoc-openssl.c

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -552,10 +552,13 @@ _contact_ocsp_responder (OCSP_CERTID *id, X509 *peer)
552552
((stapled_response) ? MONGOC_ERROR (__VA_ARGS__) \
553553
: MONGOC_DEBUG (__VA_ARGS__))
554554

555+
#define X509_CHECK_SUCCESS 1
556+
#define OCSP_VERIFY_SUCCESS 1
557+
555558
int
556559
_mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
557560
{
558-
enum { ERROR = -1, REVOKED, SUCCESS } ret;
561+
enum { OCSP_CB_ERROR = -1, OCSP_CB_REVOKED, OCSP_CB_SUCCESS } ret;
559562
bool stapled_response = true;
560563
OCSP_RESPONSE *resp = NULL;
561564
OCSP_BASICRESP *basic = NULL;
@@ -570,32 +573,32 @@ _mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
570573
*next_update = NULL;
571574

572575
if (opts->weak_cert_validation) {
573-
return SUCCESS;
576+
return OCSP_CB_SUCCESS;
574577
}
575578

576579
if (!(peer = SSL_get_peer_certificate (ssl))) {
577580
MONGOC_ERROR ("No certificate was presented by the peer");
578-
ret = ERROR;
581+
ret = OCSP_CB_ERROR;
579582
GOTO (done);
580583
}
581584

582585
/* Get a STACK_OF(X509) certs forming the cert chain of the peer, including
583586
* the peer's cert */
584587
if (!(cert_chain = SSL_get0_verified_chain (ssl))) {
585588
MONGOC_ERROR ("No certificate was presented by the peer");
586-
ret = REVOKED;
589+
ret = OCSP_CB_REVOKED;
587590
GOTO (done);
588591
}
589592

590593
if (!(issuer = _get_issuer (peer, cert_chain))) {
591594
MONGOC_ERROR ("Could not get issuer from peer cert");
592-
ret = ERROR;
595+
ret = OCSP_CB_ERROR;
593596
GOTO (done);
594597
}
595598

596599
if (!(id = OCSP_cert_to_id (NULL /* SHA1 */, peer, issuer))) {
597600
MONGOC_ERROR ("Could not obtain a valid OCSP_CERTID for peer");
598-
ret = ERROR;
601+
ret = OCSP_CB_ERROR;
599602
GOTO (done);
600603
}
601604

@@ -606,21 +609,21 @@ _mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
606609
/* obtain an OCSP_RESPONSE object from the OCSP response */
607610
if (!d2i_OCSP_RESPONSE (&resp, &r, len)) {
608611
MONGOC_ERROR ("Failed to parse OCSP response");
609-
ret = ERROR;
612+
ret = OCSP_CB_ERROR;
610613
GOTO (done);
611614
}
612615
} else {
613616
MONGOC_DEBUG ("Server does not contain a stapled response");
614617
bool must_staple = X509_get_ext_d2i (peer, NID_tlsfeature, 0, 0) != NULL;
615618
if (must_staple) {
616619
MONGOC_ERROR ("Server must contain a stapled response");
617-
ret = REVOKED;
620+
ret = OCSP_CB_REVOKED;
618621
GOTO (done);
619622
}
620623

621624
if (!(resp = _contact_ocsp_responder (id, peer))) {
622625
MONGOC_DEBUG ("Soft-fail: No OCSP responder could be reached");
623-
ret = SUCCESS;
626+
ret = OCSP_CB_SUCCESS;
624627
GOTO (done);
625628
}
626629
}
@@ -632,7 +635,7 @@ _mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
632635
SOFT_FAIL ("OCSP response error %d %s",
633636
status,
634637
OCSP_response_status_str (status));
635-
ret = ERROR;
638+
ret = OCSP_CB_ERROR;
636639
GOTO (done);
637640
}
638641

@@ -643,7 +646,7 @@ _mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
643646
basic = OCSP_response_get1_basic (resp);
644647
if (!basic) {
645648
SOFT_FAIL ("Could not find BasicOCSPResponse: %s", ERR_STR);
646-
ret = ERROR;
649+
ret = OCSP_CB_ERROR;
647650
GOTO (done);
648651
}
649652

@@ -658,9 +661,9 @@ _mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
658661
* 3. Finally, the function validates the signer cert, constructing the
659662
* validation path via the untrusted cert chain.
660663
*/
661-
if (SUCCESS != OCSP_basic_verify (basic, cert_chain, store, 0)) {
664+
if (OCSP_basic_verify (basic, cert_chain, store, 0) != OCSP_VERIFY_SUCCESS) {
662665
SOFT_FAIL ("OCSP response failed verification: %s", ERR_STR);
663-
ret = ERROR;
666+
ret = OCSP_CB_ERROR;
664667
GOTO (done);
665668
}
666669

@@ -673,14 +676,14 @@ _mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
673676
&this_update,
674677
&next_update)) {
675678
SOFT_FAIL ("No OCSP response found for the peer certificate");
676-
ret = ERROR;
679+
ret = OCSP_CB_ERROR;
677680
GOTO (done);
678681
}
679682

680683
/* checks the validity of this_update and next_update values */
681684
if (!OCSP_check_validity (this_update, next_update, 0L, -1L)) {
682685
SOFT_FAIL ("OCSP response has expired: %s", ERR_STR);
683-
ret = ERROR;
686+
ret = OCSP_CB_ERROR;
684687
GOTO (done);
685688
}
686689

@@ -693,7 +696,7 @@ _mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
693696
case V_OCSP_CERTSTATUS_REVOKED:
694697
MONGOC_ERROR ("OCSP Certificate Status: Revoked. Reason: %s",
695698
OCSP_crl_reason_str (reason));
696-
ret = REVOKED;
699+
ret = OCSP_CB_REVOKED;
697700
GOTO (done);
698701

699702
default:
@@ -703,16 +706,16 @@ _mongoc_ocsp_tlsext_status_cb (SSL *ssl, void *arg)
703706

704707
/* Validate hostname matches cert */
705708
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;
709712
GOTO (done);
710713
}
711714

712-
ret = SUCCESS;
715+
ret = OCSP_CB_SUCCESS;
713716
done:
714-
if (ret == ERROR && !stapled_response) {
715-
ret = SUCCESS;
717+
if (ret == OCSP_CB_ERROR && !stapled_response) {
718+
ret = OCSP_CB_SUCCESS;
716719
}
717720
if (basic)
718721
OCSP_BASICRESP_free (basic);

0 commit comments

Comments
 (0)