From: Yui NARUSE Date: 2011-06-14T23:57:08+09:00 Subject: [ruby-dev:43813] [Ruby 1.9 - Bug #4879] test_new(OpenSSL::TestPKeyRSA) fails on Win32 Issue #4879 has been updated by Yui NARUSE. Martin Bosslet wrote: > My guess was that some uncleared error caused this > when several tests are run in sequence. > > I briefly checked and there are still fallback scenarios > in Ruby OpenSSL code where something is first interpreted > as PEM and then as DER or the other way round. This way > such an error as described is put into OpenSSL's own error > queue. Most C code now uses > > BIO_reset(bio); > ERR_get_error(); > > in conjunction now. For the those places and the remaining > code that does not yet I'd propose to expose this functionality > as a public macro and I would use it where appropriate. This > would prevent test failures as described here in the future. > > What do you think? I agree with it, such way is suitable than my hack. ---------------------------------------- Bug #4879: test_new(OpenSSL::TestPKeyRSA) fails on Win32 http://redmine.ruby-lang.org/issues/4879 Author: Akio Tajima Status: Closed Priority: Normal Assignee: Martin Bosslet Category: ext Target version: 1.9.3 ruby -v: ruby 1.9.3dev (2011-06-13) [i386-mswin32_100] こんばんは。 opensslのtest_pkey_rsa.rb:48 がfailします。Visual C++10 を利用しています。 1) Failure: test_new(OpenSSL::TestPKeyRSA) [C:/Users/arton/Documents/ruby/trunk/test/openssl/test_pkey_rsa.rb:48]: <[]> expected but was <["error:0906D06C:PEM routines:PEM_read_bio:no start line"]>. このエラーは数回試しましたが常に発生します。 ところが、ここでテストしているRubyをインストールして同じ処理を実行すると期待している結果が得られます。 irb(main):001:0> require 'openssl' => true irb(main):002:0> key = OpenSSL::PKey::RSA.new 512 => -----BEGIN RSA PRIVATE KEY----- MIIBOgIBAAJBAMuc7mPnOVmPweq1XMZrOZaOMVoTCX88fsU4460qF0me4S+yGL90 (省略) -----END RSA PRIVATE KEY----- irb(main):003:0> pem = key.public_key.to_pem => "-----BEGIN PUBLIC KEY-----\nMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMuc7mPnOVmPweq1 XMZrOZaOMVoTCX88\nfsU4460qF0me4S+yGL902+yR5Gv2R6B4QvE5EnxGY5zD9t355+IKaQMCAwEAAQ ==\n-----END PUBLIC KEY-----\n" irb(main):004:0> OpenSSL::PKey::RSA.new pem => -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMuc7mPnOVmPweq1XMZrOZaOMVoTCX88 fsU4460qF0me4S+yGL902+yR5Gv2R6B4QvE5EnxGY5zD9t355+IKaQMCAwEAAQ== -----END PUBLIC KEY----- irb(main):005:0> OpenSSL.errors => [] もしかすると、test_newの前にエラーが設定されていてそれが読まれているのかと思って、次のようにtest_newを変えて実行したところ、 def test_new $stderr.puts OpenSSL.errors.inspect $stderr.flush key = OpenSSL::PKey::RSA.new 512 pem = key.public_key.to_pem OpenSSL::PKey::RSA.new pem assert_equal([], OpenSSL.errors) end 上のように修正するとfailしなくなりましたが、取得されるエラーは以下でした。これも数回試しましたが常に同じメッセージです。 .........................................................["error:0D07803A:asn1 e ncoding routines:ASN1_ITEM_EX_D2I:nested asn1 error"]...(省略) OpenSSLは1.0.0aです。 irb(main):001:0> require 'openssl' => true irb(main):002:0> OpenSSL::OPENSSL_VERSION => "OpenSSL 1.0.0a 1 Jun 2010" よろしくお願いします。 -- http://redmine.ruby-lang.org