-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance: Add ssh transport & dialer (#8)
Support ssh transport & enhance dialer
- Loading branch information
Showing
34 changed files
with
928 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package connection | ||
|
||
import ( | ||
"net" | ||
"time" | ||
|
||
"golang.org/x/crypto/ssh" | ||
) | ||
|
||
var _ net.Conn = (*SshConn)(nil) | ||
|
||
type SshConn struct { | ||
ssh.Channel | ||
laddr net.Addr | ||
raddr net.Addr | ||
} | ||
|
||
func NewSshConn(channel ssh.Channel, laddr, raddr net.Addr) *SshConn { | ||
return &SshConn{ | ||
Channel: channel, | ||
laddr: laddr, | ||
raddr: raddr, | ||
} | ||
} | ||
|
||
func (c *SshConn) LocalAddr() net.Addr { return c.laddr } | ||
|
||
func (c *SshConn) RemoteAddr() net.Addr { return c.raddr } | ||
|
||
func (c *SshConn) SetReadDeadline(time.Time) error { return nil } | ||
|
||
func (c *SshConn) SetWriteDeadline(time.Time) error { return nil } | ||
|
||
func (c *SshConn) SetDeadline(t time.Time) error { | ||
if err := c.SetReadDeadline(t); err != nil { | ||
return err | ||
} | ||
return c.SetWriteDeadline(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
server: | ||
- name: ss | ||
addr: 127.0.0.1:8388 | ||
password: "12345" | ||
# method: chacha20-ietf-poly1305 | ||
method: none | ||
transport: ssh | ||
ssh: | ||
user: root | ||
# password: root | ||
private_key: ssh-keys/test-key | ||
public_key: ssh-keys/test-key.pub | ||
|
||
local: | ||
socks_addr: 127.0.0.1:10086 | ||
http_addr: 127.0.0.1:10087 | ||
mixed_addr: 127.0.0.1:10088 | ||
log: | ||
color: true | ||
log_level: trace | ||
verbose_level: 2 | ||
iface: en5 | ||
auto_detect_iface: true | ||
rules: | ||
mode: global | ||
global_to: 'ss' | ||
direct_to: '' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
server: | ||
- name: ss | ||
addr: ':8388' | ||
password: "12345" | ||
# method: chacha20-ietf-poly1305 | ||
method: none | ||
transport: ssh | ||
ssh: | ||
user: root | ||
# password: root | ||
private_key: ssh-keys/pri.key | ||
authorized_key: ssh-keys/authorized_keys | ||
log: | ||
color: true | ||
log_level: debug | ||
verbose_level: 3 | ||
|
||
# iface: en5 | ||
# auto_detect_iface: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/josexy/mini-ss/options" | ||
"github.com/josexy/mini-ss/transport" | ||
) | ||
|
||
func main() { | ||
dialer := transport.NewDialer(transport.Ssh, &options.SshOptions{ | ||
User: "test", | ||
Password: "test", | ||
PrivateKey: "ssh-keys/test-key", | ||
PublicKey: "ssh-keys/test-key.pub", | ||
}) | ||
|
||
request := func() { | ||
time.Sleep(time.Millisecond * 20) | ||
conn, err := dialer.Dial(context.Background(), "127.0.0.1:10086") | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
defer conn.Close() | ||
go func() { | ||
conn.Write([]byte("GET / HTTP/1.1\r\n\r\n\r\n")) | ||
}() | ||
buf := &bytes.Buffer{} | ||
buf.ReadFrom(conn) | ||
log.Println(buf.Len()) | ||
} | ||
|
||
for i := 0; i < 10; i++ { | ||
go request() | ||
time.Sleep(time.Millisecond * 20) | ||
} | ||
|
||
interrupt := make(chan os.Signal, 1) | ||
signal.Notify(interrupt, syscall.SIGINT) | ||
<-interrupt | ||
time.Sleep(time.Millisecond * 200) | ||
} |
Oops, something went wrong.