-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tls padding, doh fragmentation, hosts feature
- Loading branch information
uoosef
committed
Aug 15, 2023
1 parent
0b427e8
commit ff5b713
Showing
13 changed files
with
465 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dialer | ||
|
||
import ( | ||
"bepass/logger" | ||
"net" | ||
) | ||
|
||
type PlainTCPDial func(network, addr, hostPort string) (net.Conn, error) | ||
|
||
type Dialer struct { | ||
Logger *logger.Std | ||
EnableLowLevelSockets bool | ||
TLSPaddingEnabled bool | ||
TLSPaddingSize [2]int | ||
ProxyAddress string | ||
} |
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,29 @@ | ||
package dialer | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"net/http" | ||
"net/url" | ||
) | ||
|
||
func (d *Dialer) MakeHTTPClient(hostPort string, enableProxy bool) *http.Client { | ||
transport := &http.Transport{ | ||
ForceAttemptHTTP2: false, | ||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { | ||
return d.TCPDial(network, addr, hostPort) | ||
}, | ||
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) { | ||
return d.TLSDial(func(network, addr, hostPort string) (net.Conn, error) { | ||
return d.TCPDial(network, addr, hostPort) | ||
}, network, addr, hostPort) | ||
}, | ||
} | ||
if enableProxy { | ||
proxyUrl, _ := url.Parse(d.ProxyAddress) | ||
|
||
// Create dialer | ||
transport.Proxy = http.ProxyURL(proxyUrl) | ||
} | ||
return &http.Client{Transport: transport} | ||
} |
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,38 @@ | ||
package dialer | ||
|
||
import ( | ||
"bepass/protect" | ||
"net" | ||
"runtime" | ||
"strconv" | ||
) | ||
|
||
// TCPDial connects to the destination address. | ||
func (d *Dialer) TCPDial(network, addr, hostPort string) (*net.TCPConn, error) { | ||
var ( | ||
tcpAddr *net.TCPAddr | ||
err error | ||
) | ||
if hostPort != "" { | ||
tcpAddr, err = net.ResolveTCPAddr(network, hostPort) | ||
} else { | ||
tcpAddr, err = net.ResolveTCPAddr(network, addr) | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
if d.EnableLowLevelSockets && (runtime.GOOS == "android" || runtime.GOOS == "linux") { | ||
dialer := protect.NewClientDialer() | ||
conn, err := dialer.Dial("tcp", net.JoinHostPort(tcpAddr.IP.String(), strconv.Itoa(tcpAddr.Port))) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return conn.(*net.TCPConn), nil | ||
} | ||
conn, err := net.DialTCP("tcp", nil, tcpAddr) | ||
if err != nil { | ||
d.Logger.Errorf("failed to connect to %v: %v", tcpAddr, err) | ||
return nil, err | ||
} | ||
return conn, nil | ||
} |
Oops, something went wrong.