2 * Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 /* see bearssl_ssl.h */
29 br_ssl_server_init_full_rsa(br_ssl_server_context
*cc
,
30 const br_x509_certificate
*chain
, size_t chain_len
,
31 const br_rsa_private_key
*sk
)
34 * The "full" profile supports all implemented cipher suites.
36 * Rationale for suite order, from most important to least
39 * -- Don't use 3DES if AES is available.
40 * -- Try to have Forward Secrecy (ECDHE suite) if possible.
41 * -- GCM is better than CBC.
42 * -- AES-128 is preferred over AES-256 (AES-128 is already
43 * strong enough, and AES-256 is 40% more expensive).
45 static const uint16_t suites
[] = {
46 BR_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
,
47 BR_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
,
48 BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
,
49 BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
,
50 BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
,
51 BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
,
52 BR_TLS_RSA_WITH_AES_128_GCM_SHA256
,
53 BR_TLS_RSA_WITH_AES_256_GCM_SHA384
,
54 BR_TLS_RSA_WITH_AES_128_CBC_SHA256
,
55 BR_TLS_RSA_WITH_AES_256_CBC_SHA256
,
56 BR_TLS_RSA_WITH_AES_128_CBC_SHA
,
57 BR_TLS_RSA_WITH_AES_256_CBC_SHA
,
58 BR_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
,
59 BR_TLS_RSA_WITH_3DES_EDE_CBC_SHA
63 * All hash functions are activated.
64 * Note: the X.509 validation engine will nonetheless refuse to
65 * validate signatures that use MD5 as hash function.
67 static const br_hash_class
*hashes
[] = {
79 * Reset server context and set supported versions from TLS-1.0
80 * to TLS-1.2 (inclusive).
82 br_ssl_server_zero(cc
);
83 br_ssl_engine_set_versions(&cc
->eng
, BR_TLS10
, BR_TLS12
);
86 * Set suites and elliptic curve implementation (for ECDHE).
88 br_ssl_engine_set_suites(&cc
->eng
, suites
,
89 (sizeof suites
) / (sizeof suites
[0]));
90 br_ssl_engine_set_ec(&cc
->eng
, &br_ec_prime_i31
);
93 * Set the "server policy": handler for the certificate chain
94 * and private key operations.
96 br_ssl_server_set_single_rsa(cc
, chain
, chain_len
, sk
,
97 BR_KEYTYPE_KEYX
| BR_KEYTYPE_SIGN
,
98 br_rsa_i31_private
, br_rsa_i31_pkcs1_sign
);
101 * Set supported hash functions.
103 for (id
= br_md5_ID
; id
<= br_sha512_ID
; id
++) {
104 const br_hash_class
*hc
;
107 br_ssl_engine_set_hash(&cc
->eng
, id
, hc
);
111 * Set the PRF implementations.
113 br_ssl_engine_set_prf10(&cc
->eng
, &br_tls10_prf
);
114 br_ssl_engine_set_prf_sha256(&cc
->eng
, &br_tls12_sha256_prf
);
115 br_ssl_engine_set_prf_sha384(&cc
->eng
, &br_tls12_sha384_prf
);
118 * Symmetric encryption. We use the "constant-time"
119 * implementations, which are the safest.
121 * On architectures detected as "64-bit", use the 64-bit
122 * versions (aes_ct64, ghash_ctmul64).
125 br_ssl_engine_set_aes_cbc(&cc
->eng
,
126 &br_aes_ct64_cbcenc_vtable
,
127 &br_aes_ct64_cbcdec_vtable
);
128 br_ssl_engine_set_aes_ctr(&cc
->eng
,
129 &br_aes_ct64_ctr_vtable
);
130 br_ssl_engine_set_ghash(&cc
->eng
,
133 br_ssl_engine_set_aes_cbc(&cc
->eng
,
134 &br_aes_ct_cbcenc_vtable
,
135 &br_aes_ct_cbcdec_vtable
);
136 br_ssl_engine_set_aes_ctr(&cc
->eng
,
137 &br_aes_ct_ctr_vtable
);
138 br_ssl_engine_set_ghash(&cc
->eng
,
141 br_ssl_engine_set_des_cbc(&cc
->eng
,
142 &br_des_ct_cbcenc_vtable
,
143 &br_des_ct_cbcdec_vtable
);
146 * Set the SSL record engines (CBC, GCM).
148 br_ssl_engine_set_cbc(&cc
->eng
,
149 &br_sslrec_in_cbc_vtable
,
150 &br_sslrec_out_cbc_vtable
);
151 br_ssl_engine_set_gcm(&cc
->eng
,
152 &br_sslrec_in_gcm_vtable
,
153 &br_sslrec_out_gcm_vtable
);