#include "chrome/common/net/x509_certificate_model.h"
#include <string_view>
#include "base/check.h"
#include "base/containers/adapters.h"
#include "base/containers/fixed_flat_map.h"
#include "base/i18n/number_formatting.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/grit/generated_resources.h"
#include "components/strings/grit/components_strings.h"
#include "components/url_formatter/url_formatter.h"
#include "crypto/sha2.h"
#include "net/base/ip_address.h"
#include "net/cert/ct_objects_extractor.h"
#include "net/cert/time_conversions.h"
#include "net/cert/x509_util.h"
#include "third_party/boringssl/src/include/openssl/bn.h"
#include "third_party/boringssl/src/include/openssl/bytestring.h"
#include "third_party/boringssl/src/include/openssl/mem.h"
#include "third_party/boringssl/src/include/openssl/rsa.h"
#include "third_party/boringssl/src/pki/cert_errors.h"
#include "third_party/boringssl/src/pki/certificate_policies.h"
#include "third_party/boringssl/src/pki/extended_key_usage.h"
#include "third_party/boringssl/src/pki/input.h"
#include "third_party/boringssl/src/pki/parse_certificate.h"
#include "third_party/boringssl/src/pki/parse_name.h"
#include "third_party/boringssl/src/pki/parse_values.h"
#include "third_party/boringssl/src/pki/parser.h"
#include "third_party/boringssl/src/pki/signature_algorithm.h"
#include "third_party/boringssl/src/pki/verify_signed_data.h"
#include "ui/base/l10n/l10n_util.h"
namespace x509_certificate_model {
namespace {
constexpr uint8_t kTypeDnQualifierOid[] = …;
constexpr uint8_t kTypeBusinessCategory[] = …;
constexpr uint8_t kTypePostalCode[] = …;
constexpr uint8_t kRFC1274UidOid[] = …;
constexpr uint8_t kRFC1274MailOid[] = …;
constexpr uint8_t kEVJurisdictionLocalityName[] = …;
constexpr uint8_t kEVJurisdictionStateOrProvinceName[] = …;
constexpr uint8_t kEVJurisdictionCountryName[] = …;
constexpr uint8_t kIssuerAltNameOid[] = …;
constexpr uint8_t kSubjectDirectoryAttributesOid[] = …;
constexpr uint8_t kPkcs1RsaEncryption[] = …;
constexpr uint8_t kPkcs1Md2WithRsaEncryption[] = …;
constexpr uint8_t kPkcs1Md4WithRsaEncryption[] = …;
constexpr uint8_t kPkcs1Md5WithRsaEncryption[] = …;
constexpr uint8_t kPkcs1Sha1WithRsaEncryption[] = …;
constexpr uint8_t kPkcs1Sha256WithRsaEncryption[] = …;
constexpr uint8_t kPkcs1Sha384WithRsaEncryption[] = …;
constexpr uint8_t kPkcs1Sha512WithRsaEncryption[] = …;
constexpr uint8_t kAnsiX962EcdsaWithSha1[] = …;
constexpr uint8_t kAnsiX962EcdsaWithSha256[] = …;
constexpr uint8_t kAnsiX962EcdsaWithSha384[] = …;
constexpr uint8_t kAnsiX962EcdsaWithSha512[] = …;
constexpr uint8_t kAnsiX962EcPublicKey[] = …;
constexpr uint8_t kSecgEcSecp256r1[] = …;
constexpr uint8_t kSecgEcSecp384r1[] = …;
constexpr uint8_t kSecgEcSecp512r1[] = …;
constexpr uint8_t kNetscapeCertificateTypeOid[] = …;
constexpr uint8_t kNetscapeBaseURLOid[] = …;
constexpr uint8_t kNetscapeRevocationURLOid[] = …;
constexpr uint8_t kNetscapeCARevocationURLOid[] = …;
constexpr uint8_t kNetscapeCACertURLOid[] = …;
constexpr uint8_t kNetscapeRenewalURLOid[] = …;
constexpr uint8_t kNetscapeCAPolicyURLOid[] = …;
constexpr uint8_t kNetscapeSSLServerNameOid[] = …;
constexpr uint8_t kNetscapeCommentOid[] = …;
constexpr uint8_t kNetscapeLostPasswordURLOid[] = …;
constexpr uint8_t kNetscapeRenewalTimeOid[] = …;
constexpr uint8_t kNetscapeServerGatedCrypto[] = …;
constexpr uint8_t kMsCertExtCerttype[] = …;
constexpr uint8_t kMsCertsrvCaVersion[] = …;
constexpr uint8_t kMsNtPrincipalName[] = …;
constexpr uint8_t kMsNtdsReplication[] = …;
constexpr uint8_t kMsCertTemplate[] = …;
constexpr uint8_t kEkuMsIndividualCodeSigning[] = …;
constexpr uint8_t kEkuMsCommercialCodeSigning[] = …;
constexpr uint8_t kEkuMsTrustListSigning[] = …;
constexpr uint8_t kEkuMsTimeStamping[] = …;
constexpr uint8_t kEkuMsServerGatedCrypto[] = …;
constexpr uint8_t kEkuMsEncryptingFileSystem[] = …;
constexpr uint8_t kEkuMsFileRecovery[] = …;
constexpr uint8_t kEkuMsWindowsHardwareDriverVerification[] = …;
constexpr uint8_t kEkuMsQualifiedSubordination[] = …;
constexpr uint8_t kEkuMsKeyRecovery[] = …;
constexpr uint8_t kEkuMsDocumentSigning[] = …;
constexpr uint8_t kEkuMsLifetimeSigning[] = …;
constexpr uint8_t kEkuMsSmartCardLogon[] = …;
constexpr uint8_t kEkuMsKeyRecoveryAgent[] = …;
constexpr auto kNameStringHandling = …;
std::string ProcessRawBytesWithSeparators(base::span<const unsigned char> data,
char hex_separator,
char line_separator) { … }
std::string ProcessRawBytes(base::span<const uint8_t> data) { … }
OptionalStringOrError FindAttributeOfType(
bssl::der::Input oid,
const bssl::RelativeDistinguishedName& rdn) { … }
OptionalStringOrError FindFirstNameOfType(bssl::der::Input oid,
const bssl::RDNSequence& rdns) { … }
OptionalStringOrError FindLastNameOfType(bssl::der::Input oid,
const bssl::RDNSequence& rdns) { … }
std::string OidToNumericString(bssl::der::Input oid) { … }
constexpr auto kOidStringMap = …;
std::optional<std::string> GetOidText(bssl::der::Input oid) { … }
std::string GetOidTextOrNumeric(bssl::der::Input oid) { … }
std::string ProcessRDN(const bssl::RelativeDistinguishedName& rdn) { … }
OptionalStringOrError RDNSequenceToStringMultiLine(
const bssl::RDNSequence& rdns) { … }
std::optional<std::string> ProcessIA5String(bssl::der::Input extension_data) { … }
std::optional<std::string> ProcessBitField(bssl::der::BitString bitfield,
base::span<const int> string_map,
char separator) { … }
std::optional<std::string> ProcessBitStringValue(
bssl::der::Input value,
base::span<const int> string_map,
char separator) { … }
std::optional<std::string> ProcessBitStringExtension(
bssl::der::Input extension_data,
base::span<const int> string_map,
char separator) { … }
std::optional<std::string> ProcessNSCertTypeExtension(
bssl::der::Input extension_data) { … }
std::optional<std::string> ProcessKeyUsageExtension(
bssl::der::Input extension_data) { … }
std::optional<std::string> ProcessBasicConstraints(
bssl::der::Input extension_data) { … }
std::optional<std::string> ProcessExtKeyUsage(bssl::der::Input extension_data) { … }
OptionalStringOrError ProcessNameValue(bssl::der::Input name_value) { … }
std::string FormatGeneralName(std::u16string key, std::string_view value) { … }
std::string FormatGeneralName(int key_string_id, std::string_view value) { … }
bool ParseOtherName(bssl::der::Input other_name,
bssl::der::Input* type,
bssl::der::Input* value) { … }
std::optional<std::string> ProcessGeneralNames(
const bssl::GeneralNames& names) { … }
std::optional<std::string> ProcessGeneralNamesTlv(
bssl::der::Input extension_data) { … }
std::optional<std::string> ProcessGeneralNamesValue(
bssl::der::Input general_names_value) { … }
std::optional<std::string> ProcessSubjectKeyId(
bssl::der::Input extension_data) { … }
std::optional<std::string> ProcessAuthorityKeyId(
bssl::der::Input extension_data) { … }
std::optional<std::string> ProcessUserNoticeDisplayText(
CBS_ASN1_TAG tag,
bssl::der::Input value) { … }
std::optional<std::string> ProcessUserNotice(bssl::der::Input qualifier) { … }
std::optional<std::string> ProcessCertificatePolicies(
bssl::der::Input extension_data) { … }
std::optional<std::string> ProcessCrlDistributionPoints(
bssl::der::Input extension_data) { … }
std::optional<std::string> ProcessAuthorityInfoAccess(
bssl::der::Input extension_data) { … }
std::string ProcessAlgorithmIdentifier(bssl::der::Input algorithm_tlv) { … }
bool ParseSubjectPublicKeyInfo(bssl::der::Input spki_tlv,
bssl::der::Input* algorithm_tlv,
bssl::der::Input* subject_public_key_value) { … }
std::vector<uint8_t> BIGNUMBytes(const BIGNUM* bn) { … }
}
X509CertificateModel::X509CertificateModel(
bssl::UniquePtr<CRYPTO_BUFFER> cert_data,
std::string nickname)
: … { … }
X509CertificateModel::X509CertificateModel(X509CertificateModel&& other) =
default;
X509CertificateModel::~X509CertificateModel() = default;
std::string X509CertificateModel::HashCertSHA256() const { … }
std::string X509CertificateModel::GetTitle() const { … }
std::string X509CertificateModel::GetVersion() const { … }
std::string X509CertificateModel::GetSerialNumberHexified() const { … }
bool X509CertificateModel::GetTimes(base::Time* not_before,
base::Time* not_after) const { … }
OptionalStringOrError X509CertificateModel::GetIssuerCommonName() const { … }
OptionalStringOrError X509CertificateModel::GetIssuerOrgName() const { … }
OptionalStringOrError X509CertificateModel::GetIssuerOrgUnitName() const { … }
OptionalStringOrError X509CertificateModel::GetSubjectCommonName() const { … }
OptionalStringOrError X509CertificateModel::GetSubjectOrgName() const { … }
OptionalStringOrError X509CertificateModel::GetSubjectOrgUnitName() const { … }
OptionalStringOrError X509CertificateModel::GetIssuerName() const { … }
OptionalStringOrError X509CertificateModel::GetSubjectName() const { … }
std::vector<Extension> X509CertificateModel::GetExtensions(
std::string_view critical_label,
std::string_view non_critical_label) const { … }
bool X509CertificateModel::ParseExtensions(
const bssl::der::Input& extensions_tlv) { … }
std::string X509CertificateModel::ProcessExtension(
std::string_view critical_label,
std::string_view non_critical_label,
const bssl::ParsedExtension& extension) const { … }
std::optional<std::string> X509CertificateModel::ProcessExtensionData(
const bssl::ParsedExtension& extension) const { … }
std::string X509CertificateModel::ProcessSecAlgorithmSignature() const { … }
std::string X509CertificateModel::ProcessSecAlgorithmSubjectPublicKey() const { … }
std::string X509CertificateModel::ProcessSecAlgorithmSignatureWrap() const { … }
std::string X509CertificateModel::ProcessSubjectPublicKeyInfo() const { … }
std::string X509CertificateModel::HashSpkiSHA256() const { … }
std::string X509CertificateModel::ProcessRawBitsSignatureWrap() const { … }
std::string ProcessIDN(const std::string& input) { … }
std::string ProcessRawSubjectPublicKeyInfo(base::span<const uint8_t> spki_der) { … }
}