* The entry point for the "ca restore" CLI command. * * @returns An exit status. */
| 57 | * @returns An exit status. |
| 58 | */ |
| 59 | int CARestoreCommand::Run(const boost::program_options::variables_map&, const std::vector<std::string>& ap) const |
| 60 | { |
| 61 | String fingerPrint = ap[0]; |
| 62 | String removedRequestFile = ApiListener::GetCertificateRequestsDir() + "/" + fingerPrint + ".removed"; |
| 63 | |
| 64 | if (!Utility::PathExists(removedRequestFile)) { |
| 65 | Log(LogCritical, "cli") |
| 66 | << "Cannot find removed fingerprint '" << fingerPrint << "', bailing out."; |
| 67 | return 1; |
| 68 | } |
| 69 | |
| 70 | Dictionary::Ptr request = Utility::LoadJsonFile(removedRequestFile); |
| 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 | /* Purge the file when we know that it is broken. */ |
| 76 | Utility::Remove(removedRequestFile); |
| 77 | return 1; |
| 78 | } |
| 79 | |
| 80 | Utility::SaveJsonFile(ApiListener::GetCertificateRequestsDir() + "/" + fingerPrint + ".json", 0600, request); |
| 81 | |
| 82 | Utility::Remove(removedRequestFile); |
| 83 | |
| 84 | Log(LogInformation, "cli") |
| 85 | << "Restored certificate request for CN '" << GetCertificateCN(certRequest) << "', sign it with:\n" |
| 86 | << "\"icinga2 ca sign " << fingerPrint << "\""; |
| 87 | |
| 88 | return 0; |
| 89 | } |
nothing calls this directly
no test coverage detected