Skip to content

Allow crypto_method context value in stream_socket_enable_crypto() #607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions ext/standard/streamsfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ typedef unsigned long long php_timeout_ull;
typedef unsigned __int64 php_timeout_ull;
#endif

#define GET_CTX_OPT(stream, wrapper, name, val) (stream->context && SUCCESS == php_stream_context_get_option(stream->context, wrapper, name, &val))

static php_stream_context *decode_context_param(zval *contextresource TSRMLS_DC);

/* Streams based network functions */
Expand Down Expand Up @@ -1502,26 +1504,34 @@ PHP_FUNCTION(stream_socket_enable_crypto)
long cryptokind = 0;
zval *zstream, *zsessstream = NULL;
php_stream *stream, *sessstream = NULL;
zend_bool enable;
zend_bool enable, cryptokindnull;
int ret;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb|lr", &zstream, &enable, &cryptokind, &zsessstream) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb|l!r", &zstream, &enable, &cryptokind, &cryptokindnull, &zsessstream) == FAILURE) {
RETURN_FALSE;
}

php_stream_from_zval(stream, &zstream);

if (ZEND_NUM_ARGS() >= 3) {
if (enable) {
if (ZEND_NUM_ARGS() < 3 || cryptokindnull) {
zval **val;

if (!GET_CTX_OPT(stream, "ssl", "crypto_method", val)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "When enabling encryption you must specify the crypto type");
RETURN_FALSE;
}

cryptokind = Z_LVAL_PP(val);
}

if (zsessstream) {
php_stream_from_zval(sessstream, &zsessstream);
}

if (php_stream_xport_crypto_setup(stream, cryptokind, sessstream TSRMLS_CC) < 0) {
RETURN_FALSE;
}
} else if (enable) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "When enabling encryption you must specify the crypto type");
RETURN_FALSE;
}

ret = php_stream_xport_crypto_enable(stream, enable TSRMLS_CC);
Expand Down