diff --git a/hphp/runtime/ext/ext_openssl.cpp b/hphp/runtime/ext/ext_openssl.cpp index 945c449b0..575b182a3 100644 --- a/hphp/runtime/ext/ext_openssl.cpp +++ b/hphp/runtime/ext/ext_openssl.cpp @@ -1655,6 +1655,35 @@ static const StaticString s_alias("alias"); static const StaticString s_purposes("purposes"); static const StaticString s_extensions("extensions"); +static const StaticString s_rsa("rsa"); +static const StaticString s_dsa("dsa"); +static const StaticString s_dh("dh"); + +static const StaticString s_n("n"); +static const StaticString s_e("e"); +static const StaticString s_d("d"); +static const StaticString s_p("p"); +static const StaticString s_q("q"); +static const StaticString s_g("g"); +static const StaticString s_dmp1("dmp1"); +static const StaticString s_dmq1("dmq1"); +static const StaticString s_iqmp("iqmp"); +static const StaticString s_priv_key("priv_key"); +static const StaticString s_pub_key("pub_key"); + +static void add_bignum_as_string(Array &arr, + StaticString key, + BIGNUM *bn) { + if (!bn) { + return; + } + int num_bytes = BN_num_bytes(bn); + unsigned char *out = (unsigned char *)smart_malloc(num_bytes); + BN_bn2bin(bn, out); + arr.set(key, String((const char *)out, num_bytes, CopyString)); + smart_free(out); +} + Array f_openssl_pkey_get_details(CObjRef key) { EVP_PKEY *pkey = key.getTyped()->m_key; BIO *out = BIO_new(BIO_s_mem()); @@ -1666,14 +1695,48 @@ Array f_openssl_pkey_get_details(CObjRef key) { ret.set(s_bits, EVP_PKEY_bits(pkey)); ret.set(s_key, String(pbio, pbio_len, CopyString)); long ktype = -1; + + Array details; + RSA *rsa = pkey->pkey.rsa; + DSA *dsa = pkey->pkey.dsa; + DH *dh = pkey->pkey.dh; switch (EVP_PKEY_type(pkey->type)) { case EVP_PKEY_RSA: - case EVP_PKEY_RSA2: ktype = k_OPENSSL_KEYTYPE_RSA; break; + case EVP_PKEY_RSA2: + ktype = k_OPENSSL_KEYTYPE_RSA; + assert(rsa); + add_bignum_as_string(details, s_n, rsa->n); + add_bignum_as_string(details, s_e, rsa->e); + add_bignum_as_string(details, s_d, rsa->d); + add_bignum_as_string(details, s_p, rsa->p); + add_bignum_as_string(details, s_q, rsa->q); + add_bignum_as_string(details, s_dmp1, rsa->dmp1); + add_bignum_as_string(details, s_dmq1, rsa->dmq1); + add_bignum_as_string(details, s_iqmp, rsa->iqmp); + ret.set(s_rsa, details); + break; case EVP_PKEY_DSA: case EVP_PKEY_DSA2: case EVP_PKEY_DSA3: - case EVP_PKEY_DSA4: ktype = k_OPENSSL_KEYTYPE_DSA; break; - case EVP_PKEY_DH: ktype = k_OPENSSL_KEYTYPE_DH; break; + case EVP_PKEY_DSA4: + ktype = k_OPENSSL_KEYTYPE_DSA; + assert(dsa); + add_bignum_as_string(details, s_p, dsa->p); + add_bignum_as_string(details, s_q, dsa->q); + add_bignum_as_string(details, s_g, dsa->g); + add_bignum_as_string(details, s_priv_key, dsa->priv_key); + add_bignum_as_string(details, s_pub_key, dsa->pub_key); + ret.set(s_dsa, details); + break; + case EVP_PKEY_DH: + ktype = k_OPENSSL_KEYTYPE_DH; + assert(dh); + add_bignum_as_string(details, s_p, dh->p); + add_bignum_as_string(details, s_g, dh->g); + add_bignum_as_string(details, s_priv_key, dh->priv_key); + add_bignum_as_string(details, s_pub_key, dh->pub_key); + ret.set(s_dh, details); + break; #ifdef EVP_PKEY_EC case EVP_PKEY_EC: ktype = k_OPENSSL_KEYTYPE_EC; break; #endif diff --git a/hphp/test/slow/ext_openssl/openssl_pkey_get_details.php b/hphp/test/slow/ext_openssl/openssl_pkey_get_details.php new file mode 100644 index 000000000..cb3f259a0 --- /dev/null +++ b/hphp/test/slow/ext_openssl/openssl_pkey_get_details.php @@ -0,0 +1,16 @@ + + diff --git a/hphp/test/slow/ext_openssl/openssl_pkey_get_details.php.expect b/hphp/test/slow/ext_openssl/openssl_pkey_get_details.php.expect new file mode 100644 index 000000000..a92cd31e2 Binary files /dev/null and b/hphp/test/slow/ext_openssl/openssl_pkey_get_details.php.expect differ diff --git a/hphp/test/slow/ext_openssl/openssl_pkey_get_details_2.php b/hphp/test/slow/ext_openssl/openssl_pkey_get_details_2.php new file mode 100644 index 000000000..523f68c31 --- /dev/null +++ b/hphp/test/slow/ext_openssl/openssl_pkey_get_details_2.php @@ -0,0 +1,24 @@ + diff --git a/hphp/test/slow/ext_openssl/openssl_pkey_get_details_2.php.expect b/hphp/test/slow/ext_openssl/openssl_pkey_get_details_2.php.expect new file mode 100644 index 000000000..d9381b8e0 Binary files /dev/null and b/hphp/test/slow/ext_openssl/openssl_pkey_get_details_2.php.expect differ diff --git a/hphp/test/slow/ext_openssl/openssl_pkey_get_details_3.php b/hphp/test/slow/ext_openssl/openssl_pkey_get_details_3.php new file mode 100644 index 000000000..180f642b6 --- /dev/null +++ b/hphp/test/slow/ext_openssl/openssl_pkey_get_details_3.php @@ -0,0 +1,46 @@ + + diff --git a/hphp/test/slow/ext_openssl/openssl_pkey_get_details_3.php.expect b/hphp/test/slow/ext_openssl/openssl_pkey_get_details_3.php.expect new file mode 100644 index 000000000..c7f89413b Binary files /dev/null and b/hphp/test/slow/ext_openssl/openssl_pkey_get_details_3.php.expect differ diff --git a/hphp/test/slow/ext_openssl/openssl_pkey_get_details_4.php b/hphp/test/slow/ext_openssl/openssl_pkey_get_details_4.php new file mode 100644 index 000000000..aa08f5bbd --- /dev/null +++ b/hphp/test/slow/ext_openssl/openssl_pkey_get_details_4.php @@ -0,0 +1,44 @@ + diff --git a/hphp/test/slow/ext_openssl/openssl_pkey_get_details_4.php.expect b/hphp/test/slow/ext_openssl/openssl_pkey_get_details_4.php.expect new file mode 100644 index 000000000..a427cc7d8 Binary files /dev/null and b/hphp/test/slow/ext_openssl/openssl_pkey_get_details_4.php.expect differ