Debian Codegraph @

modules/caddypki/command.go

raw symbols SCIP
1 // Copyright 2015 Matthew Holt and The Caddy Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package caddypkiscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/
16
17 import (
18 "crypto/x509scip-go gomod github.com/golang/go/src go1.25.1 `crypto/x509`/"
19 "encoding/jsonscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/"
20 "encoding/pemscip-go gomod github.com/golang/go/src go1.25.1 `encoding/pem`/"
21 "fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/"
22 "net/httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/"
23 "osscip-go gomod github.com/golang/go/src go1.25.1 os/"
24 "pathscip-go gomod github.com/golang/go/src go1.25.1 path/"
25
26 "github.com/smallstep/truststorescip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/"
27 "github.com/spf13/cobrascip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/"
28
29 caddycmdscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/ "github.com/caddyserver/caddy/v2/cmdscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/"
30
31 "github.com/caddyserver/caddy/v2scip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/"
32 )
33
34 func initscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/init().() {
35 caddycmdscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/.RegisterCommandscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/RegisterCommand().(caddycmdscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/.Commandscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Command#{
36 Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Command#Name.: "trust",
37 Usagescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Command#Usage.: "[--ca <id>] [--address <listen>] [--config <path> [--adapter <name>]]",
38 Shortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Command#Short.: "Installs a CA certificate into local trust stores",
39 Longscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Command#Long.: `
40 Adds a root certificate into the local trust stores.
41
42 Caddy will attempt to install its root certificates into the local
43 trust stores automatically when they are first generated, but it
44 might fail if Caddy doesn't have the appropriate permissions to
45 write to the trust store. This command is necessary to pre-install
46 the certificates before using them, if the server process runs as an
47 unprivileged user (such as via systemd).
48
49 By default, this command installs the root certificate for Caddy's
50 default CA (i.e. 'local'). You may specify the ID of another CA
51 with the --ca flag.
52
53 This command will attempt to connect to Caddy's admin API running at
54 '` + caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.DefaultAdminListenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/DefaultAdminListen. + `' to fetch the root certificate. You may
55 explicitly specify the --address, or use the --config flag to load
56 the admin address from your config, if not using the default.`,
57 CobraFuncscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Command#CobraFunc.: func(cmd *cobrascip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/.Commandscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#) {
58 cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringP().("ca", "", "", "The ID of the CA to trust (defaults to 'local')")
59 cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringP().("address", "", "", "Address of the administration API listener (if --config is not used)")
60 cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringP().("config", "c", "", "Configuration file (if --address is not used)")
61 cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringP().("adapter", "a", "", "Name of config adapter to apply (if --config is used)")
62 cmd.RunEscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#RunE. = caddycmdscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/.WrapCommandFuncForCobrascip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/WrapCommandFuncForCobra().(cmdTrustscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/cmdTrust().)
63 },
64 })
65
66 caddycmdscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/.RegisterCommandscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/RegisterCommand().(caddycmdscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/.Commandscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Command#{
67 Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Command#Name.: "untrust",
68 Usagescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Command#Usage.: "[--cert <path>] | [[--ca <id>] [--address <listen>] [--config <path> [--adapter <name>]]]",
69 Shortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Command#Short.: "Untrusts a locally-trusted CA certificate",
70 Longscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Command#Long.: `
71 Untrusts a root certificate from the local trust store(s).
72
73 This command uninstalls trust; it does not necessarily delete the
74 root certificate from trust stores entirely. Thus, repeatedly
75 trusting and untrusting new certificates can fill up trust databases.
76
77 This command does not delete or modify certificate files from Caddy's
78 configured storage.
79
80 This command can be used in one of two ways. Either by specifying
81 which certificate to untrust by a direct path to the certificate
82 file with the --cert flag, or by fetching the root certificate for
83 the CA from the admin API (default behaviour).
84
85 If the admin API is used, then the CA defaults to 'local'. You may
86 specify the ID of another CA with the --ca flag. By default, this
87 will attempt to connect to the Caddy's admin API running at
88 '` + caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.DefaultAdminListenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/DefaultAdminListen. + `' to fetch the root certificate.
89 You may explicitly specify the --address, or use the --config flag
90 to load the admin address from your config, if not using the default.`,
91 CobraFuncscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Command#CobraFunc.: func(cmd *cobrascip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/.Commandscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#) {
92 cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringP().("cert", "p", "", "The path to the CA certificate to untrust")
93 cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringP().("ca", "", "", "The ID of the CA to untrust (defaults to 'local')")
94 cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringP().("address", "", "", "Address of the administration API listener (if --config is not used)")
95 cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringP().("config", "c", "", "Configuration file (if --address is not used)")
96 cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringP().("adapter", "a", "", "Name of config adapter to apply (if --config is used)")
97 cmd.RunEscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#RunE. = caddycmdscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/.WrapCommandFuncForCobrascip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/WrapCommandFuncForCobra().(cmdUntrustscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/cmdUntrust().)
98 },
99 })
100 }
101
102 func cmdTrustscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/cmdTrust().(fl caddycmdscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/.Flagsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Flags#) (int, error) {
103 caID := fl.Stringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Flags#String().("ca")
104 addrFlag := fl.Stringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Flags#String().("address")
105 configFlag := fl.Stringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Flags#String().("config")
106 configAdapterFlag := fl.Stringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Flags#String().("adapter")
107
108 // Prepare the URI to the admin endpoint
109 if caID == "" {
110 caID = DefaultCAIDscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/DefaultCAID.
111 }
112
113 // Determine where we're sending the request to get the CA info
114 adminAddr, err := caddycmdscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/.DetermineAdminAPIAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/DetermineAdminAPIAddress().(addrFlag, nil, configFlag, configAdapterFlag)
115 if err != nil {
116 return caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ExitCodeFailedStartupscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ExitCodeFailedStartup., fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("couldn't determine admin API address: %v", err)
117 }
118
119 // Fetch the root cert from the admin API
120 rootCert, err := rootCertFromAdminscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/rootCertFromAdmin().(adminAddr, caID)
121 if err != nil {
122 return caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ExitCodeFailedStartupscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ExitCodeFailedStartup., err
123 }
124
125 // Set up the CA struct; we only need to fill in the root
126 // because we're only using it to make use of the installRoot()
127 // function. Also needs a logger for warnings, and a "cert path"
128 // for the root cert; since we're loading from the API and we
129 // don't know the actual storage path via this flow, we'll just
130 // pass through the admin API address instead.
131 ca := CAscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/CA#{
132 logscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/CA#log.: caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Logscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Log().(),
133 rootscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/CA#root.: rootCert,
134 rootCertPathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/CA#rootCertPath.: adminAddr + pathscip-go gomod github.com/golang/go/src go1.25.1 path/.Joinscip-go gomod github.com/golang/go/src go1.25.1 path/Join().(adminPKIEndpointBasescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/adminPKIEndpointBase., "ca", caID),
135 }
136
137 // Install the cert!
138 err = ca.installRootscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/CA#installRoot().()
139 if err != nil {
140 return caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ExitCodeFailedStartupscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ExitCodeFailedStartup., err
141 }
142
143 return caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ExitCodeSuccessscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ExitCodeSuccess., nil
144 }
145
146 func cmdUntrustscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/cmdUntrust().(fl caddycmdscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/.Flagsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Flags#) (int, error) {
147 certFile := fl.Stringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Flags#String().("cert")
148 caID := fl.Stringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Flags#String().("ca")
149 addrFlag := fl.Stringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Flags#String().("address")
150 configFlag := fl.Stringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Flags#String().("config")
151 configAdapterFlag := fl.Stringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/Flags#String().("adapter")
152
153 if certFile != "" && (caID != "" || addrFlag != "" || configFlag != "") {
154 return caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ExitCodeFailedStartupscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ExitCodeFailedStartup., fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("conflicting command line arguments, cannot use --cert with other flags")
155 }
156
157 // If a file was specified, try to uninstall the cert matching that file
158 if certFile != "" {
159 // Sanity check, make sure cert file exists first
160 _, err := osscip-go gomod github.com/golang/go/src go1.25.1 os/.Statscip-go gomod github.com/golang/go/src go1.25.1 os/Stat().(certFile)
161 if err != nil {
162 return caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ExitCodeFailedStartupscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ExitCodeFailedStartup., fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("accessing certificate file: %v", err)
163 }
164
165 // Uninstall the file!
166 err = truststorescip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/.UninstallFilescip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/UninstallFile().(certFile,
167 truststorescip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/.WithDebugscip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/WithDebug().(),
168 truststorescip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/.WithFirefoxscip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/WithFirefox().(),
169 truststorescip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/.WithJavascip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/WithJava().())
170 if err != nil {
171 return caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ExitCodeFailedStartupscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ExitCodeFailedStartup., fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("failed to uninstall certificate file: %v", err)
172 }
173
174 return caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ExitCodeSuccessscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ExitCodeSuccess., nil
175 }
176
177 // Prepare the URI to the admin endpoint
178 if caID == "" {
179 caID = DefaultCAIDscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/DefaultCAID.
180 }
181
182 // Determine where we're sending the request to get the CA info
183 adminAddr, err := caddycmdscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/.DetermineAdminAPIAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/DetermineAdminAPIAddress().(addrFlag, nil, configFlag, configAdapterFlag)
184 if err != nil {
185 return caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ExitCodeFailedStartupscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ExitCodeFailedStartup., fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("couldn't determine admin API address: %v", err)
186 }
187
188 // Fetch the root cert from the admin API
189 rootCert, err := rootCertFromAdminscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/rootCertFromAdmin().(adminAddr, caID)
190 if err != nil {
191 return caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ExitCodeFailedStartupscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ExitCodeFailedStartup., err
192 }
193
194 // Uninstall the cert!
195 err = truststorescip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/.Uninstallscip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/Uninstall().(rootCert,
196 truststorescip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/.WithDebugscip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/WithDebug().(),
197 truststorescip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/.WithFirefoxscip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/WithFirefox().(),
198 truststorescip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/.WithJavascip-go gomod github.com/smallstep/truststore v0.13.0 `github.com/smallstep/truststore`/WithJava().())
199 if err != nil {
200 return caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ExitCodeFailedStartupscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ExitCodeFailedStartup., fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("failed to uninstall certificate file: %v", err)
201 }
202
203 return caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ExitCodeSuccessscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ExitCodeSuccess., nil
204 }
205
206 // rootCertFromAdmin makes the API request to fetch the root certificate for the named CA via admin API.
207 func rootCertFromAdminscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/rootCertFromAdmin().(adminAddr string, caID string) (*x509scip-go gomod github.com/golang/go/src go1.25.1 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.25.1 `crypto/x509`/Certificate#, error) {
208 uri := pathscip-go gomod github.com/golang/go/src go1.25.1 path/.Joinscip-go gomod github.com/golang/go/src go1.25.1 path/Join().(adminPKIEndpointBasescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/adminPKIEndpointBase., "ca", caID)
209
210 // Make the request to fetch the CA info
211 resp, err := caddycmdscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/.AdminAPIRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/cmd`/AdminAPIRequest().(adminAddr, httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., uri, make(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#), nil)
212 if err != nil {
213 return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("requesting CA info: %v", err)
214 }
215 defer resp.Bodyscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src go1.25.1 io/Closer#Close().()
216
217 // Decode the response
218 caInfo := new(caInfoscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/caInfo#)
219 err = jsonscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/.NewDecoderscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/NewDecoder().(resp.Bodyscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Response#Body.).Decodescip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/Decoder#Decode().(caInfo)
220 if err != nil {
221 return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("failed to decode JSON response: %v", err)
222 }
223
224 // Decode the root cert
225 rootBlock, _ := pemscip-go gomod github.com/golang/go/src go1.25.1 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.25.1 `encoding/pem`/Decode().([]byte(caInfo.RootCertscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/caInfo#RootCert.))
226 if rootBlock == nil {
227 return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("failed to decode root certificate: %v", err)
228 }
229 rootCert, err := x509scip-go gomod github.com/golang/go/src go1.25.1 `crypto/x509`/.ParseCertificatescip-go gomod github.com/golang/go/src go1.25.1 `crypto/x509`/ParseCertificate().(rootBlock.Bytesscip-go gomod github.com/golang/go/src go1.25.1 `encoding/pem`/Block#Bytes.)
230 if err != nil {
231 return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("failed to parse root certificate: %v", err)
232 }
233
234 return rootCert, nil
235 }