OLD | NEW |
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 "errors" | 8 "errors" |
9 "fmt" | 9 "fmt" |
10 "io" | 10 "io" |
11 "net" | 11 "net" |
12 ) | 12 ) |
13 | 13 |
14 // authenticate authenticates with the remote server. See RFC 4252. | 14 // authenticate authenticates with the remote server. See RFC 4252. |
15 func (c *ClientConn) authenticate() error { | 15 func (c *ClientConn) authenticate() error { |
16 // initiate user auth session | 16 // initiate user auth session |
17 if err := c.transport.writePacket(marshal(msgServiceRequest, serviceRequ
estMsg{serviceUserAuth})); err != nil { | 17 if err := c.transport.writePacket(marshal(msgServiceRequest, serviceRequ
estMsg{serviceUserAuth})); err != nil { |
18 return err | 18 return err |
19 } | 19 } |
20 packet, err := c.transport.readPacket() | 20 packet, err := c.transport.readPacket() |
21 if err != nil { | 21 if err != nil { |
22 return err | 22 return err |
23 } | 23 } |
24 var serviceAccept serviceAcceptMsg | 24 var serviceAccept serviceAcceptMsg |
25 if err := unmarshal(&serviceAccept, packet, msgServiceAccept); err != ni
l { | 25 if err := unmarshal(&serviceAccept, packet, msgServiceAccept); err != ni
l { |
26 return err | 26 return err |
27 } | 27 } |
| 28 |
28 // during the authentication phase the client first attempts the "none"
method | 29 // during the authentication phase the client first attempts the "none"
method |
29 // then any untried methods suggested by the server. | 30 // then any untried methods suggested by the server. |
30 tried, remain := make(map[string]bool), make(map[string]bool) | 31 tried, remain := make(map[string]bool), make(map[string]bool) |
31 for auth := ClientAuth(new(noneAuth)); auth != nil; { | 32 for auth := ClientAuth(new(noneAuth)); auth != nil; { |
32 » » ok, methods, err := auth.auth(c.transport.sessionID, c.config.Us
er, c.transport, c.config.rand()) | 33 » » ok, methods, err := auth.auth(c.transport.getSessionID(), c.conf
ig.User, c.transport, c.config.rand()) |
33 if err != nil { | 34 if err != nil { |
34 return err | 35 return err |
35 } | 36 } |
36 if ok { | 37 if ok { |
37 // success | 38 // success |
38 return nil | 39 return nil |
39 } | 40 } |
40 tried[auth.method()] = true | 41 tried[auth.method()] = true |
41 delete(remain, auth.method()) | 42 delete(remain, auth.method()) |
42 for _, meth := range methods { | 43 for _, meth := range methods { |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 p = marshalUint32(p, uint32(len(answers))) | 501 p = marshalUint32(p, uint32(len(answers))) |
501 for _, a := range answers { | 502 for _, a := range answers { |
502 p = marshalString(p, []byte(a)) | 503 p = marshalString(p, []byte(a)) |
503 } | 504 } |
504 | 505 |
505 if err := c.writePacket(serialized); err != nil { | 506 if err := c.writePacket(serialized); err != nil { |
506 return false, nil, err | 507 return false, nil, err |
507 } | 508 } |
508 } | 509 } |
509 } | 510 } |
OLD | NEW |