summaryrefslogtreecommitdiff
path: root/ext/openssl
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2010-01-07 13:31:53 +0100
committerOndřej Surý <ondrej@sury.org>2010-01-07 13:31:53 +0100
commit0fab6db7cac8d2be99579dd049f812a8ff98e74f (patch)
tree91f01b0d06916c78262404096bfd466b8e95e5b5 /ext/openssl
parentd3a8757891280dc6650ca7eead67830c794b0e7b (diff)
downloadphp-upstream/5.3.1.tar.gz
Imported Upstream version 5.3.1upstream/5.3.1
Diffstat (limited to 'ext/openssl')
-rw-r--r--ext/openssl/README2
-rw-r--r--ext/openssl/config.w322
-rw-r--r--ext/openssl/config0.m42
-rw-r--r--ext/openssl/openssl.c38
-rw-r--r--ext/openssl/openssl.mak370
-rw-r--r--ext/openssl/php_openssl.h2
-rw-r--r--ext/openssl/tests/bug48182.phpt92
-rw-r--r--ext/openssl/xp_ssl.c32
8 files changed, 332 insertions, 208 deletions
diff --git a/ext/openssl/README b/ext/openssl/README
index cd6dad566..232a046ce 100644
--- a/ext/openssl/README
+++ b/ext/openssl/README
@@ -1,6 +1,6 @@
OpenSSL extension for PHP
-$Id: README,v 1.4 2004/01/17 12:59:41 sniper Exp $
+$Id: README 242949 2007-09-26 15:44:16Z cvs2svn $
The functions implemented so far make it possible to seal and open data, and
also create and verify signatures.
diff --git a/ext/openssl/config.w32 b/ext/openssl/config.w32
index 08b8a0c6b..a691cd85b 100644
--- a/ext/openssl/config.w32
+++ b/ext/openssl/config.w32
@@ -1,4 +1,4 @@
-// $Id: config.w32,v 1.1.6.1 2007/01/07 18:38:22 iliaa Exp $
+// $Id: config.w32 226663 2007-01-07 18:38:22Z iliaa $
// vim:ft=javascript
ARG_WITH("openssl", "OpenSSL support", "no");
diff --git a/ext/openssl/config0.m4 b/ext/openssl/config0.m4
index 91efd6629..ee5e85c29 100644
--- a/ext/openssl/config0.m4
+++ b/ext/openssl/config0.m4
@@ -1,5 +1,5 @@
dnl
-dnl $Id: config0.m4,v 1.4.4.1 2007/01/07 18:38:22 iliaa Exp $
+dnl $Id: config0.m4 226663 2007-01-07 18:38:22Z iliaa $
dnl
PHP_ARG_WITH(openssl, for OpenSSL support,
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 28d988b6d..d3e425eee 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: openssl.c,v 1.98.2.5.2.41.2.29 2009/04/20 09:44:29 mkoppanen Exp $ */
+/* $Id: openssl.c 289443 2009-10-09 19:08:56Z pajoye $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -502,8 +502,13 @@ inline static int php_openssl_safe_mode_chk(char *filename TSRMLS_DC)
static char default_ssl_conf_filename[MAXPATHLEN];
struct php_x509_request { /* {{{ */
- LHASH * global_config; /* Global SSL config */
- LHASH * req_config; /* SSL config for this request */
+#if OPENSSL_VERSION_NUMBER >= 0x10000002L
+ LHASH_OF(CONF_VALUE) * global_config; /* Global SSL config */
+ LHASH_OF(CONF_VALUE) * req_config; /* SSL config for this request */
+#else
+ LHASH * global_config; /* Global SSL config */
+ LHASH * req_config; /* SSL config for this request */
+#endif
const EVP_MD * md_alg;
const EVP_MD * digest;
char * section_name,
@@ -680,7 +685,11 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
}
/* }}} */
-static inline int php_openssl_config_check_syntax(const char * section_label, const char * config_filename, const char * section, LHASH * config TSRMLS_DC) /* {{{ */
+#if OPENSSL_VERSION_NUMBER >= 0x10000002L
+static inline int php_openssl_config_check_syntax(const char * section_label, const char * config_filename, const char * section, LHASH_OF(CONF_VALUE) * config TSRMLS_DC) /* {{{ */
+#else
+static inline int php_openssl_config_check_syntax(const char * section_label, const char * config_filename, const char * section, LHASH * config TSRMLS_DC) /* {{{ */
+#endif
{
X509V3_CTX ctx;
@@ -1158,7 +1167,11 @@ static X509 * php_openssl_x509_from_zval(zval ** val, int makeresource, long * r
if (in == NULL) {
return NULL;
}
+#ifdef TYPEDEF_D2I_OF
+ cert = (X509 *) PEM_ASN1_read_bio((d2i_of_void *)d2i_X509, PEM_STRING_X509, in, NULL, NULL, NULL);
+#else
cert = (X509 *) PEM_ASN1_read_bio((char *(*)())d2i_X509, PEM_STRING_X509, in, NULL, NULL, NULL);
+#endif
BIO_free(in);
}
@@ -2787,8 +2800,7 @@ static int php_openssl_is_private_key(EVP_PKEY* pkey TSRMLS_DC)
case EVP_PKEY_RSA:
case EVP_PKEY_RSA2:
assert(pkey->pkey.rsa != NULL);
-
- if (NULL == pkey->pkey.rsa->p || NULL == pkey->pkey.rsa->q) {
+ if (pkey->pkey.rsa != NULL && (NULL == pkey->pkey.rsa->p || NULL == pkey->pkey.rsa->q)) {
return 0;
}
break;
@@ -4311,8 +4323,15 @@ int php_openssl_apply_verification_policy(SSL *ssl, X509 *peer, php_stream *stre
GET_VER_OPT_STRING("CN_match", cnmatch);
if (cnmatch) {
int match = 0;
+ int name_len = X509_NAME_get_text_by_NID(name, NID_commonName, buf, sizeof(buf));
- X509_NAME_get_text_by_NID(name, NID_commonName, buf, sizeof(buf));
+ if (name_len == -1) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to locate peer certificate CN");
+ return FAILURE;
+ } else if (name_len != strlen(buf)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Peer certificate CN=`%.*s' is malformed", name_len, buf);
+ return FAILURE;
+ }
match = strcmp(cnmatch, buf) == 0;
if (!match && strlen(buf) > 3 && buf[0] == '*' && buf[1] == '.') {
@@ -4327,10 +4346,7 @@ int php_openssl_apply_verification_policy(SSL *ssl, X509 *peer, php_stream *stre
if (!match) {
/* didn't match */
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
- "Peer certificate CN=`%s' did not match expected CN=`%s'",
- buf, cnmatch);
-
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Peer certificate CN=`%.*s' did not match expected CN=`%s'", name_len, buf, cnmatch);
return FAILURE;
}
}
diff --git a/ext/openssl/openssl.mak b/ext/openssl/openssl.mak
index 4c907b8d7..a0c6fa483 100644
--- a/ext/openssl/openssl.mak
+++ b/ext/openssl/openssl.mak
@@ -1,185 +1,185 @@
-# Temporarily here -- later may go into some batch file
-# which will set this as an environment variable
-PROJECT_ROOT = ..\..
-
-# Module details
-MODULE_NAME = php_ossl
-MODULE_DESC = "PHP 5 - OpenSSL Extension"
-VMAJ = 1
-VMIN = 0
-VREV = 0
-
-#include the common settings
-include $(PROJECT_ROOT)/netware/common.mif
-
-# OpenSSL directory
-OSSL_DIR = P:/APPS/script/sw/OpenSSL
-
-# Build type defaults to 'release'
-ifndef BUILD
-BUILD = release
-endif
-
-# Extensions of all input and output files
-.SUFFIXES:
-.SUFFIXES: .nlm .lib .obj .cpp .c .msg .mlc .mdb .xdc .d
-
-# Source files
-C_SRC = openssl.c \
- xp_ssl.c \
- start.c \
-
-CPP_SRC_NODIR = $(notdir $(CPP_SRC))
-C_SRC_NODIR = $(notdir $(C_SRC))
-SRC_DIR = $(dir $(CPP_SRC) $(C_SRC))
-
-# Library files
-LIBRARY = $(OSSL_DIR)/lib/RSAglue.lib \
- $(OSSL_DIR)/lib/crypto.lib \
- $(OSSL_DIR)/lib/ssl.lib
-
-# Destination directories and files
-OBJ_DIR = $(BUILD)
-FINAL_DIR = $(BUILD)
-MAP_FILE = $(FINAL_DIR)\$(MODULE_NAME).map
-OBJECTS = $(addprefix $(OBJ_DIR)/,$(CPP_SRC_NODIR:.c=.obj) $(C_SRC_NODIR:.c=.obj))
-DEPDS = $(addprefix $(OBJ_DIR)/,$(CPP_SRC_NODIR:.c=.d) $(C_SRC_NODIR:.c=.d))
-
-# Binary file
-ifndef BINARY
- BINARY=$(FINAL_DIR)\$(MODULE_NAME).nlm
-endif
-
-# Compile flags
-C_FLAGS += -c -maxerrors 25 -msgstyle gcc
-C_FLAGS += -wchar_t on -bool on -processor Pentium
-C_FLAGS += -nostdinc -nosyspath
-C_FLAGS += -relax_pointers # To remove type-casting errors
-C_FLAGS += -DNETWARE -DZTS
-C_FLAGS += -DUSE_OLD_FUNCTIONS -DCOMPILE_DL_OPENSSL=1
-
-C_FLAGS += -I. -I$(PROJECT_ROOT) -I$(PROJECT_ROOT)/main
-C_FLAGS += -I$(PROJECT_ROOT)/ext/standard -I$(PROJECT_ROOT)/netware
-C_FLAGS += -I$(PROJECT_ROOT)/zend -I$(PROJECT_ROOT)/tsrm
-C_FLAGS += -I- -I$(SDK_DIR)/include -I$(MWCIncludes)
-C_FLAGS += -I$(OSSL_DIR)/include
-
-ifndef STACK_SIZE
-STACK_SIZE=8192
-endif
-
-# Extra stuff based on debug / release builds
-ifeq '$(BUILD)' 'debug'
- SYM_FILE = $(FINAL_DIR)\$(MODULE_NAME).sym
- C_FLAGS += -inline smart -sym on -sym codeview4 -opt off -opt intrinsics -sym internal -DDEBUGGING -DDKFBPON
- C_FLAGS += -exc cw -DZEND_DEBUG=1
- LD_FLAGS += -sym on -sym codeview4 -osym $(SYM_FILE)
- export MWLibraryFiles=$(SDK_DIR)/imports/libcpre.o;mwcrtld.lib
-else
- C_FLAGS += -opt all -inline on -inline smart -inline auto -sym off
- C_FLAGS += -opt intrinsics -opt level=4 -DZEND_DEBUG=0
- LD_FLAGS += -sym off
- export MWLibraryFiles=$(SDK_DIR)/imports/libcpre.o;mwcrtl.lib
-endif
-
-
-# Dependencies
-MODULE = LibC \
- phplib
-IMPORT = @$(SDK_DIR)/imports/libc.imp \
- @$(SDK_DIR)/imports/ws2nlm.imp \
- @$(SDK_DIR)/imports/netware.imp \
- @$(MPK_DIR)/import/mpkOrg.imp \
- @$(PROJECT_ROOT)/netware/phplib.imp
-EXPORT = ($(MODULE_NAME)) get_module
-API = OutputToScreen
-
-# Virtual paths
-vpath %.cpp .
-vpath %.c . ..\..\netware
-vpath %.obj $(OBJ_DIR)
-
-
-all: prebuild project
-
-.PHONY: all
-
-prebuild:
- @if not exist $(OBJ_DIR) md $(OBJ_DIR)
-
-project: $(BINARY)
- @echo Build complete.
-
-$(OBJ_DIR)/%.d: %.cpp
- @echo Building Dependencies for $(<F)
- @$(CC) -M $< $(C_FLAGS) -o $@
-
-$(OBJ_DIR)/%.d: %.c
- @echo Building Dependencies for $(<F)
- @$(CC) -M $< $(C_FLAGS) -o $@
-
-$(OBJ_DIR)/%.obj: %.cpp
- @echo Compiling $?...
- @$(CC) $< $(C_FLAGS) -o $@
-
-$(OBJ_DIR)/%.obj: %.c
- @echo Compiling $?...
- @$(CC) $< $(C_FLAGS) -o $@
-
-
-$(BINARY): $(OBJECTS)
- @echo Import $(IMPORT) > $(basename $@).def
-ifdef API
- @echo Import $(API) >> $(basename $@).def
-endif
- @echo Module $(MODULE) >> $(basename $@).def
-ifdef EXPORT
- @echo Export $(EXPORT) >> $(basename $@).def
-endif
- @echo AutoUnload >> $(basename $@).def
-ifeq '$(BUILD)' 'debug'
- @echo Debug >> $(basename $@).def
-endif
- @echo Flag_On 0x00000008 >> $(basename $@).def
- @echo Start _LibCPrelude >> $(basename $@).def
- @echo Exit _LibCPostlude >> $(basename $@).def
-
-# Two functions imported to build the openssl extension
- @echo Import GetProcessSwitchCount >> $(basename $@).def
- @echo Import RunningProcess >> $(basename $@).def
-
- $(MPKTOOL) $(XDCFLAGS) $(basename $@).xdc
- @echo xdcdata $(basename $@).xdc >> $(basename $@).def
-
- @echo Linking $@...
- @echo $(LD_FLAGS) -commandfile $(basename $@).def > $(basename $@).link
-
- @echo $(LIBRARY) $(OBJECTS) >> $(basename $@).link
-
- @$(LINK) @$(basename $@).link
-
-
-.PHONY: clean
-clean: cleanobj cleanbin
-
-.PHONY: cleand
-cleand:
- @echo Deleting all dependency files...
- -@del "$(OBJ_DIR)\*.d"
-
-.PHONY: cleanobj
-cleanobj:
- @echo Deleting all object files...
- -@del "$(OBJ_DIR)\*.obj"
-
-.PHONY: cleanbin
-cleanbin:
- @echo Deleting binary files...
- -@del "$(FINAL_DIR)\$(MODULE_NAME).nlm"
- @echo Deleting MAP, DEF files, etc....
- -@del "$(FINAL_DIR)\$(MODULE_NAME).map"
- -@del "$(FINAL_DIR)\$(MODULE_NAME).def"
- -@del "$(FINAL_DIR)\$(MODULE_NAME).link"
-ifeq '$(BUILD)' 'debug'
- -@del $(FINAL_DIR)\$(MODULE_NAME).sym
-endif
+# Temporarily here -- later may go into some batch file
+# which will set this as an environment variable
+PROJECT_ROOT = ..\..
+
+# Module details
+MODULE_NAME = php_ossl
+MODULE_DESC = "PHP 5 - OpenSSL Extension"
+VMAJ = 1
+VMIN = 0
+VREV = 0
+
+#include the common settings
+include $(PROJECT_ROOT)/netware/common.mif
+
+# OpenSSL directory
+OSSL_DIR = P:/APPS/script/sw/OpenSSL
+
+# Build type defaults to 'release'
+ifndef BUILD
+BUILD = release
+endif
+
+# Extensions of all input and output files
+.SUFFIXES:
+.SUFFIXES: .nlm .lib .obj .cpp .c .msg .mlc .mdb .xdc .d
+
+# Source files
+C_SRC = openssl.c \
+ xp_ssl.c \
+ start.c \
+
+CPP_SRC_NODIR = $(notdir $(CPP_SRC))
+C_SRC_NODIR = $(notdir $(C_SRC))
+SRC_DIR = $(dir $(CPP_SRC) $(C_SRC))
+
+# Library files
+LIBRARY = $(OSSL_DIR)/lib/RSAglue.lib \
+ $(OSSL_DIR)/lib/crypto.lib \
+ $(OSSL_DIR)/lib/ssl.lib
+
+# Destination directories and files
+OBJ_DIR = $(BUILD)
+FINAL_DIR = $(BUILD)
+MAP_FILE = $(FINAL_DIR)\$(MODULE_NAME).map
+OBJECTS = $(addprefix $(OBJ_DIR)/,$(CPP_SRC_NODIR:.c=.obj) $(C_SRC_NODIR:.c=.obj))
+DEPDS = $(addprefix $(OBJ_DIR)/,$(CPP_SRC_NODIR:.c=.d) $(C_SRC_NODIR:.c=.d))
+
+# Binary file
+ifndef BINARY
+ BINARY=$(FINAL_DIR)\$(MODULE_NAME).nlm
+endif
+
+# Compile flags
+C_FLAGS += -c -maxerrors 25 -msgstyle gcc
+C_FLAGS += -wchar_t on -bool on -processor Pentium
+C_FLAGS += -nostdinc -nosyspath
+C_FLAGS += -relax_pointers # To remove type-casting errors
+C_FLAGS += -DNETWARE -DZTS
+C_FLAGS += -DUSE_OLD_FUNCTIONS -DCOMPILE_DL_OPENSSL=1
+
+C_FLAGS += -I. -I$(PROJECT_ROOT) -I$(PROJECT_ROOT)/main
+C_FLAGS += -I$(PROJECT_ROOT)/ext/standard -I$(PROJECT_ROOT)/netware
+C_FLAGS += -I$(PROJECT_ROOT)/zend -I$(PROJECT_ROOT)/tsrm
+C_FLAGS += -I- -I$(SDK_DIR)/include -I$(MWCIncludes)
+C_FLAGS += -I$(OSSL_DIR)/include
+
+ifndef STACK_SIZE
+STACK_SIZE=8192
+endif
+
+# Extra stuff based on debug / release builds
+ifeq '$(BUILD)' 'debug'
+ SYM_FILE = $(FINAL_DIR)\$(MODULE_NAME).sym
+ C_FLAGS += -inline smart -sym on -sym codeview4 -opt off -opt intrinsics -sym internal -DDEBUGGING -DDKFBPON
+ C_FLAGS += -exc cw -DZEND_DEBUG=1
+ LD_FLAGS += -sym on -sym codeview4 -osym $(SYM_FILE)
+ export MWLibraryFiles=$(SDK_DIR)/imports/libcpre.o;mwcrtld.lib
+else
+ C_FLAGS += -opt all -inline on -inline smart -inline auto -sym off
+ C_FLAGS += -opt intrinsics -opt level=4 -DZEND_DEBUG=0
+ LD_FLAGS += -sym off
+ export MWLibraryFiles=$(SDK_DIR)/imports/libcpre.o;mwcrtl.lib
+endif
+
+
+# Dependencies
+MODULE = LibC \
+ phplib
+IMPORT = @$(SDK_DIR)/imports/libc.imp \
+ @$(SDK_DIR)/imports/ws2nlm.imp \
+ @$(SDK_DIR)/imports/netware.imp \
+ @$(MPK_DIR)/import/mpkOrg.imp \
+ @$(PROJECT_ROOT)/netware/phplib.imp
+EXPORT = ($(MODULE_NAME)) get_module
+API = OutputToScreen
+
+# Virtual paths
+vpath %.cpp .
+vpath %.c . ..\..\netware
+vpath %.obj $(OBJ_DIR)
+
+
+all: prebuild project
+
+.PHONY: all
+
+prebuild:
+ @if not exist $(OBJ_DIR) md $(OBJ_DIR)
+
+project: $(BINARY)
+ @echo Build complete.
+
+$(OBJ_DIR)/%.d: %.cpp
+ @echo Building Dependencies for $(<F)
+ @$(CC) -M $< $(C_FLAGS) -o $@
+
+$(OBJ_DIR)/%.d: %.c
+ @echo Building Dependencies for $(<F)
+ @$(CC) -M $< $(C_FLAGS) -o $@
+
+$(OBJ_DIR)/%.obj: %.cpp
+ @echo Compiling $?...
+ @$(CC) $< $(C_FLAGS) -o $@
+
+$(OBJ_DIR)/%.obj: %.c
+ @echo Compiling $?...
+ @$(CC) $< $(C_FLAGS) -o $@
+
+
+$(BINARY): $(OBJECTS)
+ @echo Import $(IMPORT) > $(basename $@).def
+ifdef API
+ @echo Import $(API) >> $(basename $@).def
+endif
+ @echo Module $(MODULE) >> $(basename $@).def
+ifdef EXPORT
+ @echo Export $(EXPORT) >> $(basename $@).def
+endif
+ @echo AutoUnload >> $(basename $@).def
+ifeq '$(BUILD)' 'debug'
+ @echo Debug >> $(basename $@).def
+endif
+ @echo Flag_On 0x00000008 >> $(basename $@).def
+ @echo Start _LibCPrelude >> $(basename $@).def
+ @echo Exit _LibCPostlude >> $(basename $@).def
+
+# Two functions imported to build the openssl extension
+ @echo Import GetProcessSwitchCount >> $(basename $@).def
+ @echo Import RunningProcess >> $(basename $@).def
+
+ $(MPKTOOL) $(XDCFLAGS) $(basename $@).xdc
+ @echo xdcdata $(basename $@).xdc >> $(basename $@).def
+
+ @echo Linking $@...
+ @echo $(LD_FLAGS) -commandfile $(basename $@).def > $(basename $@).link
+
+ @echo $(LIBRARY) $(OBJECTS) >> $(basename $@).link
+
+ @$(LINK) @$(basename $@).link
+
+
+.PHONY: clean
+clean: cleanobj cleanbin
+
+.PHONY: cleand
+cleand:
+ @echo Deleting all dependency files...
+ -@del "$(OBJ_DIR)\*.d"
+
+.PHONY: cleanobj
+cleanobj:
+ @echo Deleting all object files...
+ -@del "$(OBJ_DIR)\*.obj"
+
+.PHONY: cleanbin
+cleanbin:
+ @echo Deleting binary files...
+ -@del "$(FINAL_DIR)\$(MODULE_NAME).nlm"
+ @echo Deleting MAP, DEF files, etc....
+ -@del "$(FINAL_DIR)\$(MODULE_NAME).map"
+ -@del "$(FINAL_DIR)\$(MODULE_NAME).def"
+ -@del "$(FINAL_DIR)\$(MODULE_NAME).link"
+ifeq '$(BUILD)' 'debug'
+ -@del $(FINAL_DIR)\$(MODULE_NAME).sym
+endif
diff --git a/ext/openssl/php_openssl.h b/ext/openssl/php_openssl.h
index 83fc716e6..1aa8adf8d 100644
--- a/ext/openssl/php_openssl.h
+++ b/ext/openssl/php_openssl.h
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_openssl.h,v 1.16.2.1.2.4.2.2 2008/12/31 11:15:40 sebastian Exp $ */
+/* $Id: php_openssl.h 272370 2008-12-31 11:15:49Z sebastian $ */
#ifndef PHP_OPENSSL_H
#define PHP_OPENSSL_H
diff --git a/ext/openssl/tests/bug48182.phpt b/ext/openssl/tests/bug48182.phpt
new file mode 100644
index 000000000..0af04e1a9
--- /dev/null
+++ b/ext/openssl/tests/bug48182.phpt
@@ -0,0 +1,92 @@
+--TEST--
+#48182,ssl handshake fails during asynchronous socket connection
+--SKIPIF--
+<?php
+if (!extension_loaded("openssl")) die("skip, openssl required");
+if (!extension_loaded("pcntl")) die("skip, pcntl required");
+if (OPENSSL_VERSION_NUMBER < 0x009070af) die("skip");
+?>
+--FILE--
+<?php
+
+function ssl_server($port) {
+ $host = 'ssl://127.0.0.1'.':'.$port;
+ $flags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
+ $data = "Sending bug48182\n";
+
+ $pem = dirname(__FILE__) . '/bug46127.pem';
+ $ssl_params = array( 'verify_peer' => false, 'allow_self_signed' => true, 'local_cert' => $pem);
+ $ssl = array('ssl' => $ssl_params);
+
+ $context = stream_context_create($ssl);
+ $sock = stream_socket_server($host, $errno, $errstr, $flags, $context);
+ if (!$sock) return false;
+
+ $link = stream_socket_accept($sock);
+ if (!$link) return false; // bad link?
+
+ $r = array($link);
+ $w = array();
+ $e = array();
+ if (stream_select($r, $w, $e, 0, 1000) != 0)
+ $data .= fread($link, 8192);
+
+ $r = array();
+ $w = array($link);
+ if (stream_select($r, $w, $e, 0, 1000) != 0)
+ $wrote = fwrite($link, $data, strlen($data));
+
+ // close stuff
+ fclose($link);
+ fclose($sock);
+
+ exit;
+}
+
+function ssl_async_client($port) {
+ $host = 'ssl://127.0.0.1'.':'.$port;
+ $flags = STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT;
+ $data = "Sending data over to SSL server in async mode with contents like Hello World\n";
+
+ $socket = stream_socket_client($host, $errno, $errstr, 10, $flags);
+ stream_set_blocking($socket, 0);
+
+ while ($data) {
+ $wrote = fwrite($socket, $data, strlen($data));
+ $data = substr($data, $wrote);
+ }
+
+ $r = array($socket);
+ $w = array();
+ $e = array();
+ if (stream_select($r, $w, $e, 0, 10) != 0)
+ {
+ $data .= fread($socket, 1024);
+ }
+
+ echo "$data";
+
+ fclose($socket);
+}
+
+echo "Running bug48182\n";
+
+$port = rand(15000, 32000);
+
+$pid = pcntl_fork();
+if ($pid == 0) { // child
+ ssl_server($port);
+ exit;
+}
+
+// client or failed
+sleep(1);
+ssl_async_client($port);
+
+pcntl_waitpid($pid, $status);
+
+?>
+--EXPECTF--
+Running bug48182
+Sending bug48182
+Sending data over to SSL server in async mode with contents like Hello World
diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c
index 7c08ab147..9462e0f91 100644
--- a/ext/openssl/xp_ssl.c
+++ b/ext/openssl/xp_ssl.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: xp_ssl.c,v 1.22.2.3.2.9.2.10 2008/12/31 11:15:40 sebastian Exp $ */
+/* $Id: xp_ssl.c 289416 2009-10-09 14:20:17Z pajoye $ */
#include "php.h"
#include "ext/standard/file.h"
@@ -48,6 +48,7 @@ int php_openssl_get_x509_list_id(void);
typedef struct _php_openssl_netstream_data_t {
php_netstream_data_t s;
SSL *ssl_handle;
+ SSL_CTX *ctx;
struct timeval connect_timeout;
int enable_on_connect;
int is_client;
@@ -254,6 +255,14 @@ static int php_openssl_sockop_close(php_stream *stream, int close_handle TSRMLS_
SSL_free(sslsock->ssl_handle);
sslsock->ssl_handle = NULL;
}
+ if (sslsock->ctx) {
+ SSL_CTX_free(sslsock->ctx);
+ sslsock->ctx = NULL;
+ }
+#ifdef PHP_WIN32
+ if (sslsock->s.socket == -1)
+ sslsock->s.socket = SOCK_ERR;
+#endif
if (sslsock->s.socket != SOCK_ERR) {
#ifdef PHP_WIN32
/* prevent more data from coming in */
@@ -295,7 +304,6 @@ static inline int php_openssl_setup_crypto(php_stream *stream,
php_stream_xport_crypto_param *cparam
TSRMLS_DC)
{
- SSL_CTX *ctx;
SSL_METHOD *method;
if (sslsock->ssl_handle) {
@@ -344,18 +352,19 @@ static inline int php_openssl_setup_crypto(php_stream *stream,
}
- ctx = SSL_CTX_new(method);
- if (ctx == NULL) {
+ sslsock->ctx = SSL_CTX_new(method);
+ if (sslsock->ctx == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to create an SSL context");
return -1;
}
- SSL_CTX_set_options(ctx, SSL_OP_ALL);
+ SSL_CTX_set_options(sslsock->ctx, SSL_OP_ALL);
- sslsock->ssl_handle = php_SSL_new_from_context(ctx, stream TSRMLS_CC);
+ sslsock->ssl_handle = php_SSL_new_from_context(sslsock->ctx, stream TSRMLS_CC);
if (sslsock->ssl_handle == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to create an SSL handle");
- SSL_CTX_free(ctx);
+ SSL_CTX_free(sslsock->ctx);
+ sslsock->ctx = NULL;
return -1;
}
@@ -672,7 +681,11 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
* we notice that the connect has actually been established */
php_stream_socket_ops.set_option(stream, option, value, ptrparam TSRMLS_CC);
- if (xparam->outputs.returncode == 0 && sslsock->enable_on_connect) {
+ if ((sslsock->enable_on_connect) &&
+ ((xparam->outputs.returncode == 0) ||
+ (xparam->op == STREAM_XPORT_OP_CONNECT_ASYNC &&
+ xparam->outputs.returncode == 1 && xparam->outputs.error_code == EINPROGRESS)))
+ {
if (php_stream_xport_crypto_setup(stream, sslsock->method, NULL TSRMLS_CC) < 0 ||
php_stream_xport_crypto_enable(stream, 1 TSRMLS_CC) < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to enable crypto");
@@ -772,6 +785,9 @@ php_stream *php_openssl_ssl_socket_factory(const char *proto, long protolen,
* connecting */
sslsock->s.socket = -1;
+ /* Initialize context as NULL */
+ sslsock->ctx = NULL;
+
stream = php_stream_alloc_rel(&php_openssl_socket_ops, sslsock, persistent_id, "r+");
if (stream == NULL) {