Skip to content

Commit ce27895

Browse files
committed
Streams for ssl:// transports can now be configured to use a specific
crypto method (SSLv3, SSLv2 etc.) by calling stream_context_set_option($ctx, "ssl", "crypto_method", $crypto_method) where $crypto_method can be one of STREAM_CRYPTO_METHOD_SSLv2_CLIENT, STREAM_CRYPTO_METHOD_SSLv3_CLIENT, STREAM_CRYPTO_METHOD_SSLv23_CLIENT or STREAM_CRYPTO_METHOD_TLS_CLIENT. SSLv23 remains the default crypto method. This change makes it possible to fopen() SSL URLs that are only provided using SSL v3.
1 parent 9e3bedc commit ce27895

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

ext/openssl/xp_ssl.c

+29-1
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,29 @@ php_stream_ops php_openssl_socket_ops = {
853853
php_openssl_sockop_set_option,
854854
};
855855

856+
static int get_crypto_method(php_stream_context *ctx) {
857+
if (ctx) {
858+
zval **val = NULL;
859+
long crypto_method;
860+
861+
if (php_stream_context_get_option(ctx, "ssl", "crypto_method", &val) == SUCCESS) {
862+
convert_to_long_ex(val);
863+
crypto_method = (long)Z_LVAL_PP(val);
864+
865+
switch (crypto_method) {
866+
case STREAM_CRYPTO_METHOD_SSLv2_CLIENT:
867+
case STREAM_CRYPTO_METHOD_SSLv3_CLIENT:
868+
case STREAM_CRYPTO_METHOD_SSLv23_CLIENT:
869+
case STREAM_CRYPTO_METHOD_TLS_CLIENT:
870+
return crypto_method;
871+
}
872+
873+
}
874+
}
875+
876+
return STREAM_CRYPTO_METHOD_SSLv23_CLIENT;
877+
}
878+
856879
static char * get_sni(php_stream_context *ctx, const char *resourcename, size_t resourcenamelen, int is_persistent TSRMLS_DC) {
857880

858881
php_url *url;
@@ -939,7 +962,12 @@ php_stream *php_openssl_ssl_socket_factory(const char *proto, size_t protolen,
939962

940963
if (strncmp(proto, "ssl", protolen) == 0) {
941964
sslsock->enable_on_connect = 1;
942-
sslsock->method = STREAM_CRYPTO_METHOD_SSLv23_CLIENT;
965+
966+
/* General ssl:// transports can use a number
967+
* of crypto methods. The actual methhod can be
968+
* provided in the streams context options.
969+
*/
970+
sslsock->method = get_crypto_method(context);
943971
} else if (strncmp(proto, "sslv2", protolen) == 0) {
944972
#ifdef OPENSSL_NO_SSL2
945973
php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSLv2 support is not compiled into the OpenSSL library PHP is linked against");

0 commit comments

Comments
 (0)