@@ -390,47 +390,3 @@ func (m firstFormMatcher) matches(n *html.Node) bool {
390
390
func (m firstFormMatcher ) String () string {
391
391
return "first form"
392
392
}
393
-
394
- // NewSkipHostnameVerificationConfig returns a TLS configuration that
395
- // doesn't perform the default certificate verification because it
396
- // will verify the hostname. Instead, it verifies the server's
397
- // certificate chain in VerifyPeerCertificate and ignores the server
398
- // name.
399
- //
400
- // See https://github.com/golang/go/issues/21971#issuecomment-332693931
401
- // and https://pkg.go.dev/crypto/tls?tab=doc#example-Config-VerifyPeerCertificate
402
- // for more info.
403
- func NewSkipHostnameVerificationConfig (rootCAs * x509.CertPool ) * tls.Config {
404
- // Disable "G402 (CWE-295): TLS InsecureSkipVerify set true. (Confidence: HIGH, Severity: HIGH)"
405
- // #nosec G402
406
- return & tls.Config {
407
- // Set to true because otherwise the certs AND the hostname are verified.
408
- // Instead, the certificate verification will be done by the custom
409
- // VerifyPeerCertificate, ignoring the server name,
410
- InsecureSkipVerify : true ,
411
- VerifyPeerCertificate : func (certificates [][]byte , _ [][]* x509.Certificate ) error {
412
- certs := make ([]* x509.Certificate , len (certificates ))
413
- for i , asn1Data := range certificates {
414
- cert , err := x509 .ParseCertificate (asn1Data )
415
- if err != nil {
416
- return fmt .Errorf ("failed to parse certificate from server: %w" , err )
417
- }
418
- certs [i ] = cert
419
- }
420
-
421
- // Leave DNSName empty to skip hostname verification.
422
- opts := x509.VerifyOptions {
423
- Roots : rootCAs ,
424
- Intermediates : x509 .NewCertPool (),
425
- }
426
- // Skip the first cert because it's the leaf. All others
427
- // are intermediates.
428
- for _ , cert := range certs [1 :] {
429
- opts .Intermediates .AddCert (cert )
430
- }
431
-
432
- _ , err := certs [0 ].Verify (opts )
433
- return err
434
- },
435
- }
436
- }
0 commit comments