aboutsummaryrefslogtreecommitdiff
path: root/cmd/sigsum-debug/cosign
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/sigsum-debug/cosign')
-rw-r--r--cmd/sigsum-debug/cosign/cosign.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/cmd/sigsum-debug/cosign/cosign.go b/cmd/sigsum-debug/cosign/cosign.go
new file mode 100644
index 0000000..8597cc6
--- /dev/null
+++ b/cmd/sigsum-debug/cosign/cosign.go
@@ -0,0 +1,41 @@
+package cosign
+
+import (
+ "bytes"
+ "fmt"
+
+ "git.sigsum.org/sigsum-go/pkg/hex"
+ "git.sigsum.org/sigsum-go/pkg/types"
+ "git.sigsum.org/sigsum-tools-go/internal/util"
+)
+
+func Main(_ []string, optPriv, optPub string) error {
+ priv, err := util.SignerFromHex(optPriv)
+ if err != nil {
+ return fmt.Errorf("cosign: %v", err)
+ }
+ b, err := hex.Deserialize(optPub)
+ if err != nil {
+ return fmt.Errorf("cosign: %v", err)
+ }
+ if len(b) != types.PublicKeySize {
+ return fmt.Errorf("cosign: invalid public key length %d", len(b))
+ }
+ var pub types.PublicKey
+ copy(pub[:], b)
+ data, err := util.BytesFromStdin()
+ if err != nil {
+ return fmt.Errorf("cosign: %v", err)
+ }
+ var sth types.SignedTreeHead
+ if err := sth.FromASCII(bytes.NewBuffer(data)); err != nil {
+ return fmt.Errorf("cosign: %v", err)
+ }
+ witSTH, err := sth.TreeHead.Sign(priv, types.HashFn(pub[:]))
+ if err != nil {
+ return fmt.Errorf("cosign: %v", err)
+ }
+
+ fmt.Printf("%s\n", hex.Serialize(witSTH.Signature[:]))
+ return nil
+}