Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide new command -F to get firmware digest #21

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions cmd/tkey-sign/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type command int
const (
cmdUnknown = iota
cmdGetKey
cmdGetFW
cmdSign
cmdVerify
)
Expand Down Expand Up @@ -107,6 +108,18 @@ func signFile(signer tkeysign.Signer, pubkey []byte, fileName string) (*signatur
return &s, nil
}

// getFW asks signer to hash the length part of the firmware
//
// It returns the BLAKE2s digest on success or an error.
func getFW(signer tkeysign.Signer, len int) ([]byte, error) {
digest, err := signer.GetFWDigest(len)
if err != nil {
return []byte{}, err
}

return digest, nil
}

// verifySignature verifies a Ed25519 signature stored in sigFile over
// messageFile with public key in pubkeyFile
func verifySignature(messageFile string, sigFile string, pubkeyFile string) error {
Expand Down Expand Up @@ -263,6 +276,7 @@ func main() {
var cmd command
var cmdArgs int
getKey := pflag.BoolP("getkey", "G", false, "Get public key.")
getFirmware := pflag.BoolP("getfw", "F", false, "Get firmware digest.")
sign := pflag.BoolP("sign", "S", false, "Sign the message.")
verify := pflag.BoolP("verify", "V", false, "Verify signature of the message.")
force := pflag.BoolP("force", "f", false, "Force writing of signature and pubkey files, overwriting any existing files.")
Expand Down Expand Up @@ -310,6 +324,11 @@ func main() {
cmdArgs++
}

if *getFirmware {
cmd = cmdGetFW
cmdArgs++
}

if *sign {
cmd = cmdSign
cmdArgs++
Expand Down Expand Up @@ -361,6 +380,18 @@ func main() {

signer.Close()

case cmdGetFW:
signer, _, err := loadSigner(*devPath, *speed, *ussFile, *enterUss)
if err != nil {
le.Printf("Couldn't load signer: %v", err)
os.Exit(1)
}

digest, err := getFW(*signer, 4711)
le.Printf("digest: %x\n", digest)

signer.Close()

case cmdSign:
if *messageFile == "" {
le.Printf("Provide message file with -m message")
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ require (
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.14.0 // indirect
)

replace github.com/tillitis/tkeysign => ../tkeysign