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

Generalizing ascii conversion #37

Merged
merged 1 commit into from May 16, 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
14 changes: 7 additions & 7 deletions fastdialer/dialer.go
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/projectdiscovery/networkpolicy"
retryabledns "github.com/projectdiscovery/retryabledns"
ztls "github.com/zmap/zcrypto/tls"
"golang.org/x/net/idna"
)

// Dialer structure containing data information
Expand Down Expand Up @@ -171,6 +170,7 @@ func (d *Dialer) dial(ctx context.Context, network, address string, shouldUseTLS
}

// check if data is in cache
hostname = asAscii(hostname)
data, err := d.GetDNSData(hostname)
if err != nil {
// otherwise attempt to retrieve it
Expand Down Expand Up @@ -282,6 +282,7 @@ func (d *Dialer) GetDialedIP(hostname string) string {
if !d.options.WithDialerHistory || d.dialerHistory == nil {
return ""
}
hostname = asAscii(hostname)
v, ok := d.dialerHistory.Get(hostname)
if ok {
return string(v)
Expand All @@ -292,6 +293,7 @@ func (d *Dialer) GetDialedIP(hostname string) string {

// GetTLSData returns the tls data for a hostname
func (d *Dialer) GetTLSData(hostname string) (*cryptoutil.TLSData, error) {
hostname = asAscii(hostname)
if !d.options.WithTLSData {
return nil, NoTLSHistoryError
}
Expand All @@ -311,6 +313,7 @@ func (d *Dialer) GetTLSData(hostname string) (*cryptoutil.TLSData, error) {

// GetDNSDataFromCache cached by the resolver
func (d *Dialer) GetDNSDataFromCache(hostname string) (*retryabledns.DNSData, error) {
hostname = asAscii(hostname)
var data retryabledns.DNSData
dataBytes, ok := d.hm.Get(hostname)
if !ok {
Expand All @@ -323,6 +326,7 @@ func (d *Dialer) GetDNSDataFromCache(hostname string) (*retryabledns.DNSData, er

// GetDNSData for the given hostname
func (d *Dialer) GetDNSData(hostname string) (*retryabledns.DNSData, error) {
hostname = asAscii(hostname)
// support http://[::1] http://[::1]:8080
// https://datatracker.ietf.org/doc/html/rfc2732
// It defines a syntax
Expand Down Expand Up @@ -350,13 +354,9 @@ func (d *Dialer) GetDNSData(hostname string) (*retryabledns.DNSData, error) {
)
data, err = d.GetDNSDataFromCache(hostname)
if err != nil {
hostnameAscii, err := idna.ToASCII(hostname)
if err != nil {
return nil, AsciiConversionError
}
data, err = d.dnsclient.Resolve(hostnameAscii)
data, err = d.dnsclient.Resolve(hostname)
if err != nil && d.options.EnableFallback {
data, err = d.dnsclient.ResolveWithSyscall(hostnameAscii)
data, err = d.dnsclient.ResolveWithSyscall(hostname)
}
if err != nil {
return nil, err
Expand Down
6 changes: 6 additions & 0 deletions fastdialer/util.go
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ulule/deepcopier"
ztls "github.com/zmap/zcrypto/tls"
"golang.org/x/net/idna"
)

func AsTLSConfig(ztlsConfig *ztls.Config) (*tls.Config, error) {
Expand All @@ -29,3 +30,8 @@ func IsTLS13(config interface{}) bool {

return false
}

func asAscii(hostname string) string {
hostnameAscii, _ := idna.ToASCII(hostname)
return hostnameAscii
}