diff options
Diffstat (limited to 'cmd/tmp')
-rw-r--r-- | cmd/tmp/README.md | 2 | ||||
-rw-r--r-- | cmd/tmp/cosign/main.go | 56 | ||||
-rw-r--r-- | cmd/tmp/keygen/main.go | 17 | ||||
-rw-r--r-- | cmd/tmp/submit/main.go | 29 |
4 files changed, 104 insertions, 0 deletions
diff --git a/cmd/tmp/README.md b/cmd/tmp/README.md new file mode 100644 index 0000000..30d5317 --- /dev/null +++ b/cmd/tmp/README.md @@ -0,0 +1,2 @@ +# Warning +These basic commands will be moved or replaced by proper tooling. diff --git a/cmd/tmp/cosign/main.go b/cmd/tmp/cosign/main.go new file mode 100644 index 0000000..a51f17d --- /dev/null +++ b/cmd/tmp/cosign/main.go @@ -0,0 +1,56 @@ +package main + +import ( + "bytes" + "crypto/ed25519" + "encoding/hex" + "flag" + "fmt" + "log" + "net/http" + + "github.com/system-transparency/stfe/pkg/types" +) + +var ( + url = flag.String("url", "http://localhost:6965/st/v0", "base url") + sk = flag.String("sk", "e1d7c494dacb0ddf809a17e4528b01f584af22e3766fa740ec52a1711c59500d711090dd2286040b50961b0fe09f58aa665ccee5cb7ee042d819f18f6ab5046b", "hex key") +) + +func main() { + priv, err := hex.DecodeString(*sk) + if err != nil { + log.Fatalf("DecodeString: %v", err) + } + sk := ed25519.PrivateKey(priv) + vk := sk.Public().(ed25519.PublicKey) + fmt.Printf("sk: %x\nvk: %x\n", sk, vk) + + rsp, err := http.Get(*url + "/get-tree-head-to-sign") + if err != nil { + log.Fatalf("Get: %v", err) + } + var sth types.SignedTreeHead + if err := sth.UnmarshalASCII(rsp.Body); err != nil { + log.Fatalf("UnmarshalASCII: %v", err) + } + fmt.Printf("%+v\n", sth) + + msg := sth.TreeHead.Marshal() + sig := ed25519.Sign(sk, msg) + sigident := &types.SigIdent{ + KeyHash: types.Hash(vk[:]), + Signature: &[types.SignatureSize]byte{}, + } + copy(sigident.Signature[:], sig) + + buf := bytes.NewBuffer(nil) + if err := sigident.MarshalASCII(buf); err != nil { + log.Fatalf("MarshalASCII: %v", err) + } + rsp, err = http.Post(*url+"/add-cosignature", "type/stfe", buf) + if err != nil { + log.Fatalf("Post: %v", err) + } + fmt.Printf("Status: %v\n", rsp.StatusCode) +} diff --git a/cmd/tmp/keygen/main.go b/cmd/tmp/keygen/main.go new file mode 100644 index 0000000..c1c1b58 --- /dev/null +++ b/cmd/tmp/keygen/main.go @@ -0,0 +1,17 @@ +package main + +import ( + "crypto/ed25519" + "crypto/rand" + "fmt" + "log" +) + +func main() { + vk, sk, err := ed25519.GenerateKey(rand.Reader) + if err != nil { + log.Fatalf("GenerateKey: %v", err) + } + fmt.Printf("sk: %x\n", sk[:]) + fmt.Printf("vk: %x\n", vk[:]) +} diff --git a/cmd/tmp/submit/main.go b/cmd/tmp/submit/main.go new file mode 100644 index 0000000..3dcaa97 --- /dev/null +++ b/cmd/tmp/submit/main.go @@ -0,0 +1,29 @@ +package main + +// go run . | bash + +import ( + "crypto/ed25519" + "crypto/rand" + "fmt" + + "github.com/system-transparency/stfe/pkg/types" +) + +func main() { + checksum := [32]byte{} + msg := types.Message{ + ShardHint: 0, + Checksum: &checksum, + } + + vk, sk, err := ed25519.GenerateKey(rand.Reader) + if err != nil { + fmt.Printf("ed25519.GenerateKey: %v\n", err) + return + } + sig := ed25519.Sign(sk, msg.Marshal()) + //fmt.Printf("sk: %x\nvk: %x\n", sk[:], vk[:]) + + fmt.Printf("echo \"shard_hint=%d\nchecksum=%x\nsignature_over_message=%x\nverification_key=%x\ndomain_hint=%s\" | curl --data-binary @- localhost:6965/st/v0/add-leaf\n", msg.ShardHint, msg.Checksum[:], sig, vk[:], "example.com") +} |