lib/googleauth/id_tokens/key_sources.rb in googleauth-1.2.0 vs lib/googleauth/id_tokens/key_sources.rb in googleauth-1.3.0
- old
+ new
@@ -128,17 +128,12 @@
rescue ArgumentError
raise KeySourceError, "Badly formatted key data"
end
n_bn = OpenSSL::BN.new n_data, 2
e_bn = OpenSSL::BN.new e_data, 2
- rsa_key = OpenSSL::PKey::RSA.new
- if rsa_key.respond_to? :set_key
- rsa_key.set_key n_bn, e_bn, nil
- else
- rsa_key.n = n_bn
- rsa_key.e = e_bn
- end
+ sequence = [OpenSSL::ASN1::Integer.new(n_bn), OpenSSL::ASN1::Integer.new(e_bn)]
+ rsa_key = OpenSSL::PKey::RSA.new OpenSSL::ASN1::Sequence(sequence).to_der
rsa_key.public_key
end
# @private
CURVE_NAME_MAP = {
@@ -159,12 +154,16 @@
raise KeySourceError, "Unsupported EC curve #{jwk[:crv]}" unless curve_name
group = OpenSSL::PKey::EC::Group.new curve_name
x_hex = x_data.unpack1 "H*"
y_hex = y_data.unpack1 "H*"
bn = OpenSSL::BN.new ["04#{x_hex}#{y_hex}"].pack("H*"), 2
- key = OpenSSL::PKey::EC.new curve_name
- key.public_key = OpenSSL::PKey::EC::Point.new group, bn
- key
+ point = OpenSSL::PKey::EC::Point.new group, bn
+ sequence = OpenSSL::ASN1::Sequence([
+ OpenSSL::ASN1::Sequence([OpenSSL::ASN1::ObjectId("id-ecPublicKey"),
+ OpenSSL::ASN1::ObjectId(curve_name)]),
+ OpenSSL::ASN1::BitString(point.to_octet_string(:uncompressed))
+ ])
+ OpenSSL::PKey::EC.new sequence.to_der
end
end
end
##