-
Notifications
You must be signed in to change notification settings - Fork 19
/
knownhosts_test.go
304 lines (229 loc) · 16.5 KB
/
knownhosts_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
package sshego
import (
"context"
"fmt"
"testing"
"github.com/glycerine/sshego/xendor/github.com/glycerine/xcryptossh"
cv "github.com/glycerine/goconvey/convey"
)
func Test301ReadKnownHosts(t *testing.T) {
cv.Convey("LoadSshKnownHosts() should read a known hosts file.", t, func() {
h, err := LoadSshKnownHosts("./testdata/fake_known_hosts")
panicOn(err)
cv.So(len(h.Hosts), cv.ShouldEqual, 4)
// spot check
a, ok := h.Hosts["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDV9+u9lgOMCrRcRa3CR76eQkoJVFauaCUu7P9XasMCpWaWYK/yGqo/WuMEiA3kysAjPyfBSZ9vkOsJIVlnsgKfQqXXmE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+aIqupqN+Sc0JxCGlNvo5eKdNBZP7u/9UC7eee7Y7lHYRmhzoC7FSzFL1/mGgVxrEljcp8UZ1OD47Aq0XYvJA+5MAElbgWrK+M+EMwOGA85qQES5xtvfyVlnNvked6GQlfEuckM6H5bQCIdGkeuJ/+eWWW0rXNVkYHwA4EdiIaAXya4pO439kZfip/gWFF4mazHKCYOQAKndusFSOvxyWOTY/EbSrI7BYoYwm1WR75q7OozJTYP0V3UO+lQ+0/RgSh2uEqyfqB+EMZlATWBl3QnjxKHm7R0dVPnk9qpsjlVXGgGCCWn1UVHKq8w==\n"]
cv.So(ok, cv.ShouldBeTrue)
cv.So(b.Hostname, cv.ShouldEqual, "10.0.0.201:22")
})
}
func Test302ReadKnownHosts(t *testing.T) {
cv.Convey("LoadSshKnownHosts() should read a known hosts file.", t, func() {
fmt.Printf("\n when a client connects to a new unknown host with -new or TofuAddIfNotKnown=true, we should record the new host in the known hosts file\n")
// start a simple TCP server that is the target of the forward through the sshd,
// so we can confirm the client has made the connection.
// generate a random payload for the client to send to the server.
payloadByteCount := 50
confirmationPayload := RandomString(payloadByteCount)
confirmationReply := RandomString(payloadByteCount)
serverDone := ssh.NewHalter()
tcpSrvLsn, tcpSrvPort := GetAvailPort()
StartBackgroundTestTcpServer(
serverDone,
payloadByteCount,
confirmationPayload,
confirmationReply,
tcpSrvLsn, nil)
s := MakeTestSshClientAndServer(true)
defer TempDirCleanup(s.SrvCfg.Origdir, s.SrvCfg.Tempdir)
fmt.Printf("\n tell the server to represent itself as B so we can add its key\n")
bPubKey, err := s.SrvCfg.HostDb.adoptNewHostKeyFromPath(s.SrvCfg.Tempdir + "/testdata/id_rsa_b")
panicOn(err)
sbPubKey := string(ssh.MarshalAuthorizedKey(bPubKey))
fmt.Printf("\n we had the server adopt public key '%s'\n", sbPubKey)
// also have to update the Esshd auth state on the update channel:
s.SrvCfg.Esshd.updateHostKey <- s.SrvCfg.HostDb.HostSshSigner
dest := fmt.Sprintf("127.0.0.1:%v", tcpSrvPort)
pp("just prior to manual NewKnownHosts call")
cliKnownHosts, err := NewKnownHosts(s.CliCfg.ClientKnownHostsPath, KHSsh)
panicOn(err)
cv.So(len(cliKnownHosts.Hosts), cv.ShouldEqual, 3)
// verify that read of known hosts lacks B
_, ok := cliKnownHosts.Hosts["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC9hxNTsXHBIuWdc0SZAwN6Bytwr5vCB2K7rf5yVoC5YX5Hb08c25Xd5sGhehAj8RXooNxCa62mDnk/ACcByDa35gv3HyDqm1kmFLNvM/OcNNmK2FCuIdwKG7QWjmZwIwS3eCudJjDGR3qUTUzZbLpV80eZ0WxYE/CbZdb9gx6lNSAWx+ZaeGTt9M0sD5AfEHSxg2lJFaA5pa0Zaaq4QoultLtfisEnTHKCprjRc9RHuZ0l4kwi2eLtBdMmvR3Guk+wrd/qy6+S2zqn4WMDgE50VE6B6ODXN5nsFGrKfqx4mRD3dic28j1rJ7JVkc8sz8/tI+Mr4onomLZftbAFa5dwdiXtqDbOJlxe4sd4oVDImpocAtk+aIqupqN+Sc0JxCGlNvo5eKdNBZP7u/9UC7eee7Y7lHYRmhzoC7FSzFL1/mGgVxrEljcp8UZ1OD47Aq0XYvJA+5MAElbgWrK+M+EMwOGA85qQES5xtvfyVlnNvked6GQlfEuckM6H5bQCIdGkeuJ/+eWWW0rXNVkYHwA4EdiIaAXya4pO439kZfip/gWFF4mazHKCYOQAKndusFSOvxyWOTY/EbSrI7BYoYwm1WR75q7OozJTYP0V3UO+lQ+0/RgSh2uEqyfqB+EMZlATWBl3QnjxKHm7R0dVPnk9qpsjlVXGgGCCWn1UVHKq8w==\n"]
cv.So(ok, cv.ShouldBeFalse)
// but A should have loaded just fine
_, ok = cliKnownHosts.Hosts["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDV9+u9lgOMCrRcRa3CR76eQkoJVFauaCUu7P9XasMCpWaWYK/yGqo/WuMEiA3kysAjPyfBSZ9vkOsJIVlnsgKfQqXXmE1yIQeS0qFz+bHx5QaM4zNTLnh5HcXvs5V//831VvHnwqWCapiUj/akyFc8TQaGmUJ0IzQNF5Z1U6brTFv6w5IVO59dJUCUWwr2x08ol+NKTjMIsTtkaqLE2wDZJNUCjKDHzKDGtz1uM+do1we59PrQ3fLK1wVquiNWG9eG9qsylusJaw8IRQu7VtYLq7Y0hv/SXjzv5rULODdnoQhuKkSz/pG3BwyTkZS/Id2aI4gbRLb40pbNDFZx2iY7jyDFyqlaf2mQRFw7lTrjahTfTtpJpTl5VqJMq6+fVV1sx5YkTaCP/uELd8aTk/KdagDOnSv8s+7utz6TW43L1fJl2Ucwmvb8SvByoLZdbphnUhHxhkJ++UaDBRUpqptT2V+tyjP0mCo6GddJbFPiK6nE2DhWqrVhzo3BkkyPeA0L+VTQnF7dTmgInAjat+eU9IooYUFofkrTq+15iJxW7mNY2wp2sUCi94zCzHi9KvkMHv9tVqOU24dJCfUzXEqdYDmTt04DUtDqYB9w3THQFz6a3bdKcB1zbWXH36/6yhdocfu+lPmb9nMbpLChXMRuaSjBSRbpzcVnKxXoTFrCjw==\n"]
cv.So(ok, cv.ShouldBeTrue)
// below over SSH should be equivalent of the following
// non-encrypted ping/pong.
dc := DialConfig{
ClientKnownHostsPath: s.CliCfg.ClientKnownHostsPath,
KnownHosts: cliKnownHosts,
Mylogin: s.Mylogin,
RsaPath: s.RsaPath,
TotpUrl: s.Totp,
Pw: s.Pw,
Sshdhost: s.SrvCfg.EmbeddedSSHd.Host,
Sshdport: s.SrvCfg.EmbeddedSSHd.Port,
DownstreamHostPort: dest,
TofuAddIfNotKnown: true,
}
ctx := context.Background()
// first time we add the server key
channelToTcpServer, _, _, err := dc.Dial(ctx, nil, false)
cv.So(err.Error(), cv.ShouldContainSubstring, "Re-run without -new")
fmt.Printf("\n now host key B should be known.\n")
cv.So(len(cliKnownHosts.Hosts), cv.ShouldEqual, 4)
// show the hosts:
i := 0
for k := range cliKnownHosts.Hosts {
fmt.Printf("%v: we known about host k = '%v'\n", i, k)
i++
}
// verify that hostkey for B is now present
_, ok = cliKnownHosts.Hosts["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC9hxNTsXHBIuWdc0SZAwN6Bytwr5vCB2K7rf5yVoC5YX5Hb08c25Xd5sGhehAj8RXooNxCa62mDnk/ACcByDa35gv3HyDqm1kmFLNvM/OcNNmK2FCuIdwKG7QWjmZwIwS3eCudJjDGR3qUTUzZbLpV80eZ0WxYE/CbZdb9gx6lNSAWx+ZaeGTt9M0sD5AfEHSxg2lJFaA5pa0Zaaq4QoultLtfisEnTHKCprjRc9RHuZ0l4kwi2eLtBdMmvR3Guk+wrd/qy6+S2zqn4WMDgE50VE6B6ODXN5nsFGrKfqx4mRD3dic28j1rJ7JVkc8sz8/tI+Mr4onomLZftbAFa5dwdiXtqDbOJlxe4sd4oVDImpocAtk+aIqupqN+Sc0JxCGlNvo5eKdNBZP7u/9UC7eee7Y7lHYRmhzoC7FSzFL1/mGgVxrEljcp8UZ1OD47Aq0XYvJA+5MAElbgWrK+M+EMwOGA85qQES5xtvfyVlnNvked6GQlfEuckM6H5bQCIdGkeuJ/+eWWW0rXNVkYHwA4EdiIaAXya4pO439kZfip/gWFF4mazHKCYOQAKndusFSOvxyWOTY/EbSrI7BYoYwm1WR75q7OozJTYP0V3UO+lQ+0/RgSh2uEqyfqB+EMZlATWBl3QnjxKHm7R0dVPnk9qpsjlVXGgGCCWn1UVHKq8w==\n"]
cv.So(ok, cv.ShouldBeTrue)
// second time we connect based on that server key
dc.TofuAddIfNotKnown = false
channelToTcpServer, _, _, err = dc.Dial(ctx, nil, false)
cv.So(err, cv.ShouldBeNil)
VerifyClientServerExchangeAcrossSshd(channelToTcpServer, confirmationPayload, confirmationReply, payloadByteCount)
channelToTcpServer.Close()
// tcp-server should have exited because it got the expected
// message and replied with the agreed upon reply and then exited.
serverDone.RequestStop()
<-serverDone.DoneChan()
// done with testing, cleanup
s.SrvCfg.Esshd.Stop()
<-s.SrvCfg.Esshd.Halt.DoneChan()
cv.So(true, cv.ShouldEqual, true) // we should get here.
})
}
func (s *TestSetup) forTestingUpdateServerHostKey(path string) (sbPubKey string) {
bPubKey, err := s.SrvCfg.HostDb.adoptNewHostKeyFromPath(path)
panicOn(err)
sbPubKey = string(ssh.MarshalAuthorizedKey(bPubKey))
fmt.Printf("\n we had the server adopt public key '%s'\n", sbPubKey)
// also have to update the Esshd auth state on the update channel:
s.SrvCfg.Esshd.updateHostKey <- s.SrvCfg.HostDb.HostSshSigner
return
}
func Test303DedupKnownHosts(t *testing.T) {
cv.Convey("known hosts should be deduplicated and not add to the known hosts file every time the same server as before is contacted", t, func() {
payloadByteCount := 50
confirmationPayload := RandomString(payloadByteCount)
confirmationReply := RandomString(payloadByteCount)
serverDone := ssh.NewHalter()
tcpSrvLsn, tcpSrvPort := GetAvailPort()
StartBackgroundTestTcpServer(
serverDone,
payloadByteCount,
confirmationPayload,
confirmationReply,
tcpSrvLsn, nil)
s := MakeTestSshClientAndServer(true)
defer TempDirCleanup(s.SrvCfg.Origdir, s.SrvCfg.Tempdir)
fmt.Printf("\n tell the server to represent itself as B so we can add its key\n")
s.forTestingUpdateServerHostKey(s.SrvCfg.Tempdir + "/testdata/id_rsa_b")
dest := fmt.Sprintf("127.0.0.1:%v", tcpSrvPort)
pp("just prior to manual NewKnownHosts call")
cliKnownHosts, err := NewKnownHosts(s.CliCfg.ClientKnownHostsPath, KHSsh)
panicOn(err)
p("cliKnownHosts.Hosts=(len %v) '%#v'", len(cliKnownHosts.Hosts), cliKnownHosts.Hosts)
cv.So(len(cliKnownHosts.Hosts), cv.ShouldEqual, 3)
// verify that read of known hosts lacks B
_, ok := cliKnownHosts.Hosts["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC9hxNTsXHBIuWdc0SZAwN6Bytwr5vCB2K7rf5yVoC5YX5Hb08c25Xd5sGhehAj8RXooNxCa62mDnk/ACcByDa35gv3HyDqm1kmFLNvM/OcNNmK2FCuIdwKG7QWjmZwIwS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utz6TW43L1fJl2Ucwmvb8SvByoLZdbphnUhHxhkJ++UaDBRUpqptT2V+tyjP0mCo6GddJbFPiK6nE2DhWqrVhzo3BkkyPeA0L+VTQnF7dTmgInAjat+eU9IooYUFofkrTq+15iJxW7mNY2wp2sUCi94zCzHi9KvkMHv9tVqOU24dJCfUzXEqdYDmTt04DUtDqYB9w3THQFz6a3bdKcB1zbWXH36/6yhdocfu+lPmb9nMbpLChXMRuaSjBSRbpzcVnKxXoTFrCjw==\n"]
cv.So(ok, cv.ShouldBeTrue)
// below over SSH should be equivalent of the following
// non-encrypted ping/pong.
dc := DialConfig{
ClientKnownHostsPath: s.CliCfg.ClientKnownHostsPath,
KnownHosts: cliKnownHosts,
Mylogin: s.Mylogin,
RsaPath: s.RsaPath,
TotpUrl: s.Totp,
Pw: s.Pw,
Sshdhost: s.SrvCfg.EmbeddedSSHd.Host,
Sshdport: s.SrvCfg.EmbeddedSSHd.Port,
DownstreamHostPort: dest,
TofuAddIfNotKnown: true,
}
ctx := context.Background()
// first time we add the server key
channelToTcpServer, _, _, err := dc.Dial(ctx, nil, false)
cv.So(err.Error(), cv.ShouldContainSubstring, "Re-run without -new")
fmt.Printf("\n now host key B should be known.\n")
cv.So(len(cliKnownHosts.Hosts), cv.ShouldEqual, 4)
// verify that hostkey for B is now present
_, ok = cliKnownHosts.Hosts["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC9hxNTsXHBIuWdc0SZAwN6Bytwr5vCB2K7rf5yVoC5YX5Hb08c25Xd5sGhehAj8RXooNxCa62mDnk/ACcByDa35gv3HyDqm1kmFLNvM/OcNNmK2FCuIdwKG7QWjmZwIwS3eCudJjDGR3qUTUzZbLpV80eZ0WxYE/CbZdb9gx6lNSAWx+ZaeGTt9M0sD5AfEHSxg2lJFaA5pa0Zaaq4QoultLtfisEnTHKCprjRc9RHuZ0l4kwi2eLtBdMmvR3Guk+wrd/qy6+S2zqn4WMDgE50VE6B6ODXN5nsFGrKfqx4mRD3dic28j1rJ7JVkc8sz8/tI+Mr4onomLZftbAFa5dwdiXtqDbOJlxe4sd4oVDImpocAtk+aIqupqN+Sc0JxCGlNvo5eKdNBZP7u/9UC7eee7Y7lHYRmhzoC7FSzFL1/mGgVxrEljcp8UZ1OD47Aq0XYvJA+5MAElbgWrK+M+EMwOGA85qQES5xtvfyVlnNvked6GQlfEuckM6H5bQCIdGkeuJ/+eWWW0rXNVkYHwA4EdiIaAXya4pO439kZfip/gWFF4mazHKCYOQAKndusFSOvxyWOTY/EbSrI7BYoYwm1WR75q7OozJTYP0V3UO+lQ+0/RgSh2uEqyfqB+EMZlATWBl3QnjxKHm7R0dVPnk9qpsjlVXGgGCCWn1UVHKq8w==\n"]
cv.So(ok, cv.ShouldBeTrue)
// second time we connect based on that server key
dc.TofuAddIfNotKnown = false
channelToTcpServer, _, _, err = dc.Dial(ctx, nil, false)
cv.So(err, cv.ShouldBeNil)
VerifyClientServerExchangeAcrossSshd(channelToTcpServer, confirmationPayload, confirmationReply, payloadByteCount)
channelToTcpServer.Close()
// tcp-server should have exited because it got the expected
// message and replied with the agreed upon reply and then exited.
serverDone.RequestStop()
<-serverDone.DoneChan()
// now, the point of 303: connecting to a *2nd* sshd server with
// a different IP address but the same server key should
// result in de-duplication.
serverDone = ssh.NewHalter()
tcpSrvLsn, tcpSrvPort = GetAvailPort()
StartBackgroundTestTcpServer(
serverDone,
payloadByteCount,
confirmationPayload,
confirmationReply,
tcpSrvLsn, nil)
// prior to contacting the 2nd B server, we should have
// only one SplitHostname
entry, ok := cliKnownHosts.Hosts["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC9hxNTsXHBIuWdc0SZAwN6Bytwr5vCB2K7rf5yVoC5YX5Hb08c25Xd5sGhehAj8RXooNxCa62mDnk/ACcByDa35gv3HyDqm1kmFLNvM/OcNNmK2FCuIdwKG7QWjmZwIwS3eCudJjDGR3qUTUzZbLpV80eZ0WxYE/CbZdb9gx6lNSAWx+ZaeGTt9M0sD5AfEHSxg2lJFaA5pa0Zaaq4QoultLtfisEnTHKCprjRc9RHuZ0l4kwi2eLtBdMmvR3Guk+wrd/qy6+S2zqn4WMDgE50VE6B6ODXN5nsFGrKfqx4mRD3dic28j1rJ7JVkc8sz8/tI+Mr4onomLZftbAFa5dwdiXtqDbOJlxe4sd4oVDImpocAtk+aIqupqN+Sc0JxCGlNvo5eKdNBZP7u/9UC7eee7Y7lHYRmhzoC7FSzFL1/mGgVxrEljcp8UZ1OD47Aq0XYvJA+5MAElbgWrK+M+EMwOGA85qQES5xtvfyVlnNvked6GQlfEuckM6H5bQCIdGkeuJ/+eWWW0rXNVkYHwA4EdiIaAXya4pO439kZfip/gWFF4mazHKCYOQAKndusFSOvxyWOTY/EbSrI7BYoYwm1WR75q7OozJTYP0V3UO+lQ+0/RgSh2uEqyfqB+EMZlATWBl3QnjxKHm7R0dVPnk9qpsjlVXGgGCCWn1UVHKq8w==\n"]
cv.So(ok, cv.ShouldBeTrue)
cv.So(len(entry.SplitHostnames), cv.ShouldEqual, 1)
// s2 server will be on a new port, so that is enough to
// check that dedup happened.
s2 := MakeTestSshClientAndServer(true)
defer TempDirCleanup(s2.SrvCfg.Origdir, s2.SrvCfg.Tempdir)
fmt.Printf("\n tell the server to represent itself as B so we can add its key\n")
s2.forTestingUpdateServerHostKey(s2.SrvCfg.Tempdir + "/testdata/id_rsa_b")
cv.So(len(cliKnownHosts.Hosts), cv.ShouldEqual, 4)
dc2 := DialConfig{
ClientKnownHostsPath: s2.CliCfg.ClientKnownHostsPath,
KnownHosts: cliKnownHosts,
Mylogin: s2.Mylogin,
RsaPath: s2.RsaPath,
TotpUrl: s2.Totp,
Pw: s2.Pw,
Sshdhost: s2.SrvCfg.EmbeddedSSHd.Host,
Sshdport: s2.SrvCfg.EmbeddedSSHd.Port,
DownstreamHostPort: dest,
TofuAddIfNotKnown: true,
}
// first time we add the server key
channelToTcpServer, _, _, err = dc2.Dial(ctx, nil, false)
pp("dc2.Dial() -> err = %#v", err)
cv.So(err.Error(), cv.ShouldContainSubstring, "Re-run without -new")
fmt.Printf("\n now host key B under a different port should be known and dedupped \n")
cv.So(len(cliKnownHosts.Hosts), cv.ShouldEqual, 4)
// verify that hostkey for B now has two SplitHostnames
entry, ok = cliKnownHosts.Hosts["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC9hxNTsXHBIuWdc0SZAwN6Bytwr5vCB2K7rf5yVoC5YX5Hb08c25Xd5sGhehAj8RXooNxCa62mDnk/ACcByDa35gv3HyDqm1kmFLNvM/OcNNmK2FCuIdwKG7QWjmZwIwS3eCudJjDGR3qUTUzZbLpV80eZ0WxYE/CbZdb9gx6lNSAWx+ZaeGTt9M0sD5AfEHSxg2lJFaA5pa0Zaaq4QoultLtfisEnTHKCprjRc9RHuZ0l4kwi2eLtBdMmvR3Guk+wrd/qy6+S2zqn4WMDgE50VE6B6ODXN5nsFGrKfqx4mRD3dic28j1rJ7JVkc8sz8/tI+Mr4onomLZftbAFa5dwdiXtqDbOJlxe4sd4oVDImpocAtk+aIqupqN+Sc0JxCGlNvo5eKdNBZP7u/9UC7eee7Y7lHYRmhzoC7FSzFL1/mGgVxrEljcp8UZ1OD47Aq0XYvJA+5MAElbgWrK+M+EMwOGA85qQES5xtvfyVlnNvked6GQlfEuckM6H5bQCIdGkeuJ/+eWWW0rXNVkYHwA4EdiIaAXya4pO439kZfip/gWFF4mazHKCYOQAKndusFSOvxyWOTY/EbSrI7BYoYwm1WR75q7OozJTYP0V3UO+lQ+0/RgSh2uEqyfqB+EMZlATWBl3QnjxKHm7R0dVPnk9qpsjlVXGgGCCWn1UVHKq8w==\n"]
cv.So(ok, cv.ShouldBeTrue)
cv.So(len(entry.SplitHostnames), cv.ShouldEqual, 2)
for k := range entry.SplitHostnames {
fmt.Printf("entry.SplitHostnames['%v'] is present\n", k)
}
// done with testing, cleanup
s.SrvCfg.Esshd.Stop()
<-s.SrvCfg.Esshd.Halt.DoneChan()
cv.So(true, cv.ShouldEqual, true) // we should get here.
})
}