2020-10-29 08:23:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-10-29 08:23:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/ByteBuffer.h>
|
|
|
|
#include <AK/Forward.h>
|
2021-05-17 18:40:45 +00:00
|
|
|
#include <AK/Optional.h>
|
2020-10-30 08:26:31 +00:00
|
|
|
#include <AK/Singleton.h>
|
2020-10-29 08:23:13 +00:00
|
|
|
#include <AK/Types.h>
|
2021-04-18 09:16:17 +00:00
|
|
|
#include <LibCore/DateTime.h>
|
2020-10-29 08:23:13 +00:00
|
|
|
#include <LibCrypto/BigInt/UnsignedBigInteger.h>
|
|
|
|
#include <LibCrypto/PK/RSA.h>
|
|
|
|
|
|
|
|
namespace TLS {
|
|
|
|
|
|
|
|
enum class CertificateKeyAlgorithm {
|
|
|
|
Unsupported = 0x00,
|
|
|
|
RSA_RSA = 0x01,
|
|
|
|
RSA_MD5 = 0x04,
|
|
|
|
RSA_SHA1 = 0x05,
|
|
|
|
RSA_SHA256 = 0x0b,
|
2022-02-13 16:00:04 +00:00
|
|
|
RSA_SHA384 = 0x0c,
|
2020-10-29 08:23:13 +00:00
|
|
|
RSA_SHA512 = 0x0d,
|
|
|
|
};
|
|
|
|
|
2021-05-17 18:40:45 +00:00
|
|
|
class Certificate {
|
|
|
|
public:
|
2021-04-18 09:16:17 +00:00
|
|
|
u16 version { 0 };
|
|
|
|
CertificateKeyAlgorithm algorithm { CertificateKeyAlgorithm::Unsupported };
|
|
|
|
CertificateKeyAlgorithm key_algorithm { CertificateKeyAlgorithm::Unsupported };
|
|
|
|
CertificateKeyAlgorithm ec_algorithm { CertificateKeyAlgorithm::Unsupported };
|
|
|
|
ByteBuffer exponent {};
|
|
|
|
Crypto::PK::RSAPublicKey<Crypto::UnsignedBigInteger> public_key {};
|
|
|
|
Crypto::PK::RSAPrivateKey<Crypto::UnsignedBigInteger> private_key {};
|
|
|
|
struct Name {
|
|
|
|
String country;
|
|
|
|
String state;
|
|
|
|
String location;
|
|
|
|
String entity;
|
|
|
|
String subject;
|
|
|
|
String unit;
|
|
|
|
} issuer, subject;
|
|
|
|
Core::DateTime not_before;
|
|
|
|
Core::DateTime not_after;
|
2020-12-13 18:55:09 +00:00
|
|
|
Vector<String> SAN;
|
2021-04-18 09:16:17 +00:00
|
|
|
u8* ocsp { nullptr };
|
2020-10-29 08:23:13 +00:00
|
|
|
Crypto::UnsignedBigInteger serial_number;
|
2021-04-18 09:16:17 +00:00
|
|
|
ByteBuffer sign_key {};
|
|
|
|
ByteBuffer fingerprint {};
|
|
|
|
ByteBuffer der {};
|
|
|
|
ByteBuffer data {};
|
2022-02-21 21:14:40 +00:00
|
|
|
CertificateKeyAlgorithm signature_algorithm { CertificateKeyAlgorithm::Unsupported };
|
|
|
|
ByteBuffer signature_value {};
|
2020-10-29 08:23:13 +00:00
|
|
|
|
2021-05-17 18:40:45 +00:00
|
|
|
static Optional<Certificate> parse_asn1(ReadonlyBytes, bool client_cert = false);
|
|
|
|
|
2020-10-29 08:23:13 +00:00
|
|
|
bool is_valid() const;
|
|
|
|
};
|
|
|
|
|
2020-10-30 08:26:31 +00:00
|
|
|
class DefaultRootCACertificates {
|
|
|
|
public:
|
|
|
|
DefaultRootCACertificates();
|
|
|
|
|
2022-04-01 17:58:27 +00:00
|
|
|
Vector<Certificate> const& certificates() const { return m_ca_certificates; }
|
2020-10-30 08:26:31 +00:00
|
|
|
|
|
|
|
static DefaultRootCACertificates& the() { return s_the; }
|
|
|
|
|
|
|
|
private:
|
2021-08-07 19:34:11 +00:00
|
|
|
static Singleton<DefaultRootCACertificates> s_the;
|
2020-10-30 08:26:31 +00:00
|
|
|
|
|
|
|
Vector<Certificate> m_ca_certificates;
|
|
|
|
};
|
|
|
|
|
2020-10-29 08:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
using TLS::Certificate;
|
2020-10-30 08:26:31 +00:00
|
|
|
using TLS::DefaultRootCACertificates;
|