Use X509_set_version() and X509_REQ_set_version() instead doing it by hand
authorjob <job@openbsd.org>
Tue, 25 Apr 2023 09:46:36 +0000 (09:46 +0000)
committerjob <job@openbsd.org>
Tue, 25 Apr 2023 09:46:36 +0000 (09:46 +0000)
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@

lib/libcrypto/x509/x509_r2x.c
lib/libcrypto/x509/x509_req.c

index 99c423d..39b3922 100644 (file)
@@ -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;
        }
 
index 0fea7e6..7ed1062 100644 (file)
@@ -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)))