Skip to content

Commit 41fd499

Browse files
committed
ssh: fix wrong_role2 flow in ssh_protocol_SUITE
1 parent 7335f79 commit 41fd499

File tree

2 files changed

+75
-34
lines changed

2 files changed

+75
-34
lines changed

lib/ssh/test/ssh_protocol_SUITE.erl

Lines changed: 70 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
kex_strict_violation_key_exchange/1,
6060
kex_strict_violation_new_keys/1,
6161
kex_strict_violation/1,
62+
kex_strict_violation_2/1,
6263
kex_strict_msg_unknown/1,
6364
gex_client_init_option_groups/1,
6465
gex_client_init_option_groups_file/1,
@@ -99,11 +100,19 @@
99100
[{client2server,Ciphs}, {server2client,Ciphs}]
100101
end)()
101102
).
102-
103-
104103
-define(v(Key, Config), proplists:get_value(Key, Config)).
105104
-define(v(Key, Config, Default), proplists:get_value(Key, Config, Default)).
106-
105+
-define(HARDCODED_KEXDH_REPLY,
106+
#ssh_msg_kexdh_reply{
107+
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>>},
108+
{namedCurve,{1,3,101,112}}},
109+
'ssh-ed25519'},
110+
f = 18504393053016436370762156176197081926381112956345797067569792020930728564439992620494295053804030674742529174859108487694089045521619258420515443400605141150065440678508889060925968846155921972385560196703381004650914261218463420313738628465563288022895912907728767735629532940627575655703806353550720122093175255090704443612257683903495753071530605378193139909567971489952258218767352348904221407081210633467414579377014704081235998044497191940270966762124544755076128392259615566530695493013708460088312025006678879288856957348606386230195080105197251789635675011844976120745546472873505352732719507783227210178188,
111+
h_sig = <<90,247,44,240,136,196,82,215,56,165,53,33,230,101,253,
112+
34,112,201,21,131,162,169,10,129,174,14,69,25,39,174,
113+
92,210,130,249,103,2,215,245,7,213,110,235,136,134,11,
114+
124,248,139,79,17,225,77,125,182,204,84,137,167,99,186,
115+
167,42,192,10>>}).
107116

