Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use X509_ALGOR_get0() accessor for X509_ALGOR #687

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions ext/openssl/ossl_ts.c
Expand Up @@ -152,7 +152,7 @@ obj_to_asn1obj_i(VALUE obj)
}

static VALUE
get_asn1obj(ASN1_OBJECT *obj)
get_asn1obj(const ASN1_OBJECT *obj)
{
BIO *out;
VALUE ret;
Expand Down Expand Up @@ -233,11 +233,13 @@ ossl_ts_req_get_algorithm(VALUE self)
TS_REQ *req;
TS_MSG_IMPRINT *mi;
X509_ALGOR *algor;
const ASN1_OBJECT *obj;

GetTSRequest(self, req);
mi = TS_REQ_get_msg_imprint(req);
algor = TS_MSG_IMPRINT_get_algo(mi);
return get_asn1obj(algor->algorithm);
X509_ALGOR_get0(&obj, NULL, NULL, algor);
return get_asn1obj(obj);
}

/*
Expand Down Expand Up @@ -487,13 +489,15 @@ ossl_ts_req_to_der(VALUE self)
TS_REQ *req;
TS_MSG_IMPRINT *mi;
X509_ALGOR *algo;
const ASN1_OBJECT *obj;
ASN1_OCTET_STRING *hashed_msg;

GetTSRequest(self, req);
mi = TS_REQ_get_msg_imprint(req);

algo = TS_MSG_IMPRINT_get_algo(mi);
if (OBJ_obj2nid(algo->algorithm) == NID_undef)
X509_ALGOR_get0(&obj, NULL, NULL, algo);
if (OBJ_obj2nid(obj) == NID_undef)
ossl_raise(eTimestampError, "Message imprint missing algorithm");

hashed_msg = TS_MSG_IMPRINT_get_msg(mi);
Expand Down Expand Up @@ -944,11 +948,13 @@ ossl_ts_token_info_get_algorithm(VALUE self)
TS_TST_INFO *info;
TS_MSG_IMPRINT *mi;
X509_ALGOR *algo;
const ASN1_OBJECT *obj;

GetTSTokenInfo(self, info);
mi = TS_TST_INFO_get_msg_imprint(info);
algo = TS_MSG_IMPRINT_get_algo(mi);
return get_asn1obj(algo->algorithm);
X509_ALGOR_get0(&obj, NULL, NULL, algo);
return get_asn1obj(obj);
}

/*
Expand Down
4 changes: 3 additions & 1 deletion ext/openssl/ossl_x509cert.c
Expand Up @@ -328,13 +328,15 @@ ossl_x509_get_signature_algorithm(VALUE self)
{
X509 *x509;
BIO *out;
const ASN1_OBJECT *obj;
VALUE str;

GetX509(self, x509);
out = BIO_new(BIO_s_mem());
if (!out) ossl_raise(eX509CertError, NULL);

if (!i2a_ASN1_OBJECT(out, X509_get0_tbs_sigalg(x509)->algorithm)) {
X509_ALGOR_get0(&obj, NULL, NULL, X509_get0_tbs_sigalg(x509));
if (!i2a_ASN1_OBJECT(out, obj)) {
BIO_free(out);
ossl_raise(eX509CertError, NULL);
}
Expand Down
4 changes: 3 additions & 1 deletion ext/openssl/ossl_x509crl.c
Expand Up @@ -169,14 +169,16 @@ ossl_x509crl_get_signature_algorithm(VALUE self)
{
X509_CRL *crl;
const X509_ALGOR *alg;
const ASN1_OBJECT *obj;
BIO *out;

GetX509CRL(self, crl);
if (!(out = BIO_new(BIO_s_mem()))) {
ossl_raise(eX509CRLError, NULL);
}
X509_CRL_get0_signature(crl, NULL, &alg);
if (!i2a_ASN1_OBJECT(out, alg->algorithm)) {
X509_ALGOR_get0(&obj, NULL, NULL, alg);
if (!i2a_ASN1_OBJECT(out, obj)) {
BIO_free(out);
ossl_raise(eX509CRLError, NULL);
}
Expand Down
4 changes: 3 additions & 1 deletion ext/openssl/ossl_x509req.c
Expand Up @@ -259,6 +259,7 @@ ossl_x509req_get_signature_algorithm(VALUE self)
{
X509_REQ *req;
const X509_ALGOR *alg;
const ASN1_OBJECT *obj;
BIO *out;

GetX509Req(self, req);
Expand All @@ -267,7 +268,8 @@ ossl_x509req_get_signature_algorithm(VALUE self)
ossl_raise(eX509ReqError, NULL);
}
X509_REQ_get0_signature(req, NULL, &alg);
if (!i2a_ASN1_OBJECT(out, alg->algorithm)) {
X509_ALGOR_get0(&obj, NULL, NULL, alg);
if (!i2a_ASN1_OBJECT(out, obj)) {
BIO_free(out);
ossl_raise(eX509ReqError, NULL);
}
Expand Down