From f3e34edab55c87c1684078eff48405a2175da105 Mon Sep 17 00:00:00 2001 From: Eric Caruso Date: Fri, 21 Jun 2013 10:46:07 -0700 Subject: [PATCH] Match Zend behavior for openssl_pkey_get_{public,private} We weren't treating array(key, passphrase) correctly. Closes #815 --- hphp/runtime/ext/ext_openssl.cpp | 27 ++++++++------ .../openssl_pkey_get_passphrase.php | 36 +++++++++++++++++++ .../openssl_pkey_get_passphrase.php.expect | 2 ++ 3 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 hphp/test/slow/ext_openssl/openssl_pkey_get_passphrase.php create mode 100644 hphp/test/slow/ext_openssl/openssl_pkey_get_passphrase.php.expect diff --git a/hphp/runtime/ext/ext_openssl.cpp b/hphp/runtime/ext/ext_openssl.cpp index 575b182a3..2f5a4c1b0 100644 --- a/hphp/runtime/ext/ext_openssl.cpp +++ b/hphp/runtime/ext/ext_openssl.cpp @@ -181,6 +181,22 @@ public: */ static Object Get(CVarRef var, bool public_key, const char *passphrase = NULL) { + if (var.is(KindOfArray)) { + Array arr = var.toArray(); + if (!arr.exists(int64_t(0)) || !arr.exists(int64_t(1))) { + raise_warning("key array must be of the form " + "array(0 => key, 1 => phrase)"); + return Object(); + } + + String zphrase = arr[1].toString(); + return GetHelper(arr[0], public_key, zphrase.data()); + } + return GetHelper(var, public_key, passphrase); + } + + static Object GetHelper(CVarRef var, bool public_key, + const char *passphrase) { Object ocert; EVP_PKEY *key = NULL; @@ -217,17 +233,6 @@ public: BIO_free(in); } } else { - String zphrase; - if (var.is(KindOfArray)) { - Array arr = var.toArray(); - if (!arr.exists(int64_t(0)) || !arr.exists(int64_t(1))) { - raise_warning("key array must be of the form " - "array(0 => key, 1 => phrase)"); - return Object(); - } - zphrase = arr[1].toString(); - passphrase = zphrase.data(); - } /* we want the private key */ BIO *in = Certificate::ReadData(var); if (in == NULL) return Object(); diff --git a/hphp/test/slow/ext_openssl/openssl_pkey_get_passphrase.php b/hphp/test/slow/ext_openssl/openssl_pkey_get_passphrase.php new file mode 100644 index 000000000..f2b1ad913 --- /dev/null +++ b/hphp/test/slow/ext_openssl/openssl_pkey_get_passphrase.php @@ -0,0 +1,36 @@ +