mirror of https://github.com/Icinga/icinga2.git
ApiListener#Start(): auto-renew own cert if CA owner
otherwise that particular cert would expire.
This commit is contained in:
parent
6d470a3ca5
commit
3753f86c80
|
@ -235,6 +235,7 @@ void ApiListener::Start(bool runtimeCreated)
|
|||
<< "'" << GetName() << "' started.";
|
||||
|
||||
SyncLocalZoneDirs();
|
||||
RenewOwnCert();
|
||||
|
||||
ObjectImpl<ApiListener>::Start(runtimeCreated);
|
||||
|
||||
|
@ -285,6 +286,39 @@ void ApiListener::Start(bool runtimeCreated)
|
|||
OnMasterChanged(true);
|
||||
}
|
||||
|
||||
void ApiListener::RenewOwnCert()
|
||||
{
|
||||
if (!Utility::PathExists(GetIcingaCADir() + "/ca.key")) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto certPath (GetDefaultCertPath());
|
||||
auto cert (GetX509Certificate(certPath));
|
||||
|
||||
if (IsCertUptodate(cert)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Log(LogInformation, "ApiListener")
|
||||
<< "Our certificate will expire soon, but we own the CA. Renewing.";
|
||||
|
||||
cert = RenewCert(cert);
|
||||
|
||||
if (!cert) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::fstream certfp;
|
||||
auto tempCertPath (Utility::CreateTempFile(certPath + ".XXXXXX", 0644, certfp));
|
||||
|
||||
certfp.exceptions(std::ofstream::failbit | std::ofstream::badbit);
|
||||
certfp << CertificateToString(cert);
|
||||
certfp.close();
|
||||
|
||||
Utility::RenameFile(tempCertPath, certPath);
|
||||
UpdateSSLContext();
|
||||
}
|
||||
|
||||
void ApiListener::Stop(bool runtimeDeleted)
|
||||
{
|
||||
ObjectImpl<ApiListener>::Stop(runtimeDeleted);
|
||||
|
|
|
@ -222,6 +222,7 @@ private:
|
|||
|
||||
void SyncLocalZoneDirs() const;
|
||||
void SyncLocalZoneDir(const Zone::Ptr& zone) const;
|
||||
void RenewOwnCert();
|
||||
|
||||
void SendConfigUpdate(const JsonRpcConnection::Ptr& aclient);
|
||||
|
||||
|
|
Loading…
Reference in New Issue