Skip to content

Commit 24852b6

Browse files
imirkingopherbot
authored andcommitted
ssh: add decode support for banners
These banners can be printed when enabling debugHandshake, add decode support so that they're not printed as unknown messages. Change-Id: Ic8d56079d8225c35aac843accdbc80a642dd6249 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/650635 Reviewed-by: Junyang Shao <[email protected]> Reviewed-by: Nicola Murino <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Nicola Murino <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent bbc689c commit 24852b6

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

ssh/messages.go

+2
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,8 @@ func decode(packet []byte) (interface{}, error) {
818818
return new(userAuthSuccessMsg), nil
819819
case msgUserAuthFailure:
820820
msg = new(userAuthFailureMsg)
821+
case msgUserAuthBanner:
822+
msg = new(userAuthBannerMsg)
821823
case msgUserAuthPubKeyOk:
822824
msg = new(userAuthPubKeyOkMsg)
823825
case msgGlobalRequest:

ssh/messages_test.go

+56
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,62 @@ func TestMarshalMultiTag(t *testing.T) {
206206
}
207207
}
208208

209+
func TestDecode(t *testing.T) {
210+
rnd := rand.New(rand.NewSource(0))
211+
kexInit := new(kexInitMsg).Generate(rnd, 10).Interface()
212+
kexDHInit := new(kexDHInitMsg).Generate(rnd, 10).Interface()
213+
kexDHReply := new(kexDHReplyMsg)
214+
kexDHReply.Y = randomInt(rnd)
215+
// Note: userAuthSuccessMsg can't be tested directly since it
216+
// doesn't have a field for sshtype. So it's tested separately
217+
// at the end.
218+
decodeMessageTypes := []interface{}{
219+
new(disconnectMsg),
220+
new(serviceRequestMsg),
221+
new(serviceAcceptMsg),
222+
new(extInfoMsg),
223+
kexInit,
224+
kexDHInit,
225+
kexDHReply,
226+
new(userAuthRequestMsg),
227+
new(userAuthFailureMsg),
228+
new(userAuthBannerMsg),
229+
new(userAuthPubKeyOkMsg),
230+
new(globalRequestMsg),
231+
new(globalRequestSuccessMsg),
232+
new(globalRequestFailureMsg),
233+
new(channelOpenMsg),
234+
new(channelDataMsg),
235+
new(channelOpenConfirmMsg),
236+
new(channelOpenFailureMsg),
237+
new(windowAdjustMsg),
238+
new(channelEOFMsg),
239+
new(channelCloseMsg),
240+
new(channelRequestMsg),
241+
new(channelRequestSuccessMsg),
242+
new(channelRequestFailureMsg),
243+
new(userAuthGSSAPIToken),
244+
new(userAuthGSSAPIMIC),
245+
new(userAuthGSSAPIErrTok),
246+
new(userAuthGSSAPIError),
247+
}
248+
for _, msg := range decodeMessageTypes {
249+
decoded, err := decode(Marshal(msg))
250+
if err != nil {
251+
t.Errorf("error decoding %T", msg)
252+
} else if reflect.TypeOf(msg) != reflect.TypeOf(decoded) {
253+
t.Errorf("error decoding %T, unexpected %T", msg, decoded)
254+
}
255+
}
256+
257+
userAuthSuccess, err := decode([]byte{msgUserAuthSuccess})
258+
if err != nil {
259+
t.Errorf("error decoding userAuthSuccessMsg")
260+
} else if reflect.TypeOf(userAuthSuccess) != reflect.TypeOf((*userAuthSuccessMsg)(nil)) {
261+
t.Errorf("error decoding userAuthSuccessMsg, unexpected %T", userAuthSuccess)
262+
}
263+
}
264+
209265
func randomBytes(out []byte, rand *rand.Rand) {
210266
for i := 0; i < len(out); i++ {
211267
out[i] = byte(rand.Int31())

0 commit comments

Comments
 (0)