source_file
comment "// Copyright 2015 Matthew Holt and The Caddy Authors"
comment "//"
comment "// Licensed under the Apache License, Version 2.0 (the \"Lice"...
comment "// you may not use this file except in compliance with the L"...
comment "// You may obtain a copy of the License at"
comment "//"
comment "// http://www.apache.org/licenses/LICENSE-2.0"
comment "//"
comment "// Unless required by applicable law or agreed to in writing"...
comment "// distributed under the License is distributed on an \"AS IS"...
comment "// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expr"...
comment "// See the License for the specific language governing permi"...
comment "// limitations under the License."
package_clause
package "package"
package_identifier "httpcaddyfile"
import_declaration (+70 nodes collapsed)
method_declaration
func "func"
parameter_list
( "("
parameter_declaration
identifier "st"
type_identifier "ServerType"
) ")"
field_identifier "buildTLSApp"
parameter_list (+29 nodes collapsed)
parameter_list (+22 nodes collapsed)
block
{ "{"
statement_list
short_var_declaration (+29 nodes collapsed)
var_declaration
var "var"
var_spec
identifier "certLoaders"
slice_type
[ "["
] "]"
qualified_type
package_identifier "caddytls"
. "."
type_identifier "CertificateLoader"
short_var_declaration
expression_list
identifier "httpPort"
:= ":="
expression_list
call_expression
selector_expression
identifier "strconv"
. "."
field_identifier "Itoa"
argument_list
( "("
selector_expression
identifier "caddyhttp"
. "."
field_identifier "DefaultHTTPPort"
) ")"
if_statement (+42 nodes collapsed)
short_var_declaration
expression_list
identifier "autoHTTPS"
:= ":="
expression_list
interpreted_string_literal
" "\""
interpreted_string_literal_content "on"
" "\""
if_statement (+34 nodes collapsed)
comment "// find all hosts that share a server block with a hostless"
comment "// key, so that they don't get forgotten/omitted by auto-HTT"...
comment "// (since they won't appear in route matchers)"
short_var_declaration
expression_list
identifier "httpsHostsSharedWithHostlessKey"
:= ":="
expression_list
call_expression
identifier "make"
argument_list
( "("
map_type
map "map"
[ "["
type_identifier "string"
] "]"
struct_type
struct "struct"
field_declaration_list
{ "{"
} "}"
) ")"
if_statement (+172 nodes collapsed)
comment "// a catch-all automation policy is used as a \"default\" for "...
comment "// don't have custom configuration explicitly associated wit"...
comment "// is only to add if the global settings or defaults are non"...
short_var_declaration
expression_list
identifier "catchAllAP"
, ","
identifier "err"
:= ":="
expression_list
call_expression
identifier "newBaseAutomationPolicy"
argument_list
( "("
identifier "options"
, ","
identifier "warnings"
, ","
false "false"
) ")"
if_statement
if "if"
binary_expression
identifier "err"
!= "!="
nil "nil"
block
{ "{"
statement_list
return_statement
return "return"
expression_list
nil "nil"
, ","
identifier "warnings"
, ","
identifier "err"
} "}"
if_statement (+65 nodes collapsed)
for_statement
for "for"
range_clause
expression_list
identifier "_"
, ","
identifier "p"
:= ":="
range "range"
identifier "pairings"
block
{ "{"
comment "// avoid setting up TLS automation policies for a server tha"...
statement_list
if_statement (+21 nodes collapsed)
for_statement
for "for"
range_clause
expression_list
identifier "_"
, ","
identifier "sblock"
:= ":="
range "range"
selector_expression
identifier "p"
. "."
field_identifier "serverBlocks"
block
{ "{"
comment "// check the scheme of all the site addresses,"
comment "// skip building AP if they all had http://"
statement_list
if_statement
if "if"
call_expression
selector_expression
identifier "sblock"
. "."
field_identifier "isAllHTTP"
argument_list
( "("
) ")"
block
{ "{"
statement_list
continue_statement
continue "continue"
} "}"
comment "// get values that populate an automation policy for this bl"...
short_var_declaration
expression_list
identifier "ap"
, ","
identifier "err"
:= ":="
expression_list
call_expression
identifier "newBaseAutomationPolicy"
argument_list
( "("
identifier "options"
, ","
identifier "warnings"
, ","
true "true"
) ")"
if_statement
if "if"
binary_expression
identifier "err"
!= "!="
nil "nil"
block
{ "{"
statement_list
return_statement
return "return"
expression_list
nil "nil"
, ","
identifier "warnings"
, ","
identifier "err"
} "}"
short_var_declaration
expression_list
identifier "sblockHosts"
:= ":="
expression_list
call_expression
selector_expression
identifier "sblock"
. "."
field_identifier "hostsFromKeys"
argument_list
( "("
false "false"
) ")"
if_statement (+27 nodes collapsed)
comment "// on-demand tls"
if_statement (+35 nodes collapsed)
if_statement (+47 nodes collapsed)
comment "// certificate issuers"
if_statement (+151 nodes collapsed)
comment "// certificate managers"
if_statement (+115 nodes collapsed)
comment "// custom bind host"
for_statement (+216 nodes collapsed)
comment "// we used to ensure this block is allowed to create an auto"...
comment "// doing so was forbidden if it has a key with no host (i.e."...
comment "// and if there is a different server block that also has a "...
comment "// host -- since a key with no host matches any host, we nee"...
comment "// associated automation policy to have an empty Subjects li"...
comment "// host filter, which is indistinguishable between the two s"...
comment "// because automation is not done in the context of a partic"...
comment "// this is an example of a poor mapping from Caddyfile to JS"...
comment "// the least-leaky abstraction I could figure out -- however"...
comment "// was preventing certain listeners, like those provided by "...
comment "// being used as desired (see the Tailscale listener plugin)"...
comment "// the check: and I think since I originally wrote the check"...
comment "// check above which *properly* detects this ambiguity witho"...
comment "// listener plugin; see the check above with a commented exa"...
if_statement (+30 nodes collapsed)
comment "// associate our new automation policy with this server bloc"...
assignment_statement
expression_list
selector_expression
identifier "ap"
. "."
field_identifier "SubjectsRaw"
= "="
expression_list
call_expression
selector_expression
identifier "sblock"
. "."
field_identifier "hostsFromKeysNotHTTP"
argument_list
( "("
identifier "httpPort"
) ")"
expression_statement
call_expression
selector_expression
identifier "sort"
. "."
field_identifier "Strings"
argument_list
( "("
selector_expression
identifier "ap"
. "."
field_identifier "SubjectsRaw"
) ")"
comment "// solely for deterministic test results"
comment "// if a combination of public and internal names were given"
comment "// for this same server block and no issuer was specified, w"...
comment "// need to separate them out in the automation policies so"
comment "// that the internal names can use the internal issuer and"
comment "// the other names can use the default/public/ACME issuer"
var_declaration
var "var"
var_spec
identifier "ap2"
pointer_type
* "*"
qualified_type
package_identifier "caddytls"
. "."
type_identifier "AutomationPolicy"
if_statement (+276 nodes collapsed)
if_statement (+30 nodes collapsed)
assignment_statement (+25 nodes collapsed)
if_statement (+35 nodes collapsed)
comment "// certificate loaders"
if_statement (+64 nodes collapsed)
} "}"
} "}"
comment "// group certificate loaders by module name, then add to con"...
if_statement (+290 nodes collapsed)
comment "// set any of the on-demand options, for if/when on-demand T"...
if_statement (+75 nodes collapsed)
comment "// set the storage clean interval if configured"
if_statement (+73 nodes collapsed)
comment "// set the expired certificates renew interval if configured"
if_statement (+73 nodes collapsed)
comment "// set the OCSP check interval if configured"
if_statement (+73 nodes collapsed)
comment "// set whether OCSP stapling should be disabled for manually"...
if_statement (+43 nodes collapsed)
comment "// if any hostnames appear on the same server block as a key"...
comment "// no host, they will not be used with route matchers becaus"...
comment "// hostless key matches all hosts, therefore, it wouldn't be"
comment "// considered for auto-HTTPS, so we need to make sure those "...
comment "// are manually considered for managed certificates; we also"...
comment "// to make sure that any of these names which are internal-o"...
comment "// get internal certificates by default rather than ACME"
var_declaration
var "var"
var_spec
identifier "al"
qualified_type
package_identifier "caddytls"
. "."
type_identifier "AutomateLoader"
short_var_declaration (+45 nodes collapsed)
if_statement (+74 nodes collapsed)
if_statement (+43 nodes collapsed)
if_statement (+73 nodes collapsed)
comment "// if there are any global options set for issuers (ACME one"...
comment "// take effect in every automation policy that does not have"...
if_statement (+344 nodes collapsed)
comment "// finalize and verify policies; do cleanup"
if_statement (+427 nodes collapsed)
return_statement
return "return"
expression_list
identifier "tlsApp"
, ","
identifier "warnings"
, ","
nil "nil"
} "}"
type_declaration
type "type"
type_spec
type_identifier "acmeCapable"
interface_type
interface "interface"
{ "{"
method_elem
field_identifier "GetACMEIssuer"
parameter_list
( "("
) ")"
pointer_type
* "*"
qualified_type
package_identifier "caddytls"
. "."
type_identifier "ACMEIssuer"
} "}"
function_declaration (+478 nodes collapsed)
comment "// newBaseAutomationPolicy returns a new TLS automation poli"...
comment "// its values from the global options map. It should be used"...
comment "// for any other automation policies. A nil policy (and no e"...
comment "// returned if there are no default/global options. However,"...
comment "// true, a non-nil value will always be returned (unless the"...
function_declaration (+335 nodes collapsed)
comment "// consolidateAutomationPolicies combines automation policie"...
comment "// for a cleaner overall output."
function_declaration
func "func"
identifier "consolidateAutomationPolicies"
parameter_list
( "("
parameter_declaration
identifier "aps"
slice_type
[ "["
] "]"
pointer_type
* "*"
qualified_type
package_identifier "caddytls"
. "."
type_identifier "AutomationPolicy"
) ")"
slice_type
[ "["
] "]"
pointer_type
* "*"
qualified_type
package_identifier "caddytls"
. "."
type_identifier "AutomationPolicy"
block
{ "{"
comment "// sort from most specific to least specific; we depend on t"...
statement_list
expression_statement (+109 nodes collapsed)
short_var_declaration
expression_list
identifier "emptyAPCount"
:= ":="
expression_list
int_literal "0"
short_var_declaration
expression_list
identifier "origLenAPs"
:= ":="
expression_list
call_expression
identifier "len"
argument_list
( "("
identifier "aps"
) ")"
comment "// compute the number of empty policies (disregarding subjec"...
short_var_declaration
expression_list
identifier "emptyAP"
:= ":="
expression_list
call_expression
identifier "new"
argument_list
( "("
qualified_type
package_identifier "caddytls"
. "."
type_identifier "AutomationPolicy"
) ")"
for_statement (+118 nodes collapsed)
comment "// If all policies are empty, we can return nil, as there is"...
if_statement
if "if"
binary_expression
identifier "emptyAPCount"
== "=="
identifier "origLenAPs"
block
{ "{"
statement_list
return_statement
return "return"
expression_list
nil "nil"
} "}"
comment "// remove or combine duplicate policies"
labeled_statement
label_name "outer"
: ":"
for_statement
for "for"
for_clause (+21 nodes collapsed)
block
{ "{"
comment "// compare only with next policies; we sorted by specificity"...
statement_list
for_statement
for "for"
for_clause (+24 nodes collapsed)
block
{ "{"
comment "// if they're exactly equal in every way, just keep one of t"...
statement_list
if_statement (+61 nodes collapsed)
comment "// if the policy is the same, we can keep just one, but we h"...
comment "// to be careful which one we keep; if only one has any host"...
comment "// defined, then we need to keep the one without any hostnam"...
comment "// otherwise the one without any subjects (a catch-all) woul"...
comment "// eaten up by the one with subjects; and if both have subje"...
comment "// need to combine their lists"
if_statement
if "if"
binary_expression any 6:7
binary_expression any 6:7
binary_expression any 6:7
binary_expression any 6:7
binary_expression any 6:7
binary_expression any 6:7
call_expression (+25 nodes collapsed)
&& "&&"
call_expression (+25 nodes collapsed)
&& "&&"
call_expression (+25 nodes collapsed)
&& "&&"
binary_expression
selector_expression
index_expression
identifier "aps"
[ "["
identifier "i"
] "]"
. "."
field_identifier "MustStaple"
== "=="
selector_expression
index_expression
identifier "aps"
[ "["
identifier "j"
] "]"
. "."
field_identifier "MustStaple"
&& "&&"
binary_expression
selector_expression
index_expression
identifier "aps"
[ "["
identifier "i"
] "]"
. "."
field_identifier "KeyType"
== "=="
selector_expression
index_expression
identifier "aps"
[ "["
identifier "j"
] "]"
. "."
field_identifier "KeyType"
&& "&&"
binary_expression
selector_expression
index_expression
identifier "aps"
[ "["
identifier "i"
] "]"
. "."
field_identifier "OnDemand"
== "=="
selector_expression
index_expression
identifier "aps"
[ "["
identifier "j"
] "]"
. "."
field_identifier "OnDemand"
&& "&&"
binary_expression
selector_expression
index_expression
identifier "aps"
[ "["
identifier "i"
] "]"
. "."
field_identifier "RenewalWindowRatio"
== "=="
selector_expression
index_expression
identifier "aps"
[ "["
identifier "j"
] "]"
. "."
field_identifier "RenewalWindowRatio"
block (+210 nodes collapsed)
} "}"
} "}"
return_statement
return "return"
expression_list
identifier "aps"
} "}"
comment "// automationPolicyIsSubset returns true if a's subjects are"...
comment "// of b's subjects."
function_declaration (+146 nodes collapsed)
comment "// automationPolicyShadows returns the index of a policy tha"...
comment "// in other words, for all policies after position i, if tha"...
comment "// the same subjects but is less specific, that policy's pos"...
comment "// or -1 if no shadowing is found. For example, if policy i "...
comment "// \"foo.example.com\" and policy i+2 is for \"*.example.com\", "...
comment "// returned, since that policy is shadowed by i, which is in"...
function_declaration (+88 nodes collapsed)
comment "// subjectQualifiesForPublicCert is like certmagic.SubjectQu"...
comment "// that this allows domains with multiple wildcard levels li"...
comment "// if the automation policy has OnDemand enabled (i.e. this "...
function_declaration (+78 nodes collapsed)
function_declaration (+60 nodes collapsed)