From 6048ac32b4e8fc5dacb89af7e4408e3116609317 Mon Sep 17 00:00:00 2001 From: Dominic Luechinger Date: Mon, 24 Nov 2014 02:31:19 +0100 Subject: [PATCH] Adds test cases for openssl EC improvements --- ext/openssl/openssl.c | 15 ++++----- ext/openssl/tests/027.phpt | 52 ++++++++++++++++++++++++++++++++ ext/openssl/tests/028.phpt | 28 +++++++++++++++++ ext/openssl/tests/private_ec.key | 5 +++ ext/openssl/tests/public_ec.key | 4 +++ 5 files changed, 97 insertions(+), 7 deletions(-) create mode 100644 ext/openssl/tests/027.phpt create mode 100644 ext/openssl/tests/028.phpt create mode 100644 ext/openssl/tests/private_ec.key create mode 100644 ext/openssl/tests/public_ec.key diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index a1304437d74..b221d96602c 100755 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -3487,8 +3487,8 @@ PHP_FUNCTION(openssl_pkey_get_details) if (pkey->pkey.ec == NULL) { break; } - - zval ec; + { + zval *ec; const EC_GROUP *ec_group; int nid; char *crv_sn; @@ -3503,24 +3503,25 @@ PHP_FUNCTION(openssl_pkey_get_details) if (nid == NID_undef) { break; } - - array_init(&ec); + ALLOC_INIT_ZVAL(ec); + array_init(ec); // Short object name crv_sn = (char*) OBJ_nid2sn(nid); if (crv_sn != NULL) { - add_assoc_string(&ec, "curve_name", crv_sn); + add_assoc_string(ec, "curve_name", crv_sn, 1); } obj = OBJ_nid2obj(nid); if (obj != NULL) { int oir_len = OBJ_obj2txt(oir_buf, sizeof(oir_buf), obj, 1); - add_assoc_stringl(&ec, "curve_oid", (char*)oir_buf, oir_len); + add_assoc_stringl(ec, "curve_oid", (char*)oir_buf, oir_len, 1); ASN1_OBJECT_free(obj); } - add_assoc_zval(return_value, "ec", &ec); + add_assoc_zval(return_value, "ec", ec); break; + } #endif default: ktype = -1; diff --git a/ext/openssl/tests/027.phpt b/ext/openssl/tests/027.phpt new file mode 100644 index 00000000000..8311ab1bd92 --- /dev/null +++ b/ext/openssl/tests/027.phpt @@ -0,0 +1,52 @@ +--TEST-- +openssl_pkey_export() with EC key +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +resource(%d) of type (OpenSSL key) +bool(true) +-----BEGIN EC PRIVATE KEY-----%a-----END EC PRIVATE KEY----- +bool(true) +bool(true) +resource(%d) of type (OpenSSL key) +bool(true) +bool(true) +bool(true) diff --git a/ext/openssl/tests/028.phpt b/ext/openssl/tests/028.phpt new file mode 100644 index 00000000000..8e0cef46c07 --- /dev/null +++ b/ext/openssl/tests/028.phpt @@ -0,0 +1,28 @@ +--TEST-- +openssl_pkey_get_details() with EC key +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Array +( + [bits] => 256 + [key] => -----BEGIN PUBLIC KEY-----%a +-----END PUBLIC KEY----- + + [ec] => Array + ( + [curve_name] => prime256v1 + [curve_oid] => 1.2.840.10045.3.1.7 + ) + + [type] => 3 +) diff --git a/ext/openssl/tests/private_ec.key b/ext/openssl/tests/private_ec.key new file mode 100644 index 00000000000..51cdcb728bf --- /dev/null +++ b/ext/openssl/tests/private_ec.key @@ -0,0 +1,5 @@ +-----BEGIN EC PRIVATE KEY----- +MHcCAQEEILPkqoeyM7XgwYkuSj3077lrsrfWJK5LqMolv+m2oOjZoAoGCCqGSM49 +AwEHoUQDQgAEPq4hbIWHvB51rdWr8ejrjWo4qVNWVugYFtPg/xLQw0mHkIPZ4DvK +sqOTOnMoezkbSmVVMuwz9flvnqHGmQvmug== +-----END EC PRIVATE KEY----- diff --git a/ext/openssl/tests/public_ec.key b/ext/openssl/tests/public_ec.key new file mode 100644 index 00000000000..a93b2c8ab4c --- /dev/null +++ b/ext/openssl/tests/public_ec.key @@ -0,0 +1,4 @@ +-----BEGIN PUBLIC KEY----- +MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEPq4hbIWHvB51rdWr8ejrjWo4qVNW +VugYFtPg/xLQw0mHkIPZ4DvKsqOTOnMoezkbSmVVMuwz9flvnqHGmQvmug== +-----END PUBLIC KEY-----