mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 23:24:09 +02:00
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.";
|
<< "'" << GetName() << "' started.";
|
||||||
|
|
||||||
SyncLocalZoneDirs();
|
SyncLocalZoneDirs();
|
||||||
|
RenewOwnCert();
|
||||||
|
|
||||||
ObjectImpl<ApiListener>::Start(runtimeCreated);
|
ObjectImpl<ApiListener>::Start(runtimeCreated);
|
||||||
|
|
||||||
@ -285,6 +286,39 @@ void ApiListener::Start(bool runtimeCreated)
|
|||||||
OnMasterChanged(true);
|
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)
|
void ApiListener::Stop(bool runtimeDeleted)
|
||||||
{
|
{
|
||||||
ObjectImpl<ApiListener>::Stop(runtimeDeleted);
|
ObjectImpl<ApiListener>::Stop(runtimeDeleted);
|
||||||
|
@ -222,6 +222,7 @@ private:
|
|||||||
|
|
||||||
void SyncLocalZoneDirs() const;
|
void SyncLocalZoneDirs() const;
|
||||||
void SyncLocalZoneDir(const Zone::Ptr& zone) const;
|
void SyncLocalZoneDir(const Zone::Ptr& zone) const;
|
||||||
|
void RenewOwnCert();
|
||||||
|
|
||||||
void SendConfigUpdate(const JsonRpcConnection::Ptr& aclient);
|
void SendConfigUpdate(const JsonRpcConnection::Ptr& aclient);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user