Skip to content

Commit 678f3ac

Browse files
committed
ssh: fix wrong_role2 flow in ssh_protocol_SUITE
1 parent 9e6f674 commit 678f3ac

File tree

2 files changed

+76
-31
lines changed

2 files changed

+76
-31
lines changed

lib/ssh/test/ssh_protocol_SUITE.erl

Lines changed: 71 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
kex_strict_violation_key_exchange/1,
6464
kex_strict_violation_new_keys/1,
6565
kex_strict_violation/1,
66+
kex_strict_violation_2/1,
6667
kex_strict_msg_unknown/1,
6768
gex_client_init_option_groups/1,
6869
gex_client_init_option_groups_file/1,
@@ -103,6 +104,18 @@
103104
[{client2server,Ciphs}, {server2client,Ciphs}]
104105
end)()
105106
).
107+
-define(HARDCODED_KEXDH_REPLY,
108+
#ssh_msg_kexdh_reply{
109+
public_host_key = {{{'ECPoint',<<73,72,235,162,96,101,154,59,217,114,123,192,96,105,250,29,214,76,60,63,167,21,221,118,246,168,152,2,7,172,137,125>>},
110+
{namedCurve,{1,3,101,112}}},
111+
'ssh-ed25519'},
112+
f = 18504393053016436370762156176197081926381112956345797067569792020930728564439992620494295053804030674742529174859108487694089045521619258420515443400605141150065440678508889060925968846155921972385560196703381004650914261218463420313738628465563288022895912907728767735629532940627575655703806353550720122093175255090704443612257683903495753071530605378193139909567971489952258218767352348904221407081210633467414579377014704081235998044497191940270966762124544755076128392259615566530695493013708460088312025006678879288856957348606386230195080105197251789635675011844976120745546472873505352732719507783227210178188,
113+
h_sig = <<90,247,44,240,136,196,82,215,56,165,53,33,230,101,253,
114+
34,112,201,21,131,162,169,10,129,174,14,69,25,39,174,
115+
92,210,130,249,103,2,215,245,7,213,110,235,136,134,11,
116+
124,248,139,79,17,225,77,125,182,204,84,137,167,99,186,
117+
167,42,192,10>>}).
118+
106119
%%--------------------------------------------------------------------
107120
%% Common Test interface functions -----------------------------------
108121
%%--------------------------------------------------------------------
@@ -147,6 +160,7 @@ groups() ->
147160
kex_strict_violation_key_exchange,
148161
kex_strict_violation_new_keys,
149162
kex_strict_violation,
163+
kex_strict_violation_2,
150164
kex_strict_msg_unknown]},
151165
{service_requests, [], [bad_service_name,
152166
bad_long_service_name,
@@ -406,7 +420,7 @@ early_rce(Config) ->
406420
DataReq = <<?STRING(<<"lists:seq(1,10).">>)>>,
407421
SshMsgChannelRequest =
408422
ssh_connection:channel_request_msg(Id, TypeReq, WantReply, DataReq),
409-
{ok,_} =
423+
{ok, _AfterKexState} =
410424
ssh_trpt_test_lib:exec(
411425
[{connect,
412426
ssh_test_lib:server_host(Config),ssh_test_lib:server_port(Config),
@@ -1128,20 +1142,8 @@ kex_strict_violation_new_keys(Config) ->
11281142
%% Connect to an erlang server and inject unexpected SSH message
11291143
%% duplicated KEXINIT
11301144
kex_strict_violation(Config) ->
1131-
KexDhReply =
1132-
#ssh_msg_kexdh_reply{
1133-
public_host_key = {{{'ECPoint',<<73,72,235,162,96,101,154,59,217,114,123,192,96,105,250,29,214,76,60,63,167,21,221,118,246,168,152,2,7,172,137,125>>},
1134-
{namedCurve,{1,3,101,112}}},
1135-
'ssh-ed25519'},
1136-
f = 18504393053016436370762156176197081926381112956345797067569792020930728564439992620494295053804030674742529174859108487694089045521619258420515443400605141150065440678508889060925968846155921972385560196703381004650914261218463420313738628465563288022895912907728767735629532940627575655703806353550720122093175255090704443612257683903495753071530605378193139909567971489952258218767352348904221407081210633467414579377014704081235998044497191940270966762124544755076128392259615566530695493013708460088312025006678879288856957348606386230195080105197251789635675011844976120745546472873505352732719507783227210178188,
1137-
h_sig = <<90,247,44,240,136,196,82,215,56,165,53,33,230,101,253,
1138-
34,112,201,21,131,162,169,10,129,174,14,69,25,39,174,
1139-
92,210,130,249,103,2,215,245,7,213,110,235,136,134,11,
1140-
124,248,139,79,17,225,77,125,182,204,84,137,167,99,186,
1141-
167,42,192,10>>},
11421145
TestFlows =
1143-
[
1144-
{kexinit, "KEX strict violation",
1146+
[{kexinit, "KEX strict violation",
11451147
[receive_hello,
11461148
{send, hello},
11471149
{send, ssh_msg_kexinit},
@@ -1181,20 +1183,8 @@ kex_strict_violation(Config) ->
11811183
{send, ssh_msg_kexinit},
11821184
{match, #ssh_msg_kexinit{_='_'}, receive_msg},
11831185
%% client should not send message below
1184-
{send, KexDhReply},
1185-
{match, disconnect(?SSH_DISCONNECT_KEY_EXCHANGE_FAILED), receive_msg}]},
1186-
{wrong_role2, "KEX strict violation",
1187-
[receive_hello,
1188-
{send, hello},
1189-
{send, ssh_msg_kexinit},
1190-
{match, #ssh_msg_kexinit{_='_'}, receive_msg},
1191-
{send, ssh_msg_kexdh_init},
1192-
{match,# ssh_msg_kexdh_reply{_='_'}, receive_msg},
1193-
%% client should not send message below
1194-
{send, KexDhReply},
1195-
{match, #ssh_msg_newkeys{_='_'}, receive_msg},
1196-
{match, disconnect(?SSH_DISCONNECT_KEY_EXCHANGE_FAILED), receive_msg}]}
1197-
],
1186+
{send, ?HARDCODED_KEXDH_REPLY},
1187+
{match, disconnect(?SSH_DISCONNECT_KEY_EXCHANGE_FAILED), receive_msg}]}],
11981188
TestProcedure =
11991189
fun({Msg, _, P}) ->
12001190
ct:log(
@@ -1207,6 +1197,58 @@ kex_strict_violation(Config) ->
12071197
ct:log("==== END ====="),
12081198
ok.
12091199

1200+
kex_strict_violation_2(Config) ->
1201+
ExpectedReason = "KEX strict violation",
1202+
{ok, TestRef} = ssh_test_lib:add_log_handler(),
1203+
Level = ssh_test_lib:get_log_level(),
1204+
ssh_test_lib:set_log_level(debug),
1205+
%% Connect and negotiate keys
1206+
{ok, InitialState} = ssh_trpt_test_lib:exec(
1207+
[{set_options, [print_ops, print_seqnums, print_messages]}]),
1208+
{ok, UpToUnexpectedKexDHReply} =
1209+
ssh_trpt_test_lib:exec(
1210+
[{connect,
1211+
ssh_test_lib:server_host(Config),ssh_test_lib:server_port(Config),
1212+
[{preferred_algorithms,[{kex,[?DEFAULT_KEX]},
1213+
{cipher,?DEFAULT_CIPHERS}
1214+
]},
1215+
{silently_accept_hosts, true},
1216+
{recv_ext_info, false},
1217+
{user_dir, user_dir(Config)},
1218+
{user_interaction, false}
1219+
| proplists:get_value(extra_options,Config,[])
1220+
]}] ++
1221+
[receive_hello,
1222+
{send, hello},
1223+
{send, ssh_msg_kexinit},
1224+
{match, #ssh_msg_kexinit{_='_'}, receive_msg},
1225+
{send, ssh_msg_kexdh_init},
1226+
{match, #ssh_msg_kexdh_reply{_='_'}, receive_msg},
1227+
%% client should not send message below
1228+
{send, ?HARDCODED_KEXDH_REPLY},
1229+
{match, {'or', [#ssh_msg_newkeys{_='_'},
1230+
disconnect(?SSH_DISCONNECT_KEY_EXCHANGE_FAILED)]},
1231+
receive_msg}],
1232+
InitialState),
1233+
case ssh_trpt_test_lib:return_value(UpToUnexpectedKexDHReply) of
1234+
{ssh_msg_newkeys} ->
1235+
ct:log("1st flow - extra match for disconnect needed"),
1236+
ssh_trpt_test_lib:exec(
1237+
[{match, disconnect(?SSH_DISCONNECT_KEY_EXCHANGE_FAILED), receive_msg}],
1238+
UpToUnexpectedKexDHReply);
1239+
_ ->
1240+
ct:log("2nd flow disconnect already received")
1241+
end,
1242+
ct:sleep(100),
1243+
{ok, Events} = ssh_test_lib:get_log_events(TestRef),
1244+
ssh_test_lib:rm_log_handler(),
1245+
ct:log("Events = ~p", [Events]),
1246+
true = ssh_test_lib:kex_strict_negotiated(client, Events),
1247+
true = ssh_test_lib:kex_strict_negotiated(server, Events),
1248+
true = ssh_test_lib:event_logged(server, Events, ExpectedReason),
1249+
ssh_test_lib:set_log_level(Level),
1250+
ok.
1251+
12101252
%% Connect to an erlang server and inject unexpected non-SSH binary
12111253
kex_strict_msg_unknown(Config) ->
12121254
ct:log("START: ~p~n=================================", [?FUNCTION_NAME]),
@@ -1228,8 +1270,7 @@ kex_strict_helper(Config, TestMessages, ExpectedReason) ->
12281270
ssh_test_lib:set_log_level(debug),
12291271
%% Connect and negotiate keys
12301272
{ok, InitialState} = ssh_trpt_test_lib:exec(
1231-
[{set_options, [print_ops, print_seqnums, print_messages]}]
1232-
),
1273+
[{set_options, [print_ops, print_seqnums, print_messages]}]),
12331274
{ok, _AfterKexState} =
12341275
ssh_trpt_test_lib:exec(
12351276
[{connect,

lib/ssh/test/ssh_trpt_test_lib.erl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
-export([exec/1, exec/2,
2727
instantiate/2,
2828
format_msg/1,
29-
server_host_port/1
29+
server_host_port/1,
30+
return_value/1
3031
]
3132
).
3233

@@ -816,3 +817,6 @@ opt(Flag, S, Fun) when is_function(Fun,1) ->
816817

817818
save_prints({Fmt,Args}, S) ->
818819
S#s{prints = [{Fmt,Args}|S#s.prints]}.
820+
821+
return_value(#s{return_value = ReturnValue}) ->
822+
ReturnValue.

0 commit comments

Comments
 (0)