@@ -29,6 +29,35 @@ import (
29
29
"k8s.io/klog/v2"
30
30
)
31
31
32
+ type ChainValidationConfig struct {
33
+ // Path to the file containing root certificates that are acceptable to the
34
+ // log. The certs are served through get-roots endpoint.
35
+ RootsPemFile string
36
+ // If RejectExpired is true then the certificate validity period will be
37
+ // checked against the current time during the validation of submissions.
38
+ // This will cause expired certificates to be rejected.
39
+ RejectExpired bool
40
+ // If RejectUnexpired is true then CTFE rejects certificates that are either
41
+ // currently valid or not yet valid.
42
+ RejectUnexpired bool
43
+ // If set, ExtKeyUsages will restrict the set of such usages that the
44
+ // server will accept. By default all are accepted. The values specified
45
+ // must be ones known to the x509 package, comma separated.
46
+ ExtKeyUsages string
47
+ // A comma separated list of X.509 extension OIDs, in dotted string form
48
+ // (e.g. "2.3.4.5") which, if present, should cause submissions to be
49
+ // rejected.
50
+ RejectExtensions string
51
+ // NotAfterStart defines the start of the range of acceptable NotAfter
52
+ // values, inclusive.
53
+ // Leaving this unset implies no lower bound to the range.
54
+ NotAfterStart * time.Time
55
+ // NotAfterLimit defines the end of the range of acceptable NotAfter values,
56
+ // exclusive.
57
+ // Leaving this unset implies no upper bound to the range.
58
+ NotAfterLimit * time.Time
59
+ }
60
+
32
61
// ValidatedLogConfig represents the LogConfig with the information that has
33
62
// been successfully parsed as a result of validating it.
34
63
type ValidatedLogConfig struct {
@@ -49,17 +78,18 @@ type ValidatedLogConfig struct {
49
78
// - Merge delays (if present) are correct.
50
79
//
51
80
// Returns the validated structures (useful to avoid double validation).
52
- func ValidateLogConfig (origin string , rootsPemFile string , rejectExpired bool , rejectUnexpired bool , extKeyUsages string , rejectExtensions string , notAfterStart * time.Time , notAfterLimit * time.Time , signer crypto.Signer ) (* ValidatedLogConfig , error ) {
81
+ // TODO(phboneff): change the name of this function.
82
+ func ValidateLogConfig (cfg ChainValidationConfig , origin string , signer crypto.Signer ) (* ValidatedLogConfig , error ) {
53
83
if origin == "" {
54
84
return nil , errors .New ("empty origin" )
55
85
}
56
86
57
87
// Load the trusted roots.
58
- if rootsPemFile == "" {
88
+ if cfg . RootsPemFile == "" {
59
89
return nil , errors .New ("empty rootsPemFile" )
60
90
}
61
91
roots := x509util .NewPEMCertPool ()
62
- if err := roots .AppendCertsFromPEMFile (rootsPemFile ); err != nil {
92
+ if err := roots .AppendCertsFromPEMFile (cfg . RootsPemFile ); err != nil {
63
93
return nil , fmt .Errorf ("failed to read trusted roots: %v" , err )
64
94
}
65
95
@@ -73,27 +103,27 @@ func ValidateLogConfig(origin string, rootsPemFile string, rejectExpired bool, r
73
103
return nil , fmt .Errorf ("unsupported key type: %v" , keyType )
74
104
}
75
105
76
- if rejectExpired && rejectUnexpired {
106
+ if cfg . RejectExpired && cfg . RejectUnexpired {
77
107
return nil , errors .New ("configuration would reject all certificates" )
78
108
}
79
109
80
110
// Validate the time interval.
81
- if notAfterStart != nil && notAfterLimit != nil && (notAfterLimit ).Before (* notAfterStart ) {
82
- return nil , fmt .Errorf ("'Not After' limit %q before start %q" , notAfterLimit . Format (time .RFC3339 ), notAfterStart .Format (time .RFC3339 ))
111
+ if cfg . NotAfterStart != nil && cfg . NotAfterLimit != nil && (cfg . NotAfterLimit ).Before (* cfg . NotAfterStart ) {
112
+ return nil , fmt .Errorf ("'Not After' limit %q before start %q" , cfg . NotAfterLimit . Format (time .RFC3339 ), cfg . NotAfterStart .Format (time .RFC3339 ))
83
113
}
84
114
85
115
validationOpts := CertValidationOpts {
86
116
trustedRoots : roots ,
87
- rejectExpired : rejectExpired ,
88
- rejectUnexpired : rejectUnexpired ,
89
- notAfterStart : notAfterStart ,
90
- notAfterLimit : notAfterLimit ,
117
+ rejectExpired : cfg . RejectExpired ,
118
+ rejectUnexpired : cfg . RejectUnexpired ,
119
+ notAfterStart : cfg . NotAfterStart ,
120
+ notAfterLimit : cfg . NotAfterLimit ,
91
121
}
92
122
93
123
// Filter which extended key usages are allowed.
94
124
lExtKeyUsages := []string {}
95
- if extKeyUsages != "" {
96
- lExtKeyUsages = strings .Split (extKeyUsages , "," )
125
+ if cfg . ExtKeyUsages != "" {
126
+ lExtKeyUsages = strings .Split (cfg . ExtKeyUsages , "," )
97
127
}
98
128
// Validate the extended key usages list.
99
129
for _ , kuStr := range lExtKeyUsages {
@@ -112,8 +142,8 @@ func ValidateLogConfig(origin string, rootsPemFile string, rejectExpired bool, r
112
142
}
113
143
// Filter which extensions are rejected.
114
144
var err error
115
- if rejectExtensions != "" {
116
- lRejectExtensions := strings .Split (rejectExtensions , "," )
145
+ if cfg . RejectExtensions != "" {
146
+ lRejectExtensions := strings .Split (cfg . RejectExtensions , "," )
117
147
validationOpts .rejectExtIds , err = parseOIDs (lRejectExtensions )
118
148
if err != nil {
119
149
return nil , fmt .Errorf ("failed to parse RejectExtensions: %v" , err )
0 commit comments