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

ruby-changes:43270

From: rhe <ko1@a...>
Date: Thu, 9 Jun 2016 21:42:14 +0900 (JST)
Subject: [ruby-changes:43270] rhe:r55344 (trunk): openssl: use ASN1_ENUMERATED_to_BN() if needed

rhe	2016-06-09 21:42:08 +0900 (Thu, 09 Jun 2016)

  New Revision: 55344

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55344

  Log:
    openssl: use ASN1_ENUMERATED_to_BN() if needed
    
    * ext/openssl/ossl_asn1.c (asn1integer_to_num): Use
      ASN1_ENUMERATED_to_BN() to convert an ASN1_ENUMERATED to a BN.
      Starting from OpenSSL 1.1.0, ASN1_INTEGER_to_BN() rejects
      non-ASN1_INTEGER objects. The format of INTEGER and ENUMERATED are
      almost identical so they behaved in the same way in OpenSSL <= 1.0.2.
      [ruby-core:75225] [Feature #12324]
    
    * test/openssl/test_asn1.rb (test_decode_enumerated): Test that it
      works.

  Modified files:
    trunk/ChangeLog
    trunk/ext/openssl/ossl_asn1.c
    trunk/test/openssl/test_asn1.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55343)
+++ ChangeLog	(revision 55344)
@@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jun  9 21:42:00 2016  Kazuki Yamaguchi  <k@r...>
+
+	* ext/openssl/ossl_asn1.c (asn1integer_to_num): Use
+	  ASN1_ENUMERATED_to_BN() to convert an ASN1_ENUMERATED to a BN.
+	  Starting from OpenSSL 1.1.0, ASN1_INTEGER_to_BN() rejects
+	  non-ASN1_INTEGER objects. The format of INTEGER and ENUMERATED are
+	  almost identical so they behaved in the same way in OpenSSL <= 1.0.2.
+	  [ruby-core:75225] [Feature #12324]
+
+	* test/openssl/test_asn1.rb (test_decode_enumerated): Test that it
+	  works.
+
 Thu Jun  9 21:10:04 2016  Kazuhiro NISHIYAMA  <zn@m...>
 
 	* tool/ifchange: fix timestamp error when target without
Index: test/openssl/test_asn1.rb
===================================================================
--- test/openssl/test_asn1.rb	(revision 55343)
+++ test/openssl/test_asn1.rb	(revision 55344)
@@ -280,6 +280,12 @@ rEzBQ0F9dUyqQ9gyRg8KHhDfv9HzT1d/rnUZMkoo https://github.com/ruby/ruby/blob/trunk/test/openssl/test_asn1.rb#L280
     assert_equal 2 ** 31, OpenSSL::ASN1.decode(encoded).value.to_i
   end
 
+  def test_decode_enumerated
+    encoded = OpenSSL::ASN1.Enumerated(0).to_der
+    assert_equal "\x0a\x01\x00".b, encoded
+    assert_equal encoded, OpenSSL::ASN1.decode(encoded).to_der
+  end
+
   def test_create_inf_length_primitive
     expected = %w{ 24 80 04 01 61 00 00 }
     raw = [expected.join('')].pack('H*')
Index: ext/openssl/ossl_asn1.c
===================================================================
--- ext/openssl/ossl_asn1.c	(revision 55343)
+++ ext/openssl/ossl_asn1.c	(revision 55344)
@@ -125,9 +125,13 @@ asn1integer_to_num(ASN1_INTEGER *ai) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_asn1.c#L125
     if (!ai) {
 	ossl_raise(rb_eTypeError, "ASN1_INTEGER is NULL!");
     }
-    if (!(bn = ASN1_INTEGER_to_BN(ai, NULL))) {
+    if (ai->type == V_ASN1_ENUMERATED)
+	bn = ASN1_ENUMERATED_to_BN(ai, NULL);
+    else
+	bn = ASN1_INTEGER_to_BN(ai, NULL);
+
+    if (!bn)
 	ossl_raise(eOSSLError, NULL);
-    }
 #if DO_IT_VIA_RUBY
     if (!(txt = BN_bn2dec(bn))) {
 	BN_free(bn);

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

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