-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverifier.go
More file actions
116 lines (107 loc) · 3 KB
/
verifier.go
File metadata and controls
116 lines (107 loc) · 3 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
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
package securelog
import (
"crypto/hmac"
"errors"
)
// SemiTrustedVerifier represents a semi-trusted verifier (V) from Section 4.1 of the paper.
// V can verify logs using the A_i key chain but could potentially modify logs if malicious.
// The T-chain provides protection against malicious verifiers.
type SemiTrustedVerifier struct{ store Store }
// NewSemiTrustedVerifier creates a new semi-trusted verifier that validates the V-chain.
func NewSemiTrustedVerifier(store Store) *SemiTrustedVerifier {
return &SemiTrustedVerifier{store: store}
}
// VerifyFromAnchor loads records after anchor.Index and verifies the V-chain using (A_i, μ_V,i).
func (v *SemiTrustedVerifier) VerifyFromAnchor(a Anchor) error {
ch, done, err := v.store.Iter(a.Index + 1)
if err != nil {
return err
}
defer done()
var recs []Record
for r := range ch {
recs = append(recs, r)
}
final, err := VerifyFrom(recs, a.Index, a.Key, a.TagV)
if err != nil {
return err
}
tail, ok, err := v.store.Tail()
if err != nil {
return err
}
if !ok {
return errors.New("tail state unavailable")
}
if !hmac.Equal(final[:], tail.TagV[:]) {
return ErrTagMismatch
}
return nil
}
// TrustedVerifier represents the trusted server (T) from Section 4.1 of the paper.
// T holds the B_i key chain and can verify the T-chain which is protected from malicious verifiers.
type TrustedVerifier struct {
store Store
initialKeyB0 [KeySize]byte // B_0 - initial key for T-chain
}
// NewTrustedVerifier creates a new trusted verifier that validates the T-chain using initial key B_0.
func NewTrustedVerifier(store Store, b0 [KeySize]byte) *TrustedVerifier {
return &TrustedVerifier{store: store, initialKeyB0: b0}
}
// VerifyAll verifies the entire log from the beginning using the T-chain.
// This provides final validation that cannot be forged by a malicious verifier V.
func (t *TrustedVerifier) VerifyAll() error {
ch, done, err := t.store.Iter(1)
if err != nil {
return err
}
defer done()
var recs []Record
for r := range ch {
recs = append(recs, r)
}
var zeroTag [32]byte
final, err := VerifyFromTrusted(recs, 0, t.initialKeyB0, zeroTag)
if err != nil {
return err
}
tail, ok, err := t.store.Tail()
if err != nil {
return err
}
if !ok {
return errors.New("tail state unavailable")
}
if !hmac.Equal(final[:], tail.TagT[:]) {
return ErrTagMismatch
}
return nil
}
// VerifyFromAnchor verifies from a checkpoint using the T-chain.
// The anchor must contain B_i and μ_T,i for checkpoint i.
func (t *TrustedVerifier) VerifyFromAnchor(idx uint64, bi [KeySize]byte, tagT [32]byte) error {
ch, done, err := t.store.Iter(idx + 1)
if err != nil {
return err
}
defer done()
var recs []Record
for r := range ch {
recs = append(recs, r)
}
final, err := VerifyFromTrusted(recs, idx, bi, tagT)
if err != nil {
return err
}
tail, ok, err := t.store.Tail()
if err != nil {
return err
}
if !ok {
return errors.New("tail state unavailable")
}
if !hmac.Equal(final[:], tail.TagT[:]) {
return ErrTagMismatch
}
return nil
}