Skip to content

Commit

Permalink
support for softReset command
Browse files Browse the repository at this point in the history
  • Loading branch information
solipsis committed Mar 8, 2018
1 parent 87dde94 commit 30c520d
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 225 deletions.
2 changes: 1 addition & 1 deletion cmd/flashDump.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func init() {
flashDumpCmd.Flags().StringVarP(&memAddress, "address", "a", "", "memory address")
flashDumpCmd.Flags().StringVarP(&file, "file", "f", "", "store result to file")
flashDumpCmd.Flags().Uint32VarP(&length, "length", "l", 0, "length of memory to dump")
flashDumpCmd.Flags().Uint32VarP(&length, "length", "l", 1024, "length of memory to dump")
rootCmd.AddCommand(flashDumpCmd)
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/resetDevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

func init() {
resetDeviceCmd.Flags().Uint32VarP(&entropyStrength, "entropyStrength", "e", 128, "Bits of entropy for the device to generate, must be (128, 196, 256)")
resetDeviceCmd.Flags().Uint32VarP(&wordsPerScreen, "wordsPerScreen", "w", 12, "Maximum number of recovery words to show on a single screen. Max=24")
resetDeviceCmd.Flags().BoolVarP(&displayRandom, "displayRandom", "d", false, "Display generated entropy on the device")
resetDeviceCmd.Flags().BoolVarP(&passphraseProtection, "passphrase", "", false, "Enable passphrase protection")
resetDeviceCmd.Flags().BoolVarP(&pinProtection, "pin", "", true, "Enable pin protection")
Expand All @@ -21,6 +22,7 @@ func init() {
}

var entropyStrength uint32
var wordsPerScreen uint32
var addtlEntropy string
var displayRandom bool

Expand All @@ -46,7 +48,7 @@ var resetDeviceCmd = &cobra.Command{
ent = keepkey.Entropy256
}

err := kk.ResetDevice(ent, entropy, displayRandom, passphraseProtection, pinProtection, label)
err := kk.ResetDevice(ent, entropy, displayRandom, passphraseProtection, pinProtection, label, wordsPerScreen)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
24 changes: 24 additions & 0 deletions cmd/softReset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(softResetCmd)
}

var softResetCmd = &cobra.Command{
Use: "softReset",
Short: "Soft reset / power cycle the device. Only works on devices in manufacturer mode",
Long: "Soft reset / power cycle the device. Only works on devices in manufacturer mode",
Run: func(cmd *cobra.Command, args []string) {
if err := kk.SoftReset(); err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}
14 changes: 12 additions & 2 deletions pkg/keepkey/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ func (kk *Keepkey) WipeDevice() error {
return nil
}

// SoftReset power cycles the device. The device only responds to
// this message while in manufacturer mode
func (kk *Keepkey) SoftReset() error {

if _, err := kk.keepkeyExchange(&kkProto.SoftReset{}, &kkProto.Success{}); err != nil {
return err
}
return nil
}

// FirmwareErase askes the device to erase its firmware
func (kk *Keepkey) FirmwareErase() error {

Expand Down Expand Up @@ -311,7 +321,7 @@ const (
// ResetDevice generates a new seed using device RNG for entropy and applies the provided settings
// The device must be uninitialized before calling this method. This can be achieved by calling WipeDevice()
// The device entropy strength must be 128, 192, or 256
func (kk *Keepkey) ResetDevice(strength entropyStrength, addtlEntropy []byte, showRandom, passphrase, pin bool, label string) error {
func (kk *Keepkey) ResetDevice(strength entropyStrength, addtlEntropy []byte, showRandom, passphrase, pin bool, label string, wordsPerScreen uint32) error {

deviceEntropyStrength := uint32(strength)
reset := &kkProto.ResetDevice{
Expand All @@ -326,7 +336,7 @@ func (kk *Keepkey) ResetDevice(strength entropyStrength, addtlEntropy []byte, sh
}

// The device will respond asking for additional entropy from the computer
if _, err := kk.keepkeyExchange(&kkProto.EntropyAck{Entropy: addtlEntropy}, &kkProto.Success{}); err != nil {
if _, err := kk.keepkeyExchange(&kkProto.EntropyAck{Entropy: addtlEntropy, WordsPerPage: &wordsPerScreen}, &kkProto.Success{}); err != nil {
return err
}
return nil
Expand Down
Loading

0 comments on commit 30c520d

Please sign in to comment.