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_ec(br_ssl_server_context
*cc
,
30 const br_x509_certificate
*chain
, size_t chain_len
,
31 unsigned cert_issuer_key_type
, const br_ec_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 * -- ChaCha20+Poly1305 is better than AES/GCM (faster, smaller).
42 * -- GCM is better than CBC.
43 * -- AES-128 is preferred over AES-256 (AES-128 is already
44 * strong enough, and AES-256 is 40% more expensive).
46 * Note that for ECDH suites, the list will be automatically
47 * filtered based on the issuing CA key type.
49 static const uint16_t suites
[] = {
50 BR_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
,
51 BR_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
,
52 BR_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
,
53 BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
,
54 BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
,
55 BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
,
56 BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
,
57 BR_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
,
58 BR_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
,
59 BR_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
,
60 BR_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
,
61 BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
,
62 BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
,
63 BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
,
64 BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
,
65 BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
,
66 BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
,
67 BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
,
68 BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
,
69 BR_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
,
70 BR_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
,
71 BR_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
75 * All hash functions are activated.
76 * Note: the X.509 validation engine will nonetheless refuse to
77 * validate signatures that use MD5 as hash function.
79 static const br_hash_class
*hashes
[] = {
91 * Reset server context and set supported versions from TLS-1.0
92 * to TLS-1.2 (inclusive).
94 br_ssl_server_zero(cc
);
95 br_ssl_engine_set_versions(&cc
->eng
, BR_TLS10
, BR_TLS12
);
98 * Set suites and elliptic curve implementation (for ECDHE).
100 br_ssl_engine_set_suites(&cc
->eng
, suites
,
101 (sizeof suites
) / (sizeof suites
[0]));
102 br_ssl_engine_set_default_ec(&cc
->eng
);
105 * Set the "server policy": handler for the certificate chain
106 * and private key operations.
108 br_ssl_server_set_single_ec(cc
, chain
, chain_len
, sk
,
109 BR_KEYTYPE_KEYX
| BR_KEYTYPE_SIGN
,
110 cert_issuer_key_type
,
111 br_ssl_engine_get_ec(&cc
->eng
),
113 br_ecdsa_i15_sign_asn1
115 br_ecdsa_i31_sign_asn1
120 * Set supported hash functions.
122 for (id
= br_md5_ID
; id
<= br_sha512_ID
; id
++) {
123 const br_hash_class
*hc
;
126 br_ssl_engine_set_hash(&cc
->eng
, id
, hc
);
130 * Set the PRF implementations.
132 br_ssl_engine_set_prf10(&cc
->eng
, &br_tls10_prf
);
133 br_ssl_engine_set_prf_sha256(&cc
->eng
, &br_tls12_sha256_prf
);
134 br_ssl_engine_set_prf_sha384(&cc
->eng
, &br_tls12_sha384_prf
);
137 * Symmetric encryption.
139 br_ssl_engine_set_default_aes_cbc(&cc
->eng
);
140 br_ssl_engine_set_default_aes_gcm(&cc
->eng
);
141 br_ssl_engine_set_default_des_cbc(&cc
->eng
);
142 br_ssl_engine_set_default_chapol(&cc
->eng
);