]>
Commit | Line | Data |
---|---|---|
b1322259 RS |
1 | /* |
2 | * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. | |
d02b48c6 | 3 | * |
b1322259 RS |
4 | * Licensed under the OpenSSL license (the "License"). You may not use |
5 | * this file except in compliance with the License. You can obtain a copy | |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
d02b48c6 RE |
8 | */ |
9 | ||
10 | #include <stdio.h> | |
b39fc560 | 11 | #include "internal/cryptlib.h" |
ec577822 BM |
12 | #include <openssl/bn.h> |
13 | #include <openssl/evp.h> | |
14 | #include <openssl/asn1.h> | |
15 | #include <openssl/x509.h> | |
124055a9 | 16 | #include "internal/x509_int.h" |
ec577822 BM |
17 | #include <openssl/objects.h> |
18 | #include <openssl/buffer.h> | |
d02b48c6 | 19 | |
6b691a5c | 20 | X509 *X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey) |
0f113f3e MC |
21 | { |
22 | X509 *ret = NULL; | |
23 | X509_CINF *xi = NULL; | |
24 | X509_NAME *xn; | |
0517538d | 25 | EVP_PKEY *pubkey = NULL; |
d02b48c6 | 26 | |
0f113f3e MC |
27 | if ((ret = X509_new()) == NULL) { |
28 | X509err(X509_F_X509_REQ_TO_X509, ERR_R_MALLOC_FAILURE); | |
0517538d | 29 | return NULL; |
0f113f3e | 30 | } |
d02b48c6 | 31 | |
0f113f3e | 32 | /* duplicate the request */ |
5cf6abd8 | 33 | xi = &ret->cert_info; |
d02b48c6 | 34 | |
95ed0e7c | 35 | if (sk_X509_ATTRIBUTE_num(r->req_info.attributes) != 0) { |
f422a514 | 36 | if ((xi->version = ASN1_INTEGER_new()) == NULL) |
0f113f3e MC |
37 | goto err; |
38 | if (!ASN1_INTEGER_set(xi->version, 2)) | |
39 | goto err; | |
35a1cc90 MC |
40 | /*- xi->extensions=ri->attributes; <- bad, should not ever be done |
41 | ri->attributes=NULL; */ | |
0f113f3e | 42 | } |
d02b48c6 | 43 | |
0f113f3e | 44 | xn = X509_REQ_get_subject_name(r); |
0517538d | 45 | if (X509_set_subject_name(ret, xn) == 0) |
0f113f3e | 46 | goto err; |
0517538d | 47 | if (X509_set_issuer_name(ret, xn) == 0) |
0f113f3e | 48 | goto err; |
d02b48c6 | 49 | |
2869e79f | 50 | if (X509_gmtime_adj(xi->validity.notBefore, 0) == NULL) |
0f113f3e | 51 | goto err; |
2869e79f | 52 | if (X509_gmtime_adj(xi->validity.notAfter, (long)60 * 60 * 24 * days) == |
0f113f3e MC |
53 | NULL) |
54 | goto err; | |
d02b48c6 | 55 | |
c5137473 F |
56 | pubkey = X509_REQ_get0_pubkey(r); |
57 | if (pubkey == NULL || !X509_set_pubkey(ret, pubkey)) | |
0517538d F |
58 | goto err; |
59 | ||
0f113f3e MC |
60 | if (!X509_sign(ret, pkey, EVP_md5())) |
61 | goto err; | |
222561fe RS |
62 | return ret; |
63 | ||
0f113f3e | 64 | err: |
222561fe RS |
65 | X509_free(ret); |
66 | return NULL; | |
0f113f3e | 67 | } |