mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:47:37 +00:00
LibTLS: Cleanup of verify_chain and verify_certificate_pair
This commit is contained in:
parent
be654dad8a
commit
fa18c283dc
2 changed files with 33 additions and 32 deletions
|
@ -270,7 +270,7 @@ bool Context::verify_chain(StringView host) const
|
|||
|
||||
auto maybe_root_certificate = root_certificates.get(issuer_string);
|
||||
if (maybe_root_certificate.has_value()) {
|
||||
auto root_certificate = maybe_root_certificate.release_value();
|
||||
auto& root_certificate = *maybe_root_certificate;
|
||||
auto verification_correct = verify_certificate_pair(cert, root_certificate);
|
||||
|
||||
if (!verification_correct) {
|
||||
|
@ -280,7 +280,8 @@ bool Context::verify_chain(StringView host) const
|
|||
|
||||
// Root certificate reached, and correctly verified, so we can stop now
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
|
||||
if (subject_string == issuer_string) {
|
||||
dbgln("verify_chain: Non-root self-signed certificate");
|
||||
return options.allow_self_signed_certificates;
|
||||
|
@ -312,13 +313,12 @@ bool Context::verify_chain(StringView host) const
|
|||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Either a root certificate is reached, or parent validation fails as the end of the local chain is reached
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
bool Context::verify_certificate_pair(Certificate& subject, Certificate& issuer) const
|
||||
bool Context::verify_certificate_pair(Certificate const& subject, Certificate const& issuer) const
|
||||
{
|
||||
Crypto::Hash::HashKind kind;
|
||||
switch (subject.signature_algorithm) {
|
||||
|
@ -340,7 +340,8 @@ bool Context::verify_certificate_pair(Certificate& subject, Certificate& issuer)
|
|||
}
|
||||
|
||||
Crypto::PK::RSAPrivateKey dummy_private_key;
|
||||
auto rsa = Crypto::PK::RSA(issuer.public_key, dummy_private_key);
|
||||
Crypto::PK::RSAPublicKey public_key_copy { issuer.public_key };
|
||||
auto rsa = Crypto::PK::RSA(public_key_copy, dummy_private_key);
|
||||
auto verification_buffer_result = ByteBuffer::create_uninitialized(subject.signature_value.size());
|
||||
if (verification_buffer_result.is_error()) {
|
||||
dbgln("verify_certificate_pair: Unable to allocate buffer for verification");
|
||||
|
|
|
@ -263,7 +263,7 @@ struct Options {
|
|||
|
||||
struct Context {
|
||||
bool verify_chain(StringView host) const;
|
||||
bool verify_certificate_pair(Certificate& subject, Certificate& issuer) const;
|
||||
bool verify_certificate_pair(Certificate const& subject, Certificate const& issuer) const;
|
||||
|
||||
Options options;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue