Skip to content

Commit

Permalink
Merge pull request #264 from projectdiscovery/maint-reducing-allocations
Browse files Browse the repository at this point in the history
TLS config custom clone
  • Loading branch information
Mzack9999 committed Mar 5, 2024
2 parents 3b0ce17 + d9dbdf8 commit bc3dccb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
29 changes: 22 additions & 7 deletions fastdialer/util.go
Expand Up @@ -3,21 +3,36 @@ package fastdialer
import (
"crypto/tls"

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

func AsTLSConfig(ztlsConfig *ztls.Config) (*tls.Config, error) {
tlsConfig := &tls.Config{}
err := deepcopier.Copy(ztlsConfig).To(tlsConfig)
return tlsConfig, err
tlsConfig := &tls.Config{
NextProtos: ztlsConfig.NextProtos,
ServerName: ztlsConfig.ServerName,
ClientAuth: tls.ClientAuthType(ztlsConfig.ClientAuth),
InsecureSkipVerify: ztlsConfig.InsecureSkipVerify,
CipherSuites: ztlsConfig.CipherSuites,
SessionTicketsDisabled: ztlsConfig.SessionTicketsDisabled,
MinVersion: ztlsConfig.MinVersion,
MaxVersion: ztlsConfig.MaxVersion,
}
return tlsConfig, nil
}

func AsZTLSConfig(tlsConfig *tls.Config) (*ztls.Config, error) {
ztlsConfig := &ztls.Config{}
err := deepcopier.Copy(tlsConfig).To(ztlsConfig)
return ztlsConfig, err
ztlsConfig := &ztls.Config{
NextProtos: tlsConfig.NextProtos,
ServerName: tlsConfig.ServerName,
ClientAuth: ztls.ClientAuthType(tlsConfig.ClientAuth),
InsecureSkipVerify: tlsConfig.InsecureSkipVerify,
CipherSuites: tlsConfig.CipherSuites,
SessionTicketsDisabled: tlsConfig.SessionTicketsDisabled,
MinVersion: tlsConfig.MinVersion,
MaxVersion: tlsConfig.MaxVersion,
}
return ztlsConfig, nil
}

func IsTLS13(config interface{}) bool {
Expand Down
1 change: 0 additions & 1 deletion go.mod
Expand Up @@ -13,7 +13,6 @@ require (
github.com/projectdiscovery/utils v0.0.82
github.com/refraction-networking/utls v1.5.4
github.com/stretchr/testify v1.8.4
github.com/ulule/deepcopier v0.0.0-20200430083143-45decc6639b6
github.com/zmap/zcrypto v0.0.0-20230422215203-9a665e1e9968
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db
golang.org/x/net v0.17.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Expand Up @@ -133,8 +133,6 @@ github.com/tidwall/rtred v0.1.2 h1:exmoQtOLvDoO8ud++6LwVsAMTu0KPzLTUrMln8u1yu8=
github.com/tidwall/rtred v0.1.2/go.mod h1:hd69WNXQ5RP9vHd7dqekAz+RIdtfBogmglkZSRxCHFQ=
github.com/tidwall/tinyqueue v0.1.1 h1:SpNEvEggbpyN5DIReaJ2/1ndroY8iyEGxPYxoSaymYE=
github.com/tidwall/tinyqueue v0.1.1/go.mod h1:O/QNHwrnjqr6IHItYrzoHAKYhBkLI67Q096fQP5zMYw=
github.com/ulule/deepcopier v0.0.0-20200430083143-45decc6639b6 h1:TtyC78WMafNW8QFfv3TeP3yWNDG+uxNkk9vOrnDu6JA=
github.com/ulule/deepcopier v0.0.0-20200430083143-45decc6639b6/go.mod h1:h8272+G2omSmi30fBXiZDMkmHuOgonplfKIKjQWzlfs=
github.com/weppos/publicsuffix-go v0.13.0/go.mod h1:z3LCPQ38eedDQSwmsSRW4Y7t2L8Ln16JPQ02lHAdn5k=
github.com/weppos/publicsuffix-go v0.30.1-0.20230422193905-8fecedd899db h1:/WcxBne+5CbtbgWd/sV2wbravmr4sT7y52ifQaCgoLs=
github.com/weppos/publicsuffix-go v0.30.1-0.20230422193905-8fecedd899db/go.mod h1:aiQaH1XpzIfgrJq3S1iw7w+3EDbRP7mF5fmwUhWyRUs=
Expand Down

0 comments on commit bc3dccb

Please sign in to comment.