Skip to content

Commit

Permalink
Adjust pki app config structure
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie committed Dec 19, 2021
1 parent 1f71601 commit 7d8af08
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 47 deletions.
80 changes: 41 additions & 39 deletions caddyconfig/httpcaddyfile/pkiapp.go
Expand Up @@ -26,64 +26,66 @@ func init() {

// parsePKIApp parses the global log option. Syntax:
//
// pki [id] {
// name <name>
// root_common_name <name>
// intermediate_common_name <name>
// pki {
// ca [<id>] {
// name <name>
// root_common_name <name>
// intermediate_common_name <name>
// }
// }
//
// When the CA ID is unspecified, 'local' is assumed.
//
func parsePKIApp(d *caddyfile.Dispenser, existingVal interface{}) (interface{}, error) {
var pki *caddypki.PKI
if existingVal != nil {
unwrappedPki, ok := existingVal.(*caddypki.PKI)
if !ok {
return nil, d.Errf("failed to unwrap existing PKI value")
}
pki = unwrappedPki
} else {
pki = &caddypki.PKI{CAs: make(map[string]*caddypki.CA)}
}
pki := &caddypki.PKI{CAs: make(map[string]*caddypki.CA)}

pkiCa := new(caddypki.CA)
for d.Next() {
if d.NextArg() {
pkiCa.ID = d.Val()
if d.NextArg() {
return nil, d.ArgErr()
}
}
for nesting := d.Nesting(); d.NextBlock(nesting); {
switch d.Val() {
case "name":
if !d.NextArg() {
return nil, d.ArgErr()
case "ca":
pkiCa := new(caddypki.CA)
if d.NextArg() {
pkiCa.ID = d.Val()
if d.NextArg() {
return nil, d.ArgErr()
}
}
pkiCa.Name = d.Val()

case "root_common_name":
if !d.NextArg() {
return nil, d.ArgErr()
if pkiCa.ID == "" {
pkiCa.ID = caddypki.DefaultCAID
}
pkiCa.Name = d.Val()

case "intermediate_common_name":
if !d.NextArg() {
return nil, d.ArgErr()
for nesting := d.Nesting(); d.NextBlock(nesting); {
switch d.Val() {
case "name":
if !d.NextArg() {
return nil, d.ArgErr()
}
pkiCa.Name = d.Val()

case "root_common_name":
if !d.NextArg() {
return nil, d.ArgErr()
}
pkiCa.Name = d.Val()

case "intermediate_common_name":
if !d.NextArg() {
return nil, d.ArgErr()
}
pkiCa.Name = d.Val()

default:
return nil, d.Errf("unrecognized pki ca option '%s'", d.Val())
}
}
pkiCa.Name = d.Val()

pki.CAs[pkiCa.ID] = pkiCa

default:
return nil, d.Errf("unrecognized pki option '%s'", d.Val())
}
}
}
if pkiCa.ID == "" {
pkiCa.ID = caddypki.DefaultCAID
}

pki.CAs[pkiCa.ID] = pkiCa

return pki, nil
}
Expand Down
@@ -1,14 +1,16 @@
{
skip_install_trust
pki {
name "Local"
root_common_name "Custom Local Root Name"
intermediate_common_name "Custom Local Intermediate Name"
}
pki foo {
name "Foo"
root_common_name "Custom Foo Root Name"
intermediate_common_name "Custom Foo Intermediate Name"
ca {
name "Local"
root_common_name "Custom Local Root Name"
intermediate_common_name "Custom Local Intermediate Name"
}
ca foo {
name "Foo"
root_common_name "Custom Foo Root Name"
intermediate_common_name "Custom Foo Intermediate Name"
}
}
}

Expand Down

0 comments on commit 7d8af08

Please sign in to comment.