Skip to content

Commit 75a8608

Browse files
gballetkaralabe
authored andcommitted
accounts/scwallet: display PUK retry count, validate PIN/PUK length
1 parent fc85777 commit 75a8608

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎accounts/scwallet/wallet.go‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"errors"
2828
"fmt"
2929
"math/big"
30+
"regexp"
3031
"sort"
3132
"strings"
3233
"sync"
@@ -310,8 +311,10 @@ func (w *Wallet) Status() (string, error) {
310311
return fmt.Sprintf("Failed: %v", err), err
311312
}
312313
switch {
314+
case !w.session.verified && status.PinRetryCount == 0 && status.PukRetryCount == 0:
315+
return fmt.Sprintf("Bricked, waiting for full wipe"), nil
313316
case !w.session.verified && status.PinRetryCount == 0:
314-
return fmt.Sprintf("Blocked, waiting for PUK and new PIN"), nil
317+
return fmt.Sprintf("Blocked, waiting for PUK (%d attempts left) and new PIN", status.PukRetryCount), nil
315318
case !w.session.verified:
316319
return fmt.Sprintf("Locked, waiting for PIN (%d attempts left)", status.PinRetryCount), nil
317320
case !status.Initialized:
@@ -377,10 +380,18 @@ func (w *Wallet) Open(passphrase string) error {
377380
case passphrase == "":
378381
return ErrPINUnblockNeeded
379382
case status.PinRetryCount > 0:
383+
if !regexp.MustCompile(`^[0-9]{6,}$`).MatchString(passphrase) {
384+
w.log.Error("PIN needs to be at least 6 digits")
385+
return ErrPINNeeded
386+
}
380387
if err := w.session.verifyPin([]byte(passphrase)); err != nil {
381388
return err
382389
}
383390
default:
391+
if !regexp.MustCompile(`^[0-9]{12,}$`).MatchString(passphrase) {
392+
w.log.Error("PUK needs to be at least 12 digits")
393+
return ErrPINUnblockNeeded
394+
}
384395
if err := w.session.unblockPin([]byte(passphrase)); err != nil {
385396
return err
386397
}

0 commit comments

Comments
 (0)