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_CTX_use_PrivateKey,
10       SSL_CTX_use_PrivateKey_ASN1, SSL_CTX_use_PrivateKey_file,
11       SSL_CTX_use_RSAPrivateKey, SSL_CTX_use_RSAPrivateKey_ASN1,
12       SSL_CTX_use_RSAPrivateKey_file, SSL_use_PrivateKey_file,
13       SSL_use_PrivateKey_ASN1, SSL_use_PrivateKey, SSL_use_RSAPrivateKey,
14       SSL_use_RSAPrivateKey_ASN1, SSL_use_RSAPrivateKey_file,
15       SSL_CTX_check_private_key, SSL_check_private_key - load certificate and
16       key data
17

SYNOPSIS

19        #include <openssl/ssl.h>
20
21        int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
22        int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d);
23        int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
24        int SSL_use_certificate(SSL *ssl, X509 *x);
25        int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len);
26        int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
27
28        int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file);
29
30        int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
31        int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx, unsigned char *d,
32                                        long len);
33        int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
34        int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
35        int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len);
36        int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
37        int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
38        int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len);
39        int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
40        int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
41        int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len);
42        int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
43
44        int SSL_CTX_check_private_key(const SSL_CTX *ctx);
45        int SSL_check_private_key(const SSL *ssl);
46

DESCRIPTION

48       These functions load the certificates and private keys into the SSL_CTX
49       or SSL object, respectively.
50
51       The SSL_CTX_* class of functions loads the certificates and keys into
52       the SSL_CTX object ctx. The information is passed to SSL objects ssl
53       created from ctx with SSL_new(3) by copying, so that changes applied to
54       ctx do not propagate to already existing SSL objects.
55
56       The SSL_* class of functions only loads certificates and keys into a
57       specific SSL object. The specific information is kept, when
58       SSL_clear(3) is called for this SSL object.
59
60       SSL_CTX_use_certificate() loads the certificate x into ctx,
61       SSL_use_certificate() loads x into ssl. The rest of the certificates
62       needed to form the complete certificate chain can be specified using
63       the SSL_CTX_add_extra_chain_cert(3) function.
64
65       SSL_CTX_use_certificate_ASN1() loads the ASN1 encoded certificate from
66       the memory location d (with length len) into ctx,
67       SSL_use_certificate_ASN1() loads the ASN1 encoded certificate into ssl.
68
69       SSL_CTX_use_certificate_file() loads the first certificate stored in
70       file into ctx. The formatting type of the certificate must be specified
71       from the known types SSL_FILETYPE_PEM, SSL_FILETYPE_ASN1.
72       SSL_use_certificate_file() loads the certificate from file into ssl.
73       See the NOTES section on why SSL_CTX_use_certificate_chain_file()
74       should be preferred.
75
76       SSL_CTX_use_certificate_chain_file() loads a certificate chain from
77       file into ctx. The certificates must be in PEM format and must be
78       sorted starting with the subject's certificate (actual client or server
79       certificate), followed by intermediate CA certificates if applicable,
80       and ending at the highest level (root) CA.  There is no corresponding
81       function working on a single SSL object.
82
83       SSL_CTX_use_PrivateKey() adds pkey as private key to ctx.
84       SSL_CTX_use_RSAPrivateKey() adds the private key rsa of type RSA to
85       ctx. SSL_use_PrivateKey() adds pkey as private key to ssl;
86       SSL_use_RSAPrivateKey() adds rsa as private key of type RSA to ssl.  If
87       a certificate has already been set and the private does not belong to
88       the certificate an error is returned. To change a certificate, private
89       key pair the new certificate needs to be set with SSL_use_certificate()
90       or SSL_CTX_use_certificate() before setting the private key with
91       SSL_CTX_use_PrivateKey() or SSL_use_PrivateKey().
92
93       SSL_CTX_use_PrivateKey_ASN1() adds the private key of type pk stored at
94       memory location d (length len) to ctx.
95       SSL_CTX_use_RSAPrivateKey_ASN1() adds the private key of type RSA
96       stored at memory location d (length len) to ctx.
97       SSL_use_PrivateKey_ASN1() and SSL_use_RSAPrivateKey_ASN1() add the
98       private key to ssl.
99
100       SSL_CTX_use_PrivateKey_file() adds the first private key found in file
101       to ctx. The formatting type of the certificate must be specified from
102       the known types SSL_FILETYPE_PEM, SSL_FILETYPE_ASN1.
103       SSL_CTX_use_RSAPrivateKey_file() adds the first private RSA key found
104       in file to ctx. SSL_use_PrivateKey_file() adds the first private key
105       found in file to ssl; SSL_use_RSAPrivateKey_file() adds the first
106       private RSA key found to ssl.
107
108       SSL_CTX_check_private_key() checks the consistency of a private key
109       with the corresponding certificate loaded into ctx. If more than one
110       key/certificate pair (RSA/DSA) is installed, the last item installed
111       will be checked. If e.g. the last item was a RSA certificate or key,
112       the RSA key/certificate pair will be checked. SSL_check_private_key()
113       performs the same check for ssl. If no key/certificate was explicitly
114       added for this ssl, the last item added into ctx will be checked.
115

