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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
package testdata
import (
"bytes"
"testing"
"time"
"crypto/ed25519"
"github.com/google/trillian"
ttypes "github.com/google/trillian/types"
"github.com/system-transparency/stfe/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
var (
Ed25519VkLog = [32]byte{}
Ed25519VkLog2 = [32]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
Ed25519VkLog3 = [32]byte{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}
//Ed25519VkWitness = [32]byte{3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}
// Ed25519VkWitness2 = [32]byte{4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}
Ed25519VkWitness3 = [32]byte{5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}
//Ed25519VkSubmitter = [32]byte{6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6}
TreeId = int64(0)
Prefix = "test"
MaxRange = int64(3)
Interval = time.Second * 10
Deadline = time.Second * 5
Timestamp = uint64(0)
TreeSize = uint64(0)
Extension = make([]byte, 0)
NodeHash = make([]byte, 32)
Signature = make([]byte, 64)
Identifier = []byte("foobar-1.2.3")
Checksum = make([]byte, 32)
Index = int64(0)
HashPath = [][]byte{
NodeHash,
}
NodePath = []types.NodeHash{
types.NodeHash{NodeHash},
}
LeafHash = [32]byte{}
// TODO: make these unique and load more pretty maybe
Ed25519SkWitness = [64]byte{230, 122, 195, 152, 194, 195, 147, 153, 80, 120, 153, 79, 102, 27, 52, 187, 136, 218, 150, 234, 107, 9, 167, 4, 92, 21, 11, 113, 42, 29, 129, 69, 75, 60, 249, 150, 229, 93, 75, 32, 103, 126, 244, 37, 53, 182, 68, 82, 249, 109, 49, 94, 10, 19, 146, 244, 58, 191, 169, 107, 78, 37, 45, 210}
Ed25519VkWitness = [32]byte{75, 60, 249, 150, 229, 93, 75, 32, 103, 126, 244, 37, 53, 182, 68, 82, 249, 109, 49, 94, 10, 19, 146, 244, 58, 191, 169, 107, 78, 37, 45, 210}
Ed25519SkWitness2 = [64]byte{98, 65, 92, 117, 33, 167, 138, 36, 252, 147, 87, 173, 44, 62, 17, 66, 126, 70, 218, 87, 91, 148, 64, 194, 241, 248, 62, 90, 140, 122, 234, 76, 144, 6, 250, 185, 37, 217, 77, 201, 180, 42, 81, 37, 165, 27, 22, 32, 25, 8, 156, 228, 78, 207, 208, 18, 91, 77, 189, 51, 112, 31, 237, 6}
Ed25519VkWitness2 = [32]byte{144, 6, 250, 185, 37, 217, 77, 201, 180, 42, 81, 37, 165, 27, 22, 32, 25, 8, 156, 228, 78, 207, 208, 18, 91, 77, 189, 51, 112, 31, 237, 6}
Ed25519SkSubmitter = [64]byte{230, 122, 195, 152, 194, 195, 147, 153, 80, 120, 153, 79, 102, 27, 52, 187, 136, 218, 150, 234, 107, 9, 167, 4, 92, 21, 11, 113, 42, 29, 129, 69, 75, 60, 249, 150, 229, 93, 75, 32, 103, 126, 244, 37, 53, 182, 68, 82, 249, 109, 49, 94, 10, 19, 146, 244, 58, 191, 169, 107, 78, 37, 45, 210}
Ed25519VkSubmitter = [32]byte{75, 60, 249, 150, 229, 93, 75, 32, 103, 126, 244, 37, 53, 182, 68, 82, 249, 109, 49, 94, 10, 19, 146, 244, 58, 191, 169, 107, 78, 37, 45, 210}
Ed25519SkSubmitter2 = [64]byte{98, 65, 92, 117, 33, 167, 138, 36, 252, 147, 87, 173, 44, 62, 17, 66, 126, 70, 218, 87, 91, 148, 64, 194, 241, 248, 62, 90, 140, 122, 234, 76, 144, 6, 250, 185, 37, 217, 77, 201, 180, 42, 81, 37, 165, 27, 22, 32, 25, 8, 156, 228, 78, 207, 208, 18, 91, 77, 189, 51, 112, 31, 237, 6}
Ed25519VkSubmitter2 = [32]byte{144, 6, 250, 185, 37, 217, 77, 201, 180, 42, 81, 37, 165, 27, 22, 32, 25, 8, 156, 228, 78, 207, 208, 18, 91, 77, 189, 51, 112, 31, 237, 6}
)
// TODO: reorder and docdoc where need be
//
// Helpers that must create default values for different STFE types
//
func DefaultCosth(t *testing.T, logVk [32]byte, witVk [][32]byte) *types.StItem {
t.Helper()
cosigs := make([]types.SignatureV1, 0)
for _, vk := range witVk {
cosigs = append(cosigs, types.SignatureV1{*NewNamespace(t, vk), Signature})
}
return types.NewCosignedTreeHeadV1(DefaultSth(t, logVk).SignedTreeHeadV1, cosigs)
}
func DefaultSth(t *testing.T, vk [32]byte) *types.StItem {
t.Helper()
return types.NewSignedTreeHeadV1(DefaultTh(t), DefaultSig(t, vk))
}
func DefaultSignedChecksum(t *testing.T, vk [32]byte) *types.StItem {
t.Helper()
return types.NewSignedChecksumV1(DefaultChecksum(t), DefaultSig(t, vk))
}
func DefaultTh(t *testing.T) *types.TreeHeadV1 {
t.Helper()
return types.NewTreeHeadV1(Timestamp, TreeSize, NodeHash, Extension)
}
func DefaultSig(t *testing.T, vk [32]byte) *types.SignatureV1 {
t.Helper()
return &types.SignatureV1{*NewNamespace(t, vk), Signature}
}
func DefaultChecksum(t *testing.T) *types.ChecksumV1 {
t.Helper()
return &types.ChecksumV1{Identifier, Checksum}
}
func AddCosignatureBuffer(t *testing.T, sth *types.StItem, sk *[64]byte, vk *[32]byte) *bytes.Buffer {
t.Helper()
var cosigs []types.SignatureV1
if vk != nil {
cosigs = []types.SignatureV1{
types.SignatureV1{
Namespace: *NewNamespace(t, *vk),
Signature: ed25519.Sign(ed25519.PrivateKey((*sk)[:]), marshal(t, *sth.SignedTreeHeadV1)),
},
}
}
return bytes.NewBuffer(marshal(t, *types.NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, cosigs)))
}
func AddSignedChecksumBuffer(t *testing.T, sk [64]byte, vk [32]byte) *bytes.Buffer {
t.Helper()
data := DefaultChecksum(t)
return bytes.NewBuffer(marshal(t, *types.NewSignedChecksumV1(
data,
&types.SignatureV1{
Namespace: *NewNamespace(t, vk),
Signature: ed25519.Sign(ed25519.PrivateKey(sk[:]), marshal(t, *data)),
},
)))
}
func NewNamespacePool(t *testing.T, namespaces []*types.Namespace) *types.NamespacePool {
pool, err := types.NewNamespacePool(namespaces)
if err != nil {
t.Fatalf("must make namespace pool: %v", err)
}
return pool
}
func NewNamespace(t *testing.T, vk [32]byte) *types.Namespace {
namespace, err := types.NewNamespaceEd25519V1(vk[:])
if err != nil {
t.Fatalf("must make Ed25519V1 namespace: %v", err)
}
return namespace
}
//
// Helpers that must create default values for different Trillian types
//
// DefaultTLr creates a default Trillian log root
func DefaultTLr(t *testing.T) *ttypes.LogRootV1 {
t.Helper()
return Tlr(t, TreeSize, Timestamp, NodeHash)
}
// Tlr creates a Trillian log root
func Tlr(t *testing.T, size, timestamp uint64, hash []byte) *ttypes.LogRootV1 {
t.Helper()
return &ttypes.LogRootV1{
TreeSize: size,
RootHash: hash,
TimestampNanos: timestamp,
Revision: 0, // not used by stfe
Metadata: nil, // not used by stfe
}
}
// DefaultTSlr creates a default Trillian signed log root
func DefaultTSlr(t *testing.T) *trillian.GetLatestSignedLogRootResponse {
t.Helper()
return Tslr(t, DefaultTLr(t))
}
// Tslr creates a Trillian signed log root
func Tslr(t *testing.T, lr *ttypes.LogRootV1) *trillian.GetLatestSignedLogRootResponse {
t.Helper()
b, err := lr.MarshalBinary()
if err != nil {
t.Fatalf("must marshal Trillian log root: %v", err)
}
return &trillian.GetLatestSignedLogRootResponse{
SignedLogRoot: &trillian.SignedLogRoot{
KeyHint: nil, // not used by stfe
LogRoot: b,
LogRootSignature: nil, // not used by stfe
},
Proof: nil, // not used by stfe
}
}
// DefaultTQlr creates a default Trillian queue leaf response
func DefaultTQlr(t *testing.T, withDupCode bool) *trillian.QueueLeafResponse {
t.Helper()
s := status.New(codes.OK, "ok").Proto()
if withDupCode {
s = status.New(codes.AlreadyExists, "duplicate").Proto()
}
return &trillian.QueueLeafResponse{
QueuedLeaf: &trillian.QueuedLogLeaf{
Leaf: &trillian.LogLeaf{
MerkleLeafHash: nil, // not used by stfe
LeafValue: marshal(t, *DefaultSignedChecksum(t, Ed25519VkSubmitter)),
ExtraData: nil, // not used by stfe
LeafIndex: 0, // not applicable (log is not pre-ordered)
LeafIdentityHash: nil, // not used by stfe
},
Status: s,
},
}
}
// DefaultTglbrr creates a default Trillian get leaves by range response
func DefaultTGlbrr(t *testing.T, start, end int64) *trillian.GetLeavesByRangeResponse {
t.Helper()
leaves := make([]*trillian.LogLeaf, 0, end-start+1)
for i, n := start, end+1; i < n; i++ {
leaves = append(leaves, &trillian.LogLeaf{
MerkleLeafHash: nil, // not usedb y stfe
LeafValue: marshal(t, *DefaultSignedChecksum(t, Ed25519VkSubmitter)),
ExtraData: nil, // not used by stfe
LeafIndex: i,
LeafIdentityHash: nil, // not used by stfe
})
}
return &trillian.GetLeavesByRangeResponse{
Leaves: leaves,
SignedLogRoot: Tslr(t, Tlr(t, uint64(end)+1, Timestamp, NodeHash)).SignedLogRoot,
}
}
func DefaultStItemList(t *testing.T, start, end uint64) *types.StItemList {
items := make([]types.StItem, 0, end-start+1)
for i, n := start, end+1; i < n; i++ {
items = append(items, *DefaultSignedChecksum(t, Ed25519VkSubmitter))
}
return &types.StItemList{items}
}
// DefaultTGipbhr creates a default Trillian get inclusion proof by hash response
func DefaultTGipbhr(t *testing.T) *trillian.GetInclusionProofByHashResponse {
t.Helper()
return &trillian.GetInclusionProofByHashResponse{
Proof: []*trillian.Proof{
&trillian.Proof{
LeafIndex: Index,
Hashes: HashPath,
},
},
SignedLogRoot: nil, // not used by stfe
}
}
func DefaultInclusionProof(t *testing.T, size uint64) *types.StItem {
return types.NewInclusionProofV1(NewNamespace(t, Ed25519VkLog), size, uint64(Index), NodePath)
}
// DefaultTGcpr creates a default Trillian get consistency proof response
func DefaultTGcpr(t *testing.T) *trillian.GetConsistencyProofResponse {
t.Helper()
return &trillian.GetConsistencyProofResponse{
Proof: &trillian.Proof{
LeafIndex: 0, // not applicable for consistency proofs
Hashes: HashPath,
},
SignedLogRoot: nil, // not used by stfe
}
}
func DefaultConsistencyProof(t *testing.T, first, second uint64) *types.StItem {
return types.NewConsistencyProofV1(NewNamespace(t, Ed25519VkLog), first, second, NodePath)
}
//
// Other helpers
//
func Fingerprint(t *testing.T, namespace *types.Namespace) [types.NamespaceFingerprintSize]byte {
fpr, err := namespace.Fingerprint()
if err != nil {
t.Fatalf("must have namespace fingerprint: %v", err)
}
return *fpr
}
func marshal(t *testing.T, i interface{}) []byte {
b, err := types.Marshal(i)
if err != nil {
t.Fatalf("must marshal interface: %v", err)
}
return b
}
|