1SSL_CTX_USE_CERTIFICATE(3)          OpenSSL         SSL_CTX_USE_CERTIFICATE(3)
2
3
4

NAME

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

SYNOPSIS

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, 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, 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, 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, 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, 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, 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

DESCRIPTION

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 does not belong to
94       the certificate an error is returned. To change a certificate, private
95       key pair the new certificate needs to be set with SSL_use_certificate()
96       or SSL_CTX_use_certificate() before setting the private key with
97       SSL_CTX_use_PrivateKey() or SSL_use_PrivateKey().
98
99       SSL_CTX_use_cert_and_key() and SSL_use_cert_and_key() assign the X.509
100       certificate x, private key key, and certificate chain onto the
101       corresponding ssl or ctx. The pkey argument must be the private key of
102       the X.509 certificate x. If the override argument is 0, then x, pkey
103       and chain are set only if all were not previously set.  If override is
104       non-0, then the certificate, private key and chain certs are always
105       set. If pkey is NULL, then the public key of x is used as the private
106       key. This is intended to be used with hardware (via the ENGINE
107       interface) that stores the private key securely, such that it cannot be
108       accessed by OpenSSL. The reference count of the public key is
109       incremented (twice if there is no private key); it is not copied nor
110       duplicated. This allows all private key validations checks to succeed
111       without an actual private key being assigned via
112       SSL_CTX_use_PrivateKey(), etc.
113
114       SSL_CTX_use_PrivateKey_ASN1() adds the private key of type pk stored at
115       memory location d (length len) to ctx.
116       SSL_CTX_use_RSAPrivateKey_ASN1() adds the private key of type RSA
117       stored at memory location d (length len) to ctx.
118       SSL_use_PrivateKey_ASN1() and SSL_use_RSAPrivateKey_ASN1() add the
119       private key to ssl.
120
121       SSL_CTX_use_PrivateKey_file() adds the first private key found in file
122       to ctx. The formatting type of the private key must be specified from
123       the known types SSL_FILETYPE_PEM, SSL_FILETYPE_ASN1.
124       SSL_CTX_use_RSAPrivateKey_file() adds the first private RSA key found
125       in file to ctx. SSL_use_PrivateKey_file() adds the first private key
126       found in file to ssl; SSL_use_RSAPrivateKey_file() adds the first
127       private RSA key found to ssl.
128
129       SSL_CTX_check_private_key() checks the consistency of a private key
130       with the corresponding certificate loaded into ctx. If more than one
131       key/certificate pair (RSA/DSA) is installed, the last item installed
132       will be checked. If e.g. the last item was a RSA certificate or key,
133       the RSA key/certificate pair will be checked. SSL_check_private_key()
134       performs the same check for ssl. If no key/certificate was explicitly
135       added for this ssl, the last item added into ctx will be checked.
136

NOTES

138       The internal certificate store of OpenSSL can hold several private
139       key/certificate pairs at a time. The certificate used depends on the
140       cipher selected, see also SSL_CTX_set_cipher_list(3).
141
142       When reading certificates and private keys from file, files of type
143       SSL_FILETYPE_ASN1 (also known as DER, binary encoding) can only contain
144       one certificate or private key, consequently
145       SSL_CTX_use_certificate_chain_file() is only applicable to PEM
146       formatting.  Files of type SSL_FILETYPE_PEM can contain more than one
147       item.
148
149       SSL_CTX_use_certificate_chain_file() adds the first certificate found
150       in the file to the certificate store. The other certificates are added
151       to the store of chain certificates using SSL_CTX_add1_chain_cert(3).
152       Note: versions of OpenSSL before 1.0.2 only had a single certificate
153       chain store for all certificate types, OpenSSL 1.0.2 and later have a
154       separate chain store for each type.
155       SSL_CTX_use_certificate_chain_file() should be used instead of the
156       SSL_CTX_use_certificate_file() function in order to allow the use of
157       complete certificate chains even when no trusted CA storage is used or
158       when the CA issuing the certificate shall not be added to the trusted
159       CA storage.
160
161       If additional certificates are needed to complete the chain during the
162       TLS negotiation, CA certificates are additionally looked up in the
163       locations of trusted CA certificates, see
164       SSL_CTX_load_verify_locations(3).
165
166       The private keys loaded from file can be encrypted. In order to
167       successfully load encrypted keys, a function returning the passphrase
168       must have been supplied, see SSL_CTX_set_default_passwd_cb(3).
169       (Certificate files might be encrypted as well from the technical point
170       of view, it however does not make sense as the data in the certificate
171       is considered public anyway.)
172
173       All of the functions to set a new certificate will replace any existing
174       certificate of the same type that has already been set. Similarly all
175       of the functions to set a new private key will replace any private key
176       that has already been set. Applications should call
177       SSL_CTX_check_private_key(3) or SSL_check_private_key(3) as appropriate
178       after loading a new certificate and private key to confirm that the
179       certificate and key match.
180

RETURN VALUES

182       On success, the functions return 1.  Otherwise check out the error
183       stack to find out the reason.
184

SEE ALSO

186       ssl(7), SSL_new(3), SSL_clear(3), SSL_CTX_load_verify_locations(3),
187       SSL_CTX_set_default_passwd_cb(3), SSL_CTX_set_cipher_list(3),
188       SSL_CTX_set_client_CA_list(3), SSL_CTX_set_client_cert_cb(3),
189       SSL_CTX_add_extra_chain_cert(3)
190
192       Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
193
194       Licensed under the OpenSSL license (the "License").  You may not use
195       this file except in compliance with the License.  You can obtain a copy
196       in the file LICENSE in the source distribution or at
197       <https://www.openssl.org/source/license.html>.
198
199
200
2011.1.1i                            2021-07-22        SSL_CTX_USE_CERTIFICATE(3)
Impressum