Skip to content

Commit a090391

Browse files
committed
ssl: Make PQC groups most preferred
1 parent 8e99e81 commit a090391

5 files changed

Lines changed: 46 additions & 70 deletions

File tree

lib/ssl/src/ssl.erl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,7 @@ Options common to both client and server side.
693693
Used to limit the size of valid TLS handshake packets to avoid DoS
694694
attacks.
695695

696-
Integer (24 bits, unsigned). Defaults to `256*1024` before OTP-26 or if SLH-DSA algorithms
697-
are configured, otherwise the default is `256*1024`/2.
698-
696+
Integer (24 bits, unsigned). Defaults to `256*1024` since OTP-29.0
699697
- **`{hibernate_after, HibernateTimeout}`** - Hibernate inactive connection processes.
700698

701699
When an integer-value is specified, the TLS/DTLS connection goes into hibernation
@@ -1392,7 +1390,7 @@ The following options are specific to the client side, or have
13921390
different semantics for the client and server:
13931391

13941392
- **`{psk_groups, Groups}`** - key exchange groups that the client
1395-
will send pre share keys for, defaults to first group in
1393+
will send pre shared keys for, defaults to the first group in
13961394
supported_groups. Must be a subset of supported_groups and will
13971395
be sent in the same order as they appear in supported_groups.
13981396

