Skip to content

Commit da8fa24

Browse files
committed
ssl: Make key share groups configurable
1 parent 019476c commit da8fa24

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

lib/ssl/src/ssl.erl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,11 @@ certificate signatures.
13801380
The following options are specific to the client side, or have
13811381
different semantics for the client and server:
13821382

1383+
- **`{psk_groups, Groups}`** - key exchange groups that the client
1384+
will send pre share keys for, defaults to first group in
1385+
supported_groups. Must be a subset of supported_groups and will
1386+
be sent in the same order as they appear in supported_groups.
1387+
13831388
- **`{alpn_advertised_protocols, AppProtocols}`** - Application layer protocol
13841389

13851390
The list of protocols supported by the client to be sent to the server to be
@@ -1397,6 +1402,7 @@ different semantics for the client and server:
13971402

13981403
-type client_option() :: client_option_cert() |
13991404
common_option_cert() |
1405+
{psk_groups, [group()]} |
14001406
{alpn_advertised_protocols, AppProtocols::[AppProto::binary()]} |
14011407
{max_fragment_length, MaxLen:: undefined | 512 | 1024 | 2048 | 4096} |
14021408
client_option_tls13() |

lib/ssl/src/ssl_config.erl

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ ssl_options() ->
493493
partial_chain,
494494
password,
495495
protocol,
496+
psk_groups,
496497
psk_identity,
497498
receiver_spawn_opts,
498499
renegotiate_at,
@@ -1371,7 +1372,7 @@ handle_user_lookup(UserOpts, #{versions := Versions} = Opts) ->
13711372
end.
13721373

13731374

1374-
opt_supported_groups(UserOpts, #{versions := TlsVsns} = Opts, _Env) ->
1375+
opt_supported_groups(UserOpts, #{versions := TlsVsns} = Opts, Env) ->
13751376
SG = case get_opt_list(supported_groups, undefined, UserOpts, Opts) of
13761377
{default, undefined} ->
13771378
try assert_version_dep(supported_groups, TlsVsns, ['tlsv1.3']) of
@@ -1404,7 +1405,27 @@ opt_supported_groups(UserOpts, #{versions := TlsVsns} = Opts, _Env) ->
14041405
throw:_ ->
14051406
[]
14061407
end,
1407-
Opts#{ciphers => CPHS, eccs => ECCS, supported_groups => SG}.
1408+
case opt_psk_groups(SG, UserOpts, Opts, Env) of
1409+
undefined ->
1410+
Opts#{ciphers => CPHS, eccs => ECCS, supported_groups => SG};
1411+
PSKGroups ->
1412+
Opts#{ciphers => CPHS, eccs => ECCS, supported_groups => SG, psk_groups => PSKGroups}
1413+
end.
1414+
1415+
opt_psk_groups(undefined, _, _, _) ->
1416+
undefined;
1417+
opt_psk_groups(#supported_groups{supported_groups = SupportedGroups}, UserOpts, Opts, _Env) ->
1418+
%% Version dependency already asserted when SupportedGroups is supported
1419+
%% so is psk_groups
1420+
First = hd(SupportedGroups),
1421+
case get_opt_list(psk_groups, [First], UserOpts, Opts) of
1422+
{default, Default} ->
1423+
Default;
1424+
{new, PSKGroups} ->
1425+
[Group || Group <- SupportedGroups, lists:member(Group, PSKGroups)];
1426+
{old, PSKGroups} ->
1427+
PSKGroups
1428+
end.
14081429

14091430
opt_crl(UserOpts, Opts, _Env) ->
14101431
{_, Check} = get_opt_of(crl_check, [best_effort, peer, true, false], false, UserOpts, Opts),

lib/ssl/src/tls_client_connection_1_3.erl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,9 @@ maybe_resumption(_) ->
593593
ok.
594594

595595
maybe_generate_client_shares(#{versions := [?TLS_1_3|_],
596-
supported_groups :=
597-
#supported_groups{
598-
supported_groups = [Group|_]}}) ->
599-
%% Generate only key_share entry for the most preferred group
600-
ssl_cipher:generate_client_shares([Group]);
596+
psk_groups := Groups}) ->
597+
%% Default will be the list of only the most proffered supported group
598+
ssl_cipher:generate_client_shares(Groups);
601599
maybe_generate_client_shares(_) ->
602600
undefined.
603601

lib/ssl/test/ssl_api_SUITE.erl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
-include_lib("common_test/include/ct.hrl").
3030
-include_lib("ssl/src/ssl_api.hrl").
3131
-include_lib("ssl/src/ssl_internal.hrl").
32+
-include_lib("ssl/src/ssl_handshake.hrl").
3233
-include_lib("public_key/include/public_key.hrl").
3334
-include_lib("ssl/src/ssl_record.hrl").
3435

@@ -3122,12 +3123,19 @@ options_sign_alg(_Config) -> %% signature_algs[_cert]
31223123
ok.
31233124

31243125
options_supported_groups(_Config) ->
3125-
Default = ssl:groups(default),
3126-
?OK(#{supported_groups := {supported_groups, Default}},
3126+
DefaultGroups = ssl:groups(default),
3127+
First = hd(DefaultGroups),
3128+
?OK(#{supported_groups := #supported_groups{supported_groups = DefaultGroups}},
31273129
[], client),
3128-
?OK(#{supported_groups := {supported_groups, [secp521r1, ffdhe2048]}},
3130+
?OK(#{supported_groups := #supported_groups{supported_groups = [secp521r1, ffdhe2048]}},
31293131
[{supported_groups, [secp521r1, ffdhe2048]}], client),
31303132

3133+
?OK(#{psk_groups := [First]},
3134+
[], client),
3135+
?OK(#{psk_groups := [secp521r1, secp256r1],
3136+
supported_groups := #supported_groups{supported_groups = [secp521r1, secp256r1, ffdhe2048]}},
3137+
[{supported_groups, [secp521r1, secp256r1, ffdhe2048]}, {psk_groups, [secp521r1, secp384r1, secp256r1]}], client),
3138+
31313139
%% ERRORs
31323140
?ERR({{'tlvs1.2'},{versions,[{'tlvs1.2'}]}},
31333141
[{supported_groups, []}, {versions, [{'tlvs1.2'}]}], client),

0 commit comments

Comments
 (0)