-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcheckpoint_test.go
More file actions
69 lines (66 loc) · 1.83 KB
/
checkpoint_test.go
File metadata and controls
69 lines (66 loc) · 1.83 KB
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
package sunlight
import (
"encoding/base64"
"encoding/json"
"testing"
ct "github.com/google/certificate-transparency-go"
"golang.org/x/mod/sumdb/note"
"golang.org/x/mod/sumdb/tlog"
)
func TestRFC6962InjectedSigner(t *testing.T) {
sig, err := base64.StdEncoding.DecodeString("BAMASDBGAiEAnaHGuwnyyHWvrfgEn3qtl1j2heMzocku6ZAItYD75m8CIQCpotlpH5GEPEfMMzky72BCuIl14FB65t5SWZ91vgTQOg==")
if err != nil {
t.Fatal(err)
}
sthBytes := []byte(`{
"sha256_root_hash": "l+XrWXWRyp4SmATORgTfz4CcYS/VlE7CeTuWI0FAk3o=",
"timestamp": 1588741228371,
"tree_head_signature": "BAMASDBGAiEAnaHGuwnyyHWvrfgEn3qtl1j2heMzocku6ZAItYD75m8CIQCpotlpH5GEPEfMMzky72BCuIl14FB65t5SWZ91vgTQOg==",
"tree_size": 90785920
}`)
var sth ct.SignedTreeHead
if err := json.Unmarshal(sthBytes, &sth); err != nil {
t.Fatal(err)
}
key, err := ct.PublicKeyFromB64("MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAESYlKFDLLFmA9JScaiaNnqlU8oWDytxIYMfswHy9Esg0aiX+WnP/yj4O0ViEHtLwbmOQeSWBGkIu9YK9CLeer+g==")
if err != nil {
t.Fatal(err)
}
verifier, err := ct.NewSignatureVerifier(key)
if err != nil {
t.Fatal(err)
}
if err := verifier.VerifySTHSignature(sth); err != nil {
t.Fatal(err)
}
s, err := NewRFC6962InjectedSigner("example.com", key, sig, int64(sth.Timestamp))
if err != nil {
t.Fatal(err)
}
c := &Checkpoint{
Origin: "example.com",
Tree: tlog.Tree{
N: int64(sth.TreeSize),
Hash: tlog.Hash(sth.SHA256RootHash),
},
}
n, err := note.Sign(¬e.Note{Text: c.String()}, s)
if err != nil {
t.Fatal(err)
}
v, err := NewRFC6962Verifier("example.com", key)
if err != nil {
t.Fatal(err)
}
nn, err := note.Open([]byte(n), note.VerifierList(v))
if err != nil {
t.Fatal(err)
}
tt, err := RFC6962SignatureTimestamp(nn.Sigs[0])
if err != nil {
t.Fatal(err)
}
if tt != int64(sth.Timestamp) {
t.Fatalf("got timestamp %d, want %d", tt, sth.Timestamp)
}
}