1# This file is dual licensed under the terms of the Apache License, Version
2# 2.0, and the BSD License. See the LICENSE file in the root of this repository
3# for complete details.
4
5from __future__ import annotations
6
7from cryptography.hazmat.bindings._rust import (
8 ObjectIdentifier as ObjectIdentifier,
9)
10from cryptography.hazmat.primitives import hashes
11
12
13class ExtensionOID:
14 SUBJECT_DIRECTORY_ATTRIBUTES = ObjectIdentifier("2.5.29.9")
15 SUBJECT_KEY_IDENTIFIER = ObjectIdentifier("2.5.29.14")
16 KEY_USAGE = ObjectIdentifier("2.5.29.15")
17 SUBJECT_ALTERNATIVE_NAME = ObjectIdentifier("2.5.29.17")
18 ISSUER_ALTERNATIVE_NAME = ObjectIdentifier("2.5.29.18")
19 BASIC_CONSTRAINTS = ObjectIdentifier("2.5.29.19")
20 NAME_CONSTRAINTS = ObjectIdentifier("2.5.29.30")
21 CRL_DISTRIBUTION_POINTS = ObjectIdentifier("2.5.29.31")
22 CERTIFICATE_POLICIES = ObjectIdentifier("2.5.29.32")
23 POLICY_MAPPINGS = ObjectIdentifier("2.5.29.33")
24 AUTHORITY_KEY_IDENTIFIER = ObjectIdentifier("2.5.29.35")
25 POLICY_CONSTRAINTS = ObjectIdentifier("2.5.29.36")
26 EXTENDED_KEY_USAGE = ObjectIdentifier("2.5.29.37")
27 FRESHEST_CRL = ObjectIdentifier("2.5.29.46")
28 INHIBIT_ANY_POLICY = ObjectIdentifier("2.5.29.54")
29 ISSUING_DISTRIBUTION_POINT = ObjectIdentifier("2.5.29.28")
30 AUTHORITY_INFORMATION_ACCESS = ObjectIdentifier("1.3.6.1.5.5.7.1.1")
31 SUBJECT_INFORMATION_ACCESS = ObjectIdentifier("1.3.6.1.5.5.7.1.11")
32 OCSP_NO_CHECK = ObjectIdentifier("1.3.6.1.5.5.7.48.1.5")
33 TLS_FEATURE = ObjectIdentifier("1.3.6.1.5.5.7.1.24")
34 CRL_NUMBER = ObjectIdentifier("2.5.29.20")
35 DELTA_CRL_INDICATOR = ObjectIdentifier("2.5.29.27")
36 PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS = ObjectIdentifier(
37 "1.3.6.1.4.1.11129.2.4.2"
38 )
39 PRECERT_POISON = ObjectIdentifier("1.3.6.1.4.1.11129.2.4.3")
40 SIGNED_CERTIFICATE_TIMESTAMPS = ObjectIdentifier("1.3.6.1.4.1.11129.2.4.5")
41 MS_CERTIFICATE_TEMPLATE = ObjectIdentifier("1.3.6.1.4.1.311.21.7")
42
43
44class OCSPExtensionOID:
45 NONCE = ObjectIdentifier("1.3.6.1.5.5.7.48.1.2")
46 ACCEPTABLE_RESPONSES = ObjectIdentifier("1.3.6.1.5.5.7.48.1.4")
47
48
49class CRLEntryExtensionOID:
50 CERTIFICATE_ISSUER = ObjectIdentifier("2.5.29.29")
51 CRL_REASON = ObjectIdentifier("2.5.29.21")
52 INVALIDITY_DATE = ObjectIdentifier("2.5.29.24")
53
54
55class NameOID:
56 COMMON_NAME = ObjectIdentifier("2.5.4.3")
57 COUNTRY_NAME = ObjectIdentifier("2.5.4.6")
58 LOCALITY_NAME = ObjectIdentifier("2.5.4.7")
59 STATE_OR_PROVINCE_NAME = ObjectIdentifier("2.5.4.8")
60 STREET_ADDRESS = ObjectIdentifier("2.5.4.9")
61 ORGANIZATION_IDENTIFIER = ObjectIdentifier("2.5.4.97")
62 ORGANIZATION_NAME = ObjectIdentifier("2.5.4.10")
63 ORGANIZATIONAL_UNIT_NAME = ObjectIdentifier("2.5.4.11")
64 SERIAL_NUMBER = ObjectIdentifier("2.5.4.5")
65 SURNAME = ObjectIdentifier("2.5.4.4")
66 GIVEN_NAME = ObjectIdentifier("2.5.4.42")
67 TITLE = ObjectIdentifier("2.5.4.12")
68 INITIALS = ObjectIdentifier("2.5.4.43")
69 GENERATION_QUALIFIER = ObjectIdentifier("2.5.4.44")
70 X500_UNIQUE_IDENTIFIER = ObjectIdentifier("2.5.4.45")
71 DN_QUALIFIER = ObjectIdentifier("2.5.4.46")
72 PSEUDONYM = ObjectIdentifier("2.5.4.65")
73 USER_ID = ObjectIdentifier("0.9.2342.19200300.100.1.1")
74 DOMAIN_COMPONENT = ObjectIdentifier("0.9.2342.19200300.100.1.25")
75 EMAIL_ADDRESS = ObjectIdentifier("1.2.840.113549.1.9.1")
76 JURISDICTION_COUNTRY_NAME = ObjectIdentifier("1.3.6.1.4.1.311.60.2.1.3")
77 JURISDICTION_LOCALITY_NAME = ObjectIdentifier("1.3.6.1.4.1.311.60.2.1.1")
78 JURISDICTION_STATE_OR_PROVINCE_NAME = ObjectIdentifier(
79 "1.3.6.1.4.1.311.60.2.1.2"
80 )
81 BUSINESS_CATEGORY = ObjectIdentifier("2.5.4.15")
82 POSTAL_ADDRESS = ObjectIdentifier("2.5.4.16")
83 POSTAL_CODE = ObjectIdentifier("2.5.4.17")
84 INN = ObjectIdentifier("1.2.643.3.131.1.1")
85 OGRN = ObjectIdentifier("1.2.643.100.1")
86 SNILS = ObjectIdentifier("1.2.643.100.3")
87 UNSTRUCTURED_NAME = ObjectIdentifier("1.2.840.113549.1.9.2")
88
89
90class SignatureAlgorithmOID:
91 RSA_WITH_MD5 = ObjectIdentifier("1.2.840.113549.1.1.4")
92 RSA_WITH_SHA1 = ObjectIdentifier("1.2.840.113549.1.1.5")
93 # This is an alternate OID for RSA with SHA1 that is occasionally seen
94 _RSA_WITH_SHA1 = ObjectIdentifier("1.3.14.3.2.29")
95 RSA_WITH_SHA224 = ObjectIdentifier("1.2.840.113549.1.1.14")
96 RSA_WITH_SHA256 = ObjectIdentifier("1.2.840.113549.1.1.11")
97 RSA_WITH_SHA384 = ObjectIdentifier("1.2.840.113549.1.1.12")
98 RSA_WITH_SHA512 = ObjectIdentifier("1.2.840.113549.1.1.13")
99 RSA_WITH_SHA3_224 = ObjectIdentifier("2.16.840.1.101.3.4.3.13")
100 RSA_WITH_SHA3_256 = ObjectIdentifier("2.16.840.1.101.3.4.3.14")
101 RSA_WITH_SHA3_384 = ObjectIdentifier("2.16.840.1.101.3.4.3.15")
102 RSA_WITH_SHA3_512 = ObjectIdentifier("2.16.840.1.101.3.4.3.16")
103 RSASSA_PSS = ObjectIdentifier("1.2.840.113549.1.1.10")
104 ECDSA_WITH_SHA1 = ObjectIdentifier("1.2.840.10045.4.1")
105 ECDSA_WITH_SHA224 = ObjectIdentifier("1.2.840.10045.4.3.1")
106 ECDSA_WITH_SHA256 = ObjectIdentifier("1.2.840.10045.4.3.2")
107 ECDSA_WITH_SHA384 = ObjectIdentifier("1.2.840.10045.4.3.3")
108 ECDSA_WITH_SHA512 = ObjectIdentifier("1.2.840.10045.4.3.4")
109 ECDSA_WITH_SHA3_224 = ObjectIdentifier("2.16.840.1.101.3.4.3.9")
110 ECDSA_WITH_SHA3_256 = ObjectIdentifier("2.16.840.1.101.3.4.3.10")
111 ECDSA_WITH_SHA3_384 = ObjectIdentifier("2.16.840.1.101.3.4.3.11")
112 ECDSA_WITH_SHA3_512 = ObjectIdentifier("2.16.840.1.101.3.4.3.12")
113 DSA_WITH_SHA1 = ObjectIdentifier("1.2.840.10040.4.3")
114 DSA_WITH_SHA224 = ObjectIdentifier("2.16.840.1.101.3.4.3.1")
115 DSA_WITH_SHA256 = ObjectIdentifier("2.16.840.1.101.3.4.3.2")
116 DSA_WITH_SHA384 = ObjectIdentifier("2.16.840.1.101.3.4.3.3")
117 DSA_WITH_SHA512 = ObjectIdentifier("2.16.840.1.101.3.4.3.4")
118 ED25519 = ObjectIdentifier("1.3.101.112")
119 ED448 = ObjectIdentifier("1.3.101.113")
120 GOSTR3411_94_WITH_3410_2001 = ObjectIdentifier("1.2.643.2.2.3")
121 GOSTR3410_2012_WITH_3411_2012_256 = ObjectIdentifier("1.2.643.7.1.1.3.2")
122 GOSTR3410_2012_WITH_3411_2012_512 = ObjectIdentifier("1.2.643.7.1.1.3.3")
123
124
125_SIG_OIDS_TO_HASH: dict[ObjectIdentifier, hashes.HashAlgorithm | None] = {
126 SignatureAlgorithmOID.RSA_WITH_MD5: hashes.MD5(),
127 SignatureAlgorithmOID.RSA_WITH_SHA1: hashes.SHA1(),
128 SignatureAlgorithmOID._RSA_WITH_SHA1: hashes.SHA1(),
129 SignatureAlgorithmOID.RSA_WITH_SHA224: hashes.SHA224(),
130 SignatureAlgorithmOID.RSA_WITH_SHA256: hashes.SHA256(),
131 SignatureAlgorithmOID.RSA_WITH_SHA384: hashes.SHA384(),
132 SignatureAlgorithmOID.RSA_WITH_SHA512: hashes.SHA512(),
133 SignatureAlgorithmOID.RSA_WITH_SHA3_224: hashes.SHA3_224(),
134 SignatureAlgorithmOID.RSA_WITH_SHA3_256: hashes.SHA3_256(),
135 SignatureAlgorithmOID.RSA_WITH_SHA3_384: hashes.SHA3_384(),
136 SignatureAlgorithmOID.RSA_WITH_SHA3_512: hashes.SHA3_512(),
137 SignatureAlgorithmOID.ECDSA_WITH_SHA1: hashes.SHA1(),
138 SignatureAlgorithmOID.ECDSA_WITH_SHA224: hashes.SHA224(),
139 SignatureAlgorithmOID.ECDSA_WITH_SHA256: hashes.SHA256(),
140 SignatureAlgorithmOID.ECDSA_WITH_SHA384: hashes.SHA384(),
141 SignatureAlgorithmOID.ECDSA_WITH_SHA512: hashes.SHA512(),
142 SignatureAlgorithmOID.ECDSA_WITH_SHA3_224: hashes.SHA3_224(),
143 SignatureAlgorithmOID.ECDSA_WITH_SHA3_256: hashes.SHA3_256(),
144 SignatureAlgorithmOID.ECDSA_WITH_SHA3_384: hashes.SHA3_384(),
145 SignatureAlgorithmOID.ECDSA_WITH_SHA3_512: hashes.SHA3_512(),
146 SignatureAlgorithmOID.DSA_WITH_SHA1: hashes.SHA1(),
147 SignatureAlgorithmOID.DSA_WITH_SHA224: hashes.SHA224(),
148 SignatureAlgorithmOID.DSA_WITH_SHA256: hashes.SHA256(),
149 SignatureAlgorithmOID.ED25519: None,
150 SignatureAlgorithmOID.ED448: None,
151 SignatureAlgorithmOID.GOSTR3411_94_WITH_3410_2001: None,
152 SignatureAlgorithmOID.GOSTR3410_2012_WITH_3411_2012_256: None,
153 SignatureAlgorithmOID.GOSTR3410_2012_WITH_3411_2012_512: None,
154}
155
156
157class PublicKeyAlgorithmOID:
158 DSA = ObjectIdentifier("1.2.840.10040.4.1")
159 EC_PUBLIC_KEY = ObjectIdentifier("1.2.840.10045.2.1")
160 RSAES_PKCS1_v1_5 = ObjectIdentifier("1.2.840.113549.1.1.1")
161 RSASSA_PSS = ObjectIdentifier("1.2.840.113549.1.1.10")
162 X25519 = ObjectIdentifier("1.3.101.110")
163 X448 = ObjectIdentifier("1.3.101.111")
164 ED25519 = ObjectIdentifier("1.3.101.112")
165 ED448 = ObjectIdentifier("1.3.101.113")
166
167
168class ExtendedKeyUsageOID:
169 SERVER_AUTH = ObjectIdentifier("1.3.6.1.5.5.7.3.1")
170 CLIENT_AUTH = ObjectIdentifier("1.3.6.1.5.5.7.3.2")
171 CODE_SIGNING = ObjectIdentifier("1.3.6.1.5.5.7.3.3")
172 EMAIL_PROTECTION = ObjectIdentifier("1.3.6.1.5.5.7.3.4")
173 TIME_STAMPING = ObjectIdentifier("1.3.6.1.5.5.7.3.8")
174 OCSP_SIGNING = ObjectIdentifier("1.3.6.1.5.5.7.3.9")
175 ANY_EXTENDED_KEY_USAGE = ObjectIdentifier("2.5.29.37.0")
176 SMARTCARD_LOGON = ObjectIdentifier("1.3.6.1.4.1.311.20.2.2")
177 KERBEROS_PKINIT_KDC = ObjectIdentifier("1.3.6.1.5.2.3.5")
178 IPSEC_IKE = ObjectIdentifier("1.3.6.1.5.5.7.3.17")
179 CERTIFICATE_TRANSPARENCY = ObjectIdentifier("1.3.6.1.4.1.11129.2.4.4")
180
181
182class AuthorityInformationAccessOID:
183 CA_ISSUERS = ObjectIdentifier("1.3.6.1.5.5.7.48.2")
184 OCSP = ObjectIdentifier("1.3.6.1.5.5.7.48.1")
185
186
187class SubjectInformationAccessOID:
188 CA_REPOSITORY = ObjectIdentifier("1.3.6.1.5.5.7.48.5")
189
190
191class CertificatePoliciesOID:
192 CPS_QUALIFIER = ObjectIdentifier("1.3.6.1.5.5.7.2.1")
193 CPS_USER_NOTICE = ObjectIdentifier("1.3.6.1.5.5.7.2.2")
194 ANY_POLICY = ObjectIdentifier("2.5.29.32.0")
195
196
197class AttributeOID:
198 CHALLENGE_PASSWORD = ObjectIdentifier("1.2.840.113549.1.9.7")
199 UNSTRUCTURED_NAME = ObjectIdentifier("1.2.840.113549.1.9.2")
200
201
202_OID_NAMES = {
203 NameOID.COMMON_NAME: "commonName",
204 NameOID.COUNTRY_NAME: "countryName",
205 NameOID.LOCALITY_NAME: "localityName",
206 NameOID.STATE_OR_PROVINCE_NAME: "stateOrProvinceName",
207 NameOID.STREET_ADDRESS: "streetAddress",
208 NameOID.ORGANIZATION_NAME: "organizationName",
209 NameOID.ORGANIZATIONAL_UNIT_NAME: "organizationalUnitName",
210 NameOID.SERIAL_NUMBER: "serialNumber",
211 NameOID.SURNAME: "surname",
212 NameOID.GIVEN_NAME: "givenName",
213 NameOID.TITLE: "title",
214 NameOID.GENERATION_QUALIFIER: "generationQualifier",
215 NameOID.X500_UNIQUE_IDENTIFIER: "x500UniqueIdentifier",
216 NameOID.DN_QUALIFIER: "dnQualifier",
217 NameOID.PSEUDONYM: "pseudonym",
218 NameOID.USER_ID: "userID",
219 NameOID.DOMAIN_COMPONENT: "domainComponent",
220 NameOID.EMAIL_ADDRESS: "emailAddress",
221 NameOID.JURISDICTION_COUNTRY_NAME: "jurisdictionCountryName",
222 NameOID.JURISDICTION_LOCALITY_NAME: "jurisdictionLocalityName",
223 NameOID.JURISDICTION_STATE_OR_PROVINCE_NAME: (
224 "jurisdictionStateOrProvinceName"
225 ),
226 NameOID.BUSINESS_CATEGORY: "businessCategory",
227 NameOID.POSTAL_ADDRESS: "postalAddress",
228 NameOID.POSTAL_CODE: "postalCode",
229 NameOID.INN: "INN",
230 NameOID.OGRN: "OGRN",
231 NameOID.SNILS: "SNILS",
232 NameOID.UNSTRUCTURED_NAME: "unstructuredName",
233 SignatureAlgorithmOID.RSA_WITH_MD5: "md5WithRSAEncryption",
234 SignatureAlgorithmOID.RSA_WITH_SHA1: "sha1WithRSAEncryption",
235 SignatureAlgorithmOID.RSA_WITH_SHA224: "sha224WithRSAEncryption",
236 SignatureAlgorithmOID.RSA_WITH_SHA256: "sha256WithRSAEncryption",
237 SignatureAlgorithmOID.RSA_WITH_SHA384: "sha384WithRSAEncryption",
238 SignatureAlgorithmOID.RSA_WITH_SHA512: "sha512WithRSAEncryption",
239 SignatureAlgorithmOID.RSASSA_PSS: "RSASSA-PSS",
240 SignatureAlgorithmOID.ECDSA_WITH_SHA1: "ecdsa-with-SHA1",
241 SignatureAlgorithmOID.ECDSA_WITH_SHA224: "ecdsa-with-SHA224",
242 SignatureAlgorithmOID.ECDSA_WITH_SHA256: "ecdsa-with-SHA256",
243 SignatureAlgorithmOID.ECDSA_WITH_SHA384: "ecdsa-with-SHA384",
244 SignatureAlgorithmOID.ECDSA_WITH_SHA512: "ecdsa-with-SHA512",
245 SignatureAlgorithmOID.DSA_WITH_SHA1: "dsa-with-sha1",
246 SignatureAlgorithmOID.DSA_WITH_SHA224: "dsa-with-sha224",
247 SignatureAlgorithmOID.DSA_WITH_SHA256: "dsa-with-sha256",
248 SignatureAlgorithmOID.ED25519: "ed25519",
249 SignatureAlgorithmOID.ED448: "ed448",
250 SignatureAlgorithmOID.GOSTR3411_94_WITH_3410_2001: (
251 "GOST R 34.11-94 with GOST R 34.10-2001"
252 ),
253 SignatureAlgorithmOID.GOSTR3410_2012_WITH_3411_2012_256: (
254 "GOST R 34.10-2012 with GOST R 34.11-2012 (256 bit)"
255 ),
256 SignatureAlgorithmOID.GOSTR3410_2012_WITH_3411_2012_512: (
257 "GOST R 34.10-2012 with GOST R 34.11-2012 (512 bit)"
258 ),
259 PublicKeyAlgorithmOID.DSA: "dsaEncryption",
260 PublicKeyAlgorithmOID.EC_PUBLIC_KEY: "id-ecPublicKey",
261 PublicKeyAlgorithmOID.RSAES_PKCS1_v1_5: "rsaEncryption",
262 PublicKeyAlgorithmOID.RSASSA_PSS: "rsassaPss",
263 PublicKeyAlgorithmOID.X25519: "X25519",
264 PublicKeyAlgorithmOID.X448: "X448",
265 ExtendedKeyUsageOID.SERVER_AUTH: "serverAuth",
266 ExtendedKeyUsageOID.CLIENT_AUTH: "clientAuth",
267 ExtendedKeyUsageOID.CODE_SIGNING: "codeSigning",
268 ExtendedKeyUsageOID.EMAIL_PROTECTION: "emailProtection",
269 ExtendedKeyUsageOID.TIME_STAMPING: "timeStamping",
270 ExtendedKeyUsageOID.OCSP_SIGNING: "OCSPSigning",
271 ExtendedKeyUsageOID.SMARTCARD_LOGON: "msSmartcardLogin",
272 ExtendedKeyUsageOID.KERBEROS_PKINIT_KDC: "pkInitKDC",
273 ExtensionOID.SUBJECT_DIRECTORY_ATTRIBUTES: "subjectDirectoryAttributes",
274 ExtensionOID.SUBJECT_KEY_IDENTIFIER: "subjectKeyIdentifier",
275 ExtensionOID.KEY_USAGE: "keyUsage",
276 ExtensionOID.SUBJECT_ALTERNATIVE_NAME: "subjectAltName",
277 ExtensionOID.ISSUER_ALTERNATIVE_NAME: "issuerAltName",
278 ExtensionOID.BASIC_CONSTRAINTS: "basicConstraints",
279 ExtensionOID.PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS: (
280 "signedCertificateTimestampList"
281 ),
282 ExtensionOID.SIGNED_CERTIFICATE_TIMESTAMPS: (
283 "signedCertificateTimestampList"
284 ),
285 ExtensionOID.PRECERT_POISON: "ctPoison",
286 ExtensionOID.MS_CERTIFICATE_TEMPLATE: "msCertificateTemplate",
287 CRLEntryExtensionOID.CRL_REASON: "cRLReason",
288 CRLEntryExtensionOID.INVALIDITY_DATE: "invalidityDate",
289 CRLEntryExtensionOID.CERTIFICATE_ISSUER: "certificateIssuer",
290 ExtensionOID.NAME_CONSTRAINTS: "nameConstraints",
291 ExtensionOID.CRL_DISTRIBUTION_POINTS: "cRLDistributionPoints",
292 ExtensionOID.CERTIFICATE_POLICIES: "certificatePolicies",
293 ExtensionOID.POLICY_MAPPINGS: "policyMappings",
294 ExtensionOID.AUTHORITY_KEY_IDENTIFIER: "authorityKeyIdentifier",
295 ExtensionOID.POLICY_CONSTRAINTS: "policyConstraints",
296 ExtensionOID.EXTENDED_KEY_USAGE: "extendedKeyUsage",
297 ExtensionOID.FRESHEST_CRL: "freshestCRL",
298 ExtensionOID.INHIBIT_ANY_POLICY: "inhibitAnyPolicy",
299 ExtensionOID.ISSUING_DISTRIBUTION_POINT: "issuingDistributionPoint",
300 ExtensionOID.AUTHORITY_INFORMATION_ACCESS: "authorityInfoAccess",
301 ExtensionOID.SUBJECT_INFORMATION_ACCESS: "subjectInfoAccess",
302 ExtensionOID.OCSP_NO_CHECK: "OCSPNoCheck",
303 ExtensionOID.CRL_NUMBER: "cRLNumber",
304 ExtensionOID.DELTA_CRL_INDICATOR: "deltaCRLIndicator",
305 ExtensionOID.TLS_FEATURE: "TLSFeature",
306 AuthorityInformationAccessOID.OCSP: "OCSP",
307 AuthorityInformationAccessOID.CA_ISSUERS: "caIssuers",
308 SubjectInformationAccessOID.CA_REPOSITORY: "caRepository",
309 CertificatePoliciesOID.CPS_QUALIFIER: "id-qt-cps",
310 CertificatePoliciesOID.CPS_USER_NOTICE: "id-qt-unotice",
311 OCSPExtensionOID.NONCE: "OCSPNonce",
312 AttributeOID.CHALLENGE_PASSWORD: "challengePassword",
313}