ssr: check obfs and protocol type

This commit is contained in:
nadoo 2018-05-22 12:19:57 +08:00
parent a25cc5cfe3
commit dcd02cebd9
7 changed files with 22 additions and 11 deletions

View File

@ -91,7 +91,7 @@ glider -config CONFIGPATH -listen :8080 -verbose
## Usage
```bash
glider v0.5.3 usage:
glider v0.5.2 usage:
-checkduration int
proxy check duration(seconds) (default 30)
-checkwebsite string
@ -175,7 +175,7 @@ Examples:
glider -listen redir://:1081 -forward ss://method:pass@1.1.1.1:8443
-listen on :1081 as a transparent redirect server, forward all requests via remote ss server.
glider -listen redir://:1081 -forward ssr://method:pass@1.1.1.1:8444?protocol=a&protocol_param=b&obfs=c&obfs_param=d
glider -listen redir://:1081 -forward "ssr://method:pass@1.1.1.1:8444?protocol=a&protocol_param=b&obfs=c&obfs_param=d"
-listen on :1081 as a transparent redirect server, forward all requests via remote ssr server.
glider -listen tcptun://:80=2.2.2.2:80 -forward ss://method:pass@1.1.1.1:8443

View File

@ -200,7 +200,7 @@ func usage() {
fmt.Fprintf(os.Stderr, " "+app+" -listen redir://:1081 -forward ss://method:pass@1.1.1.1:8443\n")
fmt.Fprintf(os.Stderr, " -listen on :1081 as a transparent redirect server, forward all requests via remote ss server.\n")
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, " "+app+" -listen redir://:1081 -forward ssr://method:pass@1.1.1.1:8444?protocol=a&protocol_param=b&obfs=c&obfs_param=d\n")
fmt.Fprintf(os.Stderr, " "+app+" -listen redir://:1081 -forward \"ssr://method:pass@1.1.1.1:8444?protocol=a&protocol_param=b&obfs=c&obfs_param=d\"\n")
fmt.Fprintf(os.Stderr, " -listen on :1081 as a transparent redirect server, forward all requests via remote ssr server.\n")
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, " "+app+" -listen tcptun://:80=2.2.2.2:80 -forward ss://method:pass@1.1.1.1:8443\n")

View File

@ -39,7 +39,7 @@ checkduration=30
# Setup a dns forwarding server
dns://53
dns=:53
# global remote dns server (you can specify different dns server in rule file)
dnsserver=8.8.8.8:53

12
http.go
View File

@ -118,7 +118,7 @@ func (s *HTTP) Serve(c net.Conn) {
url, err := url.ParseRequestURI(requestURI)
if err != nil {
logf("parse request url error: %s", err)
logf("proxy-http parse request url error: %s", err)
return
}
@ -150,9 +150,11 @@ func (s *HTTP) Serve(c net.Conn) {
// copy the left request bytes to remote server. eg. length specificed or chunked body.
go func() {
io.Copy(rc, reqR)
rc.SetDeadline(time.Now())
c.SetDeadline(time.Now())
if _, err := reqR.Peek(1); err == nil {
io.Copy(rc, reqR)
rc.SetDeadline(time.Now())
c.SetDeadline(time.Now())
}
}()
respR := bufio.NewReader(rc)
@ -197,7 +199,7 @@ func (s *HTTP) servHTTPS(method, requestURI, proto string, c net.Conn) {
c.Write([]byte("HTTP/1.0 200 Connection established\r\n\r\n"))
logf("proxy-http %s <-> %s [connect]", c.RemoteAddr(), requestURI)
logf("proxy-http %s <-> %s [c]", c.RemoteAddr(), requestURI)
_, _, err = relay(c, rc)
if err != nil {

View File

@ -9,7 +9,7 @@ import (
)
// VERSION .
const VERSION = "0.5.3"
const VERSION = "0.5.2"
func dialerFromConf() Dialer {
// global forwarders in xx.conf

2
ss.go
View File

@ -25,7 +25,7 @@ type SS struct {
func NewSS(addr, method, pass string, dialer Dialer) (*SS, error) {
ciph, err := core.PickCipher(method, nil, pass)
if err != nil {
log.Fatalf("PickCipher for '%s', error: %s", method, err)
log.Fatalf("proxy-ss PickCipher for '%s', error: %s", method, err)
}
s := &SS{

9
ssr.go
View File

@ -92,6 +92,10 @@ func (s *SSR) Dial(network, addr string) (net.Conn, error) {
port, _ := strconv.Atoi(rs[1])
ssrconn.IObfs = obfs.NewObfs(s.Obfs)
if ssrconn.IObfs == nil {
return nil, errors.New("proxy-ssr unsupported obfs type: " + s.Obfs)
}
obfsServerInfo := &ssr.ServerInfoForObfs{
Host: rs[0],
Port: uint16(port),
@ -99,7 +103,12 @@ func (s *SSR) Dial(network, addr string) (net.Conn, error) {
Param: s.ObfsParam,
}
ssrconn.IObfs.SetServerInfo(obfsServerInfo)
ssrconn.IProtocol = protocol.NewProtocol(s.Protocol)
if ssrconn.IProtocol == nil {
return nil, errors.New("proxy-ssr unsupported protocol type: " + s.Protocol)
}
protocolServerInfo := &ssr.ServerInfoForObfs{
Host: rs[0],
Port: uint16(port),