From 58b31713fcbc8723a769b3c217d2e04f63e0bc75 Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Mon, 29 Jul 2024 11:59:00 -0300 Subject: [PATCH] fix: removing unused verifiedChains parameter, replacing fmt errors %v by %w and unused test log --- direct.go | 12 ++++++------ direct_test.go | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/direct.go b/direct.go index 4357bec..de9e330 100644 --- a/direct.go +++ b/direct.go @@ -427,9 +427,9 @@ func (d *direct) dialServerWith(m *Masquerade) (net.Conn, error) { op.Set("arbitrary_sni", m.SNI) tlsConfig.ServerName = m.SNI tlsConfig.InsecureSkipVerify = true - tlsConfig.VerifyPeerCertificate = func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error { + tlsConfig.VerifyPeerCertificate = func(rawCerts [][]byte, _ [][]*x509.Certificate) error { log.Tracef("verifying peer certificate for masquerade domain %s", m.Domain) - return verifyPeerCertificate(rawCerts, verifiedChains, d.certPool, m.Domain) + return verifyPeerCertificate(rawCerts, d.certPool, m.Domain) } } @@ -454,13 +454,13 @@ func (d *direct) dialServerWith(m *Masquerade) (net.Conn, error) { return conn, err } -func verifyPeerCertificate(rawCerts [][]byte, verifiedChains [][]*x509.Certificate, roots *x509.CertPool, domain string) error { +func verifyPeerCertificate(rawCerts [][]byte, roots *x509.CertPool, domain string) error { if len(rawCerts) == 0 { return fmt.Errorf("no certificates presented") } cert, err := x509.ParseCertificate(rawCerts[0]) if err != nil { - return fmt.Errorf("unable to parse certificate: %v", err) + return fmt.Errorf("unable to parse certificate: %w", err) } masqueradeOpts := x509.VerifyOptions{ @@ -476,14 +476,14 @@ func verifyPeerCertificate(rawCerts [][]byte, verifiedChains [][]*x509.Certifica } crt, err := x509.ParseCertificate(rawCerts[i]) if err != nil { - return fmt.Errorf("unable to parse intermediate certificate: %v", err) + return fmt.Errorf("unable to parse intermediate certificate: %w", err) } masqueradeOpts.Intermediates.AddCert(crt) } _, masqueradeErr := cert.Verify(masqueradeOpts) if masqueradeErr != nil { - return fmt.Errorf("certificate verification failed for masquerade: %v", masqueradeErr) + return fmt.Errorf("certificate verification failed for masquerade: %w", masqueradeErr) } return nil diff --git a/direct_test.go b/direct_test.go index 619307a..66c1ad2 100644 --- a/direct_test.go +++ b/direct_test.go @@ -60,7 +60,6 @@ func TestDirectDomainFrontingWithSNIConfig(t *testing.T) { Transport: transport, } require.True(t, doCheck(client, http.MethodGet, http.StatusOK, getURL)) - t.Logf("SNIConfig test passed") } func doTestDomainFronting(t *testing.T, cacheFile string, expectedMasqueradesAtEnd int) int {