-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathboot_entry.go
More file actions
97 lines (79 loc) · 2.63 KB
/
boot_entry.go
File metadata and controls
97 lines (79 loc) · 2.63 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
// Copyright (c) The go-boot authors. All Rights Reserved.
//
// Use of this source code is governed by the license
// that can be found in the LICENSE file.
// Package transparency implements an interface to the
// boot-transparency library functions to ease boot bundle
// validation.
package transparency
import (
"fmt"
"github.com/usbarmory/boot-transparency/policy"
"github.com/usbarmory/boot-transparency/transparency"
)
// Validate applies boot-transparency validation (e.g. inclusion proof,
// boot policy and claims consistency) for the argument [Config] representing
// the boot transparency configuration.
// Returns error if the boot artifacts are not passing the validation.
func Validate(c *Config, b *policy.BootEntry) (err error) {
if c.Status == None {
return
}
if len(*b) == 0 {
return fmt.Errorf("invalid boot entry")
}
// Automatically load the configuration from the configured root filesystem.
if c.Root != nil {
entryPath, err := c.Path(b)
if err != nil {
return fmt.Errorf("cannot load boot-transparency configuration, %v", err)
}
if err = c.loadFromRoot(entryPath); err != nil {
return fmt.Errorf("cannot load boot-transparency configuration, %v", err)
}
}
te, err := transparency.GetEngine(c.Engine)
if err != nil {
return fmt.Errorf("unable to get transparency engine, %v", err)
}
if err = te.SetKey(c.LogKey, c.SubmitKey); err != nil {
return fmt.Errorf("unable to set log and submitter keys, %v", err)
}
if err = te.SetWitnessPolicy(c.WitnessPolicy); err != nil {
return fmt.Errorf("unable to set witness policy, %v", err)
}
format, statement, proof, probe, _, err := transparency.ParseProofBundle(c.ProofBundle)
if err != nil {
return fmt.Errorf("unable to parse the proof bundle, %v", err)
}
if format != c.Engine {
return fmt.Errorf("proof bundle format doesn't match the transparency engine.")
}
// If network access is available the inclusion proof verification
// is performed using the proof fetched from the log.
if c.Status == Online {
proof, err = te.GetProof(statement, probe)
if err != nil {
return err
}
}
if err = te.VerifyProof(statement, proof, nil); err != nil {
return err
}
requirements, err := policy.ParseRequirements(c.BootPolicy)
if err != nil {
return
}
claims, err := policy.ParseStatement(statement)
if err != nil {
return
}
// Validate the matching between the logged claims and the policy requirements,
// fot the given set of boot artifacts.
if err = policy.Validate(requirements, claims, b); err != nil {
// The boot bundle is NOT authorized.
return
}
// boot-transparency validation passed, boot bundle is authorized.
return
}