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

ruby-changes:22440

From: naruse <ko1@a...>
Date: Wed, 8 Feb 2012 18:52:10 +0900 (JST)
Subject: [ruby-changes:22440] naruse:r34489 (ruby_1_9_3): merge revision(s) 34481,34488: [Backport #5983]

naruse	2012-02-08 18:51:53 +0900 (Wed, 08 Feb 2012)

  New Revision: 34489

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

  Log:
    merge revision(s) 34481,34488: [Backport #5983]
    
    * ext/openssl/ossl_x509name.c: Use the numerical representation of
      unrecognized OIDs instead of the sn "UNDEF".
      
    
    * test/openssl/test_x509name.rb: Add tests for the fixed behavior.
      
      Patch provided by Paul Kehrer, thank you!
      [ruby-core:41769] [Feature #5787]

  Modified files:
    branches/ruby_1_9_3/ext/openssl/ossl_x509name.c
    branches/ruby_1_9_3/test/openssl/test_x509name.rb
    branches/ruby_1_9_3/version.h

Index: ruby_1_9_3/ext/openssl/ossl_x509name.c
===================================================================
--- ruby_1_9_3/ext/openssl/ossl_x509name.c	(revision 34488)
+++ ruby_1_9_3/ext/openssl/ossl_x509name.c	(revision 34489)
@@ -227,10 +227,10 @@
 {
     X509_NAME *name;
     X509_NAME_ENTRY *entry;
-    int i,entries;
+    int i,entries,nid;
     char long_name[512];
     const char *short_name;
-    VALUE ary, ret;
+    VALUE ary, vname, ret;
 
     GetX509Name(self, name);
     entries = X509_NAME_entry_count(name);
@@ -246,8 +246,15 @@
 	if (!i2t_ASN1_OBJECT(long_name, sizeof(long_name), entry->object)) {
 	    ossl_raise(eX509NameError, NULL);
 	}
-	short_name = OBJ_nid2sn(OBJ_ln2nid(long_name));
-	ary = rb_ary_new3(3, rb_str_new2(short_name),
+	nid = OBJ_ln2nid(long_name);
+	if (nid == NID_undef) {
+	    vname = rb_str_new2((const char *) &long_name);
+	} else {
+	    short_name = OBJ_nid2sn(nid);
+	    vname = rb_str_new2(short_name); /*do not free*/
+	}
+	ary = rb_ary_new3(3, 
+			  vname,
         		  rb_str_new((const char *)entry->value->data, entry->value->length),
         		  INT2FIX(entry->value->type));
 	rb_ary_push(ret, ary);
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 34488)
+++ ruby_1_9_3/version.h	(revision 34489)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 65
+#define RUBY_PATCHLEVEL 66
 
 #define RUBY_RELEASE_DATE "2012-02-08"
 #define RUBY_RELEASE_YEAR 2012
Index: ruby_1_9_3/test/openssl/test_x509name.rb
===================================================================
--- ruby_1_9_3/test/openssl/test_x509name.rb	(revision 34488)
+++ ruby_1_9_3/test/openssl/test_x509name.rb	(revision 34489)
@@ -100,6 +100,58 @@
     assert_equal(name_from_der.to_der, name.to_der)
   end
 
+  def test_unrecognized_oid
+    dn = [ ["1.2.3.4.5.6.7.8.9.7.5.3.1", "Unknown OID 1"],
+           ["1.1.2.3.5.8.13.21.34", "Unknown OID 2"],
+           ["C", "US"],
+           ["postalCode", "60602"],
+           ["ST", "Illinois"],
+           ["L", "Chicago"],
+           #["street", "123 Fake St"],
+           ["O", "Some Company LLC"],
+           ["CN", "mydomain.com"] ]
+
+    name = OpenSSL::X509::Name.new(dn)
+    ary = name.to_a
+    #assert_equal("/1.2.3.4.5.6.7.8.9.7.5.3.1=Unknown OID 1/1.1.2.3.5.8.13.21.34=Unknown OID 2/C=US/postalCode=60602/ST=Illinois/L=Chicago/street=123 Fake St/O=Some Company LLC/CN=mydomain.com", name.to_s)
+    assert_equal("/1.2.3.4.5.6.7.8.9.7.5.3.1=Unknown OID 1/1.1.2.3.5.8.13.21.34=Unknown OID 2/C=US/postalCode=60602/ST=Illinois/L=Chicago/O=Some Company LLC/CN=mydomain.com", name.to_s)
+    assert_equal("1.2.3.4.5.6.7.8.9.7.5.3.1", ary[0][0])
+    assert_equal("1.1.2.3.5.8.13.21.34", ary[1][0])
+    assert_equal("C", ary[2][0])
+    assert_equal("postalCode", ary[3][0])
+    assert_equal("ST", ary[4][0])
+    assert_equal("L", ary[5][0])
+    #assert_equal("street", ary[6][0])
+    assert_equal("O", ary[6][0])
+    assert_equal("CN", ary[7][0])
+    assert_equal("Unknown OID 1", ary[0][1])
+    assert_equal("Unknown OID 2", ary[1][1])
+    assert_equal("US", ary[2][1])
+    assert_equal("60602", ary[3][1])
+    assert_equal("Illinois", ary[4][1])
+    assert_equal("Chicago", ary[5][1])
+    #assert_equal("123 Fake St", ary[6][1])
+    assert_equal("Some Company LLC", ary[6][1])
+    assert_equal("mydomain.com", ary[7][1])
+  end
+
+  def test_unrecognized_oid_parse_encode_equality
+    dn = [ ["1.2.3.4.5.6.7.8.9.7.5.3.2", "Unknown OID1"],
+           ["1.1.2.3.5.8.13.21.35", "Unknown OID2"],
+           ["C", "US"],
+           ["postalCode", "60602"],
+           ["ST", "Illinois"],
+           ["L", "Chicago"],
+           #["street", "123 Fake St"],
+           ["O", "Some Company LLC"],
+           ["CN", "mydomain.com"] ]
+
+    name1 = OpenSSL::X509::Name.new(dn)
+    name2 = OpenSSL::X509::Name.parse(name1.to_s)
+    assert_equal(name1.to_s, name2.to_s)
+    assert_equal(name1.to_a, name2.to_a)
+  end
+
   def test_s_parse
     dn = "/DC=org/DC=ruby-lang/CN=www.ruby-lang.org"
     name = OpenSSL::X509::Name.parse(dn)
@@ -258,6 +310,24 @@
     assert_equal(OpenSSL::ASN1::PRINTABLESTRING, ary[4][2])
   end
 
+  def test_add_entry_street
+    return if OpenSSL::OPENSSL_VERSION_NUMBER >= 0x009080df # 0.9.8m
+    # openssl/crypto/objects/obj_mac.h 1.83
+    dn = [
+      ["DC", "org"],
+      ["DC", "ruby-lang"],
+      ["CN", "GOTOU Yuuzou"],
+      ["emailAddress", "gotoyuzo@r..."],
+      ["serialNumber", "123"],
+      ["street", "Namiki"],
+    ]
+    name = OpenSSL::X509::Name.new
+    dn.each{|attr| name.add_entry(*attr) }
+    ary = name.to_a
+    assert_equal("/DC=org/DC=ruby-lang/CN=GOTOU Yuuzou/emailAddress=gotoyuzo@r.../serialNumber=123/street=Namiki", name.to_s)
+    assert_equal("Namiki", ary[5][1])
+  end
+
   def test_equals2
     n1 = OpenSSL::X509::Name.parse 'CN=a'
     n2 = OpenSSL::X509::Name.parse 'CN=a'

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

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