15
package httpcaddyfile
16
17
import (
18
+ "encoding/base64"
19
+ "encoding/pem"
20
"fmt"
21
"html"
22
+ "io/ioutil"
23
"net/http"
24
"reflect"
25
"strings"
62
// protocols <min> [<max>]
63
// ciphers <cipher_suites...>
64
// curves <curves...>
65
+// client_auth {
66
+// mode [request|require|verify_if_given|require_and_verify]
67
+// trusted_ca_cert <base64_der>
68
+// trusted_ca_cert_file <filename>
69
+// trusted_leaf_cert <base64_der>
70
+// trusted_leaf_cert_file <filename>
71
+// }
72
// alpn <values...>
73
// load <paths...>
74
// ca <acme_ca_endpoint>
153
}
154
155
var hasBlock bool
146
- for h.NextBlock(0) {
156
+ for nesting := h.Nesting(); h.NextBlock(nesting); {
157
hasBlock = true
158
159
switch h.Val() {
191
cp.Curves = append(cp.Curves, h.Val())
192
}
193
194
+ case "client_auth":
195
+ cp.ClientAuthentication = &caddytls.ClientAuthentication{}
196
+ for nesting := h.Nesting(); h.NextBlock(nesting); {
197
+ subdir := h.Val()
198
+ switch subdir {
199
+ case "mode":
200
+ if !h.Args(&cp.ClientAuthentication.Mode) {
201
+ return nil, h.ArgErr()
202
+ }
203
+ if h.NextArg() {
204
+ return nil, h.ArgErr()
205
+ }
206
+
207
+ case "trusted_ca_cert",
208
+ "trusted_leaf_cert":
209
+ if !h.NextArg() {
210
+ return nil, h.ArgErr()
211
+ }
212
+ if subdir == "trusted_ca_cert" {
213
+ cp.ClientAuthentication.TrustedCACerts = append(cp.ClientAuthentication.TrustedCACerts, h.Val())
214
+ } else {
215
+ cp.ClientAuthentication.TrustedLeafCerts = append(cp.ClientAuthentication.TrustedLeafCerts, h.Val())
216
+ }
217
+
218
+ case "trusted_ca_cert_file",
219
+ "trusted_leaf_cert_file":
220
+ if !h.NextArg() {
221
+ return nil, h.ArgErr()
222
+ }
223
+ filename := h.Val()
224
+ certDataPEM, err := ioutil.ReadFile(filename)
225
+ if err != nil {
226
+ return nil, err
227
+ }
228
+ block, _ := pem.Decode(certDataPEM)
229
+ if block == nil || block.Type != "CERTIFICATE" {
230
+ return nil, h.Errf("no CERTIFICATE pem block found in %s", h.Val())
231
+ }
232
+ if subdir == "trusted_ca_cert_file" {
233
+ cp.ClientAuthentication.TrustedCACerts = append(cp.ClientAuthentication.TrustedCACerts,
234
+ base64.StdEncoding.EncodeToString(block.Bytes))
235
+ } else {
236
+ cp.ClientAuthentication.TrustedLeafCerts = append(cp.ClientAuthentication.TrustedLeafCerts,
237
+ base64.StdEncoding.EncodeToString(block.Bytes))
238
+ }
239
+
240
+ default:
241
+ return nil, h.Errf("unknown subdirective for client_auth: %s", subdir)
242
+ }
243
+ }
244
+
245
case "alpn":
246
args := h.RemainingArgs()
247
if len(args) == 0 {