Skip to content

Commit

Permalink
Don't use the deprecated set_XXX methods on RSA keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
bschmeck authored and fwininger committed Feb 8, 2023
1 parent ab74b03 commit d9b259c
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions lib/net/ssh/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ def read_key
def read_private_keyblob(type)
case type
when /^ssh-rsa$/
key = OpenSSL::PKey::RSA.new
n = read_bignum
e = read_bignum
d = read_bignum
Expand All @@ -262,27 +261,28 @@ def read_private_keyblob(type)
_unkown2 = read_bignum
dmp1 = d % (p - 1)
dmq1 = d % (q - 1)
if key.respond_to?(:set_key)
key.set_key(n, e, d)
else
key.e = e
key.n = n
key.d = d
end
if key.respond_to?(:set_factors)
key.set_factors(p, q)
else
key.p = p
key.q = q
# Public key
data_sequence = OpenSSL::ASN1::Sequence([
OpenSSL::ASN1::Integer(n),
OpenSSL::ASN1::Integer(e),
])

if d && p && q && dmp1 && dmq1 && iqmp
data_sequence = OpenSSL::ASN1::Sequence([
OpenSSL::ASN1::Integer(0),
OpenSSL::ASN1::Integer(n),
OpenSSL::ASN1::Integer(e),
OpenSSL::ASN1::Integer(d),
OpenSSL::ASN1::Integer(p),
OpenSSL::ASN1::Integer(q),
OpenSSL::ASN1::Integer(dmp1),
OpenSSL::ASN1::Integer(dmq1),
OpenSSL::ASN1::Integer(iqmp),
])
end
if key.respond_to?(:set_crt_params)
key.set_crt_params(dmp1, dmq1, iqmp)
else
key.dmp1 = dmp1
key.dmq1 = dmq1
key.iqmp = iqmp
end
key

asn1 = OpenSSL::ASN1::Sequence(data_sequence)
OpenSSL::PKey::RSA.new(asn1.to_der)
when /^ecdsa\-sha2\-(\w*)$/
OpenSSL::PKey::EC.read_keyblob($1, self)
else
Expand Down

0 comments on commit d9b259c

Please sign in to comment.