@@ -658,7 +658,8 @@ _contact_ocsp_responder (OCSP_CERTID *id, X509 *peer)
658658{
659659 STACK_OF (OPENSSL_STRING ) * url_stack = NULL ;
660660 OPENSSL_STRING url = NULL , host = NULL , path = NULL , port = NULL ;
661- OCSP_REQUEST * req = NULL ;
661+ OCSP_REQUEST * req ;
662+ OCSP_REQ_CTX * sendreq_ctx = NULL ;
662663 OCSP_RESPONSE * resp = NULL ;
663664 BIO * bio = NULL ;
664665 int i , ssl ;
@@ -702,12 +703,39 @@ _contact_ocsp_responder (OCSP_CERTID *id, X509 *peer)
702703 GOTO (retry );
703704 }
704705
705- if (!(resp = OCSP_sendreq_bio (bio , path , req ))) {
706- MONGOC_DEBUG (
707- "Could not perform an OCSP request for url '%s'. Error: %s" ,
708- url ,
709- ERR_STR );
706+ /* Leave OCSP request NULL, set it onto the request context after setting
707+ * the host header. */
708+ sendreq_ctx =
709+ OCSP_sendreq_new (bio , path , NULL /* OCSP request */ , 0 /* maxline */ );
710+ if (host ) {
711+ if (0 == OCSP_REQ_CTX_add1_header (sendreq_ctx , "Host" , host )) {
712+ MONGOC_DEBUG ("Could not set OCSP request header for host: %s" ,
713+ host );
714+ GOTO (retry );
715+ }
716+ }
717+
718+ if (0 == OCSP_REQ_CTX_set1_req (sendreq_ctx , req )) {
719+ MONGOC_DEBUG ("Could not set OCSP request" );
720+ GOTO (retry );
710721 }
722+
723+ do {
724+ int ret = OCSP_sendreq_nbio (& resp , sendreq_ctx );
725+ if (ret == 1 ) {
726+ /* Success. */
727+ break ;
728+ } else if (ret == -1 && BIO_should_retry (bio )) {
729+ /* Non-blocking write not finished, repeat. */
730+ continue ;
731+ } else {
732+ MONGOC_DEBUG ("Could not send OCSP request for url '%s'. Error: %s" ,
733+ url ,
734+ ERR_STR );
735+ GOTO (retry );
736+ }
737+ } while (true);
738+
711739 retry :
712740 if (bio )
713741 BIO_free_all (bio );
@@ -719,6 +747,8 @@ _contact_ocsp_responder (OCSP_CERTID *id, X509 *peer)
719747 OPENSSL_free (path );
720748 if (req )
721749 OCSP_REQUEST_free (req );
750+ if (sendreq_ctx )
751+ OCSP_REQ_CTX_free (sendreq_ctx );
722752 }
723753
724754 if (url_stack )
0 commit comments