// SPDX-License-Identifier: GPL-3.0-only // Copyright (c) 2022, Sylvain Huet, Ambermind // Minimacy (r) System // https://datatracker.ietf.org/doc/html/rfc1779 A String Representation of Distinguished Names // https://datatracker.ietf.org/doc/html/rfc2985 PKCS #9: Selected Object Classes and Attribute Types const OID_userId="0.9.2342.19200300.100.1.1";; const OID_ecPublicKey="1.2.840.10045.2.1";; const OID_prime256v1="1.2.840.10045.3.1.7";; // aka secp256r1 const OID_ecdsa_with_SHA256="1.2.840.10045.4.3.2";; const OID_ecdsa_with_SHA384="1.2.840.10045.4.3.3";; const OID_rsaEncryption="1.2.840.113549.1.1.1";; const OID_RSA_PKCS1_SHA1="1.2.840.113549.1.1.5";; const OID_RSA_PKCS1_SHA256="1.2.840.113549.1.1.11";; const OID_RSA_PKCS1_SHA384="1.2.840.113549.1.1.12";; const OID_RSA_PKCS1_SHA512="1.2.840.113549.1.1.13";; const OID_PBKDF2="1.2.840.113549.1.5.12";; const OID_PBES2="1.2.840.113549.1.5.13";; const OID_emailAddress="1.2.840.113549.1.9.1";; const OID_id_ExtensionReq="1.2.840.113549.1.9.14";; const OID_hmacWithSHA256="1.2.840.113549.2.9";; const OID_des_ede3_cbc="1.2.840.113549.3.7";; const OID_jurisdictionOfIncorporationStateOrProvinceName="1.3.6.1.4.1.311.60.2.1.2";; const OID_jurisdictionOfIncorporationCountryName="1.3.6.1.4.1.311.60.2.1.3";; const OID_signedCertificateTimestampList="1.3.6.1.4.1.11129.2.4.2";; const OID_LetsEncrypt="1.3.6.1.4.1.44947.1.1.1";; const OID_authorityInfoAccess="1.3.6.1.5.5.7.1.1";; const OID_cps="1.3.6.1.5.5.7.2.1";; const OID_unotice="1.3.6.1.5.5.7.2.2";; const OID_serverAuth="1.3.6.1.5.5.7.3.1";; const OID_clientAuth="1.3.6.1.5.5.7.3.2";; const OID_codeSigning="1.3.6.1.5.5.7.3.3";; const OID_id_ad_ocsp="1.3.6.1.5.5.7.48.1";; const OID_caIssuers="1.3.6.1.5.5.7.48.2";; const OID_DES_CBC="1.3.36.3.1.1.2";; const OID_DES_3CBC="1.3.36.3.1.3.2";; const OID_x25519="1.3.101.110";; const OID_ed25519="1.3.101.112";; const OID_secp256k1="1.3.132.0.10";; const OID_secp384r1="1.3.132.0.34";; const OID_secp521r1="1.3.132.0.35";; const OID_CN="2.5.4.3";; const OID_serialNumber="2.5.4.5";; const OID_C="2.5.4.6";; const OID_L="2.5.4.7";; const OID_ST="2.5.4.8";; const OID_STREET="2.5.4.9";; const OID_O="2.5.4.10";; const OID_OU="2.5.4.11";; const OID_businessCategory="2.5.4.15";; const OID_subjectKeyIdentifier="2.5.29.14";; const OID_keyUsage="2.5.29.15";; const OID_subjectAltName="2.5.29.17";; const OID_basicConstraints="2.5.29.19";; const OID_cRLDistributionPoints="2.5.29.31";; const OID_certificatePolicies="2.5.29.32";; const OID_anyPolicy="2.5.29.32.0";; const OID_authorityKeyIdentifier="2.5.29.35";; const OID_extKeyUsage="2.5.29.37";; const OID_AES128_CBC="2.16.840.1.101.3.4.1.2";; const OID_AES192_CBC="2.16.840.1.101.3.4.1.22";; const OID_AES256_CBC="2.16.840.1.101.3.4.1.42";; const OID_ev_guidelines="2.23.140.1.1";; const OID_domain_validated="2.23.140.1.2.1";; const OID_organization_validated="2.23.140.1.2.2";; const OID_individual_validated="2.23.140.1.2.3";; const NiceOIDs= hashmapInit(6, [OID_userId, "userId"]:: [OID_ecPublicKey, "ecPublicKey"]:: [OID_prime256v1, "prime256v1"]:: [OID_ecdsa_with_SHA256, "ecdsa-with-SHA256"]:: [OID_ecdsa_with_SHA384, "ecdsa-with-SHA384"]:: [OID_rsaEncryption, "rsaEncryption"]:: [OID_RSA_PKCS1_SHA1, "RSA_PKCS1_SHA1"]:: [OID_RSA_PKCS1_SHA256, "RSA_PKCS1_SHA256"]:: [OID_RSA_PKCS1_SHA384, "RSA_PKCS1_SHA384"]:: [OID_RSA_PKCS1_SHA512, "RSA_PKCS1_SHA512"]:: [OID_PBKDF2, "PBKDF2"]:: [OID_PBES2, "PBES2"]:: [OID_emailAddress, "emailAddress"]:: [OID_id_ExtensionReq, "id_ExtensionReq"]:: [OID_hmacWithSHA256, "hmacWithSHA256"]:: [OID_des_ede3_cbc, "des-ede3-cbc"]:: [OID_jurisdictionOfIncorporationStateOrProvinceName, "jurisdictionOfIncorporationStateOrProvinceName"]:: [OID_jurisdictionOfIncorporationCountryName, "jurisdictionOfIncorporationCountryName"]:: [OID_signedCertificateTimestampList, "signedCertificateTimestampList"]:: [OID_LetsEncrypt, "LetsEncrypt"]:: [OID_authorityInfoAccess, "authorityInfoAccess"]:: [OID_cps, "cps"]:: [OID_unotice, "unotice"]:: [OID_serverAuth, "serverAuth"]:: [OID_clientAuth, "clientAuth"]:: [OID_codeSigning, "codeSigning"]:: [OID_id_ad_ocsp, "id_ad_ocsp"]:: [OID_caIssuers, "caIssuers"]:: [OID_secp256k1, "secp256k1"]:: [OID_secp384r1, "secp384r1"]:: [OID_secp521r1, "secp521r1"]:: [OID_DES_CBC, "DES_CBC"]:: [OID_DES_3CBC, "DES_3CBC"]:: [OID_x25519, "x25519"]:: [OID_ed25519, "ed25519"]:: [OID_CN, "CN"]:: [OID_serialNumber, "serialNumber"]:: [OID_C, "C"]:: [OID_L, "L"]:: [OID_ST, "ST"]:: [OID_STREET, "STREET"]:: [OID_O, "O"]:: [OID_OU, "OU"]:: [OID_businessCategory, "businessCategory"]:: [OID_subjectKeyIdentifier, "subjectKeyIdentifier"]:: [OID_keyUsage, "keyUsage"]:: [OID_subjectAltName, "subjectAltName"]:: [OID_basicConstraints, "basicConstraints"]:: [OID_cRLDistributionPoints, "cRLDistributionPoints"]:: [OID_certificatePolicies, "certificatePolicies"]:: [OID_anyPolicy, "anyPolicy"]:: [OID_authorityKeyIdentifier, "authorityKeyIdentifier"]:: [OID_extKeyUsage, "extKeyUsage"]:: [OID_AES128_CBC, "aes128-CBC"]:: [OID_AES192_CBC, "aes192-CBC"]:: [OID_AES256_CBC, "aes256-CBC"]:: [OID_ev_guidelines, "ev_guidelines"]:: [OID_domain_validated, "domain_validated"]:: [OID_organization_validated, "organization_validated"]:: [OID_individual_validated, "individual_validated"]:: nil);; const OIDprefix= ["1.3.6.1.4.1.", "enterprise", hashmapInit(6, [2, "IBM"]:: [9, "Cisco"]:: [63, "Apple Inc"]:: [311, "Microsoft"]:: [4146, "GlobalSign NV/SA"]:: [6449, "Comodo Technology Development Ltd"]:: [11129, "Google"]:: nil) ]:: ["2.16.840.1.", "US-Organization", hashmapInit(6, [113730, "Netscape Communications Corp."]:: [114412, "Digicert"]:: nil) ]:: ["1.2.840.", "ISO-US-Member", hashmapInit(6, [113635, "Apple"]:: nil) ]:: ["1.2.840.113549.1.9.", "pkcs9", nil]:: ["2.5.4.", "X500", nil]:: nil;; fun _prefixOID(prefixName, prefix, map, oid)= let strLength(prefix) -> start in let strCharPos(oid, '.', start) -> i in let if i==nil then strLength(oid) else i -> i in let intFromStr(strSlice(oid, start, i-start)) -> number in let hashmapGet(map, number) -> name in if name==nil then strFormat("[*].*", prefixName, strTail(oid, start)) else strFormat("[*]*", name, strTail(oid, i));; fun niceOID(oid)= let hashmapGet(NiceOIDs, oid) -> name in if name<>nil then name else ( for [prefix, prefixName, map] in OIDprefix do if strStartsWith(oid, prefix) then return _prefixOID(prefixName, prefix, map, oid); oid );; fun _oidVarUInt(bin, i)= if i(first::next) in strJoin(".", listMap((first/40)::(first%40)::next, lambda(a)=strFromInt(a)));; fun strFromOid(oid)= let listMap(strSplit(".", oid), lambda(a)=intFromStr(a)) ->(a::b::next) in strBuild(listMap((40*a+b)::next, lambda(x)=strVarUInt(x)));;