[前][次][番号順一覧][スレッド一覧]

ruby-changes:70367

From: Kazuki <ko1@a...>
Date: Tue, 21 Dec 2021 00:11:30 +0900 (JST)
Subject: [ruby-changes:70367] 50b90c5fc3 (master): [ruby/openssl] pkey/ec: avoid using EC#public_key= in EC#dh_compute_key

https://git.ruby-lang.org/ruby.git/commit/?id=50b90c5fc3

From 50b90c5fc3480d3193c9cf161c2a6e71cc688189 Mon Sep 17 00:00:00 2001
From: Kazuki Yamaguchi <k@r...>
Date: Fri, 17 Dec 2021 02:22:25 +0900
Subject: [ruby/openssl] 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.

https://github.com/ruby/openssl/commit/fc9aabc18d
---
 ext/openssl/lib/openssl/pkey.rb | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/ext/openssl/lib/openssl/pkey.rb b/ext/openssl/lib/openssl/pkey.rb
index 5864faa919d..ba04cf4b393 100644
--- a/ext/openssl/lib/openssl/pkey.rb
+++ b/ext/openssl/lib/openssl/pkey.rb
@@ -259,9 +259,14 @@ module OpenSSL::PKey https://github.com/ruby/ruby/blob/trunk/ext/openssl/lib/openssl/pkey.rb#L259
     # 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
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]