(fl caddycmd.Flags)
| 144 | } |
| 145 | |
| 146 | func cmdUntrust(fl caddycmd.Flags) (int, error) { |
| 147 | certFile := fl.String("cert") |
| 148 | caID := fl.String("ca") |
| 149 | addrFlag := fl.String("address") |
| 150 | configFlag := fl.String("config") |
| 151 | configAdapterFlag := fl.String("adapter") |
| 152 | |
| 153 | if certFile != "" && (caID != "" || addrFlag != "" || configFlag != "") { |
| 154 | return caddy.ExitCodeFailedStartup, 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 := os.Stat(certFile) |
| 161 | if err != nil { |
| 162 | return caddy.ExitCodeFailedStartup, fmt.Errorf("accessing certificate file: %v", err) |
| 163 | } |
| 164 | |
| 165 | // Uninstall the file! |
| 166 | err = truststore.UninstallFile(certFile, |
| 167 | truststore.WithDebug(), |
| 168 | truststore.WithFirefox(), |
| 169 | truststore.WithJava()) |
| 170 | if err != nil { |
| 171 | return caddy.ExitCodeFailedStartup, fmt.Errorf("failed to uninstall certificate file: %v", err) |
| 172 | } |
| 173 | |
| 174 | return caddy.ExitCodeSuccess, nil |
| 175 | } |
| 176 | |
| 177 | // Prepare the URI to the admin endpoint |
| 178 | if caID == "" { |
| 179 | caID = DefaultCAID |
| 180 | } |
| 181 | |
| 182 | // Determine where we're sending the request to get the CA info |
| 183 | adminAddr, err := caddycmd.DetermineAdminAPIAddress(addrFlag, nil, configFlag, configAdapterFlag) |
| 184 | if err != nil { |
| 185 | return caddy.ExitCodeFailedStartup, fmt.Errorf("couldn't determine admin API address: %v", err) |
| 186 | } |
| 187 | |
| 188 | // Fetch the root cert from the admin API |
| 189 | rootCert, err := rootCertFromAdmin(adminAddr, caID) |
| 190 | if err != nil { |
| 191 | return caddy.ExitCodeFailedStartup, err |
| 192 | } |
| 193 | |
| 194 | // Uninstall the cert! |
| 195 | err = truststore.Uninstall(rootCert, |
| 196 | truststore.WithDebug(), |
| 197 | truststore.WithFirefox(), |
| 198 | truststore.WithJava()) |
| 199 | if err != nil { |
| 200 | return caddy.ExitCodeFailedStartup, fmt.Errorf("failed to uninstall certificate file: %v", err) |
| 201 | } |
| 202 | |
| 203 | return caddy.ExitCodeSuccess, nil |
nothing calls this directly
no test coverage detected