1SSL_CTX_use_certificate(3) OpenSSL SSL_CTX_use_certificate(3)
2
3
4
6 SSL_CTX_use_certificate, SSL_CTX_use_certificate_ASN1, SSL_CTX_use_cer‐
7 tificate_file, SSL_use_certificate, SSL_use_certificate_ASN1,
8 SSL_use_certificate_file, SSL_CTX_use_certificate_chain_file,
9 SSL_CTX_use_PrivateKey, SSL_CTX_use_PrivateKey_ASN1, SSL_CTX_use_Pri‐
10 vateKey_file, SSL_CTX_use_RSAPrivateKey, SSL_CTX_use_RSAPri‐
11 vateKey_ASN1, SSL_CTX_use_RSAPrivateKey_file, SSL_use_PrivateKey_file,
12 SSL_use_PrivateKey_ASN1, SSL_use_PrivateKey, SSL_use_RSAPrivateKey,
13 SSL_use_RSAPrivateKey_ASN1, SSL_use_RSAPrivateKey_file,
14 SSL_CTX_check_private_key, SSL_check_private_key - load certificate and
15 key data
16
18 #include <openssl/ssl.h>
19
20 int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
21 int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d);
22 int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
23 int SSL_use_certificate(SSL *ssl, X509 *x);
24 int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len);
25 int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
26
27 int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file);
28
29 int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
30 int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx, unsigned char *d,
31 long len);
32 int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
33 int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
34 int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len);
35 int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
36 int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
37 int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len);
38 int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
39 int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
40 int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len);
41 int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
42
43 int SSL_CTX_check_private_key(const SSL_CTX *ctx);
44 int SSL_check_private_key(const SSL *ssl);
45
47 These functions load the certificates and private keys into the SSL_CTX
48 or SSL object, respectively.
49
50 The SSL_CTX_* class of functions loads the certificates and keys into
51 the SSL_CTX object ctx. The information is passed to SSL objects ssl
52 created from ctx with SSL_new(3) by copying, so that changes applied to
53 ctx do not propagate to already existing SSL objects.
54
55 The SSL_* class of functions only loads certificates and keys into a
56 specific SSL object. The specific information is kept, when
57 SSL_clear(3) is called for this SSL object.
58
59 SSL_CTX_use_certificate() loads the certificate x into ctx,
60 SSL_use_certificate() loads x into ssl. The rest of the certificates
61 needed to form the complete certificate chain can be specified using
62 the SSL_CTX_add_extra_chain_cert(3) function.
63
64 SSL_CTX_use_certificate_ASN1() loads the ASN1 encoded certificate from
65 the memory location d (with length len) into ctx, SSL_use_certifi‐
66 cate_ASN1() loads the ASN1 encoded certificate into ssl.
67
68 SSL_CTX_use_certificate_file() loads the first certificate stored in
69 file into ctx. The formatting type of the certificate must be specified
70 from the known types SSL_FILETYPE_PEM, SSL_FILETYPE_ASN1. SSL_use_cer‐
71 tificate_file() loads the certificate from file into ssl. See the
72 NOTES section on why SSL_CTX_use_certificate_chain_file() should be
73 preferred.
74
75 SSL_CTX_use_certificate_chain_file() loads a certificate chain from
76 file into ctx. The certificates must be in PEM format and must be
77 sorted starting with the subject's certificate (actual client or server
78 certificate), followed by intermediate CA certificates if applicable,
79 and ending at the highest level (root) CA. There is no corresponding
80 function working on a single SSL object.
81
82 SSL_CTX_use_PrivateKey() adds pkey as private key to ctx.
83 SSL_CTX_use_RSAPrivateKey() adds the private key rsa of type RSA to
84 ctx. SSL_use_PrivateKey() adds pkey as private key to ssl;
85 SSL_use_RSAPrivateKey() adds rsa as private key of type RSA to ssl. If
86 a certificate has already been set and the private does not belong to
87 the certificate an error is returned. To change a certificate, private
88 key pair the new certificate needs to be set with SSL_use_certificate()
89 or SSL_CTX_use_certificate() before setting the private key with
90 SSL_CTX_use_PrivateKey() or SSL_use_PrivateKey().
91
92 SSL_CTX_use_PrivateKey_ASN1() adds the private key of type pk stored at
93 memory location d (length len) to ctx. SSL_CTX_use_RSAPri‐
94 vateKey_ASN1() adds the private key of type RSA stored at memory loca‐
95 tion d (length len) to ctx. SSL_use_PrivateKey_ASN1() and
96 SSL_use_RSAPrivateKey_ASN1() add the private key to ssl.
97
98 SSL_CTX_use_PrivateKey_file() adds the first private key found in file
99 to ctx. The formatting type of the certificate must be specified from
100 the known types SSL_FILETYPE_PEM, SSL_FILETYPE_ASN1.
101 SSL_CTX_use_RSAPrivateKey_file() adds the first private RSA key found
102 in file to ctx. SSL_use_PrivateKey_file() adds the first private key
103 found in file to ssl; SSL_use_RSAPrivateKey_file() adds the first pri‐
104 vate RSA key found to ssl.
105
106 SSL_CTX_check_private_key() checks the consistency of a private key
107 with the corresponding certificate loaded into ctx. If more than one
108 key/certificate pair (RSA/DSA) is installed, the last item installed
109 will be checked. If e.g. the last item was a RSA certificate or key,
110 the RSA key/certificate pair will be checked. SSL_check_private_key()
111 performs the same check for ssl. If no key/certificate was explicitly
112 added for this ssl, the last item added into ctx will be checked.
113
115 The internal certificate store of OpenSSL can hold two private key/cer‐
116 tificate pairs at a time: one key/certificate of type RSA and one
117 key/certificate of type DSA. The certificate used depends on the cipher
118 select, see also SSL_CTX_set_cipher_list(3).
119
120 When reading certificates and private keys from file, files of type
121 SSL_FILETYPE_ASN1 (also known as DER, binary encoding) can only contain
122 one certificate or private key, consequently SSL_CTX_use_certifi‐
123 cate_chain_file() is only applicable to PEM formatting. Files of type
124 SSL_FILETYPE_PEM can contain more than one item.
125
126 SSL_CTX_use_certificate_chain_file() adds the first certificate found
127 in the file to the certificate store. The other certificates are added
128 to the store of chain certificates using
129 SSL_CTX_add_extra_chain_cert(3). There exists only one extra chain
130 store, so that the same chain is appended to both types of certifi‐
131 cates, RSA and DSA! If it is not intended to use both type of certifi‐
132 cate at the same time, it is recommended to use the SSL_CTX_use_cer‐
133 tificate_chain_file() instead of the SSL_CTX_use_certificate_file()
134 function in order to allow the use of complete certificate chains even
135 when no trusted CA storage is used or when the CA issuing the certifi‐
136 cate shall not be added to the trusted CA storage.
137
138 If additional certificates are needed to complete the chain during the
139 TLS negotiation, CA certificates are additionally looked up in the
140 locations of trusted CA certificates, see SSL_CTX_load_verify_loca‐
141 tions(3).
142
143 The private keys loaded from file can be encrypted. In order to suc‐
144 cessfully load encrypted keys, a function returning the passphrase must
145 have been supplied, see SSL_CTX_set_default_passwd_cb(3). (Certificate
146 files might be encrypted as well from the technical point of view, it
147 however does not make sense as the data in the certificate is consid‐
148 ered public anyway.)
149
151 On success, the functions return 1. Otherwise check out the error
152 stack to find out the reason.
153
155 ssl(3), SSL_new(3), SSL_clear(3), SSL_CTX_load_verify_locations(3),
156 SSL_CTX_set_default_passwd_cb(3), SSL_CTX_set_cipher_list(3),
157 SSL_CTX_set_client_cert_cb(3), SSL_CTX_add_extra_chain_cert(3)
158
160 Support for DER encoded private keys (SSL_FILETYPE_ASN1) in
161 SSL_CTX_use_PrivateKey_file() and SSL_use_PrivateKey_file() was added
162 in 0.9.8 .
163
164
165
1660.9.8b 2005-04-08 SSL_CTX_use_certificate(3)