aboutsummaryrefslogtreecommitdiff
path: root/client/get-consistency-proof/main.go
blob: 316bbdc45eaab39777d8a15ddd7d3b93214ca29f (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
package main

import (
	"context"
	"flag"
	"fmt"

	"net/http"

	"github.com/golang/glog"
	"github.com/system-transparency/stfe"
	"github.com/system-transparency/stfe/client"
)

var (
	operators = flag.String("operators", "../../descriptor/stfe.json", "path to json-encoded list of log operators")
	logId     = flag.String("log_id", "B9oCJk4XIOMXba8dBM5yUj+NLtqTE6xHwbvR9dYkHPM=", "base64-encoded log identifier")
	first     = flag.String("first", "AAEgB9oCJk4XIOMXba8dBM5yUj+NLtqTE6xHwbvR9dYkHPMAAAF1jnn7fwAAAAAAAAAxICCqLJn4QWYd0aRIRjDWGf4GWalDIb/iH60jSSX89WgvAAAAQF9XPFRdM56KaelHFFg1RqjTw1yFL085zHhdNkLeZh9BCXxVTByqrHEMngAkY69EX45aJMWh9NymmPau0qoigA8=", "first base64-encoded StItem of type StFormatSignedTreeHeadV1")
	second    = flag.String("second", "AAEgB9oCJk4XIOMXba8dBM5yUj+NLtqTE6xHwbvR9dYkHPMAAAF1jsZrygAAAAAAAABFIL7Zz0WEolql7o7G496Izl7Qy/l2Qd/Pwc87W8jFPoL6AAAAQHc7ttIDUKuMJR7uqCLb3qqAxiwEN5KLt/7IblT7f+QaKq4BqqI3cO6vT3eMSZMHZDd4EkgvkAwo1o7IsA4N8Qc=", "second base64-encoded StItem of type StFormatSignedTreeHeadV1")
)

func main() {
	flag.Parse()

	cli, err := client.NewClientFromPath(*logId, "", "", *operators, &http.Client{}, true)
	if err != nil {
		glog.Fatal(err)
	}

	k, err := cli.Log.Key()
	if err != nil {
		glog.Fatalf("bad public key: %v", err)
	}

	var sth1 stfe.StItem
	if err := sth1.UnmarshalB64(*first); err != nil {
		glog.Fatalf("bad signed tree head: %v", err)
	}
	if err := client.VerifySignedTreeHeadV1(&sth1, cli.Log.Scheme, k); err != nil {
		glog.Fatalf("bad signed tree head: %v", err)
	}
	glog.V(3).Info("verified first sth")

	var sth2 stfe.StItem
	if err := sth2.UnmarshalB64(*second); err != nil {
		glog.Fatalf("bad signed tree head: %v", err)
	}
	if err := client.VerifySignedTreeHeadV1(&sth2, cli.Log.Scheme, k); err != nil {
		glog.Fatalf("bad signed tree head: %v", err)
	}
	glog.V(3).Info("verified second sth")

	proof, err := cli.GetConsistencyProof(context.Background(), &sth1, &sth2)
	if err != nil {
		glog.Fatalf("get-proof-by-hash failed: %v", err)
	}
	glog.V(3).Info("verified inclusion proof")

	str, err := proof.MarshalB64()
	if err != nil {
		glog.Fatalf("failed encoding valid inclusion proof: %v", err)
	}
	fmt.Println(str)

	glog.Flush()
}