-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathloglist_test.go
More file actions
88 lines (78 loc) · 1.72 KB
/
Copy pathloglist_test.go
File metadata and controls
88 lines (78 loc) · 1.72 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"crypto/ed25519"
"crypto/rand"
"fmt"
"testing"
"filippo.io/mldsa"
"filippo.io/torchwood"
"golang.org/x/mod/sumdb/note"
)
func TestParseLogListAccepts(t *testing.T) {
mldsaOrigin := "example.com/mldsa-log"
mldsaKey, err := mldsa.GenerateKey(mldsa.MLDSA44())
if err != nil {
t.Fatal(err)
}
mldsaSigner, err := torchwood.NewCosignatureSigner(mldsaOrigin, mldsaKey)
if err != nil {
t.Fatal(err)
}
mldsaVkey := mldsaSigner.Verifier().String()
_, edVkey, err := note.GenerateKey(rand.Reader, "example.com/ed25519-log")
if err != nil {
t.Fatal(err)
}
list := fmt.Sprintf(`
# Log list that should be accepted
logs/v0
# ML-DSA-44 log
vkey %s
qpd 24
# should be ignored
unknown-key some-value
contact test@mldsa-log
# Ed25519 log
vkey %s
qpd 3600
contact test@ed25519-log
`, mldsaVkey, edVkey)
logs, err := parseLogList([]byte(list), false)
if err != nil {
t.Fatal(err)
}
if len(logs) != 2 {
t.Errorf("expected two logs, got: %d", len(logs))
}
if logs[mldsaOrigin] != mldsaVkey {
t.Errorf("ML-DSA log not parsed: %v", logs)
}
if logs["example.com/ed25519-log"] != edVkey {
t.Errorf("Ed25519 log not parsed: %v", logs)
}
}
func TestParseLogListSkipsEd25519Cosignature(t *testing.T) {
origin := "example.com/ed-cosig-log"
_, k, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
t.Fatal(err)
}
signer, err := torchwood.NewCosignatureSigner(origin, k)
if err != nil {
t.Fatal(err)
}
vkey := signer.Verifier().String()
list := fmt.Sprintf(`
logs/v0
vkey %s
qpd 24
contact test@ed25519-cosig
`, vkey)
logs, err := parseLogList([]byte(list), true)
if err != nil {
t.Fatal(err)
}
if len(logs) != 0 {
t.Errorf("expected Ed25519 cosignature log to be skipped, got: %v", logs)
}
}