2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
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
11 #include "internal/cryptlib.h"
12 #include <openssl/asn1.h>
13 #include <openssl/objects.h>
14 #include <openssl/evp.h>
15 #include <openssl/x509.h>
16 #include "internal/x509_int.h"
18 int X509_set_version(X509 *x, long version)
23 ASN1_INTEGER_free(x->cert_info.version);
24 x->cert_info.version = NULL;
27 if (x->cert_info.version == NULL) {
28 if ((x->cert_info.version = ASN1_INTEGER_new()) == NULL)
31 return (ASN1_INTEGER_set(x->cert_info.version, version));
34 int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial)
40 in = &x->cert_info.serialNumber;
42 return ASN1_STRING_copy(in, serial);
46 int X509_set_issuer_name(X509 *x, X509_NAME *name)
50 return (X509_NAME_set(&x->cert_info.issuer, name));
53 int X509_set_subject_name(X509 *x, X509_NAME *name)
57 return (X509_NAME_set(&x->cert_info.subject, name));
60 int x509_set1_time(ASN1_TIME **ptm, const ASN1_TIME *tm)
65 in = ASN1_STRING_dup(tm);
74 int X509_set1_notBefore(X509 *x, const ASN1_TIME *tm)
78 return x509_set1_time(&x->cert_info.validity.notBefore, tm);
81 int X509_set1_notAfter(X509 *x, const ASN1_TIME *tm)
85 return x509_set1_time(&x->cert_info.validity.notAfter, tm);
88 int X509_set_pubkey(X509 *x, EVP_PKEY *pkey)
92 return (X509_PUBKEY_set(&(x->cert_info.key), pkey));
95 int X509_up_ref(X509 *x)
99 if (CRYPTO_atomic_add(&x->references, 1, &i, x->lock) <= 0)
102 REF_PRINT_COUNT("X509", x);
103 REF_ASSERT_ISNT(i < 2);
104 return ((i > 1) ? 1 : 0);
107 long X509_get_version(const X509 *x)
109 return ASN1_INTEGER_get(x->cert_info.version);
112 const ASN1_TIME *X509_get0_notBefore(const X509 *x)
114 return x->cert_info.validity.notBefore;
117 const ASN1_TIME *X509_get0_notAfter(const X509 *x)
119 return x->cert_info.validity.notAfter;
122 ASN1_TIME *X509_getm_notBefore(const X509 *x)
124 return x->cert_info.validity.notBefore;
127 ASN1_TIME *X509_getm_notAfter(const X509 *x)
129 return x->cert_info.validity.notAfter;
132 int X509_get_signature_type(const X509 *x)
134 return EVP_PKEY_type(OBJ_obj2nid(x->sig_alg.algorithm));
137 X509_PUBKEY *X509_get_X509_PUBKEY(const X509 *x)
139 return x->cert_info.key;
142 const STACK_OF(X509_EXTENSION) *X509_get0_extensions(const X509 *x)
144 return x->cert_info.extensions;
147 void X509_get0_uids(const X509 *x, const ASN1_BIT_STRING **piuid,
148 const ASN1_BIT_STRING **psuid)
151 *piuid = x->cert_info.issuerUID;
153 *psuid = x->cert_info.subjectUID;
156 const X509_ALGOR *X509_get0_tbs_sigalg(const X509 *x)
158 return &x->cert_info.signature;