1.\" $OpenBSD: X509_sign.3,v 1.11 2024/03/06 02:34:14 tb 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: March 6 2024 $ 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 148.Fn X509_sign_ctx 149is used where the default parameters for the corresponding public key 150and digest are not suitable. 151It can be used to sign keys using RSA-PSS for example. 152.Sh RETURN VALUES 153.Fn X509_sign , 154.Fn X509_sign_ctx , 155.Fn X509_REQ_sign , 156.Fn X509_REQ_sign_ctx , 157.Fn X509_CRL_sign , 158and 159.Fn X509_CRL_sign_ctx 160return the size of the signature in bytes for success or 0 for failure. 161.Pp 162.Fn X509_verify , 163.Fn X509_REQ_verify , 164and 165.Fn X509_CRL_verify 166return 1 if the signature is valid or 0 if the signature check fails. 167If the signature could not be checked at all because it was invalid or 168some other error occurred, then -1 is returned. 169.Pp 170In some cases of failure, the reason can be determined with 171.Xr ERR_get_error 3 . 172.Sh SEE ALSO 173.Xr d2i_X509 3 , 174.Xr EVP_DigestInit 3 , 175.Xr X509_CRL_get0_by_serial 3 , 176.Xr X509_CRL_new 3 , 177.Xr X509_get_pubkey 3 , 178.Xr X509_get_subject_name 3 , 179.Xr X509_get_version 3 , 180.Xr X509_NAME_add_entry_by_txt 3 , 181.Xr X509_NAME_ENTRY_get_object 3 , 182.Xr X509_NAME_get_index_by_NID 3 , 183.Xr X509_NAME_print_ex 3 , 184.Xr X509_new 3 , 185.Xr X509_REQ_new 3 , 186.Xr X509_verify_cert 3 , 187.Xr X509V3_get_d2i 3 188.Sh HISTORY 189.Fn X509_verify 190appeared in SSLeay 0.4 or earlier. 191.Fn X509_sign 192and 193.Fn X509_REQ_sign 194first appeared in SSLeay 0.4.4. 195.Fn X509_REQ_verify 196and 197.Fn X509_CRL_verify 198first appeared in SSLeay 0.4.5b. 199.Fn X509_CRL_sign 200first appeared in SSLeay 0.5.1. 201These functions have been available since 202.Ox 2.4 . 203.Pp 204.Fn X509_sign_ctx , 205.Fn X509_REQ_sign_ctx , 206and 207.Fn X509_CRL_sign_ctx 208first appeared in OpenSSL 1.0.1 and have been available since 209.Ox 5.3 . 210