-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrfc3161_test.go
More file actions
83 lines (69 loc) · 1.82 KB
/
Copy pathrfc3161_test.go
File metadata and controls
83 lines (69 loc) · 1.82 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
package evtree
import (
"os"
"path/filepath"
"testing"
)
func TestVerifyTimestampNoToken(t *testing.T) {
bag := Acquisition{}
if err := VerifyTimestamp(bag); err == nil {
t.Error("expected error for bag with no timestamp token")
}
}
func TestTimestampInvalidTSA(t *testing.T) {
bag := makeAcquisition(t)
err := Timestamp(&bag, "http://invalid.tsa.example.com")
if err == nil {
t.Error("expected error for invalid TSA URL")
}
}
func TestTimestampAndVerify(t *testing.T) {
if testing.Short() {
t.Skip("skipping RFC 3161 integration test in short mode")
}
bag := makeAcquisition(t)
if err := Timestamp(&bag, DefaultTSA); err != nil {
t.Fatalf("Timestamp: %v", err)
}
if bag.TimestampToken == nil {
t.Fatal("expected timestamp token to be set")
}
if bag.TimestampedAt.IsZero() {
t.Fatal("expected timestamped_at to be set")
}
if err := VerifyTimestamp(bag); err != nil {
t.Fatalf("VerifyTimestamp: %v", err)
}
}
func TestVerifyTimestampTamperedAcquisition(t *testing.T) {
if testing.Short() {
t.Skip("skipping RFC 3161 integration test in short mode")
}
bag := makeAcquisition(t)
if err := Timestamp(&bag, DefaultTSA); err != nil {
t.Fatalf("Timestamp: %v", err)
}
// Tamper with the root hash after timestamping
bag.Root.Hash = Hash32{}
if err := VerifyTimestamp(bag); err == nil {
t.Error("expected verification to fail after tampering with root hash")
}
}
func makeAcquisition(t *testing.T) Acquisition {
t.Helper()
dir := t.TempDir()
if err := os.WriteFile(filepath.Join(dir, "evidence.txt"), []byte("test evidence"), 0644); err != nil {
t.Fatal(err)
}
meta := CaseMetadata{
CaseNumber: "TEST-001",
ExhibitRef: "EX-01",
Examiner: "Test Examiner",
Organisation: "Test Lab",
}
bag, _, err := Acquire(dir, meta)
if err != nil {
t.Fatalf("Acquire: %v", err)
}
return bag
}