Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package ssh | 5 package ssh |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "encoding/binary" | 9 "encoding/binary" |
10 "io" | 10 "io" |
11 "math/big" | 11 "math/big" |
12 "reflect" | 12 "reflect" |
13 ) | 13 ) |
14 | 14 |
15 // These are SSH message type numbers. They are scattered around several | 15 // These are SSH message type numbers. They are scattered around several |
16 // documents but many were taken from [SSH-PARAMETERS]. | 16 // documents but many were taken from [SSH-PARAMETERS]. |
17 const ( | 17 const ( |
18 msgDisconnect = 1 | 18 msgDisconnect = 1 |
19 msgIgnore = 2 | 19 msgIgnore = 2 |
20 msgUnimplemented = 3 | 20 msgUnimplemented = 3 |
21 msgDebug = 4 | 21 msgDebug = 4 |
22 msgServiceRequest = 5 | 22 msgServiceRequest = 5 |
23 msgServiceAccept = 6 | 23 msgServiceAccept = 6 |
24 | 24 |
25 msgKexInit = 20 | 25 msgKexInit = 20 |
26 msgNewKeys = 21 | 26 msgNewKeys = 21 |
27 | 27 |
28 // Diffie-Helman | |
28 msgKexDHInit = 30 | 29 msgKexDHInit = 30 |
29 msgKexDHReply = 31 | 30 msgKexDHReply = 31 |
30 | 31 |
32 // Standard authentication messages | |
31 msgUserAuthRequest = 50 | 33 msgUserAuthRequest = 50 |
32 msgUserAuthFailure = 51 | 34 msgUserAuthFailure = 51 |
33 msgUserAuthSuccess = 52 | 35 msgUserAuthSuccess = 52 |
34 msgUserAuthBanner = 53 | 36 msgUserAuthBanner = 53 |
35 msgUserAuthPubKeyOk = 60 | 37 msgUserAuthPubKeyOk = 60 |
36 | 38 |
37 » // Method specific messages: | 39 » // Method specific messages |
dfc
2013/06/06 12:04:42
this is a good comment, s/://
Maybe add some more
hanwen-google
2013/06/06 13:33:07
Done.
| |
38 msgUserAuthInfoRequest = 60 | 40 msgUserAuthInfoRequest = 60 |
39 msgUserAuthInfoResponse = 61 | 41 msgUserAuthInfoResponse = 61 |
40 | 42 |
41 msgGlobalRequest = 80 | 43 msgGlobalRequest = 80 |
42 msgRequestSuccess = 81 | 44 msgRequestSuccess = 81 |
43 msgRequestFailure = 82 | 45 msgRequestFailure = 82 |
44 | 46 |
47 // Channel manipulation | |
45 msgChannelOpen = 90 | 48 msgChannelOpen = 90 |
46 msgChannelOpenConfirm = 91 | 49 msgChannelOpenConfirm = 91 |
47 msgChannelOpenFailure = 92 | 50 msgChannelOpenFailure = 92 |
48 msgChannelWindowAdjust = 93 | 51 msgChannelWindowAdjust = 93 |
49 msgChannelData = 94 | 52 msgChannelData = 94 |
50 msgChannelExtendedData = 95 | 53 msgChannelExtendedData = 95 |
51 msgChannelEOF = 96 | 54 msgChannelEOF = 96 |
52 msgChannelClose = 97 | 55 msgChannelClose = 97 |
53 msgChannelRequest = 98 | 56 msgChannelRequest = 98 |
54 msgChannelSuccess = 99 | 57 msgChannelSuccess = 99 |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
574 to[1] = byte(len(s) >> 16) | 577 to[1] = byte(len(s) >> 16) |
575 to[2] = byte(len(s) >> 8) | 578 to[2] = byte(len(s) >> 8) |
576 to[3] = byte(len(s)) | 579 to[3] = byte(len(s)) |
577 to = to[4:] | 580 to = to[4:] |
578 copy(to, s) | 581 copy(to, s) |
579 return to[len(s):] | 582 return to[len(s):] |
580 } | 583 } |
581 | 584 |
582 var bigIntType = reflect.TypeOf((*big.Int)(nil)) | 585 var bigIntType = reflect.TypeOf((*big.Int)(nil)) |
583 | 586 |
584 // Decode a packet into it's corresponding message. | 587 // Decode a packet into its corresponding message. |
585 func decode(packet []byte) interface{} { | 588 func decode(packet []byte) (interface{}, error) { |
586 var msg interface{} | 589 var msg interface{} |
587 switch packet[0] { | 590 switch packet[0] { |
588 case msgDisconnect: | 591 case msgDisconnect: |
589 msg = new(disconnectMsg) | 592 msg = new(disconnectMsg) |
590 case msgServiceRequest: | 593 case msgServiceRequest: |
591 msg = new(serviceRequestMsg) | 594 msg = new(serviceRequestMsg) |
592 case msgServiceAccept: | 595 case msgServiceAccept: |
593 msg = new(serviceAcceptMsg) | 596 msg = new(serviceAcceptMsg) |
594 case msgKexInit: | 597 case msgKexInit: |
595 msg = new(kexInitMsg) | 598 msg = new(kexInitMsg) |
(...skipping 25 matching lines...) Expand all Loading... | |
621 msg = new(channelEOFMsg) | 624 msg = new(channelEOFMsg) |
622 case msgChannelClose: | 625 case msgChannelClose: |
623 msg = new(channelCloseMsg) | 626 msg = new(channelCloseMsg) |
624 case msgChannelRequest: | 627 case msgChannelRequest: |
625 msg = new(channelRequestMsg) | 628 msg = new(channelRequestMsg) |
626 case msgChannelSuccess: | 629 case msgChannelSuccess: |
627 msg = new(channelRequestSuccessMsg) | 630 msg = new(channelRequestSuccessMsg) |
628 case msgChannelFailure: | 631 case msgChannelFailure: |
629 msg = new(channelRequestFailureMsg) | 632 msg = new(channelRequestFailureMsg) |
630 default: | 633 default: |
631 » » return UnexpectedMessageError{0, packet[0]} | 634 » » return nil, UnexpectedMessageError{0, packet[0]} |
632 } | 635 } |
633 if err := unmarshal(msg, packet, packet[0]); err != nil { | 636 if err := unmarshal(msg, packet, packet[0]); err != nil { |
634 » » return err | 637 » » return nil, err |
635 » } | 638 » } |
636 » return msg | 639 » return msg, nil |
637 } | 640 } |
LEFT | RIGHT |