1.\" $OpenBSD: X509_get0_signature.3,v 1.9 2024/08/28 07:18:55 tb Exp $ 2.\" selective merge up to: 3.\" OpenSSL man3/X509_get0_signature 2f7a2520 Apr 25 17:28:08 2017 +0100 4.\" 5.\" This file is a derived work. 6.\" The changes are covered by the following Copyright and license: 7.\" 8.\" Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org> 9.\" 10.\" Permission to use, copy, modify, and distribute this software for any 11.\" purpose with or without fee is hereby granted, provided that the above 12.\" copyright notice and this permission notice appear in all copies. 13.\" 14.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 15.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 16.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 17.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 20.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21.\" 22.\" The original file was written by Dr. Stephen Henson <steve@openssl.org>. 23.\" Copyright (c) 2015 The OpenSSL Project. 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 28 2024 $ 70.Dt X509_GET0_SIGNATURE 3 71.Os 72.Sh NAME 73.Nm X509_get0_signature , 74.Nm X509_REQ_get0_signature , 75.Nm X509_CRL_get0_signature , 76.Nm X509_get0_tbs_sigalg , 77.Nm X509_CRL_get0_tbs_sigalg , 78.Nm X509_get_signature_type , 79.Nm X509_get_signature_nid , 80.Nm X509_REQ_get_signature_nid , 81.Nm X509_CRL_get_signature_nid , 82.Nm X509_get_signature_info 83.Nd signature information 84.Sh SYNOPSIS 85.In openssl/x509.h 86.Ft void 87.Fo X509_get0_signature 88.Fa "const ASN1_BIT_STRING **psig" 89.Fa "const X509_ALGOR **palg" 90.Fa "const X509 *x" 91.Fc 92.Ft void 93.Fo X509_REQ_get0_signature 94.Fa "const X509_REQ *req" 95.Fa "const ASN1_BIT_STRING **psig" 96.Fa "const X509_ALGOR **palg" 97.Fc 98.Ft void 99.Fo X509_CRL_get0_signature 100.Fa "const X509_CRL *crl" 101.Fa "const ASN1_BIT_STRING **psig" 102.Fa "const X509_ALGOR **palg" 103.Fc 104.Ft const X509_ALGOR * 105.Fo X509_get0_tbs_sigalg 106.Fa "const X509 *x" 107.Fc 108.Ft const X509_ALGOR * 109.Fo X509_CRL_get0_tbs_sigalg 110.Fa "const X509_CRL *crl" 111.Fc 112.Ft int 113.Fo X509_get_signature_type 114.Fa "const X509 *x" 115.Fc 116.Ft int 117.Fo X509_get_signature_nid 118.Fa "const X509 *x" 119.Fc 120.Ft int 121.Fo X509_REQ_get_signature_nid 122.Fa "const X509_REQ *req" 123.Fc 124.Ft int 125.Fo X509_CRL_get_signature_nid 126.Fa "const X509_CRL *crl" 127.Fc 128.Ft int 129.Fo X509_get_signature_info 130.Fa "X509 *x" 131.Fa "int *md_nid" 132.Fa "int *pkey_nid" 133.Fa "int *security_bits" 134.Fa "uint32_t *flags" 135.Fc 136.Sh DESCRIPTION 137.Fn X509_get0_signature , 138.Fn X509_REQ_get0_signature , 139and 140.Fn X509_CRL_get0_signature 141set 142.Pf * Fa psig 143to the signature and 144.Pf * Fa palg 145to the signature algorithm of 146.Fa x , 147.Fa req , 148or 149.Fa crl , 150respectively. 151.Fn X509_get0_tbs_sigalg 152and 153.Fn X509_CRL_get0_tbs_sigalg 154return the signature algorithm in the signed portion of 155.Fa x 156or 157.Fa crl , 158respectively. 159The values returned are internal pointers 160that must not be freed by the caller. 161.Pp 162.Fn X509_get_signature_type 163returns the base NID corresponding to the signature algorithm of 164.Fa x 165just like 166.Xr EVP_PKEY_base_id 3 167does. 168.Pp 169.Fn X509_get_signature_nid , 170.Fn X509_REQ_get_signature_nid , 171and 172.Fn X509_CRL_get_signature_nid 173return the NID corresponding to the signature algorithm of 174.Fa x , 175.Fa req , 176or 177.Fa crl , 178respectively, just like 179.Xr EVP_PKEY_id 3 180does. 181.Pp 182.Fn X509_get_signature_info 183retrieves information about the signature of certificate 184.Fa x . 185The NID of the digest algorithm is written to 186.Pf * Fa md_nid , 187the public key algorithm to 188.Pf * Fa pkey_nid , 189the effective security bits to 190.Pf * Fa security_bits , 191and flag details to 192.Pf * Fa flags . 193Any of the output parameters can be set to 194.Dv NULL 195if the information is not required. 196If 197.Fa flags 198is not a 199.Dv NULL 200pointer, 201.Pf * Fa flags 202is set to the bitwise OR of: 203.Bl -tag -width 1n -offset 3n 204.It Dv X509_SIG_INFO_VALID 205No error occurred. 206This flag is set if 207.Fn X509_get_signature_info 208returns 1. 209.It Dv X509_SIG_INFO_TLS 210The signature algorithm is appropriate for use in TLS. 211For a supported EdDSA algorithm (in LibreSSL this is Ed25519) 212this flag is always set. 213For an RSASSA-PSS PSS algorithm this flag is set if 214the parameters are DER encoded, 215the digest algorithm is one of SHA256, SHA384, or SHA512, 216the same digest algorithm is used in the mask generation function, 217and the salt length is equal to the digest algorithm's output length. 218For all other signature algorithms this flag is set if the digest 219algorithm is one of SHA1, SHA256, SHA384, or SHA512. 220.El 221.Pp 222.Fn X509_get_signature_info 223returns 1 on success and 0 on failure. 224Failure conditions include unsupported signature algorithms, 225certificate parsing errors and memory allocation failure. 226.Pp 227These functions provide lower level access to the signature 228for cases where an application wishes to analyse or generate a 229signature in a form where 230.Xr X509_sign 3 231is not appropriate, for example in a non-standard or unsupported format. 232.Sh SEE ALSO 233.Xr EVP_PKEY_base_id 3 , 234.Xr OBJ_obj2nid 3 , 235.Xr X509_ALGOR_new 3 , 236.Xr X509_CRL_get0_by_serial 3 , 237.Xr X509_CRL_new 3 , 238.Xr X509_get_pubkey 3 , 239.Xr X509_get_subject_name 3 , 240.Xr X509_get_version 3 , 241.Xr X509_new 3 , 242.Xr X509_REQ_new 3 , 243.Xr X509_sign 3 , 244.Xr X509_signature_dump 3 , 245.Xr X509_verify_cert 3 246.Sh HISTORY 247.Fn X509_get_signature_type 248first appeared in SSLeay 0.8.0 and has been available since 249.Ox 2.4 . 250.Pp 251.Fn X509_get0_signature 252and 253.Fn X509_get_signature_nid 254first appeared in OpenSSL 1.0.2. 255.Fn X509_REQ_get0_signature , 256.Fn X509_CRL_get0_signature , 257.Fn X509_get0_tbs_sigalg , 258.Fn X509_REQ_get_signature_nid , 259and 260.Fn X509_CRL_get_signature_nid 261first appeared in OpenSSL 1.1.0. 262All these functions have been available since 263.Ox 6.3 . 264.Pp 265.Fn X509_CRL_get0_tbs_sigalg 266first appeared in LibreSSL 3.7.1 and has been available since 267.Ox 7.3 . 268.Pp 269.Fn X509_get_signature_info 270first appeared in OpenSSL 1.1.1 and has been available since 271.Ox 7.6 . 272.Sh CAVEATS 273The security bits returned by 274.Fn X509_get_signature_info 275refer to the information available from the certificate signature 276(such as the signing digest). 277In some cases the actual security of the signature is smaller 278because the signing key is less secure. 279For example in a certificate signed using SHA512 280and a 1024-bit RSA key. 281