1SSL_CTX_USE_CERTIFICATE(3ossl) OpenSSL SSL_CTX_USE_CERTIFICATE(3ossl)
2
3
4
6 SSL_CTX_use_certificate, SSL_CTX_use_certificate_ASN1,
7 SSL_CTX_use_certificate_file, SSL_use_certificate,
8 SSL_use_certificate_ASN1, SSL_use_certificate_file,
9 SSL_CTX_use_certificate_chain_file, SSL_use_certificate_chain_file,
10 SSL_CTX_use_PrivateKey, SSL_CTX_use_PrivateKey_ASN1,
11 SSL_CTX_use_PrivateKey_file, SSL_CTX_use_RSAPrivateKey,
12 SSL_CTX_use_RSAPrivateKey_ASN1, SSL_CTX_use_RSAPrivateKey_file,
13 SSL_use_PrivateKey_file, SSL_use_PrivateKey_ASN1, SSL_use_PrivateKey,
14 SSL_use_RSAPrivateKey, SSL_use_RSAPrivateKey_ASN1,
15 SSL_use_RSAPrivateKey_file, SSL_CTX_check_private_key,
16 SSL_check_private_key, SSL_CTX_use_cert_and_key, SSL_use_cert_and_key -
17 load certificate and key data
18
20 #include <openssl/ssl.h>
21
22 int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
23 int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, const unsigned char *d);
24 int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
25 int SSL_use_certificate(SSL *ssl, X509 *x);
26 int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len);
27 int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
28
29 int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file);
30 int SSL_use_certificate_chain_file(SSL *ssl, const char *file);
31
32 int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
33 int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx, const unsigned char *d,
34 long len);
35 int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
36 int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
37 int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, long len);
38 int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
39 int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
40 int SSL_use_PrivateKey_ASN1(int pk, SSL *ssl, const unsigned char *d, long len);
41 int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
42 int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
43 int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, const unsigned char *d, long len);
44 int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
45
46 int SSL_CTX_check_private_key(const SSL_CTX *ctx);
47 int SSL_check_private_key(const SSL *ssl);
48
49 int SSL_CTX_use_cert_and_key(SSL_CTX *ctx, X509 *x, EVP_PKEY *pkey, STACK_OF(X509) *chain, int override);
50 int SSL_use_cert_and_key(SSL *ssl, X509 *x, EVP_PKEY *pkey, STACK_OF(X509) *chain, int override);
51
53 These functions load the certificates and private keys into the SSL_CTX
54 or SSL object, respectively.
55
56 The SSL_CTX_* class of functions loads the certificates and keys into
57 the SSL_CTX object ctx. The information is passed to SSL objects ssl
58 created from ctx with SSL_new(3) by copying, so that changes applied to
59 ctx do not propagate to already existing SSL objects.
60
61 The SSL_* class of functions only loads certificates and keys into a
62 specific SSL object. The specific information is kept, when
63 SSL_clear(3) is called for this SSL object.
64
65 SSL_CTX_use_certificate() loads the certificate x into ctx,
66 SSL_use_certificate() loads x into ssl. The rest of the certificates
67 needed to form the complete certificate chain can be specified using
68 the SSL_CTX_add_extra_chain_cert(3) function.
69
70 SSL_CTX_use_certificate_ASN1() loads the ASN1 encoded certificate from
71 the memory location d (with length len) into ctx,
72 SSL_use_certificate_ASN1() loads the ASN1 encoded certificate into ssl.
73
74 SSL_CTX_use_certificate_file() loads the first certificate stored in
75 file into ctx. The formatting type of the certificate must be specified
76 from the known types SSL_FILETYPE_PEM, SSL_FILETYPE_ASN1.
77 SSL_use_certificate_file() loads the certificate from file into ssl.
78 See the NOTES section on why SSL_CTX_use_certificate_chain_file()
79 should be preferred.
80
81 SSL_CTX_use_certificate_chain_file() loads a certificate chain from
82 file into ctx. The certificates must be in PEM format and must be
83 sorted starting with the subject's certificate (actual client or server
84 certificate), followed by intermediate CA certificates if applicable,
85 and ending at the highest level (root) CA.
86 SSL_use_certificate_chain_file() is similar except it loads the
87 certificate chain into ssl.
88
89 SSL_CTX_use_PrivateKey() adds pkey as private key to ctx.
90 SSL_CTX_use_RSAPrivateKey() adds the private key rsa of type RSA to
91 ctx. SSL_use_PrivateKey() adds pkey as private key to ssl;
92 SSL_use_RSAPrivateKey() adds rsa as private key of type RSA to ssl. If
93 a certificate has already been set and the private key does not belong
94 to the certificate an error is returned. To change a
95 [certificate/private-key] pair, the new certificate needs to be set
96 first with SSL_use_certificate() or SSL_CTX_use_certificate() before
97 setting the private key with SSL_CTX_use_PrivateKey() or
98 SSL_use_PrivateKey().
99
100 SSL_CTX_use_cert_and_key() and SSL_use_cert_and_key() assign the X.509
101 certificate x, private key key, and certificate chain onto the
102 corresponding ssl or ctx. The pkey argument must be the private key of
103 the X.509 certificate x. If the override argument is 0, then x, pkey
104 and chain are set only if all were not previously set. If override is
105 non-0, then the certificate, private key and chain certs are always
106 set. If pkey is NULL, then the public key of x is used as the private
107 key. This is intended to be used with hardware (via the ENGINE
108 interface) that stores the private key securely, such that it cannot be
109 accessed by OpenSSL. The reference count of the public key is
110 incremented (twice if there is no private key); it is not copied nor
111 duplicated. This allows all private key validations checks to succeed
112 without an actual private key being assigned via
113 SSL_CTX_use_PrivateKey(), etc.
114
115 SSL_CTX_use_PrivateKey_ASN1() adds the private key of type pk stored at
116 memory location d (length len) to ctx.
117 SSL_CTX_use_RSAPrivateKey_ASN1() adds the private key of type RSA
118 stored at memory location d (length len) to ctx.
119 SSL_use_PrivateKey_ASN1() and SSL_use_RSAPrivateKey_ASN1() add the
120 private key to ssl.
121
122 SSL_CTX_use_PrivateKey_file() adds the first private key found in file
123 to ctx. The formatting type of the private key must be specified from
124 the known types SSL_FILETYPE_PEM, SSL_FILETYPE_ASN1.
125 SSL_CTX_use_RSAPrivateKey_file() adds the first private RSA key found
126 in file to ctx. SSL_use_PrivateKey_file() adds the first private key
127 found in file to ssl; SSL_use_RSAPrivateKey_file() adds the first
128 private RSA key found to ssl.
129
130 SSL_CTX_check_private_key() checks the consistency of a private key
131 with the corresponding certificate loaded into ctx. If more than one
132 key/certificate pair (RSA/DSA) is installed, the last item installed
133 will be checked. If e.g. the last item was an RSA certificate or key,
134 the RSA key/certificate pair will be checked. SSL_check_private_key()
135 performs the same check for ssl. If no key/certificate was explicitly
136 added for this ssl, the last item added into ctx will be checked.
137
139 The internal certificate store of OpenSSL can hold several private
140 key/certificate pairs at a time. The certificate used depends on the
141 cipher selected, see also SSL_CTX_set_cipher_list(3).
142
143 When reading certificates and private keys from file, files of type
144 SSL_FILETYPE_ASN1 (also known as DER, binary encoding) can only contain
145 one certificate or private key, consequently
146 SSL_CTX_use_certificate_chain_file() is only applicable to PEM
147 formatting. Files of type SSL_FILETYPE_PEM can contain more than one
148 item.
149
150 SSL_CTX_use_certificate_chain_file() adds the first certificate found
151 in the file to the certificate store. The other certificates are added
152 to the store of chain certificates using SSL_CTX_add1_chain_cert(3).
153 Note: versions of OpenSSL before 1.0.2 only had a single certificate
154 chain store for all certificate types, OpenSSL 1.0.2 and later have a
155 separate chain store for each type.
156 SSL_CTX_use_certificate_chain_file() should be used instead of the
157 SSL_CTX_use_certificate_file() function in order to allow the use of
158 complete certificate chains even when no trusted CA storage is used or
159 when the CA issuing the certificate shall not be added to the trusted
160 CA storage.
161
162 If additional certificates are needed to complete the chain during the
163 TLS negotiation, CA certificates are additionally looked up in the
164 locations of trusted CA certificates, see
165 SSL_CTX_load_verify_locations(3).
166
167 The private keys loaded from file can be encrypted. In order to
168 successfully load encrypted keys, a function returning the passphrase
169 must have been supplied, see SSL_CTX_set_default_passwd_cb(3).
170 (Certificate files might be encrypted as well from the technical point
171 of view, it however does not make sense as the data in the certificate
172 is considered public anyway.)
173
174 All of the functions to set a new certificate will replace any existing
175 certificate of the same type that has already been set. Similarly all
176 of the functions to set a new private key will replace any private key
177 that has already been set. Applications should call
178 SSL_CTX_check_private_key(3) or SSL_check_private_key(3) as appropriate
179 after loading a new certificate and private key to confirm that the
180 certificate and key match.
181
183 On success, the functions return 1. Otherwise check out the error
184 stack to find out the reason.
185
187 ssl(7), SSL_new(3), SSL_clear(3), SSL_CTX_load_verify_locations(3),
188 SSL_CTX_set_default_passwd_cb(3), SSL_CTX_set_cipher_list(3),
189 SSL_CTX_set_client_CA_list(3), SSL_CTX_set_client_cert_cb(3),
190 SSL_CTX_add_extra_chain_cert(3)
191
193 Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
194
195 Licensed under the Apache License 2.0 (the "License"). You may not use
196 this file except in compliance with the License. You can obtain a copy
197 in the file LICENSE in the source distribution or at
198 <https://www.openssl.org/source/license.html>.
199
200
201
2023.0.9 2023-07-27 SSL_CTX_USE_CERTIFICATE(3ossl)