diff options
author | Rob Richards <rrichards@php.net> | 2007-01-20 22:08:29 +0000 |
---|---|---|
committer | Rob Richards <rrichards@php.net> | 2007-01-20 22:08:29 +0000 |
commit | 75fdefba0cdaf5d3c159df9b0ddaf5f90e88ba37 (patch) | |
tree | 8092d05e23a185eb879481c35f7b933e5b6c911d | |
parent | 6bef5f8e80560165a3c64ecc88fd4415205bf4b3 (diff) | |
download | php-git-75fdefba0cdaf5d3c159df9b0ddaf5f90e88ba37.tar.gz |
MFH: fix accessing public key from x509 resource
add test
fix test under win32
-rw-r--r-- | ext/openssl/openssl.c | 6 | ||||
-rw-r--r-- | ext/openssl/tests/005.phpt | 34 | ||||
-rw-r--r-- | ext/openssl/tests/bug38261.phpt | 4 |
3 files changed, 39 insertions, 5 deletions
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 638005a52c..3ccde2f27b 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -1958,10 +1958,10 @@ static EVP_PKEY * php_openssl_evp_from_zval(zval ** val, int public_key, char * /* got the key - return it */ return (EVP_PKEY*)what; } + } else { + /* other types could be used here - eg: file pointers and read in the data from them */ + TMP_CLEAN; } - - /* other types could be used here - eg: file pointers and read in the data from them */ - TMP_CLEAN; } else { /* force it to be a string and check if it refers to a file */ /* passing non string values leaks, object uses toString, it returns NULL diff --git a/ext/openssl/tests/005.phpt b/ext/openssl/tests/005.phpt new file mode 100644 index 0000000000..069c94580c --- /dev/null +++ b/ext/openssl/tests/005.phpt @@ -0,0 +1,34 @@ +--TEST-- +openSSL: read public key from x.509 resource +--SKIPIF-- +<?php +if (!extension_loaded("openssl")) die("skip"); +?> +--FILE-- +<?php +$dir = dirname(__FILE__); +$file_pub = $dir . '/bug37820cert.pem'; +$file_key = $dir . '/bug37820key.pem'; + +$priv_key = file_get_contents($file_key); +$priv_key_id = openssl_get_privatekey($priv_key); + +$x509 = openssl_x509_read(file_get_contents($file_pub)); + +$pub_key_id = openssl_get_publickey($x509); +$data = "some custom data"; +if (!openssl_sign($data, $signature, $priv_key_id, OPENSSL_ALGO_MD5)) { + echo "openssl_sign failed."; +} + +$ok = openssl_verify($data, $signature, $pub_key_id, OPENSSL_ALGO_MD5); +if ($ok == 1) { + echo "Ok"; +} elseif ($ok == 0) { + echo "openssl_verify failed."; +} + + +?> +--EXPECTF-- +Ok diff --git a/ext/openssl/tests/bug38261.phpt b/ext/openssl/tests/bug38261.phpt index e7d806083e..b06fa4f8fe 100644 --- a/ext/openssl/tests/bug38261.phpt +++ b/ext/openssl/tests/bug38261.phpt @@ -27,8 +27,8 @@ bool(false) bool(false) bool(false) -Warning: openssl_x509_parse() expects at least 1 parameter, 0 given in %s/bug38261.php on line %d +Warning: openssl_x509_parse() expects at least 1 parameter, 0 given in %sbug38261.php on line %d NULL bool(false) -Catchable fatal error: Object of class stdClass could not be converted to string in %s/bug38261.php on line %d +Catchable fatal error: Object of class stdClass could not be converted to string in %sbug38261.php on line %d |