-
Notifications
You must be signed in to change notification settings - Fork 0
/
conditions.go
66 lines (55 loc) · 1.7 KB
/
conditions.go
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
package conditions
import (
"fmt"
"github.com/go-piv/piv-go/piv"
)
type MinimumConditions struct {
Version piv.Version
PINPolicy piv.PINPolicy
//TouchPolicy piv.TouchPolicy // Unimplemented due to https://github.com/go-piv/piv-go/issues/102
Slots []piv.Slot
Formfactors []piv.Formfactor
}
func (cond *MinimumConditions) Verify(attestation piv.Attestation) error {
if cond.Version.Major > attestation.Version.Major {
return fmt.Errorf("Key's major version %v is older than the minimum, %v", attestation.Version, cond.Version)
}
if cond.Version.Minor > attestation.Version.Minor {
return fmt.Errorf("Key's minor version %v is older than the minimum, %v", attestation.Version, cond.Version)
}
if cond.Version.Patch > attestation.Version.Patch {
return fmt.Errorf("Key's patch version %v is older than the minimum, %v", attestation.Version, cond.Version)
}
if cond.PINPolicy > attestation.PINPolicy {
return fmt.Errorf("Key's PINPolicy %v is less strict than the minimum %v", attestation.PINPolicy, cond.PINPolicy)
}
if !slot_matches(cond.Slots, attestation.Slot) {
return fmt.Errorf("Key's Slot %v isn't accepted (%v}", attestation.Slot, cond.Slots)
}
if !formfactor_matches(cond.Formfactors, attestation.Formfactor) {
return fmt.Errorf("Key's Formfactor %v isn't accepted (%v}", attestation.Slot, cond.Slots)
}
return nil
}
func slot_matches(elems []piv.Slot, v piv.Slot) bool {
if len(elems) == 0 {
return true
}
for _, s := range elems {
if v == s {
return true
}
}
return false
}
func formfactor_matches(elems []piv.Formfactor, v piv.Formfactor) bool {
if len(elems) == 0 {
return true
}
for _, s := range elems {
if v == s {
return true
}
}
return false
}