diff --git a/lib/cli/pkiutility.cpp b/lib/cli/pkiutility.cpp index e630578e8..5c6e1c9dd 100644 --- a/lib/cli/pkiutility.cpp +++ b/lib/cli/pkiutility.cpp @@ -31,9 +31,24 @@ using namespace icinga; +String PkiUtility::GetPkiPath(void) +{ + return Application::GetSysconfDir() + "/icinga2/pki"; +} + +String PkiUtility::GetLocalCaPath(void) +{ + return Application::GetLocalStateDir() + "/lib/icinga2/ca"; +} + +String PkiUtility::GetLocalPkiPath(void) +{ + return Application::GetLocalStateDir() + "/lib/icinga2/pki"; +} + int PkiUtility::NewCa(void) { - String cadir = Application::GetLocalStateDir() + "/lib/icinga2/ca"; + String cadir = GetLocalCaPath(); if (Utility::PathExists(cadir)) { Log(LogCritical, "cli") @@ -242,3 +257,22 @@ int PkiUtility::RequestCertificate(const String& host, const String& port, const return 0; } + + +bool PkiUtility::CopyCertFile(const String& source, const String& target) +{ + /* + if (PathExists(target)) { + Log(LogWarning, "Utility") + << "Target file '" << target << "' already exists."; + return false; + } + + std::ifstream ifs(source, std::ios::binary); + std::ofstream ofs(target, std::ios::binary); + + ofs << ifs.rdbuf(); + */ + + return true; +} diff --git a/lib/cli/pkiutility.hpp b/lib/cli/pkiutility.hpp index fae86330c..0e965ab6f 100644 --- a/lib/cli/pkiutility.hpp +++ b/lib/cli/pkiutility.hpp @@ -33,6 +33,10 @@ namespace icinga class PkiUtility { public: + static String GetPkiPath(void); + static String GetLocalCaPath(void); + static String GetLocalPkiPath(void); + static int NewCa(void); static int NewCert(const String& cn, const String& keyfile, const String& csrfile, const String& certfile); static int SignCsr(const String& csrfile, const String& certfile); @@ -41,8 +45,12 @@ public: static int RequestCertificate(const String& host, const String& port, const String& keyfile, const String& certfile, const String& cafile, const String& trustedfile, const String& ticket); + static bool CopyCertFile(const String& source, const String& target); + private: PkiUtility(void); + + }; }