Check for leap year, and adjust the date accordingly

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2024-09-16 06:26:50 +02:00
parent 2153cbbee3
commit 8fed1361f1
+3
View File
@@ -238,6 +238,9 @@ bool generate_certificate(const char* certfile, bool rsa, const char *domain)
char not_after[16] = { 0 };
strftime(not_before, sizeof(not_before), "%Y%m%d%H%M%S", tm);
tm->tm_year += 30; // 30 years from now
// Check for leap year, and adjust the date accordingly
const bool isLeapYear = tm->tm_year % 4 == 0 && (tm->tm_year % 100 != 0 || tm->tm_year % 400 == 0);
tm->tm_mday = tm->tm_mon == 2 && tm->tm_mday == 29 && !isLeapYear ? 28 : tm->tm_mday;
strftime(not_after, sizeof(not_after), "%Y%m%d%H%M%S", tm);
// 1. Create CA certificate