blob: a46c5d623238b9ab79104a9a8649990508f7991e [file] [log] [blame]
Alex Gaynor4af5b372015-07-12 10:30:59 -05001X.509 Reference
2===============
Paul Kehrer016e08a2014-11-26 09:41:18 -10003
Paul Kehrera9d78c12014-11-26 10:59:03 -10004.. currentmodule:: cryptography.x509
Paul Kehrer016e08a2014-11-26 09:41:18 -10005
Paul Kehrerd26c4db2015-03-15 15:36:24 -05006.. testsetup::
7
Erik Trauschkedc570402015-09-24 20:24:28 -07008 pem_crl_data = b"""
9 -----BEGIN X509 CRL-----
10 MIIBtDCBnQIBAjANBgkqhkiG9w0BAQsFADAnMQswCQYDVQQGEwJVUzEYMBYGA1UE
11 AwwPY3J5cHRvZ3JhcGh5LmlvGA8yMDE1MDEwMTAwMDAwMFoYDzIwMTYwMTAxMDAw
12 MDAwWjA+MDwCAQAYDzIwMTUwMTAxMDAwMDAwWjAmMBgGA1UdGAQRGA8yMDE1MDEw
13 MTAwMDAwMFowCgYDVR0VBAMKAQEwDQYJKoZIhvcNAQELBQADggEBABRA4ww50Lz5
14 zk1j2+aluC4HPHqb7o06h4pTDcCGeXUKXIGeP5ntGGmIoxa26sNoLeOr8+5b43Gf
15 yWraHertllOwaOpNFEe+YZFaE9femtoDbf+GLMvRx/0wDfd3KxPoXnXKMXb2d1w4
16 RCLgmkYx6JyvS+5ciuLQVIKC+l7jwIUeZFLJMUJ8msM4pFYoGameeZmtjMbd/TNg
17 cVBfmZxNMHuLladJxvSo2esARo0TYPhYsgrREKoHwhpzSxdynjn4bOVkILfguwsN
18 qtEEMZFEv5Kb0GqRp2+Iagv2S6dg9JGvxVdsoGjaB6EbYSZ3Psx4aODasIn11uwo
19 X4B9vUQNXqc=
20 -----END X509 CRL-----
21 """.strip()
22
Paul Kehrerd26c4db2015-03-15 15:36:24 -050023 pem_req_data = b"""
24 -----BEGIN CERTIFICATE REQUEST-----
Lucia Lic6ba99d2021-11-08 22:06:11 +080025 MIICcDCCAVgCAQAwDTELMAkGA1UEBhMCVVMwggEiMA0GCSqGSIb3DQEBAQUAA4IB
26 DwAwggEKAoIBAQCb+ec0zYAYLzk/MDdDJYvzdvEO2ZUrBYM6z1r8NedwpJfxUWqC
27 hvK1cpc9EbQeCwS1eooTIGoNveeCrwL+pWdmf1sh6gz7SsxdN/07nyhSM8M6Xkec
28 +tGrjyi1H/N1afwWXox3WcvBNbxu3Df5RKLDb0yt9aqhmJylbl/tbvgJesXymwmp
29 Rc1vXL0fOedUtuAJ3xQ15M0pgLF8qDn4lySJz25x76pMYPeN5/a7x+SR/jj81kep
30 VaVpuh/2hePV5uwUX3uWoj5sAkrBCifi4NPge0Npd6KeKVvXytLOymH/4+WvV719
31 wCO+MyrkhpdHSakJDTIaQIxsqVeVVKdPLAPJAgMBAAGgHjAcBgkqhkiG9w0BCQcx
32 DwwNY2hhbGxlbmdlIG1lITANBgkqhkiG9w0BAQsFAAOCAQEAMmgeSa8szbjPFD/4
33 vcPBr/vBEROFGgL8mX3o5pF9gpr7nRjhLKBkgJvlRm6Ma3Xvdfc/r5Hp2ZBTA7sZ
34 ZYhyeezGfCQN/Qhda1v+sCwG58IjvGfCSS7Y5tGlEBQ4MDf0Q7PYPSxaNUEBH7vo
35 +M7U+nFuNSmyWlt6SFBSkohZkWoVSGx3KsAO+SAHYZ7JtqsAS/dm7Dflp8KxeDg7
36 wzGBDQRpGF4CpI1VQjGSJQXSEdD+J7mtvBEOD34abRfV6zOUGzOOo3NWE6wNpYgt
37 0A7gVlzSYpdwqjBdvACfXR2r/mu+4KkAvYh8WwCiTcYgGjl2pT1bO4hEmcJ0RSWy
38 /fGD8Q==
Paul Kehrerd26c4db2015-03-15 15:36:24 -050039 -----END CERTIFICATE REQUEST-----
40 """.strip()
41
Paul Kehrerd3dafbd2015-03-15 16:24:18 -050042 pem_data = b"""
43 -----BEGIN CERTIFICATE-----
44 MIIDfDCCAmSgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJVUzEf
45 MB0GA1UEChMWVGVzdCBDZXJ0aWZpY2F0ZXMgMjAxMTEVMBMGA1UEAxMMVHJ1c3Qg
46 QW5jaG9yMB4XDTEwMDEwMTA4MzAwMFoXDTMwMTIzMTA4MzAwMFowQDELMAkGA1UE
47 BhMCVVMxHzAdBgNVBAoTFlRlc3QgQ2VydGlmaWNhdGVzIDIwMTExEDAOBgNVBAMT
48 B0dvb2QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCQWJpHYo37
49 Xfb7oJSPe+WvfTlzIG21WQ7MyMbGtK/m8mejCzR6c+f/pJhEH/OcDSMsXq8h5kXa
50 BGqWK+vSwD/Pzp5OYGptXmGPcthDtAwlrafkGOS4GqIJ8+k9XGKs+vQUXJKsOk47
51 RuzD6PZupq4s16xaLVqYbUC26UcY08GpnoLNHJZS/EmXw1ZZ3d4YZjNlpIpWFNHn
52 UGmdiGKXUPX/9H0fVjIAaQwjnGAbpgyCumWgzIwPpX+ElFOUr3z7BoVnFKhIXze+
53 VmQGSWxZxvWDUN90Ul0tLEpLgk3OVxUB4VUGuf15OJOpgo1xibINPmWt14Vda2N9
54 yrNKloJGZNqLAgMBAAGjfDB6MB8GA1UdIwQYMBaAFOR9X9FclYYILAWuvnW2ZafZ
55 XahmMB0GA1UdDgQWBBRYAYQkG7wrUpRKPaUQchRR9a86yTAOBgNVHQ8BAf8EBAMC
56 AQYwFwYDVR0gBBAwDjAMBgpghkgBZQMCATABMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
57 KoZIhvcNAQELBQADggEBADWHlxbmdTXNwBL/llwhQqwnazK7CC2WsXBBqgNPWj7m
58 tvQ+aLG8/50Qc2Sun7o2VnwF9D18UUe8Gj3uPUYH+oSI1vDdyKcjmMbKRU4rk0eo
59 3UHNDXwqIVc9CQS9smyV+x1HCwL4TTrq+LXLKx/qVij0Yqk+UJfAtrg2jnYKXsCu
60 FMBQQnWCGrwa1g1TphRp/RmYHnMynYFmZrXtzFz+U9XEA7C+gPq4kqDI/iVfIT1s
61 6lBtdB50lrDVwl2oYfAvW/6sC2se2QleZidUmrziVNP4oEeXINokU6T6p//HM1FG
62 QYw2jOvpKcKtWCSAnegEbgsGYzATKjmPJPJ0npHFqzM=
63 -----END CERTIFICATE-----
64 """.strip()
65
Paul Kehrer93ae8052015-05-02 23:18:09 -050066 cryptography_cert_pem = b"""
67 -----BEGIN CERTIFICATE-----
68 MIIFvTCCBKWgAwIBAgICPyAwDQYJKoZIhvcNAQELBQAwRzELMAkGA1UEBhMCVVMx
69 FjAUBgNVBAoTDUdlb1RydXN0IEluYy4xIDAeBgNVBAMTF1JhcGlkU1NMIFNIQTI1
70 NiBDQSAtIEczMB4XDTE0MTAxNTEyMDkzMloXDTE4MTExNjAxMTUwM1owgZcxEzAR
71 BgNVBAsTCkdUNDg3NDI5NjUxMTAvBgNVBAsTKFNlZSB3d3cucmFwaWRzc2wuY29t
72 L3Jlc291cmNlcy9jcHMgKGMpMTQxLzAtBgNVBAsTJkRvbWFpbiBDb250cm9sIFZh
73 bGlkYXRlZCAtIFJhcGlkU1NMKFIpMRwwGgYDVQQDExN3d3cuY3J5cHRvZ3JhcGh5
74 LmlvMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAom/FebKJIot7Sp3s
75 itG1sicpe3thCssjI+g1JDAS7I3GLVNmbms1DOdIIqwf01gZkzzXBN2+9sOnyRaR
76 PPfCe1jTr3dk2y6rPE559vPa1nZQkhlzlhMhlPyjaT+S7g4Tio4qV2sCBZU01DZJ
77 CaksfohN+5BNVWoJzTbOcrHOEJ+M8B484KlBCiSxqf9cyNQKru4W3bHaCVNVJ8eu
78 6i6KyhzLa0L7yK3LXwwXVs583C0/vwFhccGWsFODqD/9xHUzsBIshE8HKjdjDi7Y
79 3BFQzVUQFjBB50NSZfAA/jcdt1blxJouc7z9T8Oklh+V5DDBowgAsrT4b6Z2Fq6/
80 r7D1GqivLK/ypUQmxq2WXWAUBb/Q6xHgxASxI4Br+CByIUQJsm8L2jzc7k+mF4hW
81 ltAIUkbo8fGiVnat0505YJgxWEDKOLc4Gda6d/7GVd5AvKrz242bUqeaWo6e4MTx
82 diku2Ma3rhdcr044Qvfh9hGyjqNjvhWY/I+VRWgihU7JrYvgwFdJqsQ5eiKT4OHi
83 gsejvWwkZzDtiQ+aQTrzM1FsY2swJBJsLSX4ofohlVRlIJCn/ME+XErj553431Lu
84 YQ5SzMd3nXzN78Vj6qzTfMUUY72UoT1/AcFiUMobgIqrrmwuNxfrkbVE2b6Bga74
85 FsJX63prvrJ41kuHK/16RQBM7fcCAwEAAaOCAWAwggFcMB8GA1UdIwQYMBaAFMOc
86 8/zTRgg0u85Gf6B8W/PiCMtZMFcGCCsGAQUFBwEBBEswSTAfBggrBgEFBQcwAYYT
87 aHR0cDovL2d2LnN5bWNkLmNvbTAmBggrBgEFBQcwAoYaaHR0cDovL2d2LnN5bWNi
88 LmNvbS9ndi5jcnQwDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUFBwMB
89 BggrBgEFBQcDAjAvBgNVHREEKDAmghN3d3cuY3J5cHRvZ3JhcGh5Lmlvgg9jcnlw
90 dG9ncmFwaHkuaW8wKwYDVR0fBCQwIjAgoB6gHIYaaHR0cDovL2d2LnN5bWNiLmNv
91 bS9ndi5jcmwwDAYDVR0TAQH/BAIwADBFBgNVHSAEPjA8MDoGCmCGSAGG+EUBBzYw
92 LDAqBggrBgEFBQcCARYeaHR0cHM6Ly93d3cucmFwaWRzc2wuY29tL2xlZ2FsMA0G
93 CSqGSIb3DQEBCwUAA4IBAQAzIYO2jx7h17FBT74tJ2zbV9OKqGb7QF8y3wUtP4xc
94 dH80vprI/Cfji8s86kr77aAvAqjDjaVjHn7UzebhSUivvRPmfzRgyWBacomnXTSt
95 Xlt2dp2nDQuwGyK2vB7dMfKnQAkxwq1sYUXznB8i0IhhCAoXp01QGPKq51YoIlnF
96 7DRMk6iEaL1SJbkIrLsCQyZFDf0xtfW9DqXugMMLoxeCsBhZJQzNyS2ryirrv9LH
97 aK3+6IZjrcyy9bkpz/gzJucyhU+75c4My/mnRCrtItRbCQuiI5pd5poDowm+HH9i
98 GVI9+0lAFwxOUnOnwsoI40iOoxjLMGB+CgFLKCGUcWxP
99 -----END CERTIFICATE-----
100 """.strip()
101
g_goessel16f746f2018-10-10 04:13:41 +0200102 pem_issuer_public_key = b"""
103 -----BEGIN RSA PUBLIC KEY-----
104 MIICCgKCAgEAyYcqyuT6oQxpvg/VSn2Zc68wZ823D0VAJ2woramFx+2KPWB7B7Ot
105 tVSNRfm0OxJOU3TFAoep54Z2wgOoz0zRmeW6/7gvIuBKp2TW0qZAt3l9sgpE29iw
106 CsoZQlMrLKiDPzCC6Fptk+YPSST9sqwhWDKK1QvOg68DKRxTpEek1hBpC0XRsnuX
107 fvJJQqP39vxzpA0PsicI/wrvWX3vO8z+j9+botPerbeamoeHCsc0xgTLyIygWysB
108 rNskxlzC2U4Kw6mQhGghlLReo1rFsO2/hLTnvLs+Y1lQhnFeOKCx1WVXhzBIyO9B
109 dVVH5Cinb5wBNKvxbevRf4icdWcwtknmgKf69xj7yvFjt/vft74BB1Y5ltLYFmEb
110 0JBxm5MAJfW4YnMQr0AxdjOhjHq4MN7X4ZzwEpJaYJdRmvMsMGN88cyjYPxsaOG+
111 dZ/E9MmTjh0gnTjyD4gmsvR/gtTR/XFJ2wkbnnL1RyxNi6j2UW8C7tpNv0TIuArx
112 3SHGPZN0WsaKTxZPb0L/ob1WBT0mhiq1GzB431cXgbxyh8EdKk+xSptA3V+ca2V2
113 NuXlJIJaOoPMj/qjDW4I/peKGnk9tLknJ0hpRzz11j77pJsV0dGoGKVHIR2oZqT5
114 0ZJJb5DXNbiTnspKLNmBt0YlNiXtlCIPxVUkhL141FuCLc8h6FjD6E0CAwEAAQ==
115 -----END RSA PUBLIC KEY-----
116 """.strip()
117
118 pem_data_to_check = b"""
119 -----BEGIN CERTIFICATE-----
120 MIIErjCCApagAwIBAgIUUrUZsZrrBmRD2hvRuspp+lPsZXcwDQYJKoZIhvcNAQEN
121 BQAwETEPMA0GA1UEAwwGSXNzdWVyMB4XDTE4MTAwODEzNDg1NFoXDTE4MTAxODEz
122 NDg1NFowETEPMA0GA1UEAwwGSXNzdWVyMIICIjANBgkqhkiG9w0BAQEFAAOCAg8A
123 MIICCgKCAgEAyYcqyuT6oQxpvg/VSn2Zc68wZ823D0VAJ2woramFx+2KPWB7B7Ot
124 tVSNRfm0OxJOU3TFAoep54Z2wgOoz0zRmeW6/7gvIuBKp2TW0qZAt3l9sgpE29iw
125 CsoZQlMrLKiDPzCC6Fptk+YPSST9sqwhWDKK1QvOg68DKRxTpEek1hBpC0XRsnuX
126 fvJJQqP39vxzpA0PsicI/wrvWX3vO8z+j9+botPerbeamoeHCsc0xgTLyIygWysB
127 rNskxlzC2U4Kw6mQhGghlLReo1rFsO2/hLTnvLs+Y1lQhnFeOKCx1WVXhzBIyO9B
128 dVVH5Cinb5wBNKvxbevRf4icdWcwtknmgKf69xj7yvFjt/vft74BB1Y5ltLYFmEb
129 0JBxm5MAJfW4YnMQr0AxdjOhjHq4MN7X4ZzwEpJaYJdRmvMsMGN88cyjYPxsaOG+
130 dZ/E9MmTjh0gnTjyD4gmsvR/gtTR/XFJ2wkbnnL1RyxNi6j2UW8C7tpNv0TIuArx
131 3SHGPZN0WsaKTxZPb0L/ob1WBT0mhiq1GzB431cXgbxyh8EdKk+xSptA3V+ca2V2
132 NuXlJIJaOoPMj/qjDW4I/peKGnk9tLknJ0hpRzz11j77pJsV0dGoGKVHIR2oZqT5
133 0ZJJb5DXNbiTnspKLNmBt0YlNiXtlCIPxVUkhL141FuCLc8h6FjD6E0CAwEAATAN
134 BgkqhkiG9w0BAQ0FAAOCAgEAVFzNKhEpkH8V8l0NEBAZHNi1e+lcg35fZZ9plqcw
135 Pvk+6M7LW0KD0QWYQWm/dJme4DFsM7lh5u4/m+H4yS7/RP9pads9YwBudchvGR1c
136 S4CCrRAmO8/A0vpQJcEwdS7fdYShBsqMrZ2TvzceVn2dvQbxB6pLkK7KIbDPVJA2
137 HXFFXe2npHmdc80iTz2ShbdVSvyPvk6vc6NFFCg6lSQFuif3vV0+aYqi6DXv4h92
138 9qAdES8ZLDfDulxyajyPbtF35f2Of99CumP5UzG4RQbvtI8gShuK1YFYe2sWJFE0
139 MgSsqGCbl5mcrWxm9YxysRKMZ+Hc4tnkvfmG6GsKtp8u/5pG11XgxXaQl4fZ7JNa
140 QFuD5gEXkEC1mCnhWlnguJgjQlpKadMOORmVTqG9dNQ6GEsha+XWpinm5L9fEZuA
141 F88nNyubKLwEl68N7WWWKQlIl4q8Pe5FEp1pd9rLjOW4gzgYBccIfBK3oMC7uFJg
142 a/9GeOKPiq90UMrCI+CAsIbzuPOaAp3g69JonuDwcs4cu8ui1udxs9q7ox3qSWGZ
143 G1U/hmwvZH9kfIv5BKIzNLy4oxXPDJ7MZIBsxVxaNv8KUQ/JLtpVJa3oYqEx18+V
144 JNr8Pr3y61X8pLmJnaCu+ixshiy2gjxXxDFBVEEt1G9JHrSs3R+yvcHxCrM3+ian
145 Nh4=
146 -----END CERTIFICATE-----
147 """.strip()
148
Paul Kehrerb2de9482014-12-11 14:54:48 -0600149Loading Certificates
150~~~~~~~~~~~~~~~~~~~~
Paul Kehrer016e08a2014-11-26 09:41:18 -1000151
Lucia Lic6ba99d2021-11-08 22:06:11 +0800152.. function:: load_pem_x509_certificate(data, backend=None)
Paul Kehrer016e08a2014-11-26 09:41:18 -1000153
154 .. versionadded:: 0.7
155
Paul Kehrere76cd272014-12-14 19:00:51 -0600156 Deserialize a certificate from PEM encoded data. PEM certificates are
157 base64 decoded and have delimiters that look like
158 ``-----BEGIN CERTIFICATE-----``.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000159
160 :param bytes data: The PEM encoded certificate data.
161
Lucia Lic6ba99d2021-11-08 22:06:11 +0800162 :param backend: An optional backend supporting the
Paul Kehrer016e08a2014-11-26 09:41:18 -1000163 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
164 interface.
165
Paul Kehrere76cd272014-12-14 19:00:51 -0600166 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000167
Alex Gaynor5ce14042016-05-29 13:13:46 -0400168 .. doctest::
169
170 >>> from cryptography import x509
Lucia Lic6ba99d2021-11-08 22:06:11 +0800171 >>> cert = x509.load_pem_x509_certificate(pem_data)
Chelsea Winfreee295f3a2016-06-02 21:15:54 -0700172 >>> cert.serial_number
Alex Gaynor5ce14042016-05-29 13:13:46 -0400173 2
174
Lucia Lic6ba99d2021-11-08 22:06:11 +0800175.. function:: load_der_x509_certificate(data, backend=None)
Paul Kehrer016e08a2014-11-26 09:41:18 -1000176
177 .. versionadded:: 0.7
178
Paul Kehrere76cd272014-12-14 19:00:51 -0600179 Deserialize a certificate from DER encoded data. DER is a binary format
Paul Kehrer92aac382014-12-15 16:25:28 -0600180 and is commonly found in files with the ``.cer`` extension (although file
181 extensions are not a guarantee of encoding type).
Paul Kehrer016e08a2014-11-26 09:41:18 -1000182
183 :param bytes data: The DER encoded certificate data.
184
Lucia Lic6ba99d2021-11-08 22:06:11 +0800185 :param backend: An optional backend supporting the
Paul Kehrer016e08a2014-11-26 09:41:18 -1000186 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
187 interface.
188
Paul Kehrere76cd272014-12-14 19:00:51 -0600189 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000190
Erik Trauschkedc570402015-09-24 20:24:28 -0700191Loading Certificate Revocation Lists
192~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
193
Lucia Lic6ba99d2021-11-08 22:06:11 +0800194.. function:: load_pem_x509_crl(data, backend=None)
Erik Trauschkedc570402015-09-24 20:24:28 -0700195
196 .. versionadded:: 1.1
197
198 Deserialize a certificate revocation list (CRL) from PEM encoded data. PEM
199 requests are base64 decoded and have delimiters that look like
Erik Trauschke32bbfe02015-10-21 08:04:55 -0700200 ``-----BEGIN X509 CRL-----``.
Erik Trauschkedc570402015-09-24 20:24:28 -0700201
202 :param bytes data: The PEM encoded request data.
203
Lucia Lic6ba99d2021-11-08 22:06:11 +0800204 :param backend: An optional backend supporting the
Erik Trauschkedc570402015-09-24 20:24:28 -0700205 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
206 interface.
207
208 :returns: An instance of
209 :class:`~cryptography.x509.CertificateRevocationList`.
210
Alex Gaynor5ce14042016-05-29 13:13:46 -0400211 .. doctest::
212
213 >>> from cryptography import x509
Alex Gaynor5ce14042016-05-29 13:13:46 -0400214 >>> from cryptography.hazmat.primitives import hashes
Lucia Lic6ba99d2021-11-08 22:06:11 +0800215 >>> crl = x509.load_pem_x509_crl(pem_crl_data)
Alex Gaynor5ce14042016-05-29 13:13:46 -0400216 >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256)
217 True
218
Lucia Lic6ba99d2021-11-08 22:06:11 +0800219.. function:: load_der_x509_crl(data, backend=None)
Erik Trauschkedc570402015-09-24 20:24:28 -0700220
221 .. versionadded:: 1.1
222
223 Deserialize a certificate revocation list (CRL) from DER encoded data. DER
224 is a binary format.
225
226 :param bytes data: The DER encoded request data.
227
Lucia Lic6ba99d2021-11-08 22:06:11 +0800228 :param backend: An optional backend supporting the
Erik Trauschkedc570402015-09-24 20:24:28 -0700229 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
230 interface.
231
232 :returns: An instance of
233 :class:`~cryptography.x509.CertificateRevocationList`.
234
Paul Kehrera1a1f232015-03-15 15:34:35 -0500235Loading Certificate Signing Requests
236~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600237
Lucia Lic6ba99d2021-11-08 22:06:11 +0800238.. function:: load_pem_x509_csr(data, backend=None)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600239
240 .. versionadded:: 0.9
241
Paul Kehrera1a1f232015-03-15 15:34:35 -0500242 Deserialize a certificate signing request (CSR) from PEM encoded data. PEM
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500243 requests are base64 decoded and have delimiters that look like
Paul Kehrerd3dafbd2015-03-15 16:24:18 -0500244 ``-----BEGIN CERTIFICATE REQUEST-----``. This format is also known as
245 PKCS#10.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600246
247 :param bytes data: The PEM encoded request data.
248
Lucia Lic6ba99d2021-11-08 22:06:11 +0800249 :param backend: An optional backend supporting the
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600250 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
251 interface.
252
Paul Kehrera1a1f232015-03-15 15:34:35 -0500253 :returns: An instance of
254 :class:`~cryptography.x509.CertificateSigningRequest`.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600255
Alex Gaynor5ce14042016-05-29 13:13:46 -0400256 .. doctest::
257
258 >>> from cryptography import x509
Alex Gaynor5ce14042016-05-29 13:13:46 -0400259 >>> from cryptography.hazmat.primitives import hashes
Lucia Lic6ba99d2021-11-08 22:06:11 +0800260 >>> csr = x509.load_pem_x509_csr(pem_req_data)
261 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA256)
Alex Gaynor5ce14042016-05-29 13:13:46 -0400262 True
263
Lucia Lic6ba99d2021-11-08 22:06:11 +0800264.. function:: load_der_x509_csr(data, backend=None)
Paul Kehrer1effb6e2015-03-30 15:05:59 -0500265
266 .. versionadded:: 0.9
267
268 Deserialize a certificate signing request (CSR) from DER encoded data. DER
269 is a binary format and is not commonly used with CSRs.
270
271 :param bytes data: The DER encoded request data.
272
Lucia Lic6ba99d2021-11-08 22:06:11 +0800273 :param backend: An optional backend supporting the
Paul Kehrer1effb6e2015-03-30 15:05:59 -0500274 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
275 interface.
276
277 :returns: An instance of
278 :class:`~cryptography.x509.CertificateSigningRequest`.
279
Paul Kehrere76cd272014-12-14 19:00:51 -0600280X.509 Certificate Object
281~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerb2de9482014-12-11 14:54:48 -0600282
Paul Kehrere76cd272014-12-14 19:00:51 -0600283.. class:: Certificate
Paul Kehrerb2de9482014-12-11 14:54:48 -0600284
285 .. versionadded:: 0.7
286
287 .. attribute:: version
288
Paul Kehrere76cd272014-12-14 19:00:51 -0600289 :type: :class:`~cryptography.x509.Version`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600290
Paul Kehrere76cd272014-12-14 19:00:51 -0600291 The certificate version as an enumeration. Version 3 certificates are
292 the latest version and also the only type you should see in practice.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600293
Alex Gaynor89c4dc82014-12-16 16:49:33 -0800294 :raises cryptography.x509.InvalidVersion: If the version in the
Alex Gaynor6d7ab4c2014-12-16 16:50:33 -0800295 certificate is not a known
296 :class:`X.509 version <cryptography.x509.Version>`.
Paul Kehrer92aac382014-12-15 16:25:28 -0600297
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600298 .. doctest::
299
300 >>> cert.version
301 <Version.v3: 2>
302
Paul Kehrerb2de9482014-12-11 14:54:48 -0600303 .. method:: fingerprint(algorithm)
304
305 :param algorithm: The
Paul Kehrer601278a2015-02-12 12:51:00 -0600306 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600307 that will be used to generate the fingerprint.
308
Erik Trauschke2dcce902015-05-14 16:12:24 -0700309 :return bytes: The fingerprint using the supplied hash algorithm, as
Paul Kehrerb2de9482014-12-11 14:54:48 -0600310 bytes.
311
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600312 .. doctest::
313
314 >>> from cryptography.hazmat.primitives import hashes
315 >>> cert.fingerprint(hashes.SHA256())
Paul Kehrer056c9dd2018-05-12 15:17:06 -0400316 b'\x86\xd2\x187Gc\xfc\xe7}[+E9\x8d\xb4\x8f\x10\xe5S\xda\x18u\xbe}a\x03\x08[\xac\xa04?'
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600317
Chelsea Winfreee295f3a2016-06-02 21:15:54 -0700318 .. attribute:: serial_number
Paul Kehrerb2de9482014-12-11 14:54:48 -0600319
320 :type: int
321
322 The serial as a Python integer.
323
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600324 .. doctest::
325
Chelsea Winfreee295f3a2016-06-02 21:15:54 -0700326 >>> cert.serial_number
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600327 2
328
Paul Kehrerb2de9482014-12-11 14:54:48 -0600329 .. method:: public_key()
330
Alex Gaynor4c2561a2015-10-12 23:53:39 -0400331 The public key associated with the certificate.
332
Lucia Lic6ba99d2021-11-08 22:06:11 +0800333 :returns: One of
334 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`,
335 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`,
336 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`,
337 :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey` or
338 :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PublicKey`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600339
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600340 .. doctest::
341
Alex Stapletonf79c2312014-12-30 12:50:14 +0000342 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600343 >>> public_key = cert.public_key()
Alex Stapletonf79c2312014-12-30 12:50:14 +0000344 >>> isinstance(public_key, rsa.RSAPublicKey)
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600345 True
346
Paul Kehrerb2de9482014-12-11 14:54:48 -0600347 .. attribute:: not_valid_before
348
349 :type: :class:`datetime.datetime`
350
Paul Kehrer78a81502014-12-16 14:47:52 -0600351 A naïve datetime representing the beginning of the validity period for
352 the certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600353
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600354 .. doctest::
355
356 >>> cert.not_valid_before
357 datetime.datetime(2010, 1, 1, 8, 30)
358
Paul Kehrerb2de9482014-12-11 14:54:48 -0600359 .. attribute:: not_valid_after
360
361 :type: :class:`datetime.datetime`
362
Paul Kehrer78a81502014-12-16 14:47:52 -0600363 A naïve datetime representing the end of the validity period for the
364 certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600365
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600366 .. doctest::
367
368 >>> cert.not_valid_after
369 datetime.datetime(2030, 12, 31, 8, 30)
370
Paul Kehrer719d5362015-01-01 20:03:52 -0600371 .. attribute:: issuer
372
373 .. versionadded:: 0.8
374
375 :type: :class:`Name`
376
377 The :class:`Name` of the issuer.
378
379 .. attribute:: subject
380
381 .. versionadded:: 0.8
382
383 :type: :class:`Name`
384
385 The :class:`Name` of the subject.
386
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600387 .. attribute:: signature_hash_algorithm
Paul Kehrer56da2a52015-02-11 23:35:07 -0600388
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600389 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrer56da2a52015-02-11 23:35:07 -0600390
Paul Kehrere612ec72015-02-16 14:33:35 -0600391 Returns the
Paul Kehrer71d40c62015-02-19 08:21:04 -0600392 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
Lucia Lic6ba99d2021-11-08 22:06:11 +0800393 was used in signing this certificate. Can be ``None`` if signature
394 did not use separate hash
395 (:attr:`~cryptography.x509.oid.SignatureAlgorithmOID.ED25519`,
396 :attr:`~cryptography.x509.oid.SignatureAlgorithmOID.ED448`).
Paul Kehrer56da2a52015-02-11 23:35:07 -0600397
398 .. doctest::
399
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600400 >>> from cryptography.hazmat.primitives import hashes
401 >>> isinstance(cert.signature_hash_algorithm, hashes.SHA256)
402 True
Paul Kehrer719d5362015-01-01 20:03:52 -0600403
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800404 .. attribute:: signature_algorithm_oid
405
406 .. versionadded:: 1.6
407
408 :type: :class:`ObjectIdentifier`
409
410 Returns the :class:`ObjectIdentifier` of the signature algorithm used
411 to sign the certificate. This will be one of the OIDs from
412 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
413
414
415 .. doctest::
416
417 >>> cert.signature_algorithm_oid
418 <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)>
419
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500420 .. attribute:: extensions
421
422 :type: :class:`Extensions`
423
424 The extensions encoded in the certificate.
425
426 :raises cryptography.x509.DuplicateExtension: If more than one
427 extension of the same type is found within the certificate.
428
Paul Kehrerbed07352015-04-21 08:31:10 -0500429 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
430 contains a general name that is not supported.
431
Paul Kehrerfa56a232015-03-17 13:14:03 -0500432 .. doctest::
433
434 >>> for ext in cert.extensions:
435 ... print(ext)
Paul Kehrer056c9dd2018-05-12 15:17:06 -0400436 <Extension(oid=<ObjectIdentifier(oid=2.5.29.35, name=authorityKeyIdentifier)>, critical=False, value=<AuthorityKeyIdentifier(key_identifier=b'\xe4}_\xd1\\\x95\x86\x08,\x05\xae\xbeu\xb6e\xa7\xd9]\xa8f', authority_cert_issuer=None, authority_cert_serial_number=None)>)>
437 <Extension(oid=<ObjectIdentifier(oid=2.5.29.14, name=subjectKeyIdentifier)>, critical=False, value=<SubjectKeyIdentifier(digest=b'X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9')>)>
Lucia Lic6ba99d2021-11-08 22:06:11 +0800438 <Extension(oid=<ObjectIdentifier(oid=2.5.29.15, name=keyUsage)>, critical=True, value=<KeyUsage(digital_signature=False, content_commitment=False, key_encipherment=False, data_encipherment=False, key_agreement=False, key_cert_sign=True, crl_sign=True, encipher_only=False, decipher_only=False)>)>
Paul Kehrer2008d9c2015-05-12 22:19:56 -0500439 <Extension(oid=<ObjectIdentifier(oid=2.5.29.32, name=certificatePolicies)>, critical=False, value=<CertificatePolicies([<PolicyInformation(policy_identifier=<ObjectIdentifier(oid=2.16.840.1.101.3.2.1.48.1, name=Unknown OID)>, policy_qualifiers=None)>])>)>
Paul Kehrerfa56a232015-03-17 13:14:03 -0500440 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
441
Paul Kehrerd91e7c12015-10-01 16:50:42 -0500442 .. attribute:: signature
443
444 .. versionadded:: 1.2
445
446 :type: bytes
447
448 The bytes of the certificate's signature.
449
Paul Kehrerd2898052015-11-03 22:00:41 +0900450 .. attribute:: tbs_certificate_bytes
Paul Kehrerd91e7c12015-10-01 16:50:42 -0500451
452 .. versionadded:: 1.2
453
454 :type: bytes
455
456 The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed
457 and then signed by the private key of the certificate's issuer. This
458 data may be used to validate a signature, but use extreme caution as
459 certificate validation is a complex problem that involves much more
460 than just signature checks.
461
Paul Kehrer838bc4a2018-10-10 12:02:55 +0800462 To validate the signature on a certificate you can do the following.
463 Note: This only verifies that the certificate was signed with the
464 private key associated with the public key provided and does not
465 perform any of the other checks needed for secure certificate
466 validation. Additionally, this example will only work for RSA public
467 keys with ``PKCS1v15`` signatures, and so it can't be used for general
468 purpose signature verification.
g_goessel16f746f2018-10-10 04:13:41 +0200469
470 .. doctest::
471
472 >>> from cryptography.hazmat.primitives.serialization import load_pem_public_key
473 >>> from cryptography.hazmat.primitives.asymmetric import padding
Lucia Lic6ba99d2021-11-08 22:06:11 +0800474 >>> issuer_public_key = load_pem_public_key(pem_issuer_public_key)
475 >>> cert_to_check = x509.load_pem_x509_certificate(pem_data_to_check)
g_goessel16f746f2018-10-10 04:13:41 +0200476 >>> issuer_public_key.verify(
Alex Gaynor64602282018-10-09 23:03:55 -0400477 ... cert_to_check.signature,
478 ... cert_to_check.tbs_certificate_bytes,
479 ... # Depends on the algorithm used to create the certificate
480 ... padding.PKCS1v15(),
481 ... cert_to_check.signature_hash_algorithm,
g_goessel16f746f2018-10-10 04:13:41 +0200482 ... )
483
484 An
485 :class:`~cryptography.exceptions.InvalidSignature`
486 exception will be raised if the signature fails to verify.
487
Andre Carona8aded62015-05-19 20:11:57 -0400488 .. method:: public_bytes(encoding)
489
Alex Gaynord0b376b2015-07-05 13:58:12 -0400490 .. versionadded:: 1.0
491
Andre Carona8aded62015-05-19 20:11:57 -0400492 :param encoding: The
493 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
494 that will be used to serialize the certificate.
495
496 :return bytes: The data that can be written to a file or sent
497 over the network to be verified by clients.
498
Erik Trauschke2dcce902015-05-14 16:12:24 -0700499X.509 CRL (Certificate Revocation List) Object
500~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
501
502.. class:: CertificateRevocationList
503
504 .. versionadded:: 1.0
505
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700506 A CertificateRevocationList is an object representing a list of revoked
507 certificates. The object is iterable and will yield the RevokedCertificate
508 objects stored in this CRL.
509
510 .. doctest::
Erik Trauschkeb14f7d12015-10-13 09:55:39 -0700511
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700512 >>> len(crl)
513 1
Paul Kehrerdcdf9672015-10-21 20:27:28 -0500514 >>> revoked_certificate = crl[0]
515 >>> type(revoked_certificate)
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700516 <class 'cryptography.hazmat.backends.openssl.x509._RevokedCertificate'>
517 >>> for r in crl:
518 ... print(r.serial_number)
519 0
520
Erik Trauschke2dcce902015-05-14 16:12:24 -0700521 .. method:: fingerprint(algorithm)
522
523 :param algorithm: The
524 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
525 that will be used to generate the fingerprint.
526
527 :return bytes: The fingerprint using the supplied hash algorithm, as
528 bytes.
529
Erik Trauschkedc570402015-09-24 20:24:28 -0700530 .. doctest::
531
532 >>> from cryptography.hazmat.primitives import hashes
533 >>> crl.fingerprint(hashes.SHA256())
Paul Kehrer056c9dd2018-05-12 15:17:06 -0400534 b'e\xcf.\xc4:\x83?1\xdc\xf3\xfc\x95\xd7\xb3\x87\xb3\x8e\xf8\xb93!\x87\x07\x9d\x1b\xb4!\xb9\xe4W\xf4\x1f'
Erik Trauschkedc570402015-09-24 20:24:28 -0700535
Paul Kehrer5d187402018-07-16 20:49:51 +0530536 .. method:: get_revoked_certificate_by_serial_number(serial_number)
537
538 .. versionadded:: 2.3
539
540 :param serial_number: The serial as a Python integer.
541 :returns: :class:`~cryptography.x509.RevokedCertificate` if the
542 ``serial_number`` is present in the CRL or ``None`` if it
543 is not.
544
Erik Trauschke2dcce902015-05-14 16:12:24 -0700545 .. attribute:: signature_hash_algorithm
546
547 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
548
549 Returns the
550 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
Lucia Lic6ba99d2021-11-08 22:06:11 +0800551 was used in signing this CRL. Can be ``None`` if signature
552 did not use separate hash
553 (:attr:`~cryptography.x509.oid.SignatureAlgorithmOID.ED25519`,
554 :attr:`~cryptography.x509.oid.SignatureAlgorithmOID.ED448`).
Erik Trauschke2dcce902015-05-14 16:12:24 -0700555
Erik Trauschkedc570402015-09-24 20:24:28 -0700556 .. doctest::
557
558 >>> from cryptography.hazmat.primitives import hashes
559 >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256)
560 True
561
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800562 .. attribute:: signature_algorithm_oid
563
564 .. versionadded:: 1.6
565
566 :type: :class:`ObjectIdentifier`
567
568 Returns the :class:`ObjectIdentifier` of the signature algorithm used
569 to sign the CRL. This will be one of the OIDs from
570 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
571
572 .. doctest::
573
574 >>> crl.signature_algorithm_oid
575 <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)>
576
Erik Trauschke2dcce902015-05-14 16:12:24 -0700577 .. attribute:: issuer
578
579 :type: :class:`Name`
580
581 The :class:`Name` of the issuer.
582
Erik Trauschkedc570402015-09-24 20:24:28 -0700583 .. doctest::
584
585 >>> crl.issuer
Marti Raudsepp82415572018-12-18 01:26:40 +0200586 <Name(C=US,CN=cryptography.io)>
Erik Trauschkedc570402015-09-24 20:24:28 -0700587
Erik Trauschke2dcce902015-05-14 16:12:24 -0700588 .. attribute:: next_update
589
590 :type: :class:`datetime.datetime`
591
592 A naïve datetime representing when the next update to this CRL is
593 expected.
594
Erik Trauschkedc570402015-09-24 20:24:28 -0700595 .. doctest::
596
597 >>> crl.next_update
598 datetime.datetime(2016, 1, 1, 0, 0)
599
Erik Trauschke2dcce902015-05-14 16:12:24 -0700600 .. attribute:: last_update
601
602 :type: :class:`datetime.datetime`
603
Lucia Lic6ba99d2021-11-08 22:06:11 +0800604 A naïve datetime representing when this CRL was last updated.
Erik Trauschke2dcce902015-05-14 16:12:24 -0700605
Erik Trauschkedc570402015-09-24 20:24:28 -0700606 .. doctest::
Erik Trauschke2dcce902015-05-14 16:12:24 -0700607
Erik Trauschkedc570402015-09-24 20:24:28 -0700608 >>> crl.last_update
609 datetime.datetime(2015, 1, 1, 0, 0)
Erik Trauschke2dcce902015-05-14 16:12:24 -0700610
611 .. attribute:: extensions
612
613 :type: :class:`Extensions`
614
615 The extensions encoded in the CRL.
616
Erik Trauschke6abe2bb2015-11-19 10:27:01 -0800617 .. attribute:: signature
618
619 .. versionadded:: 1.2
620
621 :type: bytes
622
623 The bytes of the CRL's signature.
624
625 .. attribute:: tbs_certlist_bytes
626
627 .. versionadded:: 1.2
628
629 :type: bytes
630
631 The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed
632 and then signed by the private key of the CRL's issuer. This data may be
633 used to validate a signature, but use extreme caution as CRL validation
634 is a complex problem that involves much more than just signature checks.
635
Paul Kehrer54a837d2015-12-20 23:42:32 -0600636 .. method:: public_bytes(encoding)
637
638 .. versionadded:: 1.2
639
640 :param encoding: The
641 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
642 that will be used to serialize the certificate revocation list.
643
644 :return bytes: The data that can be written to a file or sent
645 over the network and used as part of a certificate verification
646 process.
647
Vincent Pelletier6c02ee82017-08-12 22:05:00 +0900648 .. method:: is_signature_valid(public_key)
649
650 .. versionadded:: 2.1
651
Paul Kehrerf944c402017-08-12 08:52:55 -0500652 .. warning::
653
654 Checking the validity of the signature on the CRL is insufficient
655 to know if the CRL should be trusted. More details are available
656 in :rfc:`5280`.
657
Vincent Pelletier6c02ee82017-08-12 22:05:00 +0900658 Returns True if the CRL signature is correct for given public key,
659 False otherwise.
Erik Trauschke6abe2bb2015-11-19 10:27:01 -0800660
Andre Caron9bbfcea2015-05-18 20:55:29 -0400661X.509 Certificate Builder
662~~~~~~~~~~~~~~~~~~~~~~~~~
663
664.. class:: CertificateBuilder
665
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500666 .. versionadded:: 1.0
667
668 .. doctest::
669
670 >>> from cryptography import x509
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500671 >>> from cryptography.hazmat.primitives import hashes
672 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -0500673 >>> from cryptography.x509.oid import NameOID
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500674 >>> import datetime
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500675 >>> one_day = datetime.timedelta(1, 0, 0)
676 >>> private_key = rsa.generate_private_key(
677 ... public_exponent=65537,
678 ... key_size=2048,
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500679 ... )
Cory Benfieldc47b2522015-12-07 15:25:12 +0000680 >>> public_key = private_key.public_key()
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500681 >>> builder = x509.CertificateBuilder()
682 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500683 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500684 ... ]))
685 >>> builder = builder.issuer_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500686 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500687 ... ]))
688 >>> builder = builder.not_valid_before(datetime.datetime.today() - one_day)
Alex Gaynorcdd35852018-08-05 18:17:35 -0400689 >>> builder = builder.not_valid_after(datetime.datetime.today() + (one_day * 30))
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500690 >>> builder = builder.serial_number(x509.random_serial_number())
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500691 >>> builder = builder.public_key(public_key)
692 >>> builder = builder.add_extension(
Paul Kehrer1bab7bc2017-01-18 13:44:40 +0800693 ... x509.SubjectAlternativeName(
Paul Kehrered321052017-10-11 08:11:44 +0800694 ... [x509.DNSName(u'cryptography.io')]
Paul Kehrer1bab7bc2017-01-18 13:44:40 +0800695 ... ),
696 ... critical=False
697 ... )
698 >>> builder = builder.add_extension(
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500699 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
700 ... )
701 >>> certificate = builder.sign(
702 ... private_key=private_key, algorithm=hashes.SHA256(),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500703 ... )
704 >>> isinstance(certificate, x509.Certificate)
705 True
706
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500707 .. method:: issuer_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400708
709 Sets the issuer's distinguished name.
710
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500711 :param name: The :class:`~cryptography.x509.Name` that describes the
712 issuer (CA).
Andre Caron9bbfcea2015-05-18 20:55:29 -0400713
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500714 .. method:: subject_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400715
716 Sets the subject's distinguished name.
717
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500718 :param name: The :class:`~cryptography.x509.Name` that describes the
Ian Cordasco85fc4d52015-08-01 20:29:31 -0500719 subject.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400720
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500721 .. method:: public_key(public_key)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400722
723 Sets the subject's public key.
724
Ian Cordasco8f571422015-08-02 11:31:08 -0500725 :param public_key: The subject's public key. This can be one of
726 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`,
Lucia Lic6ba99d2021-11-08 22:06:11 +0800727 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`,
728 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`,
729 :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey` or
730 :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PublicKey`.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400731
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500732 .. method:: serial_number(serial_number)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400733
734 Sets the certificate's serial number (an integer). The CA's policy
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500735 determines how it attributes serial numbers to certificates. This
736 number must uniquely identify the certificate given the issuer.
737 `CABForum Guidelines`_ require entropy in the serial number
738 to provide protection against hash collision attacks. For more
739 information on secure random number generation, see
740 :doc:`/random-numbers`.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400741
742 :param serial_number: Integer number that will be used by the CA to
743 identify this certificate (most notably during certificate
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500744 revocation checking). Users should consider using
745 :func:`~cryptography.x509.random_serial_number` when possible.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400746
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500747 .. method:: not_valid_before(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400748
749 Sets the certificate's activation time. This is the time from which
750 clients can start trusting the certificate. It may be different from
751 the time at which the certificate was created.
752
Ian Cordasco17c89002015-08-02 21:13:59 -0500753 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400754 activation time for the certificate. The certificate may not be
755 trusted clients if it is used before this time.
756
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500757 .. method:: not_valid_after(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400758
759 Sets the certificate's expiration time. This is the time from which
760 clients should no longer trust the certificate. The CA's policy will
761 determine how long the certificate should remain in use.
762
Ian Cordasco17c89002015-08-02 21:13:59 -0500763 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400764 expiration time for the certificate. The certificate may not be
765 trusted clients if it is used after this time.
766
Ian Cordasco17c89002015-08-02 21:13:59 -0500767 .. method:: add_extension(extension, critical)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400768
769 Adds an X.509 extension to the certificate.
770
Paul Kehrer2c145cc2015-10-02 11:27:21 -0500771 :param extension: An extension conforming to the
772 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400773
Ian Cordasco17c89002015-08-02 21:13:59 -0500774 :param critical: Set to ``True`` if the extension must be understood and
775 handled by whoever reads the certificate.
776
Lucia Lic6ba99d2021-11-08 22:06:11 +0800777 .. method:: sign(private_key, algorithm, backend=None)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400778
779 Sign the certificate using the CA's private key.
780
Ian Cordascoc5e1c252015-07-31 23:33:35 -0500781 :param private_key: The
782 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
Lucia Lic6ba99d2021-11-08 22:06:11 +0800783 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey`,
784 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`,
785 :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey` or
786 :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PrivateKey`
Ian Cordascoc5e1c252015-07-31 23:33:35 -0500787 that will be used to sign the certificate.
788
Andre Caron9bbfcea2015-05-18 20:55:29 -0400789 :param algorithm: The
790 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
Lucia Lic6ba99d2021-11-08 22:06:11 +0800791 will be used to generate the signature. This must be ``None`` if
792 the ``private_key`` is an
793 :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey`
794 or an
795 :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PrivateKey`
796 and an instance of a
797 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
798 otherwise.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400799
Lucia Lic6ba99d2021-11-08 22:06:11 +0800800 :param backend: An optional backend used to build the certificate.
Paul Kehrer9add80e2015-08-03 17:53:14 +0100801 Must support the
802 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
803 interface.
804
Benjamin Peterson9ed312b2015-10-12 20:51:34 -0700805 :returns: :class:`~cryptography.x509.Certificate`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400806
807
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500808X.509 CSR (Certificate Signing Request) Object
809~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600810
Paul Kehrera1a1f232015-03-15 15:34:35 -0500811.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600812
813 .. versionadded:: 0.9
814
815 .. method:: public_key()
816
Alex Gaynor4c2561a2015-10-12 23:53:39 -0400817 The public key associated with the request.
818
Lucia Lic6ba99d2021-11-08 22:06:11 +0800819 :returns: One of
820 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`,
821 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`,
822 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`,
823 :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey` or
824 :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PublicKey`.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600825
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600826 .. doctest::
827
828 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500829 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600830 >>> isinstance(public_key, rsa.RSAPublicKey)
831 True
832
833 .. attribute:: subject
834
835 :type: :class:`Name`
836
837 The :class:`Name` of the subject.
838
839 .. attribute:: signature_hash_algorithm
840
841 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
842
843 Returns the
844 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
Lucia Lic6ba99d2021-11-08 22:06:11 +0800845 was used in signing this request. Can be ``None`` if signature
846 did not use separate hash
847 (:attr:`~cryptography.x509.oid.SignatureAlgorithmOID.ED25519`,
848 :attr:`~cryptography.x509.oid.SignatureAlgorithmOID.ED448`).
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600849
850 .. doctest::
851
852 >>> from cryptography.hazmat.primitives import hashes
Lucia Lic6ba99d2021-11-08 22:06:11 +0800853 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA256)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600854 True
855
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800856 .. attribute:: signature_algorithm_oid
857
858 .. versionadded:: 1.6
859
860 :type: :class:`ObjectIdentifier`
861
862 Returns the :class:`ObjectIdentifier` of the signature algorithm used
863 to sign the request. This will be one of the OIDs from
864 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
865
866 .. doctest::
867
868 >>> csr.signature_algorithm_oid
Lucia Lic6ba99d2021-11-08 22:06:11 +0800869 <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)>
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800870
Paul Kehrerc4e61942015-08-01 21:21:13 +0100871 .. attribute:: extensions
872
873 :type: :class:`Extensions`
874
875 The extensions encoded in the certificate signing request.
876
877 :raises cryptography.x509.DuplicateExtension: If more than one
Paul Kehrer24283d22015-08-01 21:31:19 +0100878 extension of the same type is found within the certificate signing request.
Paul Kehrerc4e61942015-08-01 21:21:13 +0100879
Paul Kehrerc4e61942015-08-01 21:21:13 +0100880 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
881 contains a general name that is not supported.
882
Lucia Lic6ba99d2021-11-08 22:06:11 +0800883 .. method:: get_attribute_for_oid(oid)
Paul Kehrerc4e61942015-08-01 21:21:13 +0100884
Lucia Lic6ba99d2021-11-08 22:06:11 +0800885 .. versionadded:: 3.0
886
887 :param oid: An :class:`ObjectIdentifier` instance.
888
889 :returns: The bytes value of the attribute or an exception if not
890 found.
891
892 :raises cryptography.x509.AttributeNotFound: If the request does
893 not have the attribute requested.
Paul Kehrerc4e61942015-08-01 21:21:13 +0100894
Andre Caron476c5df2015-05-18 10:23:28 -0400895 .. method:: public_bytes(encoding)
896
Alex Gaynord0b376b2015-07-05 13:58:12 -0400897 .. versionadded:: 1.0
898
Andre Caron476c5df2015-05-18 10:23:28 -0400899 :param encoding: The
900 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
901 that will be used to serialize the certificate request.
902
903 :return bytes: The data that can be written to a file or sent
904 over the network to be signed by the certificate
905 authority.
906
Paul Kehrerab209392015-12-01 14:50:31 -0600907 .. attribute:: signature
908
909 .. versionadded:: 1.2
910
911 :type: bytes
912
913 The bytes of the certificate signing request's signature.
914
915 .. attribute:: tbs_certrequest_bytes
916
917 .. versionadded:: 1.2
918
919 :type: bytes
920
921 The DER encoded bytes payload (as defined by :rfc:`2986`) that is
922 hashed and then signed by the private key (corresponding to the public
923 key embedded in the CSR). This data may be used to validate the CSR
924 signature.
925
Joern Heisslerfbda8ce2016-01-18 00:24:44 +0100926 .. attribute:: is_signature_valid
Joern Heissler1bd77e22016-01-13 22:51:37 +0100927
928 .. versionadded:: 1.3
929
Joern Heisslerfbda8ce2016-01-18 00:24:44 +0100930 Returns True if the CSR signature is correct, False otherwise.
Joern Heissler1bd77e22016-01-13 22:51:37 +0100931
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600932X.509 Certificate Revocation List Builder
933~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
934
935.. class:: CertificateRevocationListBuilder
936
937 .. versionadded:: 1.2
938
939 .. doctest::
940
941 >>> from cryptography import x509
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600942 >>> from cryptography.hazmat.primitives import hashes
943 >>> from cryptography.hazmat.primitives.asymmetric import rsa
944 >>> from cryptography.x509.oid import NameOID
945 >>> import datetime
946 >>> one_day = datetime.timedelta(1, 0, 0)
947 >>> private_key = rsa.generate_private_key(
948 ... public_exponent=65537,
949 ... key_size=2048,
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600950 ... )
951 >>> builder = x509.CertificateRevocationListBuilder()
952 >>> builder = builder.issuer_name(x509.Name([
953 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io CA'),
954 ... ]))
955 >>> builder = builder.last_update(datetime.datetime.today())
956 >>> builder = builder.next_update(datetime.datetime.today() + one_day)
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600957 >>> revoked_cert = x509.RevokedCertificateBuilder().serial_number(
958 ... 333
959 ... ).revocation_date(
960 ... datetime.datetime.today()
Lucia Lic6ba99d2021-11-08 22:06:11 +0800961 ... ).build()
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600962 >>> builder = builder.add_revoked_certificate(revoked_cert)
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600963 >>> crl = builder.sign(
964 ... private_key=private_key, algorithm=hashes.SHA256(),
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600965 ... )
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600966 >>> len(crl)
967 1
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600968
969 .. method:: issuer_name(name)
970
971 Sets the issuer's distinguished name.
972
973 :param name: The :class:`~cryptography.x509.Name` that describes the
974 issuer (CA).
975
976 .. method:: last_update(time)
977
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600978 Sets this CRL's activation time. This is the time from which
979 clients can start trusting this CRL. It may be different from
980 the time at which this CRL was created. This is also known as the
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600981 ``thisUpdate`` time.
982
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600983 :param time: The :class:`datetime.datetime` object (in UTC) that marks
984 the activation time for this CRL. The CRL may not be trusted if it
985 is used before this time.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600986
987 .. method:: next_update(time)
988
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600989 Sets this CRL's next update time. This is the time by which
990 a new CRL will be issued. The CA is allowed to issue a new CRL before
991 this date, however clients are not required to check for it.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600992
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600993 :param time: The :class:`datetime.datetime` object (in UTC) that marks
994 the next update time for this CRL.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600995
Paul Kehrer426b48d2015-12-24 20:50:43 -0600996 .. method:: add_extension(extension, critical)
997
998 Adds an X.509 extension to this CRL.
999
1000 :param extension: An extension with the
1001 :class:`~cryptography.x509.ExtensionType` interface.
1002
1003 :param critical: Set to ``True`` if the extension must be understood and
1004 handled by whoever reads the CRL.
1005
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -06001006 .. method:: add_revoked_certificate(revoked_certificate)
1007
1008 Adds a revoked certificate to this CRL.
1009
1010 :param revoked_certificate: An instance of
1011 :class:`~cryptography.x509.RevokedCertificate`. These can be
1012 obtained from an existing CRL or created with
1013 :class:`~cryptography.x509.RevokedCertificateBuilder`.
1014
Lucia Lic6ba99d2021-11-08 22:06:11 +08001015 .. method:: sign(private_key, algorithm, backend=None)
Paul Kehrerbfac2d12015-12-19 23:32:08 -06001016
Paul Kehrer0325b9d2015-12-24 19:19:59 -06001017 Sign this CRL using the CA's private key.
Paul Kehrerbfac2d12015-12-19 23:32:08 -06001018
1019 :param private_key: The
1020 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
Lucia Lic6ba99d2021-11-08 22:06:11 +08001021 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey`,
1022 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`,
1023 :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey` or
1024 :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PrivateKey`
Paul Kehrerbfac2d12015-12-19 23:32:08 -06001025 that will be used to sign the certificate.
1026
1027 :param algorithm: The
1028 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
1029 will be used to generate the signature.
Lucia Lic6ba99d2021-11-08 22:06:11 +08001030 This must be ``None`` if the ``private_key`` is an
1031 :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey`
1032 or an
1033 :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PrivateKey`
1034 and an instance of a
1035 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
1036 otherwise.
Paul Kehrerbfac2d12015-12-19 23:32:08 -06001037
Lucia Lic6ba99d2021-11-08 22:06:11 +08001038 :param backend: An optional backend used to build the CRL.
Paul Kehrerbfac2d12015-12-19 23:32:08 -06001039 Must support the
1040 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1041 interface.
1042
1043 :returns: :class:`~cryptography.x509.CertificateRevocationList`
1044
Erik Trauschke2dcce902015-05-14 16:12:24 -07001045X.509 Revoked Certificate Object
Erik Trauschkec5a8d172015-05-28 10:24:25 -07001046~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Erik Trauschke2dcce902015-05-14 16:12:24 -07001047
1048.. class:: RevokedCertificate
1049
1050 .. versionadded:: 1.0
1051
1052 .. attribute:: serial_number
1053
1054 :type: :class:`int`
1055
1056 An integer representing the serial number of the revoked certificate.
1057
Erik Trauschkedc570402015-09-24 20:24:28 -07001058 .. doctest::
1059
Erik Trauschke3cdabaf2015-10-13 09:42:53 -07001060 >>> revoked_certificate.serial_number
Erik Trauschkedc570402015-09-24 20:24:28 -07001061 0
1062
Erik Trauschke2dcce902015-05-14 16:12:24 -07001063 .. attribute:: revocation_date
1064
1065 :type: :class:`datetime.datetime`
1066
1067 A naïve datetime representing the date this certificates was revoked.
1068
Erik Trauschkedc570402015-09-24 20:24:28 -07001069 .. doctest::
1070
Erik Trauschke77f5a252015-10-14 08:06:38 -07001071 >>> revoked_certificate.revocation_date
Erik Trauschkedc570402015-09-24 20:24:28 -07001072 datetime.datetime(2015, 1, 1, 0, 0)
1073
Erik Trauschke2dcce902015-05-14 16:12:24 -07001074 .. attribute:: extensions
1075
1076 :type: :class:`Extensions`
1077
1078 The extensions encoded in the revoked certificate.
Andre Caron476c5df2015-05-18 10:23:28 -04001079
Erik Trauschkedc570402015-09-24 20:24:28 -07001080 .. doctest::
1081
Erik Trauschke77f5a252015-10-14 08:06:38 -07001082 >>> for ext in revoked_certificate.extensions:
Erik Trauschkedc570402015-09-24 20:24:28 -07001083 ... print(ext)
Paul Kehrer23c0bbc2015-12-25 22:35:19 -06001084 <Extension(oid=<ObjectIdentifier(oid=2.5.29.24, name=invalidityDate)>, critical=False, value=<InvalidityDate(invalidity_date=2015-01-01 00:00:00)>)>
Paul Kehrer7058ece2015-12-25 22:28:29 -06001085 <Extension(oid=<ObjectIdentifier(oid=2.5.29.21, name=cRLReason)>, critical=False, value=<CRLReason(reason=ReasonFlags.key_compromise)>)>
Erik Trauschkedc570402015-09-24 20:24:28 -07001086
Paul Kehrerc33ffd72015-12-25 10:59:22 -06001087X.509 Revoked Certificate Builder
1088~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1089
1090.. class:: RevokedCertificateBuilder
1091
1092 This class is used to create :class:`~cryptography.x509.RevokedCertificate`
1093 objects that can be used with the
1094 :class:`~cryptography.x509.CertificateRevocationListBuilder`.
1095
1096 .. versionadded:: 1.2
1097
1098 .. doctest::
1099
1100 >>> from cryptography import x509
Paul Kehrerc33ffd72015-12-25 10:59:22 -06001101 >>> import datetime
1102 >>> builder = x509.RevokedCertificateBuilder()
1103 >>> builder = builder.revocation_date(datetime.datetime.today())
1104 >>> builder = builder.serial_number(3333)
Lucia Lic6ba99d2021-11-08 22:06:11 +08001105 >>> revoked_certificate = builder.build()
Paul Kehrerc33ffd72015-12-25 10:59:22 -06001106 >>> isinstance(revoked_certificate, x509.RevokedCertificate)
1107 True
1108
1109 .. method:: serial_number(serial_number)
1110
1111 Sets the revoked certificate's serial number.
1112
1113 :param serial_number: Integer number that is used to identify the
1114 revoked certificate.
1115
1116 .. method:: revocation_date(time)
1117
1118 Sets the certificate's revocation date.
1119
1120 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
1121 revocation time for the certificate.
1122
Paul Kehrere5f152b2015-12-25 23:55:47 -06001123 .. method:: add_extension(extension, critical)
1124
1125 Adds an X.509 extension to this revoked certificate.
1126
1127 :param extension: An instance of one of the
1128 :ref:`CRL entry extensions <crl_entry_extensions>`.
1129
1130 :param critical: Set to ``True`` if the extension must be understood and
1131 handled.
1132
Lucia Lic6ba99d2021-11-08 22:06:11 +08001133 .. method:: build(backend=None)
Paul Kehrerc33ffd72015-12-25 10:59:22 -06001134
1135 Create a revoked certificate object using the provided backend.
1136
Lucia Lic6ba99d2021-11-08 22:06:11 +08001137 :param backend: An optional backend used to build the revoked
Paul Kehrerc33ffd72015-12-25 10:59:22 -06001138 certificate. Must support the
1139 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1140 interface.
1141
1142 :returns: :class:`~cryptography.x509.RevokedCertificate`
1143
Andre Caron0ef595f2015-05-18 13:53:43 -04001144X.509 CSR (Certificate Signing Request) Builder Object
1145~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1146
1147.. class:: CertificateSigningRequestBuilder
1148
Andre Carond259ee52015-06-02 23:47:11 -04001149 .. versionadded:: 1.0
1150
1151 .. doctest::
1152
1153 >>> from cryptography import x509
Andre Carond259ee52015-06-02 23:47:11 -04001154 >>> from cryptography.hazmat.primitives import hashes
1155 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Lucia Lic6ba99d2021-11-08 22:06:11 +08001156 >>> from cryptography.x509.oid import AttributeOID, NameOID
Andre Carond259ee52015-06-02 23:47:11 -04001157 >>> private_key = rsa.generate_private_key(
1158 ... public_exponent=65537,
1159 ... key_size=2048,
Andre Carond259ee52015-06-02 23:47:11 -04001160 ... )
1161 >>> builder = x509.CertificateSigningRequestBuilder()
Andre Carona9a51172015-06-06 20:18:44 -04001162 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -05001163 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Andre Carond259ee52015-06-02 23:47:11 -04001164 ... ]))
Ian Cordascof06b6be2015-06-21 10:09:18 -05001165 >>> builder = builder.add_extension(
Ian Cordasco0112b022015-06-16 17:51:18 -05001166 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
Andre Caron472fd692015-06-06 20:04:44 -04001167 ... )
Lucia Lic6ba99d2021-11-08 22:06:11 +08001168 >>> builder = builder.add_attribute(
1169 ... AttributeOID.CHALLENGE_PASSWORD, b"changeit"
1170 ... )
Andre Carond259ee52015-06-02 23:47:11 -04001171 >>> request = builder.sign(
Lucia Lic6ba99d2021-11-08 22:06:11 +08001172 ... private_key, hashes.SHA256()
Andre Carond259ee52015-06-02 23:47:11 -04001173 ... )
1174 >>> isinstance(request, x509.CertificateSigningRequest)
1175 True
1176
Andre Carona9a51172015-06-06 20:18:44 -04001177 .. method:: subject_name(name)
Andre Caron0ef595f2015-05-18 13:53:43 -04001178
Andre Caron341ff852015-06-06 20:14:31 -04001179 :param name: The :class:`~cryptography.x509.Name` of the certificate
1180 subject.
1181 :returns: A new
1182 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001183
Ian Cordascof06b6be2015-06-21 10:09:18 -05001184 .. method:: add_extension(extension, critical)
Andre Caron0ef595f2015-05-18 13:53:43 -04001185
Paul Kehrer2c145cc2015-10-02 11:27:21 -05001186 :param extension: An extension conforming to the
1187 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron472fd692015-06-06 20:04:44 -04001188 :param critical: Set to `True` if the extension must be understood and
1189 handled by whoever reads the certificate.
Andre Caron341ff852015-06-06 20:14:31 -04001190 :returns: A new
1191 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001192
Lucia Lic6ba99d2021-11-08 22:06:11 +08001193 .. method:: add_attribute(oid, value)
Andre Caron0ef595f2015-05-18 13:53:43 -04001194
Lucia Lic6ba99d2021-11-08 22:06:11 +08001195 .. versionadded:: 3.0
1196
1197 :param oid: An :class:`ObjectIdentifier` instance.
1198 :param value: The value of the attribute.
1199 :type value: bytes
1200 :returns: A new
1201 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
1202
1203 .. method:: sign(private_key, algorithm, backend=None)
1204
1205 :param backend: An optional backend used to sign the request.
Andre Caron0ef595f2015-05-18 13:53:43 -04001206 Must support the
1207 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1208 interface.
1209
1210 :param private_key: The
Andre Caron24f9bf42015-06-06 20:14:54 -04001211 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
Lucia Lic6ba99d2021-11-08 22:06:11 +08001212 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey`,
1213 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`,
1214 :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey` or
1215 :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PrivateKey`
Andre Caron0ef595f2015-05-18 13:53:43 -04001216 that will be used to sign the request. When the request is
1217 signed by a certificate authority, the private key's associated
1218 public key will be stored in the resulting certificate.
1219
1220 :param algorithm: The
1221 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
1222 that will be used to generate the request signature.
Lucia Lic6ba99d2021-11-08 22:06:11 +08001223 This must be ``None`` if the ``private_key`` is an
1224 :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey`
1225 or an
1226 :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PrivateKey`
1227 and an instance of a
1228 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
1229 otherwise.
Andre Caron0ef595f2015-05-18 13:53:43 -04001230
Andre Caron341ff852015-06-06 20:14:31 -04001231 :returns: A new
1232 :class:`~cryptography.x509.CertificateSigningRequest`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001233
1234
Paul Kehrer719d5362015-01-01 20:03:52 -06001235.. class:: Name
1236
1237 .. versionadded:: 0.8
1238
Paul Kehrer53d8d492015-02-13 18:47:30 -06001239 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -06001240 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -06001241 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -06001242 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
Marti Raudsepp82415572018-12-18 01:26:40 +02001243 ``CN=mydomain.com,O=My Org,C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -06001244
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001245 Technically, a Name is a list of *sets* of attributes, called *Relative
1246 Distinguished Names* or *RDNs*, although multi-valued RDNs are rarely
1247 encountered. The iteration order of values within a multi-valued RDN is
Marti Raudsepp9e1873a2018-07-09 16:11:18 +03001248 preserved. If you need to handle multi-valued RDNs, the ``rdns`` property
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001249 gives access to an ordered list of :class:`RelativeDistinguishedName`
1250 objects.
1251
1252 A Name can be initialized with an iterable of :class:`NameAttribute` (the
1253 common case where each RDN has a single attribute) or an iterable of
1254 :class:`RelativeDistinguishedName` objects (in the rare case of
1255 multi-valued RDNs).
1256
Paul Kehrer53d8d492015-02-13 18:47:30 -06001257 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -06001258
Paul Kehrer8b21a4a2015-02-14 07:56:36 -06001259 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -06001260 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -06001261 >>> for attribute in cert.subject:
1262 ... print(attribute)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001263 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')>
1264 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value='Test Certificates 2011')>
1265 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -06001266
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001267 .. attribute:: rdns
1268
1269 .. versionadded:: 1.6
1270
1271 :type: list of :class:`RelativeDistinguishedName`
1272
Paul Kehrere901d642015-02-11 18:50:58 -06001273 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -06001274
Paul Kehrere901d642015-02-11 18:50:58 -06001275 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -06001276
Paul Kehrere901d642015-02-11 18:50:58 -06001277 :returns: A list of :class:`NameAttribute` instances that match the
1278 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -06001279
1280 .. doctest::
1281
Paul Kehrere27f6582015-08-10 18:33:38 -05001282 >>> cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001283 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -06001284
Lucia Lic6ba99d2021-11-08 22:06:11 +08001285 .. method:: public_bytes(backend=None)
Paul Kehrer3a15b032016-11-13 14:30:11 -08001286
1287 .. versionadded:: 1.6
1288
Lucia Lic6ba99d2021-11-08 22:06:11 +08001289 :param backend: An optional backend supporting the
Paul Kehrer3a15b032016-11-13 14:30:11 -08001290 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1291 interface.
1292
1293 :return bytes: The DER encoded name.
1294
Marti Raudseppc3d38b52018-12-08 03:26:07 +02001295 .. method:: rfc4514_string()
1296
1297 .. versionadded:: 2.5
1298
Alex Gaynore5463cc2019-01-18 15:19:34 -06001299 :return str: Format the given name as a :rfc:`4514` Distinguished Name
Marti Raudsepp82415572018-12-18 01:26:40 +02001300 string, for example ``CN=mydomain.com,O=My Org,C=US``.
Marti Raudseppc3d38b52018-12-08 03:26:07 +02001301
1302
Paul Kehrere76cd272014-12-14 19:00:51 -06001303.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -10001304
1305 .. versionadded:: 0.7
1306
1307 An enumeration for X.509 versions.
1308
1309 .. attribute:: v1
1310
1311 For version 1 X.509 certificates.
1312
1313 .. attribute:: v3
1314
1315 For version 3 X.509 certificates.
1316
Paul Kehrer806bfb22015-02-02 17:05:24 -06001317.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001318
1319 .. versionadded:: 0.8
1320
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001321 An X.509 name consists of a list of :class:`RelativeDistinguishedName`
1322 instances, which consist of a set of :class:`NameAttribute` instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001323
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001324 .. attribute:: oid
1325
1326 :type: :class:`ObjectIdentifier`
1327
1328 The attribute OID.
1329
1330 .. attribute:: value
1331
Paul Kehrerd5852cb2015-01-30 08:25:23 -06001332 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001333
1334 The value of the attribute.
1335
Marti Raudseppc3d38b52018-12-08 03:26:07 +02001336 .. method:: rfc4514_string()
1337
1338 .. versionadded:: 2.5
1339
Alex Gaynore5463cc2019-01-18 15:19:34 -06001340 :return str: Format the given attribute as a :rfc:`4514` Distinguished
Marti Raudseppc3d38b52018-12-08 03:26:07 +02001341 Name string.
1342
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001343
1344.. class:: RelativeDistinguishedName(attributes)
1345
1346 .. versionadded:: 1.6
1347
1348 A relative distinguished name is a non-empty set of name attributes. The
Marti Raudsepp9e1873a2018-07-09 16:11:18 +03001349 object is iterable to get every attribute, preserving the original order.
1350 Passing duplicate attributes to the constructor raises ``ValueError``.
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001351
1352 .. method:: get_attributes_for_oid(oid)
1353
1354 :param oid: An :class:`ObjectIdentifier` instance.
1355
1356 :returns: A list of :class:`NameAttribute` instances that match the OID
1357 provided. The list should contain zero or one values.
1358
Marti Raudseppc3d38b52018-12-08 03:26:07 +02001359 .. method:: rfc4514_string()
1360
1361 .. versionadded:: 2.5
1362
Alex Gaynore5463cc2019-01-18 15:19:34 -06001363 :return str: Format the given RDN set as a :rfc:`4514` Distinguished
Marti Raudseppc3d38b52018-12-08 03:26:07 +02001364 Name string.
1365
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001366
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001367.. class:: ObjectIdentifier
1368
1369 .. versionadded:: 0.8
1370
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001371 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -06001372 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001373
Paul Kehrerd44f9a62015-02-04 14:47:34 -06001374 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001375
1376 :type: :class:`str`
1377
Paul Kehrerfedf4f42015-02-06 11:22:07 -06001378 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001379
Marti Raudseppc3d38b52018-12-08 03:26:07 +02001380
Paul Kehrer31bdf792015-03-25 14:11:00 -05001381.. _general_name_classes:
1382
1383General Name Classes
1384~~~~~~~~~~~~~~~~~~~~
1385
1386.. class:: GeneralName
1387
1388 .. versionadded:: 0.9
1389
1390 This is the generic interface that all the following classes are registered
1391 against.
1392
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001393.. class:: RFC822Name(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001394
1395 .. versionadded:: 0.9
1396
Lucia Lic6ba99d2021-11-08 22:06:11 +08001397 .. versionchanged:: 3.1
Paul Kehrer3e15ca52017-08-01 21:21:19 -05001398
Lucia Lic6ba99d2021-11-08 22:06:11 +08001399 :term:`U-label` support has been removed. Encode them to
1400 :term:`A-label` before use.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001401
1402 This corresponds to an email address. For example, ``user@example.com``.
1403
Paul Kehrere885bd62017-10-11 20:29:23 +08001404 :param value: The email address. If the address contains an
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001405 internationalized domain name then it must be encoded to an
Paul Kehrere885bd62017-10-11 20:29:23 +08001406 :term:`A-label` string before being passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001407
Lucia Lic6ba99d2021-11-08 22:06:11 +08001408 :raises ValueError: If the provided string is not an :term:`A-label`.
1409
Paul Kehrer31bdf792015-03-25 14:11:00 -05001410 .. attribute:: value
1411
1412 :type: :term:`text`
1413
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001414.. class:: DNSName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001415
1416 .. versionadded:: 0.9
1417
Lucia Lic6ba99d2021-11-08 22:06:11 +08001418 .. versionchanged:: 3.1
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001419
Lucia Lic6ba99d2021-11-08 22:06:11 +08001420 :term:`U-label` support has been removed. Encode them to
1421 :term:`A-label` before use.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001422
Paul Kehrer31bdf792015-03-25 14:11:00 -05001423 This corresponds to a domain name. For example, ``cryptography.io``.
1424
Paul Kehrere885bd62017-10-11 20:29:23 +08001425 :param value: The domain name. If it is an internationalized domain
1426 name then it must be encoded to an :term:`A-label` string before being
1427 passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001428
Lucia Lic6ba99d2021-11-08 22:06:11 +08001429 :raises ValueError: If the provided string is not an :term:`A-label`.
1430
Paul Kehrere885bd62017-10-11 20:29:23 +08001431 :type: :term:`text`
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001432
Paul Kehrer31bdf792015-03-25 14:11:00 -05001433 .. attribute:: value
1434
1435 :type: :term:`text`
1436
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001437.. class:: DirectoryName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001438
1439 .. versionadded:: 0.9
1440
1441 This corresponds to a directory name.
1442
1443 .. attribute:: value
1444
1445 :type: :class:`Name`
1446
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001447.. class:: UniformResourceIdentifier(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001448
1449 .. versionadded:: 0.9
1450
Lucia Lic6ba99d2021-11-08 22:06:11 +08001451 .. versionchanged:: 3.1
Paul Kehrerb8ef82e2015-04-22 16:04:24 -05001452
Lucia Lic6ba99d2021-11-08 22:06:11 +08001453 :term:`U-label` support has been removed. Encode them to
1454 :term:`A-label` before use.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001455
1456 This corresponds to a uniform resource identifier. For example,
1457 ``https://cryptography.io``.
1458
Paul Kehrere885bd62017-10-11 20:29:23 +08001459 :param value: The URI. If it contains an internationalized domain
1460 name then it must be encoded to an :term:`A-label` string before
1461 being passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001462
Lucia Lic6ba99d2021-11-08 22:06:11 +08001463 :raises ValueError: If the provided string is not an :term:`A-label`.
1464
Paul Kehrer31bdf792015-03-25 14:11:00 -05001465 .. attribute:: value
1466
1467 :type: :term:`text`
1468
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001469.. class:: IPAddress(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001470
1471 .. versionadded:: 0.9
1472
1473 This corresponds to an IP address.
1474
1475 .. attribute:: value
1476
Paul Kehrereb177932015-05-17 18:33:33 -07001477 :type: :class:`~ipaddress.IPv4Address`,
1478 :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
1479 or :class:`~ipaddress.IPv6Network`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001480
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001481.. class:: RegisteredID(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001482
1483 .. versionadded:: 0.9
1484
1485 This corresponds to a registered ID.
1486
1487 .. attribute:: value
1488
1489 :type: :class:`ObjectIdentifier`
1490
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001491.. class:: OtherName(type_id, value)
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001492
1493 .. versionadded:: 1.0
1494
Joshua Tauberer18b6fc82015-07-05 21:44:51 +00001495 This corresponds to an ``otherName.`` An ``otherName`` has a type identifier and a value represented in binary DER format.
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001496
1497 .. attribute:: type_id
1498
1499 :type: :class:`ObjectIdentifier`
1500
1501 .. attribute:: value
1502
Paul Kehreredfedc12018-09-14 18:24:20 -04001503 :type: bytes
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001504
Paul Kehrer8cf26422015-03-21 09:50:24 -05001505X.509 Extensions
1506~~~~~~~~~~~~~~~~
1507
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001508.. class:: Extensions
1509
1510 .. versionadded:: 0.9
1511
1512 An X.509 Extensions instance is an ordered list of extensions. The object
1513 is iterable to get every extension.
1514
Paul Kehrerfa56a232015-03-17 13:14:03 -05001515 .. method:: get_extension_for_oid(oid)
1516
1517 :param oid: An :class:`ObjectIdentifier` instance.
1518
1519 :returns: An instance of the extension class.
1520
1521 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1522 not have the extension requested.
1523
Paul Kehrerfa56a232015-03-17 13:14:03 -05001524 .. doctest::
1525
Paul Kehrere27f6582015-08-10 18:33:38 -05001526 >>> from cryptography.x509.oid import ExtensionOID
1527 >>> cert.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS)
Paul Kehrerfa56a232015-03-17 13:14:03 -05001528 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1529
Phoebe Queen019b7f82015-08-12 03:52:03 +01001530 .. method:: get_extension_for_class(extclass)
1531
Phoebe Queen6a603eb2015-08-12 14:14:49 +01001532 .. versionadded:: 1.1
1533
Phoebe Queen019b7f82015-08-12 03:52:03 +01001534 :param extclass: An extension class.
1535
1536 :returns: An instance of the extension class.
1537
1538 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1539 not have the extension requested.
1540
1541 .. doctest::
1542
1543 >>> from cryptography import x509
1544 >>> cert.extensions.get_extension_for_class(x509.BasicConstraints)
1545 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1546
Paul Kehrer8cf26422015-03-21 09:50:24 -05001547.. class:: Extension
1548
1549 .. versionadded:: 0.9
1550
Paul Kehrer85894662015-03-22 13:19:31 -05001551 .. attribute:: oid
1552
1553 :type: :class:`ObjectIdentifier`
1554
Paul Kehrere27f6582015-08-10 18:33:38 -05001555 One of the :class:`~cryptography.x509.oid.ExtensionOID` OIDs.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001556
1557 .. attribute:: critical
1558
1559 :type: bool
1560
Paul Kehrer58b75692015-03-22 23:24:58 -05001561 Determines whether a given extension is critical or not. :rfc:`5280`
1562 requires that "A certificate-using system MUST reject the certificate
1563 if it encounters a critical extension it does not recognize or a
1564 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -05001565
Paul Kehrer85894662015-03-22 13:19:31 -05001566 .. attribute:: value
1567
1568 Returns an instance of the extension type corresponding to the OID.
1569
Paul Kehrer14f0bd02015-08-06 11:55:18 +01001570.. class:: ExtensionType
1571
1572 .. versionadded:: 1.0
1573
1574 This is the interface against which all the following extension types are
1575 registered.
1576
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001577.. class:: KeyUsage(digital_signature, content_commitment, key_encipherment, data_encipherment, key_agreement, key_cert_sign, crl_sign, encipher_only, decipher_only)
Paul Kehrercecbbba2015-03-30 14:58:38 -05001578
1579 .. versionadded:: 0.9
1580
1581 The key usage extension defines the purpose of the key contained in the
1582 certificate. The usage restriction might be employed when a key that could
Paul Kehrerb33de932015-08-06 23:41:05 +01001583 be used for more than one operation is to be restricted.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001584
Paul Kehrer822f3d32015-08-06 11:47:32 +01001585 .. attribute:: oid
1586
1587 .. versionadded:: 1.0
1588
1589 :type: :class:`ObjectIdentifier`
1590
Paul Kehrere27f6582015-08-10 18:33:38 -05001591 Returns :attr:`~cryptography.x509.oid.ExtensionOID.KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001592
Paul Kehrercecbbba2015-03-30 14:58:38 -05001593 .. attribute:: digital_signature
1594
1595 :type: bool
1596
Paul Kehrer738407b2015-04-01 22:39:02 -05001597 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001598 digital signatures, other than signatures on certificates
1599 (``key_cert_sign``) and CRLs (``crl_sign``).
1600
1601 .. attribute:: content_commitment
1602
1603 :type: bool
1604
Paul Kehrer738407b2015-04-01 22:39:02 -05001605 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001606 digital signatures, other than signatures on certificates
1607 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
1608 non-repudiation service that protects against the signing entity
1609 falsely denying some action. In the case of later conflict, a
1610 reliable third party may determine the authenticity of the signed
1611 data. This was called ``non_repudiation`` in older revisions of the
1612 X.509 specification.
1613
1614 .. attribute:: key_encipherment
1615
1616 :type: bool
1617
Paul Kehrer738407b2015-04-01 22:39:02 -05001618 This purpose is set to true when the subject public key is used for
1619 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001620
1621 .. attribute:: data_encipherment
1622
1623 :type: bool
1624
Paul Kehrer738407b2015-04-01 22:39:02 -05001625 This purpose is set to true when the subject public key is used for
1626 directly enciphering raw user data without the use of an intermediate
1627 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001628
1629 .. attribute:: key_agreement
1630
1631 :type: bool
1632
Paul Kehrer738407b2015-04-01 22:39:02 -05001633 This purpose is set to true when the subject public key is used for key
1634 agreement. For example, when a Diffie-Hellman key is to be used for
1635 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001636
1637 .. attribute:: key_cert_sign
1638
1639 :type: bool
1640
Paul Kehrer738407b2015-04-01 22:39:02 -05001641 This purpose is set to true when the subject public key is used for
1642 verifying signatures on public key certificates. If this purpose is set
1643 to true then ``ca`` must be true in the :class:`BasicConstraints`
1644 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001645
1646 .. attribute:: crl_sign
1647
1648 :type: bool
1649
Paul Kehrer738407b2015-04-01 22:39:02 -05001650 This purpose is set to true when the subject public key is used for
1651 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001652
1653 .. attribute:: encipher_only
1654
1655 :type: bool
1656
Paul Kehrer738407b2015-04-01 22:39:02 -05001657 When this purposes is set to true and the ``key_agreement`` purpose is
1658 also set, the subject public key may be used only for enciphering data
1659 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001660
1661 :raises ValueError: This is raised if accessed when ``key_agreement``
1662 is false.
1663
1664 .. attribute:: decipher_only
1665
1666 :type: bool
1667
Paul Kehrer738407b2015-04-01 22:39:02 -05001668 When this purposes is set to true and the ``key_agreement`` purpose is
1669 also set, the subject public key may be used only for deciphering data
1670 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001671
1672 :raises ValueError: This is raised if accessed when ``key_agreement``
1673 is false.
1674
1675
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001676.. class:: BasicConstraints(ca, path_length)
Paul Kehrer8cf26422015-03-21 09:50:24 -05001677
1678 .. versionadded:: 0.9
1679
Paul Kehrer85894662015-03-22 13:19:31 -05001680 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -05001681 certificate is allowed to sign additional certificates and what path
Paul Kehrerb33de932015-08-06 23:41:05 +01001682 length restrictions may exist.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001683
Paul Kehrer822f3d32015-08-06 11:47:32 +01001684 .. attribute:: oid
1685
1686 .. versionadded:: 1.0
1687
1688 :type: :class:`ObjectIdentifier`
1689
Paul Kehrere27f6582015-08-10 18:33:38 -05001690 Returns :attr:`~cryptography.x509.oid.ExtensionOID.BASIC_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001691
Paul Kehrer8cf26422015-03-21 09:50:24 -05001692 .. attribute:: ca
1693
1694 :type: bool
1695
1696 Whether the certificate can sign certificates.
1697
1698 .. attribute:: path_length
1699
Paul Kehrerfd1444c2015-03-21 19:47:05 -05001700 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -05001701
1702 The maximum path length for certificates subordinate to this
1703 certificate. This attribute only has meaning if ``ca`` is true.
1704 If ``ca`` is true then a path length of None means there's no
1705 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -04001706 If it is zero or greater then it defines the maximum length for a
1707 subordinate CA's certificate chain. For example, a ``path_length`` of 1
1708 means the certificate can sign a subordinate CA, but the subordinate CA
1709 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001710
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001711.. class:: ExtendedKeyUsage(usages)
Paul Kehrerffa2a152015-03-31 08:18:25 -05001712
1713 .. versionadded:: 0.9
1714
1715 This extension indicates one or more purposes for which the certified
1716 public key may be used, in addition to or in place of the basic
1717 purposes indicated in the key usage extension. The object is
Paul Kehrere27f6582015-08-10 18:33:38 -05001718 iterable to obtain the list of
1719 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs present.
Paul Kehrerffa2a152015-03-31 08:18:25 -05001720
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001721 :param list usages: A list of
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001722 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs.
1723
Paul Kehrer822f3d32015-08-06 11:47:32 +01001724 .. attribute:: oid
1725
1726 .. versionadded:: 1.0
1727
1728 :type: :class:`ObjectIdentifier`
1729
Paul Kehrere27f6582015-08-10 18:33:38 -05001730 Returns :attr:`~cryptography.x509.oid.ExtensionOID.EXTENDED_KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001731
1732
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001733.. class:: OCSPNoCheck()
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001734
Paul Kehrer506a2152015-05-26 08:01:18 -05001735 .. versionadded:: 1.0
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001736
1737 This presence of this extension indicates that an OCSP client can trust a
1738 responder for the lifetime of the responder's certificate. CAs issuing
1739 such a certificate should realize that a compromise of the responder's key
1740 is as serious as the compromise of a CA key used to sign CRLs, at least for
1741 the validity period of this certificate. CA's may choose to issue this type
1742 of certificate with a very short lifetime and renew it frequently. This
1743 extension is only relevant when the certificate is an authorized OCSP
1744 responder.
1745
Paul Kehrer822f3d32015-08-06 11:47:32 +01001746 .. attribute:: oid
1747
1748 .. versionadded:: 1.0
1749
1750 :type: :class:`ObjectIdentifier`
1751
Paul Kehrere27f6582015-08-10 18:33:38 -05001752 Returns :attr:`~cryptography.x509.oid.ExtensionOID.OCSP_NO_CHECK`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001753
Paul Kehrer5d669662017-09-11 09:16:34 +08001754
1755.. class:: TLSFeature(features)
1756
1757 .. versionadded:: 2.1
1758
1759 The TLS Feature extension is defined in :rfc:`7633` and is used in
1760 certificates for OCSP Must-Staple. The object is iterable to get every
1761 element.
1762
1763 :param list features: A list of features to enable from the
1764 :class:`~cryptography.x509.TLSFeatureType` enum. At this time only
1765 ``status_request`` or ``status_request_v2`` are allowed.
1766
1767 .. attribute:: oid
1768
1769 :type: :class:`ObjectIdentifier`
1770
1771 Returns :attr:`~cryptography.x509.oid.ExtensionOID.TLS_FEATURE`.
1772
1773.. class:: TLSFeatureType
1774
1775 .. versionadded:: 2.1
1776
1777 An enumeration of TLS Feature types.
1778
1779 .. attribute:: status_request
1780
1781 This feature type is defined in :rfc:`6066` and, when embedded in
1782 an X.509 certificate, signals to the client that it should require
1783 a stapled OCSP response in the TLS handshake. Commonly known as OCSP
1784 Must-Staple in certificates.
1785
1786 .. attribute:: status_request_v2
1787
1788 This feature type is defined in :rfc:`6961`. This value is not
1789 commonly used and if you want to enable OCSP Must-Staple you should
1790 use ``status_request``.
1791
1792
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001793.. class:: NameConstraints(permitted_subtrees, excluded_subtrees)
Paul Kehrere0017be2015-05-17 20:39:40 -06001794
1795 .. versionadded:: 1.0
1796
1797 The name constraints extension, which only has meaning in a CA certificate,
1798 defines a name space within which all subject names in certificates issued
1799 beneath the CA certificate must (or must not) be in. For specific details
1800 on the way this extension should be processed see :rfc:`5280`.
1801
Paul Kehrer822f3d32015-08-06 11:47:32 +01001802 .. attribute:: oid
1803
1804 .. versionadded:: 1.0
1805
1806 :type: :class:`ObjectIdentifier`
1807
Paul Kehrere27f6582015-08-10 18:33:38 -05001808 Returns :attr:`~cryptography.x509.oid.ExtensionOID.NAME_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001809
Paul Kehrere0017be2015-05-17 20:39:40 -06001810 .. attribute:: permitted_subtrees
1811
1812 :type: list of :class:`GeneralName` objects or None
1813
1814 The set of permitted name patterns. If a name matches this and an
1815 element in ``excluded_subtrees`` it is invalid. At least one of
1816 ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None.
1817
1818 .. attribute:: excluded_subtrees
1819
1820 :type: list of :class:`GeneralName` objects or None
1821
1822 Any name matching a restriction in the ``excluded_subtrees`` field is
1823 invalid regardless of information appearing in the
1824 ``permitted_subtrees``. At least one of ``permitted_subtrees`` and
1825 ``excluded_subtrees`` will be non-None.
1826
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001827.. class:: AuthorityKeyIdentifier(key_identifier, authority_cert_issuer, authority_cert_serial_number)
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001828
1829 .. versionadded:: 0.9
1830
1831 The authority key identifier extension provides a means of identifying the
1832 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001833 This extension is typically used to assist in determining the appropriate
1834 certificate chain. For more information about generation and use of this
1835 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001836
Paul Kehrer822f3d32015-08-06 11:47:32 +01001837 .. attribute:: oid
1838
1839 .. versionadded:: 1.0
1840
1841 :type: :class:`ObjectIdentifier`
1842
Paul Kehrere27f6582015-08-10 18:33:38 -05001843 Returns
1844 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001845
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001846 .. attribute:: key_identifier
1847
1848 :type: bytes
1849
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001850 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001851 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001852
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001853 .. attribute:: authority_cert_issuer
1854
Thom Dixon488c0482018-05-18 03:55:29 -07001855 :type: A list of :class:`GeneralName` instances or None
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001856
Lucia Lic6ba99d2021-11-08 22:06:11 +08001857 The :class:`GeneralName` (one or multiple) of the issuer's issuer.
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001858
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001859 .. attribute:: authority_cert_serial_number
1860
1861 :type: int or None
1862
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001863 The serial number of the issuer's issuer.
1864
Paul Kehrer253929a2015-08-05 17:30:39 +01001865 .. classmethod:: from_issuer_public_key(public_key)
1866
1867 .. versionadded:: 1.0
1868
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001869 .. note::
1870
1871 This method should be used if the issuer certificate does not
1872 contain a :class:`~cryptography.x509.SubjectKeyIdentifier`.
1873 Otherwise, use
1874 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier`.
1875
Paul Kehrer253929a2015-08-05 17:30:39 +01001876 Creates a new AuthorityKeyIdentifier instance using the public key
1877 provided to generate the appropriate digest. This should be the
Paul Kehrer26ac47f2015-08-08 15:20:52 -05001878 **issuer's public key**. The resulting object will contain
1879 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1880 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1881 and
1882 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1883 will be None.
1884 The generated ``key_identifier`` is the SHA1 hash of the ``subjectPublicKey``
1885 ASN.1 bit string. This is the first recommendation in :rfc:`5280`
Paul Kehrer253929a2015-08-05 17:30:39 +01001886 section 4.2.1.2.
1887
Paul Kehrercc671822015-08-08 15:41:54 -05001888 :param public_key: One of
Lucia Lic6ba99d2021-11-08 22:06:11 +08001889 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`,
1890 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`,
1891 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`,
1892 :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey` or
1893 :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PublicKey`.
Paul Kehrer253929a2015-08-05 17:30:39 +01001894
1895 .. doctest::
1896
1897 >>> from cryptography import x509
Lucia Lic6ba99d2021-11-08 22:06:11 +08001898 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data)
Paul Kehrercc671822015-08-08 15:41:54 -05001899 >>> x509.AuthorityKeyIdentifier.from_issuer_public_key(issuer_cert.public_key())
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001900 <AuthorityKeyIdentifier(key_identifier=b'X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9', authority_cert_issuer=None, authority_cert_serial_number=None)>
Paul Kehrer253929a2015-08-05 17:30:39 +01001901
Paul Kehrer61ff3562016-03-11 22:51:27 -04001902 .. classmethod:: from_issuer_subject_key_identifier(ski)
1903
1904 .. versionadded:: 1.3
1905
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001906 .. note::
1907 This method should be used if the issuer certificate contains a
1908 :class:`~cryptography.x509.SubjectKeyIdentifier`. Otherwise, use
1909 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_public_key`.
1910
Paul Kehrer61ff3562016-03-11 22:51:27 -04001911 Creates a new AuthorityKeyIdentifier instance using the
1912 SubjectKeyIdentifier from the issuer certificate. The resulting object
1913 will contain
1914 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1915 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1916 and
1917 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1918 will be None.
1919
1920 :param ski: The
1921 :class:`~cryptography.x509.SubjectKeyIdentifier` from the issuer
1922 certificate.
1923
1924 .. doctest::
1925
1926 >>> from cryptography import x509
Lucia Lic6ba99d2021-11-08 22:06:11 +08001927 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data)
1928 >>> ski_ext = issuer_cert.extensions.get_extension_for_class(x509.SubjectKeyIdentifier)
1929 >>> x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier(ski_ext.value)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001930 <AuthorityKeyIdentifier(key_identifier=b'X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9', authority_cert_issuer=None, authority_cert_serial_number=None)>
Paul Kehrer61ff3562016-03-11 22:51:27 -04001931
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001932.. class:: SubjectKeyIdentifier(digest)
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001933
1934 .. versionadded:: 0.9
1935
1936 The subject key identifier extension provides a means of identifying
1937 certificates that contain a particular public key.
1938
Paul Kehrer822f3d32015-08-06 11:47:32 +01001939 .. attribute:: oid
1940
1941 .. versionadded:: 1.0
1942
1943 :type: :class:`ObjectIdentifier`
1944
Paul Kehrere27f6582015-08-10 18:33:38 -05001945 Returns
1946 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001947
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001948 .. attribute:: digest
1949
1950 :type: bytes
1951
1952 The binary value of the identifier.
1953
Paul Kehrerd4a7f062015-08-05 18:32:18 +01001954 .. classmethod:: from_public_key(public_key)
Paul Kehrerf22f6122015-08-05 12:57:13 +01001955
1956 .. versionadded:: 1.0
1957
1958 Creates a new SubjectKeyIdentifier instance using the public key
1959 provided to generate the appropriate digest. This should be the public
Paul Kehrereb9ec002015-08-08 10:03:02 -05001960 key that is in the certificate. The generated digest is the SHA1 hash
1961 of the ``subjectPublicKey`` ASN.1 bit string. This is the first
1962 recommendation in :rfc:`5280` section 4.2.1.2.
Paul Kehrerf22f6122015-08-05 12:57:13 +01001963
1964 :param public_key: One of
Lucia Lic6ba99d2021-11-08 22:06:11 +08001965 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`,
1966 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`,
1967 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`,
1968 :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey` or
1969 :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PublicKey`.
Paul Kehrerf22f6122015-08-05 12:57:13 +01001970
Paul Kehrer253929a2015-08-05 17:30:39 +01001971 .. doctest::
1972
1973 >>> from cryptography import x509
Lucia Lic6ba99d2021-11-08 22:06:11 +08001974 >>> csr = x509.load_pem_x509_csr(pem_req_data)
Paul Kehrercc671822015-08-08 15:41:54 -05001975 >>> x509.SubjectKeyIdentifier.from_public_key(csr.public_key())
Lucia Lic6ba99d2021-11-08 22:06:11 +08001976 <SubjectKeyIdentifier(digest=b'\x8c"\x98\xe2\xb5\xbf]\xe8*2\xf8\xd2\'?\x00\xd2\xc7#\xe4c')>
Paul Kehrer253929a2015-08-05 17:30:39 +01001977
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001978.. class:: SubjectAlternativeName(general_names)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001979
1980 .. versionadded:: 0.9
1981
1982 Subject alternative name is an X.509 extension that provides a list of
1983 :ref:`general name <general_name_classes>` instances that provide a set
1984 of identities for which the certificate is valid. The object is iterable to
1985 get every element.
1986
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001987 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001988
Paul Kehrer822f3d32015-08-06 11:47:32 +01001989 .. attribute:: oid
1990
1991 .. versionadded:: 1.0
1992
1993 :type: :class:`ObjectIdentifier`
1994
Paul Kehrere27f6582015-08-10 18:33:38 -05001995 Returns
1996 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001997
Paul Kehrer31bdf792015-03-25 14:11:00 -05001998 .. method:: get_values_for_type(type)
1999
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03002000 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer31bdf792015-03-25 14:11:00 -05002001 :ref:`general name classes <general_name_classes>`.
2002
2003 :returns: A list of values extracted from the matched general names.
Joshua Taubererd2afad32015-07-06 22:37:53 +00002004 The type of the returned values depends on the :class:`GeneralName`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05002005
Paul Kehrer93ae8052015-05-02 23:18:09 -05002006 .. doctest::
2007
2008 >>> from cryptography import x509
Paul Kehrer93ae8052015-05-02 23:18:09 -05002009 >>> from cryptography.hazmat.primitives import hashes
Lucia Lic6ba99d2021-11-08 22:06:11 +08002010 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem)
Paul Kehrerd0cd5072015-05-02 23:27:00 -05002011 >>> # Get the subjectAltName extension from the certificate
Paul Kehrere27f6582015-08-10 18:33:38 -05002012 >>> ext = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -05002013 >>> # Get the dNSName entries from the SAN extension
2014 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04002015 ['www.cryptography.io', 'cryptography.io']
Paul Kehrer93ae8052015-05-02 23:18:09 -05002016
Paul Kehrer8cf26422015-03-21 09:50:24 -05002017
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002018.. class:: IssuerAlternativeName(general_names)
Paul Kehrer99125c92015-06-07 18:37:10 -05002019
2020 .. versionadded:: 1.0
2021
2022 Issuer alternative name is an X.509 extension that provides a list of
2023 :ref:`general name <general_name_classes>` instances that provide a set
2024 of identities for the certificate issuer. The object is iterable to
2025 get every element.
2026
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002027 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002028
Paul Kehrer822f3d32015-08-06 11:47:32 +01002029 .. attribute:: oid
2030
2031 .. versionadded:: 1.0
2032
2033 :type: :class:`ObjectIdentifier`
2034
Paul Kehrere27f6582015-08-10 18:33:38 -05002035 Returns
2036 :attr:`~cryptography.x509.oid.ExtensionOID.ISSUER_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002037
Paul Kehrer99125c92015-06-07 18:37:10 -05002038 .. method:: get_values_for_type(type)
2039
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03002040 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer99125c92015-06-07 18:37:10 -05002041 :ref:`general name classes <general_name_classes>`.
2042
2043 :returns: A list of values extracted from the matched general names.
2044
2045
Alex Gaynor6a0718f2017-06-04 13:36:58 -04002046.. class:: PrecertificateSignedCertificateTimestamps(scts)
2047
2048 .. versionadded:: 2.0
2049
2050 This extension contains
2051 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2052 instances which were issued for the pre-certificate corresponding to this
2053 certificate. These can be used to verify that the certificate is included
2054 in a public Certificate Transparency log.
2055
2056 It is an iterable containing one or more
2057 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2058 objects.
2059
2060 :param list scts: A ``list`` of
2061 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2062 objects.
2063
2064 .. attribute:: oid
2065
2066 :type: :class:`ObjectIdentifier`
2067
2068 Returns
2069 :attr:`~cryptography.x509.oid.ExtensionOID.PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS`.
2070
2071
Alex Gaynordd6b78b2018-08-31 18:25:52 -05002072.. class:: PrecertPoison()
2073
2074 .. versionadded:: 2.4
2075
2076 This extension indicates that the certificate should not be treated as a
2077 certificate for the purposes of validation, but is instead for submission
2078 to a certificate transparency log in order to obtain SCTs which will be
2079 embedded in a :class:`PrecertificateSignedCertificateTimestamps` extension
2080 on the final certificate.
2081
2082 .. attribute:: oid
2083
2084 :type: :class:`ObjectIdentifier`
2085
2086 Returns :attr:`~cryptography.x509.oid.ExtensionOID.PRECERT_POISON`.
2087
2088
Lucia Lic6ba99d2021-11-08 22:06:11 +08002089.. class:: SignedCertificateTimestamps(scts)
2090
2091 .. versionadded:: 3.0
2092
2093 This extension contains
2094 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2095 instances. These can be used to verify that the certificate is included
2096 in a public Certificate Transparency log. This extension is only found
2097 in OCSP responses. For SCTs in an X.509 certificate see
2098 :class:`~cryptography.x509.PrecertificateSignedCertificateTimestamps`.
2099
2100 It is an iterable containing one or more
2101 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2102 objects.
2103
2104 :param list scts: A ``list`` of
2105 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2106 objects.
2107
2108 .. attribute:: oid
2109
2110 :type: :class:`ObjectIdentifier`
2111
2112 Returns
2113 :attr:`~cryptography.x509.oid.ExtensionOID.SIGNED_CERTIFICATE_TIMESTAMPS`.
2114
2115
Paul Kehrer5e3cc982017-09-22 21:29:36 +08002116.. class:: DeltaCRLIndicator(crl_number)
2117
2118 .. versionadded:: 2.1
2119
2120 The delta CRL indicator is a CRL extension that identifies a CRL as being
2121 a delta CRL. Delta CRLs contain updates to revocation information
2122 previously distributed, rather than all the information that would appear
2123 in a complete CRL.
2124
2125 :param int crl_number: The CRL number of the complete CRL that the
2126 delta CRL is updating.
2127
2128 .. attribute:: oid
2129
2130 :type: :class:`ObjectIdentifier`
2131
2132 Returns
2133 :attr:`~cryptography.x509.oid.ExtensionOID.DELTA_CRL_INDICATOR`.
2134
2135 .. attribute:: crl_number
2136
2137 :type: int
2138
2139
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002140.. class:: AuthorityInformationAccess(descriptions)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002141
2142 .. versionadded:: 0.9
2143
2144 The authority information access extension indicates how to access
2145 information and services for the issuer of the certificate in which
2146 the extension appears. Information and services may include online
2147 validation services (such as OCSP) and issuer data. It is an iterable,
Paul Kehrere27f6582015-08-10 18:33:38 -05002148 containing one or more :class:`~cryptography.x509.AccessDescription`
2149 instances.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002150
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002151 :param list descriptions: A list of :class:`AccessDescription` objects.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002152
Paul Kehrer822f3d32015-08-06 11:47:32 +01002153 .. attribute:: oid
2154
2155 .. versionadded:: 1.0
2156
2157 :type: :class:`ObjectIdentifier`
2158
Paul Kehrere27f6582015-08-10 18:33:38 -05002159 Returns
2160 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_INFORMATION_ACCESS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002161
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002162
Lucia Lic6ba99d2021-11-08 22:06:11 +08002163.. class:: SubjectInformationAccess(descriptions)
2164
2165 .. versionadded:: 3.0
2166
2167 The subject information access extension indicates how to access
2168 information and services for the subject of the certificate in which
2169 the extension appears. When the subject is a CA, information and
2170 services may include certificate validation services and CA policy
2171 data. When the subject is an end entity, the information describes
2172 the type of services offered and how to access them. It is an iterable,
2173 containing one or more :class:`~cryptography.x509.AccessDescription`
2174 instances.
2175
2176 :param list descriptions: A list of :class:`AccessDescription` objects.
2177
2178 .. attribute:: oid
2179
2180 :type: :class:`ObjectIdentifier`
2181
2182 Returns
2183 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_INFORMATION_ACCESS`.
2184
2185
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002186.. class:: AccessDescription(access_method, access_location)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002187
Paul Kehrer5a485522015-05-06 00:29:12 -05002188 .. versionadded:: 0.9
2189
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002190 .. attribute:: access_method
2191
2192 :type: :class:`ObjectIdentifier`
2193
Paul Kehrerf506bca2015-05-02 22:31:47 -05002194 The access method defines what the ``access_location`` means. It must
Lucia Lic6ba99d2021-11-08 22:06:11 +08002195 be
Paul Kehrere27f6582015-08-10 18:33:38 -05002196 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP` or
Lucia Lic6ba99d2021-11-08 22:06:11 +08002197 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`
2198 when used with :class:`~cryptography.x509.AuthorityInformationAccess`
2199 or
2200 :attr:`~cryptography.x509.oid.SubjectInformationAccessOID.CA_REPOSITORY`
2201 when used with :class:`~cryptography.x509.SubjectInformationAccess`.
2202
Paul Kehrere27f6582015-08-10 18:33:38 -05002203 If it is
2204 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP`
2205 the access location will be where to obtain OCSP
2206 information for the certificate. If it is
2207 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`
2208 the access location will provide additional information about the
Lucia Lic6ba99d2021-11-08 22:06:11 +08002209 issuing certificate. Finally, if it is
2210 :attr:`~cryptography.x509.oid.SubjectInformationAccessOID.CA_REPOSITORY`
2211 the access location will be the location of the CA's repository.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002212
2213 .. attribute:: access_location
2214
2215 :type: :class:`GeneralName`
2216
Paul Kehrerf506bca2015-05-02 22:31:47 -05002217 Where to access the information defined by the access method.
2218
Paul Kehrerb76bcf82017-09-24 08:44:12 +08002219.. class:: FreshestCRL(distribution_points)
2220
2221 .. versionadded:: 2.1
2222
2223 The freshest CRL extension (also known as Delta CRL Distribution Point)
2224 identifies how delta CRL information is obtained. It is an iterable,
2225 containing one or more :class:`DistributionPoint` instances.
2226
2227 :param list distribution_points: A list of :class:`DistributionPoint`
2228 instances.
2229
2230 .. attribute:: oid
2231
2232 :type: :class:`ObjectIdentifier`
2233
2234 Returns
2235 :attr:`~cryptography.x509.oid.ExtensionOID.FRESHEST_CRL`.
2236
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002237.. class:: CRLDistributionPoints(distribution_points)
Paul Kehrer5a485522015-05-06 00:29:12 -05002238
2239 .. versionadded:: 0.9
2240
2241 The CRL distribution points extension identifies how CRL information is
2242 obtained. It is an iterable, containing one or more
2243 :class:`DistributionPoint` instances.
2244
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002245 :param list distribution_points: A list of :class:`DistributionPoint`
2246 instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002247
Paul Kehrer822f3d32015-08-06 11:47:32 +01002248 .. attribute:: oid
2249
2250 .. versionadded:: 1.0
2251
2252 :type: :class:`ObjectIdentifier`
2253
Paul Kehrere27f6582015-08-10 18:33:38 -05002254 Returns
2255 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_DISTRIBUTION_POINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002256
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002257.. class:: DistributionPoint(full_name, relative_name, reasons, crl_issuer)
Paul Kehrer5a485522015-05-06 00:29:12 -05002258
2259 .. versionadded:: 0.9
2260
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002261 .. attribute:: full_name
Paul Kehrer5a485522015-05-06 00:29:12 -05002262
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002263 :type: list of :class:`GeneralName` instances or None
Paul Kehrer5a485522015-05-06 00:29:12 -05002264
Paul Kehrerf2c072b2015-05-09 17:04:28 -05002265 This field describes methods to retrieve the CRL. At most one of
2266 ``full_name`` or ``relative_name`` will be non-None.
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002267
2268 .. attribute:: relative_name
2269
Fraser Tweedale02467dd2016-11-07 15:54:04 +10002270 :type: :class:`RelativeDistinguishedName` or None
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002271
2272 This field describes methods to retrieve the CRL relative to the CRL
Paul Kehrerf2c072b2015-05-09 17:04:28 -05002273 issuer. At most one of ``full_name`` or ``relative_name`` will be
2274 non-None.
Paul Kehrer5a485522015-05-06 00:29:12 -05002275
Fraser Tweedale02467dd2016-11-07 15:54:04 +10002276 .. versionchanged:: 1.6
2277 Changed from :class:`Name` to :class:`RelativeDistinguishedName`.
2278
Paul Kehrer5a485522015-05-06 00:29:12 -05002279 .. attribute:: crl_issuer
2280
2281 :type: list of :class:`GeneralName` instances or None
2282
2283 Information about the issuer of the CRL.
2284
2285 .. attribute:: reasons
2286
Paul Kehrer3fd02602015-05-09 19:46:13 -05002287 :type: frozenset of :class:`ReasonFlags` or None
Paul Kehrer5a485522015-05-06 00:29:12 -05002288
2289 The reasons a given distribution point may be used for when performing
2290 revocation checks.
2291
2292.. class:: ReasonFlags
2293
2294 .. versionadded:: 0.9
2295
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002296 An enumeration for CRL reasons.
2297
2298 .. attribute:: unspecified
2299
2300 It is unspecified why the certificate was revoked. This reason cannot
2301 be used as a reason flag in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05002302
2303 .. attribute:: key_compromise
2304
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002305 This reason indicates that the private key was compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05002306
2307 .. attribute:: ca_compromise
2308
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002309 This reason indicates that the CA issuing the certificate was
2310 compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05002311
2312 .. attribute:: affiliation_changed
2313
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002314 This reason indicates that the subject's name or other information has
2315 changed.
Paul Kehrer5a485522015-05-06 00:29:12 -05002316
2317 .. attribute:: superseded
2318
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002319 This reason indicates that a certificate has been superseded.
Paul Kehrer5a485522015-05-06 00:29:12 -05002320
2321 .. attribute:: cessation_of_operation
2322
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002323 This reason indicates that the certificate is no longer required.
Paul Kehrer5a485522015-05-06 00:29:12 -05002324
2325 .. attribute:: certificate_hold
2326
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002327 This reason indicates that the certificate is on hold.
Paul Kehrer5a485522015-05-06 00:29:12 -05002328
2329 .. attribute:: privilege_withdrawn
2330
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002331 This reason indicates that the privilege granted by this certificate
2332 have been withdrawn.
Paul Kehrer5a485522015-05-06 00:29:12 -05002333
2334 .. attribute:: aa_compromise
2335
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002336 When an attribute authority has been compromised.
2337
2338 .. attribute:: remove_from_crl
2339
2340 This reason indicates that the certificate was on hold and should be
2341 removed from the CRL. This reason cannot be used as a reason flag
2342 in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05002343
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002344.. class:: InhibitAnyPolicy(skip_certs)
Paul Kehrer16fae762015-05-01 23:14:20 -05002345
2346 .. versionadded:: 1.0
2347
2348 The inhibit ``anyPolicy`` extension indicates that the special OID
Paul Kehrere27f6582015-08-10 18:33:38 -05002349 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY`, is not
2350 considered an explicit match for other :class:`CertificatePolicies` except
2351 when it appears in an intermediate self-issued CA certificate. The value
2352 indicates the number of additional non-self-issued certificates that may
2353 appear in the path before
2354 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` is no
2355 longer permitted. For example, a value of one indicates that
2356 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` may be
2357 processed in certificates issued by the subject of this certificate, but
2358 not in additional certificates in the path.
Paul Kehrer16fae762015-05-01 23:14:20 -05002359
Paul Kehrer822f3d32015-08-06 11:47:32 +01002360 .. attribute:: oid
2361
2362 .. versionadded:: 1.0
2363
2364 :type: :class:`ObjectIdentifier`
2365
Paul Kehrere27f6582015-08-10 18:33:38 -05002366 Returns
2367 :attr:`~cryptography.x509.oid.ExtensionOID.INHIBIT_ANY_POLICY`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002368
Paul Kehrer16fae762015-05-01 23:14:20 -05002369 .. attribute:: skip_certs
2370
2371 :type: int
2372
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002373.. class:: PolicyConstraints
2374
2375 .. versionadded:: 1.3
2376
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002377 The policy constraints extension is used to inhibit policy mapping or
2378 require that each certificate in a chain contain an acceptable policy
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002379 identifier. For more information about the use of this extension see
2380 :rfc:`5280`.
2381
Paul Kehrer159b3b52016-02-26 08:27:22 -06002382 .. attribute:: oid
2383
2384 :type: :class:`ObjectIdentifier`
2385
2386 Returns :attr:`~cryptography.x509.oid.ExtensionOID.POLICY_CONSTRAINTS`.
2387
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002388 .. attribute:: require_explicit_policy
2389
2390 :type: int or None
2391
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002392 If this field is not None, the value indicates the number of additional
2393 certificates that may appear in the chain before an explicit policy is
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002394 required for the entire path. When an explicit policy is required, it
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002395 is necessary for all certificates in the chain to contain an acceptable
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002396 policy identifier in the certificate policies extension. An
2397 acceptable policy identifier is the identifier of a policy required
2398 by the user of the certification path or the identifier of a policy
2399 that has been declared equivalent through policy mapping.
2400
2401 .. attribute:: inhibit_policy_mapping
2402
2403 :type: int or None
2404
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002405 If this field is not None, the value indicates the number of additional
2406 certificates that may appear in the chain before policy mapping is no
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002407 longer permitted. For example, a value of one indicates that policy
2408 mapping may be processed in certificates issued by the subject of this
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002409 certificate, but not in additional certificates in the chain.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002410
Paul Kehrer3b95cd72015-12-22 21:40:20 -06002411.. class:: CRLNumber(crl_number)
2412
2413 .. versionadded:: 1.2
2414
Paul Kehrere32b9942015-12-22 22:26:53 -06002415 The CRL number is a CRL extension that conveys a monotonically increasing
2416 sequence number for a given CRL scope and CRL issuer. This extension allows
2417 users to easily determine when a particular CRL supersedes another CRL.
2418 :rfc:`5280` requires that this extension be present in conforming CRLs.
Paul Kehrer3b95cd72015-12-22 21:40:20 -06002419
2420 .. attribute:: oid
2421
2422 :type: :class:`ObjectIdentifier`
2423
2424 Returns
2425 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_NUMBER`.
2426
2427 .. attribute:: crl_number
2428
2429 :type: int
2430
Paul Kehrereb3e2e02018-12-01 12:15:20 +08002431.. class:: IssuingDistributionPoint(full_name, relative_name,\
2432 only_contains_user_certs, only_contains_ca_certs, only_some_reasons,\
2433 indirect_crl, only_contains_attribute_certs)
2434
2435 .. versionadded:: 2.5
2436
2437 Issuing distribution point is a CRL extension that identifies the CRL
2438 distribution point and scope for a particular CRL. It indicates whether
2439 the CRL covers revocation for end entity certificates only, CA certificates
2440 only, attribute certificates only, or a limited set of reason codes. For
2441 specific details on the way this extension should be processed see
2442 :rfc:`5280`.
2443
2444 .. attribute:: oid
2445
2446 :type: :class:`ObjectIdentifier`
2447
2448 Returns
2449 :attr:`~cryptography.x509.oid.ExtensionOID.ISSUING_DISTRIBUTION_POINT`.
2450
2451 .. attribute:: only_contains_user_certs
2452
2453 :type: bool
2454
2455 Set to ``True`` if the CRL this extension is embedded within only
2456 contains information about user certificates.
2457
2458 .. attribute:: only_contains_ca_certs
2459
2460 :type: bool
2461
2462 Set to ``True`` if the CRL this extension is embedded within only
2463 contains information about CA certificates.
2464
2465 .. attribute:: indirect_crl
2466
2467 :type: bool
2468
2469 Set to ``True`` if the CRL this extension is embedded within includes
2470 certificates issued by one or more authorities other than the CRL
2471 issuer.
2472
2473 .. attribute:: only_contains_attribute_certs
2474
2475 :type: bool
2476
2477 Set to ``True`` if the CRL this extension is embedded within only
2478 contains information about attribute certificates.
2479
2480 .. attribute:: only_some_reasons
2481
2482 :type: frozenset of :class:`ReasonFlags` or None
2483
2484 The reasons for which the issuing distribution point is valid. None
2485 indicates that it is valid for all reasons.
2486
2487 .. attribute:: full_name
2488
2489 :type: list of :class:`GeneralName` instances or None
2490
2491 This field describes methods to retrieve the CRL. At most one of
2492 ``full_name`` or ``relative_name`` will be non-None.
2493
2494 .. attribute:: relative_name
2495
2496 :type: :class:`RelativeDistinguishedName` or None
2497
2498 This field describes methods to retrieve the CRL relative to the CRL
2499 issuer. At most one of ``full_name`` or ``relative_name`` will be
2500 non-None.
2501
Paul Kehrer14fd6972015-12-30 10:58:25 -06002502.. class:: UnrecognizedExtension
2503
2504 .. versionadded:: 1.2
2505
Alex Gaynord08ddd52017-05-20 09:01:54 -07002506 A generic extension class used to hold the raw value of extensions that
Lucia Lic6ba99d2021-11-08 22:06:11 +08002507 ``cryptography`` does not know how to parse. This can also be used when
2508 creating new certificates, CRLs, or OCSP requests and responses to encode
2509 extensions that ``cryptography`` does not know how to generate.
Paul Kehrer14fd6972015-12-30 10:58:25 -06002510
2511 .. attribute:: oid
2512
2513 :type: :class:`ObjectIdentifier`
2514
2515 Returns the OID associated with this extension.
2516
2517 .. attribute:: value
2518
Paul Kehreredfedc12018-09-14 18:24:20 -04002519 :type: bytes
Paul Kehrer14fd6972015-12-30 10:58:25 -06002520
2521 Returns the DER encoded bytes payload of the extension.
2522
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002523.. class:: CertificatePolicies(policies)
Paul Kehrer0d210922015-04-28 17:31:07 -05002524
2525 .. versionadded:: 0.9
2526
Paul Kehrer2e879742015-05-02 23:09:56 -05002527 The certificate policies extension is an iterable, containing one or more
2528 :class:`PolicyInformation` instances.
Paul Kehrer0d210922015-04-28 17:31:07 -05002529
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002530 :param list policies: A list of :class:`PolicyInformation` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002531
Lucia Lic6ba99d2021-11-08 22:06:11 +08002532 As an example of how ``CertificatePolicies`` might be used, if you wanted
2533 to check if a certificated contained the CAB Forum's "domain-validated"
2534 policy, you might write code like:
2535
2536 .. code-block:: python
2537
2538 def contains_domain_validated(policies):
2539 return any(
2540 policy.oid.dotted_string == "2.23.140.1.2.1"
2541 for policy in policies
2542 )
2543
Paul Kehrer822f3d32015-08-06 11:47:32 +01002544 .. attribute:: oid
2545
2546 .. versionadded:: 1.0
2547
2548 :type: :class:`ObjectIdentifier`
2549
Paul Kehrere27f6582015-08-10 18:33:38 -05002550 Returns
2551 :attr:`~cryptography.x509.oid.ExtensionOID.CERTIFICATE_POLICIES`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002552
Paul Kehrer0d210922015-04-28 17:31:07 -05002553Certificate Policies Classes
2554~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2555
2556These classes may be present within a :class:`CertificatePolicies` instance.
2557
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002558.. class:: PolicyInformation(policy_identifier, policy_qualifiers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002559
2560 .. versionadded:: 0.9
2561
2562 Contains a policy identifier and an optional list of qualifiers.
2563
2564 .. attribute:: policy_identifier
2565
2566 :type: :class:`ObjectIdentifier`
2567
2568 .. attribute:: policy_qualifiers
2569
2570 :type: list
2571
Paul Kehrerba35b3b2015-05-10 13:07:59 -05002572 A list consisting of :term:`text` and/or :class:`UserNotice` objects.
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002573 If the value is text it is a pointer to the practice statement
2574 published by the certificate authority. If it is a user notice it is
2575 meant for display to the relying party when the certificate is
2576 used.
Paul Kehrer2e879742015-05-02 23:09:56 -05002577
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002578.. class:: UserNotice(notice_reference, explicit_text)
Paul Kehrer0d210922015-04-28 17:31:07 -05002579
2580 .. versionadded:: 0.9
2581
Paul Kehrer2e879742015-05-02 23:09:56 -05002582 User notices are intended for display to a relying party when a certificate
2583 is used. In practice, few if any UIs expose this data and it is a rarely
2584 encoded component.
2585
Paul Kehrer0d210922015-04-28 17:31:07 -05002586 .. attribute:: notice_reference
2587
2588 :type: :class:`NoticeReference` or None
2589
Paul Kehrer2e879742015-05-02 23:09:56 -05002590 The notice reference field names an organization and identifies,
2591 by number, a particular statement prepared by that organization.
2592
Paul Kehrer0d210922015-04-28 17:31:07 -05002593 .. attribute:: explicit_text
2594
Paul Kehrer2e879742015-05-02 23:09:56 -05002595 This field includes an arbitrary textual statement directly in the
2596 certificate.
2597
Paul Kehrer0d210922015-04-28 17:31:07 -05002598 :type: :term:`text`
2599
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002600.. class:: NoticeReference(organization, notice_numbers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002601
Paul Kehrer2e879742015-05-02 23:09:56 -05002602 Notice reference can name an organization and provide information about
2603 notices related to the certificate. For example, it might identify the
2604 organization name and notice number 1. Application software could
2605 have a notice file containing the current set of notices for the named
2606 organization; the application would then extract the notice text from the
2607 file and display it. In practice this is rarely seen.
2608
Paul Kehrer0d210922015-04-28 17:31:07 -05002609 .. versionadded:: 0.9
2610
2611 .. attribute:: organization
2612
Paul Kehrer66c61702015-05-12 16:39:18 -05002613 :type: :term:`text`
Paul Kehrer0d210922015-04-28 17:31:07 -05002614
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002615 .. attribute:: notice_numbers
Paul Kehrer0d210922015-04-28 17:31:07 -05002616
Paul Kehrer66c61702015-05-12 16:39:18 -05002617 :type: list
Paul Kehrer0d210922015-04-28 17:31:07 -05002618
Paul Kehrer66c61702015-05-12 16:39:18 -05002619 A list of integers.
Paul Kehrer0d210922015-04-28 17:31:07 -05002620
Paul Kehrere5f152b2015-12-25 23:55:47 -06002621.. _crl_entry_extensions:
2622
Paul Kehrer49bb7562015-12-25 16:17:40 -06002623CRL Entry Extensions
2624~~~~~~~~~~~~~~~~~~~~
2625
2626These extensions are only valid within a :class:`RevokedCertificate` object.
2627
2628.. class:: CertificateIssuer(general_names)
2629
2630 .. versionadded:: 1.2
2631
2632 The certificate issuer is an extension that is only valid inside
2633 :class:`~cryptography.x509.RevokedCertificate` objects. If the
2634 ``indirectCRL`` property of the parent CRL's IssuingDistributionPoint
2635 extension is set, then this extension identifies the certificate issuer
2636 associated with the revoked certificate. The object is iterable to get
2637 every element.
2638
2639 :param list general_names: A list of :class:`GeneralName` instances.
2640
2641 .. attribute:: oid
2642
2643 :type: :class:`ObjectIdentifier`
2644
2645 Returns
2646 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CERTIFICATE_ISSUER`.
2647
2648 .. method:: get_values_for_type(type)
2649
2650 :param type: A :class:`GeneralName` instance. This is one of the
2651 :ref:`general name classes <general_name_classes>`.
2652
2653 :returns: A list of values extracted from the matched general names.
2654 The type of the returned values depends on the :class:`GeneralName`.
2655
Paul Kehrer7058ece2015-12-25 22:28:29 -06002656.. class:: CRLReason(reason)
2657
2658 .. versionadded:: 1.2
2659
2660 CRL reason (also known as ``reasonCode``) is an extension that is only
2661 valid inside :class:`~cryptography.x509.RevokedCertificate` objects. It
2662 identifies a reason for the certificate revocation.
2663
Paul Kehrerce4d0842017-09-20 22:14:26 +08002664 :param reason: An element from :class:`~cryptography.x509.ReasonFlags`.
Paul Kehrer7058ece2015-12-25 22:28:29 -06002665
2666 .. attribute:: oid
2667
2668 :type: :class:`ObjectIdentifier`
2669
2670 Returns
2671 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CRL_REASON`.
2672
2673 .. attribute:: reason
2674
2675 :type: An element from :class:`~cryptography.x509.ReasonFlags`
2676
Paul Kehrer23c0bbc2015-12-25 22:35:19 -06002677.. class:: InvalidityDate(invalidity_date)
2678
2679 .. versionadded:: 1.2
2680
2681 Invalidity date is an extension that is only valid inside
2682 :class:`~cryptography.x509.RevokedCertificate` objects. It provides
2683 the date on which it is known or suspected that the private key was
2684 compromised or that the certificate otherwise became invalid.
2685 This date may be earlier than the revocation date in the CRL entry,
2686 which is the date at which the CA processed the revocation.
2687
2688 :param invalidity_date: The :class:`datetime.datetime` when it is known
2689 or suspected that the private key was compromised.
2690
2691 .. attribute:: oid
2692
2693 :type: :class:`ObjectIdentifier`
2694
2695 Returns
2696 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.INVALIDITY_DATE`.
2697
2698 .. attribute:: invalidity_date
2699
2700 :type: :class:`datetime.datetime`
2701
Paul Kehrer09403102018-09-09 21:57:21 -05002702OCSP Extensions
2703~~~~~~~~~~~~~~~
2704
2705.. class:: OCSPNonce(nonce)
2706
2707 .. versionadded:: 2.4
2708
2709 OCSP nonce is an extension that is only valid inside
2710 :class:`~cryptography.x509.ocsp.OCSPRequest` and
2711 :class:`~cryptography.x509.ocsp.OCSPResponse` objects. The nonce
2712 cryptographically binds a request and a response to prevent replay attacks.
2713 In practice nonces are rarely used in OCSP due to the desire to precompute
2714 OCSP responses at large scale.
2715
2716 .. attribute:: oid
2717
2718 :type: :class:`ObjectIdentifier`
2719
2720 Returns
2721 :attr:`~cryptography.x509.oid.OCSPExtensionOID.NONCE`.
2722
2723 .. attribute:: nonce
2724
2725 :type: bytes
Paul Kehrer49bb7562015-12-25 16:17:40 -06002726
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002727Object Identifiers
2728~~~~~~~~~~~~~~~~~~
2729
Paul Kehrer4bb46492015-02-07 16:59:14 -06002730X.509 elements are frequently identified by :class:`ObjectIdentifier`
2731instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002732
Paul Kehrere27f6582015-08-10 18:33:38 -05002733.. currentmodule:: cryptography.x509.oid
Paul Kehrer56da2a52015-02-11 23:35:07 -06002734
Paul Kehrere27f6582015-08-10 18:33:38 -05002735.. class:: NameOID
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002736
Paul Kehrere27f6582015-08-10 18:33:38 -05002737 These OIDs are typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06002738
Paul Kehrere27f6582015-08-10 18:33:38 -05002739 .. versionadded:: 1.0
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002740
Paul Kehrere27f6582015-08-10 18:33:38 -05002741 .. attribute:: COMMON_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002742
Paul Kehrere27f6582015-08-10 18:33:38 -05002743 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
2744 name would be encoded here for server certificates. :rfc:`2818`
2745 deprecates this practice and names of that type should now be located
2746 in a :class:`~cryptography.x509.SubjectAlternativeName` extension.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002747
Paul Kehrere27f6582015-08-10 18:33:38 -05002748 .. attribute:: COUNTRY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002749
Paul Kehrere27f6582015-08-10 18:33:38 -05002750 Corresponds to the dotted string ``"2.5.4.6"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002751
Paul Kehrere27f6582015-08-10 18:33:38 -05002752 .. attribute:: LOCALITY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002753
Paul Kehrere27f6582015-08-10 18:33:38 -05002754 Corresponds to the dotted string ``"2.5.4.7"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002755
Paul Kehrere27f6582015-08-10 18:33:38 -05002756 .. attribute:: STATE_OR_PROVINCE_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002757
Paul Kehrere27f6582015-08-10 18:33:38 -05002758 Corresponds to the dotted string ``"2.5.4.8"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002759
Paul Kehrerc3b8ff62016-11-11 17:38:59 -08002760 .. attribute:: STREET_ADDRESS
2761
2762 .. versionadded:: 1.6
2763
2764 Corresponds to the dotted string ``"2.5.4.9"``.
2765
Paul Kehrere27f6582015-08-10 18:33:38 -05002766 .. attribute:: ORGANIZATION_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002767
Paul Kehrere27f6582015-08-10 18:33:38 -05002768 Corresponds to the dotted string ``"2.5.4.10"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002769
Paul Kehrere27f6582015-08-10 18:33:38 -05002770 .. attribute:: ORGANIZATIONAL_UNIT_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002771
Paul Kehrere27f6582015-08-10 18:33:38 -05002772 Corresponds to the dotted string ``"2.5.4.11"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002773
Paul Kehrere27f6582015-08-10 18:33:38 -05002774 .. attribute:: SERIAL_NUMBER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002775
Paul Kehrere27f6582015-08-10 18:33:38 -05002776 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from
2777 the serial number of the certificate itself (which can be obtained with
Chelsea Winfreee295f3a2016-06-02 21:15:54 -07002778 :func:`~cryptography.x509.Certificate.serial_number`).
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002779
Paul Kehrere27f6582015-08-10 18:33:38 -05002780 .. attribute:: SURNAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002781
Paul Kehrere27f6582015-08-10 18:33:38 -05002782 Corresponds to the dotted string ``"2.5.4.4"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002783
Paul Kehrere27f6582015-08-10 18:33:38 -05002784 .. attribute:: GIVEN_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002785
Paul Kehrere27f6582015-08-10 18:33:38 -05002786 Corresponds to the dotted string ``"2.5.4.42"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002787
Paul Kehrere27f6582015-08-10 18:33:38 -05002788 .. attribute:: TITLE
Paul Kehrer858b9b72015-02-05 09:50:31 -06002789
Paul Kehrere27f6582015-08-10 18:33:38 -05002790 Corresponds to the dotted string ``"2.5.4.12"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002791
Paul Kehrere27f6582015-08-10 18:33:38 -05002792 .. attribute:: GENERATION_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002793
Paul Kehrere27f6582015-08-10 18:33:38 -05002794 Corresponds to the dotted string ``"2.5.4.44"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002795
Paul Kehrerc7ab9312016-11-12 05:00:42 -08002796 .. attribute:: X500_UNIQUE_IDENTIFIER
Paul Kehrerc3b8ff62016-11-11 17:38:59 -08002797
2798 .. versionadded:: 1.6
2799
2800 Corresponds to the dotted string ``"2.5.4.45"``.
2801
Paul Kehrere27f6582015-08-10 18:33:38 -05002802 .. attribute:: DN_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002803
Paul Kehrere27f6582015-08-10 18:33:38 -05002804 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
2805 disambiguating information to add to the relative distinguished name of an
2806 entry. See :rfc:`2256`.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002807
Paul Kehrere27f6582015-08-10 18:33:38 -05002808 .. attribute:: PSEUDONYM
Paul Kehrer858b9b72015-02-05 09:50:31 -06002809
Paul Kehrere27f6582015-08-10 18:33:38 -05002810 Corresponds to the dotted string ``"2.5.4.65"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002811
Paul Kehrer36d5cd62016-11-19 22:05:26 +08002812 .. attribute:: USER_ID
2813
2814 .. versionadded:: 1.6
2815
2816 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.1"``.
2817
Paul Kehrere27f6582015-08-10 18:33:38 -05002818 .. attribute:: DOMAIN_COMPONENT
Paul Kehrer858b9b72015-02-05 09:50:31 -06002819
Paul Kehrere27f6582015-08-10 18:33:38 -05002820 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
2821 holding one component of a domain name. See :rfc:`4519`.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002822
Paul Kehrere27f6582015-08-10 18:33:38 -05002823 .. attribute:: EMAIL_ADDRESS
Paul Kehrer56da2a52015-02-11 23:35:07 -06002824
Paul Kehrere27f6582015-08-10 18:33:38 -05002825 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002826
Alex Gaynor1d3f2bf2015-12-19 12:15:09 -05002827 .. attribute:: JURISDICTION_COUNTRY_NAME
2828
2829 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.3"``.
2830
Alex Gaynor45e507f2015-12-19 13:44:23 -05002831 .. attribute:: JURISDICTION_LOCALITY_NAME
2832
2833 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.1"``.
2834
2835 .. attribute:: JURISDICTION_STATE_OR_PROVINCE_NAME
2836
2837 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.2"``.
2838
Alex Gaynora2293c82015-12-19 20:49:15 -05002839 .. attribute:: BUSINESS_CATEGORY
2840
2841 Corresponds to the dotted string ``"2.5.4.15"``.
2842
Paul Kehrer36d5cd62016-11-19 22:05:26 +08002843 .. attribute:: POSTAL_ADDRESS
2844
2845 .. versionadded:: 1.6
2846
2847 Corresponds to the dotted string ``"2.5.4.16"``.
2848
2849 .. attribute:: POSTAL_CODE
2850
2851 .. versionadded:: 1.6
2852
2853 Corresponds to the dotted string ``"2.5.4.17"``.
2854
Lucia Lic6ba99d2021-11-08 22:06:11 +08002855 .. attribute:: UNSTRUCTURED_NAME
2856
2857 .. versionadded:: 3.0
2858
2859 Corresponds to the dotted string ``"1.2.840.113549.1.9.2"``.
2860
Paul Kehrer56da2a52015-02-11 23:35:07 -06002861
Paul Kehrere27f6582015-08-10 18:33:38 -05002862.. class:: SignatureAlgorithmOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002863
Paul Kehrere27f6582015-08-10 18:33:38 -05002864 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002865
Paul Kehrere27f6582015-08-10 18:33:38 -05002866 .. attribute:: RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -06002867
Paul Kehrere27f6582015-08-10 18:33:38 -05002868 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
2869 an MD5 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002870
Paul Kehrere27f6582015-08-10 18:33:38 -05002871 .. attribute:: RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06002872
Paul Kehrere27f6582015-08-10 18:33:38 -05002873 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
2874 a SHA1 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002875
Paul Kehrere27f6582015-08-10 18:33:38 -05002876 .. attribute:: RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002877
Paul Kehrere27f6582015-08-10 18:33:38 -05002878 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
2879 a SHA224 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002880
Paul Kehrere27f6582015-08-10 18:33:38 -05002881 .. attribute:: RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002882
Paul Kehrere27f6582015-08-10 18:33:38 -05002883 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
2884 a SHA256 digest signed by an RSA key.
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002885
Paul Kehrere27f6582015-08-10 18:33:38 -05002886 .. attribute:: RSA_WITH_SHA384
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002887
Paul Kehrere27f6582015-08-10 18:33:38 -05002888 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
2889 a SHA384 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002890
Paul Kehrere27f6582015-08-10 18:33:38 -05002891 .. attribute:: RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -06002892
Paul Kehrere27f6582015-08-10 18:33:38 -05002893 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
2894 a SHA512 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002895
Marti Raudsepp33678062018-06-30 02:27:28 +03002896 .. attribute:: RSASSA_PSS
2897
2898 .. versionadded:: 2.3
2899
2900 Corresponds to the dotted string ``"1.2.840.113549.1.1.10"``. This is
2901 signed by an RSA key using the Probabilistic Signature Scheme (PSS)
Alex Gaynore5463cc2019-01-18 15:19:34 -06002902 padding from :rfc:`4055`. The hash function and padding are defined by
Marti Raudsepp33678062018-06-30 02:27:28 +03002903 signature algorithm parameters.
2904
Paul Kehrere27f6582015-08-10 18:33:38 -05002905 .. attribute:: ECDSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06002906
Paul Kehrere27f6582015-08-10 18:33:38 -05002907 Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1
2908 digest signed by an ECDSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002909
Paul Kehrere27f6582015-08-10 18:33:38 -05002910 .. attribute:: ECDSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002911
Paul Kehrere27f6582015-08-10 18:33:38 -05002912 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
2913 a SHA224 digest signed by an ECDSA key.
2914
2915 .. attribute:: ECDSA_WITH_SHA256
2916
2917 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
2918 a SHA256 digest signed by an ECDSA key.
2919
2920 .. attribute:: ECDSA_WITH_SHA384
2921
2922 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
2923 a SHA384 digest signed by an ECDSA key.
2924
2925 .. attribute:: ECDSA_WITH_SHA512
2926
2927 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
2928 a SHA512 digest signed by an ECDSA key.
2929
2930 .. attribute:: DSA_WITH_SHA1
2931
2932 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
2933 a SHA1 digest signed by a DSA key.
2934
2935 .. attribute:: DSA_WITH_SHA224
2936
2937 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
2938 a SHA224 digest signed by a DSA key.
2939
2940 .. attribute:: DSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002941
Paul Kehrere27f6582015-08-10 18:33:38 -05002942 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
2943 a SHA256 digest signed by a DSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002944
Lucia Lic6ba99d2021-11-08 22:06:11 +08002945 .. attribute:: ED25519
2946
2947 .. versionadded:: 2.8
2948
2949 Corresponds to the dotted string ``"1.3.101.112"``. This is a signature
2950 using an ed25519 key.
2951
2952 .. attribute:: ED448
2953
2954 .. versionadded:: 2.8
2955
2956 Corresponds to the dotted string ``"1.3.101.113"``. This is a signature
2957 using an ed448 key.
2958
Paul Kehrer56da2a52015-02-11 23:35:07 -06002959
Paul Kehrere27f6582015-08-10 18:33:38 -05002960.. class:: ExtendedKeyUsageOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002961
Paul Kehrere27f6582015-08-10 18:33:38 -05002962 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002963
Paul Kehrere27f6582015-08-10 18:33:38 -05002964 .. attribute:: SERVER_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002965
Paul Kehrere27f6582015-08-10 18:33:38 -05002966 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used
2967 to denote that a certificate may be used for TLS web server
2968 authentication.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002969
Paul Kehrere27f6582015-08-10 18:33:38 -05002970 .. attribute:: CLIENT_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002971
Paul Kehrere27f6582015-08-10 18:33:38 -05002972 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used
2973 to denote that a certificate may be used for TLS web client
2974 authentication.
Paul Kehrerffa2a152015-03-31 08:18:25 -05002975
Paul Kehrere27f6582015-08-10 18:33:38 -05002976 .. attribute:: CODE_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002977
Paul Kehrere27f6582015-08-10 18:33:38 -05002978 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used
2979 to denote that a certificate may be used for code signing.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002980
Paul Kehrere27f6582015-08-10 18:33:38 -05002981 .. attribute:: EMAIL_PROTECTION
Paul Kehrere1513fa2015-03-30 23:08:17 -05002982
Paul Kehrere27f6582015-08-10 18:33:38 -05002983 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used
2984 to denote that a certificate may be used for email protection.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002985
Paul Kehrere27f6582015-08-10 18:33:38 -05002986 .. attribute:: TIME_STAMPING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002987
Paul Kehrere27f6582015-08-10 18:33:38 -05002988 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used
2989 to denote that a certificate may be used for time stamping.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002990
Paul Kehrere27f6582015-08-10 18:33:38 -05002991 .. attribute:: OCSP_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002992
Paul Kehrere27f6582015-08-10 18:33:38 -05002993 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used
2994 to denote that a certificate may be used for signing OCSP responses.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002995
Alex Gaynorb7912ee2017-07-03 10:07:02 -04002996 .. attribute:: ANY_EXTENDED_KEY_USAGE
2997
2998 .. versionadded:: 2.0
2999
3000 Corresponds to the dotted string ``"2.5.29.37.0"``. This is used to
Lucia Lic6ba99d2021-11-08 22:06:11 +08003001 denote that a certificate may be used for _any_ purposes. However,
3002 :rfc:`5280` additionally notes that applications that require the
3003 presence of a particular purpose _MAY_ reject certificates that include
3004 the ``anyExtendedKeyUsage`` OID but not the particular OID expected for
3005 the application. Therefore, the presence of this OID does not mean a
3006 given application will accept the certificate for all purposes.
Alex Gaynorb7912ee2017-07-03 10:07:02 -04003007
Paul Kehrere1513fa2015-03-30 23:08:17 -05003008
Paul Kehrere27f6582015-08-10 18:33:38 -05003009.. class:: AuthorityInformationAccessOID
Paul Kehrere1513fa2015-03-30 23:08:17 -05003010
Paul Kehrere27f6582015-08-10 18:33:38 -05003011 .. versionadded:: 1.0
Paul Kehrere1513fa2015-03-30 23:08:17 -05003012
Paul Kehrere27f6582015-08-10 18:33:38 -05003013 .. attribute:: OCSP
Paul Kehrere1513fa2015-03-30 23:08:17 -05003014
Paul Kehrere27f6582015-08-10 18:33:38 -05003015 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
3016 identifier for OCSP data in
3017 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrere1513fa2015-03-30 23:08:17 -05003018
Paul Kehrere27f6582015-08-10 18:33:38 -05003019 .. attribute:: CA_ISSUERS
Paul Kehrer3e6d5582015-05-02 21:57:56 -05003020
Paul Kehrere27f6582015-08-10 18:33:38 -05003021 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
3022 identifier for CA issuer data in
3023 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05003024
Paul Kehrer3e6d5582015-05-02 21:57:56 -05003025
Lucia Lic6ba99d2021-11-08 22:06:11 +08003026.. class:: SubjectInformationAccessOID
3027
3028 .. versionadded:: 3.0
3029
3030 .. attribute:: CA_REPOSITORY
3031
3032 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.5"``. Used as the
3033 identifier for CA repository data in
3034 :class:`~cryptography.x509.AccessDescription` objects.
3035
3036
Paul Kehrere27f6582015-08-10 18:33:38 -05003037.. class:: CertificatePoliciesOID
Paul Kehrer3e6d5582015-05-02 21:57:56 -05003038
Paul Kehrere27f6582015-08-10 18:33:38 -05003039 .. versionadded:: 1.0
Paul Kehrer3e6d5582015-05-02 21:57:56 -05003040
Paul Kehrere27f6582015-08-10 18:33:38 -05003041 .. attribute:: CPS_QUALIFIER
Paul Kehrer2e879742015-05-02 23:09:56 -05003042
Paul Kehrere27f6582015-08-10 18:33:38 -05003043 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05003044
Paul Kehrere27f6582015-08-10 18:33:38 -05003045 .. attribute:: CPS_USER_NOTICE
Paul Kehrer2e879742015-05-02 23:09:56 -05003046
Paul Kehrere27f6582015-08-10 18:33:38 -05003047 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05003048
Paul Kehrere27f6582015-08-10 18:33:38 -05003049 .. attribute:: ANY_POLICY
Paul Kehrer2e879742015-05-02 23:09:56 -05003050
Paul Kehrere27f6582015-08-10 18:33:38 -05003051 Corresponds to the dotted string ``"2.5.29.32.0"``.
Paul Kehrer16fae762015-05-01 23:14:20 -05003052
Paul Kehrer16fae762015-05-01 23:14:20 -05003053
Paul Kehrere27f6582015-08-10 18:33:38 -05003054.. class:: ExtensionOID
Paul Kehrer5553d572015-03-23 21:08:01 -05003055
Paul Kehrere27f6582015-08-10 18:33:38 -05003056 .. versionadded:: 1.0
Paul Kehrer2bb94642015-03-21 09:54:17 -05003057
Paul Kehrere27f6582015-08-10 18:33:38 -05003058 .. attribute:: BASIC_CONSTRAINTS
Paul Kehrer2bb94642015-03-21 09:54:17 -05003059
Paul Kehrere27f6582015-08-10 18:33:38 -05003060 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
3061 :class:`~cryptography.x509.BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05003062
Paul Kehrere27f6582015-08-10 18:33:38 -05003063 .. attribute:: KEY_USAGE
Paul Kehrercecbbba2015-03-30 14:58:38 -05003064
Paul Kehrere27f6582015-08-10 18:33:38 -05003065 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
3066 :class:`~cryptography.x509.KeyUsage` extension type.
Paul Kehrercecbbba2015-03-30 14:58:38 -05003067
Paul Kehrere27f6582015-08-10 18:33:38 -05003068 .. attribute:: SUBJECT_ALTERNATIVE_NAME
Paul Kehrerd4f632e2015-05-12 08:25:42 -05003069
Paul Kehrere27f6582015-08-10 18:33:38 -05003070 Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the
3071 :class:`~cryptography.x509.SubjectAlternativeName` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05003072
Paul Kehrere27f6582015-08-10 18:33:38 -05003073 .. attribute:: ISSUER_ALTERNATIVE_NAME
Paul Kehrer99125c92015-06-07 18:37:10 -05003074
Paul Kehrere27f6582015-08-10 18:33:38 -05003075 Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the
3076 :class:`~cryptography.x509.IssuerAlternativeName` extension type.
Paul Kehrer99125c92015-06-07 18:37:10 -05003077
Paul Kehrere27f6582015-08-10 18:33:38 -05003078 .. attribute:: SUBJECT_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05003079
Paul Kehrere27f6582015-08-10 18:33:38 -05003080 Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the
3081 :class:`~cryptography.x509.SubjectKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05003082
Paul Kehrere27f6582015-08-10 18:33:38 -05003083 .. attribute:: NAME_CONSTRAINTS
Paul Kehrere0017be2015-05-17 20:39:40 -06003084
Paul Kehrere27f6582015-08-10 18:33:38 -05003085 Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the
3086 :class:`~cryptography.x509.NameConstraints` extension type.
Paul Kehrere0017be2015-05-17 20:39:40 -06003087
Paul Kehrere27f6582015-08-10 18:33:38 -05003088 .. attribute:: CRL_DISTRIBUTION_POINTS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05003089
Paul Kehrere27f6582015-08-10 18:33:38 -05003090 Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the
3091 :class:`~cryptography.x509.CRLDistributionPoints` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05003092
Paul Kehrere27f6582015-08-10 18:33:38 -05003093 .. attribute:: CERTIFICATE_POLICIES
Paul Kehrerd4f632e2015-05-12 08:25:42 -05003094
Paul Kehrere27f6582015-08-10 18:33:38 -05003095 Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the
3096 :class:`~cryptography.x509.CertificatePolicies` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05003097
Paul Kehrere27f6582015-08-10 18:33:38 -05003098 .. attribute:: AUTHORITY_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05003099
Paul Kehrere27f6582015-08-10 18:33:38 -05003100 Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the
3101 :class:`~cryptography.x509.AuthorityKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05003102
Paul Kehrere27f6582015-08-10 18:33:38 -05003103 .. attribute:: EXTENDED_KEY_USAGE
Paul Kehrerd4f632e2015-05-12 08:25:42 -05003104
Paul Kehrere27f6582015-08-10 18:33:38 -05003105 Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the
3106 :class:`~cryptography.x509.ExtendedKeyUsage` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05003107
Paul Kehrere27f6582015-08-10 18:33:38 -05003108 .. attribute:: AUTHORITY_INFORMATION_ACCESS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05003109
Paul Kehrere27f6582015-08-10 18:33:38 -05003110 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier
3111 for the :class:`~cryptography.x509.AuthorityInformationAccess` extension
3112 type.
Paul Kehrer56da2a52015-02-11 23:35:07 -06003113
Lucia Lic6ba99d2021-11-08 22:06:11 +08003114 .. attribute:: SUBJECT_INFORMATION_ACCESS
3115
3116 .. versionadded:: 3.0
3117
3118 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.11"``. The
3119 identifier for the :class:`~cryptography.x509.SubjectInformationAccess`
3120 extension type.
3121
Paul Kehrere27f6582015-08-10 18:33:38 -05003122 .. attribute:: INHIBIT_ANY_POLICY
Paul Kehrerb33de932015-08-06 23:41:05 +01003123
Paul Kehrere27f6582015-08-10 18:33:38 -05003124 Corresponds to the dotted string ``"2.5.29.54"``. The identifier
3125 for the :class:`~cryptography.x509.InhibitAnyPolicy` extension type.
Paul Kehrerb33de932015-08-06 23:41:05 +01003126
Paul Kehrere27f6582015-08-10 18:33:38 -05003127 .. attribute:: OCSP_NO_CHECK
Paul Kehrer4a1038e2015-05-18 10:28:31 -07003128
Paul Kehrere27f6582015-08-10 18:33:38 -05003129 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The
3130 identifier for the :class:`~cryptography.x509.OCSPNoCheck` extension
3131 type.
Paul Kehrer4a1038e2015-05-18 10:28:31 -07003132
Paul Kehrer5d669662017-09-11 09:16:34 +08003133 .. attribute:: TLS_FEATURE
3134
3135 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.24"``. The
3136 identifier for the :class:`~cryptography.x509.TLSFeature` extension
3137 type.
3138
Paul Kehrer51f39cb2015-12-21 21:17:39 -06003139 .. attribute:: CRL_NUMBER
3140
3141 Corresponds to the dotted string ``"2.5.29.20"``. The identifier for
3142 the ``CRLNumber`` extension type. This extension only has meaning
3143 for certificate revocation lists.
3144
Paul Kehrer5e3cc982017-09-22 21:29:36 +08003145 .. attribute:: DELTA_CRL_INDICATOR
3146
3147 .. versionadded:: 2.1
3148
3149 Corresponds to the dotted string ``"2.5.29.27"``. The identifier for
3150 the ``DeltaCRLIndicator`` extension type. This extension only has
3151 meaning for certificate revocation lists.
3152
Alex Gaynor9bab0ed2017-03-20 09:50:52 -04003153 .. attribute:: PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS
3154
3155 .. versionadded:: 1.9
3156
3157 Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.2"``.
3158
Alex Gaynordd6b78b2018-08-31 18:25:52 -05003159 .. attribute:: PRECERT_POISON
3160
3161 .. versionadded:: 2.4
3162
3163 Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.3"``.
3164
Lucia Lic6ba99d2021-11-08 22:06:11 +08003165 .. attribute:: SIGNED_CERTIFICATE_TIMESTAMPS
3166
3167 .. versionadded:: 3.0
3168
3169 Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.5"``.
3170
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07003171 .. attribute:: POLICY_CONSTRAINTS
3172
3173 Corresponds to the dotted string ``"2.5.29.36"``. The identifier for the
Paul Kehrer20f0df52016-02-26 08:37:13 -06003174 :class:`~cryptography.x509.PolicyConstraints` extension type.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07003175
Paul Kehrerb76bcf82017-09-24 08:44:12 +08003176 .. attribute:: FRESHEST_CRL
3177
3178 Corresponds to the dotted string ``"2.5.29.46"``. The identifier for the
3179 :class:`~cryptography.x509.FreshestCRL` extension type.
3180
Paul Kehrer6e756ae2018-10-29 02:07:40 +08003181 .. attribute:: ISSUING_DISTRIBUTION_POINT
3182
3183 .. versionadded:: 2.4
3184
3185 Corresponds to the dotted string ``"2.5.29.28"``.
3186
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07003187
Paul Kehrerc6242dc2015-12-25 16:36:46 -06003188.. class:: CRLEntryExtensionOID
3189
3190 .. versionadded:: 1.2
3191
3192 .. attribute:: CERTIFICATE_ISSUER
3193
3194 Corresponds to the dotted string ``"2.5.29.29"``.
3195
3196 .. attribute:: CRL_REASON
3197
3198 Corresponds to the dotted string ``"2.5.29.21"``.
3199
3200 .. attribute:: INVALIDITY_DATE
3201
3202 Corresponds to the dotted string ``"2.5.29.24"``.
3203
Paul Kehrer09403102018-09-09 21:57:21 -05003204
3205.. class:: OCSPExtensionOID
3206
3207 .. versionadded:: 2.4
3208
3209 .. attribute:: NONCE
3210
3211 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.2"``.
3212
Lucia Lic6ba99d2021-11-08 22:06:11 +08003213
3214.. class:: AttributeOID
3215
3216 .. versionadded:: 3.0
3217
3218 .. attribute:: CHALLENGE_PASSWORD
3219
3220 Corresponds to the dotted string ``"1.2.840.113549.1.9.7"``.
3221
3222 .. attribute:: UNSTRUCTURED_NAME
3223
3224 Corresponds to the dotted string ``"1.2.840.113549.1.9.2"``.
3225
Paul Kehrer8b89bcc2016-09-03 11:31:43 -05003226Helper Functions
3227~~~~~~~~~~~~~~~~
3228.. currentmodule:: cryptography.x509
3229
3230.. function:: random_serial_number()
3231
3232 .. versionadded:: 1.6
3233
3234 Generates a random serial number suitable for use when constructing
3235 certificates.
3236
Paul Kehrer912d3fb2015-01-29 11:19:22 -06003237Exceptions
3238~~~~~~~~~~
Paul Kehrere27f6582015-08-10 18:33:38 -05003239.. currentmodule:: cryptography.x509
Paul Kehrer912d3fb2015-01-29 11:19:22 -06003240
Paul Kehrere76cd272014-12-14 19:00:51 -06003241.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10003242
3243 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10003244
Paul Kehrerd5cccf72014-12-15 17:20:33 -06003245 .. attribute:: parsed_version
3246
Paul Kehrerbbffc402014-12-17 13:33:55 -06003247 :type: int
3248
3249 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06003250
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05003251.. class:: DuplicateExtension
3252
3253 This is raised when more than one X.509 extension of the same type is
3254 found within a certificate.
3255
3256 .. attribute:: oid
3257
3258 :type: :class:`ObjectIdentifier`
3259
3260 Returns the OID.
3261
Paul Kehrerfa56a232015-03-17 13:14:03 -05003262.. class:: ExtensionNotFound
3263
3264 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
3265 an extension OID that is not present in the certificate.
3266
3267 .. attribute:: oid
3268
3269 :type: :class:`ObjectIdentifier`
3270
3271 Returns the OID.
3272
Lucia Lic6ba99d2021-11-08 22:06:11 +08003273.. class:: AttributeNotFound
3274
3275 This is raised when calling
3276 :meth:`CertificateSigningRequest.get_attribute_for_oid` with
3277 an attribute OID that is not present in the request.
3278
3279 .. attribute:: oid
3280
3281 :type: :class:`ObjectIdentifier`
3282
3283 Returns the OID.
3284
Paul Kehrer9089c912015-04-20 22:15:20 -05003285.. class:: UnsupportedGeneralNameType
3286
3287 This is raised when a certificate contains an unsupported general name
3288 type in an extension.
3289
Paul Kehrerbed07352015-04-21 08:31:10 -05003290 .. attribute:: type
3291
Paul Kehrer0a621bf2015-04-22 09:22:56 -05003292 :type: int
3293
3294 The integer value of the unsupported type. The complete list of
3295 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05003296
Paul Kehrer016e08a2014-11-26 09:41:18 -10003297
Paul Kehrerc7c9a432015-04-19 09:20:13 -05003298.. _`RFC 5280 section 4.2.1.1`: https://tools.ietf.org/html/rfc5280#section-4.2.1.1
Paul Kehrer0a621bf2015-04-22 09:22:56 -05003299.. _`RFC 5280 section 4.2.1.6`: https://tools.ietf.org/html/rfc5280#section-4.2.1.6
Paul Kehrer8b89bcc2016-09-03 11:31:43 -05003300.. _`CABForum Guidelines`: https://cabforum.org/baseline-requirements-documents/