NOTES

117       The internal certificate store of OpenSSL can hold several private
118       key/certificate pairs at a time. The certificate used depends on the
119       cipher selected, see also SSL_CTX_set_cipher_list(3).
120
121       When reading certificates and private keys from file, files of type
122       SSL_FILETYPE_ASN1 (also known as DER, binary encoding) can only contain
123       one certificate or private key, consequently
124       SSL_CTX_use_certificate_chain_file() is only applicable to PEM
125       formatting.  Files of type SSL_FILETYPE_PEM can contain more than one
126       item.
127
128       SSL_CTX_use_certificate_chain_file() adds the first certificate found
129       in the file to the certificate store. The other certificates are added
130       to the store of chain certificates using SSL_CTX_add1_chain_cert(3).
131       Note: versions of OpenSSL before 1.0.2 only had a single certificate
132       chain store for all certificate types, OpenSSL 1.0.2 and later have a
133       separate chain store for each type.
134       SSL_CTX_use_certificate_chain_file() should be used instead of the
135       SSL_CTX_use_certificate_file() function in order to allow the use of
136       complete certificate chains even when no trusted CA storage is used or
137       when the CA issuing the certificate shall not be added to the trusted
138       CA storage.
139
140       If additional certificates are needed to complete the chain during the
141       TLS negotiation, CA certificates are additionally looked up in the
142       locations of trusted CA certificates, see
143       SSL_CTX_load_verify_locations(3).
144
145       The private keys loaded from file can be encrypted. In order to
146       successfully load encrypted keys, a function returning the passphrase
147       must have been supplied, see SSL_CTX_set_default_passwd_cb(3).
148       (Certificate files might be encrypted as well from the technical point
149       of view, it however does not make sense as the data in the certificate
150       is considered public anyway.)
151

RETURN VALUES

153       On success, the functions return 1.  Otherwise check out the error
154       stack to find out the reason.
155

SEE ALSO

157       ssl(3), SSL_new(3), SSL_clear(3), SSL_CTX_load_verify_locations(3),
158       SSL_CTX_set_default_passwd_cb(3), SSL_CTX_set_cipher_list(3),
159       SSL_CTX_set_client_cert_cb(3), SSL_CTX_add_extra_chain_cert(3)
160

HISTORY

162       Support for DER encoded private keys (SSL_FILETYPE_ASN1) in
163       SSL_CTX_use_PrivateKey_file() and SSL_use_PrivateKey_file() was added
164       in 0.9.8 .
165
166
167
1681.0.2o                            2019-09-10        SSL_CTX_use_certificate(3)
Impressum