mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 15:49:11 +00:00
LibTLS: Move some Certificate
methods to the correct file
The implementation of `Certificate::is_valid` and `Certificate::is_self_signed` were in `TLSv12.cpp` and they have been moved to `Certificate.cpp`. This is in preparation of the next commits to split the changes.
This commit is contained in:
parent
e42410a7a7
commit
32a90a7fd1
Notes:
github-actions[bot]
2024-11-25 13:12:24 +00:00
Author: https://github.com/devgianlu
Commit: 32a90a7fd1
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2563
Reviewed-by: https://github.com/alimpfard ✅
2 changed files with 35 additions and 34 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include "Certificate.h"
|
#include "Certificate.h"
|
||||||
#include <AK/Debug.h>
|
#include <AK/Debug.h>
|
||||||
#include <AK/IPv4Address.h>
|
#include <AK/IPv4Address.h>
|
||||||
|
#include <LibCore/DateTime.h>
|
||||||
#include <LibCrypto/ASN1/ASN1.h>
|
#include <LibCrypto/ASN1/ASN1.h>
|
||||||
#include <LibCrypto/ASN1/DER.h>
|
#include <LibCrypto/ASN1/DER.h>
|
||||||
#include <LibCrypto/ASN1/PEM.h>
|
#include <LibCrypto/ASN1/PEM.h>
|
||||||
|
@ -907,4 +908,38 @@ ErrorOr<String> RelativeDistinguishedName::to_string() const
|
||||||
|
|
||||||
return cert_name.to_string();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
void TLSv12::try_disambiguate_error() const
|
||||||
{
|
{
|
||||||
dbgln("Possible failure cause(s): ");
|
dbgln("Possible failure cause(s): ");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue