Skip to content

Commit c6d43a5

Browse files
committed
PHPC-698: Check HAVE_OPENSSL_EXT before calling php-ssl.c functions
1 parent 136077d commit c6d43a5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

php_phongo.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,10 +1012,15 @@ int php_phongo_peer_verify(php_stream *stream, X509 *cert, const char *hostname,
10121012
peer = hostname;
10131013
}
10141014

1015+
#ifdef HAVE_OPENSSL_EXT
10151016
if (php_phongo_verify_hostname(peer, cert TSRMLS_CC) == FAILURE) {
10161017
bson_set_error(error, MONGOC_ERROR_STREAM, MONGOC_ERROR_STREAM_CONNECT, "Remote certificate SubjectAltName or CN does not match '%s'", hostname);
10171018
return false;
10181019
}
1020+
#else
1021+
bson_set_error(error, MONGOC_ERROR_STREAM, MONGOC_ERROR_STREAM_CONNECT, "Cannot verify remote certificate SubjectAltName or CN. Please ensure that extension is compiled against PHP with OpenSSL or disable the \"verify_peer_name\" SSL context option.");
1022+
return false;
1023+
#endif
10191024
}
10201025

10211026
return true;
@@ -1067,6 +1072,7 @@ bool php_phongo_ssl_verify(php_stream *stream, const char *hostname, bson_error_
10671072
#else
10681073
if (php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "ssl", "verify_expiry", &verify_expiry) == SUCCESS && zend_is_true(*verify_expiry)) {
10691074
#endif
1075+
#ifdef HAVE_OPENSSL_EXT
10701076
time_t current = time(NULL);
10711077
time_t valid_from = php_mongodb_asn1_time_to_time_t(X509_get_notBefore(cert) TSRMLS_CC);
10721078
time_t valid_until = php_mongodb_asn1_time_to_time_t(X509_get_notAfter(cert) TSRMLS_CC);
@@ -1079,6 +1085,10 @@ bool php_phongo_ssl_verify(php_stream *stream, const char *hostname, bson_error_
10791085
bson_set_error(error, MONGOC_ERROR_STREAM, MONGOC_ERROR_STREAM_CONNECT, "Certificate has expired on %s", hostname);
10801086
return false;
10811087
}
1088+
#else
1089+
bson_set_error(error, MONGOC_ERROR_STREAM, MONGOC_ERROR_STREAM_CONNECT, "Cannot verify certificate expiration. Please ensure that extension is compiled against PHP with OpenSSL or disable the \"verify_expiry\" SSL context option.");
1090+
return false;
1091+
#endif
10821092
}
10831093

10841094
return true;

0 commit comments

Comments
 (0)