]>
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/asn1.h> |
13 | #include <openssl/objects.h> | |
14 | #include <openssl/evp.h> | |
15 | #include <openssl/x509.h> | |
94e84f5e | 16 | #include "internal/x509_int.h" |
d02b48c6 | 17 | |
6b691a5c | 18 | int X509_set_version(X509 *x, long version) |
0f113f3e MC |
19 | { |
20 | if (x == NULL) | |
21 | return (0); | |
22 | if (version == 0) { | |
5cf6abd8 DSH |
23 | ASN1_INTEGER_free(x->cert_info.version); |
24 | x->cert_info.version = NULL; | |
0f113f3e MC |
25 | return (1); |
26 | } | |
5cf6abd8 DSH |
27 | if (x->cert_info.version == NULL) { |
28 | if ((x->cert_info.version = ASN1_INTEGER_new()) == NULL) | |
0f113f3e MC |
29 | return (0); |
30 | } | |
5cf6abd8 | 31 | return (ASN1_INTEGER_set(x->cert_info.version, version)); |
0f113f3e | 32 | } |
d02b48c6 | 33 | |
6b691a5c | 34 | int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial) |
0f113f3e MC |
35 | { |
36 | ASN1_INTEGER *in; | |
d02b48c6 | 37 | |
0f113f3e | 38 | if (x == NULL) |
81e49438 DSH |
39 | return 0; |
40 | in = &x->cert_info.serialNumber; | |
41 | if (in != serial) | |
42 | return ASN1_STRING_copy(in, serial); | |
43 | return 1; | |
0f113f3e | 44 | } |
d02b48c6 | 45 | |
6b691a5c | 46 | int X509_set_issuer_name(X509 *x, X509_NAME *name) |
0f113f3e | 47 | { |
5cf6abd8 | 48 | if (x == NULL) |
0f113f3e | 49 | return (0); |
5cf6abd8 | 50 | return (X509_NAME_set(&x->cert_info.issuer, name)); |
0f113f3e | 51 | } |
d02b48c6 | 52 | |
6b691a5c | 53 | int X509_set_subject_name(X509 *x, X509_NAME *name) |
0f113f3e | 54 | { |
5cf6abd8 | 55 | if (x == NULL) |
0f113f3e | 56 | return (0); |
5cf6abd8 | 57 | return (X509_NAME_set(&x->cert_info.subject, name)); |
0f113f3e | 58 | } |
d02b48c6 | 59 | |
3a60d6fa | 60 | int x509_set1_time(ASN1_TIME **ptm, const ASN1_TIME *tm) |
0f113f3e MC |
61 | { |
62 | ASN1_TIME *in; | |
3a60d6fa | 63 | in = *ptm; |
0f113f3e | 64 | if (in != tm) { |
f422a514 | 65 | in = ASN1_STRING_dup(tm); |
0f113f3e | 66 | if (in != NULL) { |
3a60d6fa DSH |
67 | ASN1_TIME_free(*ptm); |
68 | *ptm = in; | |
0f113f3e MC |
69 | } |
70 | } | |
71 | return (in != NULL); | |
72 | } | |
d02b48c6 | 73 | |
568ce3a5 | 74 | int X509_set1_notBefore(X509 *x, const ASN1_TIME *tm) |
0f113f3e | 75 | { |
3a60d6fa DSH |
76 | if (x == NULL) |
77 | return 0; | |
78 | return x509_set1_time(&x->cert_info.validity.notBefore, tm); | |
79 | } | |
d02b48c6 | 80 | |
568ce3a5 | 81 | int X509_set1_notAfter(X509 *x, const ASN1_TIME *tm) |
3a60d6fa | 82 | { |
2869e79f | 83 | if (x == NULL) |
3a60d6fa DSH |
84 | return 0; |
85 | return x509_set1_time(&x->cert_info.validity.notAfter, tm); | |
0f113f3e | 86 | } |
d02b48c6 | 87 | |
6b691a5c | 88 | int X509_set_pubkey(X509 *x, EVP_PKEY *pkey) |
0f113f3e | 89 | { |
5cf6abd8 | 90 | if (x == NULL) |
0f113f3e | 91 | return (0); |
5cf6abd8 | 92 | return (X509_PUBKEY_set(&(x->cert_info.key), pkey)); |
0f113f3e | 93 | } |
05f0fb9f | 94 | |
c5ebfcab | 95 | int X509_up_ref(X509 *x) |
05f0fb9f | 96 | { |
c001ce33 | 97 | int i; |
c5ebfcab | 98 | |
2f545ae4 | 99 | if (CRYPTO_UP_REF(&x->references, &i, x->lock) <= 0) |
c5ebfcab F |
100 | return 0; |
101 | ||
102 | REF_PRINT_COUNT("X509", x); | |
103 | REF_ASSERT_ISNT(i < 2); | |
104 | return ((i > 1) ? 1 : 0); | |
05f0fb9f | 105 | } |
f728254a | 106 | |
1421aead | 107 | long X509_get_version(const X509 *x) |
f728254a | 108 | { |
5cf6abd8 | 109 | return ASN1_INTEGER_get(x->cert_info.version); |
f728254a DSH |
110 | } |
111 | ||
568ce3a5 DSH |
112 | const ASN1_TIME *X509_get0_notBefore(const X509 *x) |
113 | { | |
114 | return x->cert_info.validity.notBefore; | |
115 | } | |
116 | ||
117 | const ASN1_TIME *X509_get0_notAfter(const X509 *x) | |
118 | { | |
119 | return x->cert_info.validity.notAfter; | |
120 | } | |
121 | ||
0b7347ef | 122 | ASN1_TIME *X509_getm_notBefore(const X509 *x) |
f728254a | 123 | { |
5cf6abd8 | 124 | return x->cert_info.validity.notBefore; |
f728254a DSH |
125 | } |
126 | ||
0b7347ef | 127 | ASN1_TIME *X509_getm_notAfter(const X509 *x) |
f728254a | 128 | { |
5cf6abd8 | 129 | return x->cert_info.validity.notAfter; |
f728254a DSH |
130 | } |
131 | ||
132 | int X509_get_signature_type(const X509 *x) | |
133 | { | |
6e63c142 | 134 | return EVP_PKEY_type(OBJ_obj2nid(x->sig_alg.algorithm)); |
f728254a DSH |
135 | } |
136 | ||
137 | X509_PUBKEY *X509_get_X509_PUBKEY(const X509 *x) | |
138 | { | |
5cf6abd8 | 139 | return x->cert_info.key; |
f728254a | 140 | } |
748118a8 | 141 | |
8900f3e3 | 142 | const STACK_OF(X509_EXTENSION) *X509_get0_extensions(const X509 *x) |
748118a8 DSH |
143 | { |
144 | return x->cert_info.extensions; | |
145 | } | |
146 | ||
8900f3e3 DSH |
147 | void X509_get0_uids(const X509 *x, const ASN1_BIT_STRING **piuid, |
148 | const ASN1_BIT_STRING **psuid) | |
748118a8 DSH |
149 | { |
150 | if (piuid != NULL) | |
151 | *piuid = x->cert_info.issuerUID; | |
152 | if (psuid != NULL) | |
153 | *psuid = x->cert_info.subjectUID; | |
154 | } | |
155 | ||
8900f3e3 | 156 | const X509_ALGOR *X509_get0_tbs_sigalg(const X509 *x) |
748118a8 DSH |
157 | { |
158 | return &x->cert_info.signature; | |
159 | } |