(ctx context.Context, dialer *net.Dialer, targetAddress string)
| 187 | } |
| 188 | |
| 189 | func tcpTLSCheck(ctx context.Context, dialer *net.Dialer, targetAddress string) error { |
| 190 | // TODO use mullvad API if current provider is Mullvad |
| 191 | |
| 192 | address, err := makeAddressToDial(targetAddress) |
| 193 | if err != nil { |
| 194 | return err |
| 195 | } |
| 196 | |
| 197 | const dialNetwork = "tcp4" |
| 198 | connection, err := dialer.DialContext(ctx, dialNetwork, address) |
| 199 | if err != nil { |
| 200 | return fmt.Errorf("dialing: %w", err) |
| 201 | } |
| 202 | |
| 203 | if strings.HasSuffix(address, ":443") { |
| 204 | host, _, err := net.SplitHostPort(address) |
| 205 | if err != nil { |
| 206 | return fmt.Errorf("splitting host and port: %w", err) |
| 207 | } |
| 208 | tlsConfig := &tls.Config{ |
| 209 | MinVersion: tls.VersionTLS12, |
| 210 | ServerName: host, |
| 211 | } |
| 212 | tlsConnection := tls.Client(connection, tlsConfig) |
| 213 | err = tlsConnection.HandshakeContext(ctx) |
| 214 | if err != nil { |
| 215 | return fmt.Errorf("running TLS handshake: %w", err) |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | err = connection.Close() |
| 220 | if err != nil { |
| 221 | return fmt.Errorf("closing connection: %w", err) |
| 222 | } |
| 223 | |
| 224 | return nil |
| 225 | } |
| 226 | |
| 227 | func makeAddressToDial(address string) (addressToDial string, err error) { |
| 228 | host, port, err := net.SplitHostPort(address) |
no test coverage detected