forked from Gr33nbl00d/caddy-revocation-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaddyUnmarshal.go
134 lines (115 loc) · 3.13 KB
/
caddyUnmarshal.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package revocation
import (
"log"
"strconv"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/gr33nbl00d/caddy-revocation-validator/config"
)
func (c *CertRevocationValidator) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
// initialize structs
crlConfg := config.CRLConfig{
CDPConfig: &config.CDPConfig{},
CRLUrls: []string{},
CRLFiles: []string{},
TrustedSignatureCertsFiles: []string{},
}
ocspConfig := config.OCSPConfig{
TrustedResponderCertsFiles: []string{},
}
c.CRLConfig = &crlConfg
c.OCSPConfig = &ocspConfig
for d.Next() {
for nesting := d.Nesting(); d.NextBlock(nesting); {
key := d.Val()
log.Printf("key: %v", key)
switch key {
case "mode":
if !d.NextArg() {
return d.ArgErr()
}
c.Mode = d.Val()
case "crl_config":
for nesting := d.Nesting(); d.NextBlock(nesting); {
switch d.Val() {
case "work_dir":
if !d.NextArg() {
return d.ArgErr()
}
crlConfg.WorkDir = d.Val()
case "crl_fetch_mode":
if !d.NextArg() {
return d.ArgErr()
}
crlConfg.CDPConfig.CRLFetchMode = d.Val()
case "crl_cdp_strict":
if !d.NextArg() {
return d.ArgErr()
}
b, err := strconv.ParseBool(d.Val())
if err != nil {
return d.ArgErr()
}
crlConfg.CDPConfig.CRLCDPStrict = b
case "storage_type":
if !d.NextArg() {
return d.ArgErr()
}
crlConfg.StorageType = d.Val()
case "update_interval":
if !d.NextArg() {
return d.ArgErr()
}
crlConfg.UpdateInterval = d.Val()
case "signature_validation_mode":
if !d.NextArg() {
return d.ArgErr()
}
crlConfg.SignatureValidationMode = d.Val()
case "crl_url":
if !d.NextArg() {
return d.ArgErr()
}
crlConfg.CRLUrls = append(crlConfg.CRLUrls, d.Val())
case "crl_file":
if !d.NextArg() {
return d.ArgErr()
}
crlConfg.CRLFiles = append(crlConfg.CRLFiles, d.Val())
case "trusted_signature_cert_file":
if !d.NextArg() {
return nil
}
crlConfg.TrustedSignatureCertsFiles = append(crlConfg.TrustedSignatureCertsFiles, d.Val())
default:
return d.Errf("unknown subdirective for the crl config in the revocation verifier: %s", d.Val())
}
}
case "ocsp_config":
for nesting := d.Nesting(); d.NextBlock(nesting); {
switch d.Val() {
case "default_cache_duration":
if !d.NextArg() {
return nil
}
ocspConfig.DefaultCacheDuration = d.Val()
case "trusted_responder_cert_file":
if !d.NextArg() {
return nil
}
ocspConfig.TrustedResponderCertsFiles = append(ocspConfig.TrustedResponderCertsFiles, d.Val())
case "ocsp_aia_strict":
if !d.NextArg() {
return nil
}
ocspConfig.OCSPAIAStrict = false
default:
return d.Errf("unknown subdirective for the ocsp config in the revocation verifier: %s", d.Val())
}
}
default:
return d.Errf("unknown subdirective for the revocation verifier: %s", key)
}
}
}
return nil
}