Skip to content

Commit

Permalink
Merge pull request #687 from botovq/x509_algor
Browse files Browse the repository at this point in the history
Use X509_ALGOR_get0() accessor for X509_ALGOR
  • Loading branch information
rhenium authored Jan 21, 2025
2 parents 050f0c6 + 812aeab commit 6f1695d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
14 changes: 10 additions & 4 deletions ext/openssl/ossl_ts.c
Original file line number Diff line number Diff line change
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 @@ -236,11 +236,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 @@ -490,13 +492,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 @@ -969,11 +973,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 6f1695d

Please sign in to comment.