blob: 6b2f74cfd01b454bccfd190c948082b6d7a4178b [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-----
25 MIIC0zCCAbsCAQAwWTELMAkGA1UEBhMCVVMxETAPBgNVBAgMCElsbGlub2lzMRAw
26 DgYDVQQHDAdDaGljYWdvMREwDwYDVQQKDAhyNTA5IExMQzESMBAGA1UEAwwJaGVs
27 bG8uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqhZx+Mo9VRd9
28 vsnWWa6NBCws21rZ0+1B/JGgB4hDsZS7iDE4Bj5z4idheFRtl8bBbdjPknq7BfoF
29 8v15Zq/Zv7i2xMSDL+LUrTBZezRd4bRTGqCm6YJ5EYkhqdcqeZleHCFImguHoq1J
30 Fh0+kObQrTHXw3ZP57a3o1IvyIUA3nNoCBL0QQhwBXaDXOojMKNR+bqB5ve8GS1y
31 Elr0AM/+cJsfaIahNQUgFKx3Eu3GeEOMKYOAG1lycgdQdmTUybLrT3U7vkClTseM
32 xHg1r5En7ALjONIhqRuq3rddYahrP8HXozb3zUy3cJ7P6IeaosuvNzvMXOX9P6HD
33 Ha9urDAJ1wIDAQABoDUwMwYJKoZIhvcNAQkOMSYwJDAiBgNVHREEGzAZggl3b3Js
34 ZC5jb22CDHdoYXRldmVyLmNvbTANBgkqhkiG9w0BAQUFAAOCAQEAS4Ro6h+z52SK
35 YSLCYARpnEu/rmh4jdqndt8naqcNb6uLx9mlKZ2W9on9XDjnSdQD9q+ZP5aZfESw
36 R0+rJhW9ZrNa/g1pt6M24ihclHYDAxYMWxT1z/TXXGM3TmZZ6gfYlNE1kkBuODHa
37 UYsR/1Ht1E1EsmmUimt2n+zQR2K8T9Coa+boaUW/GsTEuz1aaJAkj5ZvTDiIhRG4
38 AOCqFZOLAQmCCNgJnnspD9hDz/Ons085LF5wnYjN4/Nsk5tS6AGs3xjZ3jPoOGGn
39 82WQ9m4dBGoVDZXsobVTaN592JEYwN5iu72zRn7Einb4V4H5y3yD2dD4yWPlt4pk
40 5wFkeYsZEA==
41 -----END CERTIFICATE REQUEST-----
42 """.strip()
43
Paul Kehrerd3dafbd2015-03-15 16:24:18 -050044 pem_data = b"""
45 -----BEGIN CERTIFICATE-----
46 MIIDfDCCAmSgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJVUzEf
47 MB0GA1UEChMWVGVzdCBDZXJ0aWZpY2F0ZXMgMjAxMTEVMBMGA1UEAxMMVHJ1c3Qg
48 QW5jaG9yMB4XDTEwMDEwMTA4MzAwMFoXDTMwMTIzMTA4MzAwMFowQDELMAkGA1UE
49 BhMCVVMxHzAdBgNVBAoTFlRlc3QgQ2VydGlmaWNhdGVzIDIwMTExEDAOBgNVBAMT
50 B0dvb2QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCQWJpHYo37
51 Xfb7oJSPe+WvfTlzIG21WQ7MyMbGtK/m8mejCzR6c+f/pJhEH/OcDSMsXq8h5kXa
52 BGqWK+vSwD/Pzp5OYGptXmGPcthDtAwlrafkGOS4GqIJ8+k9XGKs+vQUXJKsOk47
53 RuzD6PZupq4s16xaLVqYbUC26UcY08GpnoLNHJZS/EmXw1ZZ3d4YZjNlpIpWFNHn
54 UGmdiGKXUPX/9H0fVjIAaQwjnGAbpgyCumWgzIwPpX+ElFOUr3z7BoVnFKhIXze+
55 VmQGSWxZxvWDUN90Ul0tLEpLgk3OVxUB4VUGuf15OJOpgo1xibINPmWt14Vda2N9
56 yrNKloJGZNqLAgMBAAGjfDB6MB8GA1UdIwQYMBaAFOR9X9FclYYILAWuvnW2ZafZ
57 XahmMB0GA1UdDgQWBBRYAYQkG7wrUpRKPaUQchRR9a86yTAOBgNVHQ8BAf8EBAMC
58 AQYwFwYDVR0gBBAwDjAMBgpghkgBZQMCATABMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
59 KoZIhvcNAQELBQADggEBADWHlxbmdTXNwBL/llwhQqwnazK7CC2WsXBBqgNPWj7m
60 tvQ+aLG8/50Qc2Sun7o2VnwF9D18UUe8Gj3uPUYH+oSI1vDdyKcjmMbKRU4rk0eo
61 3UHNDXwqIVc9CQS9smyV+x1HCwL4TTrq+LXLKx/qVij0Yqk+UJfAtrg2jnYKXsCu
62 FMBQQnWCGrwa1g1TphRp/RmYHnMynYFmZrXtzFz+U9XEA7C+gPq4kqDI/iVfIT1s
63 6lBtdB50lrDVwl2oYfAvW/6sC2se2QleZidUmrziVNP4oEeXINokU6T6p//HM1FG
64 QYw2jOvpKcKtWCSAnegEbgsGYzATKjmPJPJ0npHFqzM=
65 -----END CERTIFICATE-----
66 """.strip()
67
Paul Kehrer93ae8052015-05-02 23:18:09 -050068 cryptography_cert_pem = b"""
69 -----BEGIN CERTIFICATE-----
70 MIIFvTCCBKWgAwIBAgICPyAwDQYJKoZIhvcNAQELBQAwRzELMAkGA1UEBhMCVVMx
71 FjAUBgNVBAoTDUdlb1RydXN0IEluYy4xIDAeBgNVBAMTF1JhcGlkU1NMIFNIQTI1
72 NiBDQSAtIEczMB4XDTE0MTAxNTEyMDkzMloXDTE4MTExNjAxMTUwM1owgZcxEzAR
73 BgNVBAsTCkdUNDg3NDI5NjUxMTAvBgNVBAsTKFNlZSB3d3cucmFwaWRzc2wuY29t
74 L3Jlc291cmNlcy9jcHMgKGMpMTQxLzAtBgNVBAsTJkRvbWFpbiBDb250cm9sIFZh
75 bGlkYXRlZCAtIFJhcGlkU1NMKFIpMRwwGgYDVQQDExN3d3cuY3J5cHRvZ3JhcGh5
76 LmlvMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAom/FebKJIot7Sp3s
77 itG1sicpe3thCssjI+g1JDAS7I3GLVNmbms1DOdIIqwf01gZkzzXBN2+9sOnyRaR
78 PPfCe1jTr3dk2y6rPE559vPa1nZQkhlzlhMhlPyjaT+S7g4Tio4qV2sCBZU01DZJ
79 CaksfohN+5BNVWoJzTbOcrHOEJ+M8B484KlBCiSxqf9cyNQKru4W3bHaCVNVJ8eu
80 6i6KyhzLa0L7yK3LXwwXVs583C0/vwFhccGWsFODqD/9xHUzsBIshE8HKjdjDi7Y
81 3BFQzVUQFjBB50NSZfAA/jcdt1blxJouc7z9T8Oklh+V5DDBowgAsrT4b6Z2Fq6/
82 r7D1GqivLK/ypUQmxq2WXWAUBb/Q6xHgxASxI4Br+CByIUQJsm8L2jzc7k+mF4hW
83 ltAIUkbo8fGiVnat0505YJgxWEDKOLc4Gda6d/7GVd5AvKrz242bUqeaWo6e4MTx
84 diku2Ma3rhdcr044Qvfh9hGyjqNjvhWY/I+VRWgihU7JrYvgwFdJqsQ5eiKT4OHi
85 gsejvWwkZzDtiQ+aQTrzM1FsY2swJBJsLSX4ofohlVRlIJCn/ME+XErj553431Lu
86 YQ5SzMd3nXzN78Vj6qzTfMUUY72UoT1/AcFiUMobgIqrrmwuNxfrkbVE2b6Bga74
87 FsJX63prvrJ41kuHK/16RQBM7fcCAwEAAaOCAWAwggFcMB8GA1UdIwQYMBaAFMOc
88 8/zTRgg0u85Gf6B8W/PiCMtZMFcGCCsGAQUFBwEBBEswSTAfBggrBgEFBQcwAYYT
89 aHR0cDovL2d2LnN5bWNkLmNvbTAmBggrBgEFBQcwAoYaaHR0cDovL2d2LnN5bWNi
90 LmNvbS9ndi5jcnQwDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUFBwMB
91 BggrBgEFBQcDAjAvBgNVHREEKDAmghN3d3cuY3J5cHRvZ3JhcGh5Lmlvgg9jcnlw
92 dG9ncmFwaHkuaW8wKwYDVR0fBCQwIjAgoB6gHIYaaHR0cDovL2d2LnN5bWNiLmNv
93 bS9ndi5jcmwwDAYDVR0TAQH/BAIwADBFBgNVHSAEPjA8MDoGCmCGSAGG+EUBBzYw
94 LDAqBggrBgEFBQcCARYeaHR0cHM6Ly93d3cucmFwaWRzc2wuY29tL2xlZ2FsMA0G
95 CSqGSIb3DQEBCwUAA4IBAQAzIYO2jx7h17FBT74tJ2zbV9OKqGb7QF8y3wUtP4xc
96 dH80vprI/Cfji8s86kr77aAvAqjDjaVjHn7UzebhSUivvRPmfzRgyWBacomnXTSt
97 Xlt2dp2nDQuwGyK2vB7dMfKnQAkxwq1sYUXznB8i0IhhCAoXp01QGPKq51YoIlnF
98 7DRMk6iEaL1SJbkIrLsCQyZFDf0xtfW9DqXugMMLoxeCsBhZJQzNyS2ryirrv9LH
99 aK3+6IZjrcyy9bkpz/gzJucyhU+75c4My/mnRCrtItRbCQuiI5pd5poDowm+HH9i
100 GVI9+0lAFwxOUnOnwsoI40iOoxjLMGB+CgFLKCGUcWxP
101 -----END CERTIFICATE-----
102 """.strip()
103
g_goessel16f746f2018-10-10 04:13:41 +0200104 pem_issuer_public_key = b"""
105 -----BEGIN RSA PUBLIC KEY-----
106 MIICCgKCAgEAyYcqyuT6oQxpvg/VSn2Zc68wZ823D0VAJ2woramFx+2KPWB7B7Ot
107 tVSNRfm0OxJOU3TFAoep54Z2wgOoz0zRmeW6/7gvIuBKp2TW0qZAt3l9sgpE29iw
108 CsoZQlMrLKiDPzCC6Fptk+YPSST9sqwhWDKK1QvOg68DKRxTpEek1hBpC0XRsnuX
109 fvJJQqP39vxzpA0PsicI/wrvWX3vO8z+j9+botPerbeamoeHCsc0xgTLyIygWysB
110 rNskxlzC2U4Kw6mQhGghlLReo1rFsO2/hLTnvLs+Y1lQhnFeOKCx1WVXhzBIyO9B
111 dVVH5Cinb5wBNKvxbevRf4icdWcwtknmgKf69xj7yvFjt/vft74BB1Y5ltLYFmEb
112 0JBxm5MAJfW4YnMQr0AxdjOhjHq4MN7X4ZzwEpJaYJdRmvMsMGN88cyjYPxsaOG+
113 dZ/E9MmTjh0gnTjyD4gmsvR/gtTR/XFJ2wkbnnL1RyxNi6j2UW8C7tpNv0TIuArx
114 3SHGPZN0WsaKTxZPb0L/ob1WBT0mhiq1GzB431cXgbxyh8EdKk+xSptA3V+ca2V2
115 NuXlJIJaOoPMj/qjDW4I/peKGnk9tLknJ0hpRzz11j77pJsV0dGoGKVHIR2oZqT5
116 0ZJJb5DXNbiTnspKLNmBt0YlNiXtlCIPxVUkhL141FuCLc8h6FjD6E0CAwEAAQ==
117 -----END RSA PUBLIC KEY-----
118 """.strip()
119
120 pem_data_to_check = b"""
121 -----BEGIN CERTIFICATE-----
122 MIIErjCCApagAwIBAgIUUrUZsZrrBmRD2hvRuspp+lPsZXcwDQYJKoZIhvcNAQEN
123 BQAwETEPMA0GA1UEAwwGSXNzdWVyMB4XDTE4MTAwODEzNDg1NFoXDTE4MTAxODEz
124 NDg1NFowETEPMA0GA1UEAwwGSXNzdWVyMIICIjANBgkqhkiG9w0BAQEFAAOCAg8A
125 MIICCgKCAgEAyYcqyuT6oQxpvg/VSn2Zc68wZ823D0VAJ2woramFx+2KPWB7B7Ot
126 tVSNRfm0OxJOU3TFAoep54Z2wgOoz0zRmeW6/7gvIuBKp2TW0qZAt3l9sgpE29iw
127 CsoZQlMrLKiDPzCC6Fptk+YPSST9sqwhWDKK1QvOg68DKRxTpEek1hBpC0XRsnuX
128 fvJJQqP39vxzpA0PsicI/wrvWX3vO8z+j9+botPerbeamoeHCsc0xgTLyIygWysB
129 rNskxlzC2U4Kw6mQhGghlLReo1rFsO2/hLTnvLs+Y1lQhnFeOKCx1WVXhzBIyO9B
130 dVVH5Cinb5wBNKvxbevRf4icdWcwtknmgKf69xj7yvFjt/vft74BB1Y5ltLYFmEb
131 0JBxm5MAJfW4YnMQr0AxdjOhjHq4MN7X4ZzwEpJaYJdRmvMsMGN88cyjYPxsaOG+
132 dZ/E9MmTjh0gnTjyD4gmsvR/gtTR/XFJ2wkbnnL1RyxNi6j2UW8C7tpNv0TIuArx
133 3SHGPZN0WsaKTxZPb0L/ob1WBT0mhiq1GzB431cXgbxyh8EdKk+xSptA3V+ca2V2
134 NuXlJIJaOoPMj/qjDW4I/peKGnk9tLknJ0hpRzz11j77pJsV0dGoGKVHIR2oZqT5
135 0ZJJb5DXNbiTnspKLNmBt0YlNiXtlCIPxVUkhL141FuCLc8h6FjD6E0CAwEAATAN
136 BgkqhkiG9w0BAQ0FAAOCAgEAVFzNKhEpkH8V8l0NEBAZHNi1e+lcg35fZZ9plqcw
137 Pvk+6M7LW0KD0QWYQWm/dJme4DFsM7lh5u4/m+H4yS7/RP9pads9YwBudchvGR1c
138 S4CCrRAmO8/A0vpQJcEwdS7fdYShBsqMrZ2TvzceVn2dvQbxB6pLkK7KIbDPVJA2
139 HXFFXe2npHmdc80iTz2ShbdVSvyPvk6vc6NFFCg6lSQFuif3vV0+aYqi6DXv4h92
140 9qAdES8ZLDfDulxyajyPbtF35f2Of99CumP5UzG4RQbvtI8gShuK1YFYe2sWJFE0
141 MgSsqGCbl5mcrWxm9YxysRKMZ+Hc4tnkvfmG6GsKtp8u/5pG11XgxXaQl4fZ7JNa
142 QFuD5gEXkEC1mCnhWlnguJgjQlpKadMOORmVTqG9dNQ6GEsha+XWpinm5L9fEZuA
143 F88nNyubKLwEl68N7WWWKQlIl4q8Pe5FEp1pd9rLjOW4gzgYBccIfBK3oMC7uFJg
144 a/9GeOKPiq90UMrCI+CAsIbzuPOaAp3g69JonuDwcs4cu8ui1udxs9q7ox3qSWGZ
145 G1U/hmwvZH9kfIv5BKIzNLy4oxXPDJ7MZIBsxVxaNv8KUQ/JLtpVJa3oYqEx18+V
146 JNr8Pr3y61X8pLmJnaCu+ixshiy2gjxXxDFBVEEt1G9JHrSs3R+yvcHxCrM3+ian
147 Nh4=
148 -----END CERTIFICATE-----
149 """.strip()
150
Paul Kehrerb2de9482014-12-11 14:54:48 -0600151Loading Certificates
152~~~~~~~~~~~~~~~~~~~~
Paul Kehrer016e08a2014-11-26 09:41:18 -1000153
154.. function:: load_pem_x509_certificate(data, backend)
155
156 .. versionadded:: 0.7
157
Paul Kehrere76cd272014-12-14 19:00:51 -0600158 Deserialize a certificate from PEM encoded data. PEM certificates are
159 base64 decoded and have delimiters that look like
160 ``-----BEGIN CERTIFICATE-----``.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000161
162 :param bytes data: The PEM encoded certificate data.
163
164 :param backend: A backend supporting the
165 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
166 interface.
167
Paul Kehrere76cd272014-12-14 19:00:51 -0600168 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000169
Alex Gaynor5ce14042016-05-29 13:13:46 -0400170 .. doctest::
171
172 >>> from cryptography import x509
173 >>> from cryptography.hazmat.backends import default_backend
174 >>> cert = x509.load_pem_x509_certificate(pem_data, default_backend())
Chelsea Winfreee295f3a2016-06-02 21:15:54 -0700175 >>> cert.serial_number
Alex Gaynor5ce14042016-05-29 13:13:46 -0400176 2
177
Paul Kehrer016e08a2014-11-26 09:41:18 -1000178.. function:: load_der_x509_certificate(data, backend)
179
180 .. versionadded:: 0.7
181
Paul Kehrere76cd272014-12-14 19:00:51 -0600182 Deserialize a certificate from DER encoded data. DER is a binary format
Paul Kehrer92aac382014-12-15 16:25:28 -0600183 and is commonly found in files with the ``.cer`` extension (although file
184 extensions are not a guarantee of encoding type).
Paul Kehrer016e08a2014-11-26 09:41:18 -1000185
186 :param bytes data: The DER encoded certificate data.
187
188 :param backend: A backend supporting the
189 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
190 interface.
191
Paul Kehrere76cd272014-12-14 19:00:51 -0600192 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000193
Erik Trauschkedc570402015-09-24 20:24:28 -0700194Loading Certificate Revocation Lists
195~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
196
197.. function:: load_pem_x509_crl(data, backend)
198
199 .. versionadded:: 1.1
200
201 Deserialize a certificate revocation list (CRL) from PEM encoded data. PEM
202 requests are base64 decoded and have delimiters that look like
Erik Trauschke32bbfe02015-10-21 08:04:55 -0700203 ``-----BEGIN X509 CRL-----``.
Erik Trauschkedc570402015-09-24 20:24:28 -0700204
205 :param bytes data: The PEM encoded request data.
206
207 :param backend: A backend supporting the
208 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
209 interface.
210
211 :returns: An instance of
212 :class:`~cryptography.x509.CertificateRevocationList`.
213
Alex Gaynor5ce14042016-05-29 13:13:46 -0400214 .. doctest::
215
216 >>> from cryptography import x509
217 >>> from cryptography.hazmat.backends import default_backend
218 >>> from cryptography.hazmat.primitives import hashes
219 >>> crl = x509.load_pem_x509_crl(pem_crl_data, default_backend())
220 >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256)
221 True
222
Erik Trauschkedc570402015-09-24 20:24:28 -0700223.. function:: load_der_x509_crl(data, backend)
224
225 .. versionadded:: 1.1
226
227 Deserialize a certificate revocation list (CRL) from DER encoded data. DER
228 is a binary format.
229
230 :param bytes data: The DER encoded request data.
231
232 :param backend: A backend supporting the
233 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
234 interface.
235
236 :returns: An instance of
237 :class:`~cryptography.x509.CertificateRevocationList`.
238
Paul Kehrera1a1f232015-03-15 15:34:35 -0500239Loading Certificate Signing Requests
240~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600241
Paul Kehrer31e39882015-03-11 11:37:04 -0500242.. function:: load_pem_x509_csr(data, backend)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600243
244 .. versionadded:: 0.9
245
Paul Kehrera1a1f232015-03-15 15:34:35 -0500246 Deserialize a certificate signing request (CSR) from PEM encoded data. PEM
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500247 requests are base64 decoded and have delimiters that look like
Paul Kehrerd3dafbd2015-03-15 16:24:18 -0500248 ``-----BEGIN CERTIFICATE REQUEST-----``. This format is also known as
249 PKCS#10.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600250
251 :param bytes data: The PEM encoded request data.
252
253 :param backend: A backend supporting the
254 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
255 interface.
256
Paul Kehrera1a1f232015-03-15 15:34:35 -0500257 :returns: An instance of
258 :class:`~cryptography.x509.CertificateSigningRequest`.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600259
Alex Gaynor5ce14042016-05-29 13:13:46 -0400260 .. doctest::
261
262 >>> from cryptography import x509
263 >>> from cryptography.hazmat.backends import default_backend
264 >>> from cryptography.hazmat.primitives import hashes
265 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
266 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
267 True
268
Paul Kehrer1effb6e2015-03-30 15:05:59 -0500269.. function:: load_der_x509_csr(data, backend)
270
271 .. versionadded:: 0.9
272
273 Deserialize a certificate signing request (CSR) from DER encoded data. DER
274 is a binary format and is not commonly used with CSRs.
275
276 :param bytes data: The DER encoded request data.
277
278 :param backend: A backend supporting the
279 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
280 interface.
281
282 :returns: An instance of
283 :class:`~cryptography.x509.CertificateSigningRequest`.
284
Paul Kehrere76cd272014-12-14 19:00:51 -0600285X.509 Certificate Object
286~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerb2de9482014-12-11 14:54:48 -0600287
Paul Kehrere76cd272014-12-14 19:00:51 -0600288.. class:: Certificate
Paul Kehrerb2de9482014-12-11 14:54:48 -0600289
290 .. versionadded:: 0.7
291
292 .. attribute:: version
293
Paul Kehrere76cd272014-12-14 19:00:51 -0600294 :type: :class:`~cryptography.x509.Version`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600295
Paul Kehrere76cd272014-12-14 19:00:51 -0600296 The certificate version as an enumeration. Version 3 certificates are
297 the latest version and also the only type you should see in practice.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600298
Alex Gaynor89c4dc82014-12-16 16:49:33 -0800299 :raises cryptography.x509.InvalidVersion: If the version in the
Alex Gaynor6d7ab4c2014-12-16 16:50:33 -0800300 certificate is not a known
301 :class:`X.509 version <cryptography.x509.Version>`.
Paul Kehrer92aac382014-12-15 16:25:28 -0600302
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600303 .. doctest::
304
305 >>> cert.version
306 <Version.v3: 2>
307
Paul Kehrerb2de9482014-12-11 14:54:48 -0600308 .. method:: fingerprint(algorithm)
309
310 :param algorithm: The
Paul Kehrer601278a2015-02-12 12:51:00 -0600311 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600312 that will be used to generate the fingerprint.
313
Erik Trauschke2dcce902015-05-14 16:12:24 -0700314 :return bytes: The fingerprint using the supplied hash algorithm, as
Paul Kehrerb2de9482014-12-11 14:54:48 -0600315 bytes.
316
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600317 .. doctest::
318
319 >>> from cryptography.hazmat.primitives import hashes
320 >>> cert.fingerprint(hashes.SHA256())
Paul Kehrer056c9dd2018-05-12 15:17:06 -0400321 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 -0600322
Chelsea Winfreee295f3a2016-06-02 21:15:54 -0700323 .. attribute:: serial_number
Paul Kehrerb2de9482014-12-11 14:54:48 -0600324
325 :type: int
326
327 The serial as a Python integer.
328
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600329 .. doctest::
330
Chelsea Winfreee295f3a2016-06-02 21:15:54 -0700331 >>> cert.serial_number
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600332 2
333
Paul Kehrerb2de9482014-12-11 14:54:48 -0600334 .. method:: public_key()
335
Alex Gaynor4c2561a2015-10-12 23:53:39 -0400336 The public key associated with the certificate.
337
338 :returns:
Alex Stapletonf79c2312014-12-30 12:50:14 +0000339 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
Paul Kehrer45efdbc2015-02-12 10:58:22 -0600340 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
341 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600342
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600343 .. doctest::
344
Alex Stapletonf79c2312014-12-30 12:50:14 +0000345 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600346 >>> public_key = cert.public_key()
Alex Stapletonf79c2312014-12-30 12:50:14 +0000347 >>> isinstance(public_key, rsa.RSAPublicKey)
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600348 True
349
Paul Kehrerb2de9482014-12-11 14:54:48 -0600350 .. attribute:: not_valid_before
351
352 :type: :class:`datetime.datetime`
353
Paul Kehrer78a81502014-12-16 14:47:52 -0600354 A naïve datetime representing the beginning of the validity period for
355 the certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600356
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600357 .. doctest::
358
359 >>> cert.not_valid_before
360 datetime.datetime(2010, 1, 1, 8, 30)
361
Paul Kehrerb2de9482014-12-11 14:54:48 -0600362 .. attribute:: not_valid_after
363
364 :type: :class:`datetime.datetime`
365
Paul Kehrer78a81502014-12-16 14:47:52 -0600366 A naïve datetime representing the end of the validity period for the
367 certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600368
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600369 .. doctest::
370
371 >>> cert.not_valid_after
372 datetime.datetime(2030, 12, 31, 8, 30)
373
Paul Kehrer719d5362015-01-01 20:03:52 -0600374 .. attribute:: issuer
375
376 .. versionadded:: 0.8
377
378 :type: :class:`Name`
379
380 The :class:`Name` of the issuer.
381
382 .. attribute:: subject
383
384 .. versionadded:: 0.8
385
386 :type: :class:`Name`
387
388 The :class:`Name` of the subject.
389
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600390 .. attribute:: signature_hash_algorithm
Paul Kehrer56da2a52015-02-11 23:35:07 -0600391
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600392 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrer56da2a52015-02-11 23:35:07 -0600393
Paul Kehrere612ec72015-02-16 14:33:35 -0600394 Returns the
Paul Kehrer71d40c62015-02-19 08:21:04 -0600395 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600396 was used in signing this certificate.
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 Kehrerb8968812015-05-15 09:01:34 -0700432 :raises UnicodeError: If an extension contains IDNA encoding that is
433 invalid or not compliant with IDNA 2008.
434
Paul Kehrerfa56a232015-03-17 13:14:03 -0500435 .. doctest::
436
437 >>> for ext in cert.extensions:
438 ... print(ext)
Paul Kehrer056c9dd2018-05-12 15:17:06 -0400439 <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)>)>
440 <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')>)>
Paul Kehrerb511ba82015-04-15 11:22:48 -0400441 <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=None, decipher_only=None)>)>
Paul Kehrer2008d9c2015-05-12 22:19:56 -0500442 <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 -0500443 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
444
Paul Kehrerd91e7c12015-10-01 16:50:42 -0500445 .. attribute:: signature
446
447 .. versionadded:: 1.2
448
449 :type: bytes
450
451 The bytes of the certificate's signature.
452
Paul Kehrerd2898052015-11-03 22:00:41 +0900453 .. attribute:: tbs_certificate_bytes
Paul Kehrerd91e7c12015-10-01 16:50:42 -0500454
455 .. versionadded:: 1.2
456
457 :type: bytes
458
459 The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed
460 and then signed by the private key of the certificate's issuer. This
461 data may be used to validate a signature, but use extreme caution as
462 certificate validation is a complex problem that involves much more
463 than just signature checks.
464
Paul Kehrer838bc4a2018-10-10 12:02:55 +0800465 To validate the signature on a certificate you can do the following.
466 Note: This only verifies that the certificate was signed with the
467 private key associated with the public key provided and does not
468 perform any of the other checks needed for secure certificate
469 validation. Additionally, this example will only work for RSA public
470 keys with ``PKCS1v15`` signatures, and so it can't be used for general
471 purpose signature verification.
g_goessel16f746f2018-10-10 04:13:41 +0200472
473 .. doctest::
474
475 >>> from cryptography.hazmat.primitives.serialization import load_pem_public_key
476 >>> from cryptography.hazmat.primitives.asymmetric import padding
477 >>> issuer_public_key = load_pem_public_key(pem_issuer_public_key, default_backend())
478 >>> cert_to_check = x509.load_pem_x509_certificate(pem_data_to_check, default_backend())
479 >>> issuer_public_key.verify(
Alex Gaynor64602282018-10-09 23:03:55 -0400480 ... cert_to_check.signature,
481 ... cert_to_check.tbs_certificate_bytes,
482 ... # Depends on the algorithm used to create the certificate
483 ... padding.PKCS1v15(),
484 ... cert_to_check.signature_hash_algorithm,
g_goessel16f746f2018-10-10 04:13:41 +0200485 ... )
486
487 An
488 :class:`~cryptography.exceptions.InvalidSignature`
489 exception will be raised if the signature fails to verify.
490
Andre Carona8aded62015-05-19 20:11:57 -0400491 .. method:: public_bytes(encoding)
492
Alex Gaynord0b376b2015-07-05 13:58:12 -0400493 .. versionadded:: 1.0
494
Andre Carona8aded62015-05-19 20:11:57 -0400495 :param encoding: The
496 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
497 that will be used to serialize the certificate.
498
499 :return bytes: The data that can be written to a file or sent
500 over the network to be verified by clients.
501
Erik Trauschke2dcce902015-05-14 16:12:24 -0700502X.509 CRL (Certificate Revocation List) Object
503~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
504
505.. class:: CertificateRevocationList
506
507 .. versionadded:: 1.0
508
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700509 A CertificateRevocationList is an object representing a list of revoked
510 certificates. The object is iterable and will yield the RevokedCertificate
511 objects stored in this CRL.
512
513 .. doctest::
Erik Trauschkeb14f7d12015-10-13 09:55:39 -0700514
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700515 >>> len(crl)
516 1
Paul Kehrerdcdf9672015-10-21 20:27:28 -0500517 >>> revoked_certificate = crl[0]
518 >>> type(revoked_certificate)
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700519 <class 'cryptography.hazmat.backends.openssl.x509._RevokedCertificate'>
520 >>> for r in crl:
521 ... print(r.serial_number)
522 0
523
Erik Trauschke2dcce902015-05-14 16:12:24 -0700524 .. method:: fingerprint(algorithm)
525
526 :param algorithm: The
527 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
528 that will be used to generate the fingerprint.
529
530 :return bytes: The fingerprint using the supplied hash algorithm, as
531 bytes.
532
Erik Trauschkedc570402015-09-24 20:24:28 -0700533 .. doctest::
534
535 >>> from cryptography.hazmat.primitives import hashes
536 >>> crl.fingerprint(hashes.SHA256())
Paul Kehrer056c9dd2018-05-12 15:17:06 -0400537 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 -0700538
Paul Kehrer5d187402018-07-16 20:49:51 +0530539 .. method:: get_revoked_certificate_by_serial_number(serial_number)
540
541 .. versionadded:: 2.3
542
543 :param serial_number: The serial as a Python integer.
544 :returns: :class:`~cryptography.x509.RevokedCertificate` if the
545 ``serial_number`` is present in the CRL or ``None`` if it
546 is not.
547
Erik Trauschke2dcce902015-05-14 16:12:24 -0700548 .. attribute:: signature_hash_algorithm
549
550 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
551
552 Returns the
553 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
554 was used in signing this CRL.
555
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
604 A naïve datetime representing when the this CRL was last updated.
605
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
671 >>> from cryptography.hazmat.backends import default_backend
672 >>> from cryptography.hazmat.primitives import hashes
673 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -0500674 >>> from cryptography.x509.oid import NameOID
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500675 >>> import datetime
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500676 >>> one_day = datetime.timedelta(1, 0, 0)
677 >>> private_key = rsa.generate_private_key(
678 ... public_exponent=65537,
679 ... key_size=2048,
680 ... backend=default_backend()
681 ... )
Cory Benfieldc47b2522015-12-07 15:25:12 +0000682 >>> public_key = private_key.public_key()
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500683 >>> builder = x509.CertificateBuilder()
684 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500685 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500686 ... ]))
687 >>> builder = builder.issuer_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500688 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500689 ... ]))
690 >>> builder = builder.not_valid_before(datetime.datetime.today() - one_day)
Alex Gaynorcdd35852018-08-05 18:17:35 -0400691 >>> builder = builder.not_valid_after(datetime.datetime.today() + (one_day * 30))
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500692 >>> builder = builder.serial_number(x509.random_serial_number())
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500693 >>> builder = builder.public_key(public_key)
694 >>> builder = builder.add_extension(
Paul Kehrer1bab7bc2017-01-18 13:44:40 +0800695 ... x509.SubjectAlternativeName(
Paul Kehrered321052017-10-11 08:11:44 +0800696 ... [x509.DNSName(u'cryptography.io')]
Paul Kehrer1bab7bc2017-01-18 13:44:40 +0800697 ... ),
698 ... critical=False
699 ... )
700 >>> builder = builder.add_extension(
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500701 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
702 ... )
703 >>> certificate = builder.sign(
704 ... private_key=private_key, algorithm=hashes.SHA256(),
705 ... backend=default_backend()
706 ... )
707 >>> isinstance(certificate, x509.Certificate)
708 True
709
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500710 .. method:: issuer_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400711
712 Sets the issuer's distinguished name.
713
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500714 :param name: The :class:`~cryptography.x509.Name` that describes the
715 issuer (CA).
Andre Caron9bbfcea2015-05-18 20:55:29 -0400716
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500717 .. method:: subject_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400718
719 Sets the subject's distinguished name.
720
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500721 :param name: The :class:`~cryptography.x509.Name` that describes the
Ian Cordasco85fc4d52015-08-01 20:29:31 -0500722 subject.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400723
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500724 .. method:: public_key(public_key)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400725
726 Sets the subject's public key.
727
Ian Cordasco8f571422015-08-02 11:31:08 -0500728 :param public_key: The subject's public key. This can be one of
729 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`,
730 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
731 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400732
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500733 .. method:: serial_number(serial_number)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400734
735 Sets the certificate's serial number (an integer). The CA's policy
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500736 determines how it attributes serial numbers to certificates. This
737 number must uniquely identify the certificate given the issuer.
738 `CABForum Guidelines`_ require entropy in the serial number
739 to provide protection against hash collision attacks. For more
740 information on secure random number generation, see
741 :doc:`/random-numbers`.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400742
743 :param serial_number: Integer number that will be used by the CA to
744 identify this certificate (most notably during certificate
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500745 revocation checking). Users should consider using
746 :func:`~cryptography.x509.random_serial_number` when possible.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400747
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500748 .. method:: not_valid_before(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400749
750 Sets the certificate's activation time. This is the time from which
751 clients can start trusting the certificate. It may be different from
752 the time at which the certificate was created.
753
Ian Cordasco17c89002015-08-02 21:13:59 -0500754 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400755 activation time for the certificate. The certificate may not be
756 trusted clients if it is used before this time.
757
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500758 .. method:: not_valid_after(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400759
760 Sets the certificate's expiration time. This is the time from which
761 clients should no longer trust the certificate. The CA's policy will
762 determine how long the certificate should remain in use.
763
Ian Cordasco17c89002015-08-02 21:13:59 -0500764 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400765 expiration time for the certificate. The certificate may not be
766 trusted clients if it is used after this time.
767
Ian Cordasco17c89002015-08-02 21:13:59 -0500768 .. method:: add_extension(extension, critical)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400769
770 Adds an X.509 extension to the certificate.
771
Paul Kehrer2c145cc2015-10-02 11:27:21 -0500772 :param extension: An extension conforming to the
773 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400774
Ian Cordasco17c89002015-08-02 21:13:59 -0500775 :param critical: Set to ``True`` if the extension must be understood and
776 handled by whoever reads the certificate.
777
Paul Kehrer9add80e2015-08-03 17:53:14 +0100778 .. method:: sign(private_key, algorithm, backend)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400779
780 Sign the certificate using the CA's private key.
781
Ian Cordascoc5e1c252015-07-31 23:33:35 -0500782 :param private_key: The
783 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
784 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
785 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
786 that will be used to sign the certificate.
787
Andre Caron9bbfcea2015-05-18 20:55:29 -0400788 :param algorithm: The
789 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
790 will be used to generate the signature.
791
Paul Kehrer9add80e2015-08-03 17:53:14 +0100792 :param backend: Backend that will be used to build the certificate.
793 Must support the
794 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
795 interface.
796
Benjamin Peterson9ed312b2015-10-12 20:51:34 -0700797 :returns: :class:`~cryptography.x509.Certificate`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400798
799
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500800X.509 CSR (Certificate Signing Request) Object
801~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600802
Paul Kehrera1a1f232015-03-15 15:34:35 -0500803.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600804
805 .. versionadded:: 0.9
806
807 .. method:: public_key()
808
Alex Gaynor4c2561a2015-10-12 23:53:39 -0400809 The public key associated with the request.
810
811 :returns:
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600812 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
813 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
814 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
815
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600816 .. doctest::
817
818 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500819 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600820 >>> isinstance(public_key, rsa.RSAPublicKey)
821 True
822
823 .. attribute:: subject
824
825 :type: :class:`Name`
826
827 The :class:`Name` of the subject.
828
829 .. attribute:: signature_hash_algorithm
830
831 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
832
833 Returns the
834 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
835 was used in signing this request.
836
837 .. doctest::
838
839 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500840 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600841 True
842
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800843 .. attribute:: signature_algorithm_oid
844
845 .. versionadded:: 1.6
846
847 :type: :class:`ObjectIdentifier`
848
849 Returns the :class:`ObjectIdentifier` of the signature algorithm used
850 to sign the request. This will be one of the OIDs from
851 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
852
853 .. doctest::
854
855 >>> csr.signature_algorithm_oid
856 <ObjectIdentifier(oid=1.2.840.113549.1.1.5, name=sha1WithRSAEncryption)>
857
Paul Kehrerc4e61942015-08-01 21:21:13 +0100858 .. attribute:: extensions
859
860 :type: :class:`Extensions`
861
862 The extensions encoded in the certificate signing request.
863
864 :raises cryptography.x509.DuplicateExtension: If more than one
Paul Kehrer24283d22015-08-01 21:31:19 +0100865 extension of the same type is found within the certificate signing request.
Paul Kehrerc4e61942015-08-01 21:21:13 +0100866
Paul Kehrerc4e61942015-08-01 21:21:13 +0100867 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
868 contains a general name that is not supported.
869
870 :raises UnicodeError: If an extension contains IDNA encoding that is
871 invalid or not compliant with IDNA 2008.
872
873
Andre Caron476c5df2015-05-18 10:23:28 -0400874 .. method:: public_bytes(encoding)
875
Alex Gaynord0b376b2015-07-05 13:58:12 -0400876 .. versionadded:: 1.0
877
Andre Caron476c5df2015-05-18 10:23:28 -0400878 :param encoding: The
879 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
880 that will be used to serialize the certificate request.
881
882 :return bytes: The data that can be written to a file or sent
883 over the network to be signed by the certificate
884 authority.
885
Paul Kehrerab209392015-12-01 14:50:31 -0600886 .. attribute:: signature
887
888 .. versionadded:: 1.2
889
890 :type: bytes
891
892 The bytes of the certificate signing request's signature.
893
894 .. attribute:: tbs_certrequest_bytes
895
896 .. versionadded:: 1.2
897
898 :type: bytes
899
900 The DER encoded bytes payload (as defined by :rfc:`2986`) that is
901 hashed and then signed by the private key (corresponding to the public
902 key embedded in the CSR). This data may be used to validate the CSR
903 signature.
904
Joern Heisslerfbda8ce2016-01-18 00:24:44 +0100905 .. attribute:: is_signature_valid
Joern Heissler1bd77e22016-01-13 22:51:37 +0100906
907 .. versionadded:: 1.3
908
Joern Heisslerfbda8ce2016-01-18 00:24:44 +0100909 Returns True if the CSR signature is correct, False otherwise.
Joern Heissler1bd77e22016-01-13 22:51:37 +0100910
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600911X.509 Certificate Revocation List Builder
912~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
913
914.. class:: CertificateRevocationListBuilder
915
916 .. versionadded:: 1.2
917
918 .. doctest::
919
920 >>> from cryptography import x509
921 >>> from cryptography.hazmat.backends import default_backend
922 >>> from cryptography.hazmat.primitives import hashes
923 >>> from cryptography.hazmat.primitives.asymmetric import rsa
924 >>> from cryptography.x509.oid import NameOID
925 >>> import datetime
926 >>> one_day = datetime.timedelta(1, 0, 0)
927 >>> private_key = rsa.generate_private_key(
928 ... public_exponent=65537,
929 ... key_size=2048,
930 ... backend=default_backend()
931 ... )
932 >>> builder = x509.CertificateRevocationListBuilder()
933 >>> builder = builder.issuer_name(x509.Name([
934 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io CA'),
935 ... ]))
936 >>> builder = builder.last_update(datetime.datetime.today())
937 >>> builder = builder.next_update(datetime.datetime.today() + one_day)
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600938 >>> revoked_cert = x509.RevokedCertificateBuilder().serial_number(
939 ... 333
940 ... ).revocation_date(
941 ... datetime.datetime.today()
942 ... ).build(default_backend())
943 >>> builder = builder.add_revoked_certificate(revoked_cert)
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600944 >>> crl = builder.sign(
945 ... private_key=private_key, algorithm=hashes.SHA256(),
946 ... backend=default_backend()
947 ... )
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600948 >>> len(crl)
949 1
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600950
951 .. method:: issuer_name(name)
952
953 Sets the issuer's distinguished name.
954
955 :param name: The :class:`~cryptography.x509.Name` that describes the
956 issuer (CA).
957
958 .. method:: last_update(time)
959
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600960 Sets this CRL's activation time. This is the time from which
961 clients can start trusting this CRL. It may be different from
962 the time at which this CRL was created. This is also known as the
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600963 ``thisUpdate`` time.
964
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600965 :param time: The :class:`datetime.datetime` object (in UTC) that marks
966 the activation time for this CRL. The CRL may not be trusted if it
967 is used before this time.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600968
969 .. method:: next_update(time)
970
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600971 Sets this CRL's next update time. This is the time by which
972 a new CRL will be issued. The CA is allowed to issue a new CRL before
973 this date, however clients are not required to check for it.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600974
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600975 :param time: The :class:`datetime.datetime` object (in UTC) that marks
976 the next update time for this CRL.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600977
Paul Kehrer426b48d2015-12-24 20:50:43 -0600978 .. method:: add_extension(extension, critical)
979
980 Adds an X.509 extension to this CRL.
981
982 :param extension: An extension with the
983 :class:`~cryptography.x509.ExtensionType` interface.
984
985 :param critical: Set to ``True`` if the extension must be understood and
986 handled by whoever reads the CRL.
987
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600988 .. method:: add_revoked_certificate(revoked_certificate)
989
990 Adds a revoked certificate to this CRL.
991
992 :param revoked_certificate: An instance of
993 :class:`~cryptography.x509.RevokedCertificate`. These can be
994 obtained from an existing CRL or created with
995 :class:`~cryptography.x509.RevokedCertificateBuilder`.
996
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600997 .. method:: sign(private_key, algorithm, backend)
998
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600999 Sign this CRL using the CA's private key.
Paul Kehrerbfac2d12015-12-19 23:32:08 -06001000
1001 :param private_key: The
1002 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
1003 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
1004 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
1005 that will be used to sign the certificate.
1006
1007 :param algorithm: The
1008 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
1009 will be used to generate the signature.
1010
1011 :param backend: Backend that will be used to build the CRL.
1012 Must support the
1013 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1014 interface.
1015
1016 :returns: :class:`~cryptography.x509.CertificateRevocationList`
1017
Erik Trauschke2dcce902015-05-14 16:12:24 -07001018X.509 Revoked Certificate Object
Erik Trauschkec5a8d172015-05-28 10:24:25 -07001019~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Erik Trauschke2dcce902015-05-14 16:12:24 -07001020
1021.. class:: RevokedCertificate
1022
1023 .. versionadded:: 1.0
1024
1025 .. attribute:: serial_number
1026
1027 :type: :class:`int`
1028
1029 An integer representing the serial number of the revoked certificate.
1030
Erik Trauschkedc570402015-09-24 20:24:28 -07001031 .. doctest::
1032
Erik Trauschke3cdabaf2015-10-13 09:42:53 -07001033 >>> revoked_certificate.serial_number
Erik Trauschkedc570402015-09-24 20:24:28 -07001034 0
1035
Erik Trauschke2dcce902015-05-14 16:12:24 -07001036 .. attribute:: revocation_date
1037
1038 :type: :class:`datetime.datetime`
1039
1040 A naïve datetime representing the date this certificates was revoked.
1041
Erik Trauschkedc570402015-09-24 20:24:28 -07001042 .. doctest::
1043
Erik Trauschke77f5a252015-10-14 08:06:38 -07001044 >>> revoked_certificate.revocation_date
Erik Trauschkedc570402015-09-24 20:24:28 -07001045 datetime.datetime(2015, 1, 1, 0, 0)
1046
Erik Trauschke2dcce902015-05-14 16:12:24 -07001047 .. attribute:: extensions
1048
1049 :type: :class:`Extensions`
1050
1051 The extensions encoded in the revoked certificate.
Andre Caron476c5df2015-05-18 10:23:28 -04001052
Erik Trauschkedc570402015-09-24 20:24:28 -07001053 .. doctest::
1054
Erik Trauschke77f5a252015-10-14 08:06:38 -07001055 >>> for ext in revoked_certificate.extensions:
Erik Trauschkedc570402015-09-24 20:24:28 -07001056 ... print(ext)
Paul Kehrer23c0bbc2015-12-25 22:35:19 -06001057 <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 -06001058 <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 -07001059
Paul Kehrerc33ffd72015-12-25 10:59:22 -06001060X.509 Revoked Certificate Builder
1061~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1062
1063.. class:: RevokedCertificateBuilder
1064
1065 This class is used to create :class:`~cryptography.x509.RevokedCertificate`
1066 objects that can be used with the
1067 :class:`~cryptography.x509.CertificateRevocationListBuilder`.
1068
1069 .. versionadded:: 1.2
1070
1071 .. doctest::
1072
1073 >>> from cryptography import x509
1074 >>> from cryptography.hazmat.backends import default_backend
1075 >>> import datetime
1076 >>> builder = x509.RevokedCertificateBuilder()
1077 >>> builder = builder.revocation_date(datetime.datetime.today())
1078 >>> builder = builder.serial_number(3333)
1079 >>> revoked_certificate = builder.build(default_backend())
1080 >>> isinstance(revoked_certificate, x509.RevokedCertificate)
1081 True
1082
1083 .. method:: serial_number(serial_number)
1084
1085 Sets the revoked certificate's serial number.
1086
1087 :param serial_number: Integer number that is used to identify the
1088 revoked certificate.
1089
1090 .. method:: revocation_date(time)
1091
1092 Sets the certificate's revocation date.
1093
1094 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
1095 revocation time for the certificate.
1096
Paul Kehrere5f152b2015-12-25 23:55:47 -06001097 .. method:: add_extension(extension, critical)
1098
1099 Adds an X.509 extension to this revoked certificate.
1100
1101 :param extension: An instance of one of the
1102 :ref:`CRL entry extensions <crl_entry_extensions>`.
1103
1104 :param critical: Set to ``True`` if the extension must be understood and
1105 handled.
1106
Paul Kehrerc33ffd72015-12-25 10:59:22 -06001107 .. method:: build(backend)
1108
1109 Create a revoked certificate object using the provided backend.
1110
1111 :param backend: Backend that will be used to build the revoked
1112 certificate. Must support the
1113 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1114 interface.
1115
1116 :returns: :class:`~cryptography.x509.RevokedCertificate`
1117
Andre Caron0ef595f2015-05-18 13:53:43 -04001118X.509 CSR (Certificate Signing Request) Builder Object
1119~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1120
1121.. class:: CertificateSigningRequestBuilder
1122
Andre Carond259ee52015-06-02 23:47:11 -04001123 .. versionadded:: 1.0
1124
1125 .. doctest::
1126
1127 >>> from cryptography import x509
1128 >>> from cryptography.hazmat.backends import default_backend
1129 >>> from cryptography.hazmat.primitives import hashes
1130 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -05001131 >>> from cryptography.x509.oid import NameOID
Andre Carond259ee52015-06-02 23:47:11 -04001132 >>> private_key = rsa.generate_private_key(
1133 ... public_exponent=65537,
1134 ... key_size=2048,
1135 ... backend=default_backend()
1136 ... )
1137 >>> builder = x509.CertificateSigningRequestBuilder()
Andre Carona9a51172015-06-06 20:18:44 -04001138 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -05001139 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Andre Carond259ee52015-06-02 23:47:11 -04001140 ... ]))
Ian Cordascof06b6be2015-06-21 10:09:18 -05001141 >>> builder = builder.add_extension(
Ian Cordasco0112b022015-06-16 17:51:18 -05001142 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
Andre Caron472fd692015-06-06 20:04:44 -04001143 ... )
Andre Carond259ee52015-06-02 23:47:11 -04001144 >>> request = builder.sign(
Alex Gaynorde9e5842015-06-26 20:11:23 -04001145 ... private_key, hashes.SHA256(), default_backend()
Andre Carond259ee52015-06-02 23:47:11 -04001146 ... )
1147 >>> isinstance(request, x509.CertificateSigningRequest)
1148 True
1149
Andre Carona9a51172015-06-06 20:18:44 -04001150 .. method:: subject_name(name)
Andre Caron0ef595f2015-05-18 13:53:43 -04001151
Andre Caron341ff852015-06-06 20:14:31 -04001152 :param name: The :class:`~cryptography.x509.Name` of the certificate
1153 subject.
1154 :returns: A new
1155 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001156
Ian Cordascof06b6be2015-06-21 10:09:18 -05001157 .. method:: add_extension(extension, critical)
Andre Caron0ef595f2015-05-18 13:53:43 -04001158
Paul Kehrer2c145cc2015-10-02 11:27:21 -05001159 :param extension: An extension conforming to the
1160 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron472fd692015-06-06 20:04:44 -04001161 :param critical: Set to `True` if the extension must be understood and
1162 handled by whoever reads the certificate.
Andre Caron341ff852015-06-06 20:14:31 -04001163 :returns: A new
1164 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001165
Alex Gaynorb3b0fbe2015-06-26 19:57:18 -04001166 .. method:: sign(private_key, algorithm, backend)
Andre Caron0ef595f2015-05-18 13:53:43 -04001167
1168 :param backend: Backend that will be used to sign the request.
1169 Must support the
1170 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1171 interface.
1172
1173 :param private_key: The
Andre Caron24f9bf42015-06-06 20:14:54 -04001174 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
1175 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
1176 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
Andre Caron0ef595f2015-05-18 13:53:43 -04001177 that will be used to sign the request. When the request is
1178 signed by a certificate authority, the private key's associated
1179 public key will be stored in the resulting certificate.
1180
1181 :param algorithm: The
1182 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
1183 that will be used to generate the request signature.
1184
Andre Caron341ff852015-06-06 20:14:31 -04001185 :returns: A new
1186 :class:`~cryptography.x509.CertificateSigningRequest`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001187
1188
Paul Kehrer719d5362015-01-01 20:03:52 -06001189.. class:: Name
1190
1191 .. versionadded:: 0.8
1192
Paul Kehrer53d8d492015-02-13 18:47:30 -06001193 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -06001194 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -06001195 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -06001196 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
Marti Raudsepp82415572018-12-18 01:26:40 +02001197 ``CN=mydomain.com,O=My Org,C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -06001198
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001199 Technically, a Name is a list of *sets* of attributes, called *Relative
1200 Distinguished Names* or *RDNs*, although multi-valued RDNs are rarely
1201 encountered. The iteration order of values within a multi-valued RDN is
Marti Raudsepp9e1873a2018-07-09 16:11:18 +03001202 preserved. If you need to handle multi-valued RDNs, the ``rdns`` property
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001203 gives access to an ordered list of :class:`RelativeDistinguishedName`
1204 objects.
1205
1206 A Name can be initialized with an iterable of :class:`NameAttribute` (the
1207 common case where each RDN has a single attribute) or an iterable of
1208 :class:`RelativeDistinguishedName` objects (in the rare case of
1209 multi-valued RDNs).
1210
Paul Kehrer53d8d492015-02-13 18:47:30 -06001211 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -06001212
Paul Kehrer8b21a4a2015-02-14 07:56:36 -06001213 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -06001214 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -06001215 >>> for attribute in cert.subject:
1216 ... print(attribute)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001217 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')>
1218 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value='Test Certificates 2011')>
1219 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -06001220
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001221 .. attribute:: rdns
1222
1223 .. versionadded:: 1.6
1224
1225 :type: list of :class:`RelativeDistinguishedName`
1226
Paul Kehrere901d642015-02-11 18:50:58 -06001227 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -06001228
Paul Kehrere901d642015-02-11 18:50:58 -06001229 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -06001230
Paul Kehrere901d642015-02-11 18:50:58 -06001231 :returns: A list of :class:`NameAttribute` instances that match the
1232 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -06001233
1234 .. doctest::
1235
Paul Kehrere27f6582015-08-10 18:33:38 -05001236 >>> cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001237 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -06001238
Paul Kehrer3a15b032016-11-13 14:30:11 -08001239 .. method:: public_bytes(backend)
1240
1241 .. versionadded:: 1.6
1242
1243 :param backend: A backend supporting the
1244 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1245 interface.
1246
1247 :return bytes: The DER encoded name.
1248
Marti Raudseppc3d38b52018-12-08 03:26:07 +02001249 .. method:: rfc4514_string()
1250
1251 .. versionadded:: 2.5
1252
1253 :return str: Format the given name as a `RFC 4514`_ Distinguished Name
Marti Raudsepp82415572018-12-18 01:26:40 +02001254 string, for example ``CN=mydomain.com,O=My Org,C=US``.
Marti Raudseppc3d38b52018-12-08 03:26:07 +02001255
1256
Paul Kehrere76cd272014-12-14 19:00:51 -06001257.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -10001258
1259 .. versionadded:: 0.7
1260
1261 An enumeration for X.509 versions.
1262
1263 .. attribute:: v1
1264
1265 For version 1 X.509 certificates.
1266
1267 .. attribute:: v3
1268
1269 For version 3 X.509 certificates.
1270
Paul Kehrer806bfb22015-02-02 17:05:24 -06001271.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001272
1273 .. versionadded:: 0.8
1274
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001275 An X.509 name consists of a list of :class:`RelativeDistinguishedName`
1276 instances, which consist of a set of :class:`NameAttribute` instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001277
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001278 .. attribute:: oid
1279
1280 :type: :class:`ObjectIdentifier`
1281
1282 The attribute OID.
1283
1284 .. attribute:: value
1285
Paul Kehrerd5852cb2015-01-30 08:25:23 -06001286 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001287
1288 The value of the attribute.
1289
Marti Raudseppc3d38b52018-12-08 03:26:07 +02001290 .. method:: rfc4514_string()
1291
1292 .. versionadded:: 2.5
1293
1294 :return str: Format the given attribute as a `RFC 4514`_ Distinguished
1295 Name string.
1296
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001297
1298.. class:: RelativeDistinguishedName(attributes)
1299
1300 .. versionadded:: 1.6
1301
1302 A relative distinguished name is a non-empty set of name attributes. The
Marti Raudsepp9e1873a2018-07-09 16:11:18 +03001303 object is iterable to get every attribute, preserving the original order.
1304 Passing duplicate attributes to the constructor raises ``ValueError``.
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001305
1306 .. method:: get_attributes_for_oid(oid)
1307
1308 :param oid: An :class:`ObjectIdentifier` instance.
1309
1310 :returns: A list of :class:`NameAttribute` instances that match the OID
1311 provided. The list should contain zero or one values.
1312
Marti Raudseppc3d38b52018-12-08 03:26:07 +02001313 .. method:: rfc4514_string()
1314
1315 .. versionadded:: 2.5
1316
1317 :return str: Format the given RDN set as a `RFC 4514`_ Distinguished
1318 Name string.
1319
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001320
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001321.. class:: ObjectIdentifier
1322
1323 .. versionadded:: 0.8
1324
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001325 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -06001326 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001327
Paul Kehrerd44f9a62015-02-04 14:47:34 -06001328 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001329
1330 :type: :class:`str`
1331
Paul Kehrerfedf4f42015-02-06 11:22:07 -06001332 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001333
Marti Raudseppc3d38b52018-12-08 03:26:07 +02001334.. _`RFC 4514`: https://tools.ietf.org/html/rfc4514
1335
Paul Kehrer31bdf792015-03-25 14:11:00 -05001336.. _general_name_classes:
1337
1338General Name Classes
1339~~~~~~~~~~~~~~~~~~~~
1340
1341.. class:: GeneralName
1342
1343 .. versionadded:: 0.9
1344
1345 This is the generic interface that all the following classes are registered
1346 against.
1347
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001348.. class:: RFC822Name(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001349
1350 .. versionadded:: 0.9
1351
Paul Kehrere885bd62017-10-11 20:29:23 +08001352 .. versionchanged:: 2.1
Paul Kehrer3e15ca52017-08-01 21:21:19 -05001353
Paul Kehrere885bd62017-10-11 20:29:23 +08001354 .. warning::
1355
1356 Starting with version 2.1 :term:`U-label` input is deprecated. If
1357 passing an internationalized domain name (IDN) you should first IDNA
1358 encode the value and then pass the result as a string. Accessing
1359 ``value`` will return the :term:`A-label` encoded form even if you pass
1360 a U-label. This breaks backwards compatibility, but only for
1361 internationalized domain names.
1362
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001363
1364 This corresponds to an email address. For example, ``user@example.com``.
1365
Paul Kehrere885bd62017-10-11 20:29:23 +08001366 :param value: The email address. If the address contains an
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001367 internationalized domain name then it must be encoded to an
Paul Kehrere885bd62017-10-11 20:29:23 +08001368 :term:`A-label` string before being passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001369
Paul Kehrer31bdf792015-03-25 14:11:00 -05001370 .. attribute:: value
1371
1372 :type: :term:`text`
1373
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001374.. class:: DNSName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001375
1376 .. versionadded:: 0.9
1377
Paul Kehrere885bd62017-10-11 20:29:23 +08001378 .. versionchanged:: 2.1
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001379
Paul Kehrere885bd62017-10-11 20:29:23 +08001380 .. warning::
1381
1382 Starting with version 2.1 :term:`U-label` input is deprecated. If
1383 passing an internationalized domain name (IDN) you should first IDNA
1384 encode the value and then pass the result as a string. Accessing
1385 ``value`` will return the :term:`A-label` encoded form even if you pass
1386 a U-label. This breaks backwards compatibility, but only for
1387 internationalized domain names.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001388
Paul Kehrer31bdf792015-03-25 14:11:00 -05001389 This corresponds to a domain name. For example, ``cryptography.io``.
1390
Paul Kehrere885bd62017-10-11 20:29:23 +08001391 :param value: The domain name. If it is an internationalized domain
1392 name then it must be encoded to an :term:`A-label` string before being
1393 passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001394
Paul Kehrere885bd62017-10-11 20:29:23 +08001395 :type: :term:`text`
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001396
Paul Kehrer31bdf792015-03-25 14:11:00 -05001397 .. attribute:: value
1398
1399 :type: :term:`text`
1400
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001401.. class:: DirectoryName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001402
1403 .. versionadded:: 0.9
1404
1405 This corresponds to a directory name.
1406
1407 .. attribute:: value
1408
1409 :type: :class:`Name`
1410
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001411.. class:: UniformResourceIdentifier(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001412
1413 .. versionadded:: 0.9
1414
Paul Kehrere885bd62017-10-11 20:29:23 +08001415 .. versionchanged:: 2.1
Paul Kehrerb8ef82e2015-04-22 16:04:24 -05001416
Paul Kehrere885bd62017-10-11 20:29:23 +08001417 .. warning::
1418
1419 Starting with version 2.1 :term:`U-label` input is deprecated. If
1420 passing an internationalized domain name (IDN) you should first IDNA
1421 encode the value and then pass the result as a string. Accessing
1422 ``value`` will return the :term:`A-label` encoded form even if you pass
1423 a U-label. This breaks backwards compatibility, but only for
1424 internationalized domain names.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001425
1426 This corresponds to a uniform resource identifier. For example,
1427 ``https://cryptography.io``.
1428
Paul Kehrere885bd62017-10-11 20:29:23 +08001429 :param value: The URI. If it contains an internationalized domain
1430 name then it must be encoded to an :term:`A-label` string before
1431 being passed.
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:: IPAddress(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001438
1439 .. versionadded:: 0.9
1440
1441 This corresponds to an IP address.
1442
1443 .. attribute:: value
1444
Paul Kehrereb177932015-05-17 18:33:33 -07001445 :type: :class:`~ipaddress.IPv4Address`,
1446 :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
1447 or :class:`~ipaddress.IPv6Network`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001448
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001449.. class:: RegisteredID(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001450
1451 .. versionadded:: 0.9
1452
1453 This corresponds to a registered ID.
1454
1455 .. attribute:: value
1456
1457 :type: :class:`ObjectIdentifier`
1458
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001459.. class:: OtherName(type_id, value)
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001460
1461 .. versionadded:: 1.0
1462
Joshua Tauberer18b6fc82015-07-05 21:44:51 +00001463 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 +00001464
1465 .. attribute:: type_id
1466
1467 :type: :class:`ObjectIdentifier`
1468
1469 .. attribute:: value
1470
Paul Kehreredfedc12018-09-14 18:24:20 -04001471 :type: bytes
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001472
Paul Kehrer8cf26422015-03-21 09:50:24 -05001473X.509 Extensions
1474~~~~~~~~~~~~~~~~
1475
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001476.. class:: Extensions
1477
1478 .. versionadded:: 0.9
1479
1480 An X.509 Extensions instance is an ordered list of extensions. The object
1481 is iterable to get every extension.
1482
Paul Kehrerfa56a232015-03-17 13:14:03 -05001483 .. method:: get_extension_for_oid(oid)
1484
1485 :param oid: An :class:`ObjectIdentifier` instance.
1486
1487 :returns: An instance of the extension class.
1488
1489 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1490 not have the extension requested.
1491
Paul Kehrerfa56a232015-03-17 13:14:03 -05001492 .. doctest::
1493
Paul Kehrere27f6582015-08-10 18:33:38 -05001494 >>> from cryptography.x509.oid import ExtensionOID
1495 >>> cert.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS)
Paul Kehrerfa56a232015-03-17 13:14:03 -05001496 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1497
Phoebe Queen019b7f82015-08-12 03:52:03 +01001498 .. method:: get_extension_for_class(extclass)
1499
Phoebe Queen6a603eb2015-08-12 14:14:49 +01001500 .. versionadded:: 1.1
1501
Phoebe Queen019b7f82015-08-12 03:52:03 +01001502 :param extclass: An extension class.
1503
1504 :returns: An instance of the extension class.
1505
1506 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1507 not have the extension requested.
1508
1509 .. doctest::
1510
1511 >>> from cryptography import x509
1512 >>> cert.extensions.get_extension_for_class(x509.BasicConstraints)
1513 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1514
Paul Kehrer8cf26422015-03-21 09:50:24 -05001515.. class:: Extension
1516
1517 .. versionadded:: 0.9
1518
Paul Kehrer85894662015-03-22 13:19:31 -05001519 .. attribute:: oid
1520
1521 :type: :class:`ObjectIdentifier`
1522
Paul Kehrere27f6582015-08-10 18:33:38 -05001523 One of the :class:`~cryptography.x509.oid.ExtensionOID` OIDs.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001524
1525 .. attribute:: critical
1526
1527 :type: bool
1528
Paul Kehrer58b75692015-03-22 23:24:58 -05001529 Determines whether a given extension is critical or not. :rfc:`5280`
1530 requires that "A certificate-using system MUST reject the certificate
1531 if it encounters a critical extension it does not recognize or a
1532 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -05001533
Paul Kehrer85894662015-03-22 13:19:31 -05001534 .. attribute:: value
1535
1536 Returns an instance of the extension type corresponding to the OID.
1537
Paul Kehrer14f0bd02015-08-06 11:55:18 +01001538.. class:: ExtensionType
1539
1540 .. versionadded:: 1.0
1541
1542 This is the interface against which all the following extension types are
1543 registered.
1544
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001545.. 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 -05001546
1547 .. versionadded:: 0.9
1548
1549 The key usage extension defines the purpose of the key contained in the
1550 certificate. The usage restriction might be employed when a key that could
Paul Kehrerb33de932015-08-06 23:41:05 +01001551 be used for more than one operation is to be restricted.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001552
Paul Kehrer822f3d32015-08-06 11:47:32 +01001553 .. attribute:: oid
1554
1555 .. versionadded:: 1.0
1556
1557 :type: :class:`ObjectIdentifier`
1558
Paul Kehrere27f6582015-08-10 18:33:38 -05001559 Returns :attr:`~cryptography.x509.oid.ExtensionOID.KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001560
Paul Kehrercecbbba2015-03-30 14:58:38 -05001561 .. attribute:: digital_signature
1562
1563 :type: bool
1564
Paul Kehrer738407b2015-04-01 22:39:02 -05001565 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001566 digital signatures, other than signatures on certificates
1567 (``key_cert_sign``) and CRLs (``crl_sign``).
1568
1569 .. attribute:: content_commitment
1570
1571 :type: bool
1572
Paul Kehrer738407b2015-04-01 22:39:02 -05001573 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001574 digital signatures, other than signatures on certificates
1575 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
1576 non-repudiation service that protects against the signing entity
1577 falsely denying some action. In the case of later conflict, a
1578 reliable third party may determine the authenticity of the signed
1579 data. This was called ``non_repudiation`` in older revisions of the
1580 X.509 specification.
1581
1582 .. attribute:: key_encipherment
1583
1584 :type: bool
1585
Paul Kehrer738407b2015-04-01 22:39:02 -05001586 This purpose is set to true when the subject public key is used for
1587 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001588
1589 .. attribute:: data_encipherment
1590
1591 :type: bool
1592
Paul Kehrer738407b2015-04-01 22:39:02 -05001593 This purpose is set to true when the subject public key is used for
1594 directly enciphering raw user data without the use of an intermediate
1595 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001596
1597 .. attribute:: key_agreement
1598
1599 :type: bool
1600
Paul Kehrer738407b2015-04-01 22:39:02 -05001601 This purpose is set to true when the subject public key is used for key
1602 agreement. For example, when a Diffie-Hellman key is to be used for
1603 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001604
1605 .. attribute:: key_cert_sign
1606
1607 :type: bool
1608
Paul Kehrer738407b2015-04-01 22:39:02 -05001609 This purpose is set to true when the subject public key is used for
1610 verifying signatures on public key certificates. If this purpose is set
1611 to true then ``ca`` must be true in the :class:`BasicConstraints`
1612 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001613
1614 .. attribute:: crl_sign
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 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001620
1621 .. attribute:: encipher_only
1622
1623 :type: bool
1624
Paul Kehrer738407b2015-04-01 22:39:02 -05001625 When this purposes is set to true and the ``key_agreement`` purpose is
1626 also set, the subject public key may be used only for enciphering data
1627 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001628
1629 :raises ValueError: This is raised if accessed when ``key_agreement``
1630 is false.
1631
1632 .. attribute:: decipher_only
1633
1634 :type: bool
1635
Paul Kehrer738407b2015-04-01 22:39:02 -05001636 When this purposes is set to true and the ``key_agreement`` purpose is
1637 also set, the subject public key may be used only for deciphering data
1638 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001639
1640 :raises ValueError: This is raised if accessed when ``key_agreement``
1641 is false.
1642
1643
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001644.. class:: BasicConstraints(ca, path_length)
Paul Kehrer8cf26422015-03-21 09:50:24 -05001645
1646 .. versionadded:: 0.9
1647
Paul Kehrer85894662015-03-22 13:19:31 -05001648 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -05001649 certificate is allowed to sign additional certificates and what path
Paul Kehrerb33de932015-08-06 23:41:05 +01001650 length restrictions may exist.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001651
Paul Kehrer822f3d32015-08-06 11:47:32 +01001652 .. attribute:: oid
1653
1654 .. versionadded:: 1.0
1655
1656 :type: :class:`ObjectIdentifier`
1657
Paul Kehrere27f6582015-08-10 18:33:38 -05001658 Returns :attr:`~cryptography.x509.oid.ExtensionOID.BASIC_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001659
Paul Kehrer8cf26422015-03-21 09:50:24 -05001660 .. attribute:: ca
1661
1662 :type: bool
1663
1664 Whether the certificate can sign certificates.
1665
1666 .. attribute:: path_length
1667
Paul Kehrerfd1444c2015-03-21 19:47:05 -05001668 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -05001669
1670 The maximum path length for certificates subordinate to this
1671 certificate. This attribute only has meaning if ``ca`` is true.
1672 If ``ca`` is true then a path length of None means there's no
1673 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -04001674 If it is zero or greater then it defines the maximum length for a
1675 subordinate CA's certificate chain. For example, a ``path_length`` of 1
1676 means the certificate can sign a subordinate CA, but the subordinate CA
1677 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001678
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001679.. class:: ExtendedKeyUsage(usages)
Paul Kehrerffa2a152015-03-31 08:18:25 -05001680
1681 .. versionadded:: 0.9
1682
1683 This extension indicates one or more purposes for which the certified
1684 public key may be used, in addition to or in place of the basic
1685 purposes indicated in the key usage extension. The object is
Paul Kehrere27f6582015-08-10 18:33:38 -05001686 iterable to obtain the list of
1687 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs present.
Paul Kehrerffa2a152015-03-31 08:18:25 -05001688
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001689 :param list usages: A list of
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001690 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs.
1691
Paul Kehrer822f3d32015-08-06 11:47:32 +01001692 .. attribute:: oid
1693
1694 .. versionadded:: 1.0
1695
1696 :type: :class:`ObjectIdentifier`
1697
Paul Kehrere27f6582015-08-10 18:33:38 -05001698 Returns :attr:`~cryptography.x509.oid.ExtensionOID.EXTENDED_KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001699
1700
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001701.. class:: OCSPNoCheck()
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001702
Paul Kehrer506a2152015-05-26 08:01:18 -05001703 .. versionadded:: 1.0
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001704
1705 This presence of this extension indicates that an OCSP client can trust a
1706 responder for the lifetime of the responder's certificate. CAs issuing
1707 such a certificate should realize that a compromise of the responder's key
1708 is as serious as the compromise of a CA key used to sign CRLs, at least for
1709 the validity period of this certificate. CA's may choose to issue this type
1710 of certificate with a very short lifetime and renew it frequently. This
1711 extension is only relevant when the certificate is an authorized OCSP
1712 responder.
1713
Paul Kehrer822f3d32015-08-06 11:47:32 +01001714 .. attribute:: oid
1715
1716 .. versionadded:: 1.0
1717
1718 :type: :class:`ObjectIdentifier`
1719
Paul Kehrere27f6582015-08-10 18:33:38 -05001720 Returns :attr:`~cryptography.x509.oid.ExtensionOID.OCSP_NO_CHECK`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001721
Paul Kehrer5d669662017-09-11 09:16:34 +08001722
1723.. class:: TLSFeature(features)
1724
1725 .. versionadded:: 2.1
1726
1727 The TLS Feature extension is defined in :rfc:`7633` and is used in
1728 certificates for OCSP Must-Staple. The object is iterable to get every
1729 element.
1730
1731 :param list features: A list of features to enable from the
1732 :class:`~cryptography.x509.TLSFeatureType` enum. At this time only
1733 ``status_request`` or ``status_request_v2`` are allowed.
1734
1735 .. attribute:: oid
1736
1737 :type: :class:`ObjectIdentifier`
1738
1739 Returns :attr:`~cryptography.x509.oid.ExtensionOID.TLS_FEATURE`.
1740
1741.. class:: TLSFeatureType
1742
1743 .. versionadded:: 2.1
1744
1745 An enumeration of TLS Feature types.
1746
1747 .. attribute:: status_request
1748
1749 This feature type is defined in :rfc:`6066` and, when embedded in
1750 an X.509 certificate, signals to the client that it should require
1751 a stapled OCSP response in the TLS handshake. Commonly known as OCSP
1752 Must-Staple in certificates.
1753
1754 .. attribute:: status_request_v2
1755
1756 This feature type is defined in :rfc:`6961`. This value is not
1757 commonly used and if you want to enable OCSP Must-Staple you should
1758 use ``status_request``.
1759
1760
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001761.. class:: NameConstraints(permitted_subtrees, excluded_subtrees)
Paul Kehrere0017be2015-05-17 20:39:40 -06001762
1763 .. versionadded:: 1.0
1764
1765 The name constraints extension, which only has meaning in a CA certificate,
1766 defines a name space within which all subject names in certificates issued
1767 beneath the CA certificate must (or must not) be in. For specific details
1768 on the way this extension should be processed see :rfc:`5280`.
1769
Paul Kehrer822f3d32015-08-06 11:47:32 +01001770 .. attribute:: oid
1771
1772 .. versionadded:: 1.0
1773
1774 :type: :class:`ObjectIdentifier`
1775
Paul Kehrere27f6582015-08-10 18:33:38 -05001776 Returns :attr:`~cryptography.x509.oid.ExtensionOID.NAME_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001777
Paul Kehrere0017be2015-05-17 20:39:40 -06001778 .. attribute:: permitted_subtrees
1779
1780 :type: list of :class:`GeneralName` objects or None
1781
1782 The set of permitted name patterns. If a name matches this and an
1783 element in ``excluded_subtrees`` it is invalid. At least one of
1784 ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None.
1785
1786 .. attribute:: excluded_subtrees
1787
1788 :type: list of :class:`GeneralName` objects or None
1789
1790 Any name matching a restriction in the ``excluded_subtrees`` field is
1791 invalid regardless of information appearing in the
1792 ``permitted_subtrees``. At least one of ``permitted_subtrees`` and
1793 ``excluded_subtrees`` will be non-None.
1794
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001795.. class:: AuthorityKeyIdentifier(key_identifier, authority_cert_issuer, authority_cert_serial_number)
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001796
1797 .. versionadded:: 0.9
1798
1799 The authority key identifier extension provides a means of identifying the
1800 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001801 This extension is typically used to assist in determining the appropriate
1802 certificate chain. For more information about generation and use of this
1803 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001804
Paul Kehrer822f3d32015-08-06 11:47:32 +01001805 .. attribute:: oid
1806
1807 .. versionadded:: 1.0
1808
1809 :type: :class:`ObjectIdentifier`
1810
Paul Kehrere27f6582015-08-10 18:33:38 -05001811 Returns
1812 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001813
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001814 .. attribute:: key_identifier
1815
1816 :type: bytes
1817
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001818 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001819 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001820
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001821 .. attribute:: authority_cert_issuer
1822
Thom Dixon488c0482018-05-18 03:55:29 -07001823 :type: A list of :class:`GeneralName` instances or None
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001824
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001825 The :class:`Name` of the issuer's issuer.
1826
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001827 .. attribute:: authority_cert_serial_number
1828
1829 :type: int or None
1830
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001831 The serial number of the issuer's issuer.
1832
Paul Kehrer253929a2015-08-05 17:30:39 +01001833 .. classmethod:: from_issuer_public_key(public_key)
1834
1835 .. versionadded:: 1.0
1836
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001837 .. note::
1838
1839 This method should be used if the issuer certificate does not
1840 contain a :class:`~cryptography.x509.SubjectKeyIdentifier`.
1841 Otherwise, use
1842 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier`.
1843
Paul Kehrer253929a2015-08-05 17:30:39 +01001844 Creates a new AuthorityKeyIdentifier instance using the public key
1845 provided to generate the appropriate digest. This should be the
Paul Kehrer26ac47f2015-08-08 15:20:52 -05001846 **issuer's public key**. The resulting object will contain
1847 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1848 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1849 and
1850 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1851 will be None.
1852 The generated ``key_identifier`` is the SHA1 hash of the ``subjectPublicKey``
1853 ASN.1 bit string. This is the first recommendation in :rfc:`5280`
Paul Kehrer253929a2015-08-05 17:30:39 +01001854 section 4.2.1.2.
1855
Paul Kehrercc671822015-08-08 15:41:54 -05001856 :param public_key: One of
1857 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1858 ,
1859 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1860 , or
1861 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
Paul Kehrer253929a2015-08-05 17:30:39 +01001862
1863 .. doctest::
1864
1865 >>> from cryptography import x509
1866 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001867 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1868 >>> x509.AuthorityKeyIdentifier.from_issuer_public_key(issuer_cert.public_key())
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001869 <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 +01001870
Paul Kehrer61ff3562016-03-11 22:51:27 -04001871 .. classmethod:: from_issuer_subject_key_identifier(ski)
1872
1873 .. versionadded:: 1.3
1874
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001875 .. note::
1876 This method should be used if the issuer certificate contains a
1877 :class:`~cryptography.x509.SubjectKeyIdentifier`. Otherwise, use
1878 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_public_key`.
1879
Paul Kehrer61ff3562016-03-11 22:51:27 -04001880 Creates a new AuthorityKeyIdentifier instance using the
1881 SubjectKeyIdentifier from the issuer certificate. The resulting object
1882 will contain
1883 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1884 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1885 and
1886 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1887 will be None.
1888
1889 :param ski: The
1890 :class:`~cryptography.x509.SubjectKeyIdentifier` from the issuer
1891 certificate.
1892
1893 .. doctest::
1894
1895 >>> from cryptography import x509
1896 >>> from cryptography.hazmat.backends import default_backend
1897 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1898 >>> ski = issuer_cert.extensions.get_extension_for_class(x509.SubjectKeyIdentifier)
1899 >>> x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier(ski)
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 Kehrer61ff3562016-03-11 22:51:27 -04001901
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001902.. class:: SubjectKeyIdentifier(digest)
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001903
1904 .. versionadded:: 0.9
1905
1906 The subject key identifier extension provides a means of identifying
1907 certificates that contain a particular public key.
1908
Paul Kehrer822f3d32015-08-06 11:47:32 +01001909 .. attribute:: oid
1910
1911 .. versionadded:: 1.0
1912
1913 :type: :class:`ObjectIdentifier`
1914
Paul Kehrere27f6582015-08-10 18:33:38 -05001915 Returns
1916 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001917
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001918 .. attribute:: digest
1919
1920 :type: bytes
1921
1922 The binary value of the identifier.
1923
Paul Kehrerd4a7f062015-08-05 18:32:18 +01001924 .. classmethod:: from_public_key(public_key)
Paul Kehrerf22f6122015-08-05 12:57:13 +01001925
1926 .. versionadded:: 1.0
1927
1928 Creates a new SubjectKeyIdentifier instance using the public key
1929 provided to generate the appropriate digest. This should be the public
Paul Kehrereb9ec002015-08-08 10:03:02 -05001930 key that is in the certificate. The generated digest is the SHA1 hash
1931 of the ``subjectPublicKey`` ASN.1 bit string. This is the first
1932 recommendation in :rfc:`5280` section 4.2.1.2.
Paul Kehrerf22f6122015-08-05 12:57:13 +01001933
1934 :param public_key: One of
1935 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1936 ,
1937 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1938 , or
1939 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
1940
Paul Kehrer253929a2015-08-05 17:30:39 +01001941 .. doctest::
1942
1943 >>> from cryptography import x509
1944 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001945 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
1946 >>> x509.SubjectKeyIdentifier.from_public_key(csr.public_key())
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001947 <SubjectKeyIdentifier(digest=b'\xdb\xaa\xf0\x06\x11\xdbD\xfe\xbf\x93\x03\x8av\x88WP7\xa6\x91\xf7')>
Paul Kehrer253929a2015-08-05 17:30:39 +01001948
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001949.. class:: SubjectAlternativeName(general_names)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001950
1951 .. versionadded:: 0.9
1952
1953 Subject alternative name is an X.509 extension that provides a list of
1954 :ref:`general name <general_name_classes>` instances that provide a set
1955 of identities for which the certificate is valid. The object is iterable to
1956 get every element.
1957
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001958 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001959
Paul Kehrer822f3d32015-08-06 11:47:32 +01001960 .. attribute:: oid
1961
1962 .. versionadded:: 1.0
1963
1964 :type: :class:`ObjectIdentifier`
1965
Paul Kehrere27f6582015-08-10 18:33:38 -05001966 Returns
1967 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001968
Paul Kehrer31bdf792015-03-25 14:11:00 -05001969 .. method:: get_values_for_type(type)
1970
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03001971 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer31bdf792015-03-25 14:11:00 -05001972 :ref:`general name classes <general_name_classes>`.
1973
1974 :returns: A list of values extracted from the matched general names.
Joshua Taubererd2afad32015-07-06 22:37:53 +00001975 The type of the returned values depends on the :class:`GeneralName`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001976
Paul Kehrer93ae8052015-05-02 23:18:09 -05001977 .. doctest::
1978
1979 >>> from cryptography import x509
1980 >>> from cryptography.hazmat.backends import default_backend
1981 >>> from cryptography.hazmat.primitives import hashes
1982 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend())
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001983 >>> # Get the subjectAltName extension from the certificate
Paul Kehrere27f6582015-08-10 18:33:38 -05001984 >>> ext = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001985 >>> # Get the dNSName entries from the SAN extension
1986 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001987 ['www.cryptography.io', 'cryptography.io']
Paul Kehrer93ae8052015-05-02 23:18:09 -05001988
Paul Kehrer8cf26422015-03-21 09:50:24 -05001989
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001990.. class:: IssuerAlternativeName(general_names)
Paul Kehrer99125c92015-06-07 18:37:10 -05001991
1992 .. versionadded:: 1.0
1993
1994 Issuer alternative name is an X.509 extension that provides a list of
1995 :ref:`general name <general_name_classes>` instances that provide a set
1996 of identities for the certificate issuer. The object is iterable to
1997 get every element.
1998
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001999 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002000
Paul Kehrer822f3d32015-08-06 11:47:32 +01002001 .. attribute:: oid
2002
2003 .. versionadded:: 1.0
2004
2005 :type: :class:`ObjectIdentifier`
2006
Paul Kehrere27f6582015-08-10 18:33:38 -05002007 Returns
2008 :attr:`~cryptography.x509.oid.ExtensionOID.ISSUER_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002009
Paul Kehrer99125c92015-06-07 18:37:10 -05002010 .. method:: get_values_for_type(type)
2011
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03002012 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer99125c92015-06-07 18:37:10 -05002013 :ref:`general name classes <general_name_classes>`.
2014
2015 :returns: A list of values extracted from the matched general names.
2016
2017
Alex Gaynor6a0718f2017-06-04 13:36:58 -04002018.. class:: PrecertificateSignedCertificateTimestamps(scts)
2019
2020 .. versionadded:: 2.0
2021
2022 This extension contains
2023 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2024 instances which were issued for the pre-certificate corresponding to this
2025 certificate. These can be used to verify that the certificate is included
2026 in a public Certificate Transparency log.
2027
2028 It is an iterable containing one or more
2029 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2030 objects.
2031
2032 :param list scts: A ``list`` of
2033 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2034 objects.
2035
2036 .. attribute:: oid
2037
2038 :type: :class:`ObjectIdentifier`
2039
2040 Returns
2041 :attr:`~cryptography.x509.oid.ExtensionOID.PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS`.
2042
2043
Alex Gaynordd6b78b2018-08-31 18:25:52 -05002044.. class:: PrecertPoison()
2045
2046 .. versionadded:: 2.4
2047
2048 This extension indicates that the certificate should not be treated as a
2049 certificate for the purposes of validation, but is instead for submission
2050 to a certificate transparency log in order to obtain SCTs which will be
2051 embedded in a :class:`PrecertificateSignedCertificateTimestamps` extension
2052 on the final certificate.
2053
2054 .. attribute:: oid
2055
2056 :type: :class:`ObjectIdentifier`
2057
2058 Returns :attr:`~cryptography.x509.oid.ExtensionOID.PRECERT_POISON`.
2059
2060
Paul Kehrer5e3cc982017-09-22 21:29:36 +08002061.. class:: DeltaCRLIndicator(crl_number)
2062
2063 .. versionadded:: 2.1
2064
2065 The delta CRL indicator is a CRL extension that identifies a CRL as being
2066 a delta CRL. Delta CRLs contain updates to revocation information
2067 previously distributed, rather than all the information that would appear
2068 in a complete CRL.
2069
2070 :param int crl_number: The CRL number of the complete CRL that the
2071 delta CRL is updating.
2072
2073 .. attribute:: oid
2074
2075 :type: :class:`ObjectIdentifier`
2076
2077 Returns
2078 :attr:`~cryptography.x509.oid.ExtensionOID.DELTA_CRL_INDICATOR`.
2079
2080 .. attribute:: crl_number
2081
2082 :type: int
2083
2084
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002085.. class:: AuthorityInformationAccess(descriptions)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002086
2087 .. versionadded:: 0.9
2088
2089 The authority information access extension indicates how to access
2090 information and services for the issuer of the certificate in which
2091 the extension appears. Information and services may include online
2092 validation services (such as OCSP) and issuer data. It is an iterable,
Paul Kehrere27f6582015-08-10 18:33:38 -05002093 containing one or more :class:`~cryptography.x509.AccessDescription`
2094 instances.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002095
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002096 :param list descriptions: A list of :class:`AccessDescription` objects.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002097
Paul Kehrer822f3d32015-08-06 11:47:32 +01002098 .. attribute:: oid
2099
2100 .. versionadded:: 1.0
2101
2102 :type: :class:`ObjectIdentifier`
2103
Paul Kehrere27f6582015-08-10 18:33:38 -05002104 Returns
2105 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_INFORMATION_ACCESS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002106
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002107
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002108.. class:: AccessDescription(access_method, access_location)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002109
Paul Kehrer5a485522015-05-06 00:29:12 -05002110 .. versionadded:: 0.9
2111
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002112 .. attribute:: access_method
2113
2114 :type: :class:`ObjectIdentifier`
2115
Paul Kehrerf506bca2015-05-02 22:31:47 -05002116 The access method defines what the ``access_location`` means. It must
Paul Kehrere27f6582015-08-10 18:33:38 -05002117 be either
2118 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP` or
2119 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`.
2120 If it is
2121 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP`
2122 the access location will be where to obtain OCSP
2123 information for the certificate. If it is
2124 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`
2125 the access location will provide additional information about the
2126 issuing certificate.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002127
2128 .. attribute:: access_location
2129
2130 :type: :class:`GeneralName`
2131
Paul Kehrerf506bca2015-05-02 22:31:47 -05002132 Where to access the information defined by the access method.
2133
Paul Kehrerb76bcf82017-09-24 08:44:12 +08002134.. class:: FreshestCRL(distribution_points)
2135
2136 .. versionadded:: 2.1
2137
2138 The freshest CRL extension (also known as Delta CRL Distribution Point)
2139 identifies how delta CRL information is obtained. It is an iterable,
2140 containing one or more :class:`DistributionPoint` instances.
2141
2142 :param list distribution_points: A list of :class:`DistributionPoint`
2143 instances.
2144
2145 .. attribute:: oid
2146
2147 :type: :class:`ObjectIdentifier`
2148
2149 Returns
2150 :attr:`~cryptography.x509.oid.ExtensionOID.FRESHEST_CRL`.
2151
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002152.. class:: CRLDistributionPoints(distribution_points)
Paul Kehrer5a485522015-05-06 00:29:12 -05002153
2154 .. versionadded:: 0.9
2155
2156 The CRL distribution points extension identifies how CRL information is
2157 obtained. It is an iterable, containing one or more
2158 :class:`DistributionPoint` instances.
2159
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002160 :param list distribution_points: A list of :class:`DistributionPoint`
2161 instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002162
Paul Kehrer822f3d32015-08-06 11:47:32 +01002163 .. attribute:: oid
2164
2165 .. versionadded:: 1.0
2166
2167 :type: :class:`ObjectIdentifier`
2168
Paul Kehrere27f6582015-08-10 18:33:38 -05002169 Returns
2170 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_DISTRIBUTION_POINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002171
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002172.. class:: DistributionPoint(full_name, relative_name, reasons, crl_issuer)
Paul Kehrer5a485522015-05-06 00:29:12 -05002173
2174 .. versionadded:: 0.9
2175
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002176 .. attribute:: full_name
Paul Kehrer5a485522015-05-06 00:29:12 -05002177
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002178 :type: list of :class:`GeneralName` instances or None
Paul Kehrer5a485522015-05-06 00:29:12 -05002179
Paul Kehrerf2c072b2015-05-09 17:04:28 -05002180 This field describes methods to retrieve the CRL. At most one of
2181 ``full_name`` or ``relative_name`` will be non-None.
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002182
2183 .. attribute:: relative_name
2184
Fraser Tweedale02467dd2016-11-07 15:54:04 +10002185 :type: :class:`RelativeDistinguishedName` or None
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002186
2187 This field describes methods to retrieve the CRL relative to the CRL
Paul Kehrerf2c072b2015-05-09 17:04:28 -05002188 issuer. At most one of ``full_name`` or ``relative_name`` will be
2189 non-None.
Paul Kehrer5a485522015-05-06 00:29:12 -05002190
Fraser Tweedale02467dd2016-11-07 15:54:04 +10002191 .. versionchanged:: 1.6
2192 Changed from :class:`Name` to :class:`RelativeDistinguishedName`.
2193
Paul Kehrer5a485522015-05-06 00:29:12 -05002194 .. attribute:: crl_issuer
2195
2196 :type: list of :class:`GeneralName` instances or None
2197
2198 Information about the issuer of the CRL.
2199
2200 .. attribute:: reasons
2201
Paul Kehrer3fd02602015-05-09 19:46:13 -05002202 :type: frozenset of :class:`ReasonFlags` or None
Paul Kehrer5a485522015-05-06 00:29:12 -05002203
2204 The reasons a given distribution point may be used for when performing
2205 revocation checks.
2206
2207.. class:: ReasonFlags
2208
2209 .. versionadded:: 0.9
2210
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002211 An enumeration for CRL reasons.
2212
2213 .. attribute:: unspecified
2214
2215 It is unspecified why the certificate was revoked. This reason cannot
2216 be used as a reason flag in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05002217
2218 .. attribute:: key_compromise
2219
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002220 This reason indicates that the private key was compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05002221
2222 .. attribute:: ca_compromise
2223
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002224 This reason indicates that the CA issuing the certificate was
2225 compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05002226
2227 .. attribute:: affiliation_changed
2228
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002229 This reason indicates that the subject's name or other information has
2230 changed.
Paul Kehrer5a485522015-05-06 00:29:12 -05002231
2232 .. attribute:: superseded
2233
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002234 This reason indicates that a certificate has been superseded.
Paul Kehrer5a485522015-05-06 00:29:12 -05002235
2236 .. attribute:: cessation_of_operation
2237
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002238 This reason indicates that the certificate is no longer required.
Paul Kehrer5a485522015-05-06 00:29:12 -05002239
2240 .. attribute:: certificate_hold
2241
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002242 This reason indicates that the certificate is on hold.
Paul Kehrer5a485522015-05-06 00:29:12 -05002243
2244 .. attribute:: privilege_withdrawn
2245
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002246 This reason indicates that the privilege granted by this certificate
2247 have been withdrawn.
Paul Kehrer5a485522015-05-06 00:29:12 -05002248
2249 .. attribute:: aa_compromise
2250
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002251 When an attribute authority has been compromised.
2252
2253 .. attribute:: remove_from_crl
2254
2255 This reason indicates that the certificate was on hold and should be
2256 removed from the CRL. This reason cannot be used as a reason flag
2257 in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05002258
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002259.. class:: InhibitAnyPolicy(skip_certs)
Paul Kehrer16fae762015-05-01 23:14:20 -05002260
2261 .. versionadded:: 1.0
2262
2263 The inhibit ``anyPolicy`` extension indicates that the special OID
Paul Kehrere27f6582015-08-10 18:33:38 -05002264 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY`, is not
2265 considered an explicit match for other :class:`CertificatePolicies` except
2266 when it appears in an intermediate self-issued CA certificate. The value
2267 indicates the number of additional non-self-issued certificates that may
2268 appear in the path before
2269 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` is no
2270 longer permitted. For example, a value of one indicates that
2271 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` may be
2272 processed in certificates issued by the subject of this certificate, but
2273 not in additional certificates in the path.
Paul Kehrer16fae762015-05-01 23:14:20 -05002274
Paul Kehrer822f3d32015-08-06 11:47:32 +01002275 .. attribute:: oid
2276
2277 .. versionadded:: 1.0
2278
2279 :type: :class:`ObjectIdentifier`
2280
Paul Kehrere27f6582015-08-10 18:33:38 -05002281 Returns
2282 :attr:`~cryptography.x509.oid.ExtensionOID.INHIBIT_ANY_POLICY`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002283
Paul Kehrer16fae762015-05-01 23:14:20 -05002284 .. attribute:: skip_certs
2285
2286 :type: int
2287
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002288.. class:: PolicyConstraints
2289
2290 .. versionadded:: 1.3
2291
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002292 The policy constraints extension is used to inhibit policy mapping or
2293 require that each certificate in a chain contain an acceptable policy
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002294 identifier. For more information about the use of this extension see
2295 :rfc:`5280`.
2296
Paul Kehrer159b3b52016-02-26 08:27:22 -06002297 .. attribute:: oid
2298
2299 :type: :class:`ObjectIdentifier`
2300
2301 Returns :attr:`~cryptography.x509.oid.ExtensionOID.POLICY_CONSTRAINTS`.
2302
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002303 .. attribute:: require_explicit_policy
2304
2305 :type: int or None
2306
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002307 If this field is not None, the value indicates the number of additional
2308 certificates that may appear in the chain before an explicit policy is
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002309 required for the entire path. When an explicit policy is required, it
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002310 is necessary for all certificates in the chain to contain an acceptable
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002311 policy identifier in the certificate policies extension. An
2312 acceptable policy identifier is the identifier of a policy required
2313 by the user of the certification path or the identifier of a policy
2314 that has been declared equivalent through policy mapping.
2315
2316 .. attribute:: inhibit_policy_mapping
2317
2318 :type: int or None
2319
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002320 If this field is not None, the value indicates the number of additional
2321 certificates that may appear in the chain before policy mapping is no
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002322 longer permitted. For example, a value of one indicates that policy
2323 mapping may be processed in certificates issued by the subject of this
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002324 certificate, but not in additional certificates in the chain.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002325
Paul Kehrer3b95cd72015-12-22 21:40:20 -06002326.. class:: CRLNumber(crl_number)
2327
2328 .. versionadded:: 1.2
2329
Paul Kehrere32b9942015-12-22 22:26:53 -06002330 The CRL number is a CRL extension that conveys a monotonically increasing
2331 sequence number for a given CRL scope and CRL issuer. This extension allows
2332 users to easily determine when a particular CRL supersedes another CRL.
2333 :rfc:`5280` requires that this extension be present in conforming CRLs.
Paul Kehrer3b95cd72015-12-22 21:40:20 -06002334
2335 .. attribute:: oid
2336
2337 :type: :class:`ObjectIdentifier`
2338
2339 Returns
2340 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_NUMBER`.
2341
2342 .. attribute:: crl_number
2343
2344 :type: int
2345
Paul Kehrereb3e2e02018-12-01 12:15:20 +08002346.. class:: IssuingDistributionPoint(full_name, relative_name,\
2347 only_contains_user_certs, only_contains_ca_certs, only_some_reasons,\
2348 indirect_crl, only_contains_attribute_certs)
2349
2350 .. versionadded:: 2.5
2351
2352 Issuing distribution point is a CRL extension that identifies the CRL
2353 distribution point and scope for a particular CRL. It indicates whether
2354 the CRL covers revocation for end entity certificates only, CA certificates
2355 only, attribute certificates only, or a limited set of reason codes. For
2356 specific details on the way this extension should be processed see
2357 :rfc:`5280`.
2358
2359 .. attribute:: oid
2360
2361 :type: :class:`ObjectIdentifier`
2362
2363 Returns
2364 :attr:`~cryptography.x509.oid.ExtensionOID.ISSUING_DISTRIBUTION_POINT`.
2365
2366 .. attribute:: only_contains_user_certs
2367
2368 :type: bool
2369
2370 Set to ``True`` if the CRL this extension is embedded within only
2371 contains information about user certificates.
2372
2373 .. attribute:: only_contains_ca_certs
2374
2375 :type: bool
2376
2377 Set to ``True`` if the CRL this extension is embedded within only
2378 contains information about CA certificates.
2379
2380 .. attribute:: indirect_crl
2381
2382 :type: bool
2383
2384 Set to ``True`` if the CRL this extension is embedded within includes
2385 certificates issued by one or more authorities other than the CRL
2386 issuer.
2387
2388 .. attribute:: only_contains_attribute_certs
2389
2390 :type: bool
2391
2392 Set to ``True`` if the CRL this extension is embedded within only
2393 contains information about attribute certificates.
2394
2395 .. attribute:: only_some_reasons
2396
2397 :type: frozenset of :class:`ReasonFlags` or None
2398
2399 The reasons for which the issuing distribution point is valid. None
2400 indicates that it is valid for all reasons.
2401
2402 .. attribute:: full_name
2403
2404 :type: list of :class:`GeneralName` instances or None
2405
2406 This field describes methods to retrieve the CRL. At most one of
2407 ``full_name`` or ``relative_name`` will be non-None.
2408
2409 .. attribute:: relative_name
2410
2411 :type: :class:`RelativeDistinguishedName` or None
2412
2413 This field describes methods to retrieve the CRL relative to the CRL
2414 issuer. At most one of ``full_name`` or ``relative_name`` will be
2415 non-None.
2416
Paul Kehrer14fd6972015-12-30 10:58:25 -06002417.. class:: UnrecognizedExtension
2418
2419 .. versionadded:: 1.2
2420
Alex Gaynord08ddd52017-05-20 09:01:54 -07002421 A generic extension class used to hold the raw value of extensions that
2422 ``cryptography`` does not know how to parse.
Paul Kehrer14fd6972015-12-30 10:58:25 -06002423
2424 .. attribute:: oid
2425
2426 :type: :class:`ObjectIdentifier`
2427
2428 Returns the OID associated with this extension.
2429
2430 .. attribute:: value
2431
Paul Kehreredfedc12018-09-14 18:24:20 -04002432 :type: bytes
Paul Kehrer14fd6972015-12-30 10:58:25 -06002433
2434 Returns the DER encoded bytes payload of the extension.
2435
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002436.. class:: CertificatePolicies(policies)
Paul Kehrer0d210922015-04-28 17:31:07 -05002437
2438 .. versionadded:: 0.9
2439
Paul Kehrer2e879742015-05-02 23:09:56 -05002440 The certificate policies extension is an iterable, containing one or more
2441 :class:`PolicyInformation` instances.
Paul Kehrer0d210922015-04-28 17:31:07 -05002442
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002443 :param list policies: A list of :class:`PolicyInformation` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002444
Paul Kehrer822f3d32015-08-06 11:47:32 +01002445 .. attribute:: oid
2446
2447 .. versionadded:: 1.0
2448
2449 :type: :class:`ObjectIdentifier`
2450
Paul Kehrere27f6582015-08-10 18:33:38 -05002451 Returns
2452 :attr:`~cryptography.x509.oid.ExtensionOID.CERTIFICATE_POLICIES`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002453
Paul Kehrer0d210922015-04-28 17:31:07 -05002454Certificate Policies Classes
2455~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2456
2457These classes may be present within a :class:`CertificatePolicies` instance.
2458
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002459.. class:: PolicyInformation(policy_identifier, policy_qualifiers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002460
2461 .. versionadded:: 0.9
2462
2463 Contains a policy identifier and an optional list of qualifiers.
2464
2465 .. attribute:: policy_identifier
2466
2467 :type: :class:`ObjectIdentifier`
2468
2469 .. attribute:: policy_qualifiers
2470
2471 :type: list
2472
Paul Kehrerba35b3b2015-05-10 13:07:59 -05002473 A list consisting of :term:`text` and/or :class:`UserNotice` objects.
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002474 If the value is text it is a pointer to the practice statement
2475 published by the certificate authority. If it is a user notice it is
2476 meant for display to the relying party when the certificate is
2477 used.
Paul Kehrer2e879742015-05-02 23:09:56 -05002478
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002479.. class:: UserNotice(notice_reference, explicit_text)
Paul Kehrer0d210922015-04-28 17:31:07 -05002480
2481 .. versionadded:: 0.9
2482
Paul Kehrer2e879742015-05-02 23:09:56 -05002483 User notices are intended for display to a relying party when a certificate
2484 is used. In practice, few if any UIs expose this data and it is a rarely
2485 encoded component.
2486
Paul Kehrer0d210922015-04-28 17:31:07 -05002487 .. attribute:: notice_reference
2488
2489 :type: :class:`NoticeReference` or None
2490
Paul Kehrer2e879742015-05-02 23:09:56 -05002491 The notice reference field names an organization and identifies,
2492 by number, a particular statement prepared by that organization.
2493
Paul Kehrer0d210922015-04-28 17:31:07 -05002494 .. attribute:: explicit_text
2495
Paul Kehrer2e879742015-05-02 23:09:56 -05002496 This field includes an arbitrary textual statement directly in the
2497 certificate.
2498
Paul Kehrer0d210922015-04-28 17:31:07 -05002499 :type: :term:`text`
2500
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002501.. class:: NoticeReference(organization, notice_numbers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002502
Paul Kehrer2e879742015-05-02 23:09:56 -05002503 Notice reference can name an organization and provide information about
2504 notices related to the certificate. For example, it might identify the
2505 organization name and notice number 1. Application software could
2506 have a notice file containing the current set of notices for the named
2507 organization; the application would then extract the notice text from the
2508 file and display it. In practice this is rarely seen.
2509
Paul Kehrer0d210922015-04-28 17:31:07 -05002510 .. versionadded:: 0.9
2511
2512 .. attribute:: organization
2513
Paul Kehrer66c61702015-05-12 16:39:18 -05002514 :type: :term:`text`
Paul Kehrer0d210922015-04-28 17:31:07 -05002515
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002516 .. attribute:: notice_numbers
Paul Kehrer0d210922015-04-28 17:31:07 -05002517
Paul Kehrer66c61702015-05-12 16:39:18 -05002518 :type: list
Paul Kehrer0d210922015-04-28 17:31:07 -05002519
Paul Kehrer66c61702015-05-12 16:39:18 -05002520 A list of integers.
Paul Kehrer0d210922015-04-28 17:31:07 -05002521
Paul Kehrere5f152b2015-12-25 23:55:47 -06002522.. _crl_entry_extensions:
2523
Paul Kehrer49bb7562015-12-25 16:17:40 -06002524CRL Entry Extensions
2525~~~~~~~~~~~~~~~~~~~~
2526
2527These extensions are only valid within a :class:`RevokedCertificate` object.
2528
2529.. class:: CertificateIssuer(general_names)
2530
2531 .. versionadded:: 1.2
2532
2533 The certificate issuer is an extension that is only valid inside
2534 :class:`~cryptography.x509.RevokedCertificate` objects. If the
2535 ``indirectCRL`` property of the parent CRL's IssuingDistributionPoint
2536 extension is set, then this extension identifies the certificate issuer
2537 associated with the revoked certificate. The object is iterable to get
2538 every element.
2539
2540 :param list general_names: A list of :class:`GeneralName` instances.
2541
2542 .. attribute:: oid
2543
2544 :type: :class:`ObjectIdentifier`
2545
2546 Returns
2547 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CERTIFICATE_ISSUER`.
2548
2549 .. method:: get_values_for_type(type)
2550
2551 :param type: A :class:`GeneralName` instance. This is one of the
2552 :ref:`general name classes <general_name_classes>`.
2553
2554 :returns: A list of values extracted from the matched general names.
2555 The type of the returned values depends on the :class:`GeneralName`.
2556
Paul Kehrer7058ece2015-12-25 22:28:29 -06002557.. class:: CRLReason(reason)
2558
2559 .. versionadded:: 1.2
2560
2561 CRL reason (also known as ``reasonCode``) is an extension that is only
2562 valid inside :class:`~cryptography.x509.RevokedCertificate` objects. It
2563 identifies a reason for the certificate revocation.
2564
Paul Kehrerce4d0842017-09-20 22:14:26 +08002565 :param reason: An element from :class:`~cryptography.x509.ReasonFlags`.
Paul Kehrer7058ece2015-12-25 22:28:29 -06002566
2567 .. attribute:: oid
2568
2569 :type: :class:`ObjectIdentifier`
2570
2571 Returns
2572 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CRL_REASON`.
2573
2574 .. attribute:: reason
2575
2576 :type: An element from :class:`~cryptography.x509.ReasonFlags`
2577
Paul Kehrer23c0bbc2015-12-25 22:35:19 -06002578.. class:: InvalidityDate(invalidity_date)
2579
2580 .. versionadded:: 1.2
2581
2582 Invalidity date is an extension that is only valid inside
2583 :class:`~cryptography.x509.RevokedCertificate` objects. It provides
2584 the date on which it is known or suspected that the private key was
2585 compromised or that the certificate otherwise became invalid.
2586 This date may be earlier than the revocation date in the CRL entry,
2587 which is the date at which the CA processed the revocation.
2588
2589 :param invalidity_date: The :class:`datetime.datetime` when it is known
2590 or suspected that the private key was compromised.
2591
2592 .. attribute:: oid
2593
2594 :type: :class:`ObjectIdentifier`
2595
2596 Returns
2597 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.INVALIDITY_DATE`.
2598
2599 .. attribute:: invalidity_date
2600
2601 :type: :class:`datetime.datetime`
2602
Paul Kehrer09403102018-09-09 21:57:21 -05002603OCSP Extensions
2604~~~~~~~~~~~~~~~
2605
2606.. class:: OCSPNonce(nonce)
2607
2608 .. versionadded:: 2.4
2609
2610 OCSP nonce is an extension that is only valid inside
2611 :class:`~cryptography.x509.ocsp.OCSPRequest` and
2612 :class:`~cryptography.x509.ocsp.OCSPResponse` objects. The nonce
2613 cryptographically binds a request and a response to prevent replay attacks.
2614 In practice nonces are rarely used in OCSP due to the desire to precompute
2615 OCSP responses at large scale.
2616
2617 .. attribute:: oid
2618
2619 :type: :class:`ObjectIdentifier`
2620
2621 Returns
2622 :attr:`~cryptography.x509.oid.OCSPExtensionOID.NONCE`.
2623
2624 .. attribute:: nonce
2625
2626 :type: bytes
Paul Kehrer49bb7562015-12-25 16:17:40 -06002627
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002628Object Identifiers
2629~~~~~~~~~~~~~~~~~~
2630
Paul Kehrer4bb46492015-02-07 16:59:14 -06002631X.509 elements are frequently identified by :class:`ObjectIdentifier`
2632instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002633
Paul Kehrere27f6582015-08-10 18:33:38 -05002634.. currentmodule:: cryptography.x509.oid
Paul Kehrer56da2a52015-02-11 23:35:07 -06002635
Paul Kehrere27f6582015-08-10 18:33:38 -05002636.. class:: NameOID
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002637
Paul Kehrere27f6582015-08-10 18:33:38 -05002638 These OIDs are typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06002639
Paul Kehrere27f6582015-08-10 18:33:38 -05002640 .. versionadded:: 1.0
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002641
Paul Kehrere27f6582015-08-10 18:33:38 -05002642 .. attribute:: COMMON_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002643
Paul Kehrere27f6582015-08-10 18:33:38 -05002644 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
2645 name would be encoded here for server certificates. :rfc:`2818`
2646 deprecates this practice and names of that type should now be located
2647 in a :class:`~cryptography.x509.SubjectAlternativeName` extension.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002648
Paul Kehrere27f6582015-08-10 18:33:38 -05002649 .. attribute:: COUNTRY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002650
Paul Kehrere27f6582015-08-10 18:33:38 -05002651 Corresponds to the dotted string ``"2.5.4.6"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002652
Paul Kehrere27f6582015-08-10 18:33:38 -05002653 .. attribute:: LOCALITY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002654
Paul Kehrere27f6582015-08-10 18:33:38 -05002655 Corresponds to the dotted string ``"2.5.4.7"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002656
Paul Kehrere27f6582015-08-10 18:33:38 -05002657 .. attribute:: STATE_OR_PROVINCE_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002658
Paul Kehrere27f6582015-08-10 18:33:38 -05002659 Corresponds to the dotted string ``"2.5.4.8"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002660
Paul Kehrerc3b8ff62016-11-11 17:38:59 -08002661 .. attribute:: STREET_ADDRESS
2662
2663 .. versionadded:: 1.6
2664
2665 Corresponds to the dotted string ``"2.5.4.9"``.
2666
Paul Kehrere27f6582015-08-10 18:33:38 -05002667 .. attribute:: ORGANIZATION_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002668
Paul Kehrere27f6582015-08-10 18:33:38 -05002669 Corresponds to the dotted string ``"2.5.4.10"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002670
Paul Kehrere27f6582015-08-10 18:33:38 -05002671 .. attribute:: ORGANIZATIONAL_UNIT_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002672
Paul Kehrere27f6582015-08-10 18:33:38 -05002673 Corresponds to the dotted string ``"2.5.4.11"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002674
Paul Kehrere27f6582015-08-10 18:33:38 -05002675 .. attribute:: SERIAL_NUMBER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002676
Paul Kehrere27f6582015-08-10 18:33:38 -05002677 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from
2678 the serial number of the certificate itself (which can be obtained with
Chelsea Winfreee295f3a2016-06-02 21:15:54 -07002679 :func:`~cryptography.x509.Certificate.serial_number`).
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002680
Paul Kehrere27f6582015-08-10 18:33:38 -05002681 .. attribute:: SURNAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002682
Paul Kehrere27f6582015-08-10 18:33:38 -05002683 Corresponds to the dotted string ``"2.5.4.4"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002684
Paul Kehrere27f6582015-08-10 18:33:38 -05002685 .. attribute:: GIVEN_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002686
Paul Kehrere27f6582015-08-10 18:33:38 -05002687 Corresponds to the dotted string ``"2.5.4.42"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002688
Paul Kehrere27f6582015-08-10 18:33:38 -05002689 .. attribute:: TITLE
Paul Kehrer858b9b72015-02-05 09:50:31 -06002690
Paul Kehrere27f6582015-08-10 18:33:38 -05002691 Corresponds to the dotted string ``"2.5.4.12"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002692
Paul Kehrere27f6582015-08-10 18:33:38 -05002693 .. attribute:: GENERATION_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002694
Paul Kehrere27f6582015-08-10 18:33:38 -05002695 Corresponds to the dotted string ``"2.5.4.44"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002696
Paul Kehrerc7ab9312016-11-12 05:00:42 -08002697 .. attribute:: X500_UNIQUE_IDENTIFIER
Paul Kehrerc3b8ff62016-11-11 17:38:59 -08002698
2699 .. versionadded:: 1.6
2700
2701 Corresponds to the dotted string ``"2.5.4.45"``.
2702
Paul Kehrere27f6582015-08-10 18:33:38 -05002703 .. attribute:: DN_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002704
Paul Kehrere27f6582015-08-10 18:33:38 -05002705 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
2706 disambiguating information to add to the relative distinguished name of an
2707 entry. See :rfc:`2256`.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002708
Paul Kehrere27f6582015-08-10 18:33:38 -05002709 .. attribute:: PSEUDONYM
Paul Kehrer858b9b72015-02-05 09:50:31 -06002710
Paul Kehrere27f6582015-08-10 18:33:38 -05002711 Corresponds to the dotted string ``"2.5.4.65"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002712
Paul Kehrer36d5cd62016-11-19 22:05:26 +08002713 .. attribute:: USER_ID
2714
2715 .. versionadded:: 1.6
2716
2717 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.1"``.
2718
Paul Kehrere27f6582015-08-10 18:33:38 -05002719 .. attribute:: DOMAIN_COMPONENT
Paul Kehrer858b9b72015-02-05 09:50:31 -06002720
Paul Kehrere27f6582015-08-10 18:33:38 -05002721 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
2722 holding one component of a domain name. See :rfc:`4519`.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002723
Paul Kehrere27f6582015-08-10 18:33:38 -05002724 .. attribute:: EMAIL_ADDRESS
Paul Kehrer56da2a52015-02-11 23:35:07 -06002725
Paul Kehrere27f6582015-08-10 18:33:38 -05002726 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002727
Alex Gaynor1d3f2bf2015-12-19 12:15:09 -05002728 .. attribute:: JURISDICTION_COUNTRY_NAME
2729
2730 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.3"``.
2731
Alex Gaynor45e507f2015-12-19 13:44:23 -05002732 .. attribute:: JURISDICTION_LOCALITY_NAME
2733
2734 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.1"``.
2735
2736 .. attribute:: JURISDICTION_STATE_OR_PROVINCE_NAME
2737
2738 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.2"``.
2739
Alex Gaynora2293c82015-12-19 20:49:15 -05002740 .. attribute:: BUSINESS_CATEGORY
2741
2742 Corresponds to the dotted string ``"2.5.4.15"``.
2743
Paul Kehrer36d5cd62016-11-19 22:05:26 +08002744 .. attribute:: POSTAL_ADDRESS
2745
2746 .. versionadded:: 1.6
2747
2748 Corresponds to the dotted string ``"2.5.4.16"``.
2749
2750 .. attribute:: POSTAL_CODE
2751
2752 .. versionadded:: 1.6
2753
2754 Corresponds to the dotted string ``"2.5.4.17"``.
2755
Paul Kehrer56da2a52015-02-11 23:35:07 -06002756
Paul Kehrere27f6582015-08-10 18:33:38 -05002757.. class:: SignatureAlgorithmOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002758
Paul Kehrere27f6582015-08-10 18:33:38 -05002759 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002760
Paul Kehrere27f6582015-08-10 18:33:38 -05002761 .. attribute:: RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -06002762
Paul Kehrere27f6582015-08-10 18:33:38 -05002763 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
2764 an MD5 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002765
Paul Kehrere27f6582015-08-10 18:33:38 -05002766 .. attribute:: RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06002767
Paul Kehrere27f6582015-08-10 18:33:38 -05002768 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
2769 a SHA1 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002770
Paul Kehrere27f6582015-08-10 18:33:38 -05002771 .. attribute:: RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002772
Paul Kehrere27f6582015-08-10 18:33:38 -05002773 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
2774 a SHA224 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002775
Paul Kehrere27f6582015-08-10 18:33:38 -05002776 .. attribute:: RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002777
Paul Kehrere27f6582015-08-10 18:33:38 -05002778 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
2779 a SHA256 digest signed by an RSA key.
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002780
Paul Kehrere27f6582015-08-10 18:33:38 -05002781 .. attribute:: RSA_WITH_SHA384
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002782
Paul Kehrere27f6582015-08-10 18:33:38 -05002783 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
2784 a SHA384 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002785
Paul Kehrere27f6582015-08-10 18:33:38 -05002786 .. attribute:: RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -06002787
Paul Kehrere27f6582015-08-10 18:33:38 -05002788 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
2789 a SHA512 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002790
Marti Raudsepp33678062018-06-30 02:27:28 +03002791 .. attribute:: RSASSA_PSS
2792
2793 .. versionadded:: 2.3
2794
2795 Corresponds to the dotted string ``"1.2.840.113549.1.1.10"``. This is
2796 signed by an RSA key using the Probabilistic Signature Scheme (PSS)
2797 padding from RFC 4055. The hash function and padding are defined by
2798 signature algorithm parameters.
2799
Paul Kehrere27f6582015-08-10 18:33:38 -05002800 .. attribute:: ECDSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06002801
Paul Kehrere27f6582015-08-10 18:33:38 -05002802 Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1
2803 digest signed by an ECDSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002804
Paul Kehrere27f6582015-08-10 18:33:38 -05002805 .. attribute:: ECDSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002806
Paul Kehrere27f6582015-08-10 18:33:38 -05002807 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
2808 a SHA224 digest signed by an ECDSA key.
2809
2810 .. attribute:: ECDSA_WITH_SHA256
2811
2812 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
2813 a SHA256 digest signed by an ECDSA key.
2814
2815 .. attribute:: ECDSA_WITH_SHA384
2816
2817 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
2818 a SHA384 digest signed by an ECDSA key.
2819
2820 .. attribute:: ECDSA_WITH_SHA512
2821
2822 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
2823 a SHA512 digest signed by an ECDSA key.
2824
2825 .. attribute:: DSA_WITH_SHA1
2826
2827 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
2828 a SHA1 digest signed by a DSA key.
2829
2830 .. attribute:: DSA_WITH_SHA224
2831
2832 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
2833 a SHA224 digest signed by a DSA key.
2834
2835 .. attribute:: DSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002836
Paul Kehrere27f6582015-08-10 18:33:38 -05002837 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
2838 a SHA256 digest signed by a DSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002839
Paul Kehrer56da2a52015-02-11 23:35:07 -06002840
Paul Kehrere27f6582015-08-10 18:33:38 -05002841.. class:: ExtendedKeyUsageOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002842
Paul Kehrere27f6582015-08-10 18:33:38 -05002843 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002844
Paul Kehrere27f6582015-08-10 18:33:38 -05002845 .. attribute:: SERVER_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002846
Paul Kehrere27f6582015-08-10 18:33:38 -05002847 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used
2848 to denote that a certificate may be used for TLS web server
2849 authentication.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002850
Paul Kehrere27f6582015-08-10 18:33:38 -05002851 .. attribute:: CLIENT_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002852
Paul Kehrere27f6582015-08-10 18:33:38 -05002853 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used
2854 to denote that a certificate may be used for TLS web client
2855 authentication.
Paul Kehrerffa2a152015-03-31 08:18:25 -05002856
Paul Kehrere27f6582015-08-10 18:33:38 -05002857 .. attribute:: CODE_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002858
Paul Kehrere27f6582015-08-10 18:33:38 -05002859 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used
2860 to denote that a certificate may be used for code signing.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002861
Paul Kehrere27f6582015-08-10 18:33:38 -05002862 .. attribute:: EMAIL_PROTECTION
Paul Kehrere1513fa2015-03-30 23:08:17 -05002863
Paul Kehrere27f6582015-08-10 18:33:38 -05002864 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used
2865 to denote that a certificate may be used for email protection.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002866
Paul Kehrere27f6582015-08-10 18:33:38 -05002867 .. attribute:: TIME_STAMPING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002868
Paul Kehrere27f6582015-08-10 18:33:38 -05002869 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used
2870 to denote that a certificate may be used for time stamping.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002871
Paul Kehrere27f6582015-08-10 18:33:38 -05002872 .. attribute:: OCSP_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002873
Paul Kehrere27f6582015-08-10 18:33:38 -05002874 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used
2875 to denote that a certificate may be used for signing OCSP responses.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002876
Alex Gaynorb7912ee2017-07-03 10:07:02 -04002877 .. attribute:: ANY_EXTENDED_KEY_USAGE
2878
2879 .. versionadded:: 2.0
2880
2881 Corresponds to the dotted string ``"2.5.29.37.0"``. This is used to
2882 denote that a certificate may be used for _any_ purposes.
2883
Paul Kehrere1513fa2015-03-30 23:08:17 -05002884
Paul Kehrere27f6582015-08-10 18:33:38 -05002885.. class:: AuthorityInformationAccessOID
Paul Kehrere1513fa2015-03-30 23:08:17 -05002886
Paul Kehrere27f6582015-08-10 18:33:38 -05002887 .. versionadded:: 1.0
Paul Kehrere1513fa2015-03-30 23:08:17 -05002888
Paul Kehrere27f6582015-08-10 18:33:38 -05002889 .. attribute:: OCSP
Paul Kehrere1513fa2015-03-30 23:08:17 -05002890
Paul Kehrere27f6582015-08-10 18:33:38 -05002891 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
2892 identifier for OCSP data in
2893 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002894
Paul Kehrere27f6582015-08-10 18:33:38 -05002895 .. attribute:: CA_ISSUERS
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002896
Paul Kehrere27f6582015-08-10 18:33:38 -05002897 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
2898 identifier for CA issuer data in
2899 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002900
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002901
Paul Kehrere27f6582015-08-10 18:33:38 -05002902.. class:: CertificatePoliciesOID
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002903
Paul Kehrere27f6582015-08-10 18:33:38 -05002904 .. versionadded:: 1.0
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002905
Paul Kehrere27f6582015-08-10 18:33:38 -05002906 .. attribute:: CPS_QUALIFIER
Paul Kehrer2e879742015-05-02 23:09:56 -05002907
Paul Kehrere27f6582015-08-10 18:33:38 -05002908 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05002909
Paul Kehrere27f6582015-08-10 18:33:38 -05002910 .. attribute:: CPS_USER_NOTICE
Paul Kehrer2e879742015-05-02 23:09:56 -05002911
Paul Kehrere27f6582015-08-10 18:33:38 -05002912 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05002913
Paul Kehrere27f6582015-08-10 18:33:38 -05002914 .. attribute:: ANY_POLICY
Paul Kehrer2e879742015-05-02 23:09:56 -05002915
Paul Kehrere27f6582015-08-10 18:33:38 -05002916 Corresponds to the dotted string ``"2.5.29.32.0"``.
Paul Kehrer16fae762015-05-01 23:14:20 -05002917
Paul Kehrer16fae762015-05-01 23:14:20 -05002918
Paul Kehrere27f6582015-08-10 18:33:38 -05002919.. class:: ExtensionOID
Paul Kehrer5553d572015-03-23 21:08:01 -05002920
Paul Kehrere27f6582015-08-10 18:33:38 -05002921 .. versionadded:: 1.0
Paul Kehrer2bb94642015-03-21 09:54:17 -05002922
Paul Kehrere27f6582015-08-10 18:33:38 -05002923 .. attribute:: BASIC_CONSTRAINTS
Paul Kehrer2bb94642015-03-21 09:54:17 -05002924
Paul Kehrere27f6582015-08-10 18:33:38 -05002925 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
2926 :class:`~cryptography.x509.BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05002927
Paul Kehrere27f6582015-08-10 18:33:38 -05002928 .. attribute:: KEY_USAGE
Paul Kehrercecbbba2015-03-30 14:58:38 -05002929
Paul Kehrere27f6582015-08-10 18:33:38 -05002930 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
2931 :class:`~cryptography.x509.KeyUsage` extension type.
Paul Kehrercecbbba2015-03-30 14:58:38 -05002932
Paul Kehrere27f6582015-08-10 18:33:38 -05002933 .. attribute:: SUBJECT_ALTERNATIVE_NAME
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002934
Paul Kehrere27f6582015-08-10 18:33:38 -05002935 Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the
2936 :class:`~cryptography.x509.SubjectAlternativeName` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002937
Paul Kehrere27f6582015-08-10 18:33:38 -05002938 .. attribute:: ISSUER_ALTERNATIVE_NAME
Paul Kehrer99125c92015-06-07 18:37:10 -05002939
Paul Kehrere27f6582015-08-10 18:33:38 -05002940 Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the
2941 :class:`~cryptography.x509.IssuerAlternativeName` extension type.
Paul Kehrer99125c92015-06-07 18:37:10 -05002942
Paul Kehrere27f6582015-08-10 18:33:38 -05002943 .. attribute:: SUBJECT_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002944
Paul Kehrere27f6582015-08-10 18:33:38 -05002945 Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the
2946 :class:`~cryptography.x509.SubjectKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002947
Paul Kehrere27f6582015-08-10 18:33:38 -05002948 .. attribute:: NAME_CONSTRAINTS
Paul Kehrere0017be2015-05-17 20:39:40 -06002949
Paul Kehrere27f6582015-08-10 18:33:38 -05002950 Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the
2951 :class:`~cryptography.x509.NameConstraints` extension type.
Paul Kehrere0017be2015-05-17 20:39:40 -06002952
Paul Kehrere27f6582015-08-10 18:33:38 -05002953 .. attribute:: CRL_DISTRIBUTION_POINTS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002954
Paul Kehrere27f6582015-08-10 18:33:38 -05002955 Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the
2956 :class:`~cryptography.x509.CRLDistributionPoints` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002957
Paul Kehrere27f6582015-08-10 18:33:38 -05002958 .. attribute:: CERTIFICATE_POLICIES
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002959
Paul Kehrere27f6582015-08-10 18:33:38 -05002960 Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the
2961 :class:`~cryptography.x509.CertificatePolicies` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002962
Paul Kehrere27f6582015-08-10 18:33:38 -05002963 .. attribute:: AUTHORITY_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002964
Paul Kehrere27f6582015-08-10 18:33:38 -05002965 Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the
2966 :class:`~cryptography.x509.AuthorityKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002967
Paul Kehrere27f6582015-08-10 18:33:38 -05002968 .. attribute:: EXTENDED_KEY_USAGE
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002969
Paul Kehrere27f6582015-08-10 18:33:38 -05002970 Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the
2971 :class:`~cryptography.x509.ExtendedKeyUsage` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002972
Paul Kehrere27f6582015-08-10 18:33:38 -05002973 .. attribute:: AUTHORITY_INFORMATION_ACCESS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002974
Paul Kehrere27f6582015-08-10 18:33:38 -05002975 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier
2976 for the :class:`~cryptography.x509.AuthorityInformationAccess` extension
2977 type.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002978
Paul Kehrere27f6582015-08-10 18:33:38 -05002979 .. attribute:: INHIBIT_ANY_POLICY
Paul Kehrerb33de932015-08-06 23:41:05 +01002980
Paul Kehrere27f6582015-08-10 18:33:38 -05002981 Corresponds to the dotted string ``"2.5.29.54"``. The identifier
2982 for the :class:`~cryptography.x509.InhibitAnyPolicy` extension type.
Paul Kehrerb33de932015-08-06 23:41:05 +01002983
Paul Kehrere27f6582015-08-10 18:33:38 -05002984 .. attribute:: OCSP_NO_CHECK
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002985
Paul Kehrere27f6582015-08-10 18:33:38 -05002986 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The
2987 identifier for the :class:`~cryptography.x509.OCSPNoCheck` extension
2988 type.
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002989
Paul Kehrer5d669662017-09-11 09:16:34 +08002990 .. attribute:: TLS_FEATURE
2991
2992 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.24"``. The
2993 identifier for the :class:`~cryptography.x509.TLSFeature` extension
2994 type.
2995
Paul Kehrer51f39cb2015-12-21 21:17:39 -06002996 .. attribute:: CRL_NUMBER
2997
2998 Corresponds to the dotted string ``"2.5.29.20"``. The identifier for
2999 the ``CRLNumber`` extension type. This extension only has meaning
3000 for certificate revocation lists.
3001
Paul Kehrer5e3cc982017-09-22 21:29:36 +08003002 .. attribute:: DELTA_CRL_INDICATOR
3003
3004 .. versionadded:: 2.1
3005
3006 Corresponds to the dotted string ``"2.5.29.27"``. The identifier for
3007 the ``DeltaCRLIndicator`` extension type. This extension only has
3008 meaning for certificate revocation lists.
3009
Alex Gaynor9bab0ed2017-03-20 09:50:52 -04003010 .. attribute:: PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS
3011
3012 .. versionadded:: 1.9
3013
3014 Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.2"``.
3015
Alex Gaynordd6b78b2018-08-31 18:25:52 -05003016 .. attribute:: PRECERT_POISON
3017
3018 .. versionadded:: 2.4
3019
3020 Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.3"``.
3021
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07003022 .. attribute:: POLICY_CONSTRAINTS
3023
3024 Corresponds to the dotted string ``"2.5.29.36"``. The identifier for the
Paul Kehrer20f0df52016-02-26 08:37:13 -06003025 :class:`~cryptography.x509.PolicyConstraints` extension type.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07003026
Paul Kehrerb76bcf82017-09-24 08:44:12 +08003027 .. attribute:: FRESHEST_CRL
3028
3029 Corresponds to the dotted string ``"2.5.29.46"``. The identifier for the
3030 :class:`~cryptography.x509.FreshestCRL` extension type.
3031
Paul Kehrer6e756ae2018-10-29 02:07:40 +08003032 .. attribute:: ISSUING_DISTRIBUTION_POINT
3033
3034 .. versionadded:: 2.4
3035
3036 Corresponds to the dotted string ``"2.5.29.28"``.
3037
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07003038
Paul Kehrerc6242dc2015-12-25 16:36:46 -06003039.. class:: CRLEntryExtensionOID
3040
3041 .. versionadded:: 1.2
3042
3043 .. attribute:: CERTIFICATE_ISSUER
3044
3045 Corresponds to the dotted string ``"2.5.29.29"``.
3046
3047 .. attribute:: CRL_REASON
3048
3049 Corresponds to the dotted string ``"2.5.29.21"``.
3050
3051 .. attribute:: INVALIDITY_DATE
3052
3053 Corresponds to the dotted string ``"2.5.29.24"``.
3054
Paul Kehrer09403102018-09-09 21:57:21 -05003055
3056.. class:: OCSPExtensionOID
3057
3058 .. versionadded:: 2.4
3059
3060 .. attribute:: NONCE
3061
3062 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.2"``.
3063
Paul Kehrer8b89bcc2016-09-03 11:31:43 -05003064Helper Functions
3065~~~~~~~~~~~~~~~~
3066.. currentmodule:: cryptography.x509
3067
3068.. function:: random_serial_number()
3069
3070 .. versionadded:: 1.6
3071
3072 Generates a random serial number suitable for use when constructing
3073 certificates.
3074
Paul Kehrer912d3fb2015-01-29 11:19:22 -06003075Exceptions
3076~~~~~~~~~~
Paul Kehrere27f6582015-08-10 18:33:38 -05003077.. currentmodule:: cryptography.x509
Paul Kehrer912d3fb2015-01-29 11:19:22 -06003078
Paul Kehrere76cd272014-12-14 19:00:51 -06003079.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10003080
3081 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10003082
Paul Kehrerd5cccf72014-12-15 17:20:33 -06003083 .. attribute:: parsed_version
3084
Paul Kehrerbbffc402014-12-17 13:33:55 -06003085 :type: int
3086
3087 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06003088
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05003089.. class:: DuplicateExtension
3090
3091 This is raised when more than one X.509 extension of the same type is
3092 found within a certificate.
3093
3094 .. attribute:: oid
3095
3096 :type: :class:`ObjectIdentifier`
3097
3098 Returns the OID.
3099
Paul Kehrerfa56a232015-03-17 13:14:03 -05003100.. class:: ExtensionNotFound
3101
3102 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
3103 an extension OID that is not present in the certificate.
3104
3105 .. attribute:: oid
3106
3107 :type: :class:`ObjectIdentifier`
3108
3109 Returns the OID.
3110
Paul Kehrer9089c912015-04-20 22:15:20 -05003111.. class:: UnsupportedGeneralNameType
3112
3113 This is raised when a certificate contains an unsupported general name
3114 type in an extension.
3115
Paul Kehrerbed07352015-04-21 08:31:10 -05003116 .. attribute:: type
3117
Paul Kehrer0a621bf2015-04-22 09:22:56 -05003118 :type: int
3119
3120 The integer value of the unsupported type. The complete list of
3121 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05003122
Paul Kehrer016e08a2014-11-26 09:41:18 -10003123
Paul Kehrerc7c9a432015-04-19 09:20:13 -05003124.. _`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 -05003125.. _`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 -05003126.. _`CABForum Guidelines`: https://cabforum.org/baseline-requirements-documents/