summaryrefslogtreecommitdiff
path: root/lib/net/ssh/transport/openssl.rb
diff options
context:
space:
mode:
authorSimon Chopin <simon.chopin@canonical.com>2022-04-08 09:32:24 +0200
committerFlorian Wininger <fw.centrale@gmail.com>2022-04-29 14:42:49 +0200
commit4de6831dea4e922bf3052192eec143af015a3486 (patch)
tree377a26fdf5d37aa02463d07535fff304ab9fbfcd /lib/net/ssh/transport/openssl.rb
parent98ccff914983370a82208263c866482928031b88 (diff)
downloadnet-ssh-4de6831dea4e922bf3052192eec143af015a3486.tar.gz
transport: create EC 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/ssh/transport/openssl.rb')
-rw-r--r--lib/net/ssh/transport/openssl.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/net/ssh/transport/openssl.rb b/lib/net/ssh/transport/openssl.rb
index a398326..40561fb 100644
--- a/lib/net/ssh/transport/openssl.rb
+++ b/lib/net/ssh/transport/openssl.rb
@@ -159,10 +159,18 @@ module OpenSSL
public_key_oct = buffer.read_string
begin
- key = OpenSSL::PKey::EC.new(OpenSSL::PKey::EC::CurveNameAlias[curve_name_in_key])
- group = key.group
+ curvename = OpenSSL::PKey::EC::CurveNameAlias[curve_name_in_key]
+ group = OpenSSL::PKey::EC::Group.new(curvename)
point = OpenSSL::PKey::EC::Point.new(group, OpenSSL::BN.new(public_key_oct, 2))
- key.public_key = point
+ asn1 = OpenSSL::ASN1::Sequence([
+ OpenSSL::ASN1::Sequence([
+ OpenSSL::ASN1::ObjectId("id-ecPublicKey"),
+ OpenSSL::ASN1::ObjectId(curvename)
+ ]),
+ OpenSSL::ASN1::BitString(point.to_octet_string(:uncompressed))
+ ])
+
+ key = OpenSSL::PKey::EC.new(asn1.to_der)
return key
rescue OpenSSL::PKey::ECError