Skip to content

Commit

Permalink
Teach sigtool verify to use public key as a command line string (in l…
Browse files Browse the repository at this point in the history
…ieu of a file).

- Reorganized the code a bit and split each of sigtool's
  commands into a separate file.
- Added extra tests to validate verify's new capabilities
- Updated README
  • Loading branch information
opencoff committed Jan 13, 2024
1 parent d49f732 commit e305314
Show file tree
Hide file tree
Showing 11 changed files with 475 additions and 362 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ e.g., to verify the signature of *archive.tar.gz* against
sigtool verify /tmp/testkey.pub archive.sig archive.tar.gz


You can also pass a public key as a string (instead of a file):

sigtool verify iF84Dymq/bAEnUMK6DRIHWAQDRD8FwDDDfsgFfzdjWM= archive.sig archive.tar.gz

Note that signing and verifying can also work with OpenSSH ed25519
keys.

Expand Down
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#
# License: GPLv2
#
Progs=".:sigtool"
Progs="src:sigtool"

# Relative path to protobuf sources
# e.g. src/foo/a.proto
Expand Down
23 changes: 23 additions & 0 deletions sign/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,29 @@ func MakePublicKey(yml []byte) (*PublicKey, error) {
return &pk, nil
}

// Make a public key from a string
func MakePublicKeyFromString(s string) (*PublicKey, error) {
// first try to decode it as a openssh key
if pk2, err := parseEncPubKey([]byte(s), "command-line-pk"); err == nil {
return pk2, nil
}

// Now try to decode as an sigtool key
b64 := base64.StdEncoding.DecodeString

pkb, err := b64(s)
if err != nil {
return nil, err
}

var pk PublicKey
err = makePublicKeyFromBytes(&pk, pkb)
if err != nil {
return nil, err
}
return &pk, nil
}

func makePublicKeyFromBytes(pk *PublicKey, b []byte) error {
if len(b) != 32 {
return fmt.Errorf("public key is malformed (len %d!)", len(b))
Expand Down
Loading

0 comments on commit e305314

Please sign in to comment.