aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2021-12-17 02:22:25 +0900
committerKazuki Yamaguchi <k@rhe.jp>2021-12-17 02:38:12 +0900
commitfc9aabc18df3c189cc6a76a1470ca908c4f16480 (patch)
treeef4a49878f0b677db4ee83e208ceda787aeeb4f8
parent46ca47060ca8ef3419ec36c2326a81b442d9b43b (diff)
downloadruby-openssl-fc9aabc18df3c189cc6a76a1470ca908c4f16480.tar.gz
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.
-rw-r--r--lib/openssl/pkey.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/openssl/pkey.rb b/lib/openssl/pkey.rb
index 5864faa9..ba04cf4b 100644
--- a/lib/openssl/pkey.rb
+++ b/lib/openssl/pkey.rb
@@ -259,9 +259,14 @@ module OpenSSL::PKey
# 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