php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #50293
Patch bug-50293 revision 2010-08-12 01:31 UTC by kalle@php.net

Patch bug-50293 for OpenSSL related Bug #50293

Patch version 2010-08-12 01:31 UTC

Return to Bug #50293 | Download this patch
Patch Revisions:

Developer: kalle@php.net

Index: openssl.c
===================================================================
--- openssl.c	(revision 302121)
+++ openssl.c	(working copy)
@@ -68,6 +68,19 @@
 
 #define DEBUG_SMIME	0
 
+#define PHP_OPENSSL_EXPORT_FILE(buffer, file, mode) \
+	{ \
+		FILE *_export_fp = php_fopen_with_path(file, mode, NULL, NULL TSRMLS_CC); \
+		buffer = BIO_new(BIO_s_file()); \
+	\
+		if (!buffer || !_export_fp) { \
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open export file for writing"); \
+			RETVAL_FALSE; \
+		} else { \
+			BIO_set_fp(buffer, _export_fp, BIO_CLOSE); \
+		} \
+	} \
+
 /* FIXME: Use the openssl constants instead of
  * enum. It is now impossible to match real values
  * against php constants. Also sorry to break the
@@ -1250,7 +1263,7 @@
 	X509 * cert;
 	zval ** zcert;
 	zend_bool notext = 1;
-	BIO * bio_out;
+	BIO * bio_out = NULL;
 	long certresource;
 	char * filename;
 	int filename_len;
@@ -1270,7 +1283,7 @@
 		return;
 	}
 
-	bio_out = BIO_new_file(filename, "w");
+	PHP_OPENSSL_EXPORT_FILE(bio_out, filename, "w")
 	if (bio_out) {
 		if (!notext) {
 			X509_print(bio_out, cert);
@@ -1844,7 +1857,7 @@
 
 	p12 = PKCS12_create(pass, friendly_name, priv_key, cert, ca, 0, 0, 0, 0, 0);
 
-	bio_out = BIO_new_file(filename, "w"); 
+	PHP_OPENSSL_EXPORT_FILE(bio_out, filename, "w")
 	if (bio_out) {
 		
 		i2d_PKCS12_bio(bio_out, p12);
@@ -2247,7 +2260,7 @@
 	zval * zcsr = NULL;
 	zend_bool notext = 1;
 	char * filename = NULL; int filename_len;
-	BIO * bio_out;
+	BIO * bio_out = NULL;
 	long csr_resource;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|b", &zcsr, &filename, &filename_len, &notext) == FAILURE) {
@@ -2265,7 +2278,7 @@
 		return;
 	}
 
-	bio_out = BIO_new_file(filename, "w");
+	PHP_OPENSSL_EXPORT_FILE(bio_out, filename, "w")
 	if (bio_out) {
 		if (!notext) {
 			X509_REQ_print(bio_out, csr);
@@ -3053,7 +3066,7 @@
 	PHP_SSL_REQ_INIT(&req);
 
 	if (PHP_SSL_REQ_PARSE(&req, args) == SUCCESS) {
-		bio_out = BIO_new_file(filename, "w");
+		PHP_OPENSSL_EXPORT_FILE(bio_out, filename, "w")
 
 		if (passphrase && req.priv_key_encrypt) {
 			if (req.priv_key_encrypt_cipher) {
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Nov 25 01:01:31 2024 UTC