Project

General

Profile

Actions

Bug #12726

closed

OpenSSL::PKCS12.new がプライベートキーを含まないデータでエラーになる

Added by tommy (Masahiro Tomita) over 7 years ago. Updated over 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.0preview1 (2016-06-20 trunk 55466) [x86_64-linux]
[ruby-dev:49776]

Description

次のように作成したプライベートキーを含まない pfx ファイルを、

% openssl pkcs12 -export -out hoge.pfx -in hoge.pem -nokeys
Enter Export Password:hoge
Verifying - Enter Export Password:hoge

OpenSSL::PKCS12.new で読み込むとエラーになります。

% ruby -ropenssl -e 'OpenSSL::PKCS12.new(File.read("hoge.pfx"), "hoge")'
-e:1:in `initialize': Cannot make new key from NULL. (OpenSSL::PKey::PKeyError)
	from -e:1:in `new'
	from -e:1:in `<main>'

Ruby 2.1, 2.2, 2.3 でも同様でした。

次のパッチで直ります。

--- a/ext/openssl/ossl_pkcs12.c
+++ b/ext/openssl/ossl_pkcs12.c
@@ -190,9 +190,11 @@ ossl_pkcs12_initialize(int argc, VALUE *argv, VALUE self)
     if(!PKCS12_parse(pkcs, passphrase, &key, &x509, &x509s))
 	ossl_raise(ePKCS12Error, "PKCS12_parse");
     ERR_pop_to_mark();
-    pkey = rb_protect((VALUE (*)(VALUE))ossl_pkey_new, (VALUE)key,
-		      &st); /* NO DUP */
-    if(st) goto err;
+    if (key) {
+	pkey = rb_protect((VALUE (*)(VALUE))ossl_pkey_new, (VALUE)key,
+			  &st); /* NO DUP */
+	if(st) goto err;
+    }
     cert = rb_protect((VALUE (*)(VALUE))ossl_x509_new, (VALUE)x509, &st);
     if(st) goto err;
     if(x509s){

Updated by rhenium (Kazuki Yamaguchi) over 7 years ago

  • Status changed from Open to Closed
  • Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: UNKNOWN, 2.2: REQUIRED, 2.3: REQUIRED

ありがとうございます。

同様に x509 も NULL になる場合があり、それもあわせて ruby/openssl に取り込みました。

https://github.com/ruby/openssl/commit/68ca4b61bf43a22581ebb5649252a65633a1b680

Actions

Also available in: Atom PDF

Like0
Like0