forked from glycerine/grpc-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh.go
81 lines (68 loc) · 2.71 KB
/
ssh.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
package ssh
// code from github.com/devops-filetransfer/sshego is
// used under the following MIT license.
/*
The MIT License (MIT)
Portions Copyright (c) 2016 Jason E. Aten, Ph.D.
Portions Copyright (c) 2015 Rackspace, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import (
"context"
"net"
"time"
tun "github.com/devops-filetransfer/sshego"
)
/*
localhost-to-localhost on my laptop, over SSH with strong crypto:
min and max observed:
elap time to send 512 MB was 13.484078385s => 37.971 MB/sec
elap time to send 512 MB was 10.078974477s => 50.799 MB/sec
*/
func ClientSshMain(trustNewServer, testAllowOneshotConnect bool, rsaPrivateKeyPath, knownHostsPath, username, host, destHostPort string, serverExternalPort int64) (func(string, time.Duration) (net.Conn, error), error) {
dc := tun.DialConfig{
ClientKnownHostsPath: knownHostsPath,
Mylogin: username,
RsaPath: rsaPrivateKeyPath,
TotpUrl: "",
Pw: "",
Sshdhost: host,
Sshdport: serverExternalPort,
DownstreamHostPort: destHostPort,
Verbose: false,
TofuAddIfNotKnown: trustNewServer,
TestAllowOneshotConnect: testAllowOneshotConnect,
}
f := func(addr string, dur time.Duration) (net.Conn, error) {
ctx := context.Background()
channelToTcpServer, _, _, err := dc.Dial(ctx, nil, false)
/*
if strings.HasPrefix(err.Error(), "good: added "+
"previously unknown sshd host") ||
strings.Contains(err.Error(), "Re-run without -new") {
// for prevention of MITM, enforce that
// client to not do TOFU every time.
if trustNewServer {
dc.TofuAddIfNotKnown = false
channelToTcpServer, _, err = dc.Dial()
}
}
*/
return channelToTcpServer, err
}
return f, nil
}