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

ruby-changes:17074

From: nahi <ko1@a...>
Date: Mon, 23 Aug 2010 12:10:41 +0900 (JST)
Subject: [ruby-changes:17074] Ruby:r29071 (ruby_1_8): * ext/openssl/ossl_asn1.c (obj_to_asn1bool): fixed ASN1::Boolean

nahi	2010-08-23 12:06:30 +0900 (Mon, 23 Aug 2010)

  New Revision: 29071

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29071

  Log:
    * ext/openssl/ossl_asn1.c (obj_to_asn1bool): fixed ASN1::Boolean
              encoding issue for OpenSSL 1.0.0 compatibility.
              ASN1::Boolean.new(false).to_der wrongly generated "\1\1\377" which
              means 'true'.
    
              ASN1_TYPE_set of OpenSSL <= 0.9.8 treats value 0x100 as 'false' but
              OpenSSL >= 1.0.0 treats it as 'true'.  ruby-ossl was using 0x100 for
              'false' for backward compatibility.  Just use 0x0 for the case
              OpenSSL >= OpenSSL 0.9.7.
    
            * test/openssl/test_asn1.rb: test added.

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/ext/openssl/ossl_asn1.c
    branches/ruby_1_8/test/openssl/test_asn1.rb

Index: ruby_1_8/ext/openssl/ossl_asn1.c
===================================================================
--- ruby_1_8/ext/openssl/ossl_asn1.c	(revision 29070)
+++ ruby_1_8/ext/openssl/ossl_asn1.c	(revision 29071)
@@ -196,7 +196,11 @@
 static ASN1_BOOLEAN
 obj_to_asn1bool(VALUE obj)
 {
+#if OPENSSL_VERSION_NUMBER < 0x00907000L
      return RTEST(obj) ? 0xff : 0x100;
+#else
+     return RTEST(obj) ? 0xff : 0x0;
+#endif
 }
 
 static ASN1_INTEGER*
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 29070)
+++ ruby_1_8/ChangeLog	(revision 29071)
@@ -1,3 +1,17 @@
+Mon Aug 23 11:42:41 2010  NAKAMURA, Hiroshi  <nahi@r...>
+
+	* ext/openssl/ossl_asn1.c (obj_to_asn1bool): fixed ASN1::Boolean
+	  encoding issue for OpenSSL 1.0.0 compatibility.
+	  ASN1::Boolean.new(false).to_der wrongly generated "\1\1\377" which
+	  means 'true'.  [BUG:3735] 
+	  
+	  ASN1_TYPE_set of OpenSSL <= 0.9.8 treats value 0x100 as 'false' but
+	  OpenSSL >= 1.0.0 treats it as 'true'.  ruby-ossl was using 0x100 for
+	  'false' for backward compatibility.  Just use 0x0 for the case
+	  OpenSSL >= OpenSSL 0.9.7.
+
+	* test/openssl/test_asn1.rb: test added.
+
 Thu Aug 19 22:57:43 2010  NAKAMURA, Hiroshi  <nahi@r...>
 
 	* test/openssl/{test_x509cert.rb,test_ssl.rb,test_x509req.rb}: added
Index: ruby_1_8/test/openssl/test_asn1.rb
===================================================================
--- ruby_1_8/test/openssl/test_asn1.rb	(revision 29070)
+++ ruby_1_8/test/openssl/test_asn1.rb	(revision 29071)
@@ -194,4 +194,18 @@
     cululated_sig = key.sign(OpenSSL::Digest::SHA1.new, tbs_cert.to_der)
     assert_equal(cululated_sig, sig_val.value)
   end
+
+  def test_encode_boolean
+    encode_decode_test(OpenSSL::ASN1::Boolean, [true, false])
+  end
+
+  def test_encode_integer
+    encode_decode_test(OpenSSL::ASN1::Integer, [72, -127, -128, 128, -1, 0, 1, -(2**12345), 2**12345])
+  end
+
+  def encode_decode_test(type, values)
+    values.each do |v|
+      assert_equal(v, OpenSSL::ASN1.decode(type.new(v).to_der).value)
+    end
+  end
 end if defined?(OpenSSL)

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

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