From 6e7fcad7a6b12a49576aa29ee57a9bc070d5d8a0 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 9 Jun 2021 10:36:34 -0700 Subject: [PATCH] Staticcheck and Connectivtiy Upgrade --- .gitignore | 1 + applications/application_chain.go | 2 +- applications/auth_test.go | 1 - .../tokenboard/tokenboard_integration_test.go | 13 ++++--------- go.mod | 2 +- go.sum | 2 ++ networks/tor/BaseOnionService.go | 2 +- persistence/bolt_persistence_test.go | 3 +-- primitives/auditable/auditablestore.go | 4 ++-- primitives/core/transcript_test.go | 4 +++- primitives/privacypass/tokenserver.go | 4 ++-- testing/tapir_integration_test.go | 6 ++---- testing/tapir_malicious_remote_integration_test.go | 5 ++--- 13 files changed, 22 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index e1e7b51..ba279bf 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ coverage.out *.db /applications/tokenboard/tor/ fuzzing/ +*.cover.out diff --git a/applications/application_chain.go b/applications/application_chain.go index 32d50f9..305ef04 100644 --- a/applications/application_chain.go +++ b/applications/application_chain.go @@ -42,7 +42,7 @@ func (appchain *ApplicationChain) Init(connection tapir.Connection) { for i, app := range appchain.apps { app.PropagateTranscript(appchain.transcript) app.Init(connection) - if connection.HasCapability(appchain.capabilities[i]) == false { + if !connection.HasCapability(appchain.capabilities[i]) { connection.Close() return } diff --git a/applications/auth_test.go b/applications/auth_test.go index be41015..f0b6db1 100644 --- a/applications/auth_test.go +++ b/applications/auth_test.go @@ -17,7 +17,6 @@ type MockConnection struct { func (mc *MockConnection) Init(outbound bool) { mc.id, _ = primitives.InitializeEphemeralIdentity() mc.outbound = outbound - return } func (mc MockConnection) Hostname() string { diff --git a/applications/tokenboard/tokenboard_integration_test.go b/applications/tokenboard/tokenboard_integration_test.go index 0446206..3ac348c 100644 --- a/applications/tokenboard/tokenboard_integration_test.go +++ b/applications/tokenboard/tokenboard_integration_test.go @@ -2,7 +2,6 @@ package tokenboard import ( "errors" - "git.openprivacy.ca/cwtch.im/tapir" "git.openprivacy.ca/cwtch.im/tapir/applications" "git.openprivacy.ca/cwtch.im/tapir/networks/tor" "git.openprivacy.ca/cwtch.im/tapir/primitives" @@ -39,8 +38,7 @@ type FreePaymentHandler struct { func (fph *FreePaymentHandler) MakePayment() { id, sk := primitives.InitializeEphemeralIdentity() - var client tapir.Service - client = new(tor.BaseOnionService) + client := new(tor.BaseOnionService) client.Init(fph.ACN, sk, &id) tokenApplication := new(applications.TokenApplication) @@ -98,8 +96,7 @@ func TestTokenBoardApp(t *testing.T) { clientAuditableStore.Init(publicsid) // Init the Server running the Simple App. - var service tapir.Service - service = new(tor.BaseOnionService) + service := new(tor.BaseOnionService) service.Init(acn, sk, &sid) // Goroutine Management @@ -111,8 +108,7 @@ func TestTokenBoardApp(t *testing.T) { }() // Init the Server running the PoW Token App. - var powTokenService tapir.Service - powTokenService = new(tor.BaseOnionService) + powTokenService := new(tor.BaseOnionService) spowid, spowk := primitives.InitializeEphemeralIdentity() powTokenService.Init(acn, spowk, &spowid) sg.Add(1) @@ -128,8 +124,7 @@ func TestTokenBoardApp(t *testing.T) { time.Sleep(time.Second * 60) // wait for server to initialize id, sk := primitives.InitializeEphemeralIdentity() - var client tapir.Service - client = new(tor.BaseOnionService) + client := new(tor.BaseOnionService) client.Init(acn, sk, &id) client.Connect(sid.Hostname(), NewTokenBoardClient(clientAuditableStore, Handler{Store: clientAuditableStore}, &FreePaymentHandler{ACN: acn, TokenService: tokenService, ServerHostname: spowid.Hostname()})) client.WaitForCapabilityOrClose(sid.Hostname(), applications.AuthCapability) diff --git a/go.mod b/go.mod index 7cf2c1b..5075997 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module git.openprivacy.ca/cwtch.im/tapir require ( - git.openprivacy.ca/openprivacy/connectivity v1.4.3 + git.openprivacy.ca/openprivacy/connectivity v1.4.4 git.openprivacy.ca/openprivacy/log v1.0.2 github.com/davecgh/go-spew v1.1.1 // indirect github.com/gtank/merlin v0.1.1 diff --git a/go.sum b/go.sum index 09fdaaf..1f8cc62 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ git.openprivacy.ca/openprivacy/connectivity v1.4.2 h1:rQFIjWunLlRmXL5Efsv+7+1cA7 git.openprivacy.ca/openprivacy/connectivity v1.4.2/go.mod h1:bR0Myx9nm2YzWtsThRelkNMV4Pp7sPDa123O1qsAbVo= git.openprivacy.ca/openprivacy/connectivity v1.4.3 h1:i2Ad/U9FlL9dKr2bhRck7lJ8NoWyGtoEfUwoCyMT0fU= git.openprivacy.ca/openprivacy/connectivity v1.4.3/go.mod h1:bR0Myx9nm2YzWtsThRelkNMV4Pp7sPDa123O1qsAbVo= +git.openprivacy.ca/openprivacy/connectivity v1.4.4 h1:11M3akVCyy/luuhMpZTM1r9Jayl7IHD944Bxsn2FDpU= +git.openprivacy.ca/openprivacy/connectivity v1.4.4/go.mod h1:JVRCIdL+lAG6ohBFWiKeC/MN42nnC0sfFszR9XG6vPQ= git.openprivacy.ca/openprivacy/log v1.0.1/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw= git.openprivacy.ca/openprivacy/log v1.0.2 h1:HLP4wsw4ljczFAelYnbObIs821z+jgMPCe8uODPnGQM= git.openprivacy.ca/openprivacy/log v1.0.2/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw= diff --git a/networks/tor/BaseOnionService.go b/networks/tor/BaseOnionService.go index 7a2a550..f15b3e2 100644 --- a/networks/tor/BaseOnionService.go +++ b/networks/tor/BaseOnionService.go @@ -158,7 +158,7 @@ func (s *BaseOnionService) Listen(app tapir.Application) error { s.lock.Unlock() if err == nil { - log.Debugf("Starting a service on %v ", ls.AddressFull()) + log.Debugf("Starting a service on %v ", s.ls.AddressFull()) for { conn, err := s.ls.Accept() if err == nil { diff --git a/persistence/bolt_persistence_test.go b/persistence/bolt_persistence_test.go index b88d454..0c2cd3e 100644 --- a/persistence/bolt_persistence_test.go +++ b/persistence/bolt_persistence_test.go @@ -7,8 +7,7 @@ import ( func TestBoltPersistence_Open(t *testing.T) { os.Remove("test.dbgi") - var db Service - db = new(BoltPersistence) + db := new(BoltPersistence) db.Open("test.dbgi") db.Setup([]string{"tokens"}) // 2020.02: Fails in WSL1 because of a mmap issue. diff --git a/primitives/auditable/auditablestore.go b/primitives/auditable/auditablestore.go index 90910a6..df26759 100644 --- a/primitives/auditable/auditablestore.go +++ b/primitives/auditable/auditablestore.go @@ -137,7 +137,7 @@ func (as *Store) AppendState(state State) error { // verify that our state matches the servers signed state // this is *not* a security check, as a rogue server can simply sign any state // however committing to a state allows us to build fraud proofs for malicious servers later on. - if ed25519.Verify(as.identity.PublicKey(), as.LatestCommit, state.SignedProof) == false { + if !ed25519.Verify(as.identity.PublicKey(), as.LatestCommit, state.SignedProof) { return errors.New("state is not consistent, the server is malicious") } return nil @@ -160,7 +160,7 @@ func (as *Store) MergeState(state State) error { // and not the cause (which could be reordered messages, dropped messages, additional messages or any combination) func (as *Store) VerifyFraudProof(fraudCommit []byte, signedFraudProof SignedProof, key ed25519.PublicKey) (bool, error) { - if ed25519.Verify(key, fraudCommit, signedFraudProof) == false { + if !ed25519.Verify(key, fraudCommit, signedFraudProof) { // This could happen due to misuse of this function (trying to verify a proof with the wrong public key) // This could happen if the server lies to us and submits a fake state proof, however we cannot use this to // prove that the server is acting maliciously diff --git a/primitives/core/transcript_test.go b/primitives/core/transcript_test.go index 7f7016d..f161bc6 100644 --- a/primitives/core/transcript_test.go +++ b/primitives/core/transcript_test.go @@ -11,7 +11,9 @@ func TestNewTranscript(t *testing.T) { transcript.AddToTranscript("action", []byte("test data")) - if transcript.OutputTranscriptToAudit() != transcript.OutputTranscriptToAudit() { + firstAudit := transcript.OutputTranscriptToAudit() + secondAudit := transcript.OutputTranscriptToAudit() + if firstAudit != secondAudit { t.Fatalf("Multiple Audit Calls should not impact underlying Transcript") } t.Logf("%v", transcript.OutputTranscriptToAudit()) diff --git a/primitives/privacypass/tokenserver.go b/primitives/privacypass/tokenserver.go index 3d039c8..fb11038 100644 --- a/primitives/privacypass/tokenserver.go +++ b/primitives/privacypass/tokenserver.go @@ -122,7 +122,7 @@ func (ts *TokenServer) SpendToken(token SpentToken, data []byte) error { } } else { spent, err := ts.persistanceService.Check(tokenBucket, hex.EncodeToString(token.T)) - if err != nil || spent == true { + if err != nil || spent { return fmt.Errorf("token: %v has already been spent", token) } } @@ -134,7 +134,7 @@ func (ts *TokenServer) SpendToken(token SpentToken, data []byte) error { mac.Write(data) computedMAC := mac.Sum(nil) result := hmac.Equal(token.MAC, computedMAC) - if result == true { + if result { if ts.persistanceService == nil { ts.seen[hex.EncodeToString(token.T)] = true } else { diff --git a/testing/tapir_integration_test.go b/testing/tapir_integration_test.go index 36c883f..7af2982 100644 --- a/testing/tapir_integration_test.go +++ b/testing/tapir_integration_test.go @@ -76,8 +76,7 @@ func TestTapir(t *testing.T) { id, sk := primitives.InitializeEphemeralIdentity() // Init the Server running the Simple App. - var service tapir.Service - service = new(tor.BaseOnionService) + service := new(tor.BaseOnionService) service.Init(acn, sk, &id) // Goroutine Management @@ -115,8 +114,7 @@ func TestTapir(t *testing.T) { func genclient(acn connectivity.ACN) (tapir.Service, string) { id, sk := primitives.InitializeEphemeralIdentity() - var client tapir.Service - client = new(tor.BaseOnionService) + client := new(tor.BaseOnionService) client.Init(acn, sk, &id) return client, id.Hostname() } diff --git a/testing/tapir_malicious_remote_integration_test.go b/testing/tapir_malicious_remote_integration_test.go index 80244e9..3aa3d98 100644 --- a/testing/tapir_malicious_remote_integration_test.go +++ b/testing/tapir_malicious_remote_integration_test.go @@ -37,8 +37,7 @@ func TestTapirMaliciousRemote(t *testing.T) { id2, sk2 := primitives.InitializeEphemeralIdentity() // Init the Server running the Simple App. - var service tapir.Service - service = new(tor.BaseOnionService) + service := new(tor.BaseOnionService) // Initialize an onion service with one identity, but the auth app with another, this should // trigger a failure in authentication protocol service.Init(acn, sk2, &id) @@ -84,7 +83,7 @@ func connectclientandfail(client tapir.Service, key ed25519.PublicKey, group *sy conn, err := client.GetConnection(torProvider.GetTorV3Hostname(key)) if err == nil { group.Done() - t.Fatalf("Connection should have failed! %v %v", conn, err) + t.Errorf("Connection should have failed! %v %v", conn, err) } log.Infof("Successfully failed to authenticate...") group.Done()