diff --git a/README.md b/README.md index 212d2c1..8823d7a 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,8 @@ Evan 增强版特性 * HTTP CONNECT方法支持自定义Host(常用于免流混淆) - 例子: gost -L http://:8888 -F http://evan.run:80?host=cdn.dingding.com -F socks5://127.0.0.1:1080 * 修改默认User Agent为Google默认浏览器的UA,修改代理默认UA为nginx -* 兼容Android环境,针对Android环境下无法解析域名的问题(Android环境下默认使用114.114.114.114作为DNS,可使用启动参数-NS自定义) +* ~~兼容Android环境,针对Android环境下无法解析域名的问题(Android环境下默认使用114.114.114.114作为DNS,可使用启动参数-NS自定义)~~ + - Android使用NDK交叉编译可以解决DNS无法解析问题,默认114.114.114.114的配置已经移除,-NS参数保留,交叉编译参考buildAndroid.sh - 例子: gost -L http://:8888 -F http://evan.run:80 -NS 114.114.114.114:53/udp * 修复原版DNS解析的BUG * 修复原版websocket协议中path参数不解码后发送问题 diff --git a/buildAndroid.sh b/buildAndroid.sh new file mode 100644 index 0000000..924eb5a --- /dev/null +++ b/buildAndroid.sh @@ -0,0 +1,27 @@ +NDK_VERSION_IF_MISSING=r23b +mkdir -p ndk +cd ndk +curl https://dl.google.com/android/repository/android-ndk-${NDK_VERSION_IF_MISSING}-linux.zip -L -o ndk.zip +unzip ndk.zip > /dev/null || exit $? +rm -f ndk.zip +[ ! -d android-ndk-${NDK_VERSION_IF_MISSING} ] && echo "Missing directory: android-ndk-${NDK_VERSION_IF_MISSING}" && exit 1 +export ANDROID_NDK_ROOT=$PWD/android-ndk-${NDK_VERSION_IF_MISSING} +cd .. +fi +echo "ANDROID_NDK_ROOT=$ANDROID_NDK_ROOT" +cd gost +CC=$(find $ANDROID_NDK_ROOT | grep 'armv7a-linux-androideabi23-clang$') \ +GOOS="android" GOARCH="arm" CGO_ENABLED="1" \ +go build -buildvcs=false -ldflags "-s -w" -a -o gost_android_arm + +CC=$(find $ANDROID_NDK_ROOT | grep 'aarch64-linux-android23-clang$') \ +GOOS="android" GOARCH="arm64" CGO_ENABLED="1" \ +go build -buildvcs=false -ldflags "-s -w" -a -o gost_android_arm64 + +CC=$(find $ANDROID_NDK_ROOT | grep 'i686-linux-android23-clang$') \ +GOOS="android" GOARCH="386" CGO_ENABLED="1" \ +go build -buildvcs=false -ldflags "-s -w" -a -o gost_android_x86 + +CC=$(find $ANDROID_NDK_ROOT | grep 'x86_64-linux-android23-clang$') \ +GOOS="android" GOARCH="amd64" CGO_ENABLED="1" \ +go build -buildvcs=false -ldflags "-s -w" -a -o gost_android_x86_64 \ No newline at end of file diff --git a/cmd/gost/main.go b/cmd/gost/main.go index b81e740..eb06eda 100644 --- a/cmd/gost/main.go +++ b/cmd/gost/main.go @@ -1,13 +1,11 @@ package main import ( - "context" "crypto/tls" "encoding/base64" "errors" "flag" "fmt" - "net" "net/http" "net/url" "os" @@ -121,12 +119,6 @@ func main() { if baseCfg.ExternalResolver != "" { gost.DefaultExternalResolver = parseResolver(baseCfg.ExternalResolver) gost.DefaultExternalResolver.Init() - } else if os.Getenv("ANDROID_ROOT") != "" { - log.Logf("Android detected modify default DNS server to %v", gost.DefaultDNSServer) - net.DefaultResolver = &net.Resolver{Dial: func(ctx context.Context, network, address string) (net.Conn, error) { - d := net.Dialer{} - return d.DialContext(ctx, network, gost.DefaultDNSServer) - }, PreferGo: true} } if err := start(); err != nil { diff --git a/gost.go b/gost.go index d5f562a..fddf12a 100644 --- a/gost.go +++ b/gost.go @@ -20,7 +20,7 @@ import ( ) // Version is the gost version. -const Version = "2.11.2-EvanMod-v1.2.2" +const Version = "2.11.2-EvanMod-v1.2.3" const ProxyAgent = "nginx" // Debug is a flag that enables the debug log. diff --git a/log.go b/log.go index d4ad519..f84273b 100644 --- a/log.go +++ b/log.go @@ -3,10 +3,12 @@ package gost import ( "fmt" "log" + "os" ) func init() { log.SetFlags(log.LstdFlags | log.Lshortfile) + log.SetOutput(os.Stdout) } // LogLogger uses the standard log package as the logger diff --git a/strong_mod.sh b/strong_mod.sh index 34b9591..6d15722 100644 --- a/strong_mod.sh +++ b/strong_mod.sh @@ -1,2 +1,6 @@ sed -b -i s/\*gost./*evan./g $1 sed -b -i s/]gost./]evan./g $1 +sed -b -i s#ginuerzh/gost#evanevan/evan#g $1 +sed -b -i s#go-gost#ev-evan#g $1 +sed -b -i s#gost.#evan.#g $1 +sed -b -i s#cmd/gost#cmd/evan#g $1 \ No newline at end of file diff --git a/tls.go b/tls.go index 9c50a8b..37609a2 100644 --- a/tls.go +++ b/tls.go @@ -280,10 +280,23 @@ func wrapTLSClient(conn net.Conn, tlsConfig *tls.Config, timeout time.Duration, //tlsConn := tls.Client(conn, tlsConfig) var tlsConn *utls.UConn + + utlsConf := &utls.Config{InsecureSkipVerify: tlsConfig.InsecureSkipVerify, ServerName: tlsConfig.ServerName, ClientAuth: utls.ClientAuthType(tlsConfig.ClientAuth), ClientCAs: tlsConfig.ClientCAs, RootCAs: tlsConfig.RootCAs} + if len(tlsConfig.Certificates) > 0 { + for _, certificate := range tlsConfig.Certificates { + utlsConf.Certificates = append(utlsConf.Certificates, utls.Certificate{ + Certificate: certificate.Certificate, + PrivateKey: certificate.PrivateKey, + OCSPStaple: certificate.OCSPStaple, + SignedCertificateTimestamps: certificate.SignedCertificateTimestamps, + Leaf: certificate.Leaf, + }) + } + } if h2Alpn { - tlsConn = utls.UClient(conn, &utls.Config{InsecureSkipVerify: tlsConfig.InsecureSkipVerify, ServerName: tlsConfig.ServerName}, utls.HelloChrome_Auto) + tlsConn = utls.UClient(conn, utlsConf, utls.HelloChrome_Auto) } else { - tlsConn = utls.UClient(conn, &utls.Config{InsecureSkipVerify: tlsConfig.InsecureSkipVerify, ServerName: tlsConfig.ServerName}, utls.HelloCustom) + tlsConn = utls.UClient(conn, utlsConf, utls.HelloCustom) tlsConn.ApplyPreset(newWsSpec()) } diff --git a/ws.go b/ws.go index 66d7dc4..bbdad2c 100644 --- a/ws.go +++ b/ws.go @@ -837,7 +837,19 @@ func websocketClientConn(url string, conn net.Conn, tlsConfig *tls.Config, optio return conn, nil }, NetDialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) { - client := utls.UClient(conn, &utls.Config{InsecureSkipVerify: tlsConfig.InsecureSkipVerify, ServerName: tlsConfig.ServerName}, utls.HelloCustom) + utlsConf := &utls.Config{InsecureSkipVerify: tlsConfig.InsecureSkipVerify, ServerName: tlsConfig.ServerName, ClientAuth: utls.ClientAuthType(tlsConfig.ClientAuth), ClientCAs: tlsConfig.ClientCAs, RootCAs: tlsConfig.RootCAs} + if len(tlsConfig.Certificates) > 0 { + for _, certificate := range tlsConfig.Certificates { + utlsConf.Certificates = append(utlsConf.Certificates, utls.Certificate{ + Certificate: certificate.Certificate, + PrivateKey: certificate.PrivateKey, + OCSPStaple: certificate.OCSPStaple, + SignedCertificateTimestamps: certificate.SignedCertificateTimestamps, + Leaf: certificate.Leaf, + }) + } + } + client := utls.UClient(conn, utlsConf, utls.HelloCustom) client.ApplyPreset(newWsSpec()) err := client.Handshake() if err != nil {