diff options
author | Guillaume Ballet <gballet@gmail.com> | 2019-05-03 23:17:45 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-05-27 22:29:01 +0800 |
commit | 75a860880cfc88cc515ef91301aea0f7df4c17bc (patch) | |
tree | 29d027c474775890f32dccae50cc59b14ba8ffdb /accounts | |
parent | fc85777a219acd12620fe9b76a3b7e585800300c (diff) | |
download | go-tangerine-75a860880cfc88cc515ef91301aea0f7df4c17bc.tar go-tangerine-75a860880cfc88cc515ef91301aea0f7df4c17bc.tar.gz go-tangerine-75a860880cfc88cc515ef91301aea0f7df4c17bc.tar.bz2 go-tangerine-75a860880cfc88cc515ef91301aea0f7df4c17bc.tar.lz go-tangerine-75a860880cfc88cc515ef91301aea0f7df4c17bc.tar.xz go-tangerine-75a860880cfc88cc515ef91301aea0f7df4c17bc.tar.zst go-tangerine-75a860880cfc88cc515ef91301aea0f7df4c17bc.zip |
accounts/scwallet: display PUK retry count, validate PIN/PUK length
Diffstat (limited to 'accounts')
-rw-r--r-- | accounts/scwallet/wallet.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/accounts/scwallet/wallet.go b/accounts/scwallet/wallet.go index 71b2c68af..c48028281 100644 --- a/accounts/scwallet/wallet.go +++ b/accounts/scwallet/wallet.go @@ -27,6 +27,7 @@ import ( "errors" "fmt" "math/big" + "regexp" "sort" "strings" "sync" @@ -310,8 +311,10 @@ func (w *Wallet) Status() (string, error) { return fmt.Sprintf("Failed: %v", err), err } switch { + case !w.session.verified && status.PinRetryCount == 0 && status.PukRetryCount == 0: + return fmt.Sprintf("Bricked, waiting for full wipe"), nil case !w.session.verified && status.PinRetryCount == 0: - return fmt.Sprintf("Blocked, waiting for PUK and new PIN"), nil + return fmt.Sprintf("Blocked, waiting for PUK (%d attempts left) and new PIN", status.PukRetryCount), nil case !w.session.verified: return fmt.Sprintf("Locked, waiting for PIN (%d attempts left)", status.PinRetryCount), nil case !status.Initialized: @@ -377,10 +380,18 @@ func (w *Wallet) Open(passphrase string) error { case passphrase == "": return ErrPINUnblockNeeded case status.PinRetryCount > 0: + if !regexp.MustCompile(`^[0-9]{6,}$`).MatchString(passphrase) { + w.log.Error("PIN needs to be at least 6 digits") + return ErrPINNeeded + } if err := w.session.verifyPin([]byte(passphrase)); err != nil { return err } default: + if !regexp.MustCompile(`^[0-9]{12,}$`).MatchString(passphrase) { + w.log.Error("PUK needs to be at least 12 digits") + return ErrPINUnblockNeeded + } if err := w.session.unblockPin([]byte(passphrase)); err != nil { return err } |