Truly independent web browser
LibCrypto: Remove OIDs and LDAP names left over from X.509 parsing
Shannon Boothe264ce7badcf
diff --git a/Libraries/LibCrypto/ASN1/Constants.h b/Libraries/LibCrypto/ASN1/Constants.hindex 9e450a45d58..c44ae8316c7 100644--- a/Libraries/LibCrypto/ASN1/Constants.h+++ b/Libraries/LibCrypto/ASN1/Constants.h@@ -12,16 +12,6 @@ namespace Crypto::ASN1 {constexpr static Array<u32, 7>rsa_encryption_oid { 1, 2, 840, 113549, 1, 1, 1 },- rsa_md5_encryption_oid { 1, 2, 840, 113549, 1, 1, 4 },- rsa_sha1_encryption_oid { 1, 2, 840, 113549, 1, 1, 5 },- rsa_sha256_encryption_oid { 1, 2, 840, 113549, 1, 1, 11 },- rsa_sha384_encryption_oid { 1, 2, 840, 113549, 1, 1, 12 },- rsa_sha512_encryption_oid { 1, 2, 840, 113549, 1, 1, 13 },- rsa_sha224_encryption_oid { 1, 2, 840, 113549, 1, 1, 14 },- ecdsa_with_sha224_encryption_oid { 1, 2, 840, 10045, 4, 3, 1 },- ecdsa_with_sha256_encryption_oid { 1, 2, 840, 10045, 4, 3, 2 },- ecdsa_with_sha384_encryption_oid { 1, 2, 840, 10045, 4, 3, 3 },- ecdsa_with_sha512_encryption_oid { 1, 2, 840, 10045, 4, 3, 4 },secp256r1_oid { 1, 2, 840, 10045, 3, 1, 7 };constexpr static Array<u32, 6>@@ -35,11 +25,7 @@ constexpr static Array<u32, 4>x25519_oid { 1, 3, 101, 110 },x448_oid { 1, 3, 101, 111 },ed25519_oid { 1, 3, 101, 112 },- ed448_oid { 1, 3, 101, 113 },- key_usage_oid { 2, 5, 29, 15 },- subject_alternative_name_oid { 2, 5, 29, 17 },- issuer_alternative_name_oid { 2, 5, 29, 18 },- basic_constraints_oid { 2, 5, 29, 19 };+ ed448_oid { 1, 3, 101, 113 };constexpr static Array<u32, 9>ml_dsa_44_oid { 2, 16, 840, 1, 101, 3, 4, 3, 17 },@@ -51,115 +37,4 @@ constexpr static Array<u32, 9>ml_kem_768_oid { 2, 16, 840, 1, 101, 3, 4, 4, 2 },ml_kem_1024_oid { 2, 16, 840, 1, 101, 3, 4, 4, 3 };-#define _ENUM(key, value) key,--#define __ENUM_OBJECT_CLASS \- _ENUM(ApplicationProcess, "2.5.6.11"sv) \- _ENUM(Country, "2.5.6.2"sv) \- _ENUM(DcObject, "1.3.6.1.4.1.1466.344"sv) \- _ENUM(Device, "2.5.6.14"sv) \- _ENUM(GroupOfNames, "2.5.6.9"sv) \- _ENUM(GroupOfUniqueNames, "2.5.6.17"sv) \- _ENUM(Locality, "2.5.6.3"sv) \- _ENUM(Organization, "2.5.6.4"sv) \- _ENUM(OrganizationalPerson, "2.5.6.7"sv) \- _ENUM(OrganizationalRole, "2.5.6.8"sv) \- _ENUM(OrganizationalUnit, "2.5.6.5"sv) \- _ENUM(Person, "2.5.6.6"sv) \- _ENUM(ResidentialPerson, "2.5.6.10"sv) \- _ENUM(UidObject, "1.3.6.1.1.3.1"sv)--// NOTE: Type = O-// NOTE: This list is not exhaustive. If more members are needed, find them at the link below.-// https://www.iana.org/assignments/ldap-parameters/ldap-parameters.xhtml#ldap-parameters-3-enum class ObjectClass {- __ENUM_OBJECT_CLASS-};--#define __ENUM_ATTRIBUTE_TYPE \- _ENUM(BusinessCategory, "2.5.4.15"sv) \- _ENUM(C, "2.5.4.6"sv) \- _ENUM(Cn, "2.5.4.3"sv) \- _ENUM(Dc, "0.9.2342.19200300.100.1.25"sv) \- _ENUM(Description, "2.5.4.13"sv) \- _ENUM(DestinationIndicator, "2.5.4.27"sv) \- _ENUM(DistinguishedName, "2.5.4.49"sv) \- _ENUM(DnQualifier, "2.5.4.46"sv) \- _ENUM(EnhancedSearchGuide, "2.5.4.47"sv) \- _ENUM(Email, "1.2.840.113549.1.9.1"sv) \- _ENUM(FacsimileTelephoneNumber, "2.5.4.23"sv) \- _ENUM(GenerationQualifier, "2.5.4.44"sv) \- _ENUM(GivenName, "2.5.4.42"sv) \- _ENUM(HouseIdentifier, "2.5.4.51"sv) \- _ENUM(Initials, "2.5.4.43"sv) \- _ENUM(InternationalISDNNumber, "2.5.4.25"sv) \- _ENUM(L, "2.5.4.7"sv) \- _ENUM(Member, "2.5.4.31"sv) \- _ENUM(Name, "2.5.4.41"sv) \- _ENUM(O, "2.5.4.10"sv) \- _ENUM(Ou, "2.5.4.11"sv) \- _ENUM(Owner, "2.5.4.32"sv) \- _ENUM(PhysicalDeliveryOfficeName, "2.5.4.19"sv) \- _ENUM(PostalAddress, "2.5.4.16"sv) \- _ENUM(PostalCode, "2.5.4.17"sv) \- _ENUM(PostOfficeBox, "2.5.4.18"sv) \- _ENUM(PreferredDeliveryMethod, "2.5.4.28"sv) \- _ENUM(RegisteredAddress, "2.5.4.26"sv) \- _ENUM(RoleOccupant, "2.5.4.33"sv) \- _ENUM(SearchGuide, "2.5.4.14"sv) \- _ENUM(SeeAlso, "2.5.4.34"sv) \- _ENUM(SerialNumber, "2.5.4.5"sv) \- _ENUM(Sn, "2.5.4.4"sv) \- _ENUM(St, "2.5.4.8"sv) \- _ENUM(Street, "2.5.4.9"sv) \- _ENUM(Surname, "2.5.4.4"sv) \- _ENUM(TelephoneNumber, "2.5.4.20"sv) \- _ENUM(TeletexTerminalIdentifier, "2.5.4.22"sv) \- _ENUM(TelexNumber, "2.5.4.21"sv) \- _ENUM(Title, "2.5.4.12"sv) \- _ENUM(Uid, "0.9.2342.19200300.100.1.1"sv) \- _ENUM(UniqueMember, "2.5.4.50"sv) \- _ENUM(UserPassword, "2.5.4.35"sv) \- _ENUM(X121Address, "2.5.4.24"sv) \- _ENUM(X500UniqueIdentifier, "2.5.4.45"sv)--// NOTE: Type = A-// NOTE: This list is not exhaustive. If more members are needed, find them at the link below.-// https://www.iana.org/assignments/ldap-parameters/ldap-parameters.xhtml#ldap-parameters-3-enum class AttributeType {- __ENUM_ATTRIBUTE_TYPE-};--#undef _ENUM--constexpr static StringView enum_value(ObjectClass object_class)-{-#define _ENUM(key, value) \- case ObjectClass::key: \- return value;-- switch (object_class) {- __ENUM_OBJECT_CLASS- }-- return "Unknown"sv;-#undef _ENUM-#undef __ENUM_OBJECT_CLASS-}--constexpr static StringView enum_value(AttributeType object_class)-{-#define _ENUM(key, value) \- case AttributeType::key: \- return value;-- switch (object_class) {- __ENUM_ATTRIBUTE_TYPE- }-- return "Unknown"sv;-#undef _ENUM-#undef __ENUM_ATTRIBUTE_TYPE-}-}diff --git a/Libraries/LibCrypto/Certificate/Certificate.cpp b/Libraries/LibCrypto/Certificate/Certificate.cppindex 746464b2249..4e462c01c32 100644--- a/Libraries/LibCrypto/Certificate/Certificate.cpp+++ b/Libraries/LibCrypto/Certificate/Certificate.cpp@@ -54,15 +54,8 @@ static ErrorOr<AlgorithmIdentifier> parse_algorithm_identifier(ASN1::Decoder& deREAD_OBJECT(ObjectIdentifier, ASN1::ObjectIdentifier, algorithm);POP_SCOPE();- constexpr static Array<Span<u32 const>, 19> known_algorithm_identifiers {+ constexpr static Array<Span<u32 const>, 12> known_algorithm_identifiers {ASN1::rsa_encryption_oid,- ASN1::rsa_md5_encryption_oid,- ASN1::rsa_sha1_encryption_oid,- ASN1::rsa_sha256_encryption_oid,- ASN1::rsa_sha384_encryption_oid,- ASN1::rsa_sha512_encryption_oid,- ASN1::ecdsa_with_sha256_encryption_oid,- ASN1::ecdsa_with_sha384_encryption_oid,ASN1::ec_public_key_encryption_oid,ASN1::x25519_oid,ASN1::ed25519_oid,@@ -88,34 +81,10 @@ static ErrorOr<AlgorithmIdentifier> parse_algorithm_identifier(ASN1::Decoder& deERROR_WITH_SCOPE(TRY(String::formatted("Unknown algorithm {}", algorithm)));}- // -- When the following OIDs are used in an AlgorithmIdentifier, the- // -- parameters MUST be present and MUST be NULL.- // sha256WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 1 }- // sha256WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 4 }- // sha256WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 5 }- // sha256WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 11 }- // sha384WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 12 }- // sha512WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 13 }- // sha224WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 14 }- constexpr static Array<Span<u32 const>, 8> rsa_null_algorithms = {- ASN1::rsa_encryption_oid,- ASN1::rsa_md5_encryption_oid,- ASN1::rsa_sha1_encryption_oid,- ASN1::rsa_sha256_encryption_oid,- ASN1::rsa_sha384_encryption_oid,- ASN1::rsa_sha512_encryption_oid,- ASN1::rsa_sha224_encryption_oid,- };-- bool is_rsa_null_algorithm = false;- for (auto const& inner : rsa_null_algorithms) {- if (inner == algorithm.span()) {- is_rsa_null_algorithm = true;- break;- }- }-- if (is_rsa_null_algorithm) {+ // -- When rsaEncryption is used in an AlgorithmIdentifier,+ // -- the parameters MUST be present and MUST be NULL.+ // rsaEncryption OBJECT IDENTIFIER ::= { pkcs-1 1 }+ if (algorithm.span() == ASN1::rsa_encryption_oid.span()) {PUSH_SCOPE("RSA null parameter"sv);READ_OBJECT(Null, void*, forced_null);(void)forced_null;@@ -125,12 +94,6 @@ static ErrorOr<AlgorithmIdentifier> parse_algorithm_identifier(ASN1::Decoder& dereturn AlgorithmIdentifier(algorithm);}- // https://www.ietf.org/rfc/rfc5758.txt- // When the ecdsa-with-SHA224, ecdsa-with-SHA256, ecdsa-with-SHA384, or- // ecdsa-with-SHA512 algorithm identifier appears in the algorithm field- // as an AlgorithmIdentifier, the encoding MUST omit the parameters- // field.-// https://datatracker.ietf.org/doc/html/rfc8410#section-9// For all of the OIDs, the parameters MUST be absent.@@ -139,11 +102,7 @@ static ErrorOr<AlgorithmIdentifier> parse_algorithm_identifier(ASN1::Decoder& de// https://datatracker.ietf.org/doc/html/rfc8410#section-9// For all of the OIDs, the parameters MUST be absent.- constexpr static Array<Span<u32 const>, 15> no_parameter_algorithms = {- ASN1::ecdsa_with_sha224_encryption_oid,- ASN1::ecdsa_with_sha256_encryption_oid,- ASN1::ecdsa_with_sha384_encryption_oid,- ASN1::ecdsa_with_sha512_encryption_oid,+ constexpr static Array<Span<u32 const>, 10> no_parameter_algorithms = {ASN1::x25519_oid,ASN1::x448_oid,ASN1::ed25519_oid,@@ -151,7 +110,6 @@ static ErrorOr<AlgorithmIdentifier> parse_algorithm_identifier(ASN1::Decoder& deASN1::ml_dsa_44_oid,ASN1::ml_dsa_65_oid,ASN1::ml_dsa_87_oid,- ASN1::ed448_oid,ASN1::ml_kem_512_oid,ASN1::ml_kem_768_oid,ASN1::ml_kem_1024_oid@@ -250,7 +208,7 @@ ErrorOr<SubjectPublicKey> parse_subject_public_key_info(ASN1::Decoder& decoder,// https://datatracker.ietf.org/doc/html/draft-ietf-lamps-kyber-certificates-07#section-3-6// The parameters field of the AlgorithmIdentifier for the ML-KEM public key MUST be absent.- constexpr static Array<Span<u32 const>, 12> no_parameter_algorithms = {+ constexpr static Array<Span<u32 const>, 11> no_parameter_algorithms = {ASN1::ec_public_key_encryption_oid,ASN1::x25519_oid,ASN1::x448_oid,@@ -259,7 +217,6 @@ ErrorOr<SubjectPublicKey> parse_subject_public_key_info(ASN1::Decoder& decoder,ASN1::ml_dsa_44_oid,ASN1::ml_dsa_65_oid,ASN1::ml_dsa_87_oid,- ASN1::ed448_oid,ASN1::ml_kem_512_oid,ASN1::ml_kem_768_oid,ASN1::ml_kem_1024_oid@@ -400,7 +357,7 @@ ErrorOr<PrivateKey> parse_private_key_info(ASN1::Decoder& decoder, Vector<String// https://datatracker.ietf.org/doc/html/draft-ietf-lamps-kyber-certificates-07#section-3-6// The parameters field of the AlgorithmIdentifier for the ML-KEM public key MUST be absent.- constexpr static Array<Span<u32 const>, 12> no_parameter_algorithms = {+ constexpr static Array<Span<u32 const>, 11> no_parameter_algorithms = {ASN1::ec_public_key_encryption_oid,ASN1::x25519_oid,ASN1::x448_oid,@@ -409,7 +366,6 @@ ErrorOr<PrivateKey> parse_private_key_info(ASN1::Decoder& decoder, Vector<StringASN1::ml_dsa_44_oid,ASN1::ml_dsa_65_oid,ASN1::ml_dsa_87_oid,- ASN1::ed448_oid,ASN1::ml_kem_512_oid,ASN1::ml_kem_768_oid,ASN1::ml_kem_1024_oid