Project

General

Profile

Actions

Bug #4879

closed

test_new(OpenSSL::TestPKeyRSA) fails on Win32

Added by arton (Akio Tajima) almost 13 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
ruby -v:
-
Backport:
[ruby-dev:43791]

Description

こんばんは。
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"

よろしくお願いします。


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #4885: [ext/openssl] Use BIO_reset and ERR_get_error in conjuntionClosedMartinBosslet (Martin Bosslet)06/14/2011Actions

Updated by jonforums (Jon Forums) almost 13 years ago

This failure also occurs when building trunk@32072 with MinGW GCC v4.5.2 (TDM) and OpenSSL 1.0.0d:

sh-3.1$ make test-all TESTS='openssl fiddle psych'
...

  1. Failure:
    test_new(OpenSSL::TestPKeyRSA) [c:/Users/Jon/Documents/RubyDev/ruby-git/test/openssl/test_pkey_rsa.rb:48]:
    <[]> expected but was
    <["error:0906D06C:PEM routines:PEM_read_bio:no start line"]>.

sh-3.1$ ruby --version
ruby 1.9.3dev (2011-06-14 trunk 32072) [i386-mingw32]

sh-3.1$ ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION'
OpenSSL 1.0.0d 8 Feb 2011

Updated by MartinBosslet (Martin Bosslet) almost 13 years ago

  • Category set to ext
  • Status changed from Open to Assigned
  • Assignee set to MartinBosslet (Martin Bosslet)

Thanks for reporting this! I might have an idea, I'll see what I can find out.

Regards,
Martin

Actions #3

Updated by naruse (Yui NARUSE) almost 13 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r32076.
Akio, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


Clear error messages before process and get errors. [ruby-dev:43791] [Bug #4879]

Updated by MartinBosslet (Martin Bosslet) almost 13 years ago

Thanks, Yui, for the fix!

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?

Regards,
Martin

PS: I opened a new issue for this (http://redmine.ruby-lang.org/issues/4885)
so that the others are also aware and can intervene should they have any
doubts or objections.

Updated by naruse (Yui NARUSE) almost 13 years ago

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.

Updated by MartinBosslet (Martin Bosslet) almost 13 years ago

  • ruby -v changed from ruby 1.9.3dev (2011-06-13) [i386-mswin32_100] to -

What do you think?

I agree with it, such way is suitable than my hack.

OK, great! I'll implement this then soon.

Thanks,
Martin

Updated by MartinBosslet (Martin Bosslet) almost 13 years ago

What do you think?

I agree with it, such way is suitable than my hack.

OK, great! I'll implement this then soon.

Thanks,
Martin

Updated by MartinBosslet (Martin Bosslet) almost 13 years ago

  • Status changed from Closed to Feedback

I just committed the fix for http://redmine.ruby-lang.org/issues/4885
in revision 32199.
This should solve the issue that was discovered here, and I was also
able to run the tests without Yui's fix.

Could you please confirm that it works for you, too?

Regards,
Martin

Updated by MartinBosslet (Martin Bosslet) almost 13 years ago

  • Status changed from Feedback to Closed

I close this since there have been no further complaints.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0