From: job Date: Tue, 25 Apr 2023 09:46:36 +0000 (+0000) Subject: Use X509_set_version() and X509_REQ_set_version() instead doing it by hand X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=caa52935dd761efce7fff45a153f656f4a1e8eb4;p=openbsd Use X509_set_version() and X509_REQ_set_version() instead doing it by hand A small side-effect in X509_to_X509_REQ() is that 'x->req_info->enc.modified' now earlier on is set to 1. OK tb@ jsing@ --- diff --git a/lib/libcrypto/x509/x509_r2x.c b/lib/libcrypto/x509/x509_r2x.c index 99c423d8c99..39b392259b5 100644 --- a/lib/libcrypto/x509/x509_r2x.c +++ b/lib/libcrypto/x509/x509_r2x.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_r2x.c,v 1.16 2023/02/16 08:38:17 tb Exp $ */ +/* $OpenBSD: x509_r2x.c,v 1.17 2023/04/25 09:46:36 job Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -85,9 +85,7 @@ X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey) xi = ret->cert_info; if (sk_X509_ATTRIBUTE_num(r->req_info->attributes) != 0) { - if ((xi->version = ASN1_INTEGER_new()) == NULL) - goto err; - if (!ASN1_INTEGER_set(xi->version, 2)) + if (!X509_set_version(ret, 2)) goto err; } diff --git a/lib/libcrypto/x509/x509_req.c b/lib/libcrypto/x509/x509_req.c index 0fea7e68b43..7ed106241aa 100644 --- a/lib/libcrypto/x509/x509_req.c +++ b/lib/libcrypto/x509/x509_req.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_req.c,v 1.32 2023/02/16 08:38:17 tb Exp $ */ +/* $OpenBSD: x509_req.c,v 1.33 2023/04/25 09:46:36 job Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -77,7 +77,6 @@ X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md) { X509_REQ *ret; - X509_REQ_INFO *ri; int i; EVP_PKEY *pktmp; @@ -87,11 +86,7 @@ X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md) goto err; } - ri = ret->req_info; - - if ((ri->version = ASN1_INTEGER_new()) == NULL) - goto err; - if (ASN1_INTEGER_set(ri->version, 0) == 0) + if (!X509_REQ_set_version(ret, 0)) goto err; if (!X509_REQ_set_subject_name(ret, X509_get_subject_name(x)))