Skip to content

Commit a9d39db

Browse files
committed
Merge branch 'v1.1'
2 parents 5061221 + aa931f3 commit a9d39db

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

php_phongo.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,13 +1030,13 @@ ssize_t phongo_stream_poll (mongoc_stream_poll_t *streams, size_t nstreams, int3
10301030
} /* }}} */
10311031

10321032
#if PHP_VERSION_ID < 50600
1033-
int php_mongo_verify_hostname(const char *hostname, X509 *cert TSRMLS_DC)
1033+
static int php_phongo_verify_hostname(const char *hostname, X509 *cert TSRMLS_DC)
10341034
{
1035-
if (php_mongo_matches_san_list(cert, hostname) == SUCCESS) {
1035+
if (php_mongodb_matches_san_list(cert, hostname) == SUCCESS) {
10361036
return SUCCESS;
10371037
}
10381038

1039-
if (php_mongo_matches_common_name(cert, hostname TSRMLS_CC) == SUCCESS) {
1039+
if (php_mongodb_matches_common_name(cert, hostname TSRMLS_CC) == SUCCESS) {
10401040
return SUCCESS;
10411041
}
10421042

@@ -1059,10 +1059,15 @@ int php_phongo_peer_verify(php_stream *stream, X509 *cert, const char *hostname,
10591059
peer = hostname;
10601060
}
10611061

1062-
if (php_mongo_verify_hostname(peer, cert TSRMLS_CC) == FAILURE) {
1062+
#ifdef HAVE_OPENSSL_EXT
1063+
if (php_phongo_verify_hostname(peer, cert TSRMLS_CC) == FAILURE) {
10631064
bson_set_error(error, MONGOC_ERROR_STREAM, MONGOC_ERROR_STREAM_CONNECT, "Remote certificate SubjectAltName or CN does not match '%s'", hostname);
10641065
return false;
10651066
}
1067+
#else
1068+
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.");
1069+
return false;
1070+
#endif
10661071
}
10671072

10681073
return true;
@@ -1114,9 +1119,10 @@ bool php_phongo_ssl_verify(php_stream *stream, const char *hostname, bson_error_
11141119
#else
11151120
if (php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "ssl", "verify_expiry", &verify_expiry) == SUCCESS && zend_is_true(*verify_expiry)) {
11161121
#endif
1122+
#ifdef HAVE_OPENSSL_EXT
11171123
time_t current = time(NULL);
1118-
time_t valid_from = php_mongo_asn1_time_to_time_t(X509_get_notBefore(cert) TSRMLS_CC);
1119-
time_t valid_until = php_mongo_asn1_time_to_time_t(X509_get_notAfter(cert) TSRMLS_CC);
1124+
time_t valid_from = php_mongodb_asn1_time_to_time_t(X509_get_notBefore(cert) TSRMLS_CC);
1125+
time_t valid_until = php_mongodb_asn1_time_to_time_t(X509_get_notAfter(cert) TSRMLS_CC);
11201126

11211127
if (valid_from > current) {
11221128
bson_set_error(error, MONGOC_ERROR_STREAM, MONGOC_ERROR_STREAM_CONNECT, "Certificate is not valid yet on %s", hostname);
@@ -1126,6 +1132,10 @@ bool php_phongo_ssl_verify(php_stream *stream, const char *hostname, bson_error_
11261132
bson_set_error(error, MONGOC_ERROR_STREAM, MONGOC_ERROR_STREAM_CONNECT, "Certificate has expired on %s", hostname);
11271133
return false;
11281134
}
1135+
#else
1136+
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.");
1137+
return false;
1138+
#endif
11291139
}
11301140

11311141
return true;

src/contrib/php-ssl.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#define timezone _timezone /* timezone is called _timezone in LibC */
3535
#endif
3636

37-
int php_mongo_matches_wildcard_name(const char *subjectname, const char *certname) /* {{{ */
37+
int php_mongodb_matches_wildcard_name(const char *subjectname, const char *certname) /* {{{ */
3838
{
3939
char *wildcard = NULL;
4040
int prefix_len, suffix_len, subject_len;
@@ -70,7 +70,7 @@ int php_mongo_matches_wildcard_name(const char *subjectname, const char *certnam
7070
}
7171
/* }}} */
7272

73-
int php_mongo_matches_san_list(X509 *peer, const char *subject_name) /* {{{ */
73+
int php_mongodb_matches_san_list(X509 *peer, const char *subject_name) /* {{{ */
7474
{
7575
int i, len;
7676
unsigned char *cert_name = NULL;
@@ -96,7 +96,7 @@ int php_mongo_matches_san_list(X509 *peer, const char *subject_name) /* {{{ */
9696
cert_name[len-1] = '\0';
9797
}
9898

99-
if (php_mongo_matches_wildcard_name(subject_name, (const char *)cert_name) == SUCCESS) {
99+
if (php_mongodb_matches_wildcard_name(subject_name, (const char *)cert_name) == SUCCESS) {
100100
OPENSSL_free(cert_name);
101101
return SUCCESS;
102102
}
@@ -124,7 +124,7 @@ int php_mongo_matches_san_list(X509 *peer, const char *subject_name) /* {{{ */
124124
}
125125
/* }}} */
126126

127-
int php_mongo_matches_common_name(X509 *peer, const char *subject_name TSRMLS_DC) /* {{{ */
127+
int php_mongodb_matches_common_name(X509 *peer, const char *subject_name TSRMLS_DC) /* {{{ */
128128
{
129129
char buf[1024];
130130
X509_NAME *cert_name;
@@ -137,7 +137,7 @@ int php_mongo_matches_common_name(X509 *peer, const char *subject_name TSRMLS_DC
137137
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to locate peer certificate CN");
138138
} else if ((size_t) cert_name_len != strlen(buf)) {
139139
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Peer certificate CN=`%.*s' is malformed", cert_name_len, buf);
140-
} else if (php_mongo_matches_wildcard_name(subject_name, buf) == SUCCESS) {
140+
} else if (php_mongodb_matches_wildcard_name(subject_name, buf) == SUCCESS) {
141141
return SUCCESS;
142142
} else {
143143
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Peer certificate CN=`%.*s' did not match expected CN=`%s'", cert_name_len, buf, subject_name);
@@ -147,7 +147,7 @@ int php_mongo_matches_common_name(X509 *peer, const char *subject_name TSRMLS_DC
147147
}
148148
/* }}} */
149149

150-
time_t php_mongo_asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
150+
time_t php_mongodb_asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
151151
{
152152
/*
153153
This is how the time string is formatted:

src/contrib/php-ssl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
#include <openssl/x509.h>
3535
#include <openssl/x509v3.h>
3636

37-
int php_mongo_matches_wildcard_name(const char *subjectname, const char *certname);
38-
int php_mongo_matches_san_list(X509 *peer, const char *subject_name);
39-
int php_mongo_matches_common_name(X509 *peer, const char *subject_name TSRMLS_DC);
40-
time_t php_mongo_asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC);
37+
int php_mongodb_matches_wildcard_name(const char *subjectname, const char *certname);
38+
int php_mongodb_matches_san_list(X509 *peer, const char *subject_name);
39+
int php_mongodb_matches_common_name(X509 *peer, const char *subject_name TSRMLS_DC);
40+
time_t php_mongodb_asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC);
4141

4242
#endif /* HAVE_OPENSSL_EXT */
4343
#endif

0 commit comments

Comments
 (0)