MCPcopy Create free account
hub / github.com/Icinga/icinga2 / Run

Method Run

lib/cli/carestorecommand.cpp:59–89  ·  view source on GitHub ↗

* The entry point for the "ca restore" CLI command. * * @returns An exit status. */

Source from the content-addressed store, hash-verified

57 * @returns An exit status.
58 */
59int 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}

Callers

nothing calls this directly

Calls 5

PathExistsFunction · 0.85
LogClass · 0.85
StringToCertificateFunction · 0.85
GetCertificateCNFunction · 0.85
GetMethod · 0.45

Tested by

no test coverage detected