From ba0acff719133eab91a4fa21feee987c327578cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Tue, 21 Jan 2020 20:21:34 +0100 Subject: [PATCH] fixed GH #2743: X509Certificate validFrom expiresOn Date parsing --- Crypto/src/X509Certificate.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Crypto/src/X509Certificate.cpp b/Crypto/src/X509Certificate.cpp index dff55bec6..53fc573be 100644 --- a/Crypto/src/X509Certificate.cpp +++ b/Crypto/src/X509Certificate.cpp @@ -305,7 +305,18 @@ Poco::DateTime X509Certificate::validFrom() const const ASN1_TIME* certTime = X509_get0_notBefore(_pCert); std::string dateTime(reinterpret_cast(certTime->data)); int tzd; - return DateTimeParser::parse("%y%m%d%H%M%S", dateTime, tzd); + if (certTime->type == V_ASN1_UTCTIME) + { + return DateTimeParser::parse("%y%m%d%H%M%S", dateTime, tzd); + } + else if (certTime->type == V_ASN1_GENERALIZEDTIME) + { + return DateTimeParser::parse("%Y%m%d%H%M%S", dateTime, tzd); + } + else + { + throw NotImplementedException("Unsupported date/time format in notBefore"); + } } @@ -314,7 +325,18 @@ Poco::DateTime X509Certificate::expiresOn() const const ASN1_TIME* certTime = X509_get0_notAfter(_pCert); std::string dateTime(reinterpret_cast(certTime->data)); int tzd; - return DateTimeParser::parse("%y%m%d%H%M%S", dateTime, tzd); + if (certTime->type == V_ASN1_UTCTIME) + { + return DateTimeParser::parse("%y%m%d%H%M%S", dateTime, tzd); + } + else if (certTime->type == V_ASN1_GENERALIZEDTIME) + { + return DateTimeParser::parse("%Y%m%d%H%M%S", dateTime, tzd); + } + else + { + throw NotImplementedException("Unsupported date/time format in notBefore"); + } }