(u *url.URL)
| 192 | } |
| 193 | |
| 194 | func TLSConfigFromURL(u *url.URL) (*tls.Config, error) { |
| 195 | host := u.Hostname() |
| 196 | params, err := url.ParseQuery(u.RawQuery) |
| 197 | if err != nil { |
| 198 | return nil, fmt.Errorf("unable to parse query string of proxy specification URL %q: %w", u.String(), err) |
| 199 | } |
| 200 | tlsConfig := &tls.Config{ |
| 201 | ServerName: host, |
| 202 | ClientSessionCache: SessionCache, |
| 203 | } |
| 204 | if params.Has("cafile") { |
| 205 | roots, err := LoadCAfile(params.Get("cafile")) |
| 206 | if err != nil { |
| 207 | return nil, err |
| 208 | } |
| 209 | tlsConfig.RootCAs = roots |
| 210 | } |
| 211 | if params.Has("sni") { |
| 212 | newServerName := params.Get("sni") |
| 213 | tlsConfig.ServerName = newServerName |
| 214 | tlsConfig.InsecureSkipVerify = true |
| 215 | tlsConfig.VerifyConnection = ExpectPeerName(host, tlsConfig.RootCAs) |
| 216 | tlsConfig.ClientSessionCache = wrapCacheWithKeyRewrite(newServerName, host, SessionCache) |
| 217 | } |
| 218 | if params.Has("peername") { |
| 219 | tlsConfig.InsecureSkipVerify = true |
| 220 | tlsConfig.VerifyConnection = ExpectPeerName(params.Get("peername"), tlsConfig.RootCAs) |
| 221 | } |
| 222 | if params.Has("cert") { |
| 223 | cert, err := tls.LoadX509KeyPair(params.Get("cert"), params.Get("key")) |
| 224 | if err != nil { |
| 225 | return nil, err |
| 226 | } |
| 227 | tlsConfig.Certificates = []tls.Certificate{cert} |
| 228 | } |
| 229 | if params.Has("ciphers") { |
| 230 | cipherList, err := ParseCipherList(params.Get("ciphers")) |
| 231 | if err != nil { |
| 232 | return nil, err |
| 233 | } |
| 234 | tlsConfig.CipherSuites = cipherList |
| 235 | } |
| 236 | if params.Has("curves") { |
| 237 | curveList, err := ParseCurveList(params.Get("curves")) |
| 238 | if err != nil { |
| 239 | return nil, err |
| 240 | } |
| 241 | tlsConfig.CurvePreferences = curveList |
| 242 | } |
| 243 | if params.Has("min-tls-version") { |
| 244 | ver, err := ParseVersion(params.Get("min-tls-version")) |
| 245 | if err != nil { |
| 246 | return nil, err |
| 247 | } |
| 248 | tlsConfig.MinVersion = ver |
| 249 | } |
| 250 | if params.Has("max-tls-version") { |
| 251 | ver, err := ParseVersion(params.Get("max-tls-version")) |
no test coverage detected