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

Method Run

lib/cli/casigncommand.cpp:59–109  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

57 * @return An exit status.
58 */
59int CASignCommand::Run(const boost::program_options::variables_map&, const std::vector<std::string>& ap) const
60{
61 String requestFile = ApiListener::GetCertificateRequestsDir() + "/" + ap[0] + ".json";
62
63 if (!Utility::PathExists(requestFile)) {
64 Log(LogCritical, "cli")
65 << "No request exists for fingerprint '" << ap[0] << "'.";
66 return 1;
67 }
68
69 Dictionary::Ptr request = Utility::LoadJsonFile(requestFile);
70
71 if (!request)
72 return 1;
73
74 String certRequestText = request->Get("cert_request");
75
76 std::shared_ptr<X509> certRequest = StringToCertificate(certRequestText);
77
78 if (!certRequest) {
79 Log(LogCritical, "cli", "Certificate request is invalid. Could not parse X.509 certificate for the 'cert_request' attribute.");
80 return 1;
81 }
82
83 std::shared_ptr<X509> certResponse = CreateCertIcingaCA(certRequest);
84
85 BIO *out = BIO_new(BIO_s_mem());
86 X509_NAME_print_ex(out, X509_get_subject_name(certRequest.get()), 0, XN_FLAG_ONELINE & ~ASN1_STRFLGS_ESC_MSB);
87
88 char *data;
89 long length;
90 length = BIO_get_mem_data(out, &data);
91
92 String subject = String(data, data + length);
93 BIO_free(out);
94
95 if (!certResponse) {
96 Log(LogCritical, "cli")
97 << "Could not sign certificate for '" << subject << "'.";
98 return 1;
99 }
100
101 request->Set("cert_response", CertificateToString(certResponse));
102
103 Utility::SaveJsonFile(requestFile, 0600, request);
104
105 Log(LogInformation, "cli")
106 << "Signed certificate for '" << subject << "'.";
107
108 return 0;
109}

Callers

nothing calls this directly

Calls 9

PathExistsFunction · 0.85
LogClass · 0.85
StringToCertificateFunction · 0.85
CreateCertIcingaCAFunction · 0.85
StringClass · 0.50
CertificateToStringFunction · 0.50
GetMethod · 0.45
getMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected