Skip to content

Commit 0412c2a

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

5 files changed

Lines changed: 57 additions & 71 deletions

File tree

lib/ssl/src/ssl.erl

Lines changed: 3 additions & 5 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
@@ -751,7 +749,7 @@ Common certificate related options to both client and server.
751749
connection will be selected.
752750

753751
The different signature algorithms are prioritized in the following
754-
order: `mldsa`, `slh-dsa`, `eddsa`, `ecdsa`, `rsa_pss_pss`, `rsa`, and `dsa`. If more
752+
order: `mldsa`, `slhdsa`, `eddsa`, `ecdsa`, `rsa_pss_pss`, `rsa`, and `dsa`. If more
755753
than one key is supplied for the same signature algorithm, they will
756754
be prioritized by strength (except for _engine keys_; see the next
757755
paragraph). This offers flexibility to, for instance, configure a
@@ -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: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,48 +1251,37 @@ ecc_curves(Version) when is_tuple(Version) ->
12511251
ecc_curves(TLSCurves);
12521252
ecc_curves(TLSCurves) ->
12531253
[pubkey_cert_records:namedCurves(Curve) || Curve <- TLSCurves].
1254-
1254+
12551255
groups() ->
12561256
TLSGroups = groups(all),
12571257
groups(TLSGroups).
12581258

12591259
-spec groups(all | default | TLSGroups :: list()) -> [ssl:group()].
12601260
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];
1261+
default_pqc_hybrid_groups() ++
1262+
[x25519,
1263+
x448,
1264+
secp521r1,
1265+
secp384r1,
1266+
secp256r1,
1267+
brainpoolP256r1tls13,
1268+
brainpoolP384r1tls13,
1269+
brainpoolP512r1tls13
1270+
] ++
1271+
other_pqc_hybrid_groups() ++
1272+
pqc_plain_groups() ++
1273+
dhe_grops();
12801274
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-
];
1275+
default_pqc_hybrid_groups() ++
1276+
[x25519,
1277+
x448,
1278+
secp521r1,
1279+
secp384r1,
1280+
secp256r1,
1281+
brainpoolP512r1tls13,
1282+
brainpoolP384r1tls13,
1283+
brainpoolP256r1tls13
1284+
];
12961285
groups(TLSGroups) when is_list(TLSGroups) ->
12971286
CryptoGroups = crypto_supported_groups(),
12981287
lists:filter(fun(x25519mlkem768) ->
@@ -1308,6 +1297,25 @@ groups(TLSGroups) when is_list(TLSGroups) ->
13081297
proplists:get_bool(maybe_group_to_curve(Group), CryptoGroups)
13091298
end, TLSGroups).
13101299

1300+
default_pqc_hybrid_groups() ->
1301+
[x25519mlkem768].
1302+
1303+
other_pqc_hybrid_groups()->
1304+
[secp384r1mlkem1024,
1305+
secp256r1mlkem768].
1306+
1307+
pqc_plain_groups() ->
1308+
[mlkem1024,
1309+
mlkem768,
1310+
mlkem512].
1311+
1312+
dhe_grops() ->
1313+
[ffdhe2048,
1314+
ffdhe3072,
1315+
ffdhe4096,
1316+
ffdhe6144,
1317+
ffdhe8192].
1318+
13111319
default_groups() ->
13121320
TLSGroups = groups(default),
13131321
groups(TLSGroups).

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)