martinzink commented on code in PR #1336:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1336#discussion_r876165303


##########
libminifi/src/controllers/SSLContextService.cpp:
##########
@@ -563,6 +559,89 @@ void SSLContextService::initializeProperties() {
   setSupportedProperties(supportedProperties);
 }
 
+void SSLContextService::verifyCertificateExpiration() {
+  auto verify = [&] (const std::string& cert_file, const 
utils::tls::X509_unique_ptr& cert) {
+    if (auto end_date = utils::tls::getCertificateExpiration(cert)) {
+      std::string end_date_str = 
getTimeStr(std::chrono::duration_cast<std::chrono::milliseconds>(end_date->time_since_epoch()).count());
+      if (end_date.value() < std::chrono::system_clock::now()) {
+        core::logging::LOG_ERROR(logger_) << "Certificate in '" << cert_file 
<< "' expired at " << end_date_str;
+      } else if (auto diff = end_date.value() - 
std::chrono::system_clock::now(); diff < std::chrono::months{3}) {
+        core::logging::LOG_WARN(logger_) << "Certificate in '" << cert_file << 
"' will expire at " << end_date_str;

Review Comment:
   FYI std::chrono::months is different than std::chrono::month, first one is 
an exact duration (year length/12 (~30.4369 days)) the other one is the nth 
month of the year.
   e.g. timestamp(2022/03/01) - 1 months is in January not February
   If we want the same day of the previous month than we would need to use the 
calendar part of std::chrono/date.h 
https://en.cppreference.com/w/cpp/chrono/year_month_day/year_month_day (but we 
probably dont want that.)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to