Debian Codegraph @

upstream/debian-unstable/man3/SSL_CTX_use_certificate.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "SSL_CTX_USE_CERTIFICATE 3SSL"
58 .TH SSL_CTX_USE_CERTIFICATE 3SSL 2026-04-07 3.6.2 OpenSSL
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 SSL_CTX_use_certificate, SSL_CTX_use_certificate_ASN1,
65 SSL_CTX_use_certificate_file, SSL_use_certificate, SSL_use_certificate_ASN1,
66 SSL_use_certificate_file, SSL_CTX_use_certificate_chain_file,
67 SSL_use_certificate_chain_file,
68 SSL_CTX_use_PrivateKey, SSL_CTX_use_PrivateKey_ASN1,
69 SSL_CTX_use_PrivateKey_file, SSL_CTX_use_RSAPrivateKey,
70 SSL_CTX_use_RSAPrivateKey_ASN1, SSL_CTX_use_RSAPrivateKey_file,
71 SSL_use_PrivateKey_file, SSL_use_PrivateKey_ASN1, SSL_use_PrivateKey,
72 SSL_use_RSAPrivateKey, SSL_use_RSAPrivateKey_ASN1,
73 SSL_use_RSAPrivateKey_file, SSL_CTX_check_private_key, SSL_check_private_key,
74 SSL_CTX_use_cert_and_key, SSL_use_cert_and_key
75 \&\- load certificate and key data
76 .SH SYNOPSIS
77 .IX Header "SYNOPSIS"
78 .Vb 1
79 \& #include <openssl/ssl.h>
80 \&
81 \& int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
82 \& int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, const unsigned char *d);
83 \& int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
84 \& int SSL_use_certificate(SSL *ssl, X509 *x);
85 \& int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len);
86 \& int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
87 \&
88 \& int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file);
89 \& int SSL_use_certificate_chain_file(SSL *ssl, const char *file);
90 \&
91 \& int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
92 \& int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx, const unsigned char *d,
93 \& long len);
94 \& int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
95 \& int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
96 \& int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, long len);
97 \& int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
98 \& int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
99 \& int SSL_use_PrivateKey_ASN1(int pk, SSL *ssl, const unsigned char *d, long len);
100 \& int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
101 \& int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
102 \& int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, const unsigned char *d, long len);
103 \& int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
104 \&
105 \& int SSL_CTX_check_private_key(const SSL_CTX *ctx);
106 \& int SSL_check_private_key(const SSL *ssl);
107 \&
108 \& int SSL_CTX_use_cert_and_key(SSL_CTX *ctx, X509 *x, EVP_PKEY *pkey, STACK_OF(X509) *chain, int override);
109 \& int SSL_use_cert_and_key(SSL *ssl, X509 *x, EVP_PKEY *pkey, STACK_OF(X509) *chain, int override);
110 .Ve
111 .SH DESCRIPTION
112 .IX Header "DESCRIPTION"
113 These functions load the certificates and private keys into the SSL_CTX
114 or SSL object, respectively.
115 .PP
116 The SSL_CTX_* class of functions loads the certificates and keys into the
117 SSL_CTX object \fBctx\fR. The information is passed to SSL objects \fBssl\fR
118 created from \fBctx\fR with \fBSSL_new\fR\|(3) by copying, so that
119 changes applied to \fBctx\fR do not propagate to already existing SSL objects.
120 .PP
121 The SSL_* class of functions only loads certificates and keys into a
122 specific SSL object. The specific information is kept, when
123 \&\fBSSL_clear\fR\|(3) is called for this SSL object.
124 .PP
125 \&\fBSSL_CTX_use_certificate()\fR loads the certificate \fBx\fR into \fBctx\fR,
126 \&\fBSSL_use_certificate()\fR loads \fBx\fR into \fBssl\fR. The rest of the
127 certificates needed to form the complete certificate chain can be
128 specified using the
129 \&\fBSSL_CTX_add_extra_chain_cert\fR\|(3)
130 function. On success the reference counter of the \fBx\fR is incremented.
131 .PP
132 \&\fBSSL_CTX_use_certificate_ASN1()\fR loads the ASN1 encoded certificate from
133 the memory location \fBd\fR (with length \fBlen\fR) into \fBctx\fR,
134 \&\fBSSL_use_certificate_ASN1()\fR loads the ASN1 encoded certificate into \fBssl\fR.
135 .PP
136 \&\fBSSL_CTX_use_certificate_file()\fR loads the first certificate stored in \fBfile\fR
137 into \fBctx\fR. The formatting \fBtype\fR of the certificate must be specified
138 from the known types SSL_FILETYPE_PEM, SSL_FILETYPE_ASN1.
139 \&\fBSSL_use_certificate_file()\fR loads the certificate from \fBfile\fR into \fBssl\fR.
140 See the NOTES section on why \fBSSL_CTX_use_certificate_chain_file()\fR
141 should be preferred.
142 .PP
143 \&\fBSSL_CTX_use_certificate_chain_file()\fR loads a certificate chain from
144 \&\fBfile\fR into \fBctx\fR. The certificates must be in PEM format and must
145 be sorted starting with the subject's certificate (actual client or server
146 certificate), followed by intermediate CA certificates if applicable, and
147 ending at the highest level (root) CA. \fBSSL_use_certificate_chain_file()\fR is
148 similar except it loads the certificate chain into \fBssl\fR.
149 .PP
150 \&\fBSSL_CTX_use_PrivateKey()\fR adds \fBpkey\fR as private key to \fBctx\fR. \fBctx\fR \fBMUST NOT\fR be NULL.
151 \&\fBSSL_CTX_use_RSAPrivateKey()\fR adds the private key \fBrsa\fR of type RSA
152 to \fBctx\fR. \fBSSL_use_PrivateKey()\fR adds \fBpkey\fR as private key to \fBssl\fR;
153 \&\fBSSL_use_RSAPrivateKey()\fR adds \fBrsa\fR as private key of type RSA to \fBssl\fR.
154 If a certificate has already been set and the private key does not belong
155 to the certificate an error is returned. To change a [certificate/private\-key]
156 pair, the new certificate needs to be set first with \fBSSL_use_certificate()\fR or
157 \&\fBSSL_CTX_use_certificate()\fR before setting the private key with
158 \&\fBSSL_CTX_use_PrivateKey()\fR or \fBSSL_use_PrivateKey()\fR.
159 On success the reference counter of the \fBpkey\fR/\fBrsa\fR is incremented.
160 .PP
161 \&\fBSSL_CTX_use_cert_and_key()\fR and \fBSSL_use_cert_and_key()\fR assign the X.509
162 certificate \fBx\fR, private key \fBkey\fR, and certificate \fBchain\fR onto the
163 corresponding \fBssl\fR or \fBctx\fR. The \fBpkey\fR argument must be the private
164 key of the X.509 certificate \fBx\fR. If the \fBoverride\fR argument is 0, then
165 \&\fBx\fR, \fBpkey\fR and \fBchain\fR are set only if all were not previously set.
166 If \fBoverride\fR is non\-0, then the certificate, private key and chain certs
167 are always set. If \fBpkey\fR is NULL, then the public key of \fBx\fR is used as
168 the private key. This is intended to be used with hardware (via the ENGINE
169 interface) that stores the private key securely, such that it cannot be
170 accessed by OpenSSL. The reference count of the public key is incremented
171 (twice if there is no private key); it is not copied nor duplicated. This
172 allows all private key validations checks to succeed without an actual
173 private key being assigned via \fBSSL_CTX_use_PrivateKey()\fR, etc.
174 .PP
175 \&\fBSSL_CTX_use_PrivateKey_ASN1()\fR adds the private key of type \fBpk\fR
176 stored at memory location \fBd\fR (length \fBlen\fR) to \fBctx\fR.
177 \&\fBSSL_CTX_use_RSAPrivateKey_ASN1()\fR adds the private key of type RSA
178 stored at memory location \fBd\fR (length \fBlen\fR) to \fBctx\fR.
179 \&\fBSSL_use_PrivateKey_ASN1()\fR and \fBSSL_use_RSAPrivateKey_ASN1()\fR add the private
180 key to \fBssl\fR.
181 .PP
182 \&\fBSSL_CTX_use_PrivateKey_file()\fR adds the first private key found in
183 \&\fBfile\fR to \fBctx\fR. The formatting \fBtype\fR of the private key must be specified
184 from the known types SSL_FILETYPE_PEM, SSL_FILETYPE_ASN1.
185 \&\fBSSL_CTX_use_RSAPrivateKey_file()\fR adds the first private RSA key found in
186 \&\fBfile\fR to \fBctx\fR. \fBSSL_use_PrivateKey_file()\fR adds the first private key found
187 in \fBfile\fR to \fBssl\fR; \fBSSL_use_RSAPrivateKey_file()\fR adds the first private
188 RSA key found to \fBssl\fR. \fBctx\fR \fBMUST NOT\fR be NULL.
189 .PP
190 \&\fBSSL_CTX_check_private_key()\fR checks the consistency of a private key with
191 the corresponding certificate loaded into \fBctx\fR. If more than one
192 key/certificate pair (RSA/DSA) is installed, the last item installed will
193 be checked. If e.g. the last item was an RSA certificate or key, the RSA
194 key/certificate pair will be checked. \fBSSL_check_private_key()\fR performs
195 the same check for \fBssl\fR. If no key/certificate was explicitly added for
196 this \fBssl\fR, the last item added into \fBctx\fR will be checked.
197 .SH NOTES
198 .IX Header "NOTES"
199 The internal certificate store of OpenSSL can hold several private
200 key/certificate pairs at a time. The certificate used depends on the
201 cipher selected, see also \fBSSL_CTX_set_cipher_list\fR\|(3).
202 .PP
203 When reading certificates and private keys from file, files of type
204 SSL_FILETYPE_ASN1 (also known as \fBDER\fR, binary encoding) can only contain
205 one certificate or private key, consequently
206 \&\fBSSL_CTX_use_certificate_chain_file()\fR is only applicable to PEM formatting.
207 Files of type SSL_FILETYPE_PEM can contain more than one item.
208 .PP
209 \&\fBSSL_CTX_use_certificate_chain_file()\fR adds the first certificate found
210 in the file to the certificate store. The other certificates are added
211 to the store of chain certificates using \fBSSL_CTX_add1_chain_cert\fR\|(3).
212 Note: versions of OpenSSL before 1.0.2 only had a single
213 certificate chain store for all certificate types, OpenSSL 1.0.2 and later
214 have a separate chain store for each type. \fBSSL_CTX_use_certificate_chain_file()\fR
215 should be used instead of the \fBSSL_CTX_use_certificate_file()\fR function in order
216 to allow the use of complete certificate chains even when no trusted CA
217 storage is used or when the CA issuing the certificate shall not be added to
218 the trusted CA storage.
219 .PP
220 If additional certificates are needed to complete the chain during the
221 TLS negotiation, CA certificates are additionally looked up in the
222 locations of trusted CA certificates, see
223 \&\fBSSL_CTX_load_verify_locations\fR\|(3).
224 .PP
225 The private keys loaded from file can be encrypted. In order to successfully
226 load encrypted keys, a function returning the passphrase must have been
227 supplied, see
228 \&\fBSSL_CTX_set_default_passwd_cb\fR\|(3).
229 (Certificate files might be encrypted as well from the technical point
230 of view, it however does not make sense as the data in the certificate
231 is considered public anyway.)
232 .PP
233 All of the functions to set a new certificate will replace any existing
234 certificate of the same type that has already been set. Similarly all of the
235 functions to set a new private key will replace any private key that has already
236 been set. Applications should call \fBSSL_CTX_check_private_key\fR\|(3) or
237 \&\fBSSL_check_private_key\fR\|(3) as appropriate after loading a new certificate and
238 private key to confirm that the certificate and key match.
239 .SH "RETURN VALUES"
240 .IX Header "RETURN VALUES"
241 On success, the functions return 1.
242 Otherwise check out the error stack to find out the reason.
243 .SH "SEE ALSO"
244 .IX Header "SEE ALSO"
245 \&\fBssl\fR\|(7), \fBSSL_new\fR\|(3), \fBSSL_clear\fR\|(3),
246 \&\fBSSL_CTX_load_verify_locations\fR\|(3),
247 \&\fBSSL_CTX_set_default_passwd_cb\fR\|(3),
248 \&\fBSSL_CTX_set_cipher_list\fR\|(3),
249 \&\fBSSL_CTX_set_client_CA_list\fR\|(3),
250 \&\fBSSL_CTX_set_client_cert_cb\fR\|(3),
251 \&\fBSSL_CTX_add_extra_chain_cert\fR\|(3)
252 .SH COPYRIGHT
253 .IX Header "COPYRIGHT"
254 Copyright 2000\-2024 The OpenSSL Project Authors. All Rights Reserved.
255 .PP
256 Licensed under the Apache License 2.0 (the "License"). You may not use
257 this file except in compliance with the License. You can obtain a copy
258 in the file LICENSE in the source distribution or at
259 <https://www.openssl.org/source/license.html>.