Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding custom SNI name #35

Merged
merged 2 commits into from May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions fastdialer/context.go
@@ -0,0 +1,8 @@
package fastdialer

type ContextOption string

const (
// SniName to use in tls connection
SniName ContextOption = "sni-name"
)
18 changes: 15 additions & 3 deletions fastdialer/dialer.go
Expand Up @@ -202,13 +202,25 @@ func (d *Dialer) dial(ctx context.Context, network, address string, shouldUseTLS
hostPort := net.JoinHostPort(ip, port)
if shouldUseTLS {
tlsconfigCopy := tlsconfig.Clone()
if !iputil.IsIP(hostname) {
switch {
case d.options.SNIName != "":
tlsconfigCopy.ServerName = d.options.SNIName
case ctx.Value(SniName) != nil:
sniName := ctx.Value(SniName).(string)
tlsconfigCopy.ServerName = sniName
case !iputil.IsIP(hostname):
tlsconfigCopy.ServerName = hostname
}
conn, err = tls.DialWithDialer(d.dialer, network, hostPort, tlsconfig)
conn, err = tls.DialWithDialer(d.dialer, network, hostPort, tlsconfigCopy)
} else if shouldUseZTLS {
ztlsconfigCopy := ztlsconfig.Clone()
if !iputil.IsIP(hostname) {
switch {
case d.options.SNIName != "":
ztlsconfigCopy.ServerName = d.options.SNIName
case ctx.Value(SniName) != nil:
sniName := ctx.Value(SniName).(string)
ztlsconfigCopy.ServerName = sniName
case !iputil.IsIP(hostname):
ztlsconfigCopy.ServerName = hostname
}
conn, err = ztls.DialWithDialer(d.dialer, network, hostPort, ztlsconfigCopy)
Expand Down
1 change: 1 addition & 0 deletions fastdialer/options.go
Expand Up @@ -46,6 +46,7 @@ type Options struct {
DialerKeepAlive time.Duration
Dialer *net.Dialer
WithZTLS bool
SNIName string
}

// DefaultOptions of the cache
Expand Down