Skip to content

Commit 3f36c31

Browse files
committed
ssl: Make PQC groups most preferred
1 parent 4991a2a commit 3f36c31

5 files changed

Lines changed: 61 additions & 74 deletions

File tree

lib/ssl/src/ssl.erl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +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.
696+
Integer (24 bits, unsigned). Defaults to `262144` since OTP 29.0
698697

699698
- **`{hibernate_after, HibernateTimeout}`** - Hibernate inactive connection processes.
700699

@@ -751,7 +750,7 @@ Common certificate related options to both client and server.
751750
connection will be selected.
752751

753752
The different signature algorithms are prioritized in the following
754-
order: `mldsa`, `slh-dsa`, `eddsa`, `ecdsa`, `rsa_pss_pss`, `rsa`, and `dsa`. If more
753+
order: `mldsa`, `slhdsa`, `eddsa`, `ecdsa`, `rsa_pss_pss`, `rsa`, and `dsa`. If more
755754
than one key is supplied for the same signature algorithm, they will
756755
be prioritized by strength (except for _engine keys_; see the next
757756
paragraph). This offers flexibility to, for instance, configure a
@@ -1392,7 +1391,7 @@ The following options are specific to the client side, or have
13921391
different semantics for the client and server:
13931392

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

@@ -1445,7 +1444,7 @@ different semantics for the client and server.
14451444
> #### Change {: .info }
14461445
>
14471446
> The default for `Verify` was changed to `verify_peer` in
1448-
> Erlang/OTP 26.
1447+
> Erlang/OTP 26.0.
14491448
14501449
- **`{cacerts, CACerts}`** - Trusted certificates
14511450

@@ -1864,7 +1863,7 @@ Certificate related options for a server.
18641863
`true`, the server fails if the client does not have a certificate to send, that
18651864
is, sends an empty certificate. If set to `false`, it fails only if the client
18661865
sends an invalid certificate (an empty certificate is considered valid).
1867-
Defaults to `true`, the default value was changed in OTP-26.0.
1866+
Defaults to `true`, the default value was changed in OTP 26.0.
18681867
18691868
- **`{certificate_authorities, ServerCertAuth}`** - Inter-operate hint option
18701869
@@ -3180,7 +3179,7 @@ eccs(Other) ->
31803179
-doc """
31813180
Returns all supported groups in TLS 1.3.
31823181
3183-
Existed since OTP 22.0; documented as of OTP 27.
3182+
Existed since OTP 22.0; documented as of OTP 27.0.
31843183
""".
31853184
-spec groups() -> [group()].
31863185
%%--------------------------------------------------------------------
@@ -3195,7 +3194,7 @@ groups() ->
31953194
-doc """
31963195
Returns default supported groups in TLS 1.3.
31973196
3198-
Existed since OTP 22.0; documented as of OTP 27.
3197+
Existed since OTP 22.0; documented as of OTP 27.0.
31993198
""".
32003199
32013200
%%--------------------------------------------------------------------

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
@@ -1248,48 +1248,37 @@ ecc_curves(Version) when is_tuple(Version) ->
12481248
ecc_curves(TLSCurves);
12491249
ecc_curves(TLSCurves) ->
12501250
[pubkey_cert_records:namedCurves(Curve) || Curve <- TLSCurves].
1251-
1251+
12521252
groups() ->
12531253
TLSGroups = groups(all),
12541254
groups(TLSGroups).
12551255

12561256
-spec groups(all | default | TLSGroups :: list()) -> [ssl:group()].
12571257
groups(all) ->
1258-
[x25519,
1259-
x448,
1260-
secp521r1,
1261-
secp384r1,
1262-
secp256r1,
1263-
brainpoolP256r1tls13,
1264-
brainpoolP384r1tls13,
1265-
brainpoolP512r1tls13,
1266-
mlkem512,
1267-
mlkem768,
1268-
mlkem1024,
1269-
x25519mlkem768,
1270-
secp384r1mlkem1024,
1271-
secp256r1mlkem768,
1272-
ffdhe2048,
1273-
ffdhe3072,
1274-
ffdhe4096,
1275-
ffdhe6144,
1276-
ffdhe8192];
1258+
default_pqc_hybrid_groups() ++
1259+
[x25519,
1260+
x448,
1261+
secp521r1,
1262+
secp384r1,
1263+
secp256r1,
1264+
brainpoolP256r1tls13,
1265+
brainpoolP384r1tls13,
1266+
brainpoolP512r1tls13
1267+
] ++
1268+
other_pqc_hybrid_groups() ++
1269+
pqc_plain_groups() ++
1270+
dhe_groups();
12771271
groups(default) ->
1278-
[x25519,
1279-
x448,
1280-
secp521r1,
1281-
secp384r1,
1282-
secp256r1,
1283-
brainpoolP512r1tls13,
1284-
brainpoolP384r1tls13,
1285-
brainpoolP256r1tls13,
1286-
mlkem512,
1287-
mlkem768,
1288-
mlkem1024,
1289-
x25519mlkem768,
1290-
secp384r1mlkem1024,
1291-
secp256r1mlkem768
1292-
];
1272+
default_pqc_hybrid_groups() ++
1273+
[x25519,
1274+
x448,
1275+
secp521r1,
1276+
secp384r1,
1277+
secp256r1,
1278+
brainpoolP512r1tls13,
1279+
brainpoolP384r1tls13,
1280+
brainpoolP256r1tls13
1281+
];
12931282
groups(TLSGroups) when is_list(TLSGroups) ->
12941283
CryptoGroups = crypto_supported_groups(),
12951284
lists:filter(fun(x25519mlkem768) ->
@@ -1305,6 +1294,25 @@ groups(TLSGroups) when is_list(TLSGroups) ->
13051294
proplists:get_bool(maybe_group_to_curve(Group), CryptoGroups)
13061295
end, TLSGroups).
13071296

1297+
default_pqc_hybrid_groups() ->
1298+
[x25519mlkem768].
1299+
1300+
other_pqc_hybrid_groups()->
1301+
[secp384r1mlkem1024,
1302+
secp256r1mlkem768].
1303+
1304+
pqc_plain_groups() ->
1305+
[mlkem1024,
1306+
mlkem768,
1307+
mlkem512].
1308+
1309+
dhe_groups() ->
1310+
[ffdhe2048,
1311+
ffdhe3072,
1312+
ffdhe4096,
1313+
ffdhe6144,
1314+
ffdhe8192].
1315+
13081316
default_groups() ->
13091317
TLSGroups = groups(default),
13101318
groups(TLSGroups).

lib/ssl/test/ssl_api_SUITE.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,7 +2233,8 @@ customize_defaults(Opts, Role, Host) ->
22332233
end,
22342234
case proplists:get_value(protocol, Opts, tls) of
22352235
dtls ->
2236-
{ok, #config{ssl=DOpts}} = ssl_config:handle_options([{protocol, dtls}|NoVerify], Role, Host),
2236+
{ok, #config{ssl=DOpts}} =
2237+
ssl_config:handle_options([{protocol, dtls}|NoVerify], Role, Host),
22372238
{DOpts, DefOpts ++ Opts};
22382239
tls ->
22392240
{ok, #config{ssl=DOpts}} = ssl_config:handle_options(NoVerify, Role, Host),
@@ -2959,7 +2960,7 @@ options_fallback(_Config) ->
29592960
ok.
29602961

29612962
options_handshake(_Config) -> %% handshake
2962-
?OK(#{handshake := full, max_handshake_size := 131072},
2963+
?OK(#{handshake := full, max_handshake_size := 262144},
29632964
[], client),
29642965
?OK(#{handshake := hello, max_handshake_size := 123800},
29652966
[{handshake, hello}, {max_handshake_size, 123800}], client),

0 commit comments

Comments
 (0)