|
@@ -27,13 +27,18 @@ var (
|
|
FRPTLSHeadByte = 0x17
|
|
FRPTLSHeadByte = 0x17
|
|
)
|
|
)
|
|
|
|
|
|
-func WrapTLSClientConn(c net.Conn, tlsConfig *tls.Config) (out net.Conn) {
|
|
|
|
- c.Write([]byte{byte(FRPTLSHeadByte)})
|
|
|
|
|
|
+func WrapTLSClientConn(c net.Conn, tlsConfig *tls.Config, disableCustomTLSHeadByte bool) (out net.Conn) {
|
|
|
|
+ if !disableCustomTLSHeadByte {
|
|
|
|
+ c.Write([]byte{byte(FRPTLSHeadByte)})
|
|
|
|
+ }
|
|
out = tls.Client(c, tlsConfig)
|
|
out = tls.Client(c, tlsConfig)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-func CheckAndEnableTLSServerConnWithTimeout(c net.Conn, tlsConfig *tls.Config, tlsOnly bool, timeout time.Duration) (out net.Conn, err error) {
|
|
|
|
|
|
+func CheckAndEnableTLSServerConnWithTimeout(
|
|
|
|
+ c net.Conn, tlsConfig *tls.Config, tlsOnly bool, timeout time.Duration,
|
|
|
|
+) (out net.Conn, isTLS bool, custom bool, err error) {
|
|
|
|
+
|
|
sc, r := gnet.NewSharedConnSize(c, 2)
|
|
sc, r := gnet.NewSharedConnSize(c, 2)
|
|
buf := make([]byte, 1)
|
|
buf := make([]byte, 1)
|
|
var n int
|
|
var n int
|
|
@@ -46,6 +51,11 @@ func CheckAndEnableTLSServerConnWithTimeout(c net.Conn, tlsConfig *tls.Config, t
|
|
|
|
|
|
if n == 1 && int(buf[0]) == FRPTLSHeadByte {
|
|
if n == 1 && int(buf[0]) == FRPTLSHeadByte {
|
|
out = tls.Server(c, tlsConfig)
|
|
out = tls.Server(c, tlsConfig)
|
|
|
|
+ isTLS = true
|
|
|
|
+ custom = true
|
|
|
|
+ } else if n == 1 && int(buf[0]) == 0x16 {
|
|
|
|
+ out = tls.Server(sc, tlsConfig)
|
|
|
|
+ isTLS = true
|
|
} else {
|
|
} else {
|
|
if tlsOnly {
|
|
if tlsOnly {
|
|
err = fmt.Errorf("non-TLS connection received on a TlsOnly server")
|
|
err = fmt.Errorf("non-TLS connection received on a TlsOnly server")
|