* The entry point for the "ca remove" CLI command. * * @returns An exit status. */
| 57 | * @returns An exit status. |
| 58 | */ |
| 59 | int CARemoveCommand::Run(const boost::program_options::variables_map&, const std::vector<std::string>& ap) const |
| 60 | { |
| 61 | String fingerPrint = ap[0]; |
| 62 | String requestFile = ApiListener::GetCertificateRequestsDir() + "/" + fingerPrint + ".json"; |
| 63 | |
| 64 | if (!Utility::PathExists(requestFile)) { |
| 65 | Log(LogCritical, "cli") |
| 66 | << "No request exists for fingerprint '" << fingerPrint << "'."; |
| 67 | return 1; |
| 68 | } |
| 69 | |
| 70 | Dictionary::Ptr request = Utility::LoadJsonFile(requestFile); |
| 71 | std::shared_ptr<X509> certRequest = StringToCertificate(request->Get("cert_request")); |
| 72 | |
| 73 | if (!certRequest) { |
| 74 | Log(LogCritical, "cli", "Certificate request is invalid. Could not parse X.509 certificate for the 'cert_request' attribute."); |
| 75 | return 1; |
| 76 | } |
| 77 | |
| 78 | String cn = GetCertificateCN(certRequest); |
| 79 | |
| 80 | if (request->Contains("cert_response")) { |
| 81 | Log(LogCritical, "cli") |
| 82 | << "Certificate request for CN '" << cn << "' already signed, removal is not possible."; |
| 83 | return 1; |
| 84 | } |
| 85 | |
| 86 | Utility::SaveJsonFile(ApiListener::GetCertificateRequestsDir() + "/" + fingerPrint + ".removed", 0600, request); |
| 87 | |
| 88 | Utility::Remove(requestFile); |
| 89 | |
| 90 | Log(LogInformation, "cli") |
| 91 | << "Certificate request for CN " << cn << " removed."; |
| 92 | |
| 93 | return 0; |
| 94 | } |
nothing calls this directly
no test coverage detected