108117
%%--------------------------------------------------------------------
109118
%% Common Test interface functions -----------------------------------
@@ -150,6 +159,7 @@ groups() ->
150159
kex_strict_violation_key_exchange,
151160
kex_strict_violation_new_keys,
152161
kex_strict_violation,
162+
kex_strict_violation_2,
153163
kex_strict_msg_unknown]},
154164
{service_requests, [], [bad_service_name,
155165
bad_long_service_name,
@@ -407,7 +417,7 @@ early_rce(Config) ->
407417
DataReq = <<?STRING(<<"lists:seq(1,10).">>)>>,
408418
SshMsgChannelRequest =
409419
ssh_connection:channel_request_msg(Id, TypeReq, WantReply, DataReq),
410-
{ok,AfterKexState} =
420+
{ok, _AfterKexState} =
411421
ssh_trpt_test_lib:exec(
412422
[{connect,
413423
server_host(Config),server_port(Config),
@@ -1061,20 +1071,8 @@ kex_strict_violation_new_keys(Config) ->
10611071
%% Connect to an erlang server and inject unexpected SSH message
10621072
%% duplicated KEXINIT
10631073
kex_strict_violation(Config) ->
1064-
KexDhReply =
1065-
#ssh_msg_kexdh_reply{
1066-
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>>},
1067-
{namedCurve,{1,3,101,112}}},
1068-
'ssh-ed25519'},
1069-
f = 18504393053016436370762156176197081926381112956345797067569792020930728564439992620494295053804030674742529174859108487694089045521619258420515443400605141150065440678508889060925968846155921972385560196703381004650914261218463420313738628465563288022895912907728767735629532940627575655703806353550720122093175255090704443612257683903495753071530605378193139909567971489952258218767352348904221407081210633467414579377014704081235998044497191940270966762124544755076128392259615566530695493013708460088312025006678879288856957348606386230195080105197251789635675011844976120745546472873505352732719507783227210178188,
1070-
h_sig = <<90,247,44,240,136,196,82,215,56,165,53,33,230,101,253,
1071-
34,112,201,21,131,162,169,10,129,174,14,69,25,39,174,
1072-
92,210,130,249,103,2,215,245,7,213,110,235,136,134,11,
1073-
124,248,139,79,17,225,77,125,182,204,84,137,167,99,186,
1074-
167,42,192,10>>},
10751074
TestFlows =
1076-
[
1077-
{kexinit, "KEX strict violation",
1075+
[{kexinit, "KEX strict violation",
10781076
[receive_hello,
10791077
{send, hello},
10801078
{send, ssh_msg_kexinit},
@@ -1114,20 +1112,8 @@ kex_strict_violation(Config) ->
11141112
{send, ssh_msg_kexinit},
11151113
{match, #ssh_msg_kexinit{_='_'}, receive_msg},
11161114
%% client should not send message below
1117-
{send, KexDhReply},
1118-
{match, disconnect(?SSH_DISCONNECT_KEY_EXCHANGE_FAILED), receive_msg}]},
1119-
{wrong_role2, "KEX strict violation",
1120-
[receive_hello,
1121-
{send, hello},
1122-
{send, ssh_msg_kexinit},
1123-
{match, #ssh_msg_kexinit{_='_'}, receive_msg},
1124-
{send, ssh_msg_kexdh_init},
1125-
{match,# ssh_msg_kexdh_reply{_='_'}, receive_msg},
1126-
%% client should not send message below
1127-
{send, KexDhReply},
1128-
{match, #ssh_msg_newkeys{_='_'}, receive_msg},
1129-
{match, disconnect(?SSH_DISCONNECT_KEY_EXCHANGE_FAILED), receive_msg}]}
1130-
],
1115+
{send, ?HARDCODED_KEXDH_REPLY},
1116+
{match, disconnect(?SSH_DISCONNECT_KEY_EXCHANGE_FAILED), receive_msg}]}],
11311117
TestProcedure =
11321118
fun({Msg, _, P}) ->
11331119
ct:log(
@@ -1140,6 +1126,58 @@ kex_strict_violation(Config) ->
11401126
ct:log("==== END ====="),
11411127
ok.
11421128

1129+
kex_strict_violation_2(Config) ->
1130+
ExpectedReason = "KEX strict violation",
1131+
{ok, TestRef} = ssh_test_lib:add_log_handler(),
1132+
Level = ssh_test_lib:get_log_level(),
1133+
ssh_test_lib:set_log_level(debug),
1134+
%% Connect and negotiate keys
1135+
{ok, InitialState} = ssh_trpt_test_lib:exec(
1136+
[{set_options, [print_ops, print_seqnums, print_messages]}]),
1137+
{ok, UpToUnexpectedKexDHReply} =
1138+
ssh_trpt_test_lib:exec(
1139+
[{connect,
1140+
server_host(Config),server_port(Config),
1141+
[{preferred_algorithms,[{kex,[?DEFAULT_KEX]},
1142+
{cipher,?DEFAULT_CIPHERS}
1143+
]},
1144+
{silently_accept_hosts, true},
1145+
{recv_ext_info, false},
1146+
{user_dir, user_dir(Config)},
1147+
{user_interaction, false}
1148+
| proplists:get_value(extra_options,Config,[])
1149+
]}] ++
1150+
[receive_hello,
1151+
{send, hello},
1152+
{send, ssh_msg_kexinit},
1153+
{match, #ssh_msg_kexinit{_='_'}, receive_msg},
1154+
{send, ssh_msg_kexdh_init},
1155+
{match, #ssh_msg_kexdh_reply{_='_'}, receive_msg},
1156+
%% client should not send message below
1157+
{send, ?HARDCODED_KEXDH_REPLY},
1158+
{match, {'or', [#ssh_msg_newkeys{_='_'},
1159+
disconnect(?SSH_DISCONNECT_KEY_EXCHANGE_FAILED)]},
1160+
receive_msg}],
1161+
InitialState),
1162+
case ssh_trpt_test_lib:return_value(UpToUnexpectedKexDHReply) of
1163+
{ssh_msg_newkeys} ->
1164+
ct:log("1st flow - extra match for disconnect needed"),
1165+
ssh_trpt_test_lib:exec(
1166+
[{match, disconnect(?SSH_DISCONNECT_KEY_EXCHANGE_FAILED), receive_msg}],
1167+
UpToUnexpectedKexDHReply);
1168+
_ ->
1169+
ct:log("2nd flow disconnect already received")
1170+
end,
1171+
ct:sleep(100),
1172+
{ok, Events} = ssh_test_lib:get_log_events(TestRef),
1173+
ssh_test_lib:rm_log_handler(),
1174+
ct:log("Events = ~p", [Events]),
1175+
true = ssh_test_lib:kex_strict_negotiated(client, Events),
1176+
true = ssh_test_lib:kex_strict_negotiated(server, Events),
1177+
true = ssh_test_lib:event_logged(server, Events, ExpectedReason),
1178+
ssh_test_lib:set_log_level(Level),
1179+
ok.
1180+
11431181
%% Connect to an erlang server and inject unexpected non-SSH binary
11441182
kex_strict_msg_unknown(Config) ->
11451183
ct:log("START: ~p~n=================================", [?FUNCTION_NAME]),
@@ -1161,8 +1199,7 @@ kex_strict_helper(Config, TestMessages, ExpectedReason) ->
11611199
ssh_test_lib:set_log_level(debug),
11621200
%% Connect and negotiate keys
11631201
{ok, InitialState} = ssh_trpt_test_lib:exec(
1164-
[{set_options, [print_ops, print_seqnums, print_messages]}]
1165-
),
1202+
[{set_options, [print_ops, print_seqnums, print_messages]}]),
11661203
{ok, _AfterKexState} =
11671204
ssh_trpt_test_lib:exec(
11681205
[{connect,

lib/ssh/test/ssh_trpt_test_lib.erl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
-export([exec/1, exec/2,
2525
instantiate/2,
2626
format_msg/1,
27-
server_host_port/1
27+
server_host_port/1,
28+
return_value/1
2829
]
2930
).
3031

@@ -814,3 +815,6 @@ opt(Flag, S, Fun) when is_function(Fun,1) ->
814815

815816
save_prints({Fmt,Args}, S) ->
816817
S#s{prints = [{Fmt,Args}|S#s.prints]}.
818+
819+
return_value(#s{return_value = ReturnValue}) ->
820+
ReturnValue.

0 commit comments

Comments
 (0)