@@ -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 }
@@ -971,12 +982,10 @@ func (s *Session) derive(path accounts.DerivationPath) (accounts.Account, error)
971982 copy (sig [32 - len (rbytes ):32 ], rbytes )
972983 copy (sig [64 - len (sbytes ):64 ], sbytes )
973984
974- pubkey , err := determinePublicKey (sig , sigdata .PublicKey )
975- if err != nil {
985+ if err := confirmPublicKey (sig , sigdata .PublicKey ); err != nil {
976986 return accounts.Account {}, err
977987 }
978-
979- pub , err := crypto .UnmarshalPubkey (pubkey )
988+ pub , err := crypto .UnmarshalPubkey (sigdata .PublicKey )
980989 if err != nil {
981990 return accounts.Account {}, err
982991 }
@@ -1046,10 +1055,10 @@ func (s *Session) sign(path accounts.DerivationPath, hash []byte) ([]byte, error
10461055 return sig , nil
10471056}
10481057
1049- // determinePublicKey uses a signature and the X component of a public key to
1050- // recover the entire public key.
1051- func determinePublicKey ( sig , pubkeyX [] byte ) ([] byte , error ) {
1052- return makeRecoverableSignature ( DerivationSignatureHash [:], sig , pubkeyX )
1058+ // confirmPublicKey confirms that the given signature belongs to the specified key.
1059+ func confirmPublicKey ( sig , pubkey [] byte ) error {
1060+ _ , err := makeRecoverableSignature ( DerivationSignatureHash [:], sig , pubkey )
1061+ return err
10531062}
10541063
10551064// makeRecoverableSignature uses a signature and an expected public key to
0 commit comments