diff --git a/cmd/tlsx/main.go b/cmd/tlsx/main.go index 9144b55e..29153cc3 100644 --- a/cmd/tlsx/main.go +++ b/cmd/tlsx/main.go @@ -9,7 +9,8 @@ import ( "github.com/projectdiscovery/tlsx/internal/runner" "github.com/projectdiscovery/tlsx/pkg/tlsx/clients" "github.com/projectdiscovery/tlsx/pkg/tlsx/openssl" - errorutils "github.com/projectdiscovery/utils/errors" + "github.com/projectdiscovery/utils/errkit" + errorutils "github.com/projectdiscovery/utils/errors" //nolint fileutil "github.com/projectdiscovery/utils/file" ) @@ -26,20 +27,20 @@ func main() { func process() error { if err := readFlags(); err != nil { - return errorutils.NewWithErr(err).Msgf("could not read flags") + return errkit.Wrapf(err, "could not read flags") } runner, err := runner.New(options) if err != nil { - return errorutils.NewWithErr(err).Msgf("could not create runner") + return errkit.Wrapf(err, "could not create runner") } if runner == nil { return nil } if err := runner.Execute(); err != nil { - return errorutils.NewWithErr(err).Msgf("could not execute runner") + return errkit.Wrapf(err, "could not execute runner") } if err := runner.Close(); err != nil { - return errorutils.NewWithErr(err).Msgf("could not close runner") + return errkit.Wrapf(err, "could not close runner") } return nil } @@ -154,13 +155,13 @@ func readFlags(args ...string) error { err := flagSet.Parse(args...) if err != nil { - return errorutils.NewWithErr(err).Msgf("could not parse flags") + return errkit.Wrapf(err, "could not parse flags") } hasStdin := fileutil.HasStdin() // Validation: CT logs mode and input mode cannot be used together if options.CTLogs && (len(options.Inputs) > 0 || options.InputList != "" || hasStdin) { - return errorutils.NewWithTag("flags", "CT logs mode (-ctl) and input mode (-u/-l/stdin) cannot be used together.") + return errorutils.NewWithTag("flags", "CT logs mode (-ctl) and input mode (-u/-l/stdin) cannot be used together.") //nolint } // Enable CT logs mode by default if no input is provided @@ -180,7 +181,7 @@ func readFlags(args ...string) error { if cfgFile != "" { if err := flagSet.MergeConfigFile(cfgFile); err != nil { - return errorutils.NewWithErr(err).Msgf("could not read config file") + return errkit.Wrapf(err, "could not read config file") } } return nil @@ -190,6 +191,6 @@ func init() { // Feature: Debug Mode // Errors will include stacktrace when debug mode is enabled if os.Getenv("DEBUG") != "" { - errorutils.ShowStackTrace = true + errkit.EnableTrace = true } } diff --git a/go.mod b/go.mod index 76c5218e..8382ba9f 100644 --- a/go.mod +++ b/go.mod @@ -10,13 +10,13 @@ require ( github.com/logrusorgru/aurora v2.0.3+incompatible github.com/miekg/dns v1.1.62 github.com/projectdiscovery/dnsx v1.2.2 - github.com/projectdiscovery/fastdialer v0.4.3 + github.com/projectdiscovery/fastdialer v0.4.9 github.com/projectdiscovery/goflags v0.1.74 github.com/projectdiscovery/gologger v1.1.54 github.com/projectdiscovery/mapcidr v1.1.34 - github.com/projectdiscovery/utils v0.4.22 + github.com/projectdiscovery/utils v0.5.0 github.com/rs/xid v1.5.0 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.0 github.com/tylertreat/BoomFilters v0.0.0-20250630160909-db6545748bc4 github.com/zmap/zcrypto v0.0.0-20231106212110-94c8f62efae4 go.uber.org/multierr v1.11.0 @@ -45,7 +45,7 @@ require ( github.com/dlclark/regexp2 v1.11.5 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/fatih/color v1.18.0 // indirect - github.com/gaissmai/bart v0.20.5 // indirect + github.com/gaissmai/bart v0.24.0 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/google/go-github/v30 v30.1.0 // indirect github.com/google/go-querystring v1.1.0 // indirect @@ -114,14 +114,14 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/projectdiscovery/blackrock v0.0.1 // indirect - github.com/projectdiscovery/cdncheck v1.1.29 // indirect - github.com/projectdiscovery/hmap v0.0.92 // indirect - github.com/projectdiscovery/networkpolicy v0.1.18 // indirect - github.com/projectdiscovery/retryabledns v1.0.105 // indirect - github.com/projectdiscovery/retryablehttp-go v1.0.119 + github.com/projectdiscovery/cdncheck v1.1.35 // indirect + github.com/projectdiscovery/hmap v0.0.93 // indirect + github.com/projectdiscovery/networkpolicy v0.1.23 // indirect + github.com/projectdiscovery/retryabledns v1.0.106 // indirect + github.com/projectdiscovery/retryablehttp-go v1.0.120 github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect github.com/syndtr/goleveldb v1.0.0 // indirect - github.com/ulikunitz/xz v0.5.12 // indirect + github.com/ulikunitz/xz v0.5.15 // indirect github.com/weppos/publicsuffix-go v0.40.3-0.20250408071509-6074bbe7fd39 // indirect github.com/zmap/rc2 v0.0.0-20190804163417-abaa70531248 // indirect go.etcd.io/bbolt v1.4.0 // indirect diff --git a/go.sum b/go.sum index e9f1322d..a9f27a03 100644 --- a/go.sum +++ b/go.sum @@ -109,8 +109,8 @@ github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= -github.com/gaissmai/bart v0.20.5 h1:ehoWZWQ7j//qt0K0Zs4i9hpoPpbgqsMQiR8W2QPJh+c= -github.com/gaissmai/bart v0.20.5/go.mod h1:cEed+ge8dalcbpi8wtS9x9m2hn/fNJH5suhdGQOHnYk= +github.com/gaissmai/bart v0.24.0 h1:HOq5aXDBa4d376KkuxD+xnS9DQWWJtD4zgDNoGV0KrQ= +github.com/gaissmai/bart v0.24.0/go.mod h1:RpLtt3lWq1BoRz3AAyDAJ7jhLWBkYhVCfi+ximB2t68= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= @@ -262,30 +262,30 @@ github.com/projectdiscovery/asnmap v1.1.1 h1:ImJiKIaACOT7HPx4Pabb5dksolzaFYsD1kI github.com/projectdiscovery/asnmap v1.1.1/go.mod h1:QT7jt9nQanj+Ucjr9BqGr1Q2veCCKSAVyUzLXfEcQ60= github.com/projectdiscovery/blackrock v0.0.1 h1:lHQqhaaEFjgf5WkuItbpeCZv2DUIE45k0VbGJyft6LQ= github.com/projectdiscovery/blackrock v0.0.1/go.mod h1:ANUtjDfaVrqB453bzToU+YB4cUbvBRpLvEwoWIwlTss= -github.com/projectdiscovery/cdncheck v1.1.29 h1:A+wPQyi2OKikHigD91Y2y7NxCwVGhnjjnv7bqcDE9N8= -github.com/projectdiscovery/cdncheck v1.1.29/go.mod h1:dFEGsG0qAJY0AaRr2N1BY0OtZiTxS4kYeT5+OkF8t1U= +github.com/projectdiscovery/cdncheck v1.1.35 h1:xyMnIWf2wzKH4Ii3lBNb73b/n9ee/baEiS3Ao23pyco= +github.com/projectdiscovery/cdncheck v1.1.35/go.mod h1:dFEGsG0qAJY0AaRr2N1BY0OtZiTxS4kYeT5+OkF8t1U= github.com/projectdiscovery/dnsx v1.2.2 h1:ZjUov0GOyrS8ERlKAAhk+AOkqzaYHBzCP0qZfO+6Ihg= github.com/projectdiscovery/dnsx v1.2.2/go.mod h1:3iYm86OEqo0WxeGDkVl5WZNmG0qYE5TYNx8fBg6wX1I= -github.com/projectdiscovery/fastdialer v0.4.3 h1:pHU5M3rngY5QuXPFy+azovpETKxUW/Si+Q1y0gOGVDQ= -github.com/projectdiscovery/fastdialer v0.4.3/go.mod h1:g7o6bF9XX8tPZvVIsEOCyfxo1BEh/BRCnNUSQPWnDfQ= +github.com/projectdiscovery/fastdialer v0.4.9 h1:/CTzoEsayQOrYJjB0CCa/0iNX7LSMeml6XmeyxX8ZVA= +github.com/projectdiscovery/fastdialer v0.4.9/go.mod h1:/4f7ELi6M5sr5XOpt+q0OpP4sQV36f3bOG23n7GOQUw= github.com/projectdiscovery/goflags v0.1.74 h1:n85uTRj5qMosm0PFBfsvOL24I7TdWRcWq/1GynhXS7c= github.com/projectdiscovery/goflags v0.1.74/go.mod h1:UMc9/7dFz2oln+10tv6cy+7WZKTHf9UGhaNkF95emh4= github.com/projectdiscovery/gologger v1.1.54 h1:WMzvJ8j/4gGfPKpCttSTaYCVDU1MWQSJnk3wU8/U6Ws= github.com/projectdiscovery/gologger v1.1.54/go.mod h1:vza/8pe2OKOt+ujFWncngknad1XWr8EnLKlbcejOyUE= -github.com/projectdiscovery/hmap v0.0.92 h1:NHGDFVJzc7b8bDuIjss7SxX5LJla9py/RxC4lri+uBo= -github.com/projectdiscovery/hmap v0.0.92/go.mod h1:IKezuOhPPwrmPusmhLuwuGsD8+fniyy6jx4gFTOZOnI= +github.com/projectdiscovery/hmap v0.0.93 h1:iIRdioT4byGJ4Hz5cOjo1fd3HFFi1MUFPv+EGYc1yng= +github.com/projectdiscovery/hmap v0.0.93/go.mod h1:oKgtWo2QMD7BkW25ezYbFCqKO3IctZ2ByEaG2XWW0t0= github.com/projectdiscovery/machineid v0.0.0-20240226150047-2e2c51e35983 h1:ZScLodGSezQVwsQDtBSMFp72WDq0nNN+KE/5DHKY5QE= github.com/projectdiscovery/machineid v0.0.0-20240226150047-2e2c51e35983/go.mod h1:3G3BRKui7nMuDFAZKR/M2hiOLtaOmyukT20g88qRQjI= github.com/projectdiscovery/mapcidr v1.1.34 h1:udr83vQ7oz3kEOwlsU6NC6o08leJzSDQtls1wmXN/kM= github.com/projectdiscovery/mapcidr v1.1.34/go.mod h1:1+1R6OkKSAKtWDXE9RvxXtXPoajXTYX0eiEdkqlhQqQ= -github.com/projectdiscovery/networkpolicy v0.1.18 h1:DAeP73SvcuT4evaohNS7BPELw+VtvcVt4PaTK3fC1qA= -github.com/projectdiscovery/networkpolicy v0.1.18/go.mod h1:2yWanKsU2oBZ75ch94IsEQy6hByFp+3oTiSyC6ew3TE= -github.com/projectdiscovery/retryabledns v1.0.105 h1:G8ln01igkNTQ5xvMY5K4cx5XIfKGTwGH6aZxWxBKMqc= -github.com/projectdiscovery/retryabledns v1.0.105/go.mod h1:3EZKhRL1rokqYR4q5qKK1eLBEe8mSzgtzkMOJilO1Ok= -github.com/projectdiscovery/retryablehttp-go v1.0.119 h1:Lpjb6gCWpIvCCX8GultM8zlaQEmFOci1dS33k9Ll4gw= -github.com/projectdiscovery/retryablehttp-go v1.0.119/go.mod h1:x29gqkLERRzw0znJDu5ORhphBaVin8FtK0+jCvCx4os= -github.com/projectdiscovery/utils v0.4.22 h1:OO3FU2uX967sQxu5JtpdBZNzOevvKHAhWqkoTGl+C0A= -github.com/projectdiscovery/utils v0.4.22/go.mod h1:3l84gpCwL9KG1/ZmslOBABCrk84CcpGWJZfR8wZysR4= +github.com/projectdiscovery/networkpolicy v0.1.23 h1:+MVm9xHCfzmZG5WhUtjAGFvNiQNKOgxZDDed1QfpLXI= +github.com/projectdiscovery/networkpolicy v0.1.23/go.mod h1:ILun9d4jgAfLOYf/NYjV+sKyW3tZTLMl+HyvaZuXZo0= +github.com/projectdiscovery/retryabledns v1.0.106 h1:repm5aGq5ge6fNJQbPNux7vyUhtUju7aIMEXZD9FX0A= +github.com/projectdiscovery/retryabledns v1.0.106/go.mod h1:1W3ogENvt3Pb+Ju4AN0aE2lZy+D76Yzxsz51DqFCIk8= +github.com/projectdiscovery/retryablehttp-go v1.0.120 h1:kH4D0MwKV6a0U6YbBQ8cBD+tT0U3zrwudTPCFVSaZg8= +github.com/projectdiscovery/retryablehttp-go v1.0.120/go.mod h1:jR3eJLdCEvW3Xz0LOQldxNc+MHHY61qZh9k3Sz7U40U= +github.com/projectdiscovery/utils v0.5.0 h1:DN7mg2DpyObLByuObXzAFEkdNRDoPUnqE5N2szd3b3c= +github.com/projectdiscovery/utils v0.5.0/go.mod h1:eCAWMmyaNxyPWbiKv1oeYJLIKpxceHE2+NWx3Jodhqk= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/refraction-networking/utls v1.7.1 h1:dxg+jla3uocgN8HtX+ccwDr68uCBBO3qLrkZUbqkcw0= github.com/refraction-networking/utls v1.7.1/go.mod h1:TUhh27RHMGtQvjQq+RyO11P6ZNQNBb3N0v7wsEjKAIQ= @@ -322,8 +322,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.0 h1:ib4sjIrwZKxE5u/Japgo/7SJV3PvgjGiRNAvTVGqQl8= +github.com/stretchr/testify v1.11.0/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/therootcompany/xz v1.0.1 h1:CmOtsn1CbtmyYiusbfmhmkpAAETj0wBIH6kCYaX+xzw= @@ -359,8 +359,10 @@ github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9f github.com/tylertreat/BoomFilters v0.0.0-20250630160909-db6545748bc4 h1:NY8dlg1XXMOf6B7rTYTESijQt5eZQTSRnSiM+eydx/o= github.com/tylertreat/BoomFilters v0.0.0-20250630160909-db6545748bc4/go.mod h1:OYRfF6eb5wY9VRFkXJH8FFBi3plw2v+giaIu7P054pM= github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= -github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc= -github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= +github.com/ulikunitz/xz v0.5.14 h1:uv/0Bq533iFdnMHZdRBTOlaNMdb1+ZxXIlHDZHIHcvg= +github.com/ulikunitz/xz v0.5.14/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= +github.com/ulikunitz/xz v0.5.15 h1:9DNdB5s+SgV3bQ2ApL10xRc35ck0DuIX/isZvIk+ubY= +github.com/ulikunitz/xz v0.5.15/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/weppos/publicsuffix-go v0.13.0/go.mod h1:z3LCPQ38eedDQSwmsSRW4Y7t2L8Ln16JPQ02lHAdn5k= github.com/weppos/publicsuffix-go v0.30.2-0.20230730094716-a20f9abcc222/go.mod h1:s41lQh6dIsDWIC1OWh7ChWJXLH0zkJ9KHZVqA7vHyuQ= github.com/weppos/publicsuffix-go v0.40.3-0.20250408071509-6074bbe7fd39 h1:Bz/zVM/LoGZ9IztGBHrq2zlFQQbEG8dBYnxb4hamIHM= diff --git a/internal/runner/banner.go b/internal/runner/banner.go index 63bed145..d4b9ba32 100644 --- a/internal/runner/banner.go +++ b/internal/runner/banner.go @@ -5,7 +5,7 @@ import ( "github.com/projectdiscovery/gologger" "github.com/projectdiscovery/gologger/levels" - errorutils "github.com/projectdiscovery/utils/errors" + "github.com/projectdiscovery/utils/errkit" fileutil "github.com/projectdiscovery/utils/file" updateutils "github.com/projectdiscovery/utils/update" ) @@ -33,10 +33,10 @@ func (r *Runner) validateOptions() error { } probeSpecified := r.options.SO || r.options.TLSVersion || r.options.Cipher || r.options.Expired || r.options.SelfSigned || r.options.Hash != "" || r.options.Jarm || r.options.MisMatched || r.options.Revoked || r.options.WildcardCertCheck if r.options.RespOnly && probeSpecified { - return errorutils.New("resp-only flag can only be used with san and cn flags") + return errkit.New("resp-only flag can only be used with san and cn flags") } if (r.options.SAN || r.options.CN) && probeSpecified { - return errorutils.New("san or cn flag cannot be used with other probes") + return errkit.New("san or cn flag cannot be used with other probes") } // Enable CT logs mode by default if no input is provided @@ -47,7 +47,7 @@ func (r *Runner) validateOptions() error { // Check if we still have no input after auto-enabling CT logs if !r.options.CTLogs && !r.hasStdin && len(r.options.Inputs) == 0 && r.options.InputList == "" { - return errorutils.New("no input provided for enumeration") + return errkit.New("no input provided for enumeration") } if len(r.options.Ports) == 0 { @@ -55,7 +55,7 @@ func (r *Runner) validateOptions() error { r.options.Ports = append(r.options.Ports, "443") } if r.options.CertsOnly && (r.options.ScanMode != "ztls" && r.options.ScanMode != "auto") { - return errorutils.New("scan-mode must be ztls or auto with certs-only option") + return errkit.New("scan-mode must be ztls or auto with certs-only option") } if r.options.CertsOnly || r.options.Ja3 || r.options.Ja3s { r.options.ScanMode = "ztls" // force setting ztls when using certs-only diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 36988732..d28accab 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -26,7 +26,7 @@ import ( "github.com/projectdiscovery/tlsx/pkg/tlsx" "github.com/projectdiscovery/tlsx/pkg/tlsx/clients" "github.com/projectdiscovery/tlsx/pkg/tlsx/openssl" - errorutil "github.com/projectdiscovery/utils/errors" + "github.com/projectdiscovery/utils/errkit" //nolint iputil "github.com/projectdiscovery/utils/ip" sliceutil "github.com/projectdiscovery/utils/slice" updateutils "github.com/projectdiscovery/utils/update" @@ -79,7 +79,7 @@ func New(options *clients.Options) (*Runner, error) { runner := &Runner{options: options} if err := runner.validateOptions(); err != nil { - return nil, errorutil.NewWithErr(err).Msgf("could not validate options") + return nil, errkit.Wrap(err, "could not validate options") } dialerTimeout := time.Duration(options.Timeout) * time.Second @@ -88,14 +88,14 @@ func New(options *clients.Options) (*Runner, error) { if options.Proxy != "" { proxyURL, err := url.Parse(options.Proxy) if err != nil { - return nil, errorutil.NewWithErr(err).Msgf("could not parse proxy") + return nil, errkit.Wrap(err, "could not parse proxy") } dialer, err := proxy.FromURL(proxyURL, &net.Dialer{ Timeout: dialerTimeout, DualStack: true, }) if err != nil { - return nil, errorutil.NewWithErr(err).Msgf("could not create proxy dialer") + return nil, errkit.Wrap(err, "could not create proxy dialer") } proxyDialer = &dialer } @@ -112,7 +112,7 @@ func New(options *clients.Options) (*Runner, error) { } fastDialer, err := fastdialer.NewDialer(dialerOpts) if err != nil { - return nil, errorutil.NewWithErr(err).Msgf("could not create dialer") + return nil, errkit.Wrap(err, "could not create dialer") } runner.fastDialer = fastDialer runner.options.Fastdialer = fastDialer @@ -131,7 +131,7 @@ func New(options *clients.Options) (*Runner, error) { outputWriter, err := output.New(options) if err != nil { - return nil, errorutil.NewWithErr(err).Msgf("could not create output writer") + return nil, errkit.Wrap(err, "could not create output writer") } runner.outputWriter = outputWriter if options.TlsCiphersEnum && !options.Silent { @@ -244,7 +244,7 @@ func (r *Runner) executeCTLogsMode() error { // Display CT log progress information in verbose mode if r.options.Verbose { progressPercent := float64(meta.Index) / float64(meta.TreeSize) * 100 - gologger.Info().Msgf("[CT] %s: Index %d/%d (%.1f%%), Lag: %d, URL: %s", + gologger.Info().Msgf("[CT] %s: Index %d/%d (%.1f%%), Lag: %d, URL: %s", meta.SourceDesc, meta.Index, meta.TreeSize, progressPercent, meta.Lag, meta.LogURL) } @@ -267,7 +267,7 @@ func (r *Runner) executeCTLogsMode() error { ctService, err := ctlogs.New(svcOpts...) if err != nil { - return errorutil.NewWithErr(err).Msgf("could not create CT logs service") + return errkit.Wrap(err, "could not create CT logs service") } // Start streaming @@ -326,7 +326,7 @@ func (r *Runner) normalizeAndQueueInputs(inputs chan taskInput) error { if r.options.InputList != "" { file, err := os.Open(r.options.InputList) if err != nil { - return errorutil.NewWithErr(err).Msgf("could not open input file") + return errkit.Wrap(err, "could not open input file") } defer func() { if err := file.Close(); err != nil { diff --git a/pkg/output/output.go b/pkg/output/output.go index cf5fa13d..8919abfe 100644 --- a/pkg/output/output.go +++ b/pkg/output/output.go @@ -11,7 +11,7 @@ import ( jsoniter "github.com/json-iterator/go" "github.com/logrusorgru/aurora" "github.com/projectdiscovery/tlsx/pkg/tlsx/clients" - errorutil "github.com/projectdiscovery/utils/errors" + "github.com/projectdiscovery/utils/errkit" //nolint mapsutil "github.com/projectdiscovery/utils/maps" "golang.org/x/exp/maps" ) @@ -50,7 +50,7 @@ func New(options *clients.Options) (Writer, error) { if options.OutputFile != "" { output, err := newFileOutputWriter(options.OutputFile) if err != nil { - return nil, errorutil.NewWithErr(err).Msgf("could not create output file") + return nil, errkit.Wrap(err, "could not create output file") } outputFile = output } @@ -75,7 +75,7 @@ func (w *StandardWriter) Write(event *clients.Response) error { data, err = w.formatStandard(event) } if err != nil { - return errorutil.NewWithErr(err).Msgf("could not format output") + return errkit.Wrap(err, "could not format output") } data = bytes.TrimSuffix(data, []byte("\n")) // remove last newline if len(data) == 0 { @@ -92,7 +92,7 @@ func (w *StandardWriter) Write(event *clients.Response) error { data = decolorizerRegex.ReplaceAll(data, []byte("")) } if writeErr := w.outputFile.Write(data); writeErr != nil { - return errorutil.NewWithErr(err).Msgf("could not write to output") + return errkit.Wrap(err, "could not write to output") } } return nil @@ -115,11 +115,11 @@ func (w *StandardWriter) formatJSON(output *clients.Response) ([]byte, error) { // formatStandard formats the output for standard client formatting func (w *StandardWriter) formatStandard(output *clients.Response) ([]byte, error) { if output == nil { - return nil, errorutil.New("empty certificate response") + return nil, errkit.New("empty certificate response") } if output.CertificateResponse == nil { - return nil, errorutil.New("empty leaf certificate") + return nil, errkit.New("empty leaf certificate") } cert := output.CertificateResponse builder := &bytes.Buffer{} diff --git a/pkg/tlsx/auto/auto.go b/pkg/tlsx/auto/auto.go index cb35df64..b31bcef5 100644 --- a/pkg/tlsx/auto/auto.go +++ b/pkg/tlsx/auto/auto.go @@ -10,7 +10,8 @@ import ( "github.com/projectdiscovery/tlsx/pkg/tlsx/openssl" "github.com/projectdiscovery/tlsx/pkg/tlsx/tls" "github.com/projectdiscovery/tlsx/pkg/tlsx/ztls" - errorutils "github.com/projectdiscovery/utils/errors" + "github.com/projectdiscovery/utils/errkit" + errorutils "github.com/projectdiscovery/utils/errors" //nolint sliceutil "github.com/projectdiscovery/utils/slice" "go.uber.org/multierr" ) @@ -29,7 +30,7 @@ func New(options *clients.Options) (*Client, error) { ztlsClient, ztlsErr := ztls.New(options) opensslClient, opensslErr := openssl.New(options) - if tlsErr != nil && ztlsErr != nil && (opensslErr != nil && !errorutils.IsAny(opensslErr, openssl.ErrNotAvailable)) { + if tlsErr != nil && ztlsErr != nil && (opensslErr != nil && !errorutils.IsAny(opensslErr, openssl.ErrNotAvailable)) { //nolint return nil, multierr.Combine(tlsErr, ztlsErr, opensslErr) } return &Client{tlsClient: tlsClient, ztlsClient: ztlsClient, opensslClient: opensslClient, options: options}, nil @@ -46,7 +47,7 @@ func (c *Client) ConnectWithOptions(hostname, ip, port string, options clients.C retryCounter := 0 if c.tlsClient == nil && c.ztlsClient == nil && c.opensslClient == nil { // logic to avoid infinite loop - return nil, errorutils.New("no tls client available available for auto mode") + return nil, errkit.New("no tls client available available for auto mode") } var errStack error for retryCounter < maxRetries { @@ -72,7 +73,7 @@ func (c *Client) ConnectWithOptions(hostname, ip, port string, options clients.C stats.IncrementOpensslTLSConnections() return response, nil } - if errorutils.IsAny(opensslErr, openssl.ErrNotAvailable) { + if errorutils.IsAny(opensslErr, openssl.ErrNotAvailable) { //nolint opensslErr = nil } retryCounter++ diff --git a/pkg/tlsx/clients/utils.go b/pkg/tlsx/clients/utils.go index 8ffd5542..dd9bbc2b 100644 --- a/pkg/tlsx/clients/utils.go +++ b/pkg/tlsx/clients/utils.go @@ -10,7 +10,7 @@ import ( "strings" "time" - errorutil "github.com/projectdiscovery/utils/errors" + "github.com/projectdiscovery/utils/errkit" iputil "github.com/projectdiscovery/utils/ip" mapsutil "github.com/projectdiscovery/utils/maps" ) @@ -102,14 +102,14 @@ func GetConn(ctx context.Context, hostname, ip, port string, inputOpts *Options) } //validation if (hostname == "" && ip == "") || port == "" { - return nil, errorutil.New("client requires valid address got port=%v,hostname=%v,ip=%v", port, hostname, ip) + return nil, errkit.Newf("client requires valid address got port=%v,hostname=%v,ip=%v", port, hostname, ip) } rawConn, err := inputOpts.Fastdialer.Dial(ctx, "tcp", address) if err != nil { - return nil, errorutil.New("could not dial address").Wrap(err) + return nil, errkit.Wrap(err, "could not dial address") } if rawConn == nil { - return nil, errorutil.New("could not connect to %s", address) + return nil, errkit.Newf("could not connect to %s", address) } if inputOpts.Timeout == 0 { inputOpts.Timeout = 5 diff --git a/pkg/tlsx/openssl/common.go b/pkg/tlsx/openssl/common.go index c6b3900e..f267bbe6 100644 --- a/pkg/tlsx/openssl/common.go +++ b/pkg/tlsx/openssl/common.go @@ -9,15 +9,15 @@ import ( "strings" "github.com/projectdiscovery/gologger" - errorutils "github.com/projectdiscovery/utils/errors" + errorutils "github.com/projectdiscovery/utils/errors" //nolint ) var ( - ErrParse = errorutils.NewWithTag("openssl", "failed to parse openssl response") - ErrCertParse = errorutils.NewWithTag("openssl", "failed to parse server certificate") - ErrNotImplemented = errorutils.NewWithTag("openssl", "feature not implemented") - ErrNotAvailable = errorutils.NewWithTag("openssl", "executable not installed or in PATH") - ErrNoSession = errorutils.NewWithTag("openssl", "session not created/found") + ErrParse = errorutils.NewWithTag("openssl", "failed to parse openssl response") //nolint + ErrCertParse = errorutils.NewWithTag("openssl", "failed to parse server certificate") //nolint + ErrNotImplemented = errorutils.NewWithTag("openssl", "feature not implemented") //nolint + ErrNotAvailable = errorutils.NewWithTag("openssl", "executable not installed or in PATH") //nolint + ErrNoSession = errorutils.NewWithTag("openssl", "session not created/found") //nolint ) var ( @@ -55,19 +55,19 @@ func init() { return } if err := openSSLSetup(); err != nil { - gologger.Debug().Label("openssl").Msg(err.Error()) + gologger.Debug().Label("openssl").Msg(err.Error()) //nolint } } // fetch openssl version -func openSSLSetup() errorutils.Error { +func openSSLSetup() errorutils.Error { //nolint result, err := execOpenSSL(context.TODO(), []string{"version"}) if err != nil { - return errorutils.NewWithErr(err).WithTag("openssl").Msgf(result.Stderr) + return errorutils.NewWithErr(err).WithTag("openssl").Msgf(result.Stderr) //nolint } arr := strings.Fields(result.Stdout) if len(arr) < 2 { - return errorutils.NewWithTag("openssl", "failed to parse openssl version got %v", result.Stdout) + return errorutils.NewWithTag("openssl", "failed to parse openssl version got %v", result.Stdout) //nolint } if arr[0] == "LibreSSL" { IsLibreSSL = true @@ -100,6 +100,6 @@ func UseOpenSSLBinary(binpath string) { BinaryPath = binpath if err := openSSLSetup(); err != nil { // do not fallback - gologger.Fatal().Label("openssl").Msg(err.Error()) + gologger.Fatal().Label("openssl").Msg(err.Error()) //nolint } } diff --git a/pkg/tlsx/openssl/openssl.go b/pkg/tlsx/openssl/openssl.go index c79f1094..81783e0d 100644 --- a/pkg/tlsx/openssl/openssl.go +++ b/pkg/tlsx/openssl/openssl.go @@ -11,7 +11,7 @@ import ( "github.com/projectdiscovery/gologger" "github.com/projectdiscovery/tlsx/pkg/output/stats" "github.com/projectdiscovery/tlsx/pkg/tlsx/clients" - errorutils "github.com/projectdiscovery/utils/errors" + errorutils "github.com/projectdiscovery/utils/errors" //nolint iputil "github.com/projectdiscovery/utils/ip" stringsutil "github.com/projectdiscovery/utils/strings" ) @@ -38,7 +38,7 @@ func New(options *clients.Options) (*Client, error) { func (c *Client) ConnectWithOptions(hostname, ip, port string, options clients.ConnectOptions) (*clients.Response, error) { opensslOpts, errx := c.getOpenSSLopts(hostname, ip, port, options) if errx != nil { - return nil, errx.Msgf("failed to generate openssl options") + return nil, errx.Msgf("failed to generate openssl options") //nolint } // timeout cannot be zero(If GOOS==windows it should be on average 3) @@ -51,14 +51,14 @@ func (c *Client) ConnectWithOptions(hostname, ip, port string, options clients.C var err error c.dialer, err = fastdialer.NewDialer(fastdialer.DefaultOptions) if err != nil { - return nil, errorutils.NewWithErr(err).WithTag(PkgTag, "fastdialer").Msgf("failed to create new fastdialer") + return nil, errorutils.NewWithErr(err).WithTag(PkgTag, "fastdialer").Msgf("failed to create new fastdialer") //nolint } } // There is no guarantee that dialed ip is same as ip used by openssl // this is only used to avoid inconsistencies rawConn, err := c.dialer.Dial(context.TODO(), "tcp", opensslOpts.Address) if err != nil || rawConn == nil { - return nil, errorutils.NewWithErr(err).WithTag(PkgTag, "fastdialer").Msgf("could not dial address:%v", opensslOpts.Address) + return nil, errorutils.NewWithErr(err).WithTag(PkgTag, "fastdialer").Msgf("could not dial address:%v", opensslOpts.Address) //nolint } defer func() { _ = rawConn.Close() @@ -73,7 +73,7 @@ func (c *Client) ConnectWithOptions(hostname, ip, port string, options clients.C // Here _ contains handshake errors and other errors returned by openssl resp, errx := getResponse(ctx, opensslOpts) if errx != nil { - return nil, errx.Msgf("failed to response from openssl").WithTag(PkgTag) + return nil, errx.Msgf("failed to response from openssl").WithTag(PkgTag) //nolint } now := time.Now() @@ -114,7 +114,7 @@ func (c *Client) EnumerateCiphers(hostname, ip, port string, options clients.Con // generate openssl options opensslOpts, err := c.getOpenSSLopts(hostname, ip, port, options) if err != nil { - return nil, err.Msgf("failed to generate openssl options") + return nil, err.Msgf("failed to generate openssl options") //nolint } opensslOpts.SkipCertParse = true gologger.Debug().Label(PkgTag).Msgf("Starting cipher enumeration with %v ciphers in %v", len(toEnumerate), options.VersionTLS) @@ -144,7 +144,7 @@ func (c *Client) SupportedTLSCiphers() ([]string, error) { return AllCiphersNames, nil } -func (c *Client) getOpenSSLopts(hostname, ip, port string, options clients.ConnectOptions) (*Options, errorutils.Error) { +func (c *Client) getOpenSSLopts(hostname, ip, port string, options clients.ConnectOptions) (*Options, errorutils.Error) { //nolint var protocolVersion string switch { case options.VersionTLS != "": @@ -158,7 +158,7 @@ func (c *Client) getOpenSSLopts(hostname, ip, port string, options clients.Conne } protocol, err := getProtocol(protocolVersion) if err != nil { - return nil, errorutils.NewWithTag("openssl", "%s", err.Error()) + return nil, errorutils.NewWithTag("openssl", "%s", err.Error()) //nolint } // Note: CLI options are omitted if given value is empty @@ -174,18 +174,18 @@ func (c *Client) getOpenSSLopts(hostname, ip, port string, options clients.Conne } // validation if (hostname == "" && ip == "") || port == "" { - return nil, errorutils.NewWithTag("openssl", "client requires valid address got port=%v,hostname=%v,ip=%v", port, hostname, ip) + return nil, errorutils.NewWithTag("openssl", "client requires valid address got port=%v,hostname=%v,ip=%v", port, hostname, ip) //nolint } // In enum mode return if given options are not supported if options.EnumMode == clients.Version && (options.VersionTLS == "" || !stringsutil.EqualFoldAny(options.VersionTLS, SupportedTLSVersions...)) { // version not supported - return nil, errorutils.NewWithTag("openssl", "tlsversion `%v` not supported in openssl", options.VersionTLS) + return nil, errorutils.NewWithTag("openssl", "tlsversion `%v` not supported in openssl", options.VersionTLS) //nolint } if options.EnumMode != clients.Cipher { ciphers, err := toOpenSSLCiphers(options.Ciphers...) if err != nil { - return nil, errorutils.NewWithErr(err).WithTag("openssl") + return nil, errorutils.NewWithErr(err).WithTag("openssl") //nolint } opensslOptions.Cipher = ciphers if opensslOptions.ServerName == "" { @@ -194,7 +194,7 @@ func (c *Client) getOpenSSLopts(hostname, ip, port string, options clients.Conne } } else { if !stringsutil.EqualFoldAny(options.VersionTLS, SupportedTLSVersions...) { - return nil, errorutils.NewWithTag(PkgTag, "cipher enum with version %v not implemented", options.VersionTLS) + return nil, errorutils.NewWithTag(PkgTag, "cipher enum with version %v not implemented", options.VersionTLS) //nolint } } return opensslOptions, nil diff --git a/pkg/tlsx/openssl/openssl_exec.go b/pkg/tlsx/openssl/openssl_exec.go index 09a5019f..bb8087d4 100644 --- a/pkg/tlsx/openssl/openssl_exec.go +++ b/pkg/tlsx/openssl/openssl_exec.go @@ -12,7 +12,7 @@ import ( "os/exec" "strings" - errorutils "github.com/projectdiscovery/utils/errors" + errorutils "github.com/projectdiscovery/utils/errors" //nolint ) const commadFormat string = "Command: %v" @@ -68,20 +68,20 @@ func getCiphers() ([]string, error) { } // read openssl s_client response -func getResponse(ctx context.Context, opts *Options) (*Response, errorutils.Error) { +func getResponse(ctx context.Context, opts *Options) (*Response, errorutils.Error) { //nolint args, errx := opts.Args() if errx != nil { - return nil, errorutils.NewWithErr(errx).WithTag(PkgTag).Msgf("failed to create cmd from args got %v", *opts) + return nil, errorutils.NewWithErr(errx).WithTag(PkgTag).Msgf("failed to create cmd from args got %v", *opts) //nolint } result, err := execOpenSSL(ctx, args) if err != nil { - return nil, errorutils.NewWithErr(err).WithTag(PkgTag, BinaryPath).Msgf("failed to execute openssl got %v", result.Stderr).Msgf(commadFormat, result.Command) + return nil, errorutils.NewWithErr(err).WithTag(PkgTag, BinaryPath).Msgf("failed to execute openssl got %v", result.Stderr).Msgf(commadFormat, result.Command) //nolint } response := &Response{} if !strings.Contains(result.Stdout, "CONNECTED") { // If connected string is not available it // openssl failed completely and did not recover - return nil, errorutils.NewWithTag(PkgTag, "failed to parse 'CONNECTED' not found got %v", result.Stderr).Msgf(commadFormat, result.Command) + return nil, errorutils.NewWithTag(PkgTag, "failed to parse 'CONNECTED' not found got %v", result.Stderr).Msgf(commadFormat, result.Command) //nolint } var errParseCertificates, errParseSessionData error // openssl s_client returns lot of data however most of @@ -92,20 +92,20 @@ func getResponse(ctx context.Context, opts *Options) (*Response, errorutils.Erro // Parse Session Data response.Session, errParseSessionData = readSessionData(result.Stdout) - var allerrors errorutils.Error + var allerrors errorutils.Error //nolint if errParseCertificates != nil { - allerrors = Wrap(allerrors, errorutils.NewWithErr(errParseCertificates).WithTag(PkgTag).Msgf("failed to parse server certificate from response")) + allerrors = Wrap(allerrors, errorutils.NewWithErr(errParseCertificates).WithTag(PkgTag).Msgf("failed to parse server certificate from response")) //nolint } if errParseSessionData != nil { - allerrors = Wrap(allerrors, errorutils.NewWithErr(errParseSessionData).WithTag(PkgTag).Msgf("failed to parse session data from response")) + allerrors = Wrap(allerrors, errorutils.NewWithErr(errParseSessionData).WithTag(PkgTag).Msgf("failed to parse session data from response")) //nolint } if !opts.SkipCertParse && len(response.AllCerts) == 0 { - allerrors = Wrap(allerrors, errorutils.NewWithTag(PkgTag, "no server certificates found")) + allerrors = Wrap(allerrors, errorutils.NewWithTag(PkgTag, "no server certificates found")) //nolint } if allerrors != nil { // if any of above case is successful // add openssl response - return nil, allerrors.Msgf("failed to parse openssl response. original response is:\n%v", *result).Msgf(commadFormat, result.Command) + return nil, allerrors.Msgf("failed to parse openssl response. original response is:\n%v", *result).Msgf(commadFormat, result.Command) //nolint } response.ClientCertRequired = isClientCertRequired(result.Stderr) return response, nil @@ -120,7 +120,7 @@ func readSessionData(data string) (*Session, error) { readline: line, err := respreader.ReadString('\n') if err != nil && err != io.EOF { - return nil, errorutils.NewWithErr(err).WithTag(PkgTag).Wrap(ErrNoSession) + return nil, errorutils.NewWithErr(err).WithTag(PkgTag).Wrap(ErrNoSession) //nolint } else if err == io.EOF { return osession, nil } @@ -171,7 +171,7 @@ readline: inFlight = false xcert, certerr := getx509Certificate(certBuff.Bytes()) if certerr != nil { - return nil, errorutils.NewWithErr(certerr).WithTag(PkgTag).Msgf("failed to parse x509 certificate from PEM data of openssl") + return nil, errorutils.NewWithErr(certerr).WithTag(PkgTag).Msgf("failed to parse x509 certificate from PEM data of openssl") //nolint } certArr = append(certArr, xcert) certBuff.Reset() diff --git a/pkg/tlsx/openssl/utils.go b/pkg/tlsx/openssl/utils.go index deecfd57..d0976d89 100644 --- a/pkg/tlsx/openssl/utils.go +++ b/pkg/tlsx/openssl/utils.go @@ -4,7 +4,7 @@ import ( "strings" "github.com/projectdiscovery/gologger" - errorutil "github.com/projectdiscovery/utils/errors" + errorutil "github.com/projectdiscovery/utils/errors" //nolint ) // AllCipherNames contains all ciphers supported by openssl @@ -20,7 +20,7 @@ func toOpenSSLCiphers(cipher ...string) ([]string, error) { if _, ok := cipherMap[v]; ok { arr = append(arr, v) } else { - return arr, errorutil.NewWithTag("openssl", "cipher suite %v not supported", v) + return arr, errorutil.NewWithTag("openssl", "cipher suite %v not supported", v) //nolint } } return arr, nil @@ -37,11 +37,11 @@ func parseSessionValue(line string) string { } // Wraps err2 over err1 even if err is nil -func Wrap(err1 errorutil.Error, err2 errorutil.Error) errorutil.Error { +func Wrap(err1 errorutil.Error, err2 errorutil.Error) errorutil.Error { //nolint if err1 == nil { return err2 } - return err1.Wrap(err2) + return err1.Wrap(err2) //nolint } var certRequiredAlerts = []string{ diff --git a/pkg/tlsx/tls/tls.go b/pkg/tlsx/tls/tls.go index 477dc6ac..c07a5ed2 100644 --- a/pkg/tlsx/tls/tls.go +++ b/pkg/tlsx/tls/tls.go @@ -16,7 +16,7 @@ import ( "github.com/projectdiscovery/tlsx/pkg/output/stats" "github.com/projectdiscovery/tlsx/pkg/tlsx/clients" "github.com/projectdiscovery/utils/conn/connpool" - errorutil "github.com/projectdiscovery/utils/errors" + errorutil "github.com/projectdiscovery/utils/errors" //nolint iputil "github.com/projectdiscovery/utils/ip" stringsutil "github.com/projectdiscovery/utils/strings" "github.com/rs/xid" @@ -59,7 +59,7 @@ func New(options *clients.Options) (*Client, error) { if len(options.Ciphers) > 0 { if customCiphers, err := toTLSCiphers(options.Ciphers); err != nil { - return nil, errorutil.NewWithTag("ctls", "could not get tls ciphers").Wrap(err) + return nil, errorutil.NewWithTag("ctls", "could not get tls ciphers").Wrap(err) //nolint } else { c.tlsConfig.CipherSuites = customCiphers } @@ -71,7 +71,7 @@ func New(options *clients.Options) (*Client, error) { if options.CACertificate != "" { caCert, err := os.ReadFile(options.CACertificate) if err != nil { - return nil, errorutil.NewWithTag("ctls", "could not read ca certificate").Wrap(err) + return nil, errorutil.NewWithTag("ctls", "could not read ca certificate").Wrap(err) //nolint } certPool := x509.NewCertPool() if !certPool.AppendCertsFromPEM(caCert) { @@ -82,7 +82,7 @@ func New(options *clients.Options) (*Client, error) { if options.MinVersion != "" { version, ok := versionStringToTLSVersion[options.MinVersion] if !ok { - return nil, errorutil.NewWithTag("ctls", "invalid min version specified: %s", options.MinVersion) + return nil, errorutil.NewWithTag("ctls", "invalid min version specified: %s", options.MinVersion) //nolint } else { c.tlsConfig.MinVersion = version } @@ -90,7 +90,7 @@ func New(options *clients.Options) (*Client, error) { if options.MaxVersion != "" { version, ok := versionStringToTLSVersion[options.MaxVersion] if !ok { - return nil, errorutil.NewWithTag("ctls", "invalid max version specified: %s", options.MaxVersion) + return nil, errorutil.NewWithTag("ctls", "invalid max version specified: %s", options.MaxVersion) //nolint } else { c.tlsConfig.MaxVersion = version } @@ -103,7 +103,7 @@ func (c *Client) ConnectWithOptions(hostname, ip, port string, options clients.C // Get Config based on options config, err := c.getConfig(hostname, ip, port, options) if err != nil { - return nil, errorutil.NewWithErr(err).Msgf("failed to connect got cfg error") + return nil, errorutil.NewWithErr(err).Msgf("failed to connect got cfg error") //nolint } ctx := context.Background() @@ -116,7 +116,7 @@ func (c *Client) ConnectWithOptions(hostname, ip, port string, options clients.C // setup a net conn rawConn, err := clients.GetConn(ctx, hostname, ip, port, c.options) if err != nil { - return nil, errorutil.NewWithErr(err).Msgf("failed to setup connection").WithTag("ctls") + return nil, errorutil.NewWithErr(err).Msgf("failed to setup connection").WithTag("ctls") //nolint } // defer rawConn.Close() //internally done by conn.Close() so just a placeholder @@ -129,7 +129,7 @@ func (c *Client) ConnectWithOptions(hostname, ip, port string, options clients.C clientCertRequired = true } else { _ = rawConn.Close() - return nil, errorutil.NewWithTag("ctls", "could not do handshake").Wrap(err) + return nil, errorutil.NewWithTag("ctls", "could not do handshake").Wrap(err) //nolint } } defer func() { @@ -138,7 +138,7 @@ func (c *Client) ConnectWithOptions(hostname, ip, port string, options clients.C connectionState := conn.ConnectionState() if len(connectionState.PeerCertificates) == 0 { - return nil, errorutil.New("no certificates returned by server") + return nil, errorutil.New("no certificates returned by server") //nolint } tlsVersion := versionToTLSVersionString[connectionState.Version] tlsCipher := tls.CipherSuiteName(connectionState.CipherSuite) @@ -186,14 +186,14 @@ func (c *Client) EnumerateCiphers(hostname, ip, port string, options clients.Con toEnumerate := clients.GetCiphersWithLevel(AllCiphersNames, options.CipherLevel...) if options.VersionTLS == "tls13" { - return nil, errorutil.NewWithTag("ctls", "cipher enum not supported in ctls with tls1.3") + return nil, errorutil.NewWithTag("ctls", "cipher enum not supported in ctls with tls1.3") //nolint } enumeratedCiphers := []string{} baseCfg, err := c.getConfig(hostname, ip, port, options) if err != nil { - return enumeratedCiphers, errorutil.NewWithErr(err).Msgf("failed to setup cfg") + return enumeratedCiphers, errorutil.NewWithErr(err).Msgf("failed to setup cfg") //nolint } gologger.Debug().Label("ctls").Msgf("Starting cipher enumeration with %v ciphers and version %v", len(toEnumerate), options.VersionTLS) @@ -213,7 +213,7 @@ func (c *Client) EnumerateCiphers(hostname, ip, port string, options clients.Con // setup connection pool pool, err := connpool.NewOneTimePool(context.Background(), address, threads) if err != nil { - return enumeratedCiphers, errorutil.NewWithErr(err).Msgf("failed to setup connection pool") + return enumeratedCiphers, errorutil.NewWithErr(err).Msgf("failed to setup connection pool") //nolint } pool.Dialer = c.dialer go func() { @@ -229,7 +229,7 @@ func (c *Client) EnumerateCiphers(hostname, ip, port string, options clients.Con // create new baseConn and pass it to tlsclient baseConn, err := pool.Acquire(context.Background()) if err != nil { - return enumeratedCiphers, errorutil.NewWithErr(err).WithTag("ctls") + return enumeratedCiphers, errorutil.NewWithErr(err).WithTag("ctls") //nolint } stats.IncrementCryptoTLSConnections() baseCfg.CipherSuites = []uint16{tlsCiphers[v]} @@ -260,7 +260,7 @@ func (c *Client) getConfig(hostname, ip, port string, options clients.ConnectOpt // In enum mode return if given options are not supported if options.EnumMode == clients.Version && (options.VersionTLS == "" || !stringsutil.EqualFoldAny(options.VersionTLS, SupportedTlsVersions...)) { // version not supported - return nil, errorutil.NewWithTag("ctls", "tlsversion `%v` not supported in ctls", options.VersionTLS) + return nil, errorutil.NewWithTag("ctls", "tlsversion `%v` not supported in ctls", options.VersionTLS) //nolint } config := c.tlsConfig if config.ServerName == "" { @@ -280,7 +280,7 @@ func (c *Client) getConfig(hostname, ip, port string, options clients.ConnectOpt if options.VersionTLS != "" { version, ok := versionStringToTLSVersion[options.VersionTLS] if !ok { - return nil, errorutil.New("invalid tls version specified: %s", options.VersionTLS).WithTag("ctls") + return nil, errorutil.New("invalid tls version specified: %s", options.VersionTLS).WithTag("ctls") //nolint } config.MinVersion = version config.MaxVersion = version @@ -289,12 +289,12 @@ func (c *Client) getConfig(hostname, ip, port string, options clients.ConnectOpt if len(options.Ciphers) > 0 && options.EnumMode != clients.Cipher { customCiphers, err := toTLSCiphers(options.Ciphers) if err != nil { - return nil, errorutil.NewWithTag("ctls", "could not get tls ciphers").Wrap(err) + return nil, errorutil.NewWithTag("ctls", "could not get tls ciphers").Wrap(err) //nolint } c.tlsConfig.CipherSuites = customCiphers } if options.EnumMode == clients.Cipher && !stringsutil.EqualFoldAny(options.VersionTLS, SupportedTlsVersions...) { - return nil, errorutil.NewWithTag("ctls", "cipher enum with version %v not implemented", options.VersionTLS) + return nil, errorutil.NewWithTag("ctls", "cipher enum with version %v not implemented", options.VersionTLS) //nolint } return config, nil } diff --git a/pkg/tlsx/tls/utils.go b/pkg/tlsx/tls/utils.go index 7165a684..d02e2c80 100644 --- a/pkg/tlsx/tls/utils.go +++ b/pkg/tlsx/tls/utils.go @@ -3,7 +3,7 @@ package tls import ( "crypto/tls" - errorutil "github.com/projectdiscovery/utils/errors" + errorutil "github.com/projectdiscovery/utils/errors" //nolint ) var ( @@ -27,7 +27,7 @@ func toTLSCiphers(items []string) ([]uint16, error) { for _, item := range items { cipher, ok := tlsCiphers[item] if !ok { - return nil, errorutil.NewWithTag("ctls", "cipher suite %v not supported", item) + return nil, errorutil.NewWithTag("ctls", "cipher suite %v not supported", item) //nolint } convertedCiphers = append(convertedCiphers, cipher) } diff --git a/pkg/tlsx/tlsx.go b/pkg/tlsx/tlsx.go index 37731b35..cae8918e 100644 --- a/pkg/tlsx/tlsx.go +++ b/pkg/tlsx/tlsx.go @@ -10,7 +10,7 @@ import ( "github.com/projectdiscovery/tlsx/pkg/tlsx/openssl" "github.com/projectdiscovery/tlsx/pkg/tlsx/tls" "github.com/projectdiscovery/tlsx/pkg/tlsx/ztls" - errorutil "github.com/projectdiscovery/utils/errors" + errorutil "github.com/projectdiscovery/utils/errors" //nolint sliceutil "github.com/projectdiscovery/utils/slice" ) @@ -49,7 +49,7 @@ func New(options *clients.Options) (*Service, error) { options.ScanMode = "ctls" } if err != nil { - return nil, errorutil.NewWithTag("auto", "could not create tls service").Wrap(err) + return nil, errorutil.NewWithTag("auto", "could not create tls service").Wrap(err) //nolint } return service, nil } @@ -66,7 +66,7 @@ func (s *Service) ConnectWithOptions(host, ip, port string, options clients.Conn //validation if (host == "" && ip == "") || port == "" { - return nil, errorutil.NewWithTag("tlsx", "tlsx requires valid address got port=%v,hostname=%v,ip=%v", port, host, ip) + return nil, errorutil.NewWithTag("tlsx", "tlsx requires valid address got port=%v,hostname=%v,ip=%v", port, host, ip) //nolint } if s.options.ScanMode != "auto" && s.options.ScanMode != "" { @@ -84,10 +84,10 @@ func (s *Service) ConnectWithOptions(host, ip, port string, options clients.Conn } } if resp == nil && err == nil { - return nil, errorutil.NewWithTag("auto", "no response returned for connection") + return nil, errorutil.NewWithTag("auto", "no response returned for connection") //nolint } if err != nil { - wrappedErr := errorutil.NewWithTag("auto", "could not connect to host").Wrap(err) + wrappedErr := errorutil.NewWithTag("auto", "could not connect to host").Wrap(err) //nolint if s.options.ProbeStatus { return &clients.Response{Host: host, Port: port, Error: err.Error(), ProbeStatus: false, ServerName: options.SNI}, wrappedErr } diff --git a/pkg/tlsx/ztls/utils.go b/pkg/tlsx/ztls/utils.go index 31e74165..fbf8661d 100644 --- a/pkg/tlsx/ztls/utils.go +++ b/pkg/tlsx/ztls/utils.go @@ -2,7 +2,7 @@ package ztls import ( "github.com/projectdiscovery/tlsx/pkg/tlsx/clients" - errorutil "github.com/projectdiscovery/utils/errors" + errorutil "github.com/projectdiscovery/utils/errors" //nolint "github.com/zmap/zcrypto/tls" "github.com/zmap/zcrypto/x509" ) @@ -28,7 +28,7 @@ func toZTLSCiphers(items []string) ([]uint16, error) { for _, item := range items { zcipher, ok := ztlsCiphers[item] if !ok { - return nil, errorutil.NewWithTag("ztls", "cipher suite %v not supported", item) + return nil, errorutil.NewWithTag("ztls", "cipher suite %v not supported", item) //nolint } convertedCiphers = append(convertedCiphers, zcipher) } diff --git a/pkg/tlsx/ztls/ztls.go b/pkg/tlsx/ztls/ztls.go index 64c728b0..a03b7267 100644 --- a/pkg/tlsx/ztls/ztls.go +++ b/pkg/tlsx/ztls/ztls.go @@ -16,7 +16,7 @@ import ( "github.com/projectdiscovery/tlsx/pkg/tlsx/clients" "github.com/projectdiscovery/tlsx/pkg/tlsx/ztls/ja3" "github.com/projectdiscovery/utils/conn/connpool" - errorutil "github.com/projectdiscovery/utils/errors" + errorutil "github.com/projectdiscovery/utils/errors" //nolint iputil "github.com/projectdiscovery/utils/ip" stringsutil "github.com/projectdiscovery/utils/strings" "github.com/rs/xid" @@ -67,7 +67,7 @@ func New(options *clients.Options) (*Client, error) { if len(options.Ciphers) > 0 { if customCiphers, err := toZTLSCiphers(options.Ciphers); err != nil { - return nil, errorutil.NewWithTag("ztls", "could not get ztls ciphers").Wrap(err) + return nil, errorutil.NewWithTag("ztls", "could not get ztls ciphers").Wrap(err) //nolint } else { c.tlsConfig.CipherSuites = customCiphers } @@ -79,7 +79,7 @@ func New(options *clients.Options) (*Client, error) { if options.CACertificate != "" { caCert, err := os.ReadFile(options.CACertificate) if err != nil { - return nil, errorutil.NewWithTag("ztls", "could not read ca certificate").Wrap(err) + return nil, errorutil.NewWithTag("ztls", "could not read ca certificate").Wrap(err) //nolint } certPool := x509.NewCertPool() if !certPool.AppendCertsFromPEM(caCert) { @@ -111,7 +111,7 @@ func (c *Client) ConnectWithOptions(hostname, ip, port string, options clients.C // Get ztls config using input config, err := c.getConfig(hostname, ip, port, options) if err != nil { - return nil, errorutil.NewWithErr(err).Msgf("failed to create ztls config") + return nil, errorutil.NewWithErr(err).Msgf("failed to create ztls config") //nolint } ctx := context.Background() @@ -124,7 +124,7 @@ func (c *Client) ConnectWithOptions(hostname, ip, port string, options clients.C // setup tcp connection conn, err := clients.GetConn(ctx, hostname, ip, port, c.options) if err != nil { - return nil, errorutil.NewWithErr(err).Msgf("failed to setup connection").WithTag("ztls") + return nil, errorutil.NewWithErr(err).Msgf("failed to setup connection").WithTag("ztls") //nolint } defer func() { _ = conn.Close() @@ -145,7 +145,7 @@ func (c *Client) ConnectWithOptions(hostname, ip, port string, options clients.C if clients.IsClientCertRequiredError(err) { clientCertRequired = true } else { - return nil, errorutil.NewWithTag("ztls", "could not do tls handshake").Wrap(err) + return nil, errorutil.NewWithTag("ztls", "could not do tls handshake").Wrap(err) //nolint } } defer func() { @@ -229,7 +229,7 @@ func (c *Client) EnumerateCiphers(hostname, ip, port string, options clients.Con // setup connection pool pool, err := connpool.NewOneTimePool(context.Background(), address, threads) if err != nil { - return enumeratedCiphers, errorutil.NewWithErr(err).Msgf("failed to setup connection pool") + return enumeratedCiphers, errorutil.NewWithErr(err).Msgf("failed to setup connection pool") //nolint } pool.Dialer = c.dialer go func() { @@ -244,14 +244,14 @@ func (c *Client) EnumerateCiphers(hostname, ip, port string, options clients.Con // create ztls base config baseCfg, err := c.getConfig(hostname, ip, port, options) if err != nil { - return enumeratedCiphers, errorutil.NewWithErr(err).Msgf("failed to setup cfg") + return enumeratedCiphers, errorutil.NewWithErr(err).Msgf("failed to setup cfg") //nolint } gologger.Debug().Label("ztls").Msgf("Starting cipher enumeration with %v ciphers in %v", len(toEnumerate), options.VersionTLS) for _, v := range toEnumerate { baseConn, err := pool.Acquire(context.Background()) if err != nil { - return enumeratedCiphers, errorutil.NewWithErr(err).WithTag("ztls") + return enumeratedCiphers, errorutil.NewWithErr(err).WithTag("ztls") //nolint } stats.IncrementZcryptoTLSConnections() conn := tls.Client(baseConn, baseCfg) @@ -281,10 +281,10 @@ func (c *Client) getConfig(hostname, ip, port string, options clients.ConnectOpt // In enum mode return if given options are not supported if options.EnumMode == clients.Version && (options.VersionTLS == "" || !stringsutil.EqualFoldAny(options.VersionTLS, SupportedTlsVersions...)) { // version not supported - return nil, errorutil.NewWithTag("ztls", "tlsversion `%v` not supported in ztls", options.VersionTLS) + return nil, errorutil.NewWithTag("ztls", "tlsversion `%v` not supported in ztls", options.VersionTLS) //nolint } if options.EnumMode == clients.Cipher && !stringsutil.EqualFoldAny(options.VersionTLS, SupportedTlsVersions...) { - return nil, errorutil.NewWithTag("ztls", "cipher enum with version %v not implemented", options.VersionTLS) + return nil, errorutil.NewWithTag("ztls", "cipher enum with version %v not implemented", options.VersionTLS) //nolint } config := c.tlsConfig @@ -304,7 +304,7 @@ func (c *Client) getConfig(hostname, ip, port string, options clients.ConnectOpt if options.VersionTLS != "" { version, ok := versionStringToTLSVersion[options.VersionTLS] if !ok { - return nil, errorutil.NewWithTag("ztls", "invalid tls version specified: %s", options.VersionTLS) + return nil, errorutil.NewWithTag("ztls", "invalid tls version specified: %s", options.VersionTLS) //nolint } config.MinVersion = version config.MaxVersion = version @@ -313,7 +313,7 @@ func (c *Client) getConfig(hostname, ip, port string, options clients.ConnectOpt if len(options.Ciphers) > 0 && options.EnumMode != clients.Cipher { customCiphers, err := toZTLSCiphers(options.Ciphers) if err != nil { - return nil, errorutil.NewWithTag("ztls", "could not get tls ciphers").Wrap(err) + return nil, errorutil.NewWithTag("ztls", "could not get tls ciphers").Wrap(err) //nolint } c.tlsConfig.CipherSuites = customCiphers } @@ -327,7 +327,7 @@ func (c *Client) tlsHandshakeWithTimeout(tlsConn *tls.Conn, ctx context.Context) select { case <-ctx.Done(): - return errorutil.NewWithTag("ztls", "timeout while attempting handshake") + return errorutil.NewWithTag("ztls", "timeout while attempting handshake") //nolint case errChan <- tlsConn.Handshake(): }