diff options
author | Simon Chopin <simon.chopin@canonical.com> | 2022-04-08 09:32:24 +0200 |
---|---|---|
committer | Florian Wininger <fw.centrale@gmail.com> | 2022-04-29 14:42:49 +0200 |
commit | 406063de2852cabe7d123c9dd72a72c4cfff8215 (patch) | |
tree | ee7c7daf619c60e8f453d822cc50d84a72ee6f70 /lib/net | |
parent | e4ffdc07b1f0f01ebeab359c1001984912d87437 (diff) | |
download | net-ssh-406063de2852cabe7d123c9dd72a72c4cfff8215.tar.gz |
buffer: create RSA keys by loading PEM data directly
The OpenSSL 3.0 changes don't allow for us to modify the private key
details directly, and there are no dedicated constructors as of Ruby
3.0, so we need to actually create a PEM certificate in-memory and load
that instead.
Co-authored-by: Lucas Kanashiro <lucas.kanashiro@canonical.com>
Diffstat (limited to 'lib/net')
-rw-r--r-- | lib/net/ssh/buffer.rb | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/net/ssh/buffer.rb b/lib/net/ssh/buffer.rb index 6ed5789..8a67d3e 100644 --- a/lib/net/ssh/buffer.rb +++ b/lib/net/ssh/buffer.rb @@ -315,15 +315,15 @@ module Net key.pub_key = read_bignum end when /^ssh-rsa$/ - key = OpenSSL::PKey::RSA.new - if key.respond_to?(:set_key) - e = read_bignum - n = read_bignum - key.set_key(n, e, nil) - else - key.e = read_bignum - key.n = read_bignum - end + e = read_bignum + n = read_bignum + + asn1 = OpenSSL::ASN1::Sequence([ + OpenSSL::ASN1::Integer(n), + OpenSSL::ASN1::Integer(e) + ]) + + key = OpenSSL::PKey::RSA.new(asn1.to_der) when /^ssh-ed25519$/ Net::SSH::Authentication::ED25519Loader.raiseUnlessLoaded("unsupported key type `#{type}'") key = Net::SSH::Authentication::ED25519::PubKey.read_keyblob(self) |