blob: 1ff23b3cbf5e31e73f2b54e482b4277887de9765 [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
g_goessel16f746f2018-10-10 04:13:41 +0200465 An example on how to check if a certificate signature is correct with a method
466 on the public key (this does not mean that the cert should be trusted):
467
468 .. doctest::
469
470 >>> from cryptography.hazmat.primitives.serialization import load_pem_public_key
471 >>> from cryptography.hazmat.primitives.asymmetric import padding
472 >>> issuer_public_key = load_pem_public_key(pem_issuer_public_key, default_backend())
473 >>> cert_to_check = x509.load_pem_x509_certificate(pem_data_to_check, default_backend())
474 >>> issuer_public_key.verify(
475 ... cert_to_check.signature,
476 ... cert_to_check.tbs_certificate_bytes,
477 ... #Depends on the algorithm used to create the certificate
478 ... padding.PKCS1v15(),
479 ... cert_to_check.signature_hash_algorithm,
480 ... )
481
482 An
483 :class:`~cryptography.exceptions.InvalidSignature`
484 exception will be raised if the signature fails to verify.
485
Andre Carona8aded62015-05-19 20:11:57 -0400486 .. method:: public_bytes(encoding)
487
Alex Gaynord0b376b2015-07-05 13:58:12 -0400488 .. versionadded:: 1.0
489
Andre Carona8aded62015-05-19 20:11:57 -0400490 :param encoding: The
491 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
492 that will be used to serialize the certificate.
493
494 :return bytes: The data that can be written to a file or sent
495 over the network to be verified by clients.
496
Erik Trauschke2dcce902015-05-14 16:12:24 -0700497X.509 CRL (Certificate Revocation List) Object
498~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
499
500.. class:: CertificateRevocationList
501
502 .. versionadded:: 1.0
503
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700504 A CertificateRevocationList is an object representing a list of revoked
505 certificates. The object is iterable and will yield the RevokedCertificate
506 objects stored in this CRL.
507
508 .. doctest::
Erik Trauschkeb14f7d12015-10-13 09:55:39 -0700509
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700510 >>> len(crl)
511 1
Paul Kehrerdcdf9672015-10-21 20:27:28 -0500512 >>> revoked_certificate = crl[0]
513 >>> type(revoked_certificate)
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700514 <class 'cryptography.hazmat.backends.openssl.x509._RevokedCertificate'>
515 >>> for r in crl:
516 ... print(r.serial_number)
517 0
518
Erik Trauschke2dcce902015-05-14 16:12:24 -0700519 .. method:: fingerprint(algorithm)
520
521 :param algorithm: The
522 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
523 that will be used to generate the fingerprint.
524
525 :return bytes: The fingerprint using the supplied hash algorithm, as
526 bytes.
527
Erik Trauschkedc570402015-09-24 20:24:28 -0700528 .. doctest::
529
530 >>> from cryptography.hazmat.primitives import hashes
531 >>> crl.fingerprint(hashes.SHA256())
Paul Kehrer056c9dd2018-05-12 15:17:06 -0400532 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 -0700533
Paul Kehrer5d187402018-07-16 20:49:51 +0530534 .. method:: get_revoked_certificate_by_serial_number(serial_number)
535
536 .. versionadded:: 2.3
537
538 :param serial_number: The serial as a Python integer.
539 :returns: :class:`~cryptography.x509.RevokedCertificate` if the
540 ``serial_number`` is present in the CRL or ``None`` if it
541 is not.
542
Erik Trauschke2dcce902015-05-14 16:12:24 -0700543 .. attribute:: signature_hash_algorithm
544
545 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
546
547 Returns the
548 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
549 was used in signing this CRL.
550
Erik Trauschkedc570402015-09-24 20:24:28 -0700551 .. doctest::
552
553 >>> from cryptography.hazmat.primitives import hashes
554 >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256)
555 True
556
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800557 .. attribute:: signature_algorithm_oid
558
559 .. versionadded:: 1.6
560
561 :type: :class:`ObjectIdentifier`
562
563 Returns the :class:`ObjectIdentifier` of the signature algorithm used
564 to sign the CRL. This will be one of the OIDs from
565 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
566
567 .. doctest::
568
569 >>> crl.signature_algorithm_oid
570 <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)>
571
Erik Trauschke2dcce902015-05-14 16:12:24 -0700572 .. attribute:: issuer
573
574 :type: :class:`Name`
575
576 The :class:`Name` of the issuer.
577
Erik Trauschkedc570402015-09-24 20:24:28 -0700578 .. doctest::
579
580 >>> crl.issuer
Paul Kehrer056c9dd2018-05-12 15:17:06 -0400581 <Name([<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')>, <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='cryptography.io')>])>
Erik Trauschkedc570402015-09-24 20:24:28 -0700582
Erik Trauschke2dcce902015-05-14 16:12:24 -0700583 .. attribute:: next_update
584
585 :type: :class:`datetime.datetime`
586
587 A naïve datetime representing when the next update to this CRL is
588 expected.
589
Erik Trauschkedc570402015-09-24 20:24:28 -0700590 .. doctest::
591
592 >>> crl.next_update
593 datetime.datetime(2016, 1, 1, 0, 0)
594
Erik Trauschke2dcce902015-05-14 16:12:24 -0700595 .. attribute:: last_update
596
597 :type: :class:`datetime.datetime`
598
599 A naïve datetime representing when the this CRL was last updated.
600
Erik Trauschkedc570402015-09-24 20:24:28 -0700601 .. doctest::
Erik Trauschke2dcce902015-05-14 16:12:24 -0700602
Erik Trauschkedc570402015-09-24 20:24:28 -0700603 >>> crl.last_update
604 datetime.datetime(2015, 1, 1, 0, 0)
Erik Trauschke2dcce902015-05-14 16:12:24 -0700605
606 .. attribute:: extensions
607
608 :type: :class:`Extensions`
609
610 The extensions encoded in the CRL.
611
Erik Trauschke6abe2bb2015-11-19 10:27:01 -0800612 .. attribute:: signature
613
614 .. versionadded:: 1.2
615
616 :type: bytes
617
618 The bytes of the CRL's signature.
619
620 .. attribute:: tbs_certlist_bytes
621
622 .. versionadded:: 1.2
623
624 :type: bytes
625
626 The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed
627 and then signed by the private key of the CRL's issuer. This data may be
628 used to validate a signature, but use extreme caution as CRL validation
629 is a complex problem that involves much more than just signature checks.
630
Paul Kehrer54a837d2015-12-20 23:42:32 -0600631 .. method:: public_bytes(encoding)
632
633 .. versionadded:: 1.2
634
635 :param encoding: The
636 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
637 that will be used to serialize the certificate revocation list.
638
639 :return bytes: The data that can be written to a file or sent
640 over the network and used as part of a certificate verification
641 process.
642
Vincent Pelletier6c02ee82017-08-12 22:05:00 +0900643 .. method:: is_signature_valid(public_key)
644
645 .. versionadded:: 2.1
646
Paul Kehrerf944c402017-08-12 08:52:55 -0500647 .. warning::
648
649 Checking the validity of the signature on the CRL is insufficient
650 to know if the CRL should be trusted. More details are available
651 in :rfc:`5280`.
652
Vincent Pelletier6c02ee82017-08-12 22:05:00 +0900653 Returns True if the CRL signature is correct for given public key,
654 False otherwise.
Erik Trauschke6abe2bb2015-11-19 10:27:01 -0800655
Andre Caron9bbfcea2015-05-18 20:55:29 -0400656X.509 Certificate Builder
657~~~~~~~~~~~~~~~~~~~~~~~~~
658
659.. class:: CertificateBuilder
660
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500661 .. versionadded:: 1.0
662
663 .. doctest::
664
665 >>> from cryptography import x509
666 >>> from cryptography.hazmat.backends import default_backend
667 >>> from cryptography.hazmat.primitives import hashes
668 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -0500669 >>> from cryptography.x509.oid import NameOID
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500670 >>> import datetime
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500671 >>> one_day = datetime.timedelta(1, 0, 0)
672 >>> private_key = rsa.generate_private_key(
673 ... public_exponent=65537,
674 ... key_size=2048,
675 ... backend=default_backend()
676 ... )
Cory Benfieldc47b2522015-12-07 15:25:12 +0000677 >>> public_key = private_key.public_key()
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500678 >>> builder = x509.CertificateBuilder()
679 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500680 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500681 ... ]))
682 >>> builder = builder.issuer_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500683 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500684 ... ]))
685 >>> builder = builder.not_valid_before(datetime.datetime.today() - one_day)
Alex Gaynorcdd35852018-08-05 18:17:35 -0400686 >>> builder = builder.not_valid_after(datetime.datetime.today() + (one_day * 30))
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500687 >>> builder = builder.serial_number(x509.random_serial_number())
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500688 >>> builder = builder.public_key(public_key)
689 >>> builder = builder.add_extension(
Paul Kehrer1bab7bc2017-01-18 13:44:40 +0800690 ... x509.SubjectAlternativeName(
Paul Kehrered321052017-10-11 08:11:44 +0800691 ... [x509.DNSName(u'cryptography.io')]
Paul Kehrer1bab7bc2017-01-18 13:44:40 +0800692 ... ),
693 ... critical=False
694 ... )
695 >>> builder = builder.add_extension(
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500696 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
697 ... )
698 >>> certificate = builder.sign(
699 ... private_key=private_key, algorithm=hashes.SHA256(),
700 ... backend=default_backend()
701 ... )
702 >>> isinstance(certificate, x509.Certificate)
703 True
704
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500705 .. method:: issuer_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400706
707 Sets the issuer's distinguished name.
708
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500709 :param name: The :class:`~cryptography.x509.Name` that describes the
710 issuer (CA).
Andre Caron9bbfcea2015-05-18 20:55:29 -0400711
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500712 .. method:: subject_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400713
714 Sets the subject's distinguished name.
715
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500716 :param name: The :class:`~cryptography.x509.Name` that describes the
Ian Cordasco85fc4d52015-08-01 20:29:31 -0500717 subject.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400718
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500719 .. method:: public_key(public_key)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400720
721 Sets the subject's public key.
722
Ian Cordasco8f571422015-08-02 11:31:08 -0500723 :param public_key: The subject's public key. This can be one of
724 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`,
725 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
726 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400727
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500728 .. method:: serial_number(serial_number)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400729
730 Sets the certificate's serial number (an integer). The CA's policy
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500731 determines how it attributes serial numbers to certificates. This
732 number must uniquely identify the certificate given the issuer.
733 `CABForum Guidelines`_ require entropy in the serial number
734 to provide protection against hash collision attacks. For more
735 information on secure random number generation, see
736 :doc:`/random-numbers`.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400737
738 :param serial_number: Integer number that will be used by the CA to
739 identify this certificate (most notably during certificate
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500740 revocation checking). Users should consider using
741 :func:`~cryptography.x509.random_serial_number` when possible.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400742
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500743 .. method:: not_valid_before(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400744
745 Sets the certificate's activation time. This is the time from which
746 clients can start trusting the certificate. It may be different from
747 the time at which the certificate was created.
748
Ian Cordasco17c89002015-08-02 21:13:59 -0500749 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400750 activation time for the certificate. The certificate may not be
751 trusted clients if it is used before this time.
752
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500753 .. method:: not_valid_after(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400754
755 Sets the certificate's expiration time. This is the time from which
756 clients should no longer trust the certificate. The CA's policy will
757 determine how long the certificate should remain in use.
758
Ian Cordasco17c89002015-08-02 21:13:59 -0500759 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400760 expiration time for the certificate. The certificate may not be
761 trusted clients if it is used after this time.
762
Ian Cordasco17c89002015-08-02 21:13:59 -0500763 .. method:: add_extension(extension, critical)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400764
765 Adds an X.509 extension to the certificate.
766
Paul Kehrer2c145cc2015-10-02 11:27:21 -0500767 :param extension: An extension conforming to the
768 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400769
Ian Cordasco17c89002015-08-02 21:13:59 -0500770 :param critical: Set to ``True`` if the extension must be understood and
771 handled by whoever reads the certificate.
772
Paul Kehrer9add80e2015-08-03 17:53:14 +0100773 .. method:: sign(private_key, algorithm, backend)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400774
775 Sign the certificate using the CA's private key.
776
Ian Cordascoc5e1c252015-07-31 23:33:35 -0500777 :param private_key: The
778 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
779 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
780 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
781 that will be used to sign the certificate.
782
Andre Caron9bbfcea2015-05-18 20:55:29 -0400783 :param algorithm: The
784 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
785 will be used to generate the signature.
786
Paul Kehrer9add80e2015-08-03 17:53:14 +0100787 :param backend: Backend that will be used to build the certificate.
788 Must support the
789 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
790 interface.
791
Benjamin Peterson9ed312b2015-10-12 20:51:34 -0700792 :returns: :class:`~cryptography.x509.Certificate`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400793
794
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500795X.509 CSR (Certificate Signing Request) Object
796~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600797
Paul Kehrera1a1f232015-03-15 15:34:35 -0500798.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600799
800 .. versionadded:: 0.9
801
802 .. method:: public_key()
803
Alex Gaynor4c2561a2015-10-12 23:53:39 -0400804 The public key associated with the request.
805
806 :returns:
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600807 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
808 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
809 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
810
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600811 .. doctest::
812
813 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500814 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600815 >>> isinstance(public_key, rsa.RSAPublicKey)
816 True
817
818 .. attribute:: subject
819
820 :type: :class:`Name`
821
822 The :class:`Name` of the subject.
823
824 .. attribute:: signature_hash_algorithm
825
826 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
827
828 Returns the
829 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
830 was used in signing this request.
831
832 .. doctest::
833
834 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500835 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600836 True
837
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800838 .. attribute:: signature_algorithm_oid
839
840 .. versionadded:: 1.6
841
842 :type: :class:`ObjectIdentifier`
843
844 Returns the :class:`ObjectIdentifier` of the signature algorithm used
845 to sign the request. This will be one of the OIDs from
846 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
847
848 .. doctest::
849
850 >>> csr.signature_algorithm_oid
851 <ObjectIdentifier(oid=1.2.840.113549.1.1.5, name=sha1WithRSAEncryption)>
852
Paul Kehrerc4e61942015-08-01 21:21:13 +0100853 .. attribute:: extensions
854
855 :type: :class:`Extensions`
856
857 The extensions encoded in the certificate signing request.
858
859 :raises cryptography.x509.DuplicateExtension: If more than one
Paul Kehrer24283d22015-08-01 21:31:19 +0100860 extension of the same type is found within the certificate signing request.
Paul Kehrerc4e61942015-08-01 21:21:13 +0100861
Paul Kehrerc4e61942015-08-01 21:21:13 +0100862 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
863 contains a general name that is not supported.
864
865 :raises UnicodeError: If an extension contains IDNA encoding that is
866 invalid or not compliant with IDNA 2008.
867
868
Andre Caron476c5df2015-05-18 10:23:28 -0400869 .. method:: public_bytes(encoding)
870
Alex Gaynord0b376b2015-07-05 13:58:12 -0400871 .. versionadded:: 1.0
872
Andre Caron476c5df2015-05-18 10:23:28 -0400873 :param encoding: The
874 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
875 that will be used to serialize the certificate request.
876
877 :return bytes: The data that can be written to a file or sent
878 over the network to be signed by the certificate
879 authority.
880
Paul Kehrerab209392015-12-01 14:50:31 -0600881 .. attribute:: signature
882
883 .. versionadded:: 1.2
884
885 :type: bytes
886
887 The bytes of the certificate signing request's signature.
888
889 .. attribute:: tbs_certrequest_bytes
890
891 .. versionadded:: 1.2
892
893 :type: bytes
894
895 The DER encoded bytes payload (as defined by :rfc:`2986`) that is
896 hashed and then signed by the private key (corresponding to the public
897 key embedded in the CSR). This data may be used to validate the CSR
898 signature.
899
Joern Heisslerfbda8ce2016-01-18 00:24:44 +0100900 .. attribute:: is_signature_valid
Joern Heissler1bd77e22016-01-13 22:51:37 +0100901
902 .. versionadded:: 1.3
903
Joern Heisslerfbda8ce2016-01-18 00:24:44 +0100904 Returns True if the CSR signature is correct, False otherwise.
Joern Heissler1bd77e22016-01-13 22:51:37 +0100905
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600906X.509 Certificate Revocation List Builder
907~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
908
909.. class:: CertificateRevocationListBuilder
910
911 .. versionadded:: 1.2
912
913 .. doctest::
914
915 >>> from cryptography import x509
916 >>> from cryptography.hazmat.backends import default_backend
917 >>> from cryptography.hazmat.primitives import hashes
918 >>> from cryptography.hazmat.primitives.asymmetric import rsa
919 >>> from cryptography.x509.oid import NameOID
920 >>> import datetime
921 >>> one_day = datetime.timedelta(1, 0, 0)
922 >>> private_key = rsa.generate_private_key(
923 ... public_exponent=65537,
924 ... key_size=2048,
925 ... backend=default_backend()
926 ... )
927 >>> builder = x509.CertificateRevocationListBuilder()
928 >>> builder = builder.issuer_name(x509.Name([
929 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io CA'),
930 ... ]))
931 >>> builder = builder.last_update(datetime.datetime.today())
932 >>> builder = builder.next_update(datetime.datetime.today() + one_day)
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600933 >>> revoked_cert = x509.RevokedCertificateBuilder().serial_number(
934 ... 333
935 ... ).revocation_date(
936 ... datetime.datetime.today()
937 ... ).build(default_backend())
938 >>> builder = builder.add_revoked_certificate(revoked_cert)
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600939 >>> crl = builder.sign(
940 ... private_key=private_key, algorithm=hashes.SHA256(),
941 ... backend=default_backend()
942 ... )
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600943 >>> len(crl)
944 1
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600945
946 .. method:: issuer_name(name)
947
948 Sets the issuer's distinguished name.
949
950 :param name: The :class:`~cryptography.x509.Name` that describes the
951 issuer (CA).
952
953 .. method:: last_update(time)
954
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600955 Sets this CRL's activation time. This is the time from which
956 clients can start trusting this CRL. It may be different from
957 the time at which this CRL was created. This is also known as the
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600958 ``thisUpdate`` time.
959
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600960 :param time: The :class:`datetime.datetime` object (in UTC) that marks
961 the activation time for this CRL. The CRL may not be trusted if it
962 is used before this time.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600963
964 .. method:: next_update(time)
965
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600966 Sets this CRL's next update time. This is the time by which
967 a new CRL will be issued. The CA is allowed to issue a new CRL before
968 this date, however clients are not required to check for it.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600969
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600970 :param time: The :class:`datetime.datetime` object (in UTC) that marks
971 the next update time for this CRL.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600972
Paul Kehrer426b48d2015-12-24 20:50:43 -0600973 .. method:: add_extension(extension, critical)
974
975 Adds an X.509 extension to this CRL.
976
977 :param extension: An extension with the
978 :class:`~cryptography.x509.ExtensionType` interface.
979
980 :param critical: Set to ``True`` if the extension must be understood and
981 handled by whoever reads the CRL.
982
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600983 .. method:: add_revoked_certificate(revoked_certificate)
984
985 Adds a revoked certificate to this CRL.
986
987 :param revoked_certificate: An instance of
988 :class:`~cryptography.x509.RevokedCertificate`. These can be
989 obtained from an existing CRL or created with
990 :class:`~cryptography.x509.RevokedCertificateBuilder`.
991
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600992 .. method:: sign(private_key, algorithm, backend)
993
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600994 Sign this CRL using the CA's private key.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600995
996 :param private_key: The
997 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
998 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
999 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
1000 that will be used to sign the certificate.
1001
1002 :param algorithm: The
1003 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
1004 will be used to generate the signature.
1005
1006 :param backend: Backend that will be used to build the CRL.
1007 Must support the
1008 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1009 interface.
1010
1011 :returns: :class:`~cryptography.x509.CertificateRevocationList`
1012
Erik Trauschke2dcce902015-05-14 16:12:24 -07001013X.509 Revoked Certificate Object
Erik Trauschkec5a8d172015-05-28 10:24:25 -07001014~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Erik Trauschke2dcce902015-05-14 16:12:24 -07001015
1016.. class:: RevokedCertificate
1017
1018 .. versionadded:: 1.0
1019
1020 .. attribute:: serial_number
1021
1022 :type: :class:`int`
1023
1024 An integer representing the serial number of the revoked certificate.
1025
Erik Trauschkedc570402015-09-24 20:24:28 -07001026 .. doctest::
1027
Erik Trauschke3cdabaf2015-10-13 09:42:53 -07001028 >>> revoked_certificate.serial_number
Erik Trauschkedc570402015-09-24 20:24:28 -07001029 0
1030
Erik Trauschke2dcce902015-05-14 16:12:24 -07001031 .. attribute:: revocation_date
1032
1033 :type: :class:`datetime.datetime`
1034
1035 A naïve datetime representing the date this certificates was revoked.
1036
Erik Trauschkedc570402015-09-24 20:24:28 -07001037 .. doctest::
1038
Erik Trauschke77f5a252015-10-14 08:06:38 -07001039 >>> revoked_certificate.revocation_date
Erik Trauschkedc570402015-09-24 20:24:28 -07001040 datetime.datetime(2015, 1, 1, 0, 0)
1041
Erik Trauschke2dcce902015-05-14 16:12:24 -07001042 .. attribute:: extensions
1043
1044 :type: :class:`Extensions`
1045
1046 The extensions encoded in the revoked certificate.
Andre Caron476c5df2015-05-18 10:23:28 -04001047
Erik Trauschkedc570402015-09-24 20:24:28 -07001048 .. doctest::
1049
Erik Trauschke77f5a252015-10-14 08:06:38 -07001050 >>> for ext in revoked_certificate.extensions:
Erik Trauschkedc570402015-09-24 20:24:28 -07001051 ... print(ext)
Paul Kehrer23c0bbc2015-12-25 22:35:19 -06001052 <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 -06001053 <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 -07001054
Paul Kehrerc33ffd72015-12-25 10:59:22 -06001055X.509 Revoked Certificate Builder
1056~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1057
1058.. class:: RevokedCertificateBuilder
1059
1060 This class is used to create :class:`~cryptography.x509.RevokedCertificate`
1061 objects that can be used with the
1062 :class:`~cryptography.x509.CertificateRevocationListBuilder`.
1063
1064 .. versionadded:: 1.2
1065
1066 .. doctest::
1067
1068 >>> from cryptography import x509
1069 >>> from cryptography.hazmat.backends import default_backend
1070 >>> import datetime
1071 >>> builder = x509.RevokedCertificateBuilder()
1072 >>> builder = builder.revocation_date(datetime.datetime.today())
1073 >>> builder = builder.serial_number(3333)
1074 >>> revoked_certificate = builder.build(default_backend())
1075 >>> isinstance(revoked_certificate, x509.RevokedCertificate)
1076 True
1077
1078 .. method:: serial_number(serial_number)
1079
1080 Sets the revoked certificate's serial number.
1081
1082 :param serial_number: Integer number that is used to identify the
1083 revoked certificate.
1084
1085 .. method:: revocation_date(time)
1086
1087 Sets the certificate's revocation date.
1088
1089 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
1090 revocation time for the certificate.
1091
Paul Kehrere5f152b2015-12-25 23:55:47 -06001092 .. method:: add_extension(extension, critical)
1093
1094 Adds an X.509 extension to this revoked certificate.
1095
1096 :param extension: An instance of one of the
1097 :ref:`CRL entry extensions <crl_entry_extensions>`.
1098
1099 :param critical: Set to ``True`` if the extension must be understood and
1100 handled.
1101
Paul Kehrerc33ffd72015-12-25 10:59:22 -06001102 .. method:: build(backend)
1103
1104 Create a revoked certificate object using the provided backend.
1105
1106 :param backend: Backend that will be used to build the revoked
1107 certificate. Must support the
1108 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1109 interface.
1110
1111 :returns: :class:`~cryptography.x509.RevokedCertificate`
1112
Andre Caron0ef595f2015-05-18 13:53:43 -04001113X.509 CSR (Certificate Signing Request) Builder Object
1114~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1115
1116.. class:: CertificateSigningRequestBuilder
1117
Andre Carond259ee52015-06-02 23:47:11 -04001118 .. versionadded:: 1.0
1119
1120 .. doctest::
1121
1122 >>> from cryptography import x509
1123 >>> from cryptography.hazmat.backends import default_backend
1124 >>> from cryptography.hazmat.primitives import hashes
1125 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -05001126 >>> from cryptography.x509.oid import NameOID
Andre Carond259ee52015-06-02 23:47:11 -04001127 >>> private_key = rsa.generate_private_key(
1128 ... public_exponent=65537,
1129 ... key_size=2048,
1130 ... backend=default_backend()
1131 ... )
1132 >>> builder = x509.CertificateSigningRequestBuilder()
Andre Carona9a51172015-06-06 20:18:44 -04001133 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -05001134 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Andre Carond259ee52015-06-02 23:47:11 -04001135 ... ]))
Ian Cordascof06b6be2015-06-21 10:09:18 -05001136 >>> builder = builder.add_extension(
Ian Cordasco0112b022015-06-16 17:51:18 -05001137 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
Andre Caron472fd692015-06-06 20:04:44 -04001138 ... )
Andre Carond259ee52015-06-02 23:47:11 -04001139 >>> request = builder.sign(
Alex Gaynorde9e5842015-06-26 20:11:23 -04001140 ... private_key, hashes.SHA256(), default_backend()
Andre Carond259ee52015-06-02 23:47:11 -04001141 ... )
1142 >>> isinstance(request, x509.CertificateSigningRequest)
1143 True
1144
Andre Carona9a51172015-06-06 20:18:44 -04001145 .. method:: subject_name(name)
Andre Caron0ef595f2015-05-18 13:53:43 -04001146
Andre Caron341ff852015-06-06 20:14:31 -04001147 :param name: The :class:`~cryptography.x509.Name` of the certificate
1148 subject.
1149 :returns: A new
1150 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001151
Ian Cordascof06b6be2015-06-21 10:09:18 -05001152 .. method:: add_extension(extension, critical)
Andre Caron0ef595f2015-05-18 13:53:43 -04001153
Paul Kehrer2c145cc2015-10-02 11:27:21 -05001154 :param extension: An extension conforming to the
1155 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron472fd692015-06-06 20:04:44 -04001156 :param critical: Set to `True` if the extension must be understood and
1157 handled by whoever reads the certificate.
Andre Caron341ff852015-06-06 20:14:31 -04001158 :returns: A new
1159 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001160
Alex Gaynorb3b0fbe2015-06-26 19:57:18 -04001161 .. method:: sign(private_key, algorithm, backend)
Andre Caron0ef595f2015-05-18 13:53:43 -04001162
1163 :param backend: Backend that will be used to sign the request.
1164 Must support the
1165 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1166 interface.
1167
1168 :param private_key: The
Andre Caron24f9bf42015-06-06 20:14:54 -04001169 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
1170 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
1171 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
Andre Caron0ef595f2015-05-18 13:53:43 -04001172 that will be used to sign the request. When the request is
1173 signed by a certificate authority, the private key's associated
1174 public key will be stored in the resulting certificate.
1175
1176 :param algorithm: The
1177 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
1178 that will be used to generate the request signature.
1179
Andre Caron341ff852015-06-06 20:14:31 -04001180 :returns: A new
1181 :class:`~cryptography.x509.CertificateSigningRequest`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001182
1183
Paul Kehrer719d5362015-01-01 20:03:52 -06001184.. class:: Name
1185
1186 .. versionadded:: 0.8
1187
Paul Kehrer53d8d492015-02-13 18:47:30 -06001188 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -06001189 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -06001190 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -06001191 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
1192 ``CN=mydomain.com, O=My Org, C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -06001193
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001194 Technically, a Name is a list of *sets* of attributes, called *Relative
1195 Distinguished Names* or *RDNs*, although multi-valued RDNs are rarely
1196 encountered. The iteration order of values within a multi-valued RDN is
Marti Raudsepp9e1873a2018-07-09 16:11:18 +03001197 preserved. If you need to handle multi-valued RDNs, the ``rdns`` property
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001198 gives access to an ordered list of :class:`RelativeDistinguishedName`
1199 objects.
1200
1201 A Name can be initialized with an iterable of :class:`NameAttribute` (the
1202 common case where each RDN has a single attribute) or an iterable of
1203 :class:`RelativeDistinguishedName` objects (in the rare case of
1204 multi-valued RDNs).
1205
Paul Kehrer53d8d492015-02-13 18:47:30 -06001206 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -06001207
Paul Kehrer8b21a4a2015-02-14 07:56:36 -06001208 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -06001209 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -06001210 >>> for attribute in cert.subject:
1211 ... print(attribute)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001212 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')>
1213 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value='Test Certificates 2011')>
1214 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -06001215
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001216 .. attribute:: rdns
1217
1218 .. versionadded:: 1.6
1219
1220 :type: list of :class:`RelativeDistinguishedName`
1221
Paul Kehrere901d642015-02-11 18:50:58 -06001222 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -06001223
Paul Kehrere901d642015-02-11 18:50:58 -06001224 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -06001225
Paul Kehrere901d642015-02-11 18:50:58 -06001226 :returns: A list of :class:`NameAttribute` instances that match the
1227 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -06001228
1229 .. doctest::
1230
Paul Kehrere27f6582015-08-10 18:33:38 -05001231 >>> cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001232 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -06001233
Paul Kehrer3a15b032016-11-13 14:30:11 -08001234 .. method:: public_bytes(backend)
1235
1236 .. versionadded:: 1.6
1237
1238 :param backend: A backend supporting the
1239 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1240 interface.
1241
1242 :return bytes: The DER encoded name.
1243
Paul Kehrere76cd272014-12-14 19:00:51 -06001244.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -10001245
1246 .. versionadded:: 0.7
1247
1248 An enumeration for X.509 versions.
1249
1250 .. attribute:: v1
1251
1252 For version 1 X.509 certificates.
1253
1254 .. attribute:: v3
1255
1256 For version 3 X.509 certificates.
1257
Paul Kehrer806bfb22015-02-02 17:05:24 -06001258.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001259
1260 .. versionadded:: 0.8
1261
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001262 An X.509 name consists of a list of :class:`RelativeDistinguishedName`
1263 instances, which consist of a set of :class:`NameAttribute` instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001264
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001265 .. attribute:: oid
1266
1267 :type: :class:`ObjectIdentifier`
1268
1269 The attribute OID.
1270
1271 .. attribute:: value
1272
Paul Kehrerd5852cb2015-01-30 08:25:23 -06001273 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001274
1275 The value of the attribute.
1276
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001277
1278.. class:: RelativeDistinguishedName(attributes)
1279
1280 .. versionadded:: 1.6
1281
1282 A relative distinguished name is a non-empty set of name attributes. The
Marti Raudsepp9e1873a2018-07-09 16:11:18 +03001283 object is iterable to get every attribute, preserving the original order.
1284 Passing duplicate attributes to the constructor raises ``ValueError``.
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001285
1286 .. method:: get_attributes_for_oid(oid)
1287
1288 :param oid: An :class:`ObjectIdentifier` instance.
1289
1290 :returns: A list of :class:`NameAttribute` instances that match the OID
1291 provided. The list should contain zero or one values.
1292
1293
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001294.. class:: ObjectIdentifier
1295
1296 .. versionadded:: 0.8
1297
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001298 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -06001299 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001300
Paul Kehrerd44f9a62015-02-04 14:47:34 -06001301 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001302
1303 :type: :class:`str`
1304
Paul Kehrerfedf4f42015-02-06 11:22:07 -06001305 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001306
Paul Kehrer31bdf792015-03-25 14:11:00 -05001307.. _general_name_classes:
1308
1309General Name Classes
1310~~~~~~~~~~~~~~~~~~~~
1311
1312.. class:: GeneralName
1313
1314 .. versionadded:: 0.9
1315
1316 This is the generic interface that all the following classes are registered
1317 against.
1318
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001319.. class:: RFC822Name(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001320
1321 .. versionadded:: 0.9
1322
Paul Kehrere885bd62017-10-11 20:29:23 +08001323 .. versionchanged:: 2.1
Paul Kehrer3e15ca52017-08-01 21:21:19 -05001324
Paul Kehrere885bd62017-10-11 20:29:23 +08001325 .. warning::
1326
1327 Starting with version 2.1 :term:`U-label` input is deprecated. If
1328 passing an internationalized domain name (IDN) you should first IDNA
1329 encode the value and then pass the result as a string. Accessing
1330 ``value`` will return the :term:`A-label` encoded form even if you pass
1331 a U-label. This breaks backwards compatibility, but only for
1332 internationalized domain names.
1333
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001334
1335 This corresponds to an email address. For example, ``user@example.com``.
1336
Paul Kehrere885bd62017-10-11 20:29:23 +08001337 :param value: The email address. If the address contains an
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001338 internationalized domain name then it must be encoded to an
Paul Kehrere885bd62017-10-11 20:29:23 +08001339 :term:`A-label` string before being passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001340
Paul Kehrer31bdf792015-03-25 14:11:00 -05001341 .. attribute:: value
1342
1343 :type: :term:`text`
1344
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001345.. class:: DNSName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001346
1347 .. versionadded:: 0.9
1348
Paul Kehrere885bd62017-10-11 20:29:23 +08001349 .. versionchanged:: 2.1
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001350
Paul Kehrere885bd62017-10-11 20:29:23 +08001351 .. warning::
1352
1353 Starting with version 2.1 :term:`U-label` input is deprecated. If
1354 passing an internationalized domain name (IDN) you should first IDNA
1355 encode the value and then pass the result as a string. Accessing
1356 ``value`` will return the :term:`A-label` encoded form even if you pass
1357 a U-label. This breaks backwards compatibility, but only for
1358 internationalized domain names.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001359
Paul Kehrer31bdf792015-03-25 14:11:00 -05001360 This corresponds to a domain name. For example, ``cryptography.io``.
1361
Paul Kehrere885bd62017-10-11 20:29:23 +08001362 :param value: The domain name. If it is an internationalized domain
1363 name then it must be encoded to an :term:`A-label` string before being
1364 passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001365
Paul Kehrere885bd62017-10-11 20:29:23 +08001366 :type: :term:`text`
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001367
Paul Kehrer31bdf792015-03-25 14:11:00 -05001368 .. attribute:: value
1369
1370 :type: :term:`text`
1371
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001372.. class:: DirectoryName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001373
1374 .. versionadded:: 0.9
1375
1376 This corresponds to a directory name.
1377
1378 .. attribute:: value
1379
1380 :type: :class:`Name`
1381
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001382.. class:: UniformResourceIdentifier(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001383
1384 .. versionadded:: 0.9
1385
Paul Kehrere885bd62017-10-11 20:29:23 +08001386 .. versionchanged:: 2.1
Paul Kehrerb8ef82e2015-04-22 16:04:24 -05001387
Paul Kehrere885bd62017-10-11 20:29:23 +08001388 .. warning::
1389
1390 Starting with version 2.1 :term:`U-label` input is deprecated. If
1391 passing an internationalized domain name (IDN) you should first IDNA
1392 encode the value and then pass the result as a string. Accessing
1393 ``value`` will return the :term:`A-label` encoded form even if you pass
1394 a U-label. This breaks backwards compatibility, but only for
1395 internationalized domain names.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001396
1397 This corresponds to a uniform resource identifier. For example,
1398 ``https://cryptography.io``.
1399
Paul Kehrere885bd62017-10-11 20:29:23 +08001400 :param value: The URI. If it contains an internationalized domain
1401 name then it must be encoded to an :term:`A-label` string before
1402 being passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001403
Paul Kehrer31bdf792015-03-25 14:11:00 -05001404 .. attribute:: value
1405
1406 :type: :term:`text`
1407
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001408.. class:: IPAddress(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001409
1410 .. versionadded:: 0.9
1411
1412 This corresponds to an IP address.
1413
1414 .. attribute:: value
1415
Paul Kehrereb177932015-05-17 18:33:33 -07001416 :type: :class:`~ipaddress.IPv4Address`,
1417 :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
1418 or :class:`~ipaddress.IPv6Network`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001419
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001420.. class:: RegisteredID(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001421
1422 .. versionadded:: 0.9
1423
1424 This corresponds to a registered ID.
1425
1426 .. attribute:: value
1427
1428 :type: :class:`ObjectIdentifier`
1429
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001430.. class:: OtherName(type_id, value)
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001431
1432 .. versionadded:: 1.0
1433
Joshua Tauberer18b6fc82015-07-05 21:44:51 +00001434 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 +00001435
1436 .. attribute:: type_id
1437
1438 :type: :class:`ObjectIdentifier`
1439
1440 .. attribute:: value
1441
Paul Kehreredfedc12018-09-14 18:24:20 -04001442 :type: bytes
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001443
Paul Kehrer8cf26422015-03-21 09:50:24 -05001444X.509 Extensions
1445~~~~~~~~~~~~~~~~
1446
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001447.. class:: Extensions
1448
1449 .. versionadded:: 0.9
1450
1451 An X.509 Extensions instance is an ordered list of extensions. The object
1452 is iterable to get every extension.
1453
Paul Kehrerfa56a232015-03-17 13:14:03 -05001454 .. method:: get_extension_for_oid(oid)
1455
1456 :param oid: An :class:`ObjectIdentifier` instance.
1457
1458 :returns: An instance of the extension class.
1459
1460 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1461 not have the extension requested.
1462
Paul Kehrerfa56a232015-03-17 13:14:03 -05001463 .. doctest::
1464
Paul Kehrere27f6582015-08-10 18:33:38 -05001465 >>> from cryptography.x509.oid import ExtensionOID
1466 >>> cert.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS)
Paul Kehrerfa56a232015-03-17 13:14:03 -05001467 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1468
Phoebe Queen019b7f82015-08-12 03:52:03 +01001469 .. method:: get_extension_for_class(extclass)
1470
Phoebe Queen6a603eb2015-08-12 14:14:49 +01001471 .. versionadded:: 1.1
1472
Phoebe Queen019b7f82015-08-12 03:52:03 +01001473 :param extclass: An extension class.
1474
1475 :returns: An instance of the extension class.
1476
1477 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1478 not have the extension requested.
1479
1480 .. doctest::
1481
1482 >>> from cryptography import x509
1483 >>> cert.extensions.get_extension_for_class(x509.BasicConstraints)
1484 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1485
Paul Kehrer8cf26422015-03-21 09:50:24 -05001486.. class:: Extension
1487
1488 .. versionadded:: 0.9
1489
Paul Kehrer85894662015-03-22 13:19:31 -05001490 .. attribute:: oid
1491
1492 :type: :class:`ObjectIdentifier`
1493
Paul Kehrere27f6582015-08-10 18:33:38 -05001494 One of the :class:`~cryptography.x509.oid.ExtensionOID` OIDs.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001495
1496 .. attribute:: critical
1497
1498 :type: bool
1499
Paul Kehrer58b75692015-03-22 23:24:58 -05001500 Determines whether a given extension is critical or not. :rfc:`5280`
1501 requires that "A certificate-using system MUST reject the certificate
1502 if it encounters a critical extension it does not recognize or a
1503 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -05001504
Paul Kehrer85894662015-03-22 13:19:31 -05001505 .. attribute:: value
1506
1507 Returns an instance of the extension type corresponding to the OID.
1508
Paul Kehrer14f0bd02015-08-06 11:55:18 +01001509.. class:: ExtensionType
1510
1511 .. versionadded:: 1.0
1512
1513 This is the interface against which all the following extension types are
1514 registered.
1515
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001516.. 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 -05001517
1518 .. versionadded:: 0.9
1519
1520 The key usage extension defines the purpose of the key contained in the
1521 certificate. The usage restriction might be employed when a key that could
Paul Kehrerb33de932015-08-06 23:41:05 +01001522 be used for more than one operation is to be restricted.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001523
Paul Kehrer822f3d32015-08-06 11:47:32 +01001524 .. attribute:: oid
1525
1526 .. versionadded:: 1.0
1527
1528 :type: :class:`ObjectIdentifier`
1529
Paul Kehrere27f6582015-08-10 18:33:38 -05001530 Returns :attr:`~cryptography.x509.oid.ExtensionOID.KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001531
Paul Kehrercecbbba2015-03-30 14:58:38 -05001532 .. attribute:: digital_signature
1533
1534 :type: bool
1535
Paul Kehrer738407b2015-04-01 22:39:02 -05001536 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001537 digital signatures, other than signatures on certificates
1538 (``key_cert_sign``) and CRLs (``crl_sign``).
1539
1540 .. attribute:: content_commitment
1541
1542 :type: bool
1543
Paul Kehrer738407b2015-04-01 22:39:02 -05001544 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001545 digital signatures, other than signatures on certificates
1546 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
1547 non-repudiation service that protects against the signing entity
1548 falsely denying some action. In the case of later conflict, a
1549 reliable third party may determine the authenticity of the signed
1550 data. This was called ``non_repudiation`` in older revisions of the
1551 X.509 specification.
1552
1553 .. attribute:: key_encipherment
1554
1555 :type: bool
1556
Paul Kehrer738407b2015-04-01 22:39:02 -05001557 This purpose is set to true when the subject public key is used for
1558 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001559
1560 .. attribute:: data_encipherment
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
1565 directly enciphering raw user data without the use of an intermediate
1566 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001567
1568 .. attribute:: key_agreement
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 key
1573 agreement. For example, when a Diffie-Hellman key is to be used for
1574 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001575
1576 .. attribute:: key_cert_sign
1577
1578 :type: bool
1579
Paul Kehrer738407b2015-04-01 22:39:02 -05001580 This purpose is set to true when the subject public key is used for
1581 verifying signatures on public key certificates. If this purpose is set
1582 to true then ``ca`` must be true in the :class:`BasicConstraints`
1583 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001584
1585 .. attribute:: crl_sign
1586
1587 :type: bool
1588
Paul Kehrer738407b2015-04-01 22:39:02 -05001589 This purpose is set to true when the subject public key is used for
1590 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001591
1592 .. attribute:: encipher_only
1593
1594 :type: bool
1595
Paul Kehrer738407b2015-04-01 22:39:02 -05001596 When this purposes is set to true and the ``key_agreement`` purpose is
1597 also set, the subject public key may be used only for enciphering data
1598 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001599
1600 :raises ValueError: This is raised if accessed when ``key_agreement``
1601 is false.
1602
1603 .. attribute:: decipher_only
1604
1605 :type: bool
1606
Paul Kehrer738407b2015-04-01 22:39:02 -05001607 When this purposes is set to true and the ``key_agreement`` purpose is
1608 also set, the subject public key may be used only for deciphering data
1609 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001610
1611 :raises ValueError: This is raised if accessed when ``key_agreement``
1612 is false.
1613
1614
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001615.. class:: BasicConstraints(ca, path_length)
Paul Kehrer8cf26422015-03-21 09:50:24 -05001616
1617 .. versionadded:: 0.9
1618
Paul Kehrer85894662015-03-22 13:19:31 -05001619 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -05001620 certificate is allowed to sign additional certificates and what path
Paul Kehrerb33de932015-08-06 23:41:05 +01001621 length restrictions may exist.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001622
Paul Kehrer822f3d32015-08-06 11:47:32 +01001623 .. attribute:: oid
1624
1625 .. versionadded:: 1.0
1626
1627 :type: :class:`ObjectIdentifier`
1628
Paul Kehrere27f6582015-08-10 18:33:38 -05001629 Returns :attr:`~cryptography.x509.oid.ExtensionOID.BASIC_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001630
Paul Kehrer8cf26422015-03-21 09:50:24 -05001631 .. attribute:: ca
1632
1633 :type: bool
1634
1635 Whether the certificate can sign certificates.
1636
1637 .. attribute:: path_length
1638
Paul Kehrerfd1444c2015-03-21 19:47:05 -05001639 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -05001640
1641 The maximum path length for certificates subordinate to this
1642 certificate. This attribute only has meaning if ``ca`` is true.
1643 If ``ca`` is true then a path length of None means there's no
1644 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -04001645 If it is zero or greater then it defines the maximum length for a
1646 subordinate CA's certificate chain. For example, a ``path_length`` of 1
1647 means the certificate can sign a subordinate CA, but the subordinate CA
1648 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001649
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001650.. class:: ExtendedKeyUsage(usages)
Paul Kehrerffa2a152015-03-31 08:18:25 -05001651
1652 .. versionadded:: 0.9
1653
1654 This extension indicates one or more purposes for which the certified
1655 public key may be used, in addition to or in place of the basic
1656 purposes indicated in the key usage extension. The object is
Paul Kehrere27f6582015-08-10 18:33:38 -05001657 iterable to obtain the list of
1658 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs present.
Paul Kehrerffa2a152015-03-31 08:18:25 -05001659
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001660 :param list usages: A list of
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001661 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs.
1662
Paul Kehrer822f3d32015-08-06 11:47:32 +01001663 .. attribute:: oid
1664
1665 .. versionadded:: 1.0
1666
1667 :type: :class:`ObjectIdentifier`
1668
Paul Kehrere27f6582015-08-10 18:33:38 -05001669 Returns :attr:`~cryptography.x509.oid.ExtensionOID.EXTENDED_KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001670
1671
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001672.. class:: OCSPNoCheck()
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001673
Paul Kehrer506a2152015-05-26 08:01:18 -05001674 .. versionadded:: 1.0
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001675
1676 This presence of this extension indicates that an OCSP client can trust a
1677 responder for the lifetime of the responder's certificate. CAs issuing
1678 such a certificate should realize that a compromise of the responder's key
1679 is as serious as the compromise of a CA key used to sign CRLs, at least for
1680 the validity period of this certificate. CA's may choose to issue this type
1681 of certificate with a very short lifetime and renew it frequently. This
1682 extension is only relevant when the certificate is an authorized OCSP
1683 responder.
1684
Paul Kehrer822f3d32015-08-06 11:47:32 +01001685 .. attribute:: oid
1686
1687 .. versionadded:: 1.0
1688
1689 :type: :class:`ObjectIdentifier`
1690
Paul Kehrere27f6582015-08-10 18:33:38 -05001691 Returns :attr:`~cryptography.x509.oid.ExtensionOID.OCSP_NO_CHECK`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001692
Paul Kehrer5d669662017-09-11 09:16:34 +08001693
1694.. class:: TLSFeature(features)
1695
1696 .. versionadded:: 2.1
1697
1698 The TLS Feature extension is defined in :rfc:`7633` and is used in
1699 certificates for OCSP Must-Staple. The object is iterable to get every
1700 element.
1701
1702 :param list features: A list of features to enable from the
1703 :class:`~cryptography.x509.TLSFeatureType` enum. At this time only
1704 ``status_request`` or ``status_request_v2`` are allowed.
1705
1706 .. attribute:: oid
1707
1708 :type: :class:`ObjectIdentifier`
1709
1710 Returns :attr:`~cryptography.x509.oid.ExtensionOID.TLS_FEATURE`.
1711
1712.. class:: TLSFeatureType
1713
1714 .. versionadded:: 2.1
1715
1716 An enumeration of TLS Feature types.
1717
1718 .. attribute:: status_request
1719
1720 This feature type is defined in :rfc:`6066` and, when embedded in
1721 an X.509 certificate, signals to the client that it should require
1722 a stapled OCSP response in the TLS handshake. Commonly known as OCSP
1723 Must-Staple in certificates.
1724
1725 .. attribute:: status_request_v2
1726
1727 This feature type is defined in :rfc:`6961`. This value is not
1728 commonly used and if you want to enable OCSP Must-Staple you should
1729 use ``status_request``.
1730
1731
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001732.. class:: NameConstraints(permitted_subtrees, excluded_subtrees)
Paul Kehrere0017be2015-05-17 20:39:40 -06001733
1734 .. versionadded:: 1.0
1735
1736 The name constraints extension, which only has meaning in a CA certificate,
1737 defines a name space within which all subject names in certificates issued
1738 beneath the CA certificate must (or must not) be in. For specific details
1739 on the way this extension should be processed see :rfc:`5280`.
1740
Paul Kehrer822f3d32015-08-06 11:47:32 +01001741 .. attribute:: oid
1742
1743 .. versionadded:: 1.0
1744
1745 :type: :class:`ObjectIdentifier`
1746
Paul Kehrere27f6582015-08-10 18:33:38 -05001747 Returns :attr:`~cryptography.x509.oid.ExtensionOID.NAME_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001748
Paul Kehrere0017be2015-05-17 20:39:40 -06001749 .. attribute:: permitted_subtrees
1750
1751 :type: list of :class:`GeneralName` objects or None
1752
1753 The set of permitted name patterns. If a name matches this and an
1754 element in ``excluded_subtrees`` it is invalid. At least one of
1755 ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None.
1756
1757 .. attribute:: excluded_subtrees
1758
1759 :type: list of :class:`GeneralName` objects or None
1760
1761 Any name matching a restriction in the ``excluded_subtrees`` field is
1762 invalid regardless of information appearing in the
1763 ``permitted_subtrees``. At least one of ``permitted_subtrees`` and
1764 ``excluded_subtrees`` will be non-None.
1765
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001766.. class:: AuthorityKeyIdentifier(key_identifier, authority_cert_issuer, authority_cert_serial_number)
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001767
1768 .. versionadded:: 0.9
1769
1770 The authority key identifier extension provides a means of identifying the
1771 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001772 This extension is typically used to assist in determining the appropriate
1773 certificate chain. For more information about generation and use of this
1774 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001775
Paul Kehrer822f3d32015-08-06 11:47:32 +01001776 .. attribute:: oid
1777
1778 .. versionadded:: 1.0
1779
1780 :type: :class:`ObjectIdentifier`
1781
Paul Kehrere27f6582015-08-10 18:33:38 -05001782 Returns
1783 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001784
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001785 .. attribute:: key_identifier
1786
1787 :type: bytes
1788
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001789 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001790 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001791
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001792 .. attribute:: authority_cert_issuer
1793
Thom Dixon488c0482018-05-18 03:55:29 -07001794 :type: A list of :class:`GeneralName` instances or None
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001795
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001796 The :class:`Name` of the issuer's issuer.
1797
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001798 .. attribute:: authority_cert_serial_number
1799
1800 :type: int or None
1801
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001802 The serial number of the issuer's issuer.
1803
Paul Kehrer253929a2015-08-05 17:30:39 +01001804 .. classmethod:: from_issuer_public_key(public_key)
1805
1806 .. versionadded:: 1.0
1807
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001808 .. note::
1809
1810 This method should be used if the issuer certificate does not
1811 contain a :class:`~cryptography.x509.SubjectKeyIdentifier`.
1812 Otherwise, use
1813 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier`.
1814
Paul Kehrer253929a2015-08-05 17:30:39 +01001815 Creates a new AuthorityKeyIdentifier instance using the public key
1816 provided to generate the appropriate digest. This should be the
Paul Kehrer26ac47f2015-08-08 15:20:52 -05001817 **issuer's public key**. The resulting object will contain
1818 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1819 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1820 and
1821 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1822 will be None.
1823 The generated ``key_identifier`` is the SHA1 hash of the ``subjectPublicKey``
1824 ASN.1 bit string. This is the first recommendation in :rfc:`5280`
Paul Kehrer253929a2015-08-05 17:30:39 +01001825 section 4.2.1.2.
1826
Paul Kehrercc671822015-08-08 15:41:54 -05001827 :param public_key: One of
1828 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1829 ,
1830 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1831 , or
1832 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
Paul Kehrer253929a2015-08-05 17:30:39 +01001833
1834 .. doctest::
1835
1836 >>> from cryptography import x509
1837 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001838 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1839 >>> x509.AuthorityKeyIdentifier.from_issuer_public_key(issuer_cert.public_key())
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001840 <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 +01001841
Paul Kehrer61ff3562016-03-11 22:51:27 -04001842 .. classmethod:: from_issuer_subject_key_identifier(ski)
1843
1844 .. versionadded:: 1.3
1845
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001846 .. note::
1847 This method should be used if the issuer certificate contains a
1848 :class:`~cryptography.x509.SubjectKeyIdentifier`. Otherwise, use
1849 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_public_key`.
1850
Paul Kehrer61ff3562016-03-11 22:51:27 -04001851 Creates a new AuthorityKeyIdentifier instance using the
1852 SubjectKeyIdentifier from the issuer certificate. The resulting object
1853 will contain
1854 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1855 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1856 and
1857 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1858 will be None.
1859
1860 :param ski: The
1861 :class:`~cryptography.x509.SubjectKeyIdentifier` from the issuer
1862 certificate.
1863
1864 .. doctest::
1865
1866 >>> from cryptography import x509
1867 >>> from cryptography.hazmat.backends import default_backend
1868 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1869 >>> ski = issuer_cert.extensions.get_extension_for_class(x509.SubjectKeyIdentifier)
1870 >>> x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier(ski)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001871 <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 -04001872
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001873.. class:: SubjectKeyIdentifier(digest)
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001874
1875 .. versionadded:: 0.9
1876
1877 The subject key identifier extension provides a means of identifying
1878 certificates that contain a particular public key.
1879
Paul Kehrer822f3d32015-08-06 11:47:32 +01001880 .. attribute:: oid
1881
1882 .. versionadded:: 1.0
1883
1884 :type: :class:`ObjectIdentifier`
1885
Paul Kehrere27f6582015-08-10 18:33:38 -05001886 Returns
1887 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001888
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001889 .. attribute:: digest
1890
1891 :type: bytes
1892
1893 The binary value of the identifier.
1894
Paul Kehrerd4a7f062015-08-05 18:32:18 +01001895 .. classmethod:: from_public_key(public_key)
Paul Kehrerf22f6122015-08-05 12:57:13 +01001896
1897 .. versionadded:: 1.0
1898
1899 Creates a new SubjectKeyIdentifier instance using the public key
1900 provided to generate the appropriate digest. This should be the public
Paul Kehrereb9ec002015-08-08 10:03:02 -05001901 key that is in the certificate. The generated digest is the SHA1 hash
1902 of the ``subjectPublicKey`` ASN.1 bit string. This is the first
1903 recommendation in :rfc:`5280` section 4.2.1.2.
Paul Kehrerf22f6122015-08-05 12:57:13 +01001904
1905 :param public_key: One of
1906 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1907 ,
1908 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1909 , or
1910 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
1911
Paul Kehrer253929a2015-08-05 17:30:39 +01001912 .. doctest::
1913
1914 >>> from cryptography import x509
1915 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001916 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
1917 >>> x509.SubjectKeyIdentifier.from_public_key(csr.public_key())
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001918 <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 +01001919
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001920.. class:: SubjectAlternativeName(general_names)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001921
1922 .. versionadded:: 0.9
1923
1924 Subject alternative name is an X.509 extension that provides a list of
1925 :ref:`general name <general_name_classes>` instances that provide a set
1926 of identities for which the certificate is valid. The object is iterable to
1927 get every element.
1928
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001929 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001930
Paul Kehrer822f3d32015-08-06 11:47:32 +01001931 .. attribute:: oid
1932
1933 .. versionadded:: 1.0
1934
1935 :type: :class:`ObjectIdentifier`
1936
Paul Kehrere27f6582015-08-10 18:33:38 -05001937 Returns
1938 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001939
Paul Kehrer31bdf792015-03-25 14:11:00 -05001940 .. method:: get_values_for_type(type)
1941
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03001942 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer31bdf792015-03-25 14:11:00 -05001943 :ref:`general name classes <general_name_classes>`.
1944
1945 :returns: A list of values extracted from the matched general names.
Joshua Taubererd2afad32015-07-06 22:37:53 +00001946 The type of the returned values depends on the :class:`GeneralName`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001947
Paul Kehrer93ae8052015-05-02 23:18:09 -05001948 .. doctest::
1949
1950 >>> from cryptography import x509
1951 >>> from cryptography.hazmat.backends import default_backend
1952 >>> from cryptography.hazmat.primitives import hashes
1953 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend())
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001954 >>> # Get the subjectAltName extension from the certificate
Paul Kehrere27f6582015-08-10 18:33:38 -05001955 >>> ext = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001956 >>> # Get the dNSName entries from the SAN extension
1957 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001958 ['www.cryptography.io', 'cryptography.io']
Paul Kehrer93ae8052015-05-02 23:18:09 -05001959
Paul Kehrer8cf26422015-03-21 09:50:24 -05001960
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001961.. class:: IssuerAlternativeName(general_names)
Paul Kehrer99125c92015-06-07 18:37:10 -05001962
1963 .. versionadded:: 1.0
1964
1965 Issuer alternative name is an X.509 extension that provides a list of
1966 :ref:`general name <general_name_classes>` instances that provide a set
1967 of identities for the certificate issuer. The object is iterable to
1968 get every element.
1969
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001970 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001971
Paul Kehrer822f3d32015-08-06 11:47:32 +01001972 .. attribute:: oid
1973
1974 .. versionadded:: 1.0
1975
1976 :type: :class:`ObjectIdentifier`
1977
Paul Kehrere27f6582015-08-10 18:33:38 -05001978 Returns
1979 :attr:`~cryptography.x509.oid.ExtensionOID.ISSUER_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001980
Paul Kehrer99125c92015-06-07 18:37:10 -05001981 .. method:: get_values_for_type(type)
1982
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03001983 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer99125c92015-06-07 18:37:10 -05001984 :ref:`general name classes <general_name_classes>`.
1985
1986 :returns: A list of values extracted from the matched general names.
1987
1988
Alex Gaynor6a0718f2017-06-04 13:36:58 -04001989.. class:: PrecertificateSignedCertificateTimestamps(scts)
1990
1991 .. versionadded:: 2.0
1992
1993 This extension contains
1994 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
1995 instances which were issued for the pre-certificate corresponding to this
1996 certificate. These can be used to verify that the certificate is included
1997 in a public Certificate Transparency log.
1998
1999 It is an iterable containing one or more
2000 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2001 objects.
2002
2003 :param list scts: A ``list`` of
2004 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2005 objects.
2006
2007 .. attribute:: oid
2008
2009 :type: :class:`ObjectIdentifier`
2010
2011 Returns
2012 :attr:`~cryptography.x509.oid.ExtensionOID.PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS`.
2013
2014
Alex Gaynordd6b78b2018-08-31 18:25:52 -05002015.. class:: PrecertPoison()
2016
2017 .. versionadded:: 2.4
2018
2019 This extension indicates that the certificate should not be treated as a
2020 certificate for the purposes of validation, but is instead for submission
2021 to a certificate transparency log in order to obtain SCTs which will be
2022 embedded in a :class:`PrecertificateSignedCertificateTimestamps` extension
2023 on the final certificate.
2024
2025 .. attribute:: oid
2026
2027 :type: :class:`ObjectIdentifier`
2028
2029 Returns :attr:`~cryptography.x509.oid.ExtensionOID.PRECERT_POISON`.
2030
2031
Paul Kehrer5e3cc982017-09-22 21:29:36 +08002032.. class:: DeltaCRLIndicator(crl_number)
2033
2034 .. versionadded:: 2.1
2035
2036 The delta CRL indicator is a CRL extension that identifies a CRL as being
2037 a delta CRL. Delta CRLs contain updates to revocation information
2038 previously distributed, rather than all the information that would appear
2039 in a complete CRL.
2040
2041 :param int crl_number: The CRL number of the complete CRL that the
2042 delta CRL is updating.
2043
2044 .. attribute:: oid
2045
2046 :type: :class:`ObjectIdentifier`
2047
2048 Returns
2049 :attr:`~cryptography.x509.oid.ExtensionOID.DELTA_CRL_INDICATOR`.
2050
2051 .. attribute:: crl_number
2052
2053 :type: int
2054
2055
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002056.. class:: AuthorityInformationAccess(descriptions)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002057
2058 .. versionadded:: 0.9
2059
2060 The authority information access extension indicates how to access
2061 information and services for the issuer of the certificate in which
2062 the extension appears. Information and services may include online
2063 validation services (such as OCSP) and issuer data. It is an iterable,
Paul Kehrere27f6582015-08-10 18:33:38 -05002064 containing one or more :class:`~cryptography.x509.AccessDescription`
2065 instances.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002066
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002067 :param list descriptions: A list of :class:`AccessDescription` objects.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002068
Paul Kehrer822f3d32015-08-06 11:47:32 +01002069 .. attribute:: oid
2070
2071 .. versionadded:: 1.0
2072
2073 :type: :class:`ObjectIdentifier`
2074
Paul Kehrere27f6582015-08-10 18:33:38 -05002075 Returns
2076 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_INFORMATION_ACCESS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002077
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002078
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002079.. class:: AccessDescription(access_method, access_location)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002080
Paul Kehrer5a485522015-05-06 00:29:12 -05002081 .. versionadded:: 0.9
2082
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002083 .. attribute:: access_method
2084
2085 :type: :class:`ObjectIdentifier`
2086
Paul Kehrerf506bca2015-05-02 22:31:47 -05002087 The access method defines what the ``access_location`` means. It must
Paul Kehrere27f6582015-08-10 18:33:38 -05002088 be either
2089 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP` or
2090 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`.
2091 If it is
2092 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP`
2093 the access location will be where to obtain OCSP
2094 information for the certificate. If it is
2095 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`
2096 the access location will provide additional information about the
2097 issuing certificate.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002098
2099 .. attribute:: access_location
2100
2101 :type: :class:`GeneralName`
2102
Paul Kehrerf506bca2015-05-02 22:31:47 -05002103 Where to access the information defined by the access method.
2104
Paul Kehrerb76bcf82017-09-24 08:44:12 +08002105.. class:: FreshestCRL(distribution_points)
2106
2107 .. versionadded:: 2.1
2108
2109 The freshest CRL extension (also known as Delta CRL Distribution Point)
2110 identifies how delta CRL information is obtained. It is an iterable,
2111 containing one or more :class:`DistributionPoint` instances.
2112
2113 :param list distribution_points: A list of :class:`DistributionPoint`
2114 instances.
2115
2116 .. attribute:: oid
2117
2118 :type: :class:`ObjectIdentifier`
2119
2120 Returns
2121 :attr:`~cryptography.x509.oid.ExtensionOID.FRESHEST_CRL`.
2122
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002123.. class:: CRLDistributionPoints(distribution_points)
Paul Kehrer5a485522015-05-06 00:29:12 -05002124
2125 .. versionadded:: 0.9
2126
2127 The CRL distribution points extension identifies how CRL information is
2128 obtained. It is an iterable, containing one or more
2129 :class:`DistributionPoint` instances.
2130
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002131 :param list distribution_points: A list of :class:`DistributionPoint`
2132 instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002133
Paul Kehrer822f3d32015-08-06 11:47:32 +01002134 .. attribute:: oid
2135
2136 .. versionadded:: 1.0
2137
2138 :type: :class:`ObjectIdentifier`
2139
Paul Kehrere27f6582015-08-10 18:33:38 -05002140 Returns
2141 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_DISTRIBUTION_POINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002142
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002143.. class:: DistributionPoint(full_name, relative_name, reasons, crl_issuer)
Paul Kehrer5a485522015-05-06 00:29:12 -05002144
2145 .. versionadded:: 0.9
2146
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002147 .. attribute:: full_name
Paul Kehrer5a485522015-05-06 00:29:12 -05002148
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002149 :type: list of :class:`GeneralName` instances or None
Paul Kehrer5a485522015-05-06 00:29:12 -05002150
Paul Kehrerf2c072b2015-05-09 17:04:28 -05002151 This field describes methods to retrieve the CRL. At most one of
2152 ``full_name`` or ``relative_name`` will be non-None.
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002153
2154 .. attribute:: relative_name
2155
Fraser Tweedale02467dd2016-11-07 15:54:04 +10002156 :type: :class:`RelativeDistinguishedName` or None
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002157
2158 This field describes methods to retrieve the CRL relative to the CRL
Paul Kehrerf2c072b2015-05-09 17:04:28 -05002159 issuer. At most one of ``full_name`` or ``relative_name`` will be
2160 non-None.
Paul Kehrer5a485522015-05-06 00:29:12 -05002161
Fraser Tweedale02467dd2016-11-07 15:54:04 +10002162 .. versionchanged:: 1.6
2163 Changed from :class:`Name` to :class:`RelativeDistinguishedName`.
2164
Paul Kehrer5a485522015-05-06 00:29:12 -05002165 .. attribute:: crl_issuer
2166
2167 :type: list of :class:`GeneralName` instances or None
2168
2169 Information about the issuer of the CRL.
2170
2171 .. attribute:: reasons
2172
Paul Kehrer3fd02602015-05-09 19:46:13 -05002173 :type: frozenset of :class:`ReasonFlags` or None
Paul Kehrer5a485522015-05-06 00:29:12 -05002174
2175 The reasons a given distribution point may be used for when performing
2176 revocation checks.
2177
2178.. class:: ReasonFlags
2179
2180 .. versionadded:: 0.9
2181
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002182 An enumeration for CRL reasons.
2183
2184 .. attribute:: unspecified
2185
2186 It is unspecified why the certificate was revoked. This reason cannot
2187 be used as a reason flag in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05002188
2189 .. attribute:: key_compromise
2190
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002191 This reason indicates that the private key was compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05002192
2193 .. attribute:: ca_compromise
2194
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002195 This reason indicates that the CA issuing the certificate was
2196 compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05002197
2198 .. attribute:: affiliation_changed
2199
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002200 This reason indicates that the subject's name or other information has
2201 changed.
Paul Kehrer5a485522015-05-06 00:29:12 -05002202
2203 .. attribute:: superseded
2204
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002205 This reason indicates that a certificate has been superseded.
Paul Kehrer5a485522015-05-06 00:29:12 -05002206
2207 .. attribute:: cessation_of_operation
2208
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002209 This reason indicates that the certificate is no longer required.
Paul Kehrer5a485522015-05-06 00:29:12 -05002210
2211 .. attribute:: certificate_hold
2212
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002213 This reason indicates that the certificate is on hold.
Paul Kehrer5a485522015-05-06 00:29:12 -05002214
2215 .. attribute:: privilege_withdrawn
2216
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002217 This reason indicates that the privilege granted by this certificate
2218 have been withdrawn.
Paul Kehrer5a485522015-05-06 00:29:12 -05002219
2220 .. attribute:: aa_compromise
2221
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002222 When an attribute authority has been compromised.
2223
2224 .. attribute:: remove_from_crl
2225
2226 This reason indicates that the certificate was on hold and should be
2227 removed from the CRL. This reason cannot be used as a reason flag
2228 in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05002229
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002230.. class:: InhibitAnyPolicy(skip_certs)
Paul Kehrer16fae762015-05-01 23:14:20 -05002231
2232 .. versionadded:: 1.0
2233
2234 The inhibit ``anyPolicy`` extension indicates that the special OID
Paul Kehrere27f6582015-08-10 18:33:38 -05002235 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY`, is not
2236 considered an explicit match for other :class:`CertificatePolicies` except
2237 when it appears in an intermediate self-issued CA certificate. The value
2238 indicates the number of additional non-self-issued certificates that may
2239 appear in the path before
2240 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` is no
2241 longer permitted. For example, a value of one indicates that
2242 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` may be
2243 processed in certificates issued by the subject of this certificate, but
2244 not in additional certificates in the path.
Paul Kehrer16fae762015-05-01 23:14:20 -05002245
Paul Kehrer822f3d32015-08-06 11:47:32 +01002246 .. attribute:: oid
2247
2248 .. versionadded:: 1.0
2249
2250 :type: :class:`ObjectIdentifier`
2251
Paul Kehrere27f6582015-08-10 18:33:38 -05002252 Returns
2253 :attr:`~cryptography.x509.oid.ExtensionOID.INHIBIT_ANY_POLICY`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002254
Paul Kehrer16fae762015-05-01 23:14:20 -05002255 .. attribute:: skip_certs
2256
2257 :type: int
2258
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002259.. class:: PolicyConstraints
2260
2261 .. versionadded:: 1.3
2262
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002263 The policy constraints extension is used to inhibit policy mapping or
2264 require that each certificate in a chain contain an acceptable policy
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002265 identifier. For more information about the use of this extension see
2266 :rfc:`5280`.
2267
Paul Kehrer159b3b52016-02-26 08:27:22 -06002268 .. attribute:: oid
2269
2270 :type: :class:`ObjectIdentifier`
2271
2272 Returns :attr:`~cryptography.x509.oid.ExtensionOID.POLICY_CONSTRAINTS`.
2273
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002274 .. attribute:: require_explicit_policy
2275
2276 :type: int or None
2277
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002278 If this field is not None, the value indicates the number of additional
2279 certificates that may appear in the chain before an explicit policy is
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002280 required for the entire path. When an explicit policy is required, it
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002281 is necessary for all certificates in the chain to contain an acceptable
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002282 policy identifier in the certificate policies extension. An
2283 acceptable policy identifier is the identifier of a policy required
2284 by the user of the certification path or the identifier of a policy
2285 that has been declared equivalent through policy mapping.
2286
2287 .. attribute:: inhibit_policy_mapping
2288
2289 :type: int or None
2290
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002291 If this field is not None, the value indicates the number of additional
2292 certificates that may appear in the chain before policy mapping is no
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002293 longer permitted. For example, a value of one indicates that policy
2294 mapping may be processed in certificates issued by the subject of this
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002295 certificate, but not in additional certificates in the chain.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002296
Paul Kehrer3b95cd72015-12-22 21:40:20 -06002297.. class:: CRLNumber(crl_number)
2298
2299 .. versionadded:: 1.2
2300
Paul Kehrere32b9942015-12-22 22:26:53 -06002301 The CRL number is a CRL extension that conveys a monotonically increasing
2302 sequence number for a given CRL scope and CRL issuer. This extension allows
2303 users to easily determine when a particular CRL supersedes another CRL.
2304 :rfc:`5280` requires that this extension be present in conforming CRLs.
Paul Kehrer3b95cd72015-12-22 21:40:20 -06002305
2306 .. attribute:: oid
2307
2308 :type: :class:`ObjectIdentifier`
2309
2310 Returns
2311 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_NUMBER`.
2312
2313 .. attribute:: crl_number
2314
2315 :type: int
2316
Paul Kehrer14fd6972015-12-30 10:58:25 -06002317.. class:: UnrecognizedExtension
2318
2319 .. versionadded:: 1.2
2320
Alex Gaynord08ddd52017-05-20 09:01:54 -07002321 A generic extension class used to hold the raw value of extensions that
2322 ``cryptography`` does not know how to parse.
Paul Kehrer14fd6972015-12-30 10:58:25 -06002323
2324 .. attribute:: oid
2325
2326 :type: :class:`ObjectIdentifier`
2327
2328 Returns the OID associated with this extension.
2329
2330 .. attribute:: value
2331
Paul Kehreredfedc12018-09-14 18:24:20 -04002332 :type: bytes
Paul Kehrer14fd6972015-12-30 10:58:25 -06002333
2334 Returns the DER encoded bytes payload of the extension.
2335
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002336.. class:: CertificatePolicies(policies)
Paul Kehrer0d210922015-04-28 17:31:07 -05002337
2338 .. versionadded:: 0.9
2339
Paul Kehrer2e879742015-05-02 23:09:56 -05002340 The certificate policies extension is an iterable, containing one or more
2341 :class:`PolicyInformation` instances.
Paul Kehrer0d210922015-04-28 17:31:07 -05002342
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002343 :param list policies: A list of :class:`PolicyInformation` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002344
Paul Kehrer822f3d32015-08-06 11:47:32 +01002345 .. attribute:: oid
2346
2347 .. versionadded:: 1.0
2348
2349 :type: :class:`ObjectIdentifier`
2350
Paul Kehrere27f6582015-08-10 18:33:38 -05002351 Returns
2352 :attr:`~cryptography.x509.oid.ExtensionOID.CERTIFICATE_POLICIES`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002353
Paul Kehrer0d210922015-04-28 17:31:07 -05002354Certificate Policies Classes
2355~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2356
2357These classes may be present within a :class:`CertificatePolicies` instance.
2358
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002359.. class:: PolicyInformation(policy_identifier, policy_qualifiers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002360
2361 .. versionadded:: 0.9
2362
2363 Contains a policy identifier and an optional list of qualifiers.
2364
2365 .. attribute:: policy_identifier
2366
2367 :type: :class:`ObjectIdentifier`
2368
2369 .. attribute:: policy_qualifiers
2370
2371 :type: list
2372
Paul Kehrerba35b3b2015-05-10 13:07:59 -05002373 A list consisting of :term:`text` and/or :class:`UserNotice` objects.
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002374 If the value is text it is a pointer to the practice statement
2375 published by the certificate authority. If it is a user notice it is
2376 meant for display to the relying party when the certificate is
2377 used.
Paul Kehrer2e879742015-05-02 23:09:56 -05002378
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002379.. class:: UserNotice(notice_reference, explicit_text)
Paul Kehrer0d210922015-04-28 17:31:07 -05002380
2381 .. versionadded:: 0.9
2382
Paul Kehrer2e879742015-05-02 23:09:56 -05002383 User notices are intended for display to a relying party when a certificate
2384 is used. In practice, few if any UIs expose this data and it is a rarely
2385 encoded component.
2386
Paul Kehrer0d210922015-04-28 17:31:07 -05002387 .. attribute:: notice_reference
2388
2389 :type: :class:`NoticeReference` or None
2390
Paul Kehrer2e879742015-05-02 23:09:56 -05002391 The notice reference field names an organization and identifies,
2392 by number, a particular statement prepared by that organization.
2393
Paul Kehrer0d210922015-04-28 17:31:07 -05002394 .. attribute:: explicit_text
2395
Paul Kehrer2e879742015-05-02 23:09:56 -05002396 This field includes an arbitrary textual statement directly in the
2397 certificate.
2398
Paul Kehrer0d210922015-04-28 17:31:07 -05002399 :type: :term:`text`
2400
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002401.. class:: NoticeReference(organization, notice_numbers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002402
Paul Kehrer2e879742015-05-02 23:09:56 -05002403 Notice reference can name an organization and provide information about
2404 notices related to the certificate. For example, it might identify the
2405 organization name and notice number 1. Application software could
2406 have a notice file containing the current set of notices for the named
2407 organization; the application would then extract the notice text from the
2408 file and display it. In practice this is rarely seen.
2409
Paul Kehrer0d210922015-04-28 17:31:07 -05002410 .. versionadded:: 0.9
2411
2412 .. attribute:: organization
2413
Paul Kehrer66c61702015-05-12 16:39:18 -05002414 :type: :term:`text`
Paul Kehrer0d210922015-04-28 17:31:07 -05002415
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002416 .. attribute:: notice_numbers
Paul Kehrer0d210922015-04-28 17:31:07 -05002417
Paul Kehrer66c61702015-05-12 16:39:18 -05002418 :type: list
Paul Kehrer0d210922015-04-28 17:31:07 -05002419
Paul Kehrer66c61702015-05-12 16:39:18 -05002420 A list of integers.
Paul Kehrer0d210922015-04-28 17:31:07 -05002421
Paul Kehrere5f152b2015-12-25 23:55:47 -06002422.. _crl_entry_extensions:
2423
Paul Kehrer49bb7562015-12-25 16:17:40 -06002424CRL Entry Extensions
2425~~~~~~~~~~~~~~~~~~~~
2426
2427These extensions are only valid within a :class:`RevokedCertificate` object.
2428
2429.. class:: CertificateIssuer(general_names)
2430
2431 .. versionadded:: 1.2
2432
2433 The certificate issuer is an extension that is only valid inside
2434 :class:`~cryptography.x509.RevokedCertificate` objects. If the
2435 ``indirectCRL`` property of the parent CRL's IssuingDistributionPoint
2436 extension is set, then this extension identifies the certificate issuer
2437 associated with the revoked certificate. The object is iterable to get
2438 every element.
2439
2440 :param list general_names: A list of :class:`GeneralName` instances.
2441
2442 .. attribute:: oid
2443
2444 :type: :class:`ObjectIdentifier`
2445
2446 Returns
2447 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CERTIFICATE_ISSUER`.
2448
2449 .. method:: get_values_for_type(type)
2450
2451 :param type: A :class:`GeneralName` instance. This is one of the
2452 :ref:`general name classes <general_name_classes>`.
2453
2454 :returns: A list of values extracted from the matched general names.
2455 The type of the returned values depends on the :class:`GeneralName`.
2456
Paul Kehrer7058ece2015-12-25 22:28:29 -06002457.. class:: CRLReason(reason)
2458
2459 .. versionadded:: 1.2
2460
2461 CRL reason (also known as ``reasonCode``) is an extension that is only
2462 valid inside :class:`~cryptography.x509.RevokedCertificate` objects. It
2463 identifies a reason for the certificate revocation.
2464
Paul Kehrerce4d0842017-09-20 22:14:26 +08002465 :param reason: An element from :class:`~cryptography.x509.ReasonFlags`.
Paul Kehrer7058ece2015-12-25 22:28:29 -06002466
2467 .. attribute:: oid
2468
2469 :type: :class:`ObjectIdentifier`
2470
2471 Returns
2472 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CRL_REASON`.
2473
2474 .. attribute:: reason
2475
2476 :type: An element from :class:`~cryptography.x509.ReasonFlags`
2477
Paul Kehrer23c0bbc2015-12-25 22:35:19 -06002478.. class:: InvalidityDate(invalidity_date)
2479
2480 .. versionadded:: 1.2
2481
2482 Invalidity date is an extension that is only valid inside
2483 :class:`~cryptography.x509.RevokedCertificate` objects. It provides
2484 the date on which it is known or suspected that the private key was
2485 compromised or that the certificate otherwise became invalid.
2486 This date may be earlier than the revocation date in the CRL entry,
2487 which is the date at which the CA processed the revocation.
2488
2489 :param invalidity_date: The :class:`datetime.datetime` when it is known
2490 or suspected that the private key was compromised.
2491
2492 .. attribute:: oid
2493
2494 :type: :class:`ObjectIdentifier`
2495
2496 Returns
2497 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.INVALIDITY_DATE`.
2498
2499 .. attribute:: invalidity_date
2500
2501 :type: :class:`datetime.datetime`
2502
Paul Kehrer09403102018-09-09 21:57:21 -05002503OCSP Extensions
2504~~~~~~~~~~~~~~~
2505
2506.. class:: OCSPNonce(nonce)
2507
2508 .. versionadded:: 2.4
2509
2510 OCSP nonce is an extension that is only valid inside
2511 :class:`~cryptography.x509.ocsp.OCSPRequest` and
2512 :class:`~cryptography.x509.ocsp.OCSPResponse` objects. The nonce
2513 cryptographically binds a request and a response to prevent replay attacks.
2514 In practice nonces are rarely used in OCSP due to the desire to precompute
2515 OCSP responses at large scale.
2516
2517 .. attribute:: oid
2518
2519 :type: :class:`ObjectIdentifier`
2520
2521 Returns
2522 :attr:`~cryptography.x509.oid.OCSPExtensionOID.NONCE`.
2523
2524 .. attribute:: nonce
2525
2526 :type: bytes
Paul Kehrer49bb7562015-12-25 16:17:40 -06002527
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002528Object Identifiers
2529~~~~~~~~~~~~~~~~~~
2530
Paul Kehrer4bb46492015-02-07 16:59:14 -06002531X.509 elements are frequently identified by :class:`ObjectIdentifier`
2532instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002533
Paul Kehrere27f6582015-08-10 18:33:38 -05002534.. currentmodule:: cryptography.x509.oid
Paul Kehrer56da2a52015-02-11 23:35:07 -06002535
Paul Kehrere27f6582015-08-10 18:33:38 -05002536.. class:: NameOID
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002537
Paul Kehrere27f6582015-08-10 18:33:38 -05002538 These OIDs are typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06002539
Paul Kehrere27f6582015-08-10 18:33:38 -05002540 .. versionadded:: 1.0
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002541
Paul Kehrere27f6582015-08-10 18:33:38 -05002542 .. attribute:: COMMON_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002543
Paul Kehrere27f6582015-08-10 18:33:38 -05002544 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
2545 name would be encoded here for server certificates. :rfc:`2818`
2546 deprecates this practice and names of that type should now be located
2547 in a :class:`~cryptography.x509.SubjectAlternativeName` extension.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002548
Paul Kehrere27f6582015-08-10 18:33:38 -05002549 .. attribute:: COUNTRY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002550
Paul Kehrere27f6582015-08-10 18:33:38 -05002551 Corresponds to the dotted string ``"2.5.4.6"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002552
Paul Kehrere27f6582015-08-10 18:33:38 -05002553 .. attribute:: LOCALITY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002554
Paul Kehrere27f6582015-08-10 18:33:38 -05002555 Corresponds to the dotted string ``"2.5.4.7"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002556
Paul Kehrere27f6582015-08-10 18:33:38 -05002557 .. attribute:: STATE_OR_PROVINCE_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002558
Paul Kehrere27f6582015-08-10 18:33:38 -05002559 Corresponds to the dotted string ``"2.5.4.8"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002560
Paul Kehrerc3b8ff62016-11-11 17:38:59 -08002561 .. attribute:: STREET_ADDRESS
2562
2563 .. versionadded:: 1.6
2564
2565 Corresponds to the dotted string ``"2.5.4.9"``.
2566
Paul Kehrere27f6582015-08-10 18:33:38 -05002567 .. attribute:: ORGANIZATION_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002568
Paul Kehrere27f6582015-08-10 18:33:38 -05002569 Corresponds to the dotted string ``"2.5.4.10"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002570
Paul Kehrere27f6582015-08-10 18:33:38 -05002571 .. attribute:: ORGANIZATIONAL_UNIT_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002572
Paul Kehrere27f6582015-08-10 18:33:38 -05002573 Corresponds to the dotted string ``"2.5.4.11"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002574
Paul Kehrere27f6582015-08-10 18:33:38 -05002575 .. attribute:: SERIAL_NUMBER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002576
Paul Kehrere27f6582015-08-10 18:33:38 -05002577 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from
2578 the serial number of the certificate itself (which can be obtained with
Chelsea Winfreee295f3a2016-06-02 21:15:54 -07002579 :func:`~cryptography.x509.Certificate.serial_number`).
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002580
Paul Kehrere27f6582015-08-10 18:33:38 -05002581 .. attribute:: SURNAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002582
Paul Kehrere27f6582015-08-10 18:33:38 -05002583 Corresponds to the dotted string ``"2.5.4.4"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002584
Paul Kehrere27f6582015-08-10 18:33:38 -05002585 .. attribute:: GIVEN_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002586
Paul Kehrere27f6582015-08-10 18:33:38 -05002587 Corresponds to the dotted string ``"2.5.4.42"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002588
Paul Kehrere27f6582015-08-10 18:33:38 -05002589 .. attribute:: TITLE
Paul Kehrer858b9b72015-02-05 09:50:31 -06002590
Paul Kehrere27f6582015-08-10 18:33:38 -05002591 Corresponds to the dotted string ``"2.5.4.12"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002592
Paul Kehrere27f6582015-08-10 18:33:38 -05002593 .. attribute:: GENERATION_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002594
Paul Kehrere27f6582015-08-10 18:33:38 -05002595 Corresponds to the dotted string ``"2.5.4.44"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002596
Paul Kehrerc7ab9312016-11-12 05:00:42 -08002597 .. attribute:: X500_UNIQUE_IDENTIFIER
Paul Kehrerc3b8ff62016-11-11 17:38:59 -08002598
2599 .. versionadded:: 1.6
2600
2601 Corresponds to the dotted string ``"2.5.4.45"``.
2602
Paul Kehrere27f6582015-08-10 18:33:38 -05002603 .. attribute:: DN_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002604
Paul Kehrere27f6582015-08-10 18:33:38 -05002605 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
2606 disambiguating information to add to the relative distinguished name of an
2607 entry. See :rfc:`2256`.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002608
Paul Kehrere27f6582015-08-10 18:33:38 -05002609 .. attribute:: PSEUDONYM
Paul Kehrer858b9b72015-02-05 09:50:31 -06002610
Paul Kehrere27f6582015-08-10 18:33:38 -05002611 Corresponds to the dotted string ``"2.5.4.65"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002612
Paul Kehrer36d5cd62016-11-19 22:05:26 +08002613 .. attribute:: USER_ID
2614
2615 .. versionadded:: 1.6
2616
2617 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.1"``.
2618
Paul Kehrere27f6582015-08-10 18:33:38 -05002619 .. attribute:: DOMAIN_COMPONENT
Paul Kehrer858b9b72015-02-05 09:50:31 -06002620
Paul Kehrere27f6582015-08-10 18:33:38 -05002621 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
2622 holding one component of a domain name. See :rfc:`4519`.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002623
Paul Kehrere27f6582015-08-10 18:33:38 -05002624 .. attribute:: EMAIL_ADDRESS
Paul Kehrer56da2a52015-02-11 23:35:07 -06002625
Paul Kehrere27f6582015-08-10 18:33:38 -05002626 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002627
Alex Gaynor1d3f2bf2015-12-19 12:15:09 -05002628 .. attribute:: JURISDICTION_COUNTRY_NAME
2629
2630 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.3"``.
2631
Alex Gaynor45e507f2015-12-19 13:44:23 -05002632 .. attribute:: JURISDICTION_LOCALITY_NAME
2633
2634 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.1"``.
2635
2636 .. attribute:: JURISDICTION_STATE_OR_PROVINCE_NAME
2637
2638 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.2"``.
2639
Alex Gaynora2293c82015-12-19 20:49:15 -05002640 .. attribute:: BUSINESS_CATEGORY
2641
2642 Corresponds to the dotted string ``"2.5.4.15"``.
2643
Paul Kehrer36d5cd62016-11-19 22:05:26 +08002644 .. attribute:: POSTAL_ADDRESS
2645
2646 .. versionadded:: 1.6
2647
2648 Corresponds to the dotted string ``"2.5.4.16"``.
2649
2650 .. attribute:: POSTAL_CODE
2651
2652 .. versionadded:: 1.6
2653
2654 Corresponds to the dotted string ``"2.5.4.17"``.
2655
Paul Kehrer56da2a52015-02-11 23:35:07 -06002656
Paul Kehrere27f6582015-08-10 18:33:38 -05002657.. class:: SignatureAlgorithmOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002658
Paul Kehrere27f6582015-08-10 18:33:38 -05002659 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002660
Paul Kehrere27f6582015-08-10 18:33:38 -05002661 .. attribute:: RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -06002662
Paul Kehrere27f6582015-08-10 18:33:38 -05002663 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
2664 an MD5 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002665
Paul Kehrere27f6582015-08-10 18:33:38 -05002666 .. attribute:: RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06002667
Paul Kehrere27f6582015-08-10 18:33:38 -05002668 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
2669 a SHA1 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002670
Paul Kehrere27f6582015-08-10 18:33:38 -05002671 .. attribute:: RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002672
Paul Kehrere27f6582015-08-10 18:33:38 -05002673 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
2674 a SHA224 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002675
Paul Kehrere27f6582015-08-10 18:33:38 -05002676 .. attribute:: RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002677
Paul Kehrere27f6582015-08-10 18:33:38 -05002678 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
2679 a SHA256 digest signed by an RSA key.
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002680
Paul Kehrere27f6582015-08-10 18:33:38 -05002681 .. attribute:: RSA_WITH_SHA384
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002682
Paul Kehrere27f6582015-08-10 18:33:38 -05002683 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
2684 a SHA384 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002685
Paul Kehrere27f6582015-08-10 18:33:38 -05002686 .. attribute:: RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -06002687
Paul Kehrere27f6582015-08-10 18:33:38 -05002688 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
2689 a SHA512 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002690
Marti Raudsepp33678062018-06-30 02:27:28 +03002691 .. attribute:: RSASSA_PSS
2692
2693 .. versionadded:: 2.3
2694
2695 Corresponds to the dotted string ``"1.2.840.113549.1.1.10"``. This is
2696 signed by an RSA key using the Probabilistic Signature Scheme (PSS)
2697 padding from RFC 4055. The hash function and padding are defined by
2698 signature algorithm parameters.
2699
Paul Kehrere27f6582015-08-10 18:33:38 -05002700 .. attribute:: ECDSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06002701
Paul Kehrere27f6582015-08-10 18:33:38 -05002702 Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1
2703 digest signed by an ECDSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002704
Paul Kehrere27f6582015-08-10 18:33:38 -05002705 .. attribute:: ECDSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002706
Paul Kehrere27f6582015-08-10 18:33:38 -05002707 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
2708 a SHA224 digest signed by an ECDSA key.
2709
2710 .. attribute:: ECDSA_WITH_SHA256
2711
2712 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
2713 a SHA256 digest signed by an ECDSA key.
2714
2715 .. attribute:: ECDSA_WITH_SHA384
2716
2717 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
2718 a SHA384 digest signed by an ECDSA key.
2719
2720 .. attribute:: ECDSA_WITH_SHA512
2721
2722 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
2723 a SHA512 digest signed by an ECDSA key.
2724
2725 .. attribute:: DSA_WITH_SHA1
2726
2727 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
2728 a SHA1 digest signed by a DSA key.
2729
2730 .. attribute:: DSA_WITH_SHA224
2731
2732 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
2733 a SHA224 digest signed by a DSA key.
2734
2735 .. attribute:: DSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002736
Paul Kehrere27f6582015-08-10 18:33:38 -05002737 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
2738 a SHA256 digest signed by a DSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002739
Paul Kehrer56da2a52015-02-11 23:35:07 -06002740
Paul Kehrere27f6582015-08-10 18:33:38 -05002741.. class:: ExtendedKeyUsageOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002742
Paul Kehrere27f6582015-08-10 18:33:38 -05002743 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002744
Paul Kehrere27f6582015-08-10 18:33:38 -05002745 .. attribute:: SERVER_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002746
Paul Kehrere27f6582015-08-10 18:33:38 -05002747 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used
2748 to denote that a certificate may be used for TLS web server
2749 authentication.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002750
Paul Kehrere27f6582015-08-10 18:33:38 -05002751 .. attribute:: CLIENT_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002752
Paul Kehrere27f6582015-08-10 18:33:38 -05002753 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used
2754 to denote that a certificate may be used for TLS web client
2755 authentication.
Paul Kehrerffa2a152015-03-31 08:18:25 -05002756
Paul Kehrere27f6582015-08-10 18:33:38 -05002757 .. attribute:: CODE_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002758
Paul Kehrere27f6582015-08-10 18:33:38 -05002759 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used
2760 to denote that a certificate may be used for code signing.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002761
Paul Kehrere27f6582015-08-10 18:33:38 -05002762 .. attribute:: EMAIL_PROTECTION
Paul Kehrere1513fa2015-03-30 23:08:17 -05002763
Paul Kehrere27f6582015-08-10 18:33:38 -05002764 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used
2765 to denote that a certificate may be used for email protection.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002766
Paul Kehrere27f6582015-08-10 18:33:38 -05002767 .. attribute:: TIME_STAMPING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002768
Paul Kehrere27f6582015-08-10 18:33:38 -05002769 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used
2770 to denote that a certificate may be used for time stamping.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002771
Paul Kehrere27f6582015-08-10 18:33:38 -05002772 .. attribute:: OCSP_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002773
Paul Kehrere27f6582015-08-10 18:33:38 -05002774 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used
2775 to denote that a certificate may be used for signing OCSP responses.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002776
Alex Gaynorb7912ee2017-07-03 10:07:02 -04002777 .. attribute:: ANY_EXTENDED_KEY_USAGE
2778
2779 .. versionadded:: 2.0
2780
2781 Corresponds to the dotted string ``"2.5.29.37.0"``. This is used to
2782 denote that a certificate may be used for _any_ purposes.
2783
Paul Kehrere1513fa2015-03-30 23:08:17 -05002784
Paul Kehrere27f6582015-08-10 18:33:38 -05002785.. class:: AuthorityInformationAccessOID
Paul Kehrere1513fa2015-03-30 23:08:17 -05002786
Paul Kehrere27f6582015-08-10 18:33:38 -05002787 .. versionadded:: 1.0
Paul Kehrere1513fa2015-03-30 23:08:17 -05002788
Paul Kehrere27f6582015-08-10 18:33:38 -05002789 .. attribute:: OCSP
Paul Kehrere1513fa2015-03-30 23:08:17 -05002790
Paul Kehrere27f6582015-08-10 18:33:38 -05002791 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
2792 identifier for OCSP data in
2793 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002794
Paul Kehrere27f6582015-08-10 18:33:38 -05002795 .. attribute:: CA_ISSUERS
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002796
Paul Kehrere27f6582015-08-10 18:33:38 -05002797 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
2798 identifier for CA issuer data in
2799 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002800
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002801
Paul Kehrere27f6582015-08-10 18:33:38 -05002802.. class:: CertificatePoliciesOID
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002803
Paul Kehrere27f6582015-08-10 18:33:38 -05002804 .. versionadded:: 1.0
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002805
Paul Kehrere27f6582015-08-10 18:33:38 -05002806 .. attribute:: CPS_QUALIFIER
Paul Kehrer2e879742015-05-02 23:09:56 -05002807
Paul Kehrere27f6582015-08-10 18:33:38 -05002808 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05002809
Paul Kehrere27f6582015-08-10 18:33:38 -05002810 .. attribute:: CPS_USER_NOTICE
Paul Kehrer2e879742015-05-02 23:09:56 -05002811
Paul Kehrere27f6582015-08-10 18:33:38 -05002812 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05002813
Paul Kehrere27f6582015-08-10 18:33:38 -05002814 .. attribute:: ANY_POLICY
Paul Kehrer2e879742015-05-02 23:09:56 -05002815
Paul Kehrere27f6582015-08-10 18:33:38 -05002816 Corresponds to the dotted string ``"2.5.29.32.0"``.
Paul Kehrer16fae762015-05-01 23:14:20 -05002817
Paul Kehrer16fae762015-05-01 23:14:20 -05002818
Paul Kehrere27f6582015-08-10 18:33:38 -05002819.. class:: ExtensionOID
Paul Kehrer5553d572015-03-23 21:08:01 -05002820
Paul Kehrere27f6582015-08-10 18:33:38 -05002821 .. versionadded:: 1.0
Paul Kehrer2bb94642015-03-21 09:54:17 -05002822
Paul Kehrere27f6582015-08-10 18:33:38 -05002823 .. attribute:: BASIC_CONSTRAINTS
Paul Kehrer2bb94642015-03-21 09:54:17 -05002824
Paul Kehrere27f6582015-08-10 18:33:38 -05002825 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
2826 :class:`~cryptography.x509.BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05002827
Paul Kehrere27f6582015-08-10 18:33:38 -05002828 .. attribute:: KEY_USAGE
Paul Kehrercecbbba2015-03-30 14:58:38 -05002829
Paul Kehrere27f6582015-08-10 18:33:38 -05002830 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
2831 :class:`~cryptography.x509.KeyUsage` extension type.
Paul Kehrercecbbba2015-03-30 14:58:38 -05002832
Paul Kehrere27f6582015-08-10 18:33:38 -05002833 .. attribute:: SUBJECT_ALTERNATIVE_NAME
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002834
Paul Kehrere27f6582015-08-10 18:33:38 -05002835 Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the
2836 :class:`~cryptography.x509.SubjectAlternativeName` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002837
Paul Kehrere27f6582015-08-10 18:33:38 -05002838 .. attribute:: ISSUER_ALTERNATIVE_NAME
Paul Kehrer99125c92015-06-07 18:37:10 -05002839
Paul Kehrere27f6582015-08-10 18:33:38 -05002840 Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the
2841 :class:`~cryptography.x509.IssuerAlternativeName` extension type.
Paul Kehrer99125c92015-06-07 18:37:10 -05002842
Paul Kehrere27f6582015-08-10 18:33:38 -05002843 .. attribute:: SUBJECT_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002844
Paul Kehrere27f6582015-08-10 18:33:38 -05002845 Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the
2846 :class:`~cryptography.x509.SubjectKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002847
Paul Kehrere27f6582015-08-10 18:33:38 -05002848 .. attribute:: NAME_CONSTRAINTS
Paul Kehrere0017be2015-05-17 20:39:40 -06002849
Paul Kehrere27f6582015-08-10 18:33:38 -05002850 Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the
2851 :class:`~cryptography.x509.NameConstraints` extension type.
Paul Kehrere0017be2015-05-17 20:39:40 -06002852
Paul Kehrere27f6582015-08-10 18:33:38 -05002853 .. attribute:: CRL_DISTRIBUTION_POINTS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002854
Paul Kehrere27f6582015-08-10 18:33:38 -05002855 Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the
2856 :class:`~cryptography.x509.CRLDistributionPoints` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002857
Paul Kehrere27f6582015-08-10 18:33:38 -05002858 .. attribute:: CERTIFICATE_POLICIES
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002859
Paul Kehrere27f6582015-08-10 18:33:38 -05002860 Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the
2861 :class:`~cryptography.x509.CertificatePolicies` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002862
Paul Kehrere27f6582015-08-10 18:33:38 -05002863 .. attribute:: AUTHORITY_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002864
Paul Kehrere27f6582015-08-10 18:33:38 -05002865 Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the
2866 :class:`~cryptography.x509.AuthorityKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002867
Paul Kehrere27f6582015-08-10 18:33:38 -05002868 .. attribute:: EXTENDED_KEY_USAGE
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002869
Paul Kehrere27f6582015-08-10 18:33:38 -05002870 Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the
2871 :class:`~cryptography.x509.ExtendedKeyUsage` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002872
Paul Kehrere27f6582015-08-10 18:33:38 -05002873 .. attribute:: AUTHORITY_INFORMATION_ACCESS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002874
Paul Kehrere27f6582015-08-10 18:33:38 -05002875 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier
2876 for the :class:`~cryptography.x509.AuthorityInformationAccess` extension
2877 type.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002878
Paul Kehrere27f6582015-08-10 18:33:38 -05002879 .. attribute:: INHIBIT_ANY_POLICY
Paul Kehrerb33de932015-08-06 23:41:05 +01002880
Paul Kehrere27f6582015-08-10 18:33:38 -05002881 Corresponds to the dotted string ``"2.5.29.54"``. The identifier
2882 for the :class:`~cryptography.x509.InhibitAnyPolicy` extension type.
Paul Kehrerb33de932015-08-06 23:41:05 +01002883
Paul Kehrere27f6582015-08-10 18:33:38 -05002884 .. attribute:: OCSP_NO_CHECK
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002885
Paul Kehrere27f6582015-08-10 18:33:38 -05002886 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The
2887 identifier for the :class:`~cryptography.x509.OCSPNoCheck` extension
2888 type.
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002889
Paul Kehrer5d669662017-09-11 09:16:34 +08002890 .. attribute:: TLS_FEATURE
2891
2892 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.24"``. The
2893 identifier for the :class:`~cryptography.x509.TLSFeature` extension
2894 type.
2895
Paul Kehrer51f39cb2015-12-21 21:17:39 -06002896 .. attribute:: CRL_NUMBER
2897
2898 Corresponds to the dotted string ``"2.5.29.20"``. The identifier for
2899 the ``CRLNumber`` extension type. This extension only has meaning
2900 for certificate revocation lists.
2901
Paul Kehrer5e3cc982017-09-22 21:29:36 +08002902 .. attribute:: DELTA_CRL_INDICATOR
2903
2904 .. versionadded:: 2.1
2905
2906 Corresponds to the dotted string ``"2.5.29.27"``. The identifier for
2907 the ``DeltaCRLIndicator`` extension type. This extension only has
2908 meaning for certificate revocation lists.
2909
Alex Gaynor9bab0ed2017-03-20 09:50:52 -04002910 .. attribute:: PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS
2911
2912 .. versionadded:: 1.9
2913
2914 Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.2"``.
2915
Alex Gaynordd6b78b2018-08-31 18:25:52 -05002916 .. attribute:: PRECERT_POISON
2917
2918 .. versionadded:: 2.4
2919
2920 Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.3"``.
2921
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002922 .. attribute:: POLICY_CONSTRAINTS
2923
2924 Corresponds to the dotted string ``"2.5.29.36"``. The identifier for the
Paul Kehrer20f0df52016-02-26 08:37:13 -06002925 :class:`~cryptography.x509.PolicyConstraints` extension type.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002926
Paul Kehrerb76bcf82017-09-24 08:44:12 +08002927 .. attribute:: FRESHEST_CRL
2928
2929 Corresponds to the dotted string ``"2.5.29.46"``. The identifier for the
2930 :class:`~cryptography.x509.FreshestCRL` extension type.
2931
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002932
Paul Kehrerc6242dc2015-12-25 16:36:46 -06002933.. class:: CRLEntryExtensionOID
2934
2935 .. versionadded:: 1.2
2936
2937 .. attribute:: CERTIFICATE_ISSUER
2938
2939 Corresponds to the dotted string ``"2.5.29.29"``.
2940
2941 .. attribute:: CRL_REASON
2942
2943 Corresponds to the dotted string ``"2.5.29.21"``.
2944
2945 .. attribute:: INVALIDITY_DATE
2946
2947 Corresponds to the dotted string ``"2.5.29.24"``.
2948
Paul Kehrer09403102018-09-09 21:57:21 -05002949
2950.. class:: OCSPExtensionOID
2951
2952 .. versionadded:: 2.4
2953
2954 .. attribute:: NONCE
2955
2956 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.2"``.
2957
Paul Kehrer8b89bcc2016-09-03 11:31:43 -05002958Helper Functions
2959~~~~~~~~~~~~~~~~
2960.. currentmodule:: cryptography.x509
2961
2962.. function:: random_serial_number()
2963
2964 .. versionadded:: 1.6
2965
2966 Generates a random serial number suitable for use when constructing
2967 certificates.
2968
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002969Exceptions
2970~~~~~~~~~~
Paul Kehrere27f6582015-08-10 18:33:38 -05002971.. currentmodule:: cryptography.x509
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002972
Paul Kehrere76cd272014-12-14 19:00:51 -06002973.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10002974
2975 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10002976
Paul Kehrerd5cccf72014-12-15 17:20:33 -06002977 .. attribute:: parsed_version
2978
Paul Kehrerbbffc402014-12-17 13:33:55 -06002979 :type: int
2980
2981 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06002982
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05002983.. class:: DuplicateExtension
2984
2985 This is raised when more than one X.509 extension of the same type is
2986 found within a certificate.
2987
2988 .. attribute:: oid
2989
2990 :type: :class:`ObjectIdentifier`
2991
2992 Returns the OID.
2993
Paul Kehrerfa56a232015-03-17 13:14:03 -05002994.. class:: ExtensionNotFound
2995
2996 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
2997 an extension OID that is not present in the certificate.
2998
2999 .. attribute:: oid
3000
3001 :type: :class:`ObjectIdentifier`
3002
3003 Returns the OID.
3004
Paul Kehrer9089c912015-04-20 22:15:20 -05003005.. class:: UnsupportedGeneralNameType
3006
3007 This is raised when a certificate contains an unsupported general name
3008 type in an extension.
3009
Paul Kehrerbed07352015-04-21 08:31:10 -05003010 .. attribute:: type
3011
Paul Kehrer0a621bf2015-04-22 09:22:56 -05003012 :type: int
3013
3014 The integer value of the unsupported type. The complete list of
3015 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05003016
Paul Kehrer016e08a2014-11-26 09:41:18 -10003017
Paul Kehrerc7c9a432015-04-19 09:20:13 -05003018.. _`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 -05003019.. _`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 -05003020.. _`CABForum Guidelines`: https://cabforum.org/baseline-requirements-documents/