xref: /openbsd-src/lib/libcrypto/man/X509_sign.3 (revision fc405d53b73a2d73393cb97f684863d17b583e38)
1.\" $OpenBSD: X509_sign.3,v 1.10 2023/04/28 15:51:18 job Exp $
2.\" full merge up to: OpenSSL df75c2bf Dec 9 01:02:36 2018 +0100
3.\"
4.\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
5.\" Copyright (c) 2015, 2016 The OpenSSL Project.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in
16.\"    the documentation and/or other materials provided with the
17.\"    distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\"    software must display the following acknowledgment:
21.\"    "This product includes software developed by the OpenSSL Project
22.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\"    endorse or promote products derived from this software without
26.\"    prior written permission. For written permission, please contact
27.\"    openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\"    nor may "OpenSSL" appear in their names without prior written
31.\"    permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\"    acknowledgment:
35.\"    "This product includes software developed by the OpenSSL Project
36.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: April 28 2023 $
52.Dt X509_SIGN 3
53.Os
54.Sh NAME
55.Nm X509_sign ,
56.Nm X509_sign_ctx ,
57.Nm X509_verify ,
58.Nm X509_REQ_sign ,
59.Nm X509_REQ_sign_ctx ,
60.Nm X509_REQ_verify ,
61.Nm X509_CRL_sign ,
62.Nm X509_CRL_sign_ctx ,
63.Nm X509_CRL_verify
64.Nd sign or verify certificate, certificate request, or CRL signature
65.Sh SYNOPSIS
66.In openssl/x509.h
67.Ft int
68.Fo X509_sign
69.Fa "X509 *x"
70.Fa "EVP_PKEY *pkey"
71.Fa "const EVP_MD *md"
72.Fc
73.Ft int
74.Fo X509_sign_ctx
75.Fa "X509 *x"
76.Fa "EVP_MD_CTX *ctx"
77.Fc
78.Ft int
79.Fo X509_verify
80.Fa "X509 *a"
81.Fa "EVP_PKEY *r"
82.Fc
83.Ft int
84.Fo X509_REQ_sign
85.Fa "X509_REQ *x"
86.Fa "EVP_PKEY *pkey"
87.Fa "const EVP_MD *md"
88.Fc
89.Ft int
90.Fo X509_REQ_sign_ctx
91.Fa "X509_REQ *x"
92.Fa "EVP_MD_CTX *ctx"
93.Fc
94.Ft int
95.Fo X509_REQ_verify
96.Fa "X509_REQ *a"
97.Fa "EVP_PKEY *r"
98.Fc
99.Ft int
100.Fo X509_CRL_sign
101.Fa "X509_CRL *x"
102.Fa "EVP_PKEY *pkey"
103.Fa "const EVP_MD *md"
104.Fc
105.Ft int
106.Fo X509_CRL_sign_ctx
107.Fa "X509_CRL *x"
108.Fa "EVP_MD_CTX *ctx"
109.Fc
110.Ft int
111.Fo X509_CRL_verify
112.Fa "X509_CRL *a"
113.Fa "EVP_PKEY *r"
114.Fc
115.Sh DESCRIPTION
116.Fn X509_sign
117signs the certificate
118.Fa x
119using the private key
120.Fa pkey
121and the message digest
122.Fa md
123and sets the signature in
124.Fa x .
125.Fn X509_sign_ctx
126also signs the certificate
127.Fa x
128but uses the parameters contained in digest context
129.Fa ctx .
130.Pp
131.Fn X509_verify
132verifies the signature of certificate
133.Fa x
134using the public key
135.Fa pkey .
136Only the signature is checked: no other checks (such as certificate
137chain validity) are performed.
138.Pp
139.Fn X509_REQ_sign ,
140.Fn X509_REQ_sign_ctx ,
141.Fn X509_REQ_verify ,
142.Fn X509_CRL_sign ,
143.Fn X509_CRL_sign_ctx ,
144and
145.Fn X509_CRL_verify
146sign and verify certificate requests and CRLs, respectively.
147.Pp
148If
149.Xr X509_CRL_set_default_method 3
150was in effect at the time the
151.Vt X509_CRL
152object was created,
153.Fn X509_CRL_verify
154calls the
155.Fn crl_verify
156callback function instead of performing the default action.
157.Pp
158.Fn X509_sign_ctx
159is used where the default parameters for the corresponding public key
160and digest are not suitable.
161It can be used to sign keys using RSA-PSS for example.
162.Sh RETURN VALUES
163.Fn X509_sign ,
164.Fn X509_sign_ctx ,
165.Fn X509_REQ_sign ,
166.Fn X509_REQ_sign_ctx ,
167.Fn X509_CRL_sign ,
168and
169.Fn X509_CRL_sign_ctx
170return the size of the signature in bytes for success or 0 for failure.
171.Pp
172.Fn X509_verify ,
173.Fn X509_REQ_verify ,
174and
175.Fn X509_CRL_verify
176return 1 if the signature is valid or 0 if the signature check fails.
177If the signature could not be checked at all because it was invalid or
178some other error occurred, then -1 is returned.
179.Pp
180In some cases of failure, the reason can be determined with
181.Xr ERR_get_error 3 .
182.Sh SEE ALSO
183.Xr d2i_X509 3 ,
184.Xr EVP_DigestInit 3 ,
185.Xr X509_CRL_get0_by_serial 3 ,
186.Xr X509_CRL_METHOD_new 3 ,
187.Xr X509_CRL_new 3 ,
188.Xr X509_get_pubkey 3 ,
189.Xr X509_get_subject_name 3 ,
190.Xr X509_get_version 3 ,
191.Xr X509_NAME_add_entry_by_txt 3 ,
192.Xr X509_NAME_ENTRY_get_object 3 ,
193.Xr X509_NAME_get_index_by_NID 3 ,
194.Xr X509_NAME_print_ex 3 ,
195.Xr X509_new 3 ,
196.Xr X509_REQ_new 3 ,
197.Xr X509_verify_cert 3 ,
198.Xr X509V3_get_d2i 3
199.Sh HISTORY
200.Fn X509_verify
201appeared in SSLeay 0.4 or earlier.
202.Fn X509_sign
203and
204.Fn X509_REQ_sign
205first appeared in SSLeay 0.4.4.
206.Fn X509_REQ_verify
207and
208.Fn X509_CRL_verify
209first appeared in SSLeay 0.4.5b.
210.Fn X509_CRL_sign
211first appeared in SSLeay 0.5.1.
212These functions have been available since
213.Ox 2.4 .
214.Pp
215.Fn X509_sign_ctx ,
216.Fn X509_REQ_sign_ctx ,
217and
218.Fn X509_CRL_sign_ctx
219first appeared in OpenSSL 1.0.1 and have been available since
220.Ox 5.3 .
221