From cb6485bb6075179dc2521b8e82db961deae74faf Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Sat, 21 May 2022 20:31:09 +0200 Subject: add proof verification to sigsum-debug --- cmd/sigsum-debug/leaf/hash/hash.go | 2 +- cmd/sigsum-debug/leaf/inclusion/inclusion.go | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'cmd/sigsum-debug/leaf') diff --git a/cmd/sigsum-debug/leaf/hash/hash.go b/cmd/sigsum-debug/leaf/hash/hash.go index 4fd471c..a6fe1ad 100644 --- a/cmd/sigsum-debug/leaf/hash/hash.go +++ b/cmd/sigsum-debug/leaf/hash/hash.go @@ -18,7 +18,7 @@ func Main(args []string, optKeyHash, optSignature string, optShardHint uint64) e if err != nil { return fmt.Errorf("read stdin: %w", err) } - keyHash, err := fmtio.KeyHashFromHex(optKeyHash) + keyHash, err := fmtio.HashFromHex(optKeyHash) if err != nil { return fmt.Errorf("parse key hash: %w", err) } diff --git a/cmd/sigsum-debug/leaf/inclusion/inclusion.go b/cmd/sigsum-debug/leaf/inclusion/inclusion.go index f9aeb68..e70b3eb 100644 --- a/cmd/sigsum-debug/leaf/inclusion/inclusion.go +++ b/cmd/sigsum-debug/leaf/inclusion/inclusion.go @@ -1,9 +1,35 @@ package inclusion import ( + "bytes" "fmt" + + "git.sigsum.org/sigsum-go/internal/fmtio" + "git.sigsum.org/sigsum-go/pkg/types" ) func Main(args []string, optLeafHash, optRootHash string, optTreeSize uint64) error { - return fmt.Errorf("TODO") + if len(args) != 0 { + return fmt.Errorf("trailing arguments: %v", args) + } + b, err := fmtio.BytesFromStdin() + if err != nil { + return fmt.Errorf("read: %w", err) + } + var proof types.InclusionProof + if err := proof.FromASCII(bytes.NewBuffer(b), optTreeSize); err != nil { + return fmt.Errorf("parse proof: %w", err) + } + leafHash, err := fmtio.HashFromHex(optLeafHash) + if err != nil { + return fmt.Errorf("parse leaf hash: %w", err) + } + rootHash, err := fmtio.HashFromHex(optRootHash) + if err != nil { + return fmt.Errorf("parse root hash: %w", err) + } + if err := proof.Verify(&leafHash, &rootHash); err != nil { + return fmt.Errorf("verify: %w", err) + } + return nil } -- cgit v1.2.3