Skip to content

Commit

Permalink
Merge pull request #35 from projectdiscovery/feat-custom-sni-name
Browse files Browse the repository at this point in the history
Adding custom SNI name
  • Loading branch information
ehsandeep committed May 12, 2022
2 parents ad0387f + 0e57a7c commit 5f45575
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
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

0 comments on commit 5f45575

Please sign in to comment.