diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2017-03-21 18:23:53 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2020-05-13 16:17:20 +0900 |
commit | f4c717bcb2276c3c3dbe4ec3da159d6f6b3ff861 (patch) | |
tree | 76163c1ad1dd33dcba3b3296b77685689290603c /ext | |
parent | 41587f69e17b9f0983c1f2a37b8661599119fc0e (diff) | |
download | ruby-openssl-f4c717bcb2276c3c3dbe4ec3da159d6f6b3ff861.tar.gz |
pkey: assume generic PKeys contain private components
The EVP interface cannot tell whether if a pkey contains the private
components or not. Assume it does if it does not respond to #private?.
This fixes the NoMethodError on calling #sign on a generic PKey.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/openssl/ossl_pkey.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/ext/openssl/ossl_pkey.c b/ext/openssl/ossl_pkey.c index 23204087..516ee8b3 100644 --- a/ext/openssl/ossl_pkey.c +++ b/ext/openssl/ossl_pkey.c @@ -246,12 +246,19 @@ GetPrivPKeyPtr(VALUE obj) { EVP_PKEY *pkey; - if (rb_funcallv(obj, id_private_q, 0, NULL) != Qtrue) { - ossl_raise(rb_eArgError, "Private key is needed."); - } GetPKey(obj, pkey); + if (OSSL_PKEY_IS_PRIVATE(obj)) + return pkey; + /* + * The EVP API does not provide a way to check if the EVP_PKEY has private + * components. Assuming it does... + */ + if (!rb_respond_to(obj, id_private_q)) + return pkey; + if (RTEST(rb_funcallv(obj, id_private_q, 0, NULL))) + return pkey; - return pkey; + rb_raise(rb_eArgError, "private key is needed"); } EVP_PKEY * |