Skip to content

Commit 84a22c6

Browse files
committed
Fix all golint-ci and gosec issues
1 parent b3d54ab commit 84a22c6

37 files changed

+221
-214
lines changed

Diff for: ake.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ func extractGx(decryptedGx []byte) (*big.Int, error) {
376376

377377
func sumHMAC(key, data []byte, v otrVersion) []byte {
378378
mac := hmac.New(v.hash2Instance, key)
379-
mac.Write(data)
379+
_, _ = mac.Write(data)
380380
return mac.Sum(nil)
381381
}
382382

Diff for: auth_state_machine.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ func (c *Conversation) processAKE(msgType byte, msg []byte) (toSend []messageWit
5757
}
5858

5959
type authStateBase struct{}
60-
type authStateNone struct{ authStateBase }
61-
type authStateAwaitingDHKey struct{ authStateBase }
62-
type authStateAwaitingRevealSig struct{ authStateBase }
60+
type authStateNone struct{}
61+
type authStateAwaitingDHKey struct{}
62+
type authStateAwaitingRevealSig struct{}
6363
type authStateAwaitingSig struct {
6464
authStateBase
6565
// revealSigMsg is only used to store the message so we can re-transmit it if needed

Diff for: auth_state_machine_test.go

+26-26
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ func Test_receiveDHCommit_AtAuthAwaitingRevealSigiForgetOldEncryptedGxAndHashedG
7070
newMsg, newEncryptedGx, _ := ExtractData(newDHCommitMsg)
7171
_, newHashedGx, _ := ExtractData(newMsg)
7272

73-
authStateNone{}.receiveDHCommitMessage(c, fixtureDHCommitMsgBody())
73+
_, _, _ = authStateNone{}.receiveDHCommitMessage(c, fixtureDHCommitMsgBody())
7474

75-
authStateAwaitingRevealSig{}.receiveDHCommitMessage(c, newDHCommitMsg)
75+
_, _, _ = authStateAwaitingRevealSig{}.receiveDHCommitMessage(c, newDHCommitMsg)
7676
assertDeepEquals(t, c.ake.encryptedGx, newEncryptedGx)
7777
assertDeepEquals(t, c.ake.xhashedGx, newHashedGx)
7878
}
@@ -110,7 +110,7 @@ func Test_receiveDHCommit_AtAwaitingDHKeyIgnoreIncomingMsgAndResendOurDHCommitMs
110110

111111
func Test_receiveDHCommit_AtAwaitingDHKeyForgetOurGxAndSendDHKeyMsgAndGoToAwaitingRevealSig(t *testing.T) {
112112
ourDHCommitAKE := fixtureConversation()
113-
ourDHCommitAKE.dhCommitMessage()
113+
_, _ = ourDHCommitAKE.dhCommitMessage()
114114

115115
//make sure we store the same values when creating the DH commit
116116
c := newConversation(otrV3{}, fixtureRand())
@@ -150,7 +150,7 @@ func Test_receiveDHKey_AtAuthStateNoneOrAuthStateAwaitingRevealSigIgnoreIt(t *te
150150

151151
func Test_receiveDHKey_TransitionsFromAwaitingDHKeyToAwaitingSigAndSendsRevealSig(t *testing.T) {
152152
ourDHCommitAKE := fixtureConversation()
153-
ourDHCommitAKE.dhCommitMessage()
153+
_, _ = ourDHCommitAKE.dhCommitMessage()
154154

155155
c := bobContextAtAwaitingDHKey()
156156
c.sentRevealSig = false
@@ -167,7 +167,7 @@ func Test_receiveDHKey_TransitionsFromAwaitingDHKeyToAwaitingSigAndSendsRevealSi
167167

168168
func Test_receiveDHKey_AtAwaitingDHKeyStoresGyAndSigKey(t *testing.T) {
169169
ourDHCommitAKE := fixtureConversation()
170-
ourDHCommitAKE.dhCommitMessage()
170+
_, _ = ourDHCommitAKE.dhCommitMessage()
171171

172172
c := bobContextAtAwaitingDHKey()
173173

@@ -182,7 +182,7 @@ func Test_receiveDHKey_AtAwaitingDHKeyStoresGyAndSigKey(t *testing.T) {
182182

183183
func Test_receiveDHKey_AtAwaitingDHKey_storesOursAndTheirDHKeys(t *testing.T) {
184184
ourDHCommitAKE := fixtureConversation()
185-
ourDHCommitAKE.dhCommitMessage()
185+
_, _ = ourDHCommitAKE.dhCommitMessage()
186186

187187
c := bobContextAtAwaitingDHKey()
188188

@@ -201,7 +201,7 @@ func Test_receiveDHKey_AtAuthAwaitingSigIfReceivesSameDHKeyMsgRetransmitRevealSi
201201
var nilB *big.Int
202202

203203
ourDHCommitAKE := fixtureConversation()
204-
ourDHCommitAKE.dhCommitMessage()
204+
_, _ = ourDHCommitAKE.dhCommitMessage()
205205

206206
c := newConversation(otrV3{}, fixtureRand())
207207
c.initAKE()
@@ -373,7 +373,7 @@ func Test_receiveDecoded_receiveDHCommitMessageAndFailsWillSignalSetupError(t *t
373373
msg := fixtureDHCommitMsgV2()
374374

375375
c.expectMessageEvent(t, func() {
376-
c.receiveDecoded(msg)
376+
_, _, _ = c.receiveDecoded(msg)
377377
}, MessageEventSetupError, nil, errShortRandomRead)
378378
}
379379

@@ -383,7 +383,7 @@ func Test_receiveDecoded_receiveDHKeyMessageAndFailsWillSignalSetupError(t *test
383383
msg := fixtureDHKeyMsg(otrV3{})
384384

385385
c.expectMessageEvent(t, func() {
386-
c.receiveDecoded(msg)
386+
_, _, _ = c.receiveDecoded(msg)
387387
}, MessageEventSetupError, nil, errShortRandomRead)
388388
}
389389

@@ -393,7 +393,7 @@ func Test_receiveDecoded_receiveRevealSigMessageAndFailsWillSignalSetupError(t *
393393
msg := fixtureRevealSigMsg(otrV2{})
394394

395395
c.expectMessageEvent(t, func() {
396-
c.receiveDecoded(msg)
396+
_, _, _ = c.receiveDecoded(msg)
397397
}, MessageEventSetupError, nil, errShortRandomRead)
398398
}
399399

@@ -403,7 +403,7 @@ func Test_receiveDecoded_receiveSigMessageAndSetMessageStateToEncrypted(t *testi
403403
msg := fixtureSigMsg(otrV2{})
404404

405405
c.expectMessageEvent(t, func() {
406-
c.receiveDecoded(msg)
406+
_, _, _ = c.receiveDecoded(msg)
407407
}, MessageEventSetupError, nil, errShortRandomRead)
408408
}
409409

@@ -451,7 +451,7 @@ func Test_receiveDecoded_receiveSigMessageAndStoresTheirKeyIDAndTheirCurrentDHPu
451451

452452
func Test_authStateAwaitingDHKey_receiveDHKeyMessage_returnsErrorIfprocessDHKeyReturnsError(t *testing.T) {
453453
ourDHCommitAKE := fixtureConversation()
454-
ourDHCommitAKE.dhCommitMessage()
454+
_, _ = ourDHCommitAKE.dhCommitMessage()
455455

456456
c := newConversation(otrV3{}, fixtureRand())
457457
c.initAKE()
@@ -465,7 +465,7 @@ func Test_authStateAwaitingDHKey_receiveDHKeyMessage_returnsErrorIfprocessDHKeyR
465465

466466
func Test_authStateAwaitingDHKey_receiveDHKeyMessage_returnsErrorIfrevealSigMessageReturnsError(t *testing.T) {
467467
ourDHCommitAKE := fixtureConversation()
468-
ourDHCommitAKE.dhCommitMessage()
468+
_, _ = ourDHCommitAKE.dhCommitMessage()
469469

470470
c := newConversation(otrV3{}, fixedRand([]string{"ABCD"}))
471471
c.initAKE()
@@ -480,7 +480,7 @@ func Test_authStateAwaitingDHKey_receiveDHKeyMessage_returnsErrorIfrevealSigMess
480480

481481
func Test_authStateAwaitingSig_receiveDHKeyMessage_returnsErrorIfprocessDHKeyReturnsError(t *testing.T) {
482482
ourDHCommitAKE := fixtureConversation()
483-
ourDHCommitAKE.dhCommitMessage()
483+
_, _ = ourDHCommitAKE.dhCommitMessage()
484484

485485
c := newConversation(otrV3{}, fixtureRand())
486486
c.initAKE()
@@ -501,7 +501,7 @@ func Test_authStateAwaitingSig_receiveSigMessage_returnsErrorIfProcessSigFails(t
501501

502502
func Test_authStateAwaitingRevealSig_receiveDHCommitMessage_returnsErrorIfProcessDHCommitOrGenerateCommitInstanceTagsFailsFails(t *testing.T) {
503503
ourDHCommitAKE := fixtureConversation()
504-
ourDHCommitAKE.dhCommitMessage()
504+
_, _ = ourDHCommitAKE.dhCommitMessage()
505505

506506
c := newConversation(otrV3{}, fixtureRand())
507507
c.initAKE()
@@ -513,7 +513,7 @@ func Test_authStateAwaitingRevealSig_receiveDHCommitMessage_returnsErrorIfProces
513513

514514
func Test_authStateNone_receiveDHCommitMessage_returnsErrorIfgenerateCommitMsgInstanceTagsFails(t *testing.T) {
515515
ourDHCommitAKE := fixtureConversation()
516-
ourDHCommitAKE.dhCommitMessage()
516+
_, _ = ourDHCommitAKE.dhCommitMessage()
517517

518518
c := newConversation(otrV3{}, fixtureRand())
519519
c.initAKE()
@@ -525,7 +525,7 @@ func Test_authStateNone_receiveDHCommitMessage_returnsErrorIfgenerateCommitMsgIn
525525

526526
func Test_authStateNone_receiveDHCommitMessage_returnsErrorIfdhKeyMessageFails(t *testing.T) {
527527
ourDHCommitAKE := fixtureConversation()
528-
ourDHCommitAKE.dhCommitMessage()
528+
_, _ = ourDHCommitAKE.dhCommitMessage()
529529

530530
c := newConversation(otrV2{}, fixedRand([]string{"ABCD"}))
531531
c.initAKE()
@@ -537,7 +537,7 @@ func Test_authStateNone_receiveDHCommitMessage_returnsErrorIfdhKeyMessageFails(t
537537

538538
func Test_authStateNone_receiveDHCommitMessage_returnsErrorIfProcessDHCommitFails(t *testing.T) {
539539
ourDHCommitAKE := fixtureConversation()
540-
ourDHCommitAKE.dhCommitMessage()
540+
_, _ = ourDHCommitAKE.dhCommitMessage()
541541

542542
c := newConversation(otrV2{}, fixtureRand())
543543
c.initAKE()
@@ -549,7 +549,7 @@ func Test_authStateNone_receiveDHCommitMessage_returnsErrorIfProcessDHCommitFail
549549

550550
func Test_authStateAwaitingDHKey_receiveDHCommitMessage_failsIfMsgDoesntHaveHeader(t *testing.T) {
551551
ourDHCommitAKE := fixtureConversation()
552-
ourDHCommitAKE.dhCommitMessage()
552+
_, _ = ourDHCommitAKE.dhCommitMessage()
553553

554554
c := newConversation(otrV2{}, fixtureRand())
555555
c.initAKE()
@@ -561,7 +561,7 @@ func Test_authStateAwaitingDHKey_receiveDHCommitMessage_failsIfMsgDoesntHaveHead
561561

562562
func Test_authStateAwaitingDHKey_receiveDHCommitMessage_failsIfCantExtractFirstPart(t *testing.T) {
563563
ourDHCommitAKE := fixtureConversation()
564-
ourDHCommitAKE.dhCommitMessage()
564+
_, _ = ourDHCommitAKE.dhCommitMessage()
565565

566566
c := newConversation(otrV2{}, fixtureRand())
567567
c.initAKE()
@@ -573,7 +573,7 @@ func Test_authStateAwaitingDHKey_receiveDHCommitMessage_failsIfCantExtractFirstP
573573

574574
func Test_authStateAwaitingDHKey_receiveDHCommitMessage_failsIfCantExtractSecondPart(t *testing.T) {
575575
ourDHCommitAKE := fixtureConversation()
576-
ourDHCommitAKE.dhCommitMessage()
576+
_, _ = ourDHCommitAKE.dhCommitMessage()
577577

578578
c := newConversation(otrV2{}, fixtureRand())
579579
c.initAKE()
@@ -605,7 +605,7 @@ func Test_akeHasFinished_willSignalThatWeAreTalkingToOurselvesIfWeAre(t *testing
605605
c.theirKey = bobPrivateKey.PublicKey()
606606

607607
c.expectMessageEvent(t, func() {
608-
c.akeHasFinished()
608+
_ = c.akeHasFinished()
609609
}, MessageEventMessageReflected, nil, nil)
610610
}
611611

@@ -616,7 +616,7 @@ func Test_akeHasFinished_willSignalThatWeHaveGoneSecureIfWeHave(t *testing.T) {
616616
c.msgState = plainText
617617

618618
c.expectSecurityEvent(t, func() {
619-
c.akeHasFinished()
619+
_ = c.akeHasFinished()
620620
}, GoneSecure)
621621
}
622622

@@ -627,7 +627,7 @@ func Test_akeHasFinished_willSignalThatWeHaveGoneSecureIfWeWereFinished(t *testi
627627
c.msgState = plainText
628628

629629
c.expectSecurityEvent(t, func() {
630-
c.akeHasFinished()
630+
_ = c.akeHasFinished()
631631
}, GoneSecure)
632632
}
633633

@@ -638,7 +638,7 @@ func Test_akeHasFinished_willSignalThatWeHaveGoneSecureIfWeHaveRefreshed(t *test
638638
c.msgState = encrypted
639639

640640
c.expectSecurityEvent(t, func() {
641-
c.akeHasFinished()
641+
_ = c.akeHasFinished()
642642
}, StillSecure)
643643
}
644644

@@ -671,7 +671,7 @@ func Test_akeHasFinished_wipesAKEKeys(t *testing.T) {
671671
state: authStateNone{},
672672
}
673673

674-
c.akeHasFinished()
674+
_ = c.akeHasFinished()
675675

676676
assertDeepEquals(t, *c.ake, ake{state: c.ake.state})
677677
}

Diff for: authenticate_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func Test_StartAuthenticate_generatesAndSetsTheFirstMessageOnTheConversation(t *
5858
c.theirKey = alicePrivateKey.PublicKey()
5959
c.smp.s1 = nil
6060

61-
c.StartAuthenticate("", []byte("hello world"))
61+
_, _ = c.StartAuthenticate("", []byte("hello world"))
6262

6363
assertNotNil(t, c.smp.s1)
6464
assertEquals(t, c.smp.s1.msg.hasQuestion, false)
@@ -73,7 +73,7 @@ func Test_StartAuthenticate_generatesAn1QMessageIfAQuestionIsGiven(t *testing.T)
7373
c.theirKey = alicePrivateKey.PublicKey()
7474
c.smp.s1 = nil
7575

76-
c.StartAuthenticate("Where did we meet?", []byte("hello world"))
76+
_, _ = c.StartAuthenticate("Where did we meet?", []byte("hello world"))
7777

7878
assertNotNil(t, c.smp.s1)
7979
assertEquals(t, c.smp.s1.msg.hasQuestion, true)

Diff for: conversation.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ func (c *Conversation) SetSecurityEventHandler(handler SecurityEventHandler) {
178178
// The instance tag created or set will be returned
179179
func (c *Conversation) InitializeInstanceTag(tag uint32) uint32 {
180180
if tag == 0 {
181-
c.generateInstanceTag()
181+
if e := c.generateInstanceTag(); e != nil {
182+
return 0
183+
}
182184
} else {
183185
c.ourInstanceTag = tag
184186
}

Diff for: conversation_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func Test_receiveDecoded_signalsAMessageEventForADataMessageWhenNoEncryptionIsAc
8585
c.SetOurKeys([]PrivateKey{bobPrivateKey})
8686

8787
c.expectMessageEvent(t, func() {
88-
c.receiveDecoded(m)
88+
_, _, _ = c.receiveDecoded(m)
8989
}, MessageEventReceivedMessageNotInPrivate, nil, nil)
9090
}
9191

@@ -333,7 +333,7 @@ func Test_End_whenStateIsEncrypted_willSignalSecurityEvent(t *testing.T) {
333333
bob.msgState = encrypted
334334

335335
bob.expectSecurityEvent(t, func() {
336-
bob.End()
336+
_, _ = bob.End()
337337
}, GoneInsecure)
338338
}
339339

@@ -342,7 +342,7 @@ func Test_End_whenStateIsPlaintext_willNotSignalSecurityEvent(t *testing.T) {
342342
bob.msgState = plainText
343343

344344
bob.doesntExpectSecurityEvent(t, func() {
345-
bob.End()
345+
_, _ = bob.End()
346346
})
347347
}
348348

@@ -351,16 +351,16 @@ func Test_End_whenStateIsFinished_willNotSignalSecurityEvent(t *testing.T) {
351351
bob.msgState = finished
352352

353353
bob.doesntExpectSecurityEvent(t, func() {
354-
bob.End()
354+
_, _ = bob.End()
355355
})
356356
}
357357

358358
func Test_End_wipesKeys(t *testing.T) {
359359
bob := bobContextAfterAKE()
360360
bob.msgState = encrypted
361-
bob.End()
361+
_, _ = bob.End()
362362
stub := bobContextAfterAKE()
363-
stub.createSerializedDataMessage(nil, messageFlagIgnoreUnreadable, []tlv{tlv{tlvType: tlvTypeDisconnected}})
363+
_, _, _ = stub.createSerializedDataMessage(nil, messageFlagIgnoreUnreadable, []tlv{tlv{tlvType: tlvTypeDisconnected}})
364364

365365
assertDeepEquals(t, dhKeyPair{}, bob.keys.ourCurrentDHKeys)
366366
assertDeepEquals(t, dhKeyPair{}, bob.keys.ourPreviousDHKeys)

Diff for: data.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88

99
func hashMPIs(h hash.Hash, magic byte, mpis ...*big.Int) []byte {
1010
h.Reset()
11-
h.Write([]byte{magic})
11+
_, _ = h.Write([]byte{magic})
1212
for _, mpi := range mpis {
13-
h.Write(AppendMPI(nil, mpi))
13+
_, _ = h.Write(AppendMPI(nil, mpi))
1414
}
1515
return h.Sum(nil)
1616
}

Diff for: data_message.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (c *Conversation) processDataMessageWithRawErrors(header, msg []byte) (plai
132132

133133
p := plainDataMsg{}
134134
//this can't return an error since receivingAESKey is a AES-128 key
135-
p.decrypt(sessionKeys.receivingAESKey[:], dataMessage.topHalfCtr, dataMessage.encryptedMsg)
135+
_ = p.decrypt(sessionKeys.receivingAESKey[:], dataMessage.topHalfCtr, dataMessage.encryptedMsg)
136136

137137
plain = makeCopy(p.message)
138138
if len(plain) == 0 {

0 commit comments

Comments
 (0)