@@ -94,9 +94,7 @@ _mongoc_stream_tls_openssl_destroy (mongoc_stream_t *stream)
94
94
SSL_CTX_free (openssl -> ctx );
95
95
openssl -> ctx = NULL ;
96
96
97
- if (openssl -> ocsp_opts )
98
- bson_free ((char * ) openssl -> ocsp_opts -> host );
99
- bson_free (openssl -> ocsp_opts );
97
+ mongoc_openssl_ocsp_opt_destroy (openssl -> ocsp_opts );
100
98
openssl -> ocsp_opts = NULL ;
101
99
102
100
bson_free (openssl );
@@ -566,13 +564,21 @@ _mongoc_stream_tls_openssl_handshake (mongoc_stream_t *stream,
566
564
if (BIO_do_handshake (openssl -> bio ) == 1 ) {
567
565
#if (OPENSSL_VERSION_NUMBER >= 0x10002000L )
568
566
X509 * peer = NULL ;
569
- peer = SSL_get_peer_certificate (ssl );
570
567
571
- if (tls -> ssl_opts .allow_invalid_hostname ||
572
- X509_check_host (peer , host , 0 , 0 , NULL ) == 1 ||
573
- X509_check_ip_asc (peer , host , 0 ) == 1 ) {
568
+ if (tls -> ssl_opts .allow_invalid_hostname ) {
569
+ RETURN (true);
570
+ }
571
+
572
+ peer = SSL_get_peer_certificate (ssl );
573
+ if (peer && (X509_check_host (peer , host , 0 , 0 , NULL ) == 1 ||
574
+ X509_check_ip_asc (peer , host , 0 ) == 1 )) {
575
+ X509_free (peer );
574
576
RETURN (true);
575
577
}
578
+
579
+ if (peer ) {
580
+ X509_free (peer );
581
+ }
576
582
#else
577
583
if (_mongoc_openssl_check_cert (
578
584
ssl , host , tls -> ssl_opts .allow_invalid_hostname )) {
@@ -733,14 +739,15 @@ mongoc_stream_tls_openssl_new (mongoc_stream_t *base_stream,
733
739
#ifdef MONGOC_ENABLE_OCSP
734
740
} else {
735
741
if (!SSL_CTX_set_tlsext_status_type (ssl_ctx , TLSEXT_STATUSTYPE_ocsp )) {
742
+ MONGOC_ERROR ("cannot enable OCSP status request extension" );
736
743
SSL_CTX_free (ssl_ctx );
737
744
RETURN (NULL );
738
745
}
739
746
740
- ocsp_opts = bson_malloc (sizeof (mongoc_openssl_ocsp_opt_t ));
747
+ ocsp_opts = bson_malloc (sizeof (mongoc_openssl_ocsp_opt_t ));
741
748
ocsp_opts -> allow_invalid_hostname = opt -> allow_invalid_hostname ;
742
749
ocsp_opts -> weak_cert_validation = opt -> weak_cert_validation ;
743
- ocsp_opts -> host = bson_strdup (host );
750
+ ocsp_opts -> host = bson_strdup (host );
744
751
745
752
SSL_CTX_set_tlsext_status_arg (ssl_ctx , ocsp_opts );
746
753
SSL_CTX_set_tlsext_status_cb (ssl_ctx , _mongoc_ocsp_tlsext_status_cb );
@@ -755,12 +762,14 @@ mongoc_stream_tls_openssl_new (mongoc_stream_t *base_stream,
755
762
756
763
bio_ssl = BIO_new_ssl (ssl_ctx , client );
757
764
if (!bio_ssl ) {
765
+ mongoc_openssl_ocsp_opt_destroy (ocsp_opts );
758
766
SSL_CTX_free (ssl_ctx );
759
767
RETURN (NULL );
760
768
}
761
769
meth = mongoc_stream_tls_openssl_bio_meth_new ();
762
770
bio_mongoc_shim = BIO_new (meth );
763
771
if (!bio_mongoc_shim ) {
772
+ mongoc_openssl_ocsp_opt_destroy (ocsp_opts );
764
773
BIO_free_all (bio_ssl );
765
774
BIO_meth_free (meth );
766
775
RETURN (NULL );
@@ -810,4 +819,17 @@ mongoc_stream_tls_openssl_new (mongoc_stream_t *base_stream,
810
819
RETURN ((mongoc_stream_t * ) tls );
811
820
}
812
821
822
+ void
823
+ mongoc_openssl_ocsp_opt_destroy (void * ocsp_opt )
824
+ {
825
+ mongoc_openssl_ocsp_opt_t * casted ;
826
+
827
+ if (!ocsp_opt ) {
828
+ return ;
829
+ }
830
+ casted = (mongoc_openssl_ocsp_opt_t * ) ocsp_opt ;
831
+ bson_free (casted -> host );
832
+ bson_free (ocsp_opt );
833
+ }
834
+
813
835
#endif /* MONGOC_ENABLE_SSL_OPENSSL */
0 commit comments