Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
golangci-lint upgrade to v1.56.2 added more checks

Relates to .goassets/#201
  • Loading branch information
Sean-Der committed Mar 16, 2024
1 parent 2597464 commit 96b8c29
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions cipher_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
})
Expand Down
10 changes: 5 additions & 5 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand Down Expand Up @@ -108,15 +108,15 @@ 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
},
},
},
"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
},
},
Expand Down
2 changes: 1 addition & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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{},
Expand All @@ -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{},
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/pion/dtls/v2/pkg/crypto/hash"
)

// nolint: gosec
const rawPrivateKey = `
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAxIA2BrrnR2sIlATsp7aRBD/3krwZ7vt9dNeoDQAee0s6SuYP
Expand Down
4 changes: 2 additions & 2 deletions handshaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions pkg/protocol/handshake/message_server_key_exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 96b8c29

Please sign in to comment.