Project

General

Profile

Feature #7181 » certid_methods.patch

reaperhulk (Paul Kehrer), 10/18/2012 12:43 PM

View differences:

ext/openssl/ossl_ocsp.c
return asn1integer_to_num(id->serialNumber);
}
static VALUE
ossl_ocspcid_get_issuer_name_hash(VALUE self)
{
OCSP_CERTID *id;
BIO *out;
VALUE str;
GetOCSPCertId(self, id);
if (!(out = BIO_new(BIO_s_mem())))
ossl_raise(eOCSPError, NULL);
i2a_ASN1_STRING(out, id->issuerNameHash, V_ASN1_OCTET_STRING);
str = ossl_membio2str(out);
return str;
}
static VALUE
ossl_ocspcid_get_issuer_key_hash(VALUE self)
{
OCSP_CERTID *id;
BIO *out;
VALUE str;
GetOCSPCertId(self, id);
if (!(out = BIO_new(BIO_s_mem())))
ossl_raise(eOCSPError, NULL);
i2a_ASN1_STRING(out, id->issuerKeyHash, V_ASN1_OCTET_STRING);
str = ossl_membio2str(out);
return str;
}
static VALUE
ossl_ocspcid_get_signature_algorithm(VALUE self)
{
OCSP_CERTID *id;
BIO *out;
VALUE str;
GetOCSPCertId(self, id);
if (!(out = BIO_new(BIO_s_mem())))
ossl_raise(eOCSPError, NULL);
if (!i2a_ASN1_OBJECT(out, id->hashAlgorithm->algorithm)) {
BIO_free(out);
ossl_raise(eOCSPError, NULL);
}
str = ossl_membio2str(out);
}
void
Init_ossl_ocsp()
{
......
rb_define_method(cOCSPCertId, "cmp", ossl_ocspcid_cmp, 1);
rb_define_method(cOCSPCertId, "cmp_issuer", ossl_ocspcid_cmp_issuer, 1);
rb_define_method(cOCSPCertId, "serial", ossl_ocspcid_get_serial, 0);
rb_define_method(cOCSPCertId, "issuer_name_hash", ossl_ocspcid_get_issuer_name_hash, 0);
rb_define_method(cOCSPCertId, "issuer_key_hash", ossl_ocspcid_get_issuer_key_hash, 0);
rb_define_method(cOCSPCertId, "signature_algorithm", ossl_ocspcid_get_signature_algorithm, 0);
#define DefOCSPConst(x) rb_define_const(mOCSP, #x, INT2NUM(OCSP_##x))
test/openssl/test_ocsp.rb
assert_equal @cert.serial, cid.serial
end
def test_certificate_id_issuer_name_hash
cid = OpenSSL::OCSP::CertificateId.new(@cert, @ca_cert)
assert_equal "D91F736AC4DC3242F0FB9B77A3149BD83C5C43D0", cid.issuer_name_hash
end
def test_certificate_id_issuer_key_hash
cid = OpenSSL::OCSP::CertificateId.new(@cert, @ca_cert)
assert_equal "D1FEF9FBF8AE1BC160CBFA03E2596DD873089213", cid.issuer_key_hash
end
def test_new_certificate_id_with_digest
cid = OpenSSL::OCSP::CertificateId.new(@cert, @ca_cert, OpenSSL::Digest::SHA256.new)
assert_kind_of OpenSSL::OCSP::CertificateId, cid
assert_equal @cert.serial, cid.serial
end if defined?(OpenSSL::Digest::SHA256)
def test_certificate_id_signature_algorithm
cid_sha1 = OpenSSL::OCSP::CertificateId.new(@cert, @ca_cert, OpenSSL::Digest::SHA1.new)
cid_md5 = OpenSSL::OCSP::CertificateId.new(@cert, @ca_cert, OpenSSL::Digest::MD5.new)
cid = OpenSSL::OCSP::CertificateId.new(@cert, @ca_cert, OpenSSL::Digest::MD5.new)
assert_equal cid_sha1.signature_algorithm, "sha1"
assert_equal cid_md5.signature_algorithm, "md5"
end
def test_new_ocsp_request
request = OpenSSL::OCSP::Request.new
cid = OpenSSL::OCSP::CertificateId.new(@cert, @ca_cert, OpenSSL::Digest::SHA1.new)
(1-1/2)