/
util.go
52 lines (45 loc) · 1.5 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package fastdialer
import (
"crypto/tls"
ztls "github.com/zmap/zcrypto/tls"
"golang.org/x/net/idna"
)
func AsTLSConfig(ztlsConfig *ztls.Config) (*tls.Config, error) {
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{
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 {
switch c := config.(type) {
case *tls.Config:
return c.MinVersion == tls.VersionTLS13
case *ztls.Config:
return c.MinVersion == tls.VersionTLS13
}
return false
}
func asAscii(hostname string) string {
hostnameAscii, _ := idna.ToASCII(hostname)
return hostnameAscii
}