Skip to content

Commit 54d332e

Browse files
gballetfjl
authored andcommitted
accounts/scwallet: fix staticcheck warnings (#20370)
1 parent e0bf5f0 commit 54d332e

2 files changed

Lines changed: 21 additions & 18 deletions

File tree

‎accounts/scwallet/securechannel.go‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func NewSecureChannelSession(card *pcsc.Card, keyData []byte) (*SecureChannelSes
7171

7272
cardPublic, ok := gen.Unmarshal(keyData)
7373
if !ok {
74-
return nil, fmt.Errorf("Could not unmarshal public key from card")
74+
return nil, fmt.Errorf("could not unmarshal public key from card")
7575
}
7676

7777
secret, err := gen.GenerateSharedSecret(private, cardPublic)
@@ -109,7 +109,7 @@ func (s *SecureChannelSession) Pair(pairingPassword []byte) error {
109109
cardChallenge := response.Data[32:64]
110110

111111
if !bytes.Equal(expectedCryptogram, cardCryptogram) {
112-
return fmt.Errorf("Invalid card cryptogram %v != %v", expectedCryptogram, cardCryptogram)
112+
return fmt.Errorf("invalid card cryptogram %v != %v", expectedCryptogram, cardCryptogram)
113113
}
114114

115115
md.Reset()
@@ -132,7 +132,7 @@ func (s *SecureChannelSession) Pair(pairingPassword []byte) error {
132132
// Unpair disestablishes an existing pairing.
133133
func (s *SecureChannelSession) Unpair() error {
134134
if s.PairingKey == nil {
135-
return fmt.Errorf("Cannot unpair: not paired")
135+
return fmt.Errorf("cannot unpair: not paired")
136136
}
137137

138138
_, err := s.transmitEncrypted(claSCWallet, insUnpair, s.PairingIndex, 0, []byte{})
@@ -148,7 +148,7 @@ func (s *SecureChannelSession) Unpair() error {
148148
// Open initializes the secure channel.
149149
func (s *SecureChannelSession) Open() error {
150150
if s.iv != nil {
151-
return fmt.Errorf("Session already opened")
151+
return fmt.Errorf("session already opened")
152152
}
153153

154154
response, err := s.open()
@@ -185,11 +185,11 @@ func (s *SecureChannelSession) mutuallyAuthenticate() error {
185185
return err
186186
}
187187
if response.Sw1 != 0x90 || response.Sw2 != 0x00 {
188-
return fmt.Errorf("Got unexpected response from MUTUALLY_AUTHENTICATE: 0x%x%x", response.Sw1, response.Sw2)
188+
return fmt.Errorf("got unexpected response from MUTUALLY_AUTHENTICATE: 0x%x%x", response.Sw1, response.Sw2)
189189
}
190190

191191
if len(response.Data) != scSecretLength {
192-
return fmt.Errorf("Response from MUTUALLY_AUTHENTICATE was %d bytes, expected %d", len(response.Data), scSecretLength)
192+
return fmt.Errorf("response from MUTUALLY_AUTHENTICATE was %d bytes, expected %d", len(response.Data), scSecretLength)
193193
}
194194

195195
return nil
@@ -222,7 +222,7 @@ func (s *SecureChannelSession) pair(p1 uint8, data []byte) (*responseAPDU, error
222222
// transmitEncrypted sends an encrypted message, and decrypts and returns the response.
223223
func (s *SecureChannelSession) transmitEncrypted(cla, ins, p1, p2 byte, data []byte) (*responseAPDU, error) {
224224
if s.iv == nil {
225-
return nil, fmt.Errorf("Channel not open")
225+
return nil, fmt.Errorf("channel not open")
226226
}
227227

228228
data, err := s.encryptAPDU(data)
@@ -261,14 +261,14 @@ func (s *SecureChannelSession) transmitEncrypted(cla, ins, p1, p2 byte, data []b
261261
return nil, err
262262
}
263263
if !bytes.Equal(s.iv, rmac) {
264-
return nil, fmt.Errorf("Invalid MAC in response")
264+
return nil, fmt.Errorf("invalid MAC in response")
265265
}
266266

267267
rapdu := &responseAPDU{}
268268
rapdu.deserialize(plainData)
269269

270270
if rapdu.Sw1 != sw1Ok {
271-
return nil, fmt.Errorf("Unexpected response status Cla=0x%x, Ins=0x%x, Sw=0x%x%x", cla, ins, rapdu.Sw1, rapdu.Sw2)
271+
return nil, fmt.Errorf("unexpected response status Cla=0x%x, Ins=0x%x, Sw=0x%x%x", cla, ins, rapdu.Sw1, rapdu.Sw2)
272272
}
273273

274274
return rapdu, nil
@@ -277,7 +277,7 @@ func (s *SecureChannelSession) transmitEncrypted(cla, ins, p1, p2 byte, data []b
277277
// encryptAPDU is an internal method that serializes and encrypts an APDU.
278278
func (s *SecureChannelSession) encryptAPDU(data []byte) ([]byte, error) {
279279
if len(data) > maxPayloadSize {
280-
return nil, fmt.Errorf("Payload of %d bytes exceeds maximum of %d", len(data), maxPayloadSize)
280+
return nil, fmt.Errorf("payload of %d bytes exceeds maximum of %d", len(data), maxPayloadSize)
281281
}
282282
data = pad(data, 0x80)
283283

@@ -323,10 +323,10 @@ func unpad(data []byte, terminator byte) ([]byte, error) {
323323
case terminator:
324324
return data[:len(data)-i], nil
325325
default:
326-
return nil, fmt.Errorf("Expected end of padding, got %d", data[len(data)-i])
326+
return nil, fmt.Errorf("expected end of padding, got %d", data[len(data)-i])
327327
}
328328
}
329-
return nil, fmt.Errorf("Expected end of padding, got 0")
329+
return nil, fmt.Errorf("expected end of padding, got 0")
330330
}
331331

332332
// updateIV is an internal method that updates the initialization vector after

‎accounts/scwallet/wallet.go‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func transmit(card *pcsc.Card, command *commandAPDU) (*responseAPDU, error) {
167167
}
168168

169169
if response.Sw1 != sw1Ok {
170-
return nil, fmt.Errorf("Unexpected insecure response status Cla=0x%x, Ins=0x%x, Sw=0x%x%x", command.Cla, command.Ins, response.Sw1, response.Sw2)
170+
return nil, fmt.Errorf("unexpected insecure response status Cla=0x%x, Ins=0x%x, Sw=0x%x%x", command.Cla, command.Ins, response.Sw1, response.Sw2)
171171
}
172172

173173
return response, nil
@@ -252,7 +252,7 @@ func (w *Wallet) release() error {
252252
// with the wallet.
253253
func (w *Wallet) pair(puk []byte) error {
254254
if w.session.paired() {
255-
return fmt.Errorf("Wallet already paired")
255+
return fmt.Errorf("wallet already paired")
256256
}
257257
pairing, err := w.session.pair(puk)
258258
if err != nil {
@@ -773,12 +773,12 @@ func (w *Wallet) findAccountPath(account accounts.Account) (accounts.DerivationP
773773

774774
// Look for the path in the URL
775775
if account.URL.Scheme != w.Hub.scheme {
776-
return nil, fmt.Errorf("Scheme %s does not match wallet scheme %s", account.URL.Scheme, w.Hub.scheme)
776+
return nil, fmt.Errorf("scheme %s does not match wallet scheme %s", account.URL.Scheme, w.Hub.scheme)
777777
}
778778

779779
parts := strings.SplitN(account.URL.Path, "/", 2)
780780
if len(parts) != 2 {
781-
return nil, fmt.Errorf("Invalid URL format: %s", account.URL)
781+
return nil, fmt.Errorf("invalid URL format: %s", account.URL)
782782
}
783783

784784
if parts[0] != fmt.Sprintf("%x", w.PublicKey[1:3]) {
@@ -813,7 +813,7 @@ func (s *Session) pair(secret []byte) (smartcardPairing, error) {
813813
// unpair deletes an existing pairing.
814814
func (s *Session) unpair() error {
815815
if !s.verified {
816-
return fmt.Errorf("Unpair requires that the PIN be verified")
816+
return fmt.Errorf("unpair requires that the PIN be verified")
817817
}
818818
return s.Channel.Unpair()
819819
}
@@ -850,7 +850,7 @@ func (s *Session) paired() bool {
850850
// authenticate uses an existing pairing to establish a secure channel.
851851
func (s *Session) authenticate(pairing smartcardPairing) error {
852852
if !bytes.Equal(s.Wallet.PublicKey, pairing.PublicKey) {
853-
return fmt.Errorf("Cannot pair using another wallet's pairing; %x != %x", s.Wallet.PublicKey, pairing.PublicKey)
853+
return fmt.Errorf("cannot pair using another wallet's pairing; %x != %x", s.Wallet.PublicKey, pairing.PublicKey)
854854
}
855855
s.Channel.PairingKey = pairing.PairingKey
856856
s.Channel.PairingIndex = pairing.PairingIndex
@@ -879,6 +879,7 @@ func (s *Session) walletStatus() (*walletStatus, error) {
879879
}
880880

881881
// derivationPath fetches the wallet's current derivation path from the card.
882+
//lint:ignore U1000 needs to be added to the console interface
882883
func (s *Session) derivationPath() (accounts.DerivationPath, error) {
883884
response, err := s.Channel.transmitEncrypted(claSCWallet, insStatus, statusP1Path, 0, nil)
884885
if err != nil {
@@ -993,12 +994,14 @@ func (s *Session) derive(path accounts.DerivationPath) (accounts.Account, error)
993994
}
994995

995996
// keyExport contains information on an exported keypair.
997+
//lint:ignore U1000 needs to be added to the console interface
996998
type keyExport struct {
997999
PublicKey []byte `asn1:"tag:0"`
9981000
PrivateKey []byte `asn1:"tag:1,optional"`
9991001
}
10001002

10011003
// publicKey returns the public key for the current derivation path.
1004+
//lint:ignore U1000 needs to be added to the console interface
10021005
func (s *Session) publicKey() ([]byte, error) {
10031006
response, err := s.Channel.transmitEncrypted(claSCWallet, insExportKey, exportP1Any, exportP2Pubkey, nil)
10041007
if err != nil {

0 commit comments

Comments
 (0)