Skip to content

Commit 618e7c6

Browse files
committed
Make all supported siphersuites available for a TLS session
1 parent 1da146b commit 618e7c6

File tree

5 files changed

+42
-77
lines changed

5 files changed

+42
-77
lines changed

tls/ciphersuites.c

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* TLS ciphersuites.
55
*
66
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
7-
* Copyright (C) 2015-2018 Tempesta Technologies, Inc.
7+
* Copyright (C) 2015-2019 Tempesta Technologies, Inc.
88
* SPDX-License-Identifier: GPL-2.0
99
*
1010
* This program is free software; you can redistribute it and/or modify
@@ -24,58 +24,6 @@
2424
#include "ciphersuites.h"
2525
#include "ttls.h"
2626

27-
/*
28-
* Ordered from most preferred to least preferred in terms of security.
29-
*
30-
* Current rule:
31-
* 1. By key exchange: Forward-secure non-PSK > other non-PSK
32-
* 2. By key length and cipher: AES-256 > AES-128
33-
* 3. By cipher mode when relevant GCM > CCM > CCM_8
34-
* 4. By hash function used when relevant
35-
* 5. By key exchange/auth again: EC > non-EC
36-
*
37-
* Note that there is no TLS_RSA_WITH_AES_128_CBC_SHA required by RFC 5246.
38-
* Current TLS version is 1.3, so we support TLS 1.2 for legacy only clients.
39-
* Next, CBC mode has security issues (so it was removed from TLS 1.3) and
40-
* incurs significant pipeline stalls that hamper its efficiency and
41-
* performance. Last, it requires additional code work flow.
42-
*/
43-
static const int ciphersuite_preference[] = {
44-
/* All AES-256 ephemeral suites */
45-
TTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
46-
TTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
47-
TTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
48-
TTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM,
49-
TTLS_TLS_DHE_RSA_WITH_AES_256_CCM,
50-
TTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8,
51-
TTLS_TLS_DHE_RSA_WITH_AES_256_CCM_8,
52-
53-
/* All AES-128 ephemeral suites */
54-
TTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
55-
TTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
56-
TTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
57-
TTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM,
58-
TTLS_TLS_DHE_RSA_WITH_AES_128_CCM,
59-
TTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8,
60-
TTLS_TLS_DHE_RSA_WITH_AES_128_CCM_8,
61-
62-
/* All AES-256 suites */
63-
TTLS_TLS_RSA_WITH_AES_256_GCM_SHA384,
64-
TTLS_TLS_RSA_WITH_AES_256_CCM,
65-
TTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384,
66-
TTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384,
67-
TTLS_TLS_RSA_WITH_AES_256_CCM_8,
68-
69-
/* All AES-128 suites */
70-
TTLS_TLS_RSA_WITH_AES_128_GCM_SHA256,
71-
TTLS_TLS_RSA_WITH_AES_128_CCM,
72-
TTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256,
73-
TTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256,
74-
TTLS_TLS_RSA_WITH_AES_128_CCM_8,
75-
76-
0
77-
};
78-
7927
static const TlsCiphersuite ciphersuite_definitions[] =
8028
{
8129
{ TTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
@@ -279,7 +227,7 @@ ttls_get_ciphersuite_name(const int ciphersuite_id)
279227
const TlsCiphersuite *cur;
280228

281229
if (!(cur = ttls_ciphersuite_from_id(ciphersuite_id)))
282-
return("unknown");
230+
return "unknown";
283231

284232
return cur->name;
285233
}

tls/error.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ void ttls_strerror(int ret, char *buf, size_t buflen)
181181
snprintf(buf, buflen, "TLS - An invalid TLS record was received");
182182
if (use_ret == -(TTLS_ERR_CONN_EOF))
183183
snprintf(buf, buflen, "TLS - The connection indicated an EOF");
184-
if (use_ret == -(TTLS_ERR_NO_CIPHER_CHOSEN))
185-
snprintf(buf, buflen, "TLS - The server has no ciphersuites in common with the client");
186184
if (use_ret == -(TTLS_ERR_NO_CLIENT_CERTIFICATE))
187185
snprintf(buf, buflen, "TLS - No client certification received from the client, but required by the authentication mode");
188186
if (use_ret == -(TTLS_ERR_CERTIFICATE_TOO_LARGE))
@@ -233,8 +231,6 @@ void ttls_strerror(int ret, char *buf, size_t buflen)
233231
snprintf(buf, buflen, "TLS - Internal error (eg, unexpected failure in lower-level module)");
234232
if (use_ret == -(TTLS_ERR_BUFFER_TOO_SMALL))
235233
snprintf(buf, buflen, "TLS - A buffer is too small to receive or write a message");
236-
if (use_ret == -(TTLS_ERR_NO_USABLE_CIPHERSUITE))
237-
snprintf(buf, buflen, "TLS - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)");
238234
if (use_ret == -(TTLS_ERR_INVALID_VERIFY_HASH))
239235
snprintf(buf, buflen, "TLS - Couldn't set the hash for verifying CertificateVerify");
240236

tls/tls_srv.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,15 +550,16 @@ ttls_choose_ciphersuite(TlsCtx *tls, const unsigned char *csp)
550550
}
551551

552552
if (got_common_suite) {
553-
T_DBG("got ciphersuites in common, but none of them usable\n");
553+
T_WARN("None of the common ciphersuites is usable"
554+
" (e.g. no suitable certificate)\n");
554555
ttls_send_alert(tls, TTLS_ALERT_LEVEL_FATAL,
555556
TTLS_ALERT_MSG_HANDSHAKE_FAILURE);
556-
return TTLS_ERR_NO_USABLE_CIPHERSUITE;
557+
return -EINVAL;
557558
} else {
558-
T_DBG("got no ciphersuites in common\n");
559+
T_WARN("Got no ciphersuites in common\n");
559560
ttls_send_alert(tls, TTLS_ALERT_LEVEL_FATAL,
560561
TTLS_ALERT_MSG_HANDSHAKE_FAILURE);
561-
return TTLS_ERR_NO_CIPHER_CHOSEN;
562+
return -EINVAL;
562563
}
563564

564565
have_ciphersuite:
@@ -1388,8 +1389,8 @@ ttls_write_server_key_exchange(TlsCtx *tls, struct sg_table *sgt,
13881389
goto curve_matching_done;
13891390
curve_matching_done:
13901391
if (!curve || !*curve) {
1391-
T_DBG("no matching curve for ECDHE key exchange\n");
1392-
r = TTLS_ERR_NO_CIPHER_CHOSEN;
1392+
T_WARN("No matching curve for ECDHE key exchange\n");
1393+
r = -EINVAL;
13931394
goto err;
13941395
}
13951396
T_DBG("ECDHE curve: %s\n", (*curve)->name);

tls/ttls.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,9 +2407,39 @@ ttls_config_init(ttls_config *conf)
24072407
}
24082408
EXPORT_SYMBOL(ttls_config_init);
24092409

2410-
static int ssl_preset_suiteb_ciphersuites[] = {
2410+
static int ttls_default_ciphersuites[] = {
2411+
/* All AES-128 ephemeral suites */
24112412
TTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
2413+
TTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2414+
TTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
2415+
TTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM,
2416+
TTLS_TLS_DHE_RSA_WITH_AES_128_CCM,
2417+
TTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8,
2418+
TTLS_TLS_DHE_RSA_WITH_AES_128_CCM_8,
2419+
2420+
/* All AES-256 ephemeral suites */
24122421
TTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
2422+
TTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
2423+
TTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
2424+
TTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM,
2425+
TTLS_TLS_DHE_RSA_WITH_AES_256_CCM,
2426+
TTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8,
2427+
TTLS_TLS_DHE_RSA_WITH_AES_256_CCM_8,
2428+
2429+
/* All AES-256 suites */
2430+
TTLS_TLS_RSA_WITH_AES_256_GCM_SHA384,
2431+
TTLS_TLS_RSA_WITH_AES_256_CCM,
2432+
TTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384,
2433+
TTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384,
2434+
TTLS_TLS_RSA_WITH_AES_256_CCM_8,
2435+
2436+
/* All AES-128 suites */
2437+
TTLS_TLS_RSA_WITH_AES_128_GCM_SHA256,
2438+
TTLS_TLS_RSA_WITH_AES_128_CCM,
2439+
TTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256,
2440+
TTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256,
2441+
TTLS_TLS_RSA_WITH_AES_128_CCM_8,
2442+
24132443
0
24142444
};
24152445

@@ -2462,11 +2492,8 @@ ttls_config_defaults(ttls_config *conf, int endpoint)
24622492
conf->min_minor_ver = TTLS_MINOR_VERSION_3; /* TLS 1.2 */
24632493
conf->max_minor_ver = TTLS_MAX_MINOR_VERSION;
24642494

2465-
conf->ciphersuite_list[TTLS_MINOR_VERSION_0]
2466-
= conf->ciphersuite_list[TTLS_MINOR_VERSION_1]
2467-
= conf->ciphersuite_list[TTLS_MINOR_VERSION_2]
2468-
= conf->ciphersuite_list[TTLS_MINOR_VERSION_3]
2469-
= ssl_preset_suiteb_ciphersuites;
2495+
ttls_conf_ciphersuites_for_version(conf, ttls_default_ciphersuites,
2496+
TTLS_MINOR_VERSION_3);
24702497

24712498
conf->cert_profile = &ttls_x509_crt_profile_suiteb;
24722499
conf->sig_hashes = ssl_preset_suiteb_hashes;

tls/ttls.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151
#define TTLS_ERR_INVALID_RECORD -0x7200
5252
/* The connection indicated an EOF. */
5353
#define TTLS_ERR_CONN_EOF -0x7280
54-
/* The server has no ciphersuites in common with the client. */
55-
#define TTLS_ERR_NO_CIPHER_CHOSEN -0x7380
5654
/*
5755
* No client certification received from the client, but required by the
5856
* authentication mode.
@@ -110,11 +108,6 @@
110108
#define TTLS_ERR_INTERNAL_ERROR -0x6C00
111109
/* A buffer is too small to receive or write a message. */
112110
#define TTLS_ERR_BUFFER_TOO_SMALL -0x6A00
113-
/*
114-
* None of the common ciphersuites is usable (eg, no suitable certificate,
115-
* see debug messages).
116-
*/
117-
#define TTLS_ERR_NO_USABLE_CIPHERSUITE -0x6980
118111
/* Couldn't set the hash for verifying CertificateVerify. */
119112
#define TTLS_ERR_INVALID_VERIFY_HASH -0x6600
120113

0 commit comments

Comments
 (0)