Skip to content

Commit

Permalink
pkey/ec: avoid using EC#public_key= in EC#dh_compute_key
Browse files Browse the repository at this point in the history
Similarly to DH#compute_key, work around it by constructing a
SubjectPublicKeyInfo. This should be considered as a temporary
implementation.
  • Loading branch information
rhenium committed Dec 16, 2021
1 parent 46ca470 commit fc9aabc
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/openssl/pkey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,14 @@ def dsa_verify_asn1(data, sig)
# This method is provided for backwards compatibility, and calls #derive
# internally.
def dh_compute_key(pubkey)
peer = OpenSSL::PKey::EC.new(group)
peer.public_key = pubkey
derive(peer)
obj = OpenSSL::ASN1.Sequence([
OpenSSL::ASN1.Sequence([
OpenSSL::ASN1.ObjectId("id-ecPublicKey"),
group.to_der,
]),
OpenSSL::ASN1.BitString(pubkey.to_octet_string(:uncompressed)),
])
derive(OpenSSL::PKey.read(obj.to_der))
end
end

Expand Down

0 comments on commit fc9aabc

Please sign in to comment.