lib/ssl/src/ssl_config.erl

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,10 +1469,10 @@ opt_supported_groups(UserOpts, #{versions := TlsVsns} = Opts, Env) ->
14691469

14701470
opt_psk_groups(undefined, _, _, _) ->
14711471
undefined;
1472-
opt_psk_groups(#supported_groups{supported_groups = SupportedGroups}, UserOpts, Opts, _Env) ->
1472+
opt_psk_groups(#supported_groups{supported_groups = [First| _] = SupportedGroups},
1473+
UserOpts, Opts, _Env) ->
14731474
%% Version dependency already asserted when SupportedGroups is supported
1474-
%% so is psk_groups
1475-
First = hd(SupportedGroups),
1475+
%% hence so is psk_groups
14761476
case get_opt_list(psk_groups, [First], UserOpts, Opts) of
14771477
{default, Default} ->
14781478
Default;
@@ -1495,30 +1495,11 @@ opt_crl(UserOpts, Opts, _Env) ->
14951495
opt_handshake(UserOpts, Opts, _Env) ->
14961496
{_, HS} = get_opt_of(handshake, [hello, full], full, UserOpts, Opts),
14971497

1498-
DefaultMaxHS = default_max_hs(Opts),
1499-
1500-
{_, MHSS} = get_opt_int(max_handshake_size, 1, ?MAX_UNIT24 , DefaultMaxHS,
1498+
{_, MHSS} = get_opt_int(max_handshake_size, 1, ?MAX_UNIT24 , ?DEFAULT_MAX_HANDSHAKE_SIZE,
15011499
UserOpts, Opts),
15021500

15031501
Opts#{handshake => HS, max_handshake_size => MHSS}.
15041502

1505-
default_max_hs(#{signature_algs:= undefined}) ->
1506-
?DEFAULT_MAX_HANDSHAKE_SIZE;
1507-
default_max_hs(#{signature_algs:= Algs}) ->
1508-
%%% In OTP-26 max handshake_size was lowered by half for most
1509-
%%% handshakes would fit that size and OpenSSL had a lower default
1510-
Set = sets:intersection(sets:from_list(Algs, [{version, 2}]),
1511-
sets:from_list(tls_v1:slh_dsa_schemes(),
1512-
[{version, 2}])),
1513-
case sets:is_empty(Set) of
1514-
true ->
1515-
?DEFAULT_MAX_HANDSHAKE_SIZE;
1516-
false ->
1517-
%% SLH_DSA creates fairly big handshake sizes so raise limit back
1518-
%% if these algorithms are supported,
1519-
?DEFAULT_MAX_HANDSHAKE_SIZE * 2
1520-
end.
1521-
15221503
opt_use_srtp(UserOpts, #{protocol := Protocol} = Opts, _Env) ->
15231504
UseSRTP = case get_opt_map(use_srtp, undefined, UserOpts, Opts) of
15241505
{old, UseSRTP0} ->

lib/ssl/src/ssl_handshake.hrl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,10 @@
8787
-define(FINISHED, 20).
8888
-define(MAX_UNIT24, 8388607).
8989

90-
%% Usually the biggest handshake message will be the message conveying the
91-
%% certificate chain. This size should be sufficient for usual certificate
92-
%% chains, certificates without special extensions have a typical size of
93-
%% 1-2kB. By dividing the old default value by 2 we still have a slightly
94-
%% bigger margin than OpenSSL
95-
-define(DEFAULT_MAX_HANDSHAKE_SIZE, ((256*1024) div 2)).
90+
%% As of OTP-29 when PQC-algorithm SLH-DSA is supported by default
91+
%% handshakes need to allowed to be bigger by default to handle
92+
%% normal SLH-DSA keys.
93+
-define(DEFAULT_MAX_HANDSHAKE_SIZE, 256*1024).
9694

9795
-record(random, {
9896
gmt_unix_time, % uint32

lib/ssl/src/tls_v1.erl

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
rsa_schemes/0,
6969
groups/0,
7070
groups/1,
71+
pqc_groups/0,
7172
group_to_enum/1,
7273
enum_to_group/1,
7374
default_groups/0,
@@ -1251,48 +1252,38 @@ ecc_curves(Version) when is_tuple(Version) ->
12511252
ecc_curves(TLSCurves);
12521253
ecc_curves(TLSCurves) ->
12531254
[pubkey_cert_records:namedCurves(Curve) || Curve <- TLSCurves].
1254-
1255+
12551256
groups() ->
12561257
TLSGroups = groups(all),
12571258
groups(TLSGroups).
12581259

12591260
-spec groups(all | default | TLSGroups :: list()) -> [ssl:group()].
12601261
groups(all) ->
1261-
[x25519,
1262-
x448,
1263-
secp521r1,
1264-
secp384r1,
1265-
secp256r1,
1266-
brainpoolP256r1tls13,
1267-
brainpoolP384r1tls13,
1268-
brainpoolP512r1tls13,
1269-
mlkem512,
1270-
mlkem768,
1271-
mlkem1024,
1272-
x25519mlkem768,
1273-
secp384r1mlkem1024,
1274-
secp256r1mlkem768,
1275-
ffdhe2048,
1276-
ffdhe3072,
1277-
ffdhe4096,
1278-
ffdhe6144,
1279-
ffdhe8192];
1262+
pqc_groups() ++
1263+
[x25519,
1264+
x448,
1265+
secp521r1,
1266+
secp384r1,
1267+
secp256r1,
1268+
brainpoolP256r1tls13,
1269+
brainpoolP384r1tls13,
1270+
brainpoolP512r1tls13,
1271+
ffdhe2048,
1272+
ffdhe3072,
1273+
ffdhe4096,
1274+
ffdhe6144,
1275+
ffdhe8192];
12801276
groups(default) ->
1281-
[x25519,
1282-
x448,
1283-
secp521r1,
1284-
secp384r1,
1285-
secp256r1,
1286-
brainpoolP512r1tls13,
1287-
brainpoolP384r1tls13,
1288-
brainpoolP256r1tls13,
1289-
mlkem512,
1290-
mlkem768,
1291-
mlkem1024,
1292-
x25519mlkem768,
1293-
secp384r1mlkem1024,
1294-
secp256r1mlkem768
1295-
];
1277+
pqc_groups() ++
1278+
[x25519,
1279+
x448,
1280+
secp521r1,
1281+
secp384r1,
1282+
secp256r1,
1283+
brainpoolP512r1tls13,
1284+
brainpoolP384r1tls13,
1285+
brainpoolP256r1tls13
1286+
];
12961287
groups(TLSGroups) when is_list(TLSGroups) ->
12971288
CryptoGroups = crypto_supported_groups(),
12981289
lists:filter(fun(x25519mlkem768) ->
@@ -1307,6 +1298,13 @@ groups(TLSGroups) when is_list(TLSGroups) ->
13071298
(Group) ->
13081299
proplists:get_bool(maybe_group_to_curve(Group), CryptoGroups)
13091300
end, TLSGroups).
1301+
pqc_groups() ->
1302+
[x25519mlkem768,
1303+
mlkem1024,
1304+
mlkem768,
1305+
mlkem512,
1306+
secp384r1mlkem1024,
1307+
secp256r1mlkem768].
13101308

13111309
default_groups() ->
13121310
TLSGroups = groups(default),

lib/ssl/test/ssl_api_SUITE.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,8 @@ customize_defaults(Opts, Role, Host) ->
22062206
end,
22072207
case proplists:get_value(protocol, Opts, tls) of
22082208
dtls ->
2209-
{ok, #config{ssl=DOpts}} = ssl_config:handle_options([{protocol, dtls}|NoVerify], Role, Host),
2209+
{ok, #config{ssl=DOpts}} =
2210+
ssl_config:handle_options([{protocol, dtls}|NoVerify], Role, Host),
22102211
{DOpts, DefOpts ++ Opts};
22112212
tls ->
22122213
{ok, #config{ssl=DOpts}} = ssl_config:handle_options(NoVerify, Role, Host),
@@ -2932,7 +2933,7 @@ options_fallback(_Config) ->
29322933
ok.
29332934

29342935
options_handshake(_Config) -> %% handshake
2935-
?OK(#{handshake := full, max_handshake_size := 131072},
2936+
?OK(#{handshake := full, max_handshake_size := 262144},
29362937
[], client),
29372938
?OK(#{handshake := hello, max_handshake_size := 123800},
29382939
[{handshake, hello}, {max_handshake_size, 123800}], client),

0 commit comments

Comments
 (0)