1.\" $OpenBSD: X509_sign.3,v 1.8 2019/06/14 13:59:32 schwarze Exp $ 2.\" OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400 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: June 14 2019 $ 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.Pp 153For efficiency reasons and to work around ASN.1 encoding issues, the 154encoding of the signed portion of a certificate, certificate request, 155and CRL is cached internally. 156If the signed portion of the structure is modified, the encoding is not 157always updated, meaning a stale version is sometimes used. 158This is not normally a problem because modifying the signed portion will 159invalidate the signature and signing will always update the encoding. 160.Sh RETURN VALUES 161.Fn X509_sign , 162.Fn X509_sign_ctx , 163.Fn X509_REQ_sign , 164.Fn X509_REQ_sign_ctx , 165.Fn X509_CRL_sign , 166and 167.Fn X509_CRL_sign_ctx 168return the size of the signature in bytes for success or 0 for failure. 169.Pp 170.Fn X509_verify , 171.Fn X509_REQ_verify , 172and 173.Fn X509_CRL_verify 174return 1 if the signature is valid or 0 if the signature check fails. 175If the signature could not be checked at all because it was invalid or 176some other error occurred, then -1 is returned. 177.Pp 178In some cases of failure, the reason can be determined with 179.Xr ERR_get_error 3 . 180.Sh SEE ALSO 181.Xr d2i_X509 3 , 182.Xr EVP_DigestInit 3 , 183.Xr X509_CRL_get0_by_serial 3 , 184.Xr X509_CRL_new 3 , 185.Xr X509_get_pubkey 3 , 186.Xr X509_get_subject_name 3 , 187.Xr X509_get_version 3 , 188.Xr X509_NAME_add_entry_by_txt 3 , 189.Xr X509_NAME_ENTRY_get_object 3 , 190.Xr X509_NAME_get_index_by_NID 3 , 191.Xr X509_NAME_print_ex 3 , 192.Xr X509_new 3 , 193.Xr X509_REQ_new 3 , 194.Xr X509_verify_cert 3 , 195.Xr X509V3_get_d2i 3 196.Sh HISTORY 197.Fn X509_verify 198appeared in SSLeay 0.4 or earlier. 199.Fn X509_sign 200and 201.Fn X509_REQ_sign 202first appeared in SSLeay 0.4.4. 203.Fn X509_REQ_verify 204and 205.Fn X509_CRL_verify 206first appeared in SSLeay 0.4.5b. 207.Fn X509_CRL_sign 208first appeared in SSLeay 0.5.1. 209These functions have been available since 210.Ox 2.4 . 211.Pp 212.Fn X509_sign_ctx , 213.Fn X509_REQ_sign_ctx , 214and 215.Fn X509_CRL_sign_ctx 216first appeared in OpenSSL 1.0.1 and have been available since 217.Ox 5.3 . 218