xref: /openbsd/lib/libcrypto/man/X509_new.3 (revision 4cfece93)
1.\" $OpenBSD: X509_new.3,v 1.22 2019/08/23 12:23:39 schwarze Exp $
2.\" full merge up to: OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400
3.\"
4.\" This file is a derived work.
5.\" The changes are covered by the following Copyright and license:
6.\"
7.\" Copyright (c) 2016, 2018, 2019 Ingo Schwarze <schwarze@openbsd.org>
8.\"
9.\" Permission to use, copy, modify, and distribute this software for any
10.\" purpose with or without fee is hereby granted, provided that the above
11.\" copyright notice and this permission notice appear in all copies.
12.\"
13.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20.\"
21.\" The original file was written by Dr. Stephen Henson <steve@openssl.org>.
22.\" Copyright (c) 2002, 2006, 2015, 2016 The OpenSSL Project.
23.\" All rights reserved.
24.\"
25.\" Redistribution and use in source and binary forms, with or without
26.\" modification, are permitted provided that the following conditions
27.\" are met:
28.\"
29.\" 1. Redistributions of source code must retain the above copyright
30.\"    notice, this list of conditions and the following disclaimer.
31.\"
32.\" 2. Redistributions in binary form must reproduce the above copyright
33.\"    notice, this list of conditions and the following disclaimer in
34.\"    the documentation and/or other materials provided with the
35.\"    distribution.
36.\"
37.\" 3. All advertising materials mentioning features or use of this
38.\"    software must display the following acknowledgment:
39.\"    "This product includes software developed by the OpenSSL Project
40.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
41.\"
42.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
43.\"    endorse or promote products derived from this software without
44.\"    prior written permission. For written permission, please contact
45.\"    openssl-core@openssl.org.
46.\"
47.\" 5. Products derived from this software may not be called "OpenSSL"
48.\"    nor may "OpenSSL" appear in their names without prior written
49.\"    permission of the OpenSSL Project.
50.\"
51.\" 6. Redistributions of any form whatsoever must retain the following
52.\"    acknowledgment:
53.\"    "This product includes software developed by the OpenSSL Project
54.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
55.\"
56.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
57.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
60.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
61.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
62.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
63.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
64.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
65.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
66.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
67.\" OF THE POSSIBILITY OF SUCH DAMAGE.
68.\"
69.Dd $Mdocdate: August 23 2019 $
70.Dt X509_NEW 3
71.Os
72.Sh NAME
73.Nm X509_new ,
74.Nm X509_dup ,
75.Nm X509_free ,
76.Nm X509_up_ref ,
77.Nm X509_chain_up_ref
78.Nd X.509 certificate object
79.Sh SYNOPSIS
80.In openssl/x509.h
81.Ft X509 *
82.Fn X509_new void
83.Ft X509 *
84.Fo X509_dup
85.Fa "X509 *a"
86.Fc
87.Ft void
88.Fo X509_free
89.Fa "X509 *a"
90.Fc
91.Ft int
92.Fo X509_up_ref
93.Fa "X509 *a"
94.Fc
95.Ft STACK_OF(X509) *
96.Fo X509_chain_up_ref
97.Fa "STACK_OF(X509) *chain"
98.Fc
99.Sh DESCRIPTION
100.Fn X509_new
101allocates and initializes an empty
102.Vt X509
103object with reference count 1.
104It represents an ASN.1
105.Vt Certificate
106structure defined in RFC 5280 section 4.1.
107It can hold a public key together with information about the person,
108organization, device, or function the associated private key belongs to.
109.Pp
110.Fn X509_dup
111creates a deep copy of
112.Fa a
113using
114.Xr ASN1_item_dup 3 ,
115setting the reference count of the copy to 1.
116.Pp
117.Fn X509_free
118decrements the reference count of the
119.Vt X509
120structure
121.Fa a
122and frees it up if the reference count reaches 0.
123If
124.Fa a
125is a
126.Dv NULL
127pointer, no action occurs.
128.Pp
129.Fn X509_up_ref
130increments the reference count of
131.Fa a
132by 1.
133This function is useful if a certificate structure is being used
134by several different operations each of which will free it up after
135use: this avoids the need to duplicate the entire certificate
136structure.
137.Pp
138.Fn X509_chain_up_ref
139performs a shallow copy of the given
140.Fa chain
141using
142.Fn sk_X509_dup
143and increments the reference count of each contained certificate
144by 1.
145Its purpose is similar to
146.Fn X509_up_ref :
147The returned chain persists after the original is freed.
148.Sh RETURN VALUES
149.Fn X509_new
150and
151.Fn X509_dup
152return a pointer to the newly allocated object or
153.Dv NULL
154if an error occurs; an error code can be obtained by
155.Xr ERR_get_error 3 .
156.Pp
157.Fn X509_up_ref
158returns 1 for success or 0 for failure.
159.Pp
160.Fn X509_chain_up_ref
161returns the copy of the
162.Fa chain
163or
164.Dv NULL
165if an error occurs.
166.Sh SEE ALSO
167.Xr AUTHORITY_KEYID_new 3 ,
168.Xr BASIC_CONSTRAINTS_new 3 ,
169.Xr crypto 3 ,
170.Xr d2i_X509 3 ,
171.Xr PKCS8_PRIV_KEY_INFO_new 3 ,
172.Xr X509_ALGOR_new 3 ,
173.Xr X509_ATTRIBUTE_new 3 ,
174.Xr X509_check_ca 3 ,
175.Xr X509_check_host 3 ,
176.Xr X509_check_issued 3 ,
177.Xr X509_check_private_key 3 ,
178.Xr X509_check_purpose 3 ,
179.Xr X509_CINF_new 3 ,
180.Xr X509_cmp 3 ,
181.Xr X509_CRL_new 3 ,
182.Xr X509_digest 3 ,
183.Xr X509_EXTENSION_new 3 ,
184.Xr X509_get0_notBefore 3 ,
185.Xr X509_get0_signature 3 ,
186.Xr X509_get1_email 3 ,
187.Xr X509_get_ex_new_index 3 ,
188.Xr X509_get_pubkey 3 ,
189.Xr X509_get_serialNumber 3 ,
190.Xr X509_get_subject_name 3 ,
191.Xr X509_get_version 3 ,
192.Xr X509_INFO_new 3 ,
193.Xr X509_NAME_new 3 ,
194.Xr X509_PUBKEY_new 3 ,
195.Xr X509_REQ_new 3 ,
196.Xr X509_SIG_new 3 ,
197.Xr X509_sign 3 ,
198.Xr X509_STORE_CTX_new 3 ,
199.Xr X509_STORE_new 3
200.Sh STANDARDS
201RFC 5280: Internet X.509 Public Key Infrastructure Certificate and
202Certificate Revocation List (CRL) Profile
203.Sh HISTORY
204.Fn X509_new
205and
206.Fn X509_free
207appeared in SSLeay 0.4 or earlier.
208.Fn X509_dup
209first appeared in SSLeay 0.4.4.
210These functions have been available since
211.Ox 2.4 .
212.Pp
213.Fn X509_up_ref
214first appeared in OpenSSL 1.1.0 and has been available since
215.Ox 6.1 .
216.Pp
217.Fn X509_chain_up_ref
218first appeared in OpenSSL 1.0.2 and has been available since
219.Ox 6.3 .
220.Sh BUGS
221The X.509 public key infrastructure and its data types contain too
222many design bugs to list them.
223For lots of examples, see the classic
224.Lk https://www.cs.auckland.ac.nz/~pgut001/pubs/x509guide.txt\
225 "X.509 Style Guide"
226that
227.An Peter Gutmann
228published in 2000.
229