...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package loglist3
16
17 import (
18 "github.com/google/certificate-transparency-go/x509"
19 "github.com/google/certificate-transparency-go/x509util"
20 "k8s.io/klog/v2"
21 )
22
23
24
25 type LogRoots map[string]*x509util.PEMCertPool
26
27
28
29 func (ll *LogList) Compatible(cert *x509.Certificate, certRoot *x509.Certificate, roots LogRoots) LogList {
30 active := ll.TemporallyCompatible(cert)
31 return active.RootCompatible(certRoot, roots)
32 }
33
34
35
36 func (ll *LogList) SelectByStatus(lstats []LogStatus) LogList {
37 var active LogList
38 for _, op := range ll.Operators {
39 activeOp := *op
40 activeOp.Logs = []*Log{}
41 for _, l := range op.Logs {
42 for _, lstat := range lstats {
43 if l.State.LogStatus() == lstat {
44 activeOp.Logs = append(activeOp.Logs, l)
45 break
46 }
47 }
48 }
49 if len(activeOp.Logs) > 0 {
50 active.Operators = append(active.Operators, &activeOp)
51 }
52 }
53 return active
54 }
55
56
57
58
59
60
61
62 func (ll *LogList) RootCompatible(certRoot *x509.Certificate, roots LogRoots) LogList {
63 var compatible LogList
64
65
66 if certRoot != nil && !certRoot.IsCA {
67 klog.Warningf("Compatible method expects fully rooted chain, while last cert of the chain provided is not root")
68 return compatible
69 }
70
71 for _, op := range ll.Operators {
72 compatibleOp := *op
73 compatibleOp.Logs = []*Log{}
74 for _, l := range op.Logs {
75
76
77 if _, ok := roots[l.URL]; !ok {
78 compatibleOp.Logs = append(compatibleOp.Logs, l)
79 continue
80 }
81
82 if certRoot == nil {
83 continue
84 }
85
86
87 if roots[l.URL].Included(certRoot) {
88 compatibleOp.Logs = append(compatibleOp.Logs, l)
89 }
90 }
91 if len(compatibleOp.Logs) > 0 {
92 compatible.Operators = append(compatible.Operators, &compatibleOp)
93 }
94 }
95 return compatible
96 }
97
98
99
100
101
102 func (ll *LogList) TemporallyCompatible(cert *x509.Certificate) LogList {
103 var compatible LogList
104 if cert == nil {
105 return compatible
106 }
107
108 for _, op := range ll.Operators {
109 compatibleOp := *op
110 compatibleOp.Logs = []*Log{}
111 for _, l := range op.Logs {
112 if l.TemporalInterval == nil {
113 compatibleOp.Logs = append(compatibleOp.Logs, l)
114 continue
115 }
116 if cert.NotAfter.Before(l.TemporalInterval.EndExclusive) && (cert.NotAfter.After(l.TemporalInterval.StartInclusive) || cert.NotAfter.Equal(l.TemporalInterval.StartInclusive)) {
117 compatibleOp.Logs = append(compatibleOp.Logs, l)
118 }
119 }
120 if len(compatibleOp.Logs) > 0 {
121 compatible.Operators = append(compatible.Operators, &compatibleOp)
122 }
123 }
124 return compatible
125 }
126
View as plain text