diff --git a/Libraries/LibTLS/Certificate.cpp b/Libraries/LibTLS/Certificate.cpp index aea4f4db94d..a3c82a93438 100644 --- a/Libraries/LibTLS/Certificate.cpp +++ b/Libraries/LibTLS/Certificate.cpp @@ -8,6 +8,7 @@ #include "Certificate.h" #include #include +#include #include #include #include @@ -907,4 +908,38 @@ ErrorOr RelativeDistinguishedName::to_string() const return cert_name.to_string(); } + +bool Certificate::is_valid() const +{ + auto now = UnixDateTime::now(); + + if (now < validity.not_before) { + dbgln("certificate expired (not yet valid, signed for {})", Core::DateTime::from_timestamp(validity.not_before.seconds_since_epoch())); + return false; + } + + if (validity.not_after < now) { + dbgln("certificate expired (expiry date {})", Core::DateTime::from_timestamp(validity.not_after.seconds_since_epoch())); + return false; + } + + return true; +} + +// https://www.ietf.org/rfc/rfc5280.html#page-12 +bool Certificate::is_self_signed() +{ + if (m_is_self_signed.has_value()) + return *m_is_self_signed; + + // Self-signed certificates are self-issued certificates where the digital + // signature may be verified by the public key bound into the certificate. + if (!this->is_self_issued) + m_is_self_signed.emplace(false); + + // FIXME: Actually check if we sign ourself + + m_is_self_signed.emplace(true); + return *m_is_self_signed; +} } diff --git a/Libraries/LibTLS/TLSv12.cpp b/Libraries/LibTLS/TLSv12.cpp index c49a3056ddb..97b3799d0fc 100644 --- a/Libraries/LibTLS/TLSv12.cpp +++ b/Libraries/LibTLS/TLSv12.cpp @@ -101,40 +101,6 @@ void TLSv12::consume(ReadonlyBytes record) } } -bool Certificate::is_valid() const -{ - auto now = UnixDateTime::now(); - - if (now < validity.not_before) { - dbgln("certificate expired (not yet valid, signed for {})", Core::DateTime::from_timestamp(validity.not_before.seconds_since_epoch())); - return false; - } - - if (validity.not_after < now) { - dbgln("certificate expired (expiry date {})", Core::DateTime::from_timestamp(validity.not_after.seconds_since_epoch())); - return false; - } - - return true; -} - -// https://www.ietf.org/rfc/rfc5280.html#page-12 -bool Certificate::is_self_signed() -{ - if (m_is_self_signed.has_value()) - return *m_is_self_signed; - - // Self-signed certificates are self-issued certificates where the digital - // signature may be verified by the public key bound into the certificate. - if (!this->is_self_issued) - m_is_self_signed.emplace(false); - - // FIXME: Actually check if we sign ourself - - m_is_self_signed.emplace(true); - return *m_is_self_signed; -} - void TLSv12::try_disambiguate_error() const { dbgln("Possible failure cause(s): ");