From f0c9079f0a1e2b9f1af3d43f43f7cec8cea2ed2d Mon Sep 17 00:00:00 2001 From: hwchan Date: Sat, 11 Apr 2020 23:07:36 +0800 Subject: [PATCH] sni: work with non-ssl --- go.mod | 1 + go.sum | 2 ++ sni.go | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/go.mod b/go.mod index 266940e..9b29236 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( git.torproject.org/pluggable-transports/obfs4.git v0.0.0-20181103133120-08f4d470188e github.com/LiamHaworth/go-tproxy v0.0.0-20190726054950-ef7efd7f24ed github.com/Yawning/chacha20 v0.0.0-20170904085104-e3b1f968fc63 // indirect + github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 github.com/bifurcation/mint v0.0.0-20181105071958-a14404e9a861 // indirect github.com/cheekybits/genny v1.0.0 // indirect github.com/coreos/go-iptables v0.4.5 // indirect diff --git a/go.sum b/go.sum index 03be3a4..fe77da3 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmH github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA= github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI= github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0= +github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 h1:zV3ejI06GQ59hwDQAvmK1qxOQGB3WuVTRoY0okPTAv0= +github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg= github.com/bifurcation/mint v0.0.0-20181105071958-a14404e9a861 h1:x17NvoJaphEzay72TFej4OSSsgu3xRYBLkbIwdofS/4= github.com/bifurcation/mint v0.0.0-20181105071958-a14404e9a861/go.mod h1:zVt7zX3K/aDCk9Tj+VM7YymsX66ERvzCJzw8rFCX2JU= github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE= diff --git a/sni.go b/sni.go index 62e5fb7..e57d4a0 100644 --- a/sni.go +++ b/sni.go @@ -17,6 +17,7 @@ import ( "strings" "sync" + "github.com/asaskevich/govalidator" dissector "github.com/ginuerzh/tls-dissector" "github.com/go-log/log" ) @@ -86,6 +87,10 @@ func (h *sniHandler) Handle(conn net.Conn) { return } + if !req.URL.IsAbs() && govalidator.IsDNSName(req.Host) { + req.URL.Scheme = "http" + } + handler := &httpHandler{options: h.options} handler.Init() handler.handleRequest(conn, req)