refactor(netx): start moving tls-specific code inside the tlsx pkg (#363)
* refactor(netx): move cert pool code inside tlsx * refactor(netx): move more tls code inside tlsx
This commit is contained in:
parent
0317420398
commit
c553afdbd5
6 changed files with 120 additions and 119 deletions
|
|
@ -40,7 +40,6 @@ import (
|
|||
"github.com/ooni/probe-cli/v3/internal/engine/netx/tlsdialer"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/tlsx"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace"
|
||||
"github.com/ooni/probe-cli/v3/internal/runtimex"
|
||||
)
|
||||
|
||||
// Logger is the logger assumed by this package
|
||||
|
|
@ -112,12 +111,8 @@ type tlsHandshaker interface {
|
|||
}
|
||||
|
||||
// NewDefaultCertPool returns a copy of the default x509
|
||||
// certificate pool. This function panics on failure.
|
||||
func NewDefaultCertPool() *x509.CertPool {
|
||||
pool, err := tlsx.CACerts()
|
||||
runtimex.PanicOnError(err, "tlsx.CACerts() failed")
|
||||
return pool
|
||||
}
|
||||
// certificate pool that we bundle from Mozilla.
|
||||
var NewDefaultCertPool = tlsx.NewDefaultCertPool
|
||||
|
||||
var defaultCertPool *x509.CertPool = NewDefaultCertPool()
|
||||
|
||||
|
|
@ -316,31 +311,11 @@ func NewDNSClient(config Config, URL string) (DNSClient, error) {
|
|||
|
||||
// ErrInvalidTLSVersion indicates that you passed us a string
|
||||
// that does not represent a valid TLS version.
|
||||
var ErrInvalidTLSVersion = errors.New("invalid TLS version")
|
||||
var ErrInvalidTLSVersion = tlsx.ErrInvalidTLSVersion
|
||||
|
||||
// ConfigureTLSVersion configures the correct TLS version into
|
||||
// the specified *tls.Config or returns an error.
|
||||
func ConfigureTLSVersion(config *tls.Config, version string) error {
|
||||
switch version {
|
||||
case "TLSv1.3":
|
||||
config.MinVersion = tls.VersionTLS13
|
||||
config.MaxVersion = tls.VersionTLS13
|
||||
case "TLSv1.2":
|
||||
config.MinVersion = tls.VersionTLS12
|
||||
config.MaxVersion = tls.VersionTLS12
|
||||
case "TLSv1.1":
|
||||
config.MinVersion = tls.VersionTLS11
|
||||
config.MaxVersion = tls.VersionTLS11
|
||||
case "TLSv1.0", "TLSv1":
|
||||
config.MinVersion = tls.VersionTLS10
|
||||
config.MaxVersion = tls.VersionTLS10
|
||||
case "":
|
||||
// nothing
|
||||
default:
|
||||
return ErrInvalidTLSVersion
|
||||
}
|
||||
return nil
|
||||
}
|
||||
var ConfigureTLSVersion = tlsx.ConfigureTLSVersion
|
||||
|
||||
// NewDNSClientWithOverrides creates a new DNS client, similar to NewDNSClient,
|
||||
// with the option to override the default Hostname and SNI.
|
||||
|
|
|
|||
Loading…
Reference in a new issue