From 96b8c2993ac4eceffd5483fd05b3819ac7a8ea65 Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Fri, 15 Mar 2024 22:08:44 -0400 Subject: [PATCH] Fix linter errors golangci-lint upgrade to v1.56.2 added more checks Relates to .goassets/#201 --- certificate_test.go | 2 +- cipher_suite_test.go | 4 ++-- config_test.go | 10 ++++---- conn.go | 2 +- conn_test.go | 24 +++++++++---------- crypto_test.go | 1 + handshaker_test.go | 4 ++-- .../message_server_key_exchange_test.go | 4 ++-- 8 files changed, 26 insertions(+), 25 deletions(-) diff --git a/certificate_test.go b/certificate_test.go index 5f2e87bb4..8c0868f45 100644 --- a/certificate_test.go +++ b/certificate_test.go @@ -77,7 +77,7 @@ func TestGetCertificate(t *testing.T) { }, { desc: "Get certificate from callback", - getCertificate: func(info *ClientHelloInfo) (*tls.Certificate, error) { + getCertificate: func(*ClientHelloInfo) (*tls.Certificate, error) { return &certificateTest, nil }, expectedCertificate: certificateTest, diff --git a/cipher_suite_test.go b/cipher_suite_test.go index c04220dee..3aa4c8fe6 100644 --- a/cipher_suite_test.go +++ b/cipher_suite_test.go @@ -98,13 +98,13 @@ func TestCustomCipherSuite(t *testing.T) { } } - t.Run("Custom ID", func(t *testing.T) { + t.Run("Custom ID", func(*testing.T) { runTest(func() []CipherSuite { return []CipherSuite{&testCustomCipherSuite{authenticationType: CipherSuiteAuthenticationTypeCertificate}} }) }) - t.Run("Anonymous Cipher", func(t *testing.T) { + t.Run("Anonymous Cipher", func(*testing.T) { runTest(func() []CipherSuite { return []CipherSuite{&testCustomCipherSuite{authenticationType: CipherSuiteAuthenticationTypeAnonymous}} }) diff --git a/config_test.go b/config_test.go index 811427a0c..806d66929 100644 --- a/config_test.go +++ b/config_test.go @@ -47,7 +47,7 @@ func TestValidateConfig(t *testing.T) { "PSK and Certificate, valid cipher suites": { config: &Config{ CipherSuites: []CipherSuiteID{TLS_PSK_WITH_AES_128_CCM_8, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, - PSK: func(hint []byte) ([]byte, error) { + PSK: func([]byte) ([]byte, error) { return nil, nil }, Certificates: []tls.Certificate{cert}, @@ -56,7 +56,7 @@ func TestValidateConfig(t *testing.T) { "PSK and Certificate, no PSK cipher suite": { config: &Config{ CipherSuites: []CipherSuiteID{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, - PSK: func(hint []byte) ([]byte, error) { + PSK: func([]byte) ([]byte, error) { return nil, nil }, Certificates: []tls.Certificate{cert}, @@ -66,7 +66,7 @@ func TestValidateConfig(t *testing.T) { "PSK and Certificate, no non-PSK cipher suite": { config: &Config{ CipherSuites: []CipherSuiteID{TLS_PSK_WITH_AES_128_CCM_8}, - PSK: func(hint []byte) ([]byte, error) { + PSK: func([]byte) ([]byte, error) { return nil, nil }, Certificates: []tls.Certificate{cert}, @@ -108,7 +108,7 @@ func TestValidateConfig(t *testing.T) { "Valid config with get certificate": { config: &Config{ CipherSuites: []CipherSuiteID{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, - GetCertificate: func(chi *ClientHelloInfo) (*tls.Certificate, error) { + GetCertificate: func(*ClientHelloInfo) (*tls.Certificate, error) { return &tls.Certificate{Certificate: cert.Certificate, PrivateKey: rsaPrivateKey}, nil }, }, @@ -116,7 +116,7 @@ func TestValidateConfig(t *testing.T) { "Valid config with get client certificate": { config: &Config{ CipherSuites: []CipherSuiteID{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, - GetClientCertificate: func(cri *CertificateRequestInfo) (*tls.Certificate, error) { + GetClientCertificate: func(*CertificateRequestInfo) (*tls.Certificate, error) { return &tls.Certificate{Certificate: cert.Certificate, PrivateKey: rsaPrivateKey}, nil }, }, diff --git a/conn.go b/conn.go index b1f552537..d4259f9e8 100644 --- a/conn.go +++ b/conn.go @@ -972,7 +972,7 @@ func (c *Conn) handshake(ctx context.Context, cfg *handshakeConfig, initialFligh done := make(chan struct{}) ctxRead, cancelRead := context.WithCancel(context.Background()) c.cancelHandshakeReader = cancelRead - cfg.onFlightState = func(f flightVal, s handshakeState) { + cfg.onFlightState = func(_ flightVal, s handshakeState) { if s == handshakeFinished && !c.isHandshakeCompletedSuccessfully() { c.setHandshakeCompletedSuccessfully() close(done) diff --git a/conn_test.go b/conn_test.go index f0264df15..f0a961afc 100644 --- a/conn_test.go +++ b/conn_test.go @@ -424,7 +424,7 @@ func TestHandshakeWithInvalidRecord(t *testing.T) { var msgSeq atomic.Int32 // Send invalid record after first message - caWithInvalidRecord.onWrite = func(b []byte) { + caWithInvalidRecord.onWrite = func([]byte) { if msgSeq.Add(1) == 2 { if _, err := ca.Write([]byte{0x01, 0x02}); err != nil { t.Fatal(err) @@ -556,7 +556,7 @@ func TestPSK(t *testing.T) { Name: "Server identity specified - Server verify connection fails", ServerIdentity: []byte("Test Identity"), CipherSuites: []CipherSuiteID{TLS_PSK_WITH_AES_128_CCM_8}, - ServerVerifyConnection: func(s *State) error { + ServerVerifyConnection: func(*State) error { return errExample }, WantFail: true, @@ -567,7 +567,7 @@ func TestPSK(t *testing.T) { Name: "Server identity specified - Client verify connection fails", ServerIdentity: []byte("Test Identity"), CipherSuites: []CipherSuiteID{TLS_PSK_WITH_AES_128_CCM_8}, - ClientVerifyConnection: func(s *State) error { + ClientVerifyConnection: func(*State) error { return errExample }, WantFail: true, @@ -685,7 +685,7 @@ func TestPSKHintFail(t *testing.T) { ca, cb := dpipe.Pipe() go func() { conf := &Config{ - PSK: func(hint []byte) ([]byte, error) { + PSK: func([]byte) ([]byte, error) { return nil, pskRejected }, PSKIdentityHint: []byte{}, @@ -697,7 +697,7 @@ func TestPSKHintFail(t *testing.T) { }() config := &Config{ - PSK: func(hint []byte) ([]byte, error) { + PSK: func([]byte) ([]byte, error) { return nil, pskRejected }, PSKIdentityHint: []byte{}, @@ -905,14 +905,14 @@ func TestClientCertificate(t *testing.T) { Certificates: []tls.Certificate{srvCert}, ClientAuth: NoClientCert, ClientCAs: caPool, - VerifyConnection: func(s *State) error { + VerifyConnection: func(*State) error { return errExample }, }, wantErr: true, }, "NoClientCert_ClientVerifyConnectionFails": { - clientCfg: &Config{RootCAs: srvCAPool, VerifyConnection: func(s *State) error { + clientCfg: &Config{RootCAs: srvCAPool, VerifyConnection: func(*State) error { return errExample }}, serverCfg: &Config{ @@ -1014,10 +1014,10 @@ func TestClientCertificate(t *testing.T) { clientCfg: &Config{ RootCAs: srvCAPool, // Certificates: []tls.Certificate{cert}, - GetClientCertificate: func(cri *CertificateRequestInfo) (*tls.Certificate, error) { return &cert, nil }, + GetClientCertificate: func(*CertificateRequestInfo) (*tls.Certificate, error) { return &cert, nil }, }, serverCfg: &Config{ - GetCertificate: func(chi *ClientHelloInfo) (*tls.Certificate, error) { return &srvCert, nil }, + GetCertificate: func(*ClientHelloInfo) (*tls.Certificate, error) { return &srvCert, nil }, // Certificates: []tls.Certificate{srvCert}, ClientAuth: RequireAndVerifyClientCert, ClientCAs: caPool, @@ -1408,7 +1408,7 @@ func TestServerCertificate(t *testing.T) { }, "good_ca_skip_verify_custom_verify_peer": { clientCfg: &Config{RootCAs: caPool, Certificates: []tls.Certificate{cert}}, - serverCfg: &Config{Certificates: []tls.Certificate{cert}, ClientAuth: RequireAnyClientCert, VerifyPeerCertificate: func(cert [][]byte, chain [][]*x509.Certificate) error { + serverCfg: &Config{Certificates: []tls.Certificate{cert}, ClientAuth: RequireAnyClientCert, VerifyPeerCertificate: func(_ [][]byte, chain [][]*x509.Certificate) error { if len(chain) != 0 { return errNotExpectedChain } @@ -1417,7 +1417,7 @@ func TestServerCertificate(t *testing.T) { }, "good_ca_verify_custom_verify_peer": { clientCfg: &Config{RootCAs: caPool, Certificates: []tls.Certificate{cert}}, - serverCfg: &Config{ClientCAs: caPool, Certificates: []tls.Certificate{cert}, ClientAuth: RequireAndVerifyClientCert, VerifyPeerCertificate: func(cert [][]byte, chain [][]*x509.Certificate) error { + serverCfg: &Config{ClientCAs: caPool, Certificates: []tls.Certificate{cert}, ClientAuth: RequireAndVerifyClientCert, VerifyPeerCertificate: func(_ [][]byte, chain [][]*x509.Certificate) error { if len(chain) == 0 { return errExpecedChain } @@ -2996,7 +2996,7 @@ func TestMultipleServerCertificates(t *testing.T) { c, err := testClient(context.TODO(), dtlsnet.PacketConnFromConn(ca), ca.RemoteAddr(), &Config{ RootCAs: caPool, ServerName: test.RequestServerName, - VerifyPeerCertificate: func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error { + VerifyPeerCertificate: func(rawCerts [][]byte, _ [][]*x509.Certificate) error { certificate, err := x509.ParseCertificate(rawCerts[0]) if err != nil { return err diff --git a/crypto_test.go b/crypto_test.go index 771ea3afa..3b88fccee 100644 --- a/crypto_test.go +++ b/crypto_test.go @@ -13,6 +13,7 @@ import ( "github.com/pion/dtls/v2/pkg/crypto/hash" ) +// nolint: gosec const rawPrivateKey = ` -----BEGIN RSA PRIVATE KEY----- MIIEowIBAAKCAQEAxIA2BrrnR2sIlATsp7aRBD/3krwZ7vt9dNeoDQAee0s6SuYP diff --git a/handshaker_test.go b/handshaker_test.go index f869959d2..9bbca6f50 100644 --- a/handshaker_test.go +++ b/handshaker_test.go @@ -271,7 +271,7 @@ func TestHandshaker(t *testing.T) { localSignatureSchemes: signaturehash.Algorithms(), insecureSkipVerify: true, log: logger, - onFlightState: func(f flightVal, s handshakeState) { + onFlightState: func(_ flightVal, s handshakeState) { if s == handshakeFinished { if clientEndpoint.OnFinished != nil { clientEndpoint.OnFinished() @@ -304,7 +304,7 @@ func TestHandshaker(t *testing.T) { localSignatureSchemes: signaturehash.Algorithms(), insecureSkipVerify: true, log: logger, - onFlightState: func(f flightVal, s handshakeState) { + onFlightState: func(_ flightVal, s handshakeState) { if s == handshakeFinished { if serverEndpoint.OnFinished != nil { serverEndpoint.OnFinished() diff --git a/pkg/protocol/handshake/message_server_key_exchange_test.go b/pkg/protocol/handshake/message_server_key_exchange_test.go index acfc17964..7e960ce03 100644 --- a/pkg/protocol/handshake/message_server_key_exchange_test.go +++ b/pkg/protocol/handshake/message_server_key_exchange_test.go @@ -32,7 +32,7 @@ func TestHandshakeMessageServerKeyExchange(t *testing.T) { } } - t.Run("Hash+Signature", func(t *testing.T) { + t.Run("Hash+Signature", func(*testing.T) { rawServerKeyExchange := []byte{ 0x03, 0x00, 0x1d, 0x41, 0x04, 0x0c, 0xb9, 0xa3, 0xb9, 0x90, 0x71, 0x35, 0x4a, 0x08, 0x66, 0xaf, 0xd6, 0x88, 0x58, 0x29, 0x69, 0x98, 0xf1, 0x87, 0x0f, 0xb5, 0xa8, 0xcd, 0x92, 0xf6, 0x2b, 0x08, @@ -57,7 +57,7 @@ func TestHandshakeMessageServerKeyExchange(t *testing.T) { test(rawServerKeyExchange, parsedServerKeyExchange) }) - t.Run("Anonymous", func(t *testing.T) { + t.Run("Anonymous", func(*testing.T) { rawServerKeyExchange := []byte{ 0x03, 0x00, 0x1d, 0x41, 0x04, 0x0c, 0xb9, 0xa3, 0xb9, 0x90, 0x71, 0x35, 0x4a, 0x08, 0x66, 0xaf, 0xd6, 0x88, 0x58, 0x29, 0x69, 0x98, 0xf1, 0x87, 0x0f, 0xb5, 0xa8, 0xcd, 0x92, 0xf6, 0x2b, 0x08,