mirror of https://github.com/Icinga/icinga2.git
Introduce IsCaUptodate() by splitting IsCertUptodate()
This commit is contained in:
parent
2d167ccd28
commit
74f52c6fcd
|
@ -760,18 +760,31 @@ std::shared_ptr<X509> CreateCertIcingaCA(const std::shared_ptr<X509>& cert)
|
||||||
return CreateCertIcingaCA(pkey.get(), X509_get_subject_name(cert.get()));
|
return CreateCertIcingaCA(pkey.get(), X509_get_subject_name(cert.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
bool CertExpiresWithin(X509* cert, int seconds)
|
||||||
|
{
|
||||||
|
time_t renewalStart = time(nullptr) + seconds;
|
||||||
|
|
||||||
|
return X509_cmp_time(X509_get_notAfter(cert), &renewalStart) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool IsCertUptodate(const std::shared_ptr<X509>& cert)
|
bool IsCertUptodate(const std::shared_ptr<X509>& cert)
|
||||||
{
|
{
|
||||||
time_t now;
|
if (CertExpiresWithin(cert.get(), RENEW_THRESHOLD)) {
|
||||||
time(&now);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* auto-renew all certificates which were created before 2017 to force an update of the CA,
|
/* auto-renew all certificates which were created before 2017 to force an update of the CA,
|
||||||
* because Icinga versions older than 2.4 sometimes create certificates with an invalid
|
* because Icinga versions older than 2.4 sometimes create certificates with an invalid
|
||||||
* serial number. */
|
* serial number. */
|
||||||
time_t forceRenewalEnd = 1483228800; /* January 1st, 2017 */
|
time_t forceRenewalEnd = 1483228800; /* January 1st, 2017 */
|
||||||
time_t renewalStart = now + RENEW_THRESHOLD;
|
|
||||||
|
|
||||||
return X509_cmp_time(X509_get_notBefore(cert.get()), &forceRenewalEnd) != -1 && X509_cmp_time(X509_get_notAfter(cert.get()), &renewalStart) != -1;
|
return X509_cmp_time(X509_get_notBefore(cert.get()), &forceRenewalEnd) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsCaUptodate(X509* cert)
|
||||||
|
{
|
||||||
|
return !CertExpiresWithin(cert, LEAF_VALID_FOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
String CertificateToString(const std::shared_ptr<X509>& cert)
|
String CertificateToString(const std::shared_ptr<X509>& cert)
|
||||||
|
|
|
@ -64,6 +64,7 @@ std::shared_ptr<X509> StringToCertificate(const String& cert);
|
||||||
std::shared_ptr<X509> CreateCertIcingaCA(EVP_PKEY *pubkey, X509_NAME *subject);
|
std::shared_ptr<X509> CreateCertIcingaCA(EVP_PKEY *pubkey, X509_NAME *subject);
|
||||||
std::shared_ptr<X509> CreateCertIcingaCA(const std::shared_ptr<X509>& cert);
|
std::shared_ptr<X509> CreateCertIcingaCA(const std::shared_ptr<X509>& cert);
|
||||||
bool IsCertUptodate(const std::shared_ptr<X509>& cert);
|
bool IsCertUptodate(const std::shared_ptr<X509>& cert);
|
||||||
|
bool IsCaUptodate(X509* cert);
|
||||||
|
|
||||||
String PBKDF2_SHA1(const String& password, const String& salt, int iterations);
|
String PBKDF2_SHA1(const String& password, const String& salt, int iterations);
|
||||||
String PBKDF2_SHA256(const String& password, const String& salt, int iterations);
|
String PBKDF2_SHA256(const String& password, const String& salt, int iterations);
|
||||||
|
|
Loading…
Reference in New Issue