Project

General

Profile

Feature #4805 ยป X509-Name-hash_old.diff

nahi (Hiroshi Nakamura), 05/31/2011 09:42 PM

View differences:

ChangeLog (working copy)
Tue May 31 21:07:53 2011 Hiroshi Nakamura <nahi@ruby-lang.org>
* ext/openssl/ossl_x509name.c: added X509::Name#hash_old as a wrapper
for X509_NAME_hash_old in OpenSSL 1.0.0.
* test/openssl/test_x509name.rb (test_hash): make test pass with
OpenSSL 1.0.0.
Tue May 31 17:03:24 2011 Hiroshi Nakamura <nahi@ruby-lang.org>
* lib/net/http.rb, lib/net/protocol.rb: Allow to configure to wait
ext/openssl/ossl_x509name.c (working copy)
return ULONG2NUM(hash);
}
#ifdef HAVE_X509_NAME_HASH_OLD
/*
* call-seq:
* name.hash_old => integer
*
* hash_old returns MD5 based hash used in OpenSSL 0.9.X.
*/
static VALUE
ossl_x509name_hash_old(VALUE self)
{
X509_NAME *name;
unsigned long hash;
GetX509Name(self, name);
hash = X509_NAME_hash_old(name);
return ULONG2NUM(hash);
}
#endif
/*
* call-seq:
* name.to_der => string
*/
static VALUE
......
rb_define_alias(cX509Name, "<=>", "cmp");
rb_define_method(cX509Name, "eql?", ossl_x509name_eql, 1);
rb_define_method(cX509Name, "hash", ossl_x509name_hash, 0);
#ifdef HAVE_X509_NAME_HASH_OLD
rb_define_method(cX509Name, "hash_old", ossl_x509name_hash_old, 0);
#endif
rb_define_method(cX509Name, "to_der", ossl_x509name_to_der, 0);
utf8str = INT2NUM(V_ASN1_UTF8STRING);
ext/openssl/extconf.rb (working copy)
have_func("X509_CRL_set_issuer_name")
have_func("X509_CRL_set_version")
have_func("X509_CRL_sort")
have_func("X509_NAME_hash_old")
have_func("X509_STORE_get_ex_data")
have_func("X509_STORE_set_ex_data")
have_func("OBJ_NAME_do_all_sorted")
test/openssl/test_x509name.rb (working copy)
assert_equal -1, n1 <=> n2
end
def name_hash(name)
# OpenSSL 1.0.0 uses SHA1 for canonical encoding (not just a der) of
# X509Name for X509_NAME_hash.
name.respond_to?(:hash_old) ? name.hash_old : name.hash
end
def test_hash
dn = "/DC=org/DC=ruby-lang/CN=www.ruby-lang.org"
name = OpenSSL::X509::Name.parse(dn)
d = Digest::MD5.digest(name.to_der)
expected = (d[0].ord & 0xff) | (d[1].ord & 0xff) << 8 | (d[2].ord & 0xff) << 16 | (d[3].ord & 0xff) << 24
assert_equal(expected, name_hash(name))
#
dn = "/DC=org/DC=ruby-lang/CN=baz.ruby-lang.org"
name = OpenSSL::X509::Name.parse(dn)
d = Digest::MD5.digest(name.to_der)
expected = (d[0].ord & 0xff) | (d[1].ord & 0xff) << 8 | (d[2].ord & 0xff) << 16 | (d[3].ord & 0xff) << 24
assert_equal(expected, name_hash(name))
end
end
end
    (1-1/1)