diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-07-19 15:37:16 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-12-21 16:58:43 +0900 |
commit | 02c4176ed41907623211d8ca9e41fcacac3d0811 (patch) | |
tree | 1765078a38b137d75099960c78a402a7719931c1 /ext | |
parent | 528fae6f9e5f46dbf7e5871fbac1bb2e78c674fc (diff) | |
download | ruby-openssl-02c4176ed41907623211d8ca9e41fcacac3d0811.tar.gz |
pkey: allow instantiating OpenSSL::PKey::PKey with unsupported key type
Fix 'unsupported key type' error if OpenSSL::SSL::SSLSocket#tmp_key is
called when X25519 is used for key exchange.
EVP_PKEY may have a key type that we don't have have a dedicated
subclass. Let's allow instantiating OpenSSL::PKey::PKey with such an
EVP_PKEY, although the resulting instance is not so useful because it
can't be exported at the moment.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/openssl/ossl_pkey.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/ext/openssl/ossl_pkey.c b/ext/openssl/ossl_pkey.c index 9e6c6157..6ab1b618 100644 --- a/ext/openssl/ossl_pkey.c +++ b/ext/openssl/ossl_pkey.c @@ -73,10 +73,13 @@ const rb_data_type_t ossl_evp_pkey_type = { static VALUE pkey_new0(EVP_PKEY *pkey) { - if (!pkey) - ossl_raise(ePKeyError, "cannot make new key from NULL"); + VALUE obj; + int type; - switch (EVP_PKEY_base_id(pkey)) { + if (!pkey || (type = EVP_PKEY_base_id(pkey)) == EVP_PKEY_NONE) + ossl_raise(rb_eRuntimeError, "pkey is empty"); + + switch (type) { #if !defined(OPENSSL_NO_RSA) case EVP_PKEY_RSA: return ossl_rsa_new(pkey); @@ -94,7 +97,9 @@ pkey_new0(EVP_PKEY *pkey) return ossl_ec_new(pkey); #endif default: - ossl_raise(ePKeyError, "unsupported key type"); + obj = NewPKey(cPKey); + SetPKey(obj, pkey); + return obj; } } @@ -260,7 +265,7 @@ static VALUE ossl_pkey_initialize(VALUE self) { if (rb_obj_is_instance_of(self, cPKey)) { - ossl_raise(rb_eNotImpError, "OpenSSL::PKey::PKey is an abstract class."); + ossl_raise(rb_eTypeError, "OpenSSL::PKey::PKey can't be instantiated directly"); } return self; } |