aboutsummaryrefslogtreecommitdiff
path: root/cmd/tmp/submit/main.go
blob: f29b168597898d87b0f08d0144650bde4f30fd73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main

// go run . | bash

import (
	"crypto/ed25519"
	"crypto/rand"
	"encoding/hex"
	"flag"
	"fmt"
	"log"

	"git.sigsum.org/sigsum-lib-go/pkg/types"
)

var (
	shardHint  = flag.Uint64("shard_hint", 0, "shard hint (decimal)")
	checksum   = flag.String("checksum", "", "checksum (hex)")
	sk         = flag.String("sk", "", "secret key (hex)")
	domainHint = flag.String("domain_hint", "example.com", "domain hint (string)")
	base_url   = flag.String("base_url", "localhost:6965/testonly", "base url (string)")
)

func main() {
	flag.Parse()

	var privBuf [64]byte
	var priv ed25519.PrivateKey = ed25519.PrivateKey(privBuf[:])
	mustDecodeHex(*sk, priv[:])

	var c types.Hash
	if *checksum != "" {
		mustDecodeHex(*checksum, c[:])
	} else {
		mustPutRandom(c[:])
	}

	msg := types.Statement{
		ShardHint: *shardHint,
		Checksum:  c,
	}
	sig := ed25519.Sign(priv, msg.ToBinary())

	fmt.Printf("echo \"shard_hint=%d\nchecksum=%x\nsignature=%x\nverification_key=%x\ndomain_hint=%s\" | curl --data-binary @- %s/sigsum/v0/add-leaf\n",
		msg.ShardHint,
		msg.Checksum[:],
		sig,
		priv.Public().(ed25519.PublicKey)[:],
		*domainHint,
		*base_url,
	)
}

func mustDecodeHex(s string, buf []byte) {
	b, err := hex.DecodeString(s)
	if err != nil {
		log.Fatal(err)
	}
	if len(b) != len(buf) {
		log.Fatal("bad flag: invalid buffer length")
	}
	copy(buf, b)
}

func mustPutRandom(buf []byte) {
	_, err := rand.Read(buf)
	if err != nil {
		log.Fatal(err)
	}
}