1SSL_CTX_use_certificate(3) OpenSSL SSL_CTX_use_certificate(3)
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_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
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
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
117 The internal certificate store of OpenSSL can hold two private
118 key/certificate pairs at a time: one key/certificate of type RSA and
119 one key/certificate of type DSA. The certificate used depends on the
120 cipher select, see also SSL_CTX_set_cipher_list(3).
121
122 When reading certificates and private keys from file, files of type
123 SSL_FILETYPE_ASN1 (also known as DER, binary encoding) can only contain
124 one certificate or private key, consequently
125 SSL_CTX_use_certificate_chain_file() is only applicable to PEM
126 formatting. Files of type SSL_FILETYPE_PEM can contain more than one
127 item.
128
129 SSL_CTX_use_certificate_chain_file() adds the first certificate found
130 in the file to the certificate store. The other certificates are added
131 to the store of chain certificates using
132 SSL_CTX_add_extra_chain_cert(3). There exists only one extra chain
133 store, so that the same chain is appended to both types of
134 certificates, RSA and DSA! If it is not intended to use both type of
135 certificate at the same time, it is recommended to use the
136 SSL_CTX_use_certificate_chain_file() instead of the
137 SSL_CTX_use_certificate_file() function in order to allow the use of
138 complete certificate chains even when no trusted CA storage is used or
139 when the CA issuing the certificate shall not be added to the trusted
140 CA storage.
141
142 If additional certificates are needed to complete the chain during the
143 TLS negotiation, CA certificates are additionally looked up in the
144 locations of trusted CA certificates, see
145 SSL_CTX_load_verify_locations(3).
146
147 The private keys loaded from file can be encrypted. In order to
148 successfully load encrypted keys, a function returning the passphrase
149 must have been supplied, see SSL_CTX_set_default_passwd_cb(3).
150 (Certificate files might be encrypted as well from the technical point
151 of view, it however does not make sense as the data in the certificate
152 is considered public anyway.)
153
155 On success, the functions return 1. Otherwise check out the error
156 stack to find out the reason.
157
159 ssl(3), SSL_new(3), SSL_clear(3), SSL_CTX_load_verify_locations(3),
160 SSL_CTX_set_default_passwd_cb(3), SSL_CTX_set_cipher_list(3),
161 SSL_CTX_set_client_cert_cb(3), SSL_CTX_add_extra_chain_cert(3)
162
164 Support for DER encoded private keys (SSL_FILETYPE_ASN1) in
165 SSL_CTX_use_PrivateKey_file() and SSL_use_PrivateKey_file() was added
166 in 0.9.8 .
167
168
169
1701.0.0e 2005-04-08 SSL_CTX_use_certificate(3)