2016-05-17 18:52:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 10:52:47 +00:00
|
|
|
*
|
2016-05-17 18:52:22 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1998-12-21 10:52:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-23 22:13:45 +00:00
|
|
|
#include <openssl/bn.h>
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/asn1.h>
|
|
|
|
#include <openssl/x509.h>
|
2015-08-31 11:58:07 +00:00
|
|
|
#include "internal/x509_int.h"
|
1999-04-23 22:13:45 +00:00
|
|
|
#include <openssl/objects.h>
|
|
|
|
#include <openssl/buffer.h>
|
1998-12-21 10:52:47 +00:00
|
|
|
|
1999-04-19 21:31:43 +00:00
|
|
|
X509 *X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
X509 *ret = NULL;
|
|
|
|
X509_CINF *xi = NULL;
|
|
|
|
X509_NAME *xn;
|
2016-03-16 23:15:48 +00:00
|
|
|
EVP_PKEY *pubkey = NULL;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if ((ret = X509_new()) == NULL) {
|
|
|
|
X509err(X509_F_X509_REQ_TO_X509, ERR_R_MALLOC_FAILURE);
|
2016-03-16 23:15:48 +00:00
|
|
|
return NULL;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/* duplicate the request */
|
2015-09-16 17:40:26 +00:00
|
|
|
xi = &ret->cert_info;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-09-16 17:46:16 +00:00
|
|
|
if (sk_X509_ATTRIBUTE_num(r->req_info.attributes) != 0) {
|
2015-03-14 04:16:42 +00:00
|
|
|
if ((xi->version = ASN1_INTEGER_new()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
|
|
|
if (!ASN1_INTEGER_set(xi->version, 2))
|
|
|
|
goto err;
|
2015-01-17 00:06:54 +00:00
|
|
|
/*- xi->extensions=ri->attributes; <- bad, should not ever be done
|
|
|
|
ri->attributes=NULL; */
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
xn = X509_REQ_get_subject_name(r);
|
2016-03-16 23:15:48 +00:00
|
|
|
if (X509_set_subject_name(ret, xn) == 0)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
2016-03-16 23:15:48 +00:00
|
|
|
if (X509_set_issuer_name(ret, xn) == 0)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-09-15 16:10:51 +00:00
|
|
|
if (X509_gmtime_adj(xi->validity.notBefore, 0) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
2015-09-15 16:10:51 +00:00
|
|
|
if (X509_gmtime_adj(xi->validity.notAfter, (long)60 * 60 * 24 * days) ==
|
2015-01-22 03:40:55 +00:00
|
|
|
NULL)
|
|
|
|
goto err;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2016-04-03 21:37:32 +00:00
|
|
|
pubkey = X509_REQ_get0_pubkey(r);
|
|
|
|
if (pubkey == NULL || !X509_set_pubkey(ret, pubkey))
|
2016-03-16 23:15:48 +00:00
|
|
|
goto err;
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (!X509_sign(ret, pkey, EVP_md5()))
|
|
|
|
goto err;
|
2015-04-30 21:33:59 +00:00
|
|
|
return ret;
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
err:
|
2015-04-30 21:33:59 +00:00
|
|
|
X509_free(ret);
|
|
|
|
return NULL;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|