From e754b8ac8855ff3e6df5e07a0618b59e8744032d Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 12 Apr 2023 11:48:52 +0200 Subject: [PATCH] Fix new golangci-lint errors --- conn_test.go | 2 +- flight0handler.go | 4 ++-- flight1handler.go | 2 +- flight2handler.go | 2 +- flight3handler.go | 2 +- flight4bhandler.go | 4 ++-- flight4handler.go | 2 +- flight4handler_test.go | 4 ++-- flight5bhandler.go | 4 ++-- flight5handler.go | 2 +- flight6handler.go | 4 ++-- handshaker_test.go | 6 +++--- pkg/crypto/ccm/ccm_test.go | 4 ++-- pkg/crypto/ciphersuite/ccm.go | 2 +- pkg/crypto/ciphersuite/gcm.go | 2 +- .../clientcertificate/client_certificate.go | 2 +- pkg/crypto/prf/prf.go | 10 +++++----- .../handshake/message_hello_verify_request.go | 20 +++++++++---------- .../handshake/message_server_hello_done.go | 2 +- resume_test.go | 6 +++--- state.go | 6 ++---- 21 files changed, 45 insertions(+), 47 deletions(-) diff --git a/conn_test.go b/conn_test.go index d9e76860f..f4666b9fb 100644 --- a/conn_test.go +++ b/conn_test.go @@ -2298,7 +2298,7 @@ func TestALPNExtension(t *testing.T) { SupportedProtocols: test.ServerProtocolNameList, } if _, err2 := testServer(ctx2, cb2, conf, true); !errors.Is(err2, context.Canceled) { - if test.ExpectAlertFromServer { + if test.ExpectAlertFromServer { //nolint // Assert the error type? } else { t.Error(err2) diff --git a/flight0handler.go b/flight0handler.go index fa4720e0e..57d94ce2b 100644 --- a/flight0handler.go +++ b/flight0handler.go @@ -11,7 +11,7 @@ import ( "github.com/pion/dtls/v2/pkg/protocol/handshake" ) -func flight0Parse(ctx context.Context, c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) { +func flight0Parse(_ context.Context, _ flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) { seq, msgs, ok := cache.fullPullMap(0, state.cipherSuite, handshakeCachePullRule{handshake.TypeClientHello, cfg.initialEpoch, true, false}, ) @@ -113,7 +113,7 @@ func handleHelloResume(sessionID []byte, state *State, cfg *handshakeConfig, nex return next, nil, nil } -func flight0Generate(c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { +func flight0Generate(_ flightConn, state *State, _ *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { // Initialize if !cfg.insecureSkipHelloVerify { state.cookie = make([]byte, cookieLength) diff --git a/flight1handler.go b/flight1handler.go index 7cfcea8fb..80530bd31 100644 --- a/flight1handler.go +++ b/flight1handler.go @@ -43,7 +43,7 @@ func flight1Parse(ctx context.Context, c flightConn, state *State, cache *handsh return 0, &alert.Alert{Level: alert.Fatal, Description: alert.InternalError}, nil } -func flight1Generate(c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { +func flight1Generate(c flightConn, state *State, _ *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { var zeroEpoch uint16 state.localEpoch.Store(zeroEpoch) state.remoteEpoch.Store(zeroEpoch) diff --git a/flight2handler.go b/flight2handler.go index 9a1bf34f7..c4c7202ed 100644 --- a/flight2handler.go +++ b/flight2handler.go @@ -41,7 +41,7 @@ func flight2Parse(ctx context.Context, c flightConn, state *State, cache *handsh return flight4, nil, nil } -func flight2Generate(c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { +func flight2Generate(_ flightConn, state *State, _ *handshakeCache, _ *handshakeConfig) ([]*packet, *alert.Alert, error) { state.handshakeSendSequence = 0 return []*packet{ { diff --git a/flight3handler.go b/flight3handler.go index 0a8c5d952..561b03afd 100644 --- a/flight3handler.go +++ b/flight3handler.go @@ -224,7 +224,7 @@ func handleServerKeyExchange(_ flightConn, state *State, cfg *handshakeConfig, h return nil, nil //nolint:nilnil } -func flight3Generate(c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { +func flight3Generate(_ flightConn, state *State, _ *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { extensions := []extension.Extension{ &extension.SupportedSignatureAlgorithms{ SignatureHashAlgorithms: cfg.localSignatureSchemes, diff --git a/flight4bhandler.go b/flight4bhandler.go index 46515c57f..79d1e27b4 100644 --- a/flight4bhandler.go +++ b/flight4bhandler.go @@ -12,7 +12,7 @@ import ( "github.com/pion/dtls/v2/pkg/protocol/recordlayer" ) -func flight4bParse(ctx context.Context, c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) { +func flight4bParse(_ context.Context, _ flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) { _, msgs, ok := cache.fullPullMap(state.handshakeRecvSequence, state.cipherSuite, handshakeCachePullRule{handshake.TypeFinished, cfg.initialEpoch + 1, true, false}, ) @@ -44,7 +44,7 @@ func flight4bParse(ctx context.Context, c flightConn, state *State, cache *hands return flight4b, nil, nil } -func flight4bGenerate(c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { +func flight4bGenerate(_ flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { var pkts []*packet extensions := []extension.Extension{&extension.RenegotiationInfo{ diff --git a/flight4handler.go b/flight4handler.go index 9792e0a92..94668f9cd 100644 --- a/flight4handler.go +++ b/flight4handler.go @@ -215,7 +215,7 @@ func flight4Parse(ctx context.Context, c flightConn, state *State, cache *handsh return flight6, nil, nil } -func flight4Generate(c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { +func flight4Generate(_ flightConn, state *State, _ *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { extensions := []extension.Extension{&extension.RenegotiationInfo{ RenegotiatedConnection: 0, }} diff --git a/flight4handler_test.go b/flight4handler_test.go index 46d3fb7b7..89c1e1e1a 100644 --- a/flight4handler_test.go +++ b/flight4handler_test.go @@ -13,12 +13,12 @@ import ( type flight4TestMockFlightConn struct{} -func (f *flight4TestMockFlightConn) notify(ctx context.Context, level alert.Level, desc alert.Description) error { +func (f *flight4TestMockFlightConn) notify(context.Context, alert.Level, alert.Description) error { return nil } func (f *flight4TestMockFlightConn) writePackets(context.Context, []*packet) error { return nil } func (f *flight4TestMockFlightConn) recvHandshake() <-chan chan struct{} { return nil } -func (f *flight4TestMockFlightConn) setLocalEpoch(epoch uint16) {} +func (f *flight4TestMockFlightConn) setLocalEpoch(uint16) {} func (f *flight4TestMockFlightConn) handleQueuedPackets(context.Context) error { return nil } func (f *flight4TestMockFlightConn) sessionKey() []byte { return nil } diff --git a/flight5bhandler.go b/flight5bhandler.go index bd330d515..5fbc6a4ff 100644 --- a/flight5bhandler.go +++ b/flight5bhandler.go @@ -10,7 +10,7 @@ import ( "github.com/pion/dtls/v2/pkg/protocol/recordlayer" ) -func flight5bParse(ctx context.Context, c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) { +func flight5bParse(_ context.Context, _ flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) { _, msgs, ok := cache.fullPullMap(state.handshakeRecvSequence-1, state.cipherSuite, handshakeCachePullRule{handshake.TypeFinished, cfg.initialEpoch + 1, false, false}, ) @@ -27,7 +27,7 @@ func flight5bParse(ctx context.Context, c flightConn, state *State, cache *hands return flight5b, nil, nil } -func flight5bGenerate(c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { //nolint:gocognit +func flight5bGenerate(_ flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { //nolint:gocognit var pkts []*packet pkts = append(pkts, diff --git a/flight5handler.go b/flight5handler.go index 5a60973d7..b5b42ab0b 100644 --- a/flight5handler.go +++ b/flight5handler.go @@ -14,7 +14,7 @@ import ( "github.com/pion/dtls/v2/pkg/protocol/recordlayer" ) -func flight5Parse(ctx context.Context, c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) { +func flight5Parse(_ context.Context, c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) { _, msgs, ok := cache.fullPullMap(state.handshakeRecvSequence, state.cipherSuite, handshakeCachePullRule{handshake.TypeFinished, cfg.initialEpoch + 1, false, false}, ) diff --git a/flight6handler.go b/flight6handler.go index d3d62f05b..15d9c8527 100644 --- a/flight6handler.go +++ b/flight6handler.go @@ -10,7 +10,7 @@ import ( "github.com/pion/dtls/v2/pkg/protocol/recordlayer" ) -func flight6Parse(ctx context.Context, c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) { +func flight6Parse(_ context.Context, _ flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) (flightVal, *alert.Alert, error) { _, msgs, ok := cache.fullPullMap(state.handshakeRecvSequence-1, state.cipherSuite, handshakeCachePullRule{handshake.TypeFinished, cfg.initialEpoch + 1, true, false}, ) @@ -27,7 +27,7 @@ func flight6Parse(ctx context.Context, c flightConn, state *State, cache *handsh return flight6, nil, nil } -func flight6Generate(c flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { +func flight6Generate(_ flightConn, state *State, cache *handshakeCache, cfg *handshakeConfig) ([]*packet, *alert.Alert, error) { var pkts []*packet pkts = append(pkts, diff --git a/handshaker_test.go b/handshaker_test.go index 2a99684db..fd31106ae 100644 --- a/handshaker_test.go +++ b/handshaker_test.go @@ -391,11 +391,11 @@ func (c *flightTestConn) setLocalEpoch(epoch uint16) { c.epoch = epoch } -func (c *flightTestConn) notify(ctx context.Context, level alert.Level, desc alert.Description) error { +func (c *flightTestConn) notify(context.Context, alert.Level, alert.Description) error { return nil } -func (c *flightTestConn) writePackets(ctx context.Context, pkts []*packet) error { +func (c *flightTestConn) writePackets(_ context.Context, pkts []*packet) error { time.Sleep(c.delay) for _, p := range pkts { if c.filter != nil && !c.filter(p) { @@ -436,7 +436,7 @@ func (c *flightTestConn) writePackets(ctx context.Context, pkts []*packet) error return nil } -func (c *flightTestConn) handleQueuedPackets(ctx context.Context) error { +func (c *flightTestConn) handleQueuedPackets(context.Context) error { return nil } diff --git a/pkg/crypto/ccm/ccm_test.go b/pkg/crypto/ccm/ccm_test.go index a5ee795c1..f9da3bdce 100644 --- a/pkg/crypto/ccm/ccm_test.go +++ b/pkg/crypto/ccm/ccm_test.go @@ -238,8 +238,8 @@ func TestRFC3610Vectors(t *testing.T) { } if len(cases) != 24 { - t.Fatalf("Expected %d test cases, got: %d", 24, len(cases)) - t.FailNow() + t.Fatalf("Expected %d test cases, got: %d", 24, len(cases)) //nolint:revive + t.FailNow() //nolint:revive } for idx, c := range cases { diff --git a/pkg/crypto/ciphersuite/ccm.go b/pkg/crypto/ciphersuite/ccm.go index 354b1cc50..98f6bce7d 100644 --- a/pkg/crypto/ciphersuite/ccm.go +++ b/pkg/crypto/ciphersuite/ccm.go @@ -98,7 +98,7 @@ func (c *CCM) Decrypt(in []byte) ([]byte, error) { additionalData := generateAEADAdditionalData(&h, len(out)-int(c.tagLen)) out, err = c.remoteCCM.Open(out[:0], nonce, out, additionalData) if err != nil { - return nil, fmt.Errorf("%w: %v", errDecryptPacket, err) + return nil, fmt.Errorf("%w: %v", errDecryptPacket, err) //nolint:errorlint } return append(in[:recordlayer.HeaderSize], out...), nil } diff --git a/pkg/crypto/ciphersuite/gcm.go b/pkg/crypto/ciphersuite/gcm.go index af986d46e..9115e85c7 100644 --- a/pkg/crypto/ciphersuite/gcm.go +++ b/pkg/crypto/ciphersuite/gcm.go @@ -94,7 +94,7 @@ func (g *GCM) Decrypt(in []byte) ([]byte, error) { additionalData := generateAEADAdditionalData(&h, len(out)-gcmTagLength) out, err = g.remoteGCM.Open(out[:0], nonce, out, additionalData) if err != nil { - return nil, fmt.Errorf("%w: %v", errDecryptPacket, err) + return nil, fmt.Errorf("%w: %v", errDecryptPacket, err) //nolint:errorlint } return append(in[:recordlayer.HeaderSize], out...), nil } diff --git a/pkg/crypto/clientcertificate/client_certificate.go b/pkg/crypto/clientcertificate/client_certificate.go index c222c01c7..7af5f9320 100644 --- a/pkg/crypto/clientcertificate/client_certificate.go +++ b/pkg/crypto/clientcertificate/client_certificate.go @@ -4,7 +4,7 @@ package clientcertificate // Type is used to communicate what // type of certificate is being transported // -//https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-2 +// https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-2 type Type byte // ClientCertificateType enums diff --git a/pkg/crypto/prf/prf.go b/pkg/crypto/prf/prf.go index 11f53a190..8afac4240 100644 --- a/pkg/crypto/prf/prf.go +++ b/pkg/crypto/prf/prf.go @@ -135,14 +135,14 @@ func ellipticCurvePreMasterSecret(publicKey, privateKey []byte, c1, c2 ellipticS // specify a PRF and, in general, SHOULD use the TLS PRF with SHA-256 or a // stronger standard hash function. // -// P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) + -// HMAC_hash(secret, A(2) + seed) + -// HMAC_hash(secret, A(3) + seed) + ... +// P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) + +// HMAC_hash(secret, A(2) + seed) + +// HMAC_hash(secret, A(3) + seed) + ... // // A() is defined as: // -// A(0) = seed -// A(i) = HMAC_hash(secret, A(i-1)) +// A(0) = seed +// A(i) = HMAC_hash(secret, A(i-1)) // // P_hash can be iterated as many times as necessary to produce the // required quantity of data. For example, if P_SHA256 is being used to diff --git a/pkg/protocol/handshake/message_hello_verify_request.go b/pkg/protocol/handshake/message_hello_verify_request.go index 20c63773d..e3313574a 100644 --- a/pkg/protocol/handshake/message_hello_verify_request.go +++ b/pkg/protocol/handshake/message_hello_verify_request.go @@ -6,19 +6,19 @@ import ( // MessageHelloVerifyRequest is as follows: // -// struct { -// ProtocolVersion server_version; -// opaque cookie<0..2^8-1>; -// } HelloVerifyRequest; +// struct { +// ProtocolVersion server_version; +// opaque cookie<0..2^8-1>; +// } HelloVerifyRequest; // -// The HelloVerifyRequest message type is hello_verify_request(3). +// The HelloVerifyRequest message type is hello_verify_request(3). // -// When the client sends its ClientHello message to the server, the server -// MAY respond with a HelloVerifyRequest message. This message contains -// a stateless cookie generated using the technique of [PHOTURIS]. The -// client MUST retransmit the ClientHello with the cookie added. +// When the client sends its ClientHello message to the server, the server +// MAY respond with a HelloVerifyRequest message. This message contains +// a stateless cookie generated using the technique of [PHOTURIS]. The +// client MUST retransmit the ClientHello with the cookie added. // -// https://tools.ietf.org/html/rfc6347#section-4.2.1 +// https://tools.ietf.org/html/rfc6347#section-4.2.1 type MessageHelloVerifyRequest struct { Version protocol.Version Cookie []byte diff --git a/pkg/protocol/handshake/message_server_hello_done.go b/pkg/protocol/handshake/message_server_hello_done.go index 0f65b198e..458414312 100644 --- a/pkg/protocol/handshake/message_server_hello_done.go +++ b/pkg/protocol/handshake/message_server_hello_done.go @@ -16,6 +16,6 @@ func (m *MessageServerHelloDone) Marshal() ([]byte, error) { } // Unmarshal populates the message from encoded data -func (m *MessageServerHelloDone) Unmarshal(data []byte) error { +func (m *MessageServerHelloDone) Unmarshal([]byte) error { return nil } diff --git a/resume_test.go b/resume_test.go index 166240393..a38e9f7a2 100644 --- a/resume_test.go +++ b/resume_test.go @@ -195,14 +195,14 @@ func (b *backupConn) RemoteAddr() net.Addr { return nil } -func (b *backupConn) SetDeadline(t time.Time) error { +func (b *backupConn) SetDeadline(time.Time) error { return nil } -func (b *backupConn) SetReadDeadline(t time.Time) error { +func (b *backupConn) SetReadDeadline(time.Time) error { return nil } -func (b *backupConn) SetWriteDeadline(t time.Time) error { +func (b *backupConn) SetWriteDeadline(time.Time) error { return nil } diff --git a/state.go b/state.go index 22c65c744..306bae905 100644 --- a/state.go +++ b/state.go @@ -169,10 +169,8 @@ func (s *State) UnmarshalBinary(data []byte) error { } s.deserialize(serialized) - if err := s.initCipherSuite(); err != nil { - return err - } - return nil + + return s.initCipherSuite() } // ExportKeyingMaterial returns length bytes of exported key material in a new