Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 13, 23:00 UTC
httpcaddyfile: Add pki app `root` and `intermediate` cert/key config (#4514)
Francis Lavoie committed
Jan 18, 2022 at 14:18 UTC
5a0715689444537cf2c41e3362468b97f31493b6
2 files changed
+89
-1
caddyconfig/httpcaddyfile/pkiapp.go
+68
@@ -31,6 +31,16 @@ func init() {
31
// name <name>
32
// root_cn <name>
33
// intermediate_cn <name>
34
+// root {
35
+// cert <path>
36
+// key <path>
37
+// format <format>
38
+// }
39
+// intermediate {
40
+// cert <path>
41
+// key <path>
42
+// format <format>
43
+// }
44
// }
45
// }
46
//
@@ -74,6 +84,64 @@ func parsePKIApp(d *caddyfile.Dispenser, existingVal interface{}) (interface{},
84
}
85
pkiCa.IntermediateCommonName = d.Val()
86
87
+ case "root":
88
+ if pkiCa.Root == nil {
89
+ pkiCa.Root = new(caddypki.KeyPair)
90
+ }
91
+ for nesting := d.Nesting(); d.NextBlock(nesting); {
92
+ switch d.Val() {
93
+ case "cert":
94
+ if !d.NextArg() {
95
+ return nil, d.ArgErr()
96
+ }
97
+ pkiCa.Root.Certificate = d.Val()
98
+
99
+ case "key":
100
+ if !d.NextArg() {
101
+ return nil, d.ArgErr()
102
+ }
103
+ pkiCa.Root.PrivateKey = d.Val()
104
+
105
+ case "format":
106
+ if !d.NextArg() {
107
+ return nil, d.ArgErr()
108
+ }
109
+ pkiCa.Root.Format = d.Val()
110
+
111
+ default:
112
+ return nil, d.Errf("unrecognized pki ca root option '%s'", d.Val())
113
+ }
114
+ }
115
+
116
+ case "intermediate":
117
+ if pkiCa.Intermediate == nil {
118
+ pkiCa.Intermediate = new(caddypki.KeyPair)
119
+ }
120
+ for nesting := d.Nesting(); d.NextBlock(nesting); {
121
+ switch d.Val() {
122
+ case "cert":
123
+ if !d.NextArg() {
124
+ return nil, d.ArgErr()
125
+ }
126
+ pkiCa.Intermediate.Certificate = d.Val()
127
+
128
+ case "key":
129
+ if !d.NextArg() {
130
+ return nil, d.ArgErr()
131
+ }
132
+ pkiCa.Intermediate.PrivateKey = d.Val()
133
+
134
+ case "format":
135
+ if !d.NextArg() {
136
+ return nil, d.ArgErr()
137
+ }
138
+ pkiCa.Intermediate.Format = d.Val()
139
+
140
+ default:
141
+ return nil, d.Errf("unrecognized pki ca intermediate option '%s'", d.Val())
142
+ }
143
+ }
144
+
145
default:
146
return nil, d.Errf("unrecognized pki ca option '%s'", d.Val())
147
}
caddytest/integration/caddyfile_adapt/global_options_skip_install_trust.txt
+21
-1
@@ -5,6 +5,16 @@
5
name "Local"
6
root_cn "Custom Local Root Name"
7
intermediate_cn "Custom Local Intermediate Name"
8
+ root {
9
+ cert /path/to/cert.pem
10
+ key /path/to/key.pem
11
+ format pem_file
12
+ }
13
+ intermediate {
14
+ cert /path/to/cert.pem
15
+ key /path/to/key.pem
16
+ format pem_file
17
+ }
18
}
19
ca foo {
20
name "Foo"
@@ -118,7 +128,17 @@ acme-bar.example.com {
128
"name": "Local",
129
"root_common_name": "Custom Local Root Name",
130
"intermediate_common_name": "Custom Local Intermediate Name",
121
- "install_trust": false
131
+ "install_trust": false,
132
+ "root": {
133
+ "certificate": "/path/to/cert.pem",
134
+ "private_key": "/path/to/key.pem",
135
+ "format": "pem_file"
136
+ },
137
+ "intermediate": {
138
+ "certificate": "/path/to/cert.pem",
139
+ "private_key": "/path/to/key.pem",
140
+ "format": "pem_file"
141
+ }
142
}
143
}
144
},