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

Method Run

lib/cli/pkiverifycommand.cpp:49–227  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

47 * @returns An exit status.
48 */
49int PKIVerifyCommand::Run(const boost::program_options::variables_map& vm, [[maybe_unused]] const std::vector<std::string>& ap) const
50{
51 String cn, certFile, caCertFile, crlFile;
52
53 if (vm.count("cn"))
54 cn = vm["cn"].as<std::string>();
55
56 if (vm.count("cert"))
57 certFile = vm["cert"].as<std::string>();
58
59 if (vm.count("cacert"))
60 caCertFile = vm["cacert"].as<std::string>();
61
62 if (vm.count("crl"))
63 crlFile = vm["crl"].as<std::string>();
64
65 /* Verify CN in certificate. */
66 if (!cn.IsEmpty() && !certFile.IsEmpty()) {
67 std::shared_ptr<X509> cert;
68 try {
69 cert = GetX509Certificate(certFile);
70 } catch (const std::exception& ex) {
71 Log(LogCritical, "cli")
72 << "Cannot read certificate file '" << certFile << "'. Please ensure that it exists and is readable.";
73
74 return ServiceCritical;
75 }
76
77 Log(LogInformation, "cli")
78 << "Verifying common name (CN) '" << cn << " in certificate '" << certFile << "'.";
79
80 std::cout << PkiUtility::GetCertificateInformation(cert) << "\n";
81
82 String certCN = GetCertificateCN(cert);
83
84 if (cn == certCN) {
85 Log(LogInformation, "cli")
86 << "OK: CN '" << cn << "' matches certificate CN '" << certCN << "'.";
87
88 return ServiceOK;
89 } else {
90 Log(LogCritical, "cli")
91 << "CRITICAL: CN '" << cn << "' does NOT match certificate CN '" << certCN << "'.";
92
93 return ServiceCritical;
94 }
95 }
96
97 /* Verify certificate. */
98 if (!certFile.IsEmpty() && !caCertFile.IsEmpty()) {
99 std::shared_ptr<X509> cert;
100 try {
101 cert = GetX509Certificate(certFile);
102 } catch (const std::exception& ex) {
103 Log(LogCritical, "cli")
104 << "Cannot read certificate file '" << certFile << "'. Please ensure that it exists and is readable.";
105
106 return ServiceCritical;

Callers

nothing calls this directly

Calls 7

GetX509CertificateFunction · 0.85
LogClass · 0.85
GetCertificateCNFunction · 0.85
VerifyCertificateFunction · 0.85
IsCaFunction · 0.85
countMethod · 0.80
IsEmptyMethod · 0.45

Tested by

no test coverage detected