Skip to content

Commit

Permalink
ssh-tpm-keygen: parse comment from public key on import
Browse files Browse the repository at this point in the history
Signed-off-by: Morten Linderud <[email protected]>
  • Loading branch information
Foxboron committed Aug 8, 2023
1 parent c81bcd9 commit 9f3cfb6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmd/ssh-tpm-keygen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ func main() {
log.Fatal("unsupported key type")
}

pubPem, err := os.ReadFile(importKey + ".pub")
if err != nil {
log.Fatalf("can't find corresponding public key: %v", err)
}

_, c, _, _, err := ssh.ParseAuthorizedKey(pubPem)
if err != nil {
log.Fatal("can't parse public key", err)
}
comment = c

} else {
fmt.Printf("Generating a sealed public/private %s key pair.\n", keyType)

Expand Down Expand Up @@ -251,7 +262,7 @@ func main() {

if importKey != "" {
// TODO: Read public key for comment
k, err = key.ImportKey(tpm, toImportKey, pin, []byte(""))
k, err = key.ImportKey(tpm, toImportKey, pin, []byte(comment))
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 9f3cfb6

Please sign in to comment.