Skip to content

Commit fc9aabc

Browse files
committed
pkey/ec: avoid using EC#public_key= in EC#dh_compute_key
Similarly to DH#compute_key, work around it by constructing a SubjectPublicKeyInfo. This should be considered as a temporary implementation.
1 parent 46ca470 commit fc9aabc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/openssl/pkey.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,14 @@ def dsa_verify_asn1(data, sig)
259259
# This method is provided for backwards compatibility, and calls #derive
260260
# internally.
261261
def dh_compute_key(pubkey)
262-
peer = OpenSSL::PKey::EC.new(group)
263-
peer.public_key = pubkey
264-
derive(peer)
262+
obj = OpenSSL::ASN1.Sequence([
263+
OpenSSL::ASN1.Sequence([
264+
OpenSSL::ASN1.ObjectId("id-ecPublicKey"),
265+
group.to_der,
266+
]),
267+
OpenSSL::ASN1.BitString(pubkey.to_octet_string(:uncompressed)),
268+
])
269+
derive(OpenSSL::PKey.read(obj.to_der))
265270
end
266271
end
267272

0 commit comments

Comments
 (0)