blob: b2278d57f7680339031ef0a88afff18a2ced3335 [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
Alex Gaynore5463cc2019-01-18 15:19:34 -06001253 :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
Alex Gaynore5463cc2019-01-18 15:19:34 -06001294 :return str: Format the given attribute as a :rfc:`4514` Distinguished
Marti Raudseppc3d38b52018-12-08 03:26:07 +02001295 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
Alex Gaynore5463cc2019-01-18 15:19:34 -06001317 :return str: Format the given RDN set as a :rfc:`4514` Distinguished
Marti Raudseppc3d38b52018-12-08 03:26:07 +02001318 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
Paul Kehrer31bdf792015-03-25 14:11:00 -05001335.. _general_name_classes:
1336
1337General Name Classes
1338~~~~~~~~~~~~~~~~~~~~
1339
1340.. class:: GeneralName
1341
1342 .. versionadded:: 0.9
1343
1344 This is the generic interface that all the following classes are registered
1345 against.
1346
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001347.. class:: RFC822Name(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001348
1349 .. versionadded:: 0.9
1350
Paul Kehrere885bd62017-10-11 20:29:23 +08001351 .. versionchanged:: 2.1
Paul Kehrer3e15ca52017-08-01 21:21:19 -05001352
Paul Kehrere885bd62017-10-11 20:29:23 +08001353 .. warning::
1354
1355 Starting with version 2.1 :term:`U-label` input is deprecated. If
1356 passing an internationalized domain name (IDN) you should first IDNA
1357 encode the value and then pass the result as a string. Accessing
1358 ``value`` will return the :term:`A-label` encoded form even if you pass
1359 a U-label. This breaks backwards compatibility, but only for
1360 internationalized domain names.
1361
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001362
1363 This corresponds to an email address. For example, ``user@example.com``.
1364
Paul Kehrere885bd62017-10-11 20:29:23 +08001365 :param value: The email address. If the address contains an
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001366 internationalized domain name then it must be encoded to an
Paul Kehrere885bd62017-10-11 20:29:23 +08001367 :term:`A-label` string before being passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001368
Paul Kehrer31bdf792015-03-25 14:11:00 -05001369 .. attribute:: value
1370
1371 :type: :term:`text`
1372
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001373.. class:: DNSName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001374
1375 .. versionadded:: 0.9
1376
Paul Kehrere885bd62017-10-11 20:29:23 +08001377 .. versionchanged:: 2.1
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001378
Paul Kehrere885bd62017-10-11 20:29:23 +08001379 .. warning::
1380
1381 Starting with version 2.1 :term:`U-label` input is deprecated. If
1382 passing an internationalized domain name (IDN) you should first IDNA
1383 encode the value and then pass the result as a string. Accessing
1384 ``value`` will return the :term:`A-label` encoded form even if you pass
1385 a U-label. This breaks backwards compatibility, but only for
1386 internationalized domain names.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001387
Paul Kehrer31bdf792015-03-25 14:11:00 -05001388 This corresponds to a domain name. For example, ``cryptography.io``.
1389
Paul Kehrere885bd62017-10-11 20:29:23 +08001390 :param value: The domain name. If it is an internationalized domain
1391 name then it must be encoded to an :term:`A-label` string before being
1392 passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001393
Paul Kehrere885bd62017-10-11 20:29:23 +08001394 :type: :term:`text`
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001395
Paul Kehrer31bdf792015-03-25 14:11:00 -05001396 .. attribute:: value
1397
1398 :type: :term:`text`
1399
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001400.. class:: DirectoryName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001401
1402 .. versionadded:: 0.9
1403
1404 This corresponds to a directory name.
1405
1406 .. attribute:: value
1407
1408 :type: :class:`Name`
1409
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001410.. class:: UniformResourceIdentifier(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001411
1412 .. versionadded:: 0.9
1413
Paul Kehrere885bd62017-10-11 20:29:23 +08001414 .. versionchanged:: 2.1
Paul Kehrerb8ef82e2015-04-22 16:04:24 -05001415
Paul Kehrere885bd62017-10-11 20:29:23 +08001416 .. warning::
1417
1418 Starting with version 2.1 :term:`U-label` input is deprecated. If
1419 passing an internationalized domain name (IDN) you should first IDNA
1420 encode the value and then pass the result as a string. Accessing
1421 ``value`` will return the :term:`A-label` encoded form even if you pass
1422 a U-label. This breaks backwards compatibility, but only for
1423 internationalized domain names.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001424
1425 This corresponds to a uniform resource identifier. For example,
1426 ``https://cryptography.io``.
1427
Paul Kehrere885bd62017-10-11 20:29:23 +08001428 :param value: The URI. If it contains an internationalized domain
1429 name then it must be encoded to an :term:`A-label` string before
1430 being passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001431
Paul Kehrer31bdf792015-03-25 14:11:00 -05001432 .. attribute:: value
1433
1434 :type: :term:`text`
1435
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001436.. class:: IPAddress(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001437
1438 .. versionadded:: 0.9
1439
1440 This corresponds to an IP address.
1441
1442 .. attribute:: value
1443
Paul Kehrereb177932015-05-17 18:33:33 -07001444 :type: :class:`~ipaddress.IPv4Address`,
1445 :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
1446 or :class:`~ipaddress.IPv6Network`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001447
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001448.. class:: RegisteredID(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001449
1450 .. versionadded:: 0.9
1451
1452 This corresponds to a registered ID.
1453
1454 .. attribute:: value
1455
1456 :type: :class:`ObjectIdentifier`
1457
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001458.. class:: OtherName(type_id, value)
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001459
1460 .. versionadded:: 1.0
1461
Joshua Tauberer18b6fc82015-07-05 21:44:51 +00001462 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 +00001463
1464 .. attribute:: type_id
1465
1466 :type: :class:`ObjectIdentifier`
1467
1468 .. attribute:: value
1469
Paul Kehreredfedc12018-09-14 18:24:20 -04001470 :type: bytes
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001471
Paul Kehrer8cf26422015-03-21 09:50:24 -05001472X.509 Extensions
1473~~~~~~~~~~~~~~~~
1474
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001475.. class:: Extensions
1476
1477 .. versionadded:: 0.9
1478
1479 An X.509 Extensions instance is an ordered list of extensions. The object
1480 is iterable to get every extension.
1481
Paul Kehrerfa56a232015-03-17 13:14:03 -05001482 .. method:: get_extension_for_oid(oid)
1483
1484 :param oid: An :class:`ObjectIdentifier` instance.
1485
1486 :returns: An instance of the extension class.
1487
1488 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1489 not have the extension requested.
1490
Paul Kehrerfa56a232015-03-17 13:14:03 -05001491 .. doctest::
1492
Paul Kehrere27f6582015-08-10 18:33:38 -05001493 >>> from cryptography.x509.oid import ExtensionOID
1494 >>> cert.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS)
Paul Kehrerfa56a232015-03-17 13:14:03 -05001495 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1496
Phoebe Queen019b7f82015-08-12 03:52:03 +01001497 .. method:: get_extension_for_class(extclass)
1498
Phoebe Queen6a603eb2015-08-12 14:14:49 +01001499 .. versionadded:: 1.1
1500
Phoebe Queen019b7f82015-08-12 03:52:03 +01001501 :param extclass: An extension class.
1502
1503 :returns: An instance of the extension class.
1504
1505 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1506 not have the extension requested.
1507
1508 .. doctest::
1509
1510 >>> from cryptography import x509
1511 >>> cert.extensions.get_extension_for_class(x509.BasicConstraints)
1512 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1513
Paul Kehrer8cf26422015-03-21 09:50:24 -05001514.. class:: Extension
1515
1516 .. versionadded:: 0.9
1517
Paul Kehrer85894662015-03-22 13:19:31 -05001518 .. attribute:: oid
1519
1520 :type: :class:`ObjectIdentifier`
1521
Paul Kehrere27f6582015-08-10 18:33:38 -05001522 One of the :class:`~cryptography.x509.oid.ExtensionOID` OIDs.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001523
1524 .. attribute:: critical
1525
1526 :type: bool
1527
Paul Kehrer58b75692015-03-22 23:24:58 -05001528 Determines whether a given extension is critical or not. :rfc:`5280`
1529 requires that "A certificate-using system MUST reject the certificate
1530 if it encounters a critical extension it does not recognize or a
1531 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -05001532
Paul Kehrer85894662015-03-22 13:19:31 -05001533 .. attribute:: value
1534
1535 Returns an instance of the extension type corresponding to the OID.
1536
Paul Kehrer14f0bd02015-08-06 11:55:18 +01001537.. class:: ExtensionType
1538
1539 .. versionadded:: 1.0
1540
1541 This is the interface against which all the following extension types are
1542 registered.
1543
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001544.. 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 -05001545
1546 .. versionadded:: 0.9
1547
1548 The key usage extension defines the purpose of the key contained in the
1549 certificate. The usage restriction might be employed when a key that could
Paul Kehrerb33de932015-08-06 23:41:05 +01001550 be used for more than one operation is to be restricted.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001551
Paul Kehrer822f3d32015-08-06 11:47:32 +01001552 .. attribute:: oid
1553
1554 .. versionadded:: 1.0
1555
1556 :type: :class:`ObjectIdentifier`
1557
Paul Kehrere27f6582015-08-10 18:33:38 -05001558 Returns :attr:`~cryptography.x509.oid.ExtensionOID.KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001559
Paul Kehrercecbbba2015-03-30 14:58:38 -05001560 .. attribute:: digital_signature
1561
1562 :type: bool
1563
Paul Kehrer738407b2015-04-01 22:39:02 -05001564 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001565 digital signatures, other than signatures on certificates
1566 (``key_cert_sign``) and CRLs (``crl_sign``).
1567
1568 .. attribute:: content_commitment
1569
1570 :type: bool
1571
Paul Kehrer738407b2015-04-01 22:39:02 -05001572 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001573 digital signatures, other than signatures on certificates
1574 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
1575 non-repudiation service that protects against the signing entity
1576 falsely denying some action. In the case of later conflict, a
1577 reliable third party may determine the authenticity of the signed
1578 data. This was called ``non_repudiation`` in older revisions of the
1579 X.509 specification.
1580
1581 .. attribute:: key_encipherment
1582
1583 :type: bool
1584
Paul Kehrer738407b2015-04-01 22:39:02 -05001585 This purpose is set to true when the subject public key is used for
1586 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001587
1588 .. attribute:: data_encipherment
1589
1590 :type: bool
1591
Paul Kehrer738407b2015-04-01 22:39:02 -05001592 This purpose is set to true when the subject public key is used for
1593 directly enciphering raw user data without the use of an intermediate
1594 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001595
1596 .. attribute:: key_agreement
1597
1598 :type: bool
1599
Paul Kehrer738407b2015-04-01 22:39:02 -05001600 This purpose is set to true when the subject public key is used for key
1601 agreement. For example, when a Diffie-Hellman key is to be used for
1602 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001603
1604 .. attribute:: key_cert_sign
1605
1606 :type: bool
1607
Paul Kehrer738407b2015-04-01 22:39:02 -05001608 This purpose is set to true when the subject public key is used for
1609 verifying signatures on public key certificates. If this purpose is set
1610 to true then ``ca`` must be true in the :class:`BasicConstraints`
1611 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001612
1613 .. attribute:: crl_sign
1614
1615 :type: bool
1616
Paul Kehrer738407b2015-04-01 22:39:02 -05001617 This purpose is set to true when the subject public key is used for
1618 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001619
1620 .. attribute:: encipher_only
1621
1622 :type: bool
1623
Paul Kehrer738407b2015-04-01 22:39:02 -05001624 When this purposes is set to true and the ``key_agreement`` purpose is
1625 also set, the subject public key may be used only for enciphering data
1626 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001627
1628 :raises ValueError: This is raised if accessed when ``key_agreement``
1629 is false.
1630
1631 .. attribute:: decipher_only
1632
1633 :type: bool
1634
Paul Kehrer738407b2015-04-01 22:39:02 -05001635 When this purposes is set to true and the ``key_agreement`` purpose is
1636 also set, the subject public key may be used only for deciphering data
1637 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001638
1639 :raises ValueError: This is raised if accessed when ``key_agreement``
1640 is false.
1641
1642
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001643.. class:: BasicConstraints(ca, path_length)
Paul Kehrer8cf26422015-03-21 09:50:24 -05001644
1645 .. versionadded:: 0.9
1646
Paul Kehrer85894662015-03-22 13:19:31 -05001647 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -05001648 certificate is allowed to sign additional certificates and what path
Paul Kehrerb33de932015-08-06 23:41:05 +01001649 length restrictions may exist.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001650
Paul Kehrer822f3d32015-08-06 11:47:32 +01001651 .. attribute:: oid
1652
1653 .. versionadded:: 1.0
1654
1655 :type: :class:`ObjectIdentifier`
1656
Paul Kehrere27f6582015-08-10 18:33:38 -05001657 Returns :attr:`~cryptography.x509.oid.ExtensionOID.BASIC_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001658
Paul Kehrer8cf26422015-03-21 09:50:24 -05001659 .. attribute:: ca
1660
1661 :type: bool
1662
1663 Whether the certificate can sign certificates.
1664
1665 .. attribute:: path_length
1666
Paul Kehrerfd1444c2015-03-21 19:47:05 -05001667 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -05001668
1669 The maximum path length for certificates subordinate to this
1670 certificate. This attribute only has meaning if ``ca`` is true.
1671 If ``ca`` is true then a path length of None means there's no
1672 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -04001673 If it is zero or greater then it defines the maximum length for a
1674 subordinate CA's certificate chain. For example, a ``path_length`` of 1
1675 means the certificate can sign a subordinate CA, but the subordinate CA
1676 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001677
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001678.. class:: ExtendedKeyUsage(usages)
Paul Kehrerffa2a152015-03-31 08:18:25 -05001679
1680 .. versionadded:: 0.9
1681
1682 This extension indicates one or more purposes for which the certified
1683 public key may be used, in addition to or in place of the basic
1684 purposes indicated in the key usage extension. The object is
Paul Kehrere27f6582015-08-10 18:33:38 -05001685 iterable to obtain the list of
1686 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs present.
Paul Kehrerffa2a152015-03-31 08:18:25 -05001687
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001688 :param list usages: A list of
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001689 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs.
1690
Paul Kehrer822f3d32015-08-06 11:47:32 +01001691 .. attribute:: oid
1692
1693 .. versionadded:: 1.0
1694
1695 :type: :class:`ObjectIdentifier`
1696
Paul Kehrere27f6582015-08-10 18:33:38 -05001697 Returns :attr:`~cryptography.x509.oid.ExtensionOID.EXTENDED_KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001698
1699
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001700.. class:: OCSPNoCheck()
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001701
Paul Kehrer506a2152015-05-26 08:01:18 -05001702 .. versionadded:: 1.0
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001703
1704 This presence of this extension indicates that an OCSP client can trust a
1705 responder for the lifetime of the responder's certificate. CAs issuing
1706 such a certificate should realize that a compromise of the responder's key
1707 is as serious as the compromise of a CA key used to sign CRLs, at least for
1708 the validity period of this certificate. CA's may choose to issue this type
1709 of certificate with a very short lifetime and renew it frequently. This
1710 extension is only relevant when the certificate is an authorized OCSP
1711 responder.
1712
Paul Kehrer822f3d32015-08-06 11:47:32 +01001713 .. attribute:: oid
1714
1715 .. versionadded:: 1.0
1716
1717 :type: :class:`ObjectIdentifier`
1718
Paul Kehrere27f6582015-08-10 18:33:38 -05001719 Returns :attr:`~cryptography.x509.oid.ExtensionOID.OCSP_NO_CHECK`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001720
Paul Kehrer5d669662017-09-11 09:16:34 +08001721
1722.. class:: TLSFeature(features)
1723
1724 .. versionadded:: 2.1
1725
1726 The TLS Feature extension is defined in :rfc:`7633` and is used in
1727 certificates for OCSP Must-Staple. The object is iterable to get every
1728 element.
1729
1730 :param list features: A list of features to enable from the
1731 :class:`~cryptography.x509.TLSFeatureType` enum. At this time only
1732 ``status_request`` or ``status_request_v2`` are allowed.
1733
1734 .. attribute:: oid
1735
1736 :type: :class:`ObjectIdentifier`
1737
1738 Returns :attr:`~cryptography.x509.oid.ExtensionOID.TLS_FEATURE`.
1739
1740.. class:: TLSFeatureType
1741
1742 .. versionadded:: 2.1
1743
1744 An enumeration of TLS Feature types.
1745
1746 .. attribute:: status_request
1747
1748 This feature type is defined in :rfc:`6066` and, when embedded in
1749 an X.509 certificate, signals to the client that it should require
1750 a stapled OCSP response in the TLS handshake. Commonly known as OCSP
1751 Must-Staple in certificates.
1752
1753 .. attribute:: status_request_v2
1754
1755 This feature type is defined in :rfc:`6961`. This value is not
1756 commonly used and if you want to enable OCSP Must-Staple you should
1757 use ``status_request``.
1758
1759
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001760.. class:: NameConstraints(permitted_subtrees, excluded_subtrees)
Paul Kehrere0017be2015-05-17 20:39:40 -06001761
1762 .. versionadded:: 1.0
1763
1764 The name constraints extension, which only has meaning in a CA certificate,
1765 defines a name space within which all subject names in certificates issued
1766 beneath the CA certificate must (or must not) be in. For specific details
1767 on the way this extension should be processed see :rfc:`5280`.
1768
Paul Kehrer822f3d32015-08-06 11:47:32 +01001769 .. attribute:: oid
1770
1771 .. versionadded:: 1.0
1772
1773 :type: :class:`ObjectIdentifier`
1774
Paul Kehrere27f6582015-08-10 18:33:38 -05001775 Returns :attr:`~cryptography.x509.oid.ExtensionOID.NAME_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001776
Paul Kehrere0017be2015-05-17 20:39:40 -06001777 .. attribute:: permitted_subtrees
1778
1779 :type: list of :class:`GeneralName` objects or None
1780
1781 The set of permitted name patterns. If a name matches this and an
1782 element in ``excluded_subtrees`` it is invalid. At least one of
1783 ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None.
1784
1785 .. attribute:: excluded_subtrees
1786
1787 :type: list of :class:`GeneralName` objects or None
1788
1789 Any name matching a restriction in the ``excluded_subtrees`` field is
1790 invalid regardless of information appearing in the
1791 ``permitted_subtrees``. At least one of ``permitted_subtrees`` and
1792 ``excluded_subtrees`` will be non-None.
1793
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001794.. class:: AuthorityKeyIdentifier(key_identifier, authority_cert_issuer, authority_cert_serial_number)
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001795
1796 .. versionadded:: 0.9
1797
1798 The authority key identifier extension provides a means of identifying the
1799 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001800 This extension is typically used to assist in determining the appropriate
1801 certificate chain. For more information about generation and use of this
1802 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001803
Paul Kehrer822f3d32015-08-06 11:47:32 +01001804 .. attribute:: oid
1805
1806 .. versionadded:: 1.0
1807
1808 :type: :class:`ObjectIdentifier`
1809
Paul Kehrere27f6582015-08-10 18:33:38 -05001810 Returns
1811 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001812
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001813 .. attribute:: key_identifier
1814
1815 :type: bytes
1816
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001817 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001818 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001819
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001820 .. attribute:: authority_cert_issuer
1821
Thom Dixon488c0482018-05-18 03:55:29 -07001822 :type: A list of :class:`GeneralName` instances or None
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001823
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001824 The :class:`Name` of the issuer's issuer.
1825
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001826 .. attribute:: authority_cert_serial_number
1827
1828 :type: int or None
1829
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001830 The serial number of the issuer's issuer.
1831
Paul Kehrer253929a2015-08-05 17:30:39 +01001832 .. classmethod:: from_issuer_public_key(public_key)
1833
1834 .. versionadded:: 1.0
1835
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001836 .. note::
1837
1838 This method should be used if the issuer certificate does not
1839 contain a :class:`~cryptography.x509.SubjectKeyIdentifier`.
1840 Otherwise, use
1841 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier`.
1842
Paul Kehrer253929a2015-08-05 17:30:39 +01001843 Creates a new AuthorityKeyIdentifier instance using the public key
1844 provided to generate the appropriate digest. This should be the
Paul Kehrer26ac47f2015-08-08 15:20:52 -05001845 **issuer's public key**. The resulting object will contain
1846 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1847 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1848 and
1849 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1850 will be None.
1851 The generated ``key_identifier`` is the SHA1 hash of the ``subjectPublicKey``
1852 ASN.1 bit string. This is the first recommendation in :rfc:`5280`
Paul Kehrer253929a2015-08-05 17:30:39 +01001853 section 4.2.1.2.
1854
Paul Kehrercc671822015-08-08 15:41:54 -05001855 :param public_key: One of
1856 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1857 ,
1858 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1859 , or
1860 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
Paul Kehrer253929a2015-08-05 17:30:39 +01001861
1862 .. doctest::
1863
1864 >>> from cryptography import x509
1865 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001866 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1867 >>> x509.AuthorityKeyIdentifier.from_issuer_public_key(issuer_cert.public_key())
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001868 <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 +01001869
Paul Kehrer61ff3562016-03-11 22:51:27 -04001870 .. classmethod:: from_issuer_subject_key_identifier(ski)
1871
1872 .. versionadded:: 1.3
1873
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001874 .. note::
1875 This method should be used if the issuer certificate contains a
1876 :class:`~cryptography.x509.SubjectKeyIdentifier`. Otherwise, use
1877 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_public_key`.
1878
Paul Kehrer61ff3562016-03-11 22:51:27 -04001879 Creates a new AuthorityKeyIdentifier instance using the
1880 SubjectKeyIdentifier from the issuer certificate. The resulting object
1881 will contain
1882 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1883 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1884 and
1885 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1886 will be None.
1887
1888 :param ski: The
1889 :class:`~cryptography.x509.SubjectKeyIdentifier` from the issuer
1890 certificate.
1891
1892 .. doctest::
1893
1894 >>> from cryptography import x509
1895 >>> from cryptography.hazmat.backends import default_backend
1896 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1897 >>> ski = issuer_cert.extensions.get_extension_for_class(x509.SubjectKeyIdentifier)
1898 >>> x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier(ski)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001899 <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 -04001900
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001901.. class:: SubjectKeyIdentifier(digest)
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001902
1903 .. versionadded:: 0.9
1904
1905 The subject key identifier extension provides a means of identifying
1906 certificates that contain a particular public key.
1907
Paul Kehrer822f3d32015-08-06 11:47:32 +01001908 .. attribute:: oid
1909
1910 .. versionadded:: 1.0
1911
1912 :type: :class:`ObjectIdentifier`
1913
Paul Kehrere27f6582015-08-10 18:33:38 -05001914 Returns
1915 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001916
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001917 .. attribute:: digest
1918
1919 :type: bytes
1920
1921 The binary value of the identifier.
1922
Paul Kehrerd4a7f062015-08-05 18:32:18 +01001923 .. classmethod:: from_public_key(public_key)
Paul Kehrerf22f6122015-08-05 12:57:13 +01001924
1925 .. versionadded:: 1.0
1926
1927 Creates a new SubjectKeyIdentifier instance using the public key
1928 provided to generate the appropriate digest. This should be the public
Paul Kehrereb9ec002015-08-08 10:03:02 -05001929 key that is in the certificate. The generated digest is the SHA1 hash
1930 of the ``subjectPublicKey`` ASN.1 bit string. This is the first
1931 recommendation in :rfc:`5280` section 4.2.1.2.
Paul Kehrerf22f6122015-08-05 12:57:13 +01001932
1933 :param public_key: One of
1934 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1935 ,
1936 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1937 , or
1938 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
1939
Paul Kehrer253929a2015-08-05 17:30:39 +01001940 .. doctest::
1941
1942 >>> from cryptography import x509
1943 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001944 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
1945 >>> x509.SubjectKeyIdentifier.from_public_key(csr.public_key())
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001946 <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 +01001947
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001948.. class:: SubjectAlternativeName(general_names)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001949
1950 .. versionadded:: 0.9
1951
1952 Subject alternative name is an X.509 extension that provides a list of
1953 :ref:`general name <general_name_classes>` instances that provide a set
1954 of identities for which the certificate is valid. The object is iterable to
1955 get every element.
1956
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001957 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001958
Paul Kehrer822f3d32015-08-06 11:47:32 +01001959 .. attribute:: oid
1960
1961 .. versionadded:: 1.0
1962
1963 :type: :class:`ObjectIdentifier`
1964
Paul Kehrere27f6582015-08-10 18:33:38 -05001965 Returns
1966 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001967
Paul Kehrer31bdf792015-03-25 14:11:00 -05001968 .. method:: get_values_for_type(type)
1969
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03001970 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer31bdf792015-03-25 14:11:00 -05001971 :ref:`general name classes <general_name_classes>`.
1972
1973 :returns: A list of values extracted from the matched general names.
Joshua Taubererd2afad32015-07-06 22:37:53 +00001974 The type of the returned values depends on the :class:`GeneralName`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001975
Paul Kehrer93ae8052015-05-02 23:18:09 -05001976 .. doctest::
1977
1978 >>> from cryptography import x509
1979 >>> from cryptography.hazmat.backends import default_backend
1980 >>> from cryptography.hazmat.primitives import hashes
1981 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend())
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001982 >>> # Get the subjectAltName extension from the certificate
Paul Kehrere27f6582015-08-10 18:33:38 -05001983 >>> ext = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001984 >>> # Get the dNSName entries from the SAN extension
1985 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001986 ['www.cryptography.io', 'cryptography.io']
Paul Kehrer93ae8052015-05-02 23:18:09 -05001987
Paul Kehrer8cf26422015-03-21 09:50:24 -05001988
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001989.. class:: IssuerAlternativeName(general_names)
Paul Kehrer99125c92015-06-07 18:37:10 -05001990
1991 .. versionadded:: 1.0
1992
1993 Issuer alternative name is an X.509 extension that provides a list of
1994 :ref:`general name <general_name_classes>` instances that provide a set
1995 of identities for the certificate issuer. The object is iterable to
1996 get every element.
1997
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001998 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001999
Paul Kehrer822f3d32015-08-06 11:47:32 +01002000 .. attribute:: oid
2001
2002 .. versionadded:: 1.0
2003
2004 :type: :class:`ObjectIdentifier`
2005
Paul Kehrere27f6582015-08-10 18:33:38 -05002006 Returns
2007 :attr:`~cryptography.x509.oid.ExtensionOID.ISSUER_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002008
Paul Kehrer99125c92015-06-07 18:37:10 -05002009 .. method:: get_values_for_type(type)
2010
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03002011 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer99125c92015-06-07 18:37:10 -05002012 :ref:`general name classes <general_name_classes>`.
2013
2014 :returns: A list of values extracted from the matched general names.
2015
2016
Alex Gaynor6a0718f2017-06-04 13:36:58 -04002017.. class:: PrecertificateSignedCertificateTimestamps(scts)
2018
2019 .. versionadded:: 2.0
2020
2021 This extension contains
2022 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2023 instances which were issued for the pre-certificate corresponding to this
2024 certificate. These can be used to verify that the certificate is included
2025 in a public Certificate Transparency log.
2026
2027 It is an iterable containing one or more
2028 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2029 objects.
2030
2031 :param list scts: A ``list`` of
2032 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2033 objects.
2034
2035 .. attribute:: oid
2036
2037 :type: :class:`ObjectIdentifier`
2038
2039 Returns
2040 :attr:`~cryptography.x509.oid.ExtensionOID.PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS`.
2041
2042
Alex Gaynordd6b78b2018-08-31 18:25:52 -05002043.. class:: PrecertPoison()
2044
2045 .. versionadded:: 2.4
2046
2047 This extension indicates that the certificate should not be treated as a
2048 certificate for the purposes of validation, but is instead for submission
2049 to a certificate transparency log in order to obtain SCTs which will be
2050 embedded in a :class:`PrecertificateSignedCertificateTimestamps` extension
2051 on the final certificate.
2052
2053 .. attribute:: oid
2054
2055 :type: :class:`ObjectIdentifier`
2056
2057 Returns :attr:`~cryptography.x509.oid.ExtensionOID.PRECERT_POISON`.
2058
2059
Paul Kehrer5e3cc982017-09-22 21:29:36 +08002060.. class:: DeltaCRLIndicator(crl_number)
2061
2062 .. versionadded:: 2.1
2063
2064 The delta CRL indicator is a CRL extension that identifies a CRL as being
2065 a delta CRL. Delta CRLs contain updates to revocation information
2066 previously distributed, rather than all the information that would appear
2067 in a complete CRL.
2068
2069 :param int crl_number: The CRL number of the complete CRL that the
2070 delta CRL is updating.
2071
2072 .. attribute:: oid
2073
2074 :type: :class:`ObjectIdentifier`
2075
2076 Returns
2077 :attr:`~cryptography.x509.oid.ExtensionOID.DELTA_CRL_INDICATOR`.
2078
2079 .. attribute:: crl_number
2080
2081 :type: int
2082
2083
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002084.. class:: AuthorityInformationAccess(descriptions)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002085
2086 .. versionadded:: 0.9
2087
2088 The authority information access extension indicates how to access
2089 information and services for the issuer of the certificate in which
2090 the extension appears. Information and services may include online
2091 validation services (such as OCSP) and issuer data. It is an iterable,
Paul Kehrere27f6582015-08-10 18:33:38 -05002092 containing one or more :class:`~cryptography.x509.AccessDescription`
2093 instances.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002094
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002095 :param list descriptions: A list of :class:`AccessDescription` objects.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002096
Paul Kehrer822f3d32015-08-06 11:47:32 +01002097 .. attribute:: oid
2098
2099 .. versionadded:: 1.0
2100
2101 :type: :class:`ObjectIdentifier`
2102
Paul Kehrere27f6582015-08-10 18:33:38 -05002103 Returns
2104 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_INFORMATION_ACCESS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002105
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002106
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002107.. class:: AccessDescription(access_method, access_location)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002108
Paul Kehrer5a485522015-05-06 00:29:12 -05002109 .. versionadded:: 0.9
2110
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002111 .. attribute:: access_method
2112
2113 :type: :class:`ObjectIdentifier`
2114
Paul Kehrerf506bca2015-05-02 22:31:47 -05002115 The access method defines what the ``access_location`` means. It must
Paul Kehrere27f6582015-08-10 18:33:38 -05002116 be either
2117 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP` or
2118 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`.
2119 If it is
2120 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP`
2121 the access location will be where to obtain OCSP
2122 information for the certificate. If it is
2123 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`
2124 the access location will provide additional information about the
2125 issuing certificate.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002126
2127 .. attribute:: access_location
2128
2129 :type: :class:`GeneralName`
2130
Paul Kehrerf506bca2015-05-02 22:31:47 -05002131 Where to access the information defined by the access method.
2132
Paul Kehrerb76bcf82017-09-24 08:44:12 +08002133.. class:: FreshestCRL(distribution_points)
2134
2135 .. versionadded:: 2.1
2136
2137 The freshest CRL extension (also known as Delta CRL Distribution Point)
2138 identifies how delta CRL information is obtained. It is an iterable,
2139 containing one or more :class:`DistributionPoint` instances.
2140
2141 :param list distribution_points: A list of :class:`DistributionPoint`
2142 instances.
2143
2144 .. attribute:: oid
2145
2146 :type: :class:`ObjectIdentifier`
2147
2148 Returns
2149 :attr:`~cryptography.x509.oid.ExtensionOID.FRESHEST_CRL`.
2150
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002151.. class:: CRLDistributionPoints(distribution_points)
Paul Kehrer5a485522015-05-06 00:29:12 -05002152
2153 .. versionadded:: 0.9
2154
2155 The CRL distribution points extension identifies how CRL information is
2156 obtained. It is an iterable, containing one or more
2157 :class:`DistributionPoint` instances.
2158
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002159 :param list distribution_points: A list of :class:`DistributionPoint`
2160 instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002161
Paul Kehrer822f3d32015-08-06 11:47:32 +01002162 .. attribute:: oid
2163
2164 .. versionadded:: 1.0
2165
2166 :type: :class:`ObjectIdentifier`
2167
Paul Kehrere27f6582015-08-10 18:33:38 -05002168 Returns
2169 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_DISTRIBUTION_POINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002170
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002171.. class:: DistributionPoint(full_name, relative_name, reasons, crl_issuer)
Paul Kehrer5a485522015-05-06 00:29:12 -05002172
2173 .. versionadded:: 0.9
2174
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002175 .. attribute:: full_name
Paul Kehrer5a485522015-05-06 00:29:12 -05002176
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002177 :type: list of :class:`GeneralName` instances or None
Paul Kehrer5a485522015-05-06 00:29:12 -05002178
Paul Kehrerf2c072b2015-05-09 17:04:28 -05002179 This field describes methods to retrieve the CRL. At most one of
2180 ``full_name`` or ``relative_name`` will be non-None.
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002181
2182 .. attribute:: relative_name
2183
Fraser Tweedale02467dd2016-11-07 15:54:04 +10002184 :type: :class:`RelativeDistinguishedName` or None
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002185
2186 This field describes methods to retrieve the CRL relative to the CRL
Paul Kehrerf2c072b2015-05-09 17:04:28 -05002187 issuer. At most one of ``full_name`` or ``relative_name`` will be
2188 non-None.
Paul Kehrer5a485522015-05-06 00:29:12 -05002189
Fraser Tweedale02467dd2016-11-07 15:54:04 +10002190 .. versionchanged:: 1.6
2191 Changed from :class:`Name` to :class:`RelativeDistinguishedName`.
2192
Paul Kehrer5a485522015-05-06 00:29:12 -05002193 .. attribute:: crl_issuer
2194
2195 :type: list of :class:`GeneralName` instances or None
2196
2197 Information about the issuer of the CRL.
2198
2199 .. attribute:: reasons
2200
Paul Kehrer3fd02602015-05-09 19:46:13 -05002201 :type: frozenset of :class:`ReasonFlags` or None
Paul Kehrer5a485522015-05-06 00:29:12 -05002202
2203 The reasons a given distribution point may be used for when performing
2204 revocation checks.
2205
2206.. class:: ReasonFlags
2207
2208 .. versionadded:: 0.9
2209
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002210 An enumeration for CRL reasons.
2211
2212 .. attribute:: unspecified
2213
2214 It is unspecified why the certificate was revoked. This reason cannot
2215 be used as a reason flag in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05002216
2217 .. attribute:: key_compromise
2218
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002219 This reason indicates that the private key was compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05002220
2221 .. attribute:: ca_compromise
2222
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002223 This reason indicates that the CA issuing the certificate was
2224 compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05002225
2226 .. attribute:: affiliation_changed
2227
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002228 This reason indicates that the subject's name or other information has
2229 changed.
Paul Kehrer5a485522015-05-06 00:29:12 -05002230
2231 .. attribute:: superseded
2232
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002233 This reason indicates that a certificate has been superseded.
Paul Kehrer5a485522015-05-06 00:29:12 -05002234
2235 .. attribute:: cessation_of_operation
2236
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002237 This reason indicates that the certificate is no longer required.
Paul Kehrer5a485522015-05-06 00:29:12 -05002238
2239 .. attribute:: certificate_hold
2240
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002241 This reason indicates that the certificate is on hold.
Paul Kehrer5a485522015-05-06 00:29:12 -05002242
2243 .. attribute:: privilege_withdrawn
2244
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002245 This reason indicates that the privilege granted by this certificate
2246 have been withdrawn.
Paul Kehrer5a485522015-05-06 00:29:12 -05002247
2248 .. attribute:: aa_compromise
2249
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002250 When an attribute authority has been compromised.
2251
2252 .. attribute:: remove_from_crl
2253
2254 This reason indicates that the certificate was on hold and should be
2255 removed from the CRL. This reason cannot be used as a reason flag
2256 in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05002257
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002258.. class:: InhibitAnyPolicy(skip_certs)
Paul Kehrer16fae762015-05-01 23:14:20 -05002259
2260 .. versionadded:: 1.0
2261
2262 The inhibit ``anyPolicy`` extension indicates that the special OID
Paul Kehrere27f6582015-08-10 18:33:38 -05002263 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY`, is not
2264 considered an explicit match for other :class:`CertificatePolicies` except
2265 when it appears in an intermediate self-issued CA certificate. The value
2266 indicates the number of additional non-self-issued certificates that may
2267 appear in the path before
2268 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` is no
2269 longer permitted. For example, a value of one indicates that
2270 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` may be
2271 processed in certificates issued by the subject of this certificate, but
2272 not in additional certificates in the path.
Paul Kehrer16fae762015-05-01 23:14:20 -05002273
Paul Kehrer822f3d32015-08-06 11:47:32 +01002274 .. attribute:: oid
2275
2276 .. versionadded:: 1.0
2277
2278 :type: :class:`ObjectIdentifier`
2279
Paul Kehrere27f6582015-08-10 18:33:38 -05002280 Returns
2281 :attr:`~cryptography.x509.oid.ExtensionOID.INHIBIT_ANY_POLICY`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002282
Paul Kehrer16fae762015-05-01 23:14:20 -05002283 .. attribute:: skip_certs
2284
2285 :type: int
2286
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002287.. class:: PolicyConstraints
2288
2289 .. versionadded:: 1.3
2290
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002291 The policy constraints extension is used to inhibit policy mapping or
2292 require that each certificate in a chain contain an acceptable policy
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002293 identifier. For more information about the use of this extension see
2294 :rfc:`5280`.
2295
Paul Kehrer159b3b52016-02-26 08:27:22 -06002296 .. attribute:: oid
2297
2298 :type: :class:`ObjectIdentifier`
2299
2300 Returns :attr:`~cryptography.x509.oid.ExtensionOID.POLICY_CONSTRAINTS`.
2301
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002302 .. attribute:: require_explicit_policy
2303
2304 :type: int or None
2305
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002306 If this field is not None, the value indicates the number of additional
2307 certificates that may appear in the chain before an explicit policy is
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002308 required for the entire path. When an explicit policy is required, it
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002309 is necessary for all certificates in the chain to contain an acceptable
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002310 policy identifier in the certificate policies extension. An
2311 acceptable policy identifier is the identifier of a policy required
2312 by the user of the certification path or the identifier of a policy
2313 that has been declared equivalent through policy mapping.
2314
2315 .. attribute:: inhibit_policy_mapping
2316
2317 :type: int or None
2318
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002319 If this field is not None, the value indicates the number of additional
2320 certificates that may appear in the chain before policy mapping is no
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002321 longer permitted. For example, a value of one indicates that policy
2322 mapping may be processed in certificates issued by the subject of this
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002323 certificate, but not in additional certificates in the chain.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002324
Paul Kehrer3b95cd72015-12-22 21:40:20 -06002325.. class:: CRLNumber(crl_number)
2326
2327 .. versionadded:: 1.2
2328
Paul Kehrere32b9942015-12-22 22:26:53 -06002329 The CRL number is a CRL extension that conveys a monotonically increasing
2330 sequence number for a given CRL scope and CRL issuer. This extension allows
2331 users to easily determine when a particular CRL supersedes another CRL.
2332 :rfc:`5280` requires that this extension be present in conforming CRLs.
Paul Kehrer3b95cd72015-12-22 21:40:20 -06002333
2334 .. attribute:: oid
2335
2336 :type: :class:`ObjectIdentifier`
2337
2338 Returns
2339 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_NUMBER`.
2340
2341 .. attribute:: crl_number
2342
2343 :type: int
2344
Paul Kehrereb3e2e02018-12-01 12:15:20 +08002345.. class:: IssuingDistributionPoint(full_name, relative_name,\
2346 only_contains_user_certs, only_contains_ca_certs, only_some_reasons,\
2347 indirect_crl, only_contains_attribute_certs)
2348
2349 .. versionadded:: 2.5
2350
2351 Issuing distribution point is a CRL extension that identifies the CRL
2352 distribution point and scope for a particular CRL. It indicates whether
2353 the CRL covers revocation for end entity certificates only, CA certificates
2354 only, attribute certificates only, or a limited set of reason codes. For
2355 specific details on the way this extension should be processed see
2356 :rfc:`5280`.
2357
2358 .. attribute:: oid
2359
2360 :type: :class:`ObjectIdentifier`
2361
2362 Returns
2363 :attr:`~cryptography.x509.oid.ExtensionOID.ISSUING_DISTRIBUTION_POINT`.
2364
2365 .. attribute:: only_contains_user_certs
2366
2367 :type: bool
2368
2369 Set to ``True`` if the CRL this extension is embedded within only
2370 contains information about user certificates.
2371
2372 .. attribute:: only_contains_ca_certs
2373
2374 :type: bool
2375
2376 Set to ``True`` if the CRL this extension is embedded within only
2377 contains information about CA certificates.
2378
2379 .. attribute:: indirect_crl
2380
2381 :type: bool
2382
2383 Set to ``True`` if the CRL this extension is embedded within includes
2384 certificates issued by one or more authorities other than the CRL
2385 issuer.
2386
2387 .. attribute:: only_contains_attribute_certs
2388
2389 :type: bool
2390
2391 Set to ``True`` if the CRL this extension is embedded within only
2392 contains information about attribute certificates.
2393
2394 .. attribute:: only_some_reasons
2395
2396 :type: frozenset of :class:`ReasonFlags` or None
2397
2398 The reasons for which the issuing distribution point is valid. None
2399 indicates that it is valid for all reasons.
2400
2401 .. attribute:: full_name
2402
2403 :type: list of :class:`GeneralName` instances or None
2404
2405 This field describes methods to retrieve the CRL. At most one of
2406 ``full_name`` or ``relative_name`` will be non-None.
2407
2408 .. attribute:: relative_name
2409
2410 :type: :class:`RelativeDistinguishedName` or None
2411
2412 This field describes methods to retrieve the CRL relative to the CRL
2413 issuer. At most one of ``full_name`` or ``relative_name`` will be
2414 non-None.
2415
Paul Kehrer14fd6972015-12-30 10:58:25 -06002416.. class:: UnrecognizedExtension
2417
2418 .. versionadded:: 1.2
2419
Alex Gaynord08ddd52017-05-20 09:01:54 -07002420 A generic extension class used to hold the raw value of extensions that
2421 ``cryptography`` does not know how to parse.
Paul Kehrer14fd6972015-12-30 10:58:25 -06002422
2423 .. attribute:: oid
2424
2425 :type: :class:`ObjectIdentifier`
2426
2427 Returns the OID associated with this extension.
2428
2429 .. attribute:: value
2430
Paul Kehreredfedc12018-09-14 18:24:20 -04002431 :type: bytes
Paul Kehrer14fd6972015-12-30 10:58:25 -06002432
2433 Returns the DER encoded bytes payload of the extension.
2434
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002435.. class:: CertificatePolicies(policies)
Paul Kehrer0d210922015-04-28 17:31:07 -05002436
2437 .. versionadded:: 0.9
2438
Paul Kehrer2e879742015-05-02 23:09:56 -05002439 The certificate policies extension is an iterable, containing one or more
2440 :class:`PolicyInformation` instances.
Paul Kehrer0d210922015-04-28 17:31:07 -05002441
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002442 :param list policies: A list of :class:`PolicyInformation` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002443
Paul Kehrer822f3d32015-08-06 11:47:32 +01002444 .. attribute:: oid
2445
2446 .. versionadded:: 1.0
2447
2448 :type: :class:`ObjectIdentifier`
2449
Paul Kehrere27f6582015-08-10 18:33:38 -05002450 Returns
2451 :attr:`~cryptography.x509.oid.ExtensionOID.CERTIFICATE_POLICIES`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002452
Paul Kehrer0d210922015-04-28 17:31:07 -05002453Certificate Policies Classes
2454~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2455
2456These classes may be present within a :class:`CertificatePolicies` instance.
2457
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002458.. class:: PolicyInformation(policy_identifier, policy_qualifiers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002459
2460 .. versionadded:: 0.9
2461
2462 Contains a policy identifier and an optional list of qualifiers.
2463
2464 .. attribute:: policy_identifier
2465
2466 :type: :class:`ObjectIdentifier`
2467
2468 .. attribute:: policy_qualifiers
2469
2470 :type: list
2471
Paul Kehrerba35b3b2015-05-10 13:07:59 -05002472 A list consisting of :term:`text` and/or :class:`UserNotice` objects.
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002473 If the value is text it is a pointer to the practice statement
2474 published by the certificate authority. If it is a user notice it is
2475 meant for display to the relying party when the certificate is
2476 used.
Paul Kehrer2e879742015-05-02 23:09:56 -05002477
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002478.. class:: UserNotice(notice_reference, explicit_text)
Paul Kehrer0d210922015-04-28 17:31:07 -05002479
2480 .. versionadded:: 0.9
2481
Paul Kehrer2e879742015-05-02 23:09:56 -05002482 User notices are intended for display to a relying party when a certificate
2483 is used. In practice, few if any UIs expose this data and it is a rarely
2484 encoded component.
2485
Paul Kehrer0d210922015-04-28 17:31:07 -05002486 .. attribute:: notice_reference
2487
2488 :type: :class:`NoticeReference` or None
2489
Paul Kehrer2e879742015-05-02 23:09:56 -05002490 The notice reference field names an organization and identifies,
2491 by number, a particular statement prepared by that organization.
2492
Paul Kehrer0d210922015-04-28 17:31:07 -05002493 .. attribute:: explicit_text
2494
Paul Kehrer2e879742015-05-02 23:09:56 -05002495 This field includes an arbitrary textual statement directly in the
2496 certificate.
2497
Paul Kehrer0d210922015-04-28 17:31:07 -05002498 :type: :term:`text`
2499
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002500.. class:: NoticeReference(organization, notice_numbers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002501
Paul Kehrer2e879742015-05-02 23:09:56 -05002502 Notice reference can name an organization and provide information about
2503 notices related to the certificate. For example, it might identify the
2504 organization name and notice number 1. Application software could
2505 have a notice file containing the current set of notices for the named
2506 organization; the application would then extract the notice text from the
2507 file and display it. In practice this is rarely seen.
2508
Paul Kehrer0d210922015-04-28 17:31:07 -05002509 .. versionadded:: 0.9
2510
2511 .. attribute:: organization
2512
Paul Kehrer66c61702015-05-12 16:39:18 -05002513 :type: :term:`text`
Paul Kehrer0d210922015-04-28 17:31:07 -05002514
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002515 .. attribute:: notice_numbers
Paul Kehrer0d210922015-04-28 17:31:07 -05002516
Paul Kehrer66c61702015-05-12 16:39:18 -05002517 :type: list
Paul Kehrer0d210922015-04-28 17:31:07 -05002518
Paul Kehrer66c61702015-05-12 16:39:18 -05002519 A list of integers.
Paul Kehrer0d210922015-04-28 17:31:07 -05002520
Paul Kehrere5f152b2015-12-25 23:55:47 -06002521.. _crl_entry_extensions:
2522
Paul Kehrer49bb7562015-12-25 16:17:40 -06002523CRL Entry Extensions
2524~~~~~~~~~~~~~~~~~~~~
2525
2526These extensions are only valid within a :class:`RevokedCertificate` object.
2527
2528.. class:: CertificateIssuer(general_names)
2529
2530 .. versionadded:: 1.2
2531
2532 The certificate issuer is an extension that is only valid inside
2533 :class:`~cryptography.x509.RevokedCertificate` objects. If the
2534 ``indirectCRL`` property of the parent CRL's IssuingDistributionPoint
2535 extension is set, then this extension identifies the certificate issuer
2536 associated with the revoked certificate. The object is iterable to get
2537 every element.
2538
2539 :param list general_names: A list of :class:`GeneralName` instances.
2540
2541 .. attribute:: oid
2542
2543 :type: :class:`ObjectIdentifier`
2544
2545 Returns
2546 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CERTIFICATE_ISSUER`.
2547
2548 .. method:: get_values_for_type(type)
2549
2550 :param type: A :class:`GeneralName` instance. This is one of the
2551 :ref:`general name classes <general_name_classes>`.
2552
2553 :returns: A list of values extracted from the matched general names.
2554 The type of the returned values depends on the :class:`GeneralName`.
2555
Paul Kehrer7058ece2015-12-25 22:28:29 -06002556.. class:: CRLReason(reason)
2557
2558 .. versionadded:: 1.2
2559
2560 CRL reason (also known as ``reasonCode``) is an extension that is only
2561 valid inside :class:`~cryptography.x509.RevokedCertificate` objects. It
2562 identifies a reason for the certificate revocation.
2563
Paul Kehrerce4d0842017-09-20 22:14:26 +08002564 :param reason: An element from :class:`~cryptography.x509.ReasonFlags`.
Paul Kehrer7058ece2015-12-25 22:28:29 -06002565
2566 .. attribute:: oid
2567
2568 :type: :class:`ObjectIdentifier`
2569
2570 Returns
2571 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CRL_REASON`.
2572
2573 .. attribute:: reason
2574
2575 :type: An element from :class:`~cryptography.x509.ReasonFlags`
2576
Paul Kehrer23c0bbc2015-12-25 22:35:19 -06002577.. class:: InvalidityDate(invalidity_date)
2578
2579 .. versionadded:: 1.2
2580
2581 Invalidity date is an extension that is only valid inside
2582 :class:`~cryptography.x509.RevokedCertificate` objects. It provides
2583 the date on which it is known or suspected that the private key was
2584 compromised or that the certificate otherwise became invalid.
2585 This date may be earlier than the revocation date in the CRL entry,
2586 which is the date at which the CA processed the revocation.
2587
2588 :param invalidity_date: The :class:`datetime.datetime` when it is known
2589 or suspected that the private key was compromised.
2590
2591 .. attribute:: oid
2592
2593 :type: :class:`ObjectIdentifier`
2594
2595 Returns
2596 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.INVALIDITY_DATE`.
2597
2598 .. attribute:: invalidity_date
2599
2600 :type: :class:`datetime.datetime`
2601
Paul Kehrer09403102018-09-09 21:57:21 -05002602OCSP Extensions
2603~~~~~~~~~~~~~~~
2604
2605.. class:: OCSPNonce(nonce)
2606
2607 .. versionadded:: 2.4
2608
2609 OCSP nonce is an extension that is only valid inside
2610 :class:`~cryptography.x509.ocsp.OCSPRequest` and
2611 :class:`~cryptography.x509.ocsp.OCSPResponse` objects. The nonce
2612 cryptographically binds a request and a response to prevent replay attacks.
2613 In practice nonces are rarely used in OCSP due to the desire to precompute
2614 OCSP responses at large scale.
2615
2616 .. attribute:: oid
2617
2618 :type: :class:`ObjectIdentifier`
2619
2620 Returns
2621 :attr:`~cryptography.x509.oid.OCSPExtensionOID.NONCE`.
2622
2623 .. attribute:: nonce
2624
2625 :type: bytes
Paul Kehrer49bb7562015-12-25 16:17:40 -06002626
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002627Object Identifiers
2628~~~~~~~~~~~~~~~~~~
2629
Paul Kehrer4bb46492015-02-07 16:59:14 -06002630X.509 elements are frequently identified by :class:`ObjectIdentifier`
2631instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002632
Paul Kehrere27f6582015-08-10 18:33:38 -05002633.. currentmodule:: cryptography.x509.oid
Paul Kehrer56da2a52015-02-11 23:35:07 -06002634
Paul Kehrere27f6582015-08-10 18:33:38 -05002635.. class:: NameOID
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002636
Paul Kehrere27f6582015-08-10 18:33:38 -05002637 These OIDs are typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06002638
Paul Kehrere27f6582015-08-10 18:33:38 -05002639 .. versionadded:: 1.0
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002640
Paul Kehrere27f6582015-08-10 18:33:38 -05002641 .. attribute:: COMMON_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002642
Paul Kehrere27f6582015-08-10 18:33:38 -05002643 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
2644 name would be encoded here for server certificates. :rfc:`2818`
2645 deprecates this practice and names of that type should now be located
2646 in a :class:`~cryptography.x509.SubjectAlternativeName` extension.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002647
Paul Kehrere27f6582015-08-10 18:33:38 -05002648 .. attribute:: COUNTRY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002649
Paul Kehrere27f6582015-08-10 18:33:38 -05002650 Corresponds to the dotted string ``"2.5.4.6"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002651
Paul Kehrere27f6582015-08-10 18:33:38 -05002652 .. attribute:: LOCALITY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002653
Paul Kehrere27f6582015-08-10 18:33:38 -05002654 Corresponds to the dotted string ``"2.5.4.7"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002655
Paul Kehrere27f6582015-08-10 18:33:38 -05002656 .. attribute:: STATE_OR_PROVINCE_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002657
Paul Kehrere27f6582015-08-10 18:33:38 -05002658 Corresponds to the dotted string ``"2.5.4.8"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002659
Paul Kehrerc3b8ff62016-11-11 17:38:59 -08002660 .. attribute:: STREET_ADDRESS
2661
2662 .. versionadded:: 1.6
2663
2664 Corresponds to the dotted string ``"2.5.4.9"``.
2665
Paul Kehrere27f6582015-08-10 18:33:38 -05002666 .. attribute:: ORGANIZATION_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002667
Paul Kehrere27f6582015-08-10 18:33:38 -05002668 Corresponds to the dotted string ``"2.5.4.10"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002669
Paul Kehrere27f6582015-08-10 18:33:38 -05002670 .. attribute:: ORGANIZATIONAL_UNIT_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002671
Paul Kehrere27f6582015-08-10 18:33:38 -05002672 Corresponds to the dotted string ``"2.5.4.11"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002673
Paul Kehrere27f6582015-08-10 18:33:38 -05002674 .. attribute:: SERIAL_NUMBER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002675
Paul Kehrere27f6582015-08-10 18:33:38 -05002676 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from
2677 the serial number of the certificate itself (which can be obtained with
Chelsea Winfreee295f3a2016-06-02 21:15:54 -07002678 :func:`~cryptography.x509.Certificate.serial_number`).
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002679
Paul Kehrere27f6582015-08-10 18:33:38 -05002680 .. attribute:: SURNAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002681
Paul Kehrere27f6582015-08-10 18:33:38 -05002682 Corresponds to the dotted string ``"2.5.4.4"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002683
Paul Kehrere27f6582015-08-10 18:33:38 -05002684 .. attribute:: GIVEN_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002685
Paul Kehrere27f6582015-08-10 18:33:38 -05002686 Corresponds to the dotted string ``"2.5.4.42"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002687
Paul Kehrere27f6582015-08-10 18:33:38 -05002688 .. attribute:: TITLE
Paul Kehrer858b9b72015-02-05 09:50:31 -06002689
Paul Kehrere27f6582015-08-10 18:33:38 -05002690 Corresponds to the dotted string ``"2.5.4.12"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002691
Paul Kehrere27f6582015-08-10 18:33:38 -05002692 .. attribute:: GENERATION_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002693
Paul Kehrere27f6582015-08-10 18:33:38 -05002694 Corresponds to the dotted string ``"2.5.4.44"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002695
Paul Kehrerc7ab9312016-11-12 05:00:42 -08002696 .. attribute:: X500_UNIQUE_IDENTIFIER
Paul Kehrerc3b8ff62016-11-11 17:38:59 -08002697
2698 .. versionadded:: 1.6
2699
2700 Corresponds to the dotted string ``"2.5.4.45"``.
2701
Paul Kehrere27f6582015-08-10 18:33:38 -05002702 .. attribute:: DN_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002703
Paul Kehrere27f6582015-08-10 18:33:38 -05002704 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
2705 disambiguating information to add to the relative distinguished name of an
2706 entry. See :rfc:`2256`.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002707
Paul Kehrere27f6582015-08-10 18:33:38 -05002708 .. attribute:: PSEUDONYM
Paul Kehrer858b9b72015-02-05 09:50:31 -06002709
Paul Kehrere27f6582015-08-10 18:33:38 -05002710 Corresponds to the dotted string ``"2.5.4.65"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002711
Paul Kehrer36d5cd62016-11-19 22:05:26 +08002712 .. attribute:: USER_ID
2713
2714 .. versionadded:: 1.6
2715
2716 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.1"``.
2717
Paul Kehrere27f6582015-08-10 18:33:38 -05002718 .. attribute:: DOMAIN_COMPONENT
Paul Kehrer858b9b72015-02-05 09:50:31 -06002719
Paul Kehrere27f6582015-08-10 18:33:38 -05002720 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
2721 holding one component of a domain name. See :rfc:`4519`.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002722
Paul Kehrere27f6582015-08-10 18:33:38 -05002723 .. attribute:: EMAIL_ADDRESS
Paul Kehrer56da2a52015-02-11 23:35:07 -06002724
Paul Kehrere27f6582015-08-10 18:33:38 -05002725 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002726
Alex Gaynor1d3f2bf2015-12-19 12:15:09 -05002727 .. attribute:: JURISDICTION_COUNTRY_NAME
2728
2729 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.3"``.
2730
Alex Gaynor45e507f2015-12-19 13:44:23 -05002731 .. attribute:: JURISDICTION_LOCALITY_NAME
2732
2733 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.1"``.
2734
2735 .. attribute:: JURISDICTION_STATE_OR_PROVINCE_NAME
2736
2737 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.2"``.
2738
Alex Gaynora2293c82015-12-19 20:49:15 -05002739 .. attribute:: BUSINESS_CATEGORY
2740
2741 Corresponds to the dotted string ``"2.5.4.15"``.
2742
Paul Kehrer36d5cd62016-11-19 22:05:26 +08002743 .. attribute:: POSTAL_ADDRESS
2744
2745 .. versionadded:: 1.6
2746
2747 Corresponds to the dotted string ``"2.5.4.16"``.
2748
2749 .. attribute:: POSTAL_CODE
2750
2751 .. versionadded:: 1.6
2752
2753 Corresponds to the dotted string ``"2.5.4.17"``.
2754
Paul Kehrer56da2a52015-02-11 23:35:07 -06002755
Paul Kehrere27f6582015-08-10 18:33:38 -05002756.. class:: SignatureAlgorithmOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002757
Paul Kehrere27f6582015-08-10 18:33:38 -05002758 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002759
Paul Kehrere27f6582015-08-10 18:33:38 -05002760 .. attribute:: RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -06002761
Paul Kehrere27f6582015-08-10 18:33:38 -05002762 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
2763 an MD5 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002764
Paul Kehrere27f6582015-08-10 18:33:38 -05002765 .. attribute:: RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06002766
Paul Kehrere27f6582015-08-10 18:33:38 -05002767 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
2768 a SHA1 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002769
Paul Kehrere27f6582015-08-10 18:33:38 -05002770 .. attribute:: RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002771
Paul Kehrere27f6582015-08-10 18:33:38 -05002772 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
2773 a SHA224 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002774
Paul Kehrere27f6582015-08-10 18:33:38 -05002775 .. attribute:: RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002776
Paul Kehrere27f6582015-08-10 18:33:38 -05002777 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
2778 a SHA256 digest signed by an RSA key.
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002779
Paul Kehrere27f6582015-08-10 18:33:38 -05002780 .. attribute:: RSA_WITH_SHA384
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002781
Paul Kehrere27f6582015-08-10 18:33:38 -05002782 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
2783 a SHA384 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002784
Paul Kehrere27f6582015-08-10 18:33:38 -05002785 .. attribute:: RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -06002786
Paul Kehrere27f6582015-08-10 18:33:38 -05002787 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
2788 a SHA512 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002789
Marti Raudsepp33678062018-06-30 02:27:28 +03002790 .. attribute:: RSASSA_PSS
2791
2792 .. versionadded:: 2.3
2793
2794 Corresponds to the dotted string ``"1.2.840.113549.1.1.10"``. This is
2795 signed by an RSA key using the Probabilistic Signature Scheme (PSS)
Alex Gaynore5463cc2019-01-18 15:19:34 -06002796 padding from :rfc:`4055`. The hash function and padding are defined by
Marti Raudsepp33678062018-06-30 02:27:28 +03002797 signature algorithm parameters.
2798
Paul Kehrere27f6582015-08-10 18:33:38 -05002799 .. attribute:: ECDSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06002800
Paul Kehrere27f6582015-08-10 18:33:38 -05002801 Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1
2802 digest signed by an ECDSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002803
Paul Kehrere27f6582015-08-10 18:33:38 -05002804 .. attribute:: ECDSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002805
Paul Kehrere27f6582015-08-10 18:33:38 -05002806 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
2807 a SHA224 digest signed by an ECDSA key.
2808
2809 .. attribute:: ECDSA_WITH_SHA256
2810
2811 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
2812 a SHA256 digest signed by an ECDSA key.
2813
2814 .. attribute:: ECDSA_WITH_SHA384
2815
2816 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
2817 a SHA384 digest signed by an ECDSA key.
2818
2819 .. attribute:: ECDSA_WITH_SHA512
2820
2821 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
2822 a SHA512 digest signed by an ECDSA key.
2823
2824 .. attribute:: DSA_WITH_SHA1
2825
2826 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
2827 a SHA1 digest signed by a DSA key.
2828
2829 .. attribute:: DSA_WITH_SHA224
2830
2831 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
2832 a SHA224 digest signed by a DSA key.
2833
2834 .. attribute:: DSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002835
Paul Kehrere27f6582015-08-10 18:33:38 -05002836 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
2837 a SHA256 digest signed by a DSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002838
Paul Kehrer56da2a52015-02-11 23:35:07 -06002839
Paul Kehrere27f6582015-08-10 18:33:38 -05002840.. class:: ExtendedKeyUsageOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002841
Paul Kehrere27f6582015-08-10 18:33:38 -05002842 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002843
Paul Kehrere27f6582015-08-10 18:33:38 -05002844 .. attribute:: SERVER_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002845
Paul Kehrere27f6582015-08-10 18:33:38 -05002846 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used
2847 to denote that a certificate may be used for TLS web server
2848 authentication.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002849
Paul Kehrere27f6582015-08-10 18:33:38 -05002850 .. attribute:: CLIENT_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002851
Paul Kehrere27f6582015-08-10 18:33:38 -05002852 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used
2853 to denote that a certificate may be used for TLS web client
2854 authentication.
Paul Kehrerffa2a152015-03-31 08:18:25 -05002855
Paul Kehrere27f6582015-08-10 18:33:38 -05002856 .. attribute:: CODE_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002857
Paul Kehrere27f6582015-08-10 18:33:38 -05002858 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used
2859 to denote that a certificate may be used for code signing.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002860
Paul Kehrere27f6582015-08-10 18:33:38 -05002861 .. attribute:: EMAIL_PROTECTION
Paul Kehrere1513fa2015-03-30 23:08:17 -05002862
Paul Kehrere27f6582015-08-10 18:33:38 -05002863 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used
2864 to denote that a certificate may be used for email protection.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002865
Paul Kehrere27f6582015-08-10 18:33:38 -05002866 .. attribute:: TIME_STAMPING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002867
Paul Kehrere27f6582015-08-10 18:33:38 -05002868 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used
2869 to denote that a certificate may be used for time stamping.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002870
Paul Kehrere27f6582015-08-10 18:33:38 -05002871 .. attribute:: OCSP_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002872
Paul Kehrere27f6582015-08-10 18:33:38 -05002873 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used
2874 to denote that a certificate may be used for signing OCSP responses.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002875
Alex Gaynorb7912ee2017-07-03 10:07:02 -04002876 .. attribute:: ANY_EXTENDED_KEY_USAGE
2877
2878 .. versionadded:: 2.0
2879
2880 Corresponds to the dotted string ``"2.5.29.37.0"``. This is used to
2881 denote that a certificate may be used for _any_ purposes.
2882
Paul Kehrere1513fa2015-03-30 23:08:17 -05002883
Paul Kehrere27f6582015-08-10 18:33:38 -05002884.. class:: AuthorityInformationAccessOID
Paul Kehrere1513fa2015-03-30 23:08:17 -05002885
Paul Kehrere27f6582015-08-10 18:33:38 -05002886 .. versionadded:: 1.0
Paul Kehrere1513fa2015-03-30 23:08:17 -05002887
Paul Kehrere27f6582015-08-10 18:33:38 -05002888 .. attribute:: OCSP
Paul Kehrere1513fa2015-03-30 23:08:17 -05002889
Paul Kehrere27f6582015-08-10 18:33:38 -05002890 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
2891 identifier for OCSP data in
2892 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002893
Paul Kehrere27f6582015-08-10 18:33:38 -05002894 .. attribute:: CA_ISSUERS
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002895
Paul Kehrere27f6582015-08-10 18:33:38 -05002896 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
2897 identifier for CA issuer data in
2898 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002899
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002900
Paul Kehrere27f6582015-08-10 18:33:38 -05002901.. class:: CertificatePoliciesOID
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002902
Paul Kehrere27f6582015-08-10 18:33:38 -05002903 .. versionadded:: 1.0
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002904
Paul Kehrere27f6582015-08-10 18:33:38 -05002905 .. attribute:: CPS_QUALIFIER
Paul Kehrer2e879742015-05-02 23:09:56 -05002906
Paul Kehrere27f6582015-08-10 18:33:38 -05002907 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05002908
Paul Kehrere27f6582015-08-10 18:33:38 -05002909 .. attribute:: CPS_USER_NOTICE
Paul Kehrer2e879742015-05-02 23:09:56 -05002910
Paul Kehrere27f6582015-08-10 18:33:38 -05002911 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05002912
Paul Kehrere27f6582015-08-10 18:33:38 -05002913 .. attribute:: ANY_POLICY
Paul Kehrer2e879742015-05-02 23:09:56 -05002914
Paul Kehrere27f6582015-08-10 18:33:38 -05002915 Corresponds to the dotted string ``"2.5.29.32.0"``.
Paul Kehrer16fae762015-05-01 23:14:20 -05002916
Paul Kehrer16fae762015-05-01 23:14:20 -05002917
Paul Kehrere27f6582015-08-10 18:33:38 -05002918.. class:: ExtensionOID
Paul Kehrer5553d572015-03-23 21:08:01 -05002919
Paul Kehrere27f6582015-08-10 18:33:38 -05002920 .. versionadded:: 1.0
Paul Kehrer2bb94642015-03-21 09:54:17 -05002921
Paul Kehrere27f6582015-08-10 18:33:38 -05002922 .. attribute:: BASIC_CONSTRAINTS
Paul Kehrer2bb94642015-03-21 09:54:17 -05002923
Paul Kehrere27f6582015-08-10 18:33:38 -05002924 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
2925 :class:`~cryptography.x509.BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05002926
Paul Kehrere27f6582015-08-10 18:33:38 -05002927 .. attribute:: KEY_USAGE
Paul Kehrercecbbba2015-03-30 14:58:38 -05002928
Paul Kehrere27f6582015-08-10 18:33:38 -05002929 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
2930 :class:`~cryptography.x509.KeyUsage` extension type.
Paul Kehrercecbbba2015-03-30 14:58:38 -05002931
Paul Kehrere27f6582015-08-10 18:33:38 -05002932 .. attribute:: SUBJECT_ALTERNATIVE_NAME
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002933
Paul Kehrere27f6582015-08-10 18:33:38 -05002934 Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the
2935 :class:`~cryptography.x509.SubjectAlternativeName` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002936
Paul Kehrere27f6582015-08-10 18:33:38 -05002937 .. attribute:: ISSUER_ALTERNATIVE_NAME
Paul Kehrer99125c92015-06-07 18:37:10 -05002938
Paul Kehrere27f6582015-08-10 18:33:38 -05002939 Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the
2940 :class:`~cryptography.x509.IssuerAlternativeName` extension type.
Paul Kehrer99125c92015-06-07 18:37:10 -05002941
Paul Kehrere27f6582015-08-10 18:33:38 -05002942 .. attribute:: SUBJECT_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002943
Paul Kehrere27f6582015-08-10 18:33:38 -05002944 Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the
2945 :class:`~cryptography.x509.SubjectKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002946
Paul Kehrere27f6582015-08-10 18:33:38 -05002947 .. attribute:: NAME_CONSTRAINTS
Paul Kehrere0017be2015-05-17 20:39:40 -06002948
Paul Kehrere27f6582015-08-10 18:33:38 -05002949 Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the
2950 :class:`~cryptography.x509.NameConstraints` extension type.
Paul Kehrere0017be2015-05-17 20:39:40 -06002951
Paul Kehrere27f6582015-08-10 18:33:38 -05002952 .. attribute:: CRL_DISTRIBUTION_POINTS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002953
Paul Kehrere27f6582015-08-10 18:33:38 -05002954 Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the
2955 :class:`~cryptography.x509.CRLDistributionPoints` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002956
Paul Kehrere27f6582015-08-10 18:33:38 -05002957 .. attribute:: CERTIFICATE_POLICIES
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002958
Paul Kehrere27f6582015-08-10 18:33:38 -05002959 Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the
2960 :class:`~cryptography.x509.CertificatePolicies` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002961
Paul Kehrere27f6582015-08-10 18:33:38 -05002962 .. attribute:: AUTHORITY_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002963
Paul Kehrere27f6582015-08-10 18:33:38 -05002964 Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the
2965 :class:`~cryptography.x509.AuthorityKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002966
Paul Kehrere27f6582015-08-10 18:33:38 -05002967 .. attribute:: EXTENDED_KEY_USAGE
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002968
Paul Kehrere27f6582015-08-10 18:33:38 -05002969 Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the
2970 :class:`~cryptography.x509.ExtendedKeyUsage` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002971
Paul Kehrere27f6582015-08-10 18:33:38 -05002972 .. attribute:: AUTHORITY_INFORMATION_ACCESS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002973
Paul Kehrere27f6582015-08-10 18:33:38 -05002974 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier
2975 for the :class:`~cryptography.x509.AuthorityInformationAccess` extension
2976 type.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002977
Paul Kehrere27f6582015-08-10 18:33:38 -05002978 .. attribute:: INHIBIT_ANY_POLICY
Paul Kehrerb33de932015-08-06 23:41:05 +01002979
Paul Kehrere27f6582015-08-10 18:33:38 -05002980 Corresponds to the dotted string ``"2.5.29.54"``. The identifier
2981 for the :class:`~cryptography.x509.InhibitAnyPolicy` extension type.
Paul Kehrerb33de932015-08-06 23:41:05 +01002982
Paul Kehrere27f6582015-08-10 18:33:38 -05002983 .. attribute:: OCSP_NO_CHECK
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002984
Paul Kehrere27f6582015-08-10 18:33:38 -05002985 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The
2986 identifier for the :class:`~cryptography.x509.OCSPNoCheck` extension
2987 type.
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002988
Paul Kehrer5d669662017-09-11 09:16:34 +08002989 .. attribute:: TLS_FEATURE
2990
2991 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.24"``. The
2992 identifier for the :class:`~cryptography.x509.TLSFeature` extension
2993 type.
2994
Paul Kehrer51f39cb2015-12-21 21:17:39 -06002995 .. attribute:: CRL_NUMBER
2996
2997 Corresponds to the dotted string ``"2.5.29.20"``. The identifier for
2998 the ``CRLNumber`` extension type. This extension only has meaning
2999 for certificate revocation lists.
3000
Paul Kehrer5e3cc982017-09-22 21:29:36 +08003001 .. attribute:: DELTA_CRL_INDICATOR
3002
3003 .. versionadded:: 2.1
3004
3005 Corresponds to the dotted string ``"2.5.29.27"``. The identifier for
3006 the ``DeltaCRLIndicator`` extension type. This extension only has
3007 meaning for certificate revocation lists.
3008
Alex Gaynor9bab0ed2017-03-20 09:50:52 -04003009 .. attribute:: PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS
3010
3011 .. versionadded:: 1.9
3012
3013 Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.2"``.
3014
Alex Gaynordd6b78b2018-08-31 18:25:52 -05003015 .. attribute:: PRECERT_POISON
3016
3017 .. versionadded:: 2.4
3018
3019 Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.3"``.
3020
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07003021 .. attribute:: POLICY_CONSTRAINTS
3022
3023 Corresponds to the dotted string ``"2.5.29.36"``. The identifier for the
Paul Kehrer20f0df52016-02-26 08:37:13 -06003024 :class:`~cryptography.x509.PolicyConstraints` extension type.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07003025
Paul Kehrerb76bcf82017-09-24 08:44:12 +08003026 .. attribute:: FRESHEST_CRL
3027
3028 Corresponds to the dotted string ``"2.5.29.46"``. The identifier for the
3029 :class:`~cryptography.x509.FreshestCRL` extension type.
3030
Paul Kehrer6e756ae2018-10-29 02:07:40 +08003031 .. attribute:: ISSUING_DISTRIBUTION_POINT
3032
3033 .. versionadded:: 2.4
3034
3035 Corresponds to the dotted string ``"2.5.29.28"``.
3036
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07003037
Paul Kehrerc6242dc2015-12-25 16:36:46 -06003038.. class:: CRLEntryExtensionOID
3039
3040 .. versionadded:: 1.2
3041
3042 .. attribute:: CERTIFICATE_ISSUER
3043
3044 Corresponds to the dotted string ``"2.5.29.29"``.
3045
3046 .. attribute:: CRL_REASON
3047
3048 Corresponds to the dotted string ``"2.5.29.21"``.
3049
3050 .. attribute:: INVALIDITY_DATE
3051
3052 Corresponds to the dotted string ``"2.5.29.24"``.
3053
Paul Kehrer09403102018-09-09 21:57:21 -05003054
3055.. class:: OCSPExtensionOID
3056
3057 .. versionadded:: 2.4
3058
3059 .. attribute:: NONCE
3060
3061 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.2"``.
3062
Paul Kehrer8b89bcc2016-09-03 11:31:43 -05003063Helper Functions
3064~~~~~~~~~~~~~~~~
3065.. currentmodule:: cryptography.x509
3066
3067.. function:: random_serial_number()
3068
3069 .. versionadded:: 1.6
3070
3071 Generates a random serial number suitable for use when constructing
3072 certificates.
3073
Paul Kehrer912d3fb2015-01-29 11:19:22 -06003074Exceptions
3075~~~~~~~~~~
Paul Kehrere27f6582015-08-10 18:33:38 -05003076.. currentmodule:: cryptography.x509
Paul Kehrer912d3fb2015-01-29 11:19:22 -06003077
Paul Kehrere76cd272014-12-14 19:00:51 -06003078.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10003079
3080 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10003081
Paul Kehrerd5cccf72014-12-15 17:20:33 -06003082 .. attribute:: parsed_version
3083
Paul Kehrerbbffc402014-12-17 13:33:55 -06003084 :type: int
3085
3086 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06003087
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05003088.. class:: DuplicateExtension
3089
3090 This is raised when more than one X.509 extension of the same type is
3091 found within a certificate.
3092
3093 .. attribute:: oid
3094
3095 :type: :class:`ObjectIdentifier`
3096
3097 Returns the OID.
3098
Paul Kehrerfa56a232015-03-17 13:14:03 -05003099.. class:: ExtensionNotFound
3100
3101 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
3102 an extension OID that is not present in the certificate.
3103
3104 .. attribute:: oid
3105
3106 :type: :class:`ObjectIdentifier`
3107
3108 Returns the OID.
3109
Paul Kehrer9089c912015-04-20 22:15:20 -05003110.. class:: UnsupportedGeneralNameType
3111
3112 This is raised when a certificate contains an unsupported general name
3113 type in an extension.
3114
Paul Kehrerbed07352015-04-21 08:31:10 -05003115 .. attribute:: type
3116
Paul Kehrer0a621bf2015-04-22 09:22:56 -05003117 :type: int
3118
3119 The integer value of the unsupported type. The complete list of
3120 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05003121
Paul Kehrer016e08a2014-11-26 09:41:18 -10003122
Paul Kehrerc7c9a432015-04-19 09:20:13 -05003123.. _`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 -05003124.. _`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 -05003125.. _`CABForum Guidelines`: https://cabforum.org/baseline-requirements-documents/