LEFT | RIGHT |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 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 agent | 5 package agent |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "crypto/rsa" | 9 "crypto/rsa" |
10 "crypto/x509" | 10 "crypto/x509" |
11 "encoding/pem" | 11 "encoding/pem" |
12 "net" | 12 "net" |
13 "os" | 13 "os" |
14 "os/exec" | 14 "os/exec" |
15 "strconv" | 15 "strconv" |
16 "testing" | 16 "testing" |
17 | 17 |
18 » "code.google.com/p/gosshnew.agent/ssh" | 18 » "code.google.com/p/gosshnew/ssh" |
19 ) | 19 ) |
20 | 20 |
21 const rsaKeySerialized = `-----BEGIN RSA PRIVATE KEY----- | 21 const rsaKeySerialized = `-----BEGIN RSA PRIVATE KEY----- |
22 MIIBOwIBAAJBALdGZxkXDAjsYk10ihwU6Id2KeILz1TAJuoq4tOgDWxEEGeTrcld | 22 MIIBOwIBAAJBALdGZxkXDAjsYk10ihwU6Id2KeILz1TAJuoq4tOgDWxEEGeTrcld |
23 r/ZwVaFzjWzxaf6zQIJbfaSEAhqD5yo72+sCAwEAAQJBAK8PEVU23Wj8mV0QjwcJ | 23 r/ZwVaFzjWzxaf6zQIJbfaSEAhqD5yo72+sCAwEAAQJBAK8PEVU23Wj8mV0QjwcJ |
24 tZ4GcTUYQL7cF4+ezTCE9a1NrGnCP2RuQkHEKxuTVrxXt+6OF15/1/fuXnxKjmJC | 24 tZ4GcTUYQL7cF4+ezTCE9a1NrGnCP2RuQkHEKxuTVrxXt+6OF15/1/fuXnxKjmJC |
25 nxkCIQDaXvPPBi0c7vAxGwNY9726x01/dNbHCE0CBtcotobxpwIhANbbQbh3JHVW | 25 nxkCIQDaXvPPBi0c7vAxGwNY9726x01/dNbHCE0CBtcotobxpwIhANbbQbh3JHVW |
26 2haQh4fAG5mhesZKAGcxTyv4mQ7uMSQdAiAj+4dzMpJWdSzQ+qGHlHMIBvVHLkqB | 26 2haQh4fAG5mhesZKAGcxTyv4mQ7uMSQdAiAj+4dzMpJWdSzQ+qGHlHMIBvVHLkqB |
27 y2VdEyF7DPCZewIhAI7GOI/6LDIFOvtPo6Bj2nNmyQ1HU6k/LRtNIXi4c9NJAiAr | 27 y2VdEyF7DPCZewIhAI7GOI/6LDIFOvtPo6Bj2nNmyQ1HU6k/LRtNIXi4c9NJAiAr |
28 rrxx26itVhJmcvoUhOjwuzSlP2bE5VHAvkGB352YBg== | 28 rrxx26itVhJmcvoUhOjwuzSlP2bE5VHAvkGB352YBg== |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 if proc != nil { | 81 if proc != nil { |
82 proc.Kill() | 82 proc.Kill() |
83 } | 83 } |
84 ac.Close() | 84 ac.Close() |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 func TestAgent(t *testing.T) { | 88 func TestAgent(t *testing.T) { |
89 agent, cleanup := startAgent(t) | 89 agent, cleanup := startAgent(t) |
90 defer cleanup() | 90 defer cleanup() |
91 » keys, err := agent.RequestIdentities() | 91 » keys, err := agent.List() |
92 if err != nil { | 92 if err != nil { |
93 t.Fatalf("RequestIdentities: %v", err) | 93 t.Fatalf("RequestIdentities: %v", err) |
94 } | 94 } |
95 if len(keys) > 0 { | 95 if len(keys) > 0 { |
96 t.Errorf("got %d keys, want 0", len(keys)) | 96 t.Errorf("got %d keys, want 0", len(keys)) |
97 } | 97 } |
98 if err := agent.Insert(rawRSAKey, "comment"); err != nil { | 98 if err := agent.Insert(rawRSAKey, "comment"); err != nil { |
99 t.Fatalf("insert: %v", err) | 99 t.Fatalf("insert: %v", err) |
100 } | 100 } |
101 » if keys, _ := agent.RequestIdentities(); len(keys) != 1 || keys[0].Comme
nt != "comment" { | 101 » if keys, _ := agent.List(); len(keys) != 1 || keys[0].Comment != "commen
t" { |
102 t.Fatalf("got %v, want 1 key with comment `comment`", keys) | 102 t.Fatalf("got %v, want 1 key with comment `comment`", keys) |
103 } | 103 } |
104 data := []byte("hello") | 104 data := []byte("hello") |
105 sigBytes, err := agent.Sign(rsaKey.PublicKey(), data) | 105 sigBytes, err := agent.Sign(rsaKey.PublicKey(), data) |
106 if err != nil { | 106 if err != nil { |
107 t.Fatalf("Sign: %v", err) | 107 t.Fatalf("Sign: %v", err) |
108 } | 108 } |
109 | 109 |
110 type Sig struct { | 110 type Sig struct { |
111 Algo string | 111 Algo string |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 t.Fatalf("Server: %v", err) | 172 t.Fatalf("Server: %v", err) |
173 } | 173 } |
174 }() | 174 }() |
175 | 175 |
176 conf := ssh.ClientConfig{} | 176 conf := ssh.ClientConfig{} |
177 conf.Auth = append(conf.Auth, ssh.ClientAuthKeyring(agent)) | 177 conf.Auth = append(conf.Auth, ssh.ClientAuthKeyring(agent)) |
178 if _, err := ssh.Client(b, &conf); err != nil { | 178 if _, err := ssh.Client(b, &conf); err != nil { |
179 t.Fatalf("Client: %v", err) | 179 t.Fatalf("Client: %v", err) |
180 } | 180 } |
181 } | 181 } |
LEFT | RIGHT |