blob: 07a692a8ac23eb1082c8cf3fa9120fcfeb97691b [file] [log] [blame]
Alex Gaynor4af5b372015-07-12 10:30:59 -05001X.509 Reference
2===============
Paul Kehrer016e08a2014-11-26 09:41:18 -10003
Paul Kehrera9d78c12014-11-26 10:59:03 -10004.. currentmodule:: cryptography.x509
Paul Kehrer016e08a2014-11-26 09:41:18 -10005
Paul Kehrerd26c4db2015-03-15 15:36:24 -05006.. testsetup::
7
Erik Trauschkedc570402015-09-24 20:24:28 -07008 pem_crl_data = b"""
9 -----BEGIN X509 CRL-----
10 MIIBtDCBnQIBAjANBgkqhkiG9w0BAQsFADAnMQswCQYDVQQGEwJVUzEYMBYGA1UE
11 AwwPY3J5cHRvZ3JhcGh5LmlvGA8yMDE1MDEwMTAwMDAwMFoYDzIwMTYwMTAxMDAw
12 MDAwWjA+MDwCAQAYDzIwMTUwMTAxMDAwMDAwWjAmMBgGA1UdGAQRGA8yMDE1MDEw
13 MTAwMDAwMFowCgYDVR0VBAMKAQEwDQYJKoZIhvcNAQELBQADggEBABRA4ww50Lz5
14 zk1j2+aluC4HPHqb7o06h4pTDcCGeXUKXIGeP5ntGGmIoxa26sNoLeOr8+5b43Gf
15 yWraHertllOwaOpNFEe+YZFaE9femtoDbf+GLMvRx/0wDfd3KxPoXnXKMXb2d1w4
16 RCLgmkYx6JyvS+5ciuLQVIKC+l7jwIUeZFLJMUJ8msM4pFYoGameeZmtjMbd/TNg
17 cVBfmZxNMHuLladJxvSo2esARo0TYPhYsgrREKoHwhpzSxdynjn4bOVkILfguwsN
18 qtEEMZFEv5Kb0GqRp2+Iagv2S6dg9JGvxVdsoGjaB6EbYSZ3Psx4aODasIn11uwo
19 X4B9vUQNXqc=
20 -----END X509 CRL-----
21 """.strip()
22
Paul Kehrerd26c4db2015-03-15 15:36:24 -050023 pem_req_data = b"""
24 -----BEGIN CERTIFICATE REQUEST-----
25 MIIC0zCCAbsCAQAwWTELMAkGA1UEBhMCVVMxETAPBgNVBAgMCElsbGlub2lzMRAw
26 DgYDVQQHDAdDaGljYWdvMREwDwYDVQQKDAhyNTA5IExMQzESMBAGA1UEAwwJaGVs
27 bG8uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqhZx+Mo9VRd9
28 vsnWWa6NBCws21rZ0+1B/JGgB4hDsZS7iDE4Bj5z4idheFRtl8bBbdjPknq7BfoF
29 8v15Zq/Zv7i2xMSDL+LUrTBZezRd4bRTGqCm6YJ5EYkhqdcqeZleHCFImguHoq1J
30 Fh0+kObQrTHXw3ZP57a3o1IvyIUA3nNoCBL0QQhwBXaDXOojMKNR+bqB5ve8GS1y
31 Elr0AM/+cJsfaIahNQUgFKx3Eu3GeEOMKYOAG1lycgdQdmTUybLrT3U7vkClTseM
32 xHg1r5En7ALjONIhqRuq3rddYahrP8HXozb3zUy3cJ7P6IeaosuvNzvMXOX9P6HD
33 Ha9urDAJ1wIDAQABoDUwMwYJKoZIhvcNAQkOMSYwJDAiBgNVHREEGzAZggl3b3Js
34 ZC5jb22CDHdoYXRldmVyLmNvbTANBgkqhkiG9w0BAQUFAAOCAQEAS4Ro6h+z52SK
35 YSLCYARpnEu/rmh4jdqndt8naqcNb6uLx9mlKZ2W9on9XDjnSdQD9q+ZP5aZfESw
36 R0+rJhW9ZrNa/g1pt6M24ihclHYDAxYMWxT1z/TXXGM3TmZZ6gfYlNE1kkBuODHa
37 UYsR/1Ht1E1EsmmUimt2n+zQR2K8T9Coa+boaUW/GsTEuz1aaJAkj5ZvTDiIhRG4
38 AOCqFZOLAQmCCNgJnnspD9hDz/Ons085LF5wnYjN4/Nsk5tS6AGs3xjZ3jPoOGGn
39 82WQ9m4dBGoVDZXsobVTaN592JEYwN5iu72zRn7Einb4V4H5y3yD2dD4yWPlt4pk
40 5wFkeYsZEA==
41 -----END CERTIFICATE REQUEST-----
42 """.strip()
43
Paul Kehrerd3dafbd2015-03-15 16:24:18 -050044 pem_data = b"""
45 -----BEGIN CERTIFICATE-----
46 MIIDfDCCAmSgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJVUzEf
47 MB0GA1UEChMWVGVzdCBDZXJ0aWZpY2F0ZXMgMjAxMTEVMBMGA1UEAxMMVHJ1c3Qg
48 QW5jaG9yMB4XDTEwMDEwMTA4MzAwMFoXDTMwMTIzMTA4MzAwMFowQDELMAkGA1UE
49 BhMCVVMxHzAdBgNVBAoTFlRlc3QgQ2VydGlmaWNhdGVzIDIwMTExEDAOBgNVBAMT
50 B0dvb2QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCQWJpHYo37
51 Xfb7oJSPe+WvfTlzIG21WQ7MyMbGtK/m8mejCzR6c+f/pJhEH/OcDSMsXq8h5kXa
52 BGqWK+vSwD/Pzp5OYGptXmGPcthDtAwlrafkGOS4GqIJ8+k9XGKs+vQUXJKsOk47
53 RuzD6PZupq4s16xaLVqYbUC26UcY08GpnoLNHJZS/EmXw1ZZ3d4YZjNlpIpWFNHn
54 UGmdiGKXUPX/9H0fVjIAaQwjnGAbpgyCumWgzIwPpX+ElFOUr3z7BoVnFKhIXze+
55 VmQGSWxZxvWDUN90Ul0tLEpLgk3OVxUB4VUGuf15OJOpgo1xibINPmWt14Vda2N9
56 yrNKloJGZNqLAgMBAAGjfDB6MB8GA1UdIwQYMBaAFOR9X9FclYYILAWuvnW2ZafZ
57 XahmMB0GA1UdDgQWBBRYAYQkG7wrUpRKPaUQchRR9a86yTAOBgNVHQ8BAf8EBAMC
58 AQYwFwYDVR0gBBAwDjAMBgpghkgBZQMCATABMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
59 KoZIhvcNAQELBQADggEBADWHlxbmdTXNwBL/llwhQqwnazK7CC2WsXBBqgNPWj7m
60 tvQ+aLG8/50Qc2Sun7o2VnwF9D18UUe8Gj3uPUYH+oSI1vDdyKcjmMbKRU4rk0eo
61 3UHNDXwqIVc9CQS9smyV+x1HCwL4TTrq+LXLKx/qVij0Yqk+UJfAtrg2jnYKXsCu
62 FMBQQnWCGrwa1g1TphRp/RmYHnMynYFmZrXtzFz+U9XEA7C+gPq4kqDI/iVfIT1s
63 6lBtdB50lrDVwl2oYfAvW/6sC2se2QleZidUmrziVNP4oEeXINokU6T6p//HM1FG
64 QYw2jOvpKcKtWCSAnegEbgsGYzATKjmPJPJ0npHFqzM=
65 -----END CERTIFICATE-----
66 """.strip()
67
Paul Kehrer93ae8052015-05-02 23:18:09 -050068 cryptography_cert_pem = b"""
69 -----BEGIN CERTIFICATE-----
70 MIIFvTCCBKWgAwIBAgICPyAwDQYJKoZIhvcNAQELBQAwRzELMAkGA1UEBhMCVVMx
71 FjAUBgNVBAoTDUdlb1RydXN0IEluYy4xIDAeBgNVBAMTF1JhcGlkU1NMIFNIQTI1
72 NiBDQSAtIEczMB4XDTE0MTAxNTEyMDkzMloXDTE4MTExNjAxMTUwM1owgZcxEzAR
73 BgNVBAsTCkdUNDg3NDI5NjUxMTAvBgNVBAsTKFNlZSB3d3cucmFwaWRzc2wuY29t
74 L3Jlc291cmNlcy9jcHMgKGMpMTQxLzAtBgNVBAsTJkRvbWFpbiBDb250cm9sIFZh
75 bGlkYXRlZCAtIFJhcGlkU1NMKFIpMRwwGgYDVQQDExN3d3cuY3J5cHRvZ3JhcGh5
76 LmlvMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAom/FebKJIot7Sp3s
77 itG1sicpe3thCssjI+g1JDAS7I3GLVNmbms1DOdIIqwf01gZkzzXBN2+9sOnyRaR
78 PPfCe1jTr3dk2y6rPE559vPa1nZQkhlzlhMhlPyjaT+S7g4Tio4qV2sCBZU01DZJ
79 CaksfohN+5BNVWoJzTbOcrHOEJ+M8B484KlBCiSxqf9cyNQKru4W3bHaCVNVJ8eu
80 6i6KyhzLa0L7yK3LXwwXVs583C0/vwFhccGWsFODqD/9xHUzsBIshE8HKjdjDi7Y
81 3BFQzVUQFjBB50NSZfAA/jcdt1blxJouc7z9T8Oklh+V5DDBowgAsrT4b6Z2Fq6/
82 r7D1GqivLK/ypUQmxq2WXWAUBb/Q6xHgxASxI4Br+CByIUQJsm8L2jzc7k+mF4hW
83 ltAIUkbo8fGiVnat0505YJgxWEDKOLc4Gda6d/7GVd5AvKrz242bUqeaWo6e4MTx
84 diku2Ma3rhdcr044Qvfh9hGyjqNjvhWY/I+VRWgihU7JrYvgwFdJqsQ5eiKT4OHi
85 gsejvWwkZzDtiQ+aQTrzM1FsY2swJBJsLSX4ofohlVRlIJCn/ME+XErj553431Lu
86 YQ5SzMd3nXzN78Vj6qzTfMUUY72UoT1/AcFiUMobgIqrrmwuNxfrkbVE2b6Bga74
87 FsJX63prvrJ41kuHK/16RQBM7fcCAwEAAaOCAWAwggFcMB8GA1UdIwQYMBaAFMOc
88 8/zTRgg0u85Gf6B8W/PiCMtZMFcGCCsGAQUFBwEBBEswSTAfBggrBgEFBQcwAYYT
89 aHR0cDovL2d2LnN5bWNkLmNvbTAmBggrBgEFBQcwAoYaaHR0cDovL2d2LnN5bWNi
90 LmNvbS9ndi5jcnQwDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUFBwMB
91 BggrBgEFBQcDAjAvBgNVHREEKDAmghN3d3cuY3J5cHRvZ3JhcGh5Lmlvgg9jcnlw
92 dG9ncmFwaHkuaW8wKwYDVR0fBCQwIjAgoB6gHIYaaHR0cDovL2d2LnN5bWNiLmNv
93 bS9ndi5jcmwwDAYDVR0TAQH/BAIwADBFBgNVHSAEPjA8MDoGCmCGSAGG+EUBBzYw
94 LDAqBggrBgEFBQcCARYeaHR0cHM6Ly93d3cucmFwaWRzc2wuY29tL2xlZ2FsMA0G
95 CSqGSIb3DQEBCwUAA4IBAQAzIYO2jx7h17FBT74tJ2zbV9OKqGb7QF8y3wUtP4xc
96 dH80vprI/Cfji8s86kr77aAvAqjDjaVjHn7UzebhSUivvRPmfzRgyWBacomnXTSt
97 Xlt2dp2nDQuwGyK2vB7dMfKnQAkxwq1sYUXznB8i0IhhCAoXp01QGPKq51YoIlnF
98 7DRMk6iEaL1SJbkIrLsCQyZFDf0xtfW9DqXugMMLoxeCsBhZJQzNyS2ryirrv9LH
99 aK3+6IZjrcyy9bkpz/gzJucyhU+75c4My/mnRCrtItRbCQuiI5pd5poDowm+HH9i
100 GVI9+0lAFwxOUnOnwsoI40iOoxjLMGB+CgFLKCGUcWxP
101 -----END CERTIFICATE-----
102 """.strip()
103
g_goessel16f746f2018-10-10 04:13:41 +0200104 pem_issuer_public_key = b"""
105 -----BEGIN RSA PUBLIC KEY-----
106 MIICCgKCAgEAyYcqyuT6oQxpvg/VSn2Zc68wZ823D0VAJ2woramFx+2KPWB7B7Ot
107 tVSNRfm0OxJOU3TFAoep54Z2wgOoz0zRmeW6/7gvIuBKp2TW0qZAt3l9sgpE29iw
108 CsoZQlMrLKiDPzCC6Fptk+YPSST9sqwhWDKK1QvOg68DKRxTpEek1hBpC0XRsnuX
109 fvJJQqP39vxzpA0PsicI/wrvWX3vO8z+j9+botPerbeamoeHCsc0xgTLyIygWysB
110 rNskxlzC2U4Kw6mQhGghlLReo1rFsO2/hLTnvLs+Y1lQhnFeOKCx1WVXhzBIyO9B
111 dVVH5Cinb5wBNKvxbevRf4icdWcwtknmgKf69xj7yvFjt/vft74BB1Y5ltLYFmEb
112 0JBxm5MAJfW4YnMQr0AxdjOhjHq4MN7X4ZzwEpJaYJdRmvMsMGN88cyjYPxsaOG+
113 dZ/E9MmTjh0gnTjyD4gmsvR/gtTR/XFJ2wkbnnL1RyxNi6j2UW8C7tpNv0TIuArx
114 3SHGPZN0WsaKTxZPb0L/ob1WBT0mhiq1GzB431cXgbxyh8EdKk+xSptA3V+ca2V2
115 NuXlJIJaOoPMj/qjDW4I/peKGnk9tLknJ0hpRzz11j77pJsV0dGoGKVHIR2oZqT5
116 0ZJJb5DXNbiTnspKLNmBt0YlNiXtlCIPxVUkhL141FuCLc8h6FjD6E0CAwEAAQ==
117 -----END RSA PUBLIC KEY-----
118 """.strip()
119
120 pem_data_to_check = b"""
121 -----BEGIN CERTIFICATE-----
122 MIIErjCCApagAwIBAgIUUrUZsZrrBmRD2hvRuspp+lPsZXcwDQYJKoZIhvcNAQEN
123 BQAwETEPMA0GA1UEAwwGSXNzdWVyMB4XDTE4MTAwODEzNDg1NFoXDTE4MTAxODEz
124 NDg1NFowETEPMA0GA1UEAwwGSXNzdWVyMIICIjANBgkqhkiG9w0BAQEFAAOCAg8A
125 MIICCgKCAgEAyYcqyuT6oQxpvg/VSn2Zc68wZ823D0VAJ2woramFx+2KPWB7B7Ot
126 tVSNRfm0OxJOU3TFAoep54Z2wgOoz0zRmeW6/7gvIuBKp2TW0qZAt3l9sgpE29iw
127 CsoZQlMrLKiDPzCC6Fptk+YPSST9sqwhWDKK1QvOg68DKRxTpEek1hBpC0XRsnuX
128 fvJJQqP39vxzpA0PsicI/wrvWX3vO8z+j9+botPerbeamoeHCsc0xgTLyIygWysB
129 rNskxlzC2U4Kw6mQhGghlLReo1rFsO2/hLTnvLs+Y1lQhnFeOKCx1WVXhzBIyO9B
130 dVVH5Cinb5wBNKvxbevRf4icdWcwtknmgKf69xj7yvFjt/vft74BB1Y5ltLYFmEb
131 0JBxm5MAJfW4YnMQr0AxdjOhjHq4MN7X4ZzwEpJaYJdRmvMsMGN88cyjYPxsaOG+
132 dZ/E9MmTjh0gnTjyD4gmsvR/gtTR/XFJ2wkbnnL1RyxNi6j2UW8C7tpNv0TIuArx
133 3SHGPZN0WsaKTxZPb0L/ob1WBT0mhiq1GzB431cXgbxyh8EdKk+xSptA3V+ca2V2
134 NuXlJIJaOoPMj/qjDW4I/peKGnk9tLknJ0hpRzz11j77pJsV0dGoGKVHIR2oZqT5
135 0ZJJb5DXNbiTnspKLNmBt0YlNiXtlCIPxVUkhL141FuCLc8h6FjD6E0CAwEAATAN
136 BgkqhkiG9w0BAQ0FAAOCAgEAVFzNKhEpkH8V8l0NEBAZHNi1e+lcg35fZZ9plqcw
137 Pvk+6M7LW0KD0QWYQWm/dJme4DFsM7lh5u4/m+H4yS7/RP9pads9YwBudchvGR1c
138 S4CCrRAmO8/A0vpQJcEwdS7fdYShBsqMrZ2TvzceVn2dvQbxB6pLkK7KIbDPVJA2
139 HXFFXe2npHmdc80iTz2ShbdVSvyPvk6vc6NFFCg6lSQFuif3vV0+aYqi6DXv4h92
140 9qAdES8ZLDfDulxyajyPbtF35f2Of99CumP5UzG4RQbvtI8gShuK1YFYe2sWJFE0
141 MgSsqGCbl5mcrWxm9YxysRKMZ+Hc4tnkvfmG6GsKtp8u/5pG11XgxXaQl4fZ7JNa
142 QFuD5gEXkEC1mCnhWlnguJgjQlpKadMOORmVTqG9dNQ6GEsha+XWpinm5L9fEZuA
143 F88nNyubKLwEl68N7WWWKQlIl4q8Pe5FEp1pd9rLjOW4gzgYBccIfBK3oMC7uFJg
144 a/9GeOKPiq90UMrCI+CAsIbzuPOaAp3g69JonuDwcs4cu8ui1udxs9q7ox3qSWGZ
145 G1U/hmwvZH9kfIv5BKIzNLy4oxXPDJ7MZIBsxVxaNv8KUQ/JLtpVJa3oYqEx18+V
146 JNr8Pr3y61X8pLmJnaCu+ixshiy2gjxXxDFBVEEt1G9JHrSs3R+yvcHxCrM3+ian
147 Nh4=
148 -----END CERTIFICATE-----
149 """.strip()
150
Paul Kehrerb2de9482014-12-11 14:54:48 -0600151Loading Certificates
152~~~~~~~~~~~~~~~~~~~~
Paul Kehrer016e08a2014-11-26 09:41:18 -1000153
154.. function:: load_pem_x509_certificate(data, backend)
155
156 .. versionadded:: 0.7
157
Paul Kehrere76cd272014-12-14 19:00:51 -0600158 Deserialize a certificate from PEM encoded data. PEM certificates are
159 base64 decoded and have delimiters that look like
160 ``-----BEGIN CERTIFICATE-----``.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000161
162 :param bytes data: The PEM encoded certificate data.
163
164 :param backend: A backend supporting the
165 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
166 interface.
167
Paul Kehrere76cd272014-12-14 19:00:51 -0600168 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000169
Alex Gaynor5ce14042016-05-29 13:13:46 -0400170 .. doctest::
171
172 >>> from cryptography import x509
173 >>> from cryptography.hazmat.backends import default_backend
174 >>> cert = x509.load_pem_x509_certificate(pem_data, default_backend())
Chelsea Winfreee295f3a2016-06-02 21:15:54 -0700175 >>> cert.serial_number
Alex Gaynor5ce14042016-05-29 13:13:46 -0400176 2
177
Paul Kehrer016e08a2014-11-26 09:41:18 -1000178.. function:: load_der_x509_certificate(data, backend)
179
180 .. versionadded:: 0.7
181
Paul Kehrere76cd272014-12-14 19:00:51 -0600182 Deserialize a certificate from DER encoded data. DER is a binary format
Paul Kehrer92aac382014-12-15 16:25:28 -0600183 and is commonly found in files with the ``.cer`` extension (although file
184 extensions are not a guarantee of encoding type).
Paul Kehrer016e08a2014-11-26 09:41:18 -1000185
186 :param bytes data: The DER encoded certificate data.
187
188 :param backend: A backend supporting the
189 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
190 interface.
191
Paul Kehrere76cd272014-12-14 19:00:51 -0600192 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000193
Erik Trauschkedc570402015-09-24 20:24:28 -0700194Loading Certificate Revocation Lists
195~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
196
197.. function:: load_pem_x509_crl(data, backend)
198
199 .. versionadded:: 1.1
200
201 Deserialize a certificate revocation list (CRL) from PEM encoded data. PEM
202 requests are base64 decoded and have delimiters that look like
Erik Trauschke32bbfe02015-10-21 08:04:55 -0700203 ``-----BEGIN X509 CRL-----``.
Erik Trauschkedc570402015-09-24 20:24:28 -0700204
205 :param bytes data: The PEM encoded request data.
206
207 :param backend: A backend supporting the
208 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
209 interface.
210
211 :returns: An instance of
212 :class:`~cryptography.x509.CertificateRevocationList`.
213
Alex Gaynor5ce14042016-05-29 13:13:46 -0400214 .. doctest::
215
216 >>> from cryptography import x509
217 >>> from cryptography.hazmat.backends import default_backend
218 >>> from cryptography.hazmat.primitives import hashes
219 >>> crl = x509.load_pem_x509_crl(pem_crl_data, default_backend())
220 >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256)
221 True
222
Erik Trauschkedc570402015-09-24 20:24:28 -0700223.. function:: load_der_x509_crl(data, backend)
224
225 .. versionadded:: 1.1
226
227 Deserialize a certificate revocation list (CRL) from DER encoded data. DER
228 is a binary format.
229
230 :param bytes data: The DER encoded request data.
231
232 :param backend: A backend supporting the
233 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
234 interface.
235
236 :returns: An instance of
237 :class:`~cryptography.x509.CertificateRevocationList`.
238
Paul Kehrera1a1f232015-03-15 15:34:35 -0500239Loading Certificate Signing Requests
240~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600241
Paul Kehrer31e39882015-03-11 11:37:04 -0500242.. function:: load_pem_x509_csr(data, backend)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600243
244 .. versionadded:: 0.9
245
Paul Kehrera1a1f232015-03-15 15:34:35 -0500246 Deserialize a certificate signing request (CSR) from PEM encoded data. PEM
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500247 requests are base64 decoded and have delimiters that look like
Paul Kehrerd3dafbd2015-03-15 16:24:18 -0500248 ``-----BEGIN CERTIFICATE REQUEST-----``. This format is also known as
249 PKCS#10.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600250
251 :param bytes data: The PEM encoded request data.
252
253 :param backend: A backend supporting the
254 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
255 interface.
256
Paul Kehrera1a1f232015-03-15 15:34:35 -0500257 :returns: An instance of
258 :class:`~cryptography.x509.CertificateSigningRequest`.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600259
Alex Gaynor5ce14042016-05-29 13:13:46 -0400260 .. doctest::
261
262 >>> from cryptography import x509
263 >>> from cryptography.hazmat.backends import default_backend
264 >>> from cryptography.hazmat.primitives import hashes
265 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
266 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
267 True
268
Paul Kehrer1effb6e2015-03-30 15:05:59 -0500269.. function:: load_der_x509_csr(data, backend)
270
271 .. versionadded:: 0.9
272
273 Deserialize a certificate signing request (CSR) from DER encoded data. DER
274 is a binary format and is not commonly used with CSRs.
275
276 :param bytes data: The DER encoded request data.
277
278 :param backend: A backend supporting the
279 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
280 interface.
281
282 :returns: An instance of
283 :class:`~cryptography.x509.CertificateSigningRequest`.
284
Paul Kehrere76cd272014-12-14 19:00:51 -0600285X.509 Certificate Object
286~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerb2de9482014-12-11 14:54:48 -0600287
Paul Kehrere76cd272014-12-14 19:00:51 -0600288.. class:: Certificate
Paul Kehrerb2de9482014-12-11 14:54:48 -0600289
290 .. versionadded:: 0.7
291
292 .. attribute:: version
293
Paul Kehrere76cd272014-12-14 19:00:51 -0600294 :type: :class:`~cryptography.x509.Version`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600295
Paul Kehrere76cd272014-12-14 19:00:51 -0600296 The certificate version as an enumeration. Version 3 certificates are
297 the latest version and also the only type you should see in practice.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600298
Alex Gaynor89c4dc82014-12-16 16:49:33 -0800299 :raises cryptography.x509.InvalidVersion: If the version in the
Alex Gaynor6d7ab4c2014-12-16 16:50:33 -0800300 certificate is not a known
301 :class:`X.509 version <cryptography.x509.Version>`.
Paul Kehrer92aac382014-12-15 16:25:28 -0600302
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600303 .. doctest::
304
305 >>> cert.version
306 <Version.v3: 2>
307
Paul Kehrerb2de9482014-12-11 14:54:48 -0600308 .. method:: fingerprint(algorithm)
309
310 :param algorithm: The
Paul Kehrer601278a2015-02-12 12:51:00 -0600311 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600312 that will be used to generate the fingerprint.
313
Erik Trauschke2dcce902015-05-14 16:12:24 -0700314 :return bytes: The fingerprint using the supplied hash algorithm, as
Paul Kehrerb2de9482014-12-11 14:54:48 -0600315 bytes.
316
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600317 .. doctest::
318
319 >>> from cryptography.hazmat.primitives import hashes
320 >>> cert.fingerprint(hashes.SHA256())
Paul Kehrer056c9dd2018-05-12 15:17:06 -0400321 b'\x86\xd2\x187Gc\xfc\xe7}[+E9\x8d\xb4\x8f\x10\xe5S\xda\x18u\xbe}a\x03\x08[\xac\xa04?'
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600322
Chelsea Winfreee295f3a2016-06-02 21:15:54 -0700323 .. attribute:: serial_number
Paul Kehrerb2de9482014-12-11 14:54:48 -0600324
325 :type: int
326
327 The serial as a Python integer.
328
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600329 .. doctest::
330
Chelsea Winfreee295f3a2016-06-02 21:15:54 -0700331 >>> cert.serial_number
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600332 2
333
Paul Kehrerb2de9482014-12-11 14:54:48 -0600334 .. method:: public_key()
335
Alex Gaynor4c2561a2015-10-12 23:53:39 -0400336 The public key associated with the certificate.
337
338 :returns:
Alex Stapletonf79c2312014-12-30 12:50:14 +0000339 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
Paul Kehrer45efdbc2015-02-12 10:58:22 -0600340 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
341 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600342
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600343 .. doctest::
344
Alex Stapletonf79c2312014-12-30 12:50:14 +0000345 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600346 >>> public_key = cert.public_key()
Alex Stapletonf79c2312014-12-30 12:50:14 +0000347 >>> isinstance(public_key, rsa.RSAPublicKey)
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600348 True
349
Paul Kehrerb2de9482014-12-11 14:54:48 -0600350 .. attribute:: not_valid_before
351
352 :type: :class:`datetime.datetime`
353
Paul Kehrer78a81502014-12-16 14:47:52 -0600354 A naïve datetime representing the beginning of the validity period for
355 the certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600356
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600357 .. doctest::
358
359 >>> cert.not_valid_before
360 datetime.datetime(2010, 1, 1, 8, 30)
361
Paul Kehrerb2de9482014-12-11 14:54:48 -0600362 .. attribute:: not_valid_after
363
364 :type: :class:`datetime.datetime`
365
Paul Kehrer78a81502014-12-16 14:47:52 -0600366 A naïve datetime representing the end of the validity period for the
367 certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600368
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600369 .. doctest::
370
371 >>> cert.not_valid_after
372 datetime.datetime(2030, 12, 31, 8, 30)
373
Paul Kehrer719d5362015-01-01 20:03:52 -0600374 .. attribute:: issuer
375
376 .. versionadded:: 0.8
377
378 :type: :class:`Name`
379
380 The :class:`Name` of the issuer.
381
382 .. attribute:: subject
383
384 .. versionadded:: 0.8
385
386 :type: :class:`Name`
387
388 The :class:`Name` of the subject.
389
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600390 .. attribute:: signature_hash_algorithm
Paul Kehrer56da2a52015-02-11 23:35:07 -0600391
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600392 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrer56da2a52015-02-11 23:35:07 -0600393
Paul Kehrere612ec72015-02-16 14:33:35 -0600394 Returns the
Paul Kehrer71d40c62015-02-19 08:21:04 -0600395 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600396 was used in signing this certificate.
Paul Kehrer56da2a52015-02-11 23:35:07 -0600397
398 .. doctest::
399
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600400 >>> from cryptography.hazmat.primitives import hashes
401 >>> isinstance(cert.signature_hash_algorithm, hashes.SHA256)
402 True
Paul Kehrer719d5362015-01-01 20:03:52 -0600403
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800404 .. attribute:: signature_algorithm_oid
405
406 .. versionadded:: 1.6
407
408 :type: :class:`ObjectIdentifier`
409
410 Returns the :class:`ObjectIdentifier` of the signature algorithm used
411 to sign the certificate. This will be one of the OIDs from
412 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
413
414
415 .. doctest::
416
417 >>> cert.signature_algorithm_oid
418 <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)>
419
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500420 .. attribute:: extensions
421
422 :type: :class:`Extensions`
423
424 The extensions encoded in the certificate.
425
426 :raises cryptography.x509.DuplicateExtension: If more than one
427 extension of the same type is found within the certificate.
428
Paul Kehrerbed07352015-04-21 08:31:10 -0500429 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
430 contains a general name that is not supported.
431
Paul Kehrerb8968812015-05-15 09:01:34 -0700432 :raises UnicodeError: If an extension contains IDNA encoding that is
433 invalid or not compliant with IDNA 2008.
434
Paul Kehrerfa56a232015-03-17 13:14:03 -0500435 .. doctest::
436
437 >>> for ext in cert.extensions:
438 ... print(ext)
Paul Kehrer056c9dd2018-05-12 15:17:06 -0400439 <Extension(oid=<ObjectIdentifier(oid=2.5.29.35, name=authorityKeyIdentifier)>, critical=False, value=<AuthorityKeyIdentifier(key_identifier=b'\xe4}_\xd1\\\x95\x86\x08,\x05\xae\xbeu\xb6e\xa7\xd9]\xa8f', authority_cert_issuer=None, authority_cert_serial_number=None)>)>
440 <Extension(oid=<ObjectIdentifier(oid=2.5.29.14, name=subjectKeyIdentifier)>, critical=False, value=<SubjectKeyIdentifier(digest=b'X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9')>)>
Paul Kehrerb511ba82015-04-15 11:22:48 -0400441 <Extension(oid=<ObjectIdentifier(oid=2.5.29.15, name=keyUsage)>, critical=True, value=<KeyUsage(digital_signature=False, content_commitment=False, key_encipherment=False, data_encipherment=False, key_agreement=False, key_cert_sign=True, crl_sign=True, encipher_only=None, decipher_only=None)>)>
Paul Kehrer2008d9c2015-05-12 22:19:56 -0500442 <Extension(oid=<ObjectIdentifier(oid=2.5.29.32, name=certificatePolicies)>, critical=False, value=<CertificatePolicies([<PolicyInformation(policy_identifier=<ObjectIdentifier(oid=2.16.840.1.101.3.2.1.48.1, name=Unknown OID)>, policy_qualifiers=None)>])>)>
Paul Kehrerfa56a232015-03-17 13:14:03 -0500443 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
444
Paul Kehrerd91e7c12015-10-01 16:50:42 -0500445 .. attribute:: signature
446
447 .. versionadded:: 1.2
448
449 :type: bytes
450
451 The bytes of the certificate's signature.
452
Paul Kehrerd2898052015-11-03 22:00:41 +0900453 .. attribute:: tbs_certificate_bytes
Paul Kehrerd91e7c12015-10-01 16:50:42 -0500454
455 .. versionadded:: 1.2
456
457 :type: bytes
458
459 The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed
460 and then signed by the private key of the certificate's issuer. This
461 data may be used to validate a signature, but use extreme caution as
462 certificate validation is a complex problem that involves much more
463 than just signature checks.
464
Paul Kehrer838bc4a2018-10-10 12:02:55 +0800465 To validate the signature on a certificate you can do the following.
466 Note: This only verifies that the certificate was signed with the
467 private key associated with the public key provided and does not
468 perform any of the other checks needed for secure certificate
469 validation. Additionally, this example will only work for RSA public
470 keys with ``PKCS1v15`` signatures, and so it can't be used for general
471 purpose signature verification.
g_goessel16f746f2018-10-10 04:13:41 +0200472
473 .. doctest::
474
475 >>> from cryptography.hazmat.primitives.serialization import load_pem_public_key
476 >>> from cryptography.hazmat.primitives.asymmetric import padding
477 >>> issuer_public_key = load_pem_public_key(pem_issuer_public_key, default_backend())
478 >>> cert_to_check = x509.load_pem_x509_certificate(pem_data_to_check, default_backend())
479 >>> issuer_public_key.verify(
Alex Gaynor64602282018-10-09 23:03:55 -0400480 ... cert_to_check.signature,
481 ... cert_to_check.tbs_certificate_bytes,
482 ... # Depends on the algorithm used to create the certificate
483 ... padding.PKCS1v15(),
484 ... cert_to_check.signature_hash_algorithm,
g_goessel16f746f2018-10-10 04:13:41 +0200485 ... )
486
487 An
488 :class:`~cryptography.exceptions.InvalidSignature`
489 exception will be raised if the signature fails to verify.
490
Andre Carona8aded62015-05-19 20:11:57 -0400491 .. method:: public_bytes(encoding)
492
Alex Gaynord0b376b2015-07-05 13:58:12 -0400493 .. versionadded:: 1.0
494
Andre Carona8aded62015-05-19 20:11:57 -0400495 :param encoding: The
496 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
497 that will be used to serialize the certificate.
498
499 :return bytes: The data that can be written to a file or sent
500 over the network to be verified by clients.
501
Erik Trauschke2dcce902015-05-14 16:12:24 -0700502X.509 CRL (Certificate Revocation List) Object
503~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
504
505.. class:: CertificateRevocationList
506
507 .. versionadded:: 1.0
508
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700509 A CertificateRevocationList is an object representing a list of revoked
510 certificates. The object is iterable and will yield the RevokedCertificate
511 objects stored in this CRL.
512
513 .. doctest::
Erik Trauschkeb14f7d12015-10-13 09:55:39 -0700514
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700515 >>> len(crl)
516 1
Paul Kehrerdcdf9672015-10-21 20:27:28 -0500517 >>> revoked_certificate = crl[0]
518 >>> type(revoked_certificate)
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700519 <class 'cryptography.hazmat.backends.openssl.x509._RevokedCertificate'>
520 >>> for r in crl:
521 ... print(r.serial_number)
522 0
523
Erik Trauschke2dcce902015-05-14 16:12:24 -0700524 .. method:: fingerprint(algorithm)
525
526 :param algorithm: The
527 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
528 that will be used to generate the fingerprint.
529
530 :return bytes: The fingerprint using the supplied hash algorithm, as
531 bytes.
532
Erik Trauschkedc570402015-09-24 20:24:28 -0700533 .. doctest::
534
535 >>> from cryptography.hazmat.primitives import hashes
536 >>> crl.fingerprint(hashes.SHA256())
Paul Kehrer056c9dd2018-05-12 15:17:06 -0400537 b'e\xcf.\xc4:\x83?1\xdc\xf3\xfc\x95\xd7\xb3\x87\xb3\x8e\xf8\xb93!\x87\x07\x9d\x1b\xb4!\xb9\xe4W\xf4\x1f'
Erik Trauschkedc570402015-09-24 20:24:28 -0700538
Paul Kehrer5d187402018-07-16 20:49:51 +0530539 .. method:: get_revoked_certificate_by_serial_number(serial_number)
540
541 .. versionadded:: 2.3
542
543 :param serial_number: The serial as a Python integer.
544 :returns: :class:`~cryptography.x509.RevokedCertificate` if the
545 ``serial_number`` is present in the CRL or ``None`` if it
546 is not.
547
Erik Trauschke2dcce902015-05-14 16:12:24 -0700548 .. attribute:: signature_hash_algorithm
549
550 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
551
552 Returns the
553 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
554 was used in signing this CRL.
555
Erik Trauschkedc570402015-09-24 20:24:28 -0700556 .. doctest::
557
558 >>> from cryptography.hazmat.primitives import hashes
559 >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256)
560 True
561
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800562 .. attribute:: signature_algorithm_oid
563
564 .. versionadded:: 1.6
565
566 :type: :class:`ObjectIdentifier`
567
568 Returns the :class:`ObjectIdentifier` of the signature algorithm used
569 to sign the CRL. This will be one of the OIDs from
570 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
571
572 .. doctest::
573
574 >>> crl.signature_algorithm_oid
575 <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)>
576
Erik Trauschke2dcce902015-05-14 16:12:24 -0700577 .. attribute:: issuer
578
579 :type: :class:`Name`
580
581 The :class:`Name` of the issuer.
582
Erik Trauschkedc570402015-09-24 20:24:28 -0700583 .. doctest::
584
585 >>> crl.issuer
Paul Kehrer056c9dd2018-05-12 15:17:06 -0400586 <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 -0700587
Erik Trauschke2dcce902015-05-14 16:12:24 -0700588 .. attribute:: next_update
589
590 :type: :class:`datetime.datetime`
591
592 A naïve datetime representing when the next update to this CRL is
593 expected.
594
Erik Trauschkedc570402015-09-24 20:24:28 -0700595 .. doctest::
596
597 >>> crl.next_update
598 datetime.datetime(2016, 1, 1, 0, 0)
599
Erik Trauschke2dcce902015-05-14 16:12:24 -0700600 .. attribute:: last_update
601
602 :type: :class:`datetime.datetime`
603
604 A naïve datetime representing when the this CRL was last updated.
605
Erik Trauschkedc570402015-09-24 20:24:28 -0700606 .. doctest::
Erik Trauschke2dcce902015-05-14 16:12:24 -0700607
Erik Trauschkedc570402015-09-24 20:24:28 -0700608 >>> crl.last_update
609 datetime.datetime(2015, 1, 1, 0, 0)
Erik Trauschke2dcce902015-05-14 16:12:24 -0700610
611 .. attribute:: extensions
612
613 :type: :class:`Extensions`
614
615 The extensions encoded in the CRL.
616
Erik Trauschke6abe2bb2015-11-19 10:27:01 -0800617 .. attribute:: signature
618
619 .. versionadded:: 1.2
620
621 :type: bytes
622
623 The bytes of the CRL's signature.
624
625 .. attribute:: tbs_certlist_bytes
626
627 .. versionadded:: 1.2
628
629 :type: bytes
630
631 The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed
632 and then signed by the private key of the CRL's issuer. This data may be
633 used to validate a signature, but use extreme caution as CRL validation
634 is a complex problem that involves much more than just signature checks.
635
Paul Kehrer54a837d2015-12-20 23:42:32 -0600636 .. method:: public_bytes(encoding)
637
638 .. versionadded:: 1.2
639
640 :param encoding: The
641 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
642 that will be used to serialize the certificate revocation list.
643
644 :return bytes: The data that can be written to a file or sent
645 over the network and used as part of a certificate verification
646 process.
647
Vincent Pelletier6c02ee82017-08-12 22:05:00 +0900648 .. method:: is_signature_valid(public_key)
649
650 .. versionadded:: 2.1
651
Paul Kehrerf944c402017-08-12 08:52:55 -0500652 .. warning::
653
654 Checking the validity of the signature on the CRL is insufficient
655 to know if the CRL should be trusted. More details are available
656 in :rfc:`5280`.
657
Vincent Pelletier6c02ee82017-08-12 22:05:00 +0900658 Returns True if the CRL signature is correct for given public key,
659 False otherwise.
Erik Trauschke6abe2bb2015-11-19 10:27:01 -0800660
Andre Caron9bbfcea2015-05-18 20:55:29 -0400661X.509 Certificate Builder
662~~~~~~~~~~~~~~~~~~~~~~~~~
663
664.. class:: CertificateBuilder
665
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500666 .. versionadded:: 1.0
667
668 .. doctest::
669
670 >>> from cryptography import x509
671 >>> from cryptography.hazmat.backends import default_backend
672 >>> from cryptography.hazmat.primitives import hashes
673 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -0500674 >>> from cryptography.x509.oid import NameOID
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500675 >>> import datetime
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500676 >>> one_day = datetime.timedelta(1, 0, 0)
677 >>> private_key = rsa.generate_private_key(
678 ... public_exponent=65537,
679 ... key_size=2048,
680 ... backend=default_backend()
681 ... )
Cory Benfieldc47b2522015-12-07 15:25:12 +0000682 >>> public_key = private_key.public_key()
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500683 >>> builder = x509.CertificateBuilder()
684 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500685 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500686 ... ]))
687 >>> builder = builder.issuer_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500688 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500689 ... ]))
690 >>> builder = builder.not_valid_before(datetime.datetime.today() - one_day)
Alex Gaynorcdd35852018-08-05 18:17:35 -0400691 >>> builder = builder.not_valid_after(datetime.datetime.today() + (one_day * 30))
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500692 >>> builder = builder.serial_number(x509.random_serial_number())
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500693 >>> builder = builder.public_key(public_key)
694 >>> builder = builder.add_extension(
Paul Kehrer1bab7bc2017-01-18 13:44:40 +0800695 ... x509.SubjectAlternativeName(
Paul Kehrered321052017-10-11 08:11:44 +0800696 ... [x509.DNSName(u'cryptography.io')]
Paul Kehrer1bab7bc2017-01-18 13:44:40 +0800697 ... ),
698 ... critical=False
699 ... )
700 >>> builder = builder.add_extension(
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500701 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
702 ... )
703 >>> certificate = builder.sign(
704 ... private_key=private_key, algorithm=hashes.SHA256(),
705 ... backend=default_backend()
706 ... )
707 >>> isinstance(certificate, x509.Certificate)
708 True
709
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500710 .. method:: issuer_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400711
712 Sets the issuer's distinguished name.
713
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500714 :param name: The :class:`~cryptography.x509.Name` that describes the
715 issuer (CA).
Andre Caron9bbfcea2015-05-18 20:55:29 -0400716
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500717 .. method:: subject_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400718
719 Sets the subject's distinguished name.
720
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500721 :param name: The :class:`~cryptography.x509.Name` that describes the
Ian Cordasco85fc4d52015-08-01 20:29:31 -0500722 subject.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400723
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500724 .. method:: public_key(public_key)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400725
726 Sets the subject's public key.
727
Ian Cordasco8f571422015-08-02 11:31:08 -0500728 :param public_key: The subject's public key. This can be one of
729 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`,
730 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
731 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400732
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500733 .. method:: serial_number(serial_number)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400734
735 Sets the certificate's serial number (an integer). The CA's policy
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500736 determines how it attributes serial numbers to certificates. This
737 number must uniquely identify the certificate given the issuer.
738 `CABForum Guidelines`_ require entropy in the serial number
739 to provide protection against hash collision attacks. For more
740 information on secure random number generation, see
741 :doc:`/random-numbers`.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400742
743 :param serial_number: Integer number that will be used by the CA to
744 identify this certificate (most notably during certificate
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500745 revocation checking). Users should consider using
746 :func:`~cryptography.x509.random_serial_number` when possible.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400747
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500748 .. method:: not_valid_before(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400749
750 Sets the certificate's activation time. This is the time from which
751 clients can start trusting the certificate. It may be different from
752 the time at which the certificate was created.
753
Ian Cordasco17c89002015-08-02 21:13:59 -0500754 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400755 activation time for the certificate. The certificate may not be
756 trusted clients if it is used before this time.
757
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500758 .. method:: not_valid_after(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400759
760 Sets the certificate's expiration time. This is the time from which
761 clients should no longer trust the certificate. The CA's policy will
762 determine how long the certificate should remain in use.
763
Ian Cordasco17c89002015-08-02 21:13:59 -0500764 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400765 expiration time for the certificate. The certificate may not be
766 trusted clients if it is used after this time.
767
Ian Cordasco17c89002015-08-02 21:13:59 -0500768 .. method:: add_extension(extension, critical)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400769
770 Adds an X.509 extension to the certificate.
771
Paul Kehrer2c145cc2015-10-02 11:27:21 -0500772 :param extension: An extension conforming to the
773 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400774
Ian Cordasco17c89002015-08-02 21:13:59 -0500775 :param critical: Set to ``True`` if the extension must be understood and
776 handled by whoever reads the certificate.
777
Paul Kehrer9add80e2015-08-03 17:53:14 +0100778 .. method:: sign(private_key, algorithm, backend)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400779
780 Sign the certificate using the CA's private key.
781
Ian Cordascoc5e1c252015-07-31 23:33:35 -0500782 :param private_key: The
783 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
784 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
785 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
786 that will be used to sign the certificate.
787
Andre Caron9bbfcea2015-05-18 20:55:29 -0400788 :param algorithm: The
789 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
790 will be used to generate the signature.
791
Paul Kehrer9add80e2015-08-03 17:53:14 +0100792 :param backend: Backend that will be used to build the certificate.
793 Must support the
794 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
795 interface.
796
Benjamin Peterson9ed312b2015-10-12 20:51:34 -0700797 :returns: :class:`~cryptography.x509.Certificate`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400798
799
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500800X.509 CSR (Certificate Signing Request) Object
801~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600802
Paul Kehrera1a1f232015-03-15 15:34:35 -0500803.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600804
805 .. versionadded:: 0.9
806
807 .. method:: public_key()
808
Alex Gaynor4c2561a2015-10-12 23:53:39 -0400809 The public key associated with the request.
810
811 :returns:
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600812 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
813 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
814 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
815
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600816 .. doctest::
817
818 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500819 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600820 >>> isinstance(public_key, rsa.RSAPublicKey)
821 True
822
823 .. attribute:: subject
824
825 :type: :class:`Name`
826
827 The :class:`Name` of the subject.
828
829 .. attribute:: signature_hash_algorithm
830
831 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
832
833 Returns the
834 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
835 was used in signing this request.
836
837 .. doctest::
838
839 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500840 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600841 True
842
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800843 .. attribute:: signature_algorithm_oid
844
845 .. versionadded:: 1.6
846
847 :type: :class:`ObjectIdentifier`
848
849 Returns the :class:`ObjectIdentifier` of the signature algorithm used
850 to sign the request. This will be one of the OIDs from
851 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
852
853 .. doctest::
854
855 >>> csr.signature_algorithm_oid
856 <ObjectIdentifier(oid=1.2.840.113549.1.1.5, name=sha1WithRSAEncryption)>
857
Paul Kehrerc4e61942015-08-01 21:21:13 +0100858 .. attribute:: extensions
859
860 :type: :class:`Extensions`
861
862 The extensions encoded in the certificate signing request.
863
864 :raises cryptography.x509.DuplicateExtension: If more than one
Paul Kehrer24283d22015-08-01 21:31:19 +0100865 extension of the same type is found within the certificate signing request.
Paul Kehrerc4e61942015-08-01 21:21:13 +0100866
Paul Kehrerc4e61942015-08-01 21:21:13 +0100867 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
868 contains a general name that is not supported.
869
870 :raises UnicodeError: If an extension contains IDNA encoding that is
871 invalid or not compliant with IDNA 2008.
872
873
Andre Caron476c5df2015-05-18 10:23:28 -0400874 .. method:: public_bytes(encoding)
875
Alex Gaynord0b376b2015-07-05 13:58:12 -0400876 .. versionadded:: 1.0
877
Andre Caron476c5df2015-05-18 10:23:28 -0400878 :param encoding: The
879 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
880 that will be used to serialize the certificate request.
881
882 :return bytes: The data that can be written to a file or sent
883 over the network to be signed by the certificate
884 authority.
885
Paul Kehrerab209392015-12-01 14:50:31 -0600886 .. attribute:: signature
887
888 .. versionadded:: 1.2
889
890 :type: bytes
891
892 The bytes of the certificate signing request's signature.
893
894 .. attribute:: tbs_certrequest_bytes
895
896 .. versionadded:: 1.2
897
898 :type: bytes
899
900 The DER encoded bytes payload (as defined by :rfc:`2986`) that is
901 hashed and then signed by the private key (corresponding to the public
902 key embedded in the CSR). This data may be used to validate the CSR
903 signature.
904
Joern Heisslerfbda8ce2016-01-18 00:24:44 +0100905 .. attribute:: is_signature_valid
Joern Heissler1bd77e22016-01-13 22:51:37 +0100906
907 .. versionadded:: 1.3
908
Joern Heisslerfbda8ce2016-01-18 00:24:44 +0100909 Returns True if the CSR signature is correct, False otherwise.
Joern Heissler1bd77e22016-01-13 22:51:37 +0100910
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600911X.509 Certificate Revocation List Builder
912~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
913
914.. class:: CertificateRevocationListBuilder
915
916 .. versionadded:: 1.2
917
918 .. doctest::
919
920 >>> from cryptography import x509
921 >>> from cryptography.hazmat.backends import default_backend
922 >>> from cryptography.hazmat.primitives import hashes
923 >>> from cryptography.hazmat.primitives.asymmetric import rsa
924 >>> from cryptography.x509.oid import NameOID
925 >>> import datetime
926 >>> one_day = datetime.timedelta(1, 0, 0)
927 >>> private_key = rsa.generate_private_key(
928 ... public_exponent=65537,
929 ... key_size=2048,
930 ... backend=default_backend()
931 ... )
932 >>> builder = x509.CertificateRevocationListBuilder()
933 >>> builder = builder.issuer_name(x509.Name([
934 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io CA'),
935 ... ]))
936 >>> builder = builder.last_update(datetime.datetime.today())
937 >>> builder = builder.next_update(datetime.datetime.today() + one_day)
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600938 >>> revoked_cert = x509.RevokedCertificateBuilder().serial_number(
939 ... 333
940 ... ).revocation_date(
941 ... datetime.datetime.today()
942 ... ).build(default_backend())
943 >>> builder = builder.add_revoked_certificate(revoked_cert)
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600944 >>> crl = builder.sign(
945 ... private_key=private_key, algorithm=hashes.SHA256(),
946 ... backend=default_backend()
947 ... )
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600948 >>> len(crl)
949 1
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600950
951 .. method:: issuer_name(name)
952
953 Sets the issuer's distinguished name.
954
955 :param name: The :class:`~cryptography.x509.Name` that describes the
956 issuer (CA).
957
958 .. method:: last_update(time)
959
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600960 Sets this CRL's activation time. This is the time from which
961 clients can start trusting this CRL. It may be different from
962 the time at which this CRL was created. This is also known as the
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600963 ``thisUpdate`` time.
964
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600965 :param time: The :class:`datetime.datetime` object (in UTC) that marks
966 the activation time for this CRL. The CRL may not be trusted if it
967 is used before this time.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600968
969 .. method:: next_update(time)
970
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600971 Sets this CRL's next update time. This is the time by which
972 a new CRL will be issued. The CA is allowed to issue a new CRL before
973 this date, however clients are not required to check for it.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600974
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600975 :param time: The :class:`datetime.datetime` object (in UTC) that marks
976 the next update time for this CRL.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600977
Paul Kehrer426b48d2015-12-24 20:50:43 -0600978 .. method:: add_extension(extension, critical)
979
980 Adds an X.509 extension to this CRL.
981
982 :param extension: An extension with the
983 :class:`~cryptography.x509.ExtensionType` interface.
984
985 :param critical: Set to ``True`` if the extension must be understood and
986 handled by whoever reads the CRL.
987
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600988 .. method:: add_revoked_certificate(revoked_certificate)
989
990 Adds a revoked certificate to this CRL.
991
992 :param revoked_certificate: An instance of
993 :class:`~cryptography.x509.RevokedCertificate`. These can be
994 obtained from an existing CRL or created with
995 :class:`~cryptography.x509.RevokedCertificateBuilder`.
996
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600997 .. method:: sign(private_key, algorithm, backend)
998
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600999 Sign this CRL using the CA's private key.
Paul Kehrerbfac2d12015-12-19 23:32:08 -06001000
1001 :param private_key: The
1002 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
1003 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
1004 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
1005 that will be used to sign the certificate.
1006
1007 :param algorithm: The
1008 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
1009 will be used to generate the signature.
1010
1011 :param backend: Backend that will be used to build the CRL.
1012 Must support the
1013 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1014 interface.
1015
1016 :returns: :class:`~cryptography.x509.CertificateRevocationList`
1017
Erik Trauschke2dcce902015-05-14 16:12:24 -07001018X.509 Revoked Certificate Object
Erik Trauschkec5a8d172015-05-28 10:24:25 -07001019~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Erik Trauschke2dcce902015-05-14 16:12:24 -07001020
1021.. class:: RevokedCertificate
1022
1023 .. versionadded:: 1.0
1024
1025 .. attribute:: serial_number
1026
1027 :type: :class:`int`
1028
1029 An integer representing the serial number of the revoked certificate.
1030
Erik Trauschkedc570402015-09-24 20:24:28 -07001031 .. doctest::
1032
Erik Trauschke3cdabaf2015-10-13 09:42:53 -07001033 >>> revoked_certificate.serial_number
Erik Trauschkedc570402015-09-24 20:24:28 -07001034 0
1035
Erik Trauschke2dcce902015-05-14 16:12:24 -07001036 .. attribute:: revocation_date
1037
1038 :type: :class:`datetime.datetime`
1039
1040 A naïve datetime representing the date this certificates was revoked.
1041
Erik Trauschkedc570402015-09-24 20:24:28 -07001042 .. doctest::
1043
Erik Trauschke77f5a252015-10-14 08:06:38 -07001044 >>> revoked_certificate.revocation_date
Erik Trauschkedc570402015-09-24 20:24:28 -07001045 datetime.datetime(2015, 1, 1, 0, 0)
1046
Erik Trauschke2dcce902015-05-14 16:12:24 -07001047 .. attribute:: extensions
1048
1049 :type: :class:`Extensions`
1050
1051 The extensions encoded in the revoked certificate.
Andre Caron476c5df2015-05-18 10:23:28 -04001052
Erik Trauschkedc570402015-09-24 20:24:28 -07001053 .. doctest::
1054
Erik Trauschke77f5a252015-10-14 08:06:38 -07001055 >>> for ext in revoked_certificate.extensions:
Erik Trauschkedc570402015-09-24 20:24:28 -07001056 ... print(ext)
Paul Kehrer23c0bbc2015-12-25 22:35:19 -06001057 <Extension(oid=<ObjectIdentifier(oid=2.5.29.24, name=invalidityDate)>, critical=False, value=<InvalidityDate(invalidity_date=2015-01-01 00:00:00)>)>
Paul Kehrer7058ece2015-12-25 22:28:29 -06001058 <Extension(oid=<ObjectIdentifier(oid=2.5.29.21, name=cRLReason)>, critical=False, value=<CRLReason(reason=ReasonFlags.key_compromise)>)>
Erik Trauschkedc570402015-09-24 20:24:28 -07001059
Paul Kehrerc33ffd72015-12-25 10:59:22 -06001060X.509 Revoked Certificate Builder
1061~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1062
1063.. class:: RevokedCertificateBuilder
1064
1065 This class is used to create :class:`~cryptography.x509.RevokedCertificate`
1066 objects that can be used with the
1067 :class:`~cryptography.x509.CertificateRevocationListBuilder`.
1068
1069 .. versionadded:: 1.2
1070
1071 .. doctest::
1072
1073 >>> from cryptography import x509
1074 >>> from cryptography.hazmat.backends import default_backend
1075 >>> import datetime
1076 >>> builder = x509.RevokedCertificateBuilder()
1077 >>> builder = builder.revocation_date(datetime.datetime.today())
1078 >>> builder = builder.serial_number(3333)
1079 >>> revoked_certificate = builder.build(default_backend())
1080 >>> isinstance(revoked_certificate, x509.RevokedCertificate)
1081 True
1082
1083 .. method:: serial_number(serial_number)
1084
1085 Sets the revoked certificate's serial number.
1086
1087 :param serial_number: Integer number that is used to identify the
1088 revoked certificate.
1089
1090 .. method:: revocation_date(time)
1091
1092 Sets the certificate's revocation date.
1093
1094 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
1095 revocation time for the certificate.
1096
Paul Kehrere5f152b2015-12-25 23:55:47 -06001097 .. method:: add_extension(extension, critical)
1098
1099 Adds an X.509 extension to this revoked certificate.
1100
1101 :param extension: An instance of one of the
1102 :ref:`CRL entry extensions <crl_entry_extensions>`.
1103
1104 :param critical: Set to ``True`` if the extension must be understood and
1105 handled.
1106
Paul Kehrerc33ffd72015-12-25 10:59:22 -06001107 .. method:: build(backend)
1108
1109 Create a revoked certificate object using the provided backend.
1110
1111 :param backend: Backend that will be used to build the revoked
1112 certificate. Must support the
1113 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1114 interface.
1115
1116 :returns: :class:`~cryptography.x509.RevokedCertificate`
1117
Andre Caron0ef595f2015-05-18 13:53:43 -04001118X.509 CSR (Certificate Signing Request) Builder Object
1119~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1120
1121.. class:: CertificateSigningRequestBuilder
1122
Andre Carond259ee52015-06-02 23:47:11 -04001123 .. versionadded:: 1.0
1124
1125 .. doctest::
1126
1127 >>> from cryptography import x509
1128 >>> from cryptography.hazmat.backends import default_backend
1129 >>> from cryptography.hazmat.primitives import hashes
1130 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -05001131 >>> from cryptography.x509.oid import NameOID
Andre Carond259ee52015-06-02 23:47:11 -04001132 >>> private_key = rsa.generate_private_key(
1133 ... public_exponent=65537,
1134 ... key_size=2048,
1135 ... backend=default_backend()
1136 ... )
1137 >>> builder = x509.CertificateSigningRequestBuilder()
Andre Carona9a51172015-06-06 20:18:44 -04001138 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -05001139 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Andre Carond259ee52015-06-02 23:47:11 -04001140 ... ]))
Ian Cordascof06b6be2015-06-21 10:09:18 -05001141 >>> builder = builder.add_extension(
Ian Cordasco0112b022015-06-16 17:51:18 -05001142 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
Andre Caron472fd692015-06-06 20:04:44 -04001143 ... )
Andre Carond259ee52015-06-02 23:47:11 -04001144 >>> request = builder.sign(
Alex Gaynorde9e5842015-06-26 20:11:23 -04001145 ... private_key, hashes.SHA256(), default_backend()
Andre Carond259ee52015-06-02 23:47:11 -04001146 ... )
1147 >>> isinstance(request, x509.CertificateSigningRequest)
1148 True
1149
Andre Carona9a51172015-06-06 20:18:44 -04001150 .. method:: subject_name(name)
Andre Caron0ef595f2015-05-18 13:53:43 -04001151
Andre Caron341ff852015-06-06 20:14:31 -04001152 :param name: The :class:`~cryptography.x509.Name` of the certificate
1153 subject.
1154 :returns: A new
1155 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001156
Ian Cordascof06b6be2015-06-21 10:09:18 -05001157 .. method:: add_extension(extension, critical)
Andre Caron0ef595f2015-05-18 13:53:43 -04001158
Paul Kehrer2c145cc2015-10-02 11:27:21 -05001159 :param extension: An extension conforming to the
1160 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron472fd692015-06-06 20:04:44 -04001161 :param critical: Set to `True` if the extension must be understood and
1162 handled by whoever reads the certificate.
Andre Caron341ff852015-06-06 20:14:31 -04001163 :returns: A new
1164 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001165
Alex Gaynorb3b0fbe2015-06-26 19:57:18 -04001166 .. method:: sign(private_key, algorithm, backend)
Andre Caron0ef595f2015-05-18 13:53:43 -04001167
1168 :param backend: Backend that will be used to sign the request.
1169 Must support the
1170 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1171 interface.
1172
1173 :param private_key: The
Andre Caron24f9bf42015-06-06 20:14:54 -04001174 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
1175 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
1176 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
Andre Caron0ef595f2015-05-18 13:53:43 -04001177 that will be used to sign the request. When the request is
1178 signed by a certificate authority, the private key's associated
1179 public key will be stored in the resulting certificate.
1180
1181 :param algorithm: The
1182 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
1183 that will be used to generate the request signature.
1184
Andre Caron341ff852015-06-06 20:14:31 -04001185 :returns: A new
1186 :class:`~cryptography.x509.CertificateSigningRequest`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001187
1188
Paul Kehrer719d5362015-01-01 20:03:52 -06001189.. class:: Name
1190
1191 .. versionadded:: 0.8
1192
Paul Kehrer53d8d492015-02-13 18:47:30 -06001193 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -06001194 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -06001195 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -06001196 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
1197 ``CN=mydomain.com, O=My Org, C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -06001198
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001199 Technically, a Name is a list of *sets* of attributes, called *Relative
1200 Distinguished Names* or *RDNs*, although multi-valued RDNs are rarely
1201 encountered. The iteration order of values within a multi-valued RDN is
Marti Raudsepp9e1873a2018-07-09 16:11:18 +03001202 preserved. If you need to handle multi-valued RDNs, the ``rdns`` property
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001203 gives access to an ordered list of :class:`RelativeDistinguishedName`
1204 objects.
1205
1206 A Name can be initialized with an iterable of :class:`NameAttribute` (the
1207 common case where each RDN has a single attribute) or an iterable of
1208 :class:`RelativeDistinguishedName` objects (in the rare case of
1209 multi-valued RDNs).
1210
Paul Kehrer53d8d492015-02-13 18:47:30 -06001211 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -06001212
Paul Kehrer8b21a4a2015-02-14 07:56:36 -06001213 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -06001214 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -06001215 >>> for attribute in cert.subject:
1216 ... print(attribute)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001217 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')>
1218 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value='Test Certificates 2011')>
1219 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -06001220
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001221 .. attribute:: rdns
1222
1223 .. versionadded:: 1.6
1224
1225 :type: list of :class:`RelativeDistinguishedName`
1226
Paul Kehrere901d642015-02-11 18:50:58 -06001227 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -06001228
Paul Kehrere901d642015-02-11 18:50:58 -06001229 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -06001230
Paul Kehrere901d642015-02-11 18:50:58 -06001231 :returns: A list of :class:`NameAttribute` instances that match the
1232 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -06001233
1234 .. doctest::
1235
Paul Kehrere27f6582015-08-10 18:33:38 -05001236 >>> cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001237 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -06001238
Paul Kehrer3a15b032016-11-13 14:30:11 -08001239 .. method:: public_bytes(backend)
1240
1241 .. versionadded:: 1.6
1242
1243 :param backend: A backend supporting the
1244 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1245 interface.
1246
1247 :return bytes: The DER encoded name.
1248
Paul Kehrere76cd272014-12-14 19:00:51 -06001249.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -10001250
1251 .. versionadded:: 0.7
1252
1253 An enumeration for X.509 versions.
1254
1255 .. attribute:: v1
1256
1257 For version 1 X.509 certificates.
1258
1259 .. attribute:: v3
1260
1261 For version 3 X.509 certificates.
1262
Paul Kehrer806bfb22015-02-02 17:05:24 -06001263.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001264
1265 .. versionadded:: 0.8
1266
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001267 An X.509 name consists of a list of :class:`RelativeDistinguishedName`
1268 instances, which consist of a set of :class:`NameAttribute` instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001269
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001270 .. attribute:: oid
1271
1272 :type: :class:`ObjectIdentifier`
1273
1274 The attribute OID.
1275
1276 .. attribute:: value
1277
Paul Kehrerd5852cb2015-01-30 08:25:23 -06001278 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001279
1280 The value of the attribute.
1281
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001282
1283.. class:: RelativeDistinguishedName(attributes)
1284
1285 .. versionadded:: 1.6
1286
1287 A relative distinguished name is a non-empty set of name attributes. The
Marti Raudsepp9e1873a2018-07-09 16:11:18 +03001288 object is iterable to get every attribute, preserving the original order.
1289 Passing duplicate attributes to the constructor raises ``ValueError``.
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001290
1291 .. method:: get_attributes_for_oid(oid)
1292
1293 :param oid: An :class:`ObjectIdentifier` instance.
1294
1295 :returns: A list of :class:`NameAttribute` instances that match the OID
1296 provided. The list should contain zero or one values.
1297
1298
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001299.. class:: ObjectIdentifier
1300
1301 .. versionadded:: 0.8
1302
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001303 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -06001304 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001305
Paul Kehrerd44f9a62015-02-04 14:47:34 -06001306 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001307
1308 :type: :class:`str`
1309
Paul Kehrerfedf4f42015-02-06 11:22:07 -06001310 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001311
Paul Kehrer31bdf792015-03-25 14:11:00 -05001312.. _general_name_classes:
1313
1314General Name Classes
1315~~~~~~~~~~~~~~~~~~~~
1316
1317.. class:: GeneralName
1318
1319 .. versionadded:: 0.9
1320
1321 This is the generic interface that all the following classes are registered
1322 against.
1323
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001324.. class:: RFC822Name(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001325
1326 .. versionadded:: 0.9
1327
Paul Kehrere885bd62017-10-11 20:29:23 +08001328 .. versionchanged:: 2.1
Paul Kehrer3e15ca52017-08-01 21:21:19 -05001329
Paul Kehrere885bd62017-10-11 20:29:23 +08001330 .. warning::
1331
1332 Starting with version 2.1 :term:`U-label` input is deprecated. If
1333 passing an internationalized domain name (IDN) you should first IDNA
1334 encode the value and then pass the result as a string. Accessing
1335 ``value`` will return the :term:`A-label` encoded form even if you pass
1336 a U-label. This breaks backwards compatibility, but only for
1337 internationalized domain names.
1338
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001339
1340 This corresponds to an email address. For example, ``user@example.com``.
1341
Paul Kehrere885bd62017-10-11 20:29:23 +08001342 :param value: The email address. If the address contains an
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001343 internationalized domain name then it must be encoded to an
Paul Kehrere885bd62017-10-11 20:29:23 +08001344 :term:`A-label` string before being passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001345
Paul Kehrer31bdf792015-03-25 14:11:00 -05001346 .. attribute:: value
1347
1348 :type: :term:`text`
1349
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001350.. class:: DNSName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001351
1352 .. versionadded:: 0.9
1353
Paul Kehrere885bd62017-10-11 20:29:23 +08001354 .. versionchanged:: 2.1
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001355
Paul Kehrere885bd62017-10-11 20:29:23 +08001356 .. warning::
1357
1358 Starting with version 2.1 :term:`U-label` input is deprecated. If
1359 passing an internationalized domain name (IDN) you should first IDNA
1360 encode the value and then pass the result as a string. Accessing
1361 ``value`` will return the :term:`A-label` encoded form even if you pass
1362 a U-label. This breaks backwards compatibility, but only for
1363 internationalized domain names.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001364
Paul Kehrer31bdf792015-03-25 14:11:00 -05001365 This corresponds to a domain name. For example, ``cryptography.io``.
1366
Paul Kehrere885bd62017-10-11 20:29:23 +08001367 :param value: The domain name. If it is an internationalized domain
1368 name then it must be encoded to an :term:`A-label` string before being
1369 passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001370
Paul Kehrere885bd62017-10-11 20:29:23 +08001371 :type: :term:`text`
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001372
Paul Kehrer31bdf792015-03-25 14:11:00 -05001373 .. attribute:: value
1374
1375 :type: :term:`text`
1376
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001377.. class:: DirectoryName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001378
1379 .. versionadded:: 0.9
1380
1381 This corresponds to a directory name.
1382
1383 .. attribute:: value
1384
1385 :type: :class:`Name`
1386
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001387.. class:: UniformResourceIdentifier(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001388
1389 .. versionadded:: 0.9
1390
Paul Kehrere885bd62017-10-11 20:29:23 +08001391 .. versionchanged:: 2.1
Paul Kehrerb8ef82e2015-04-22 16:04:24 -05001392
Paul Kehrere885bd62017-10-11 20:29:23 +08001393 .. warning::
1394
1395 Starting with version 2.1 :term:`U-label` input is deprecated. If
1396 passing an internationalized domain name (IDN) you should first IDNA
1397 encode the value and then pass the result as a string. Accessing
1398 ``value`` will return the :term:`A-label` encoded form even if you pass
1399 a U-label. This breaks backwards compatibility, but only for
1400 internationalized domain names.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001401
1402 This corresponds to a uniform resource identifier. For example,
1403 ``https://cryptography.io``.
1404
Paul Kehrere885bd62017-10-11 20:29:23 +08001405 :param value: The URI. If it contains an internationalized domain
1406 name then it must be encoded to an :term:`A-label` string before
1407 being passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001408
Paul Kehrer31bdf792015-03-25 14:11:00 -05001409 .. attribute:: value
1410
1411 :type: :term:`text`
1412
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001413.. class:: IPAddress(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001414
1415 .. versionadded:: 0.9
1416
1417 This corresponds to an IP address.
1418
1419 .. attribute:: value
1420
Paul Kehrereb177932015-05-17 18:33:33 -07001421 :type: :class:`~ipaddress.IPv4Address`,
1422 :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
1423 or :class:`~ipaddress.IPv6Network`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001424
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001425.. class:: RegisteredID(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001426
1427 .. versionadded:: 0.9
1428
1429 This corresponds to a registered ID.
1430
1431 .. attribute:: value
1432
1433 :type: :class:`ObjectIdentifier`
1434
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001435.. class:: OtherName(type_id, value)
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001436
1437 .. versionadded:: 1.0
1438
Joshua Tauberer18b6fc82015-07-05 21:44:51 +00001439 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 +00001440
1441 .. attribute:: type_id
1442
1443 :type: :class:`ObjectIdentifier`
1444
1445 .. attribute:: value
1446
Paul Kehreredfedc12018-09-14 18:24:20 -04001447 :type: bytes
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001448
Paul Kehrer8cf26422015-03-21 09:50:24 -05001449X.509 Extensions
1450~~~~~~~~~~~~~~~~
1451
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001452.. class:: Extensions
1453
1454 .. versionadded:: 0.9
1455
1456 An X.509 Extensions instance is an ordered list of extensions. The object
1457 is iterable to get every extension.
1458
Paul Kehrerfa56a232015-03-17 13:14:03 -05001459 .. method:: get_extension_for_oid(oid)
1460
1461 :param oid: An :class:`ObjectIdentifier` instance.
1462
1463 :returns: An instance of the extension class.
1464
1465 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1466 not have the extension requested.
1467
Paul Kehrerfa56a232015-03-17 13:14:03 -05001468 .. doctest::
1469
Paul Kehrere27f6582015-08-10 18:33:38 -05001470 >>> from cryptography.x509.oid import ExtensionOID
1471 >>> cert.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS)
Paul Kehrerfa56a232015-03-17 13:14:03 -05001472 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1473
Phoebe Queen019b7f82015-08-12 03:52:03 +01001474 .. method:: get_extension_for_class(extclass)
1475
Phoebe Queen6a603eb2015-08-12 14:14:49 +01001476 .. versionadded:: 1.1
1477
Phoebe Queen019b7f82015-08-12 03:52:03 +01001478 :param extclass: An extension class.
1479
1480 :returns: An instance of the extension class.
1481
1482 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1483 not have the extension requested.
1484
1485 .. doctest::
1486
1487 >>> from cryptography import x509
1488 >>> cert.extensions.get_extension_for_class(x509.BasicConstraints)
1489 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1490
Paul Kehrer8cf26422015-03-21 09:50:24 -05001491.. class:: Extension
1492
1493 .. versionadded:: 0.9
1494
Paul Kehrer85894662015-03-22 13:19:31 -05001495 .. attribute:: oid
1496
1497 :type: :class:`ObjectIdentifier`
1498
Paul Kehrere27f6582015-08-10 18:33:38 -05001499 One of the :class:`~cryptography.x509.oid.ExtensionOID` OIDs.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001500
1501 .. attribute:: critical
1502
1503 :type: bool
1504
Paul Kehrer58b75692015-03-22 23:24:58 -05001505 Determines whether a given extension is critical or not. :rfc:`5280`
1506 requires that "A certificate-using system MUST reject the certificate
1507 if it encounters a critical extension it does not recognize or a
1508 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -05001509
Paul Kehrer85894662015-03-22 13:19:31 -05001510 .. attribute:: value
1511
1512 Returns an instance of the extension type corresponding to the OID.
1513
Paul Kehrer14f0bd02015-08-06 11:55:18 +01001514.. class:: ExtensionType
1515
1516 .. versionadded:: 1.0
1517
1518 This is the interface against which all the following extension types are
1519 registered.
1520
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001521.. 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 -05001522
1523 .. versionadded:: 0.9
1524
1525 The key usage extension defines the purpose of the key contained in the
1526 certificate. The usage restriction might be employed when a key that could
Paul Kehrerb33de932015-08-06 23:41:05 +01001527 be used for more than one operation is to be restricted.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001528
Paul Kehrer822f3d32015-08-06 11:47:32 +01001529 .. attribute:: oid
1530
1531 .. versionadded:: 1.0
1532
1533 :type: :class:`ObjectIdentifier`
1534
Paul Kehrere27f6582015-08-10 18:33:38 -05001535 Returns :attr:`~cryptography.x509.oid.ExtensionOID.KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001536
Paul Kehrercecbbba2015-03-30 14:58:38 -05001537 .. attribute:: digital_signature
1538
1539 :type: bool
1540
Paul Kehrer738407b2015-04-01 22:39:02 -05001541 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001542 digital signatures, other than signatures on certificates
1543 (``key_cert_sign``) and CRLs (``crl_sign``).
1544
1545 .. attribute:: content_commitment
1546
1547 :type: bool
1548
Paul Kehrer738407b2015-04-01 22:39:02 -05001549 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001550 digital signatures, other than signatures on certificates
1551 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
1552 non-repudiation service that protects against the signing entity
1553 falsely denying some action. In the case of later conflict, a
1554 reliable third party may determine the authenticity of the signed
1555 data. This was called ``non_repudiation`` in older revisions of the
1556 X.509 specification.
1557
1558 .. attribute:: key_encipherment
1559
1560 :type: bool
1561
Paul Kehrer738407b2015-04-01 22:39:02 -05001562 This purpose is set to true when the subject public key is used for
1563 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001564
1565 .. attribute:: data_encipherment
1566
1567 :type: bool
1568
Paul Kehrer738407b2015-04-01 22:39:02 -05001569 This purpose is set to true when the subject public key is used for
1570 directly enciphering raw user data without the use of an intermediate
1571 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001572
1573 .. attribute:: key_agreement
1574
1575 :type: bool
1576
Paul Kehrer738407b2015-04-01 22:39:02 -05001577 This purpose is set to true when the subject public key is used for key
1578 agreement. For example, when a Diffie-Hellman key is to be used for
1579 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001580
1581 .. attribute:: key_cert_sign
1582
1583 :type: bool
1584
Paul Kehrer738407b2015-04-01 22:39:02 -05001585 This purpose is set to true when the subject public key is used for
1586 verifying signatures on public key certificates. If this purpose is set
1587 to true then ``ca`` must be true in the :class:`BasicConstraints`
1588 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001589
1590 .. attribute:: crl_sign
1591
1592 :type: bool
1593
Paul Kehrer738407b2015-04-01 22:39:02 -05001594 This purpose is set to true when the subject public key is used for
1595 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001596
1597 .. attribute:: encipher_only
1598
1599 :type: bool
1600
Paul Kehrer738407b2015-04-01 22:39:02 -05001601 When this purposes is set to true and the ``key_agreement`` purpose is
1602 also set, the subject public key may be used only for enciphering data
1603 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001604
1605 :raises ValueError: This is raised if accessed when ``key_agreement``
1606 is false.
1607
1608 .. attribute:: decipher_only
1609
1610 :type: bool
1611
Paul Kehrer738407b2015-04-01 22:39:02 -05001612 When this purposes is set to true and the ``key_agreement`` purpose is
1613 also set, the subject public key may be used only for deciphering data
1614 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001615
1616 :raises ValueError: This is raised if accessed when ``key_agreement``
1617 is false.
1618
1619
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001620.. class:: BasicConstraints(ca, path_length)
Paul Kehrer8cf26422015-03-21 09:50:24 -05001621
1622 .. versionadded:: 0.9
1623
Paul Kehrer85894662015-03-22 13:19:31 -05001624 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -05001625 certificate is allowed to sign additional certificates and what path
Paul Kehrerb33de932015-08-06 23:41:05 +01001626 length restrictions may exist.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001627
Paul Kehrer822f3d32015-08-06 11:47:32 +01001628 .. attribute:: oid
1629
1630 .. versionadded:: 1.0
1631
1632 :type: :class:`ObjectIdentifier`
1633
Paul Kehrere27f6582015-08-10 18:33:38 -05001634 Returns :attr:`~cryptography.x509.oid.ExtensionOID.BASIC_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001635
Paul Kehrer8cf26422015-03-21 09:50:24 -05001636 .. attribute:: ca
1637
1638 :type: bool
1639
1640 Whether the certificate can sign certificates.
1641
1642 .. attribute:: path_length
1643
Paul Kehrerfd1444c2015-03-21 19:47:05 -05001644 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -05001645
1646 The maximum path length for certificates subordinate to this
1647 certificate. This attribute only has meaning if ``ca`` is true.
1648 If ``ca`` is true then a path length of None means there's no
1649 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -04001650 If it is zero or greater then it defines the maximum length for a
1651 subordinate CA's certificate chain. For example, a ``path_length`` of 1
1652 means the certificate can sign a subordinate CA, but the subordinate CA
1653 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001654
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001655.. class:: ExtendedKeyUsage(usages)
Paul Kehrerffa2a152015-03-31 08:18:25 -05001656
1657 .. versionadded:: 0.9
1658
1659 This extension indicates one or more purposes for which the certified
1660 public key may be used, in addition to or in place of the basic
1661 purposes indicated in the key usage extension. The object is
Paul Kehrere27f6582015-08-10 18:33:38 -05001662 iterable to obtain the list of
1663 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs present.
Paul Kehrerffa2a152015-03-31 08:18:25 -05001664
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001665 :param list usages: A list of
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001666 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs.
1667
Paul Kehrer822f3d32015-08-06 11:47:32 +01001668 .. attribute:: oid
1669
1670 .. versionadded:: 1.0
1671
1672 :type: :class:`ObjectIdentifier`
1673
Paul Kehrere27f6582015-08-10 18:33:38 -05001674 Returns :attr:`~cryptography.x509.oid.ExtensionOID.EXTENDED_KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001675
1676
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001677.. class:: OCSPNoCheck()
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001678
Paul Kehrer506a2152015-05-26 08:01:18 -05001679 .. versionadded:: 1.0
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001680
1681 This presence of this extension indicates that an OCSP client can trust a
1682 responder for the lifetime of the responder's certificate. CAs issuing
1683 such a certificate should realize that a compromise of the responder's key
1684 is as serious as the compromise of a CA key used to sign CRLs, at least for
1685 the validity period of this certificate. CA's may choose to issue this type
1686 of certificate with a very short lifetime and renew it frequently. This
1687 extension is only relevant when the certificate is an authorized OCSP
1688 responder.
1689
Paul Kehrer822f3d32015-08-06 11:47:32 +01001690 .. attribute:: oid
1691
1692 .. versionadded:: 1.0
1693
1694 :type: :class:`ObjectIdentifier`
1695
Paul Kehrere27f6582015-08-10 18:33:38 -05001696 Returns :attr:`~cryptography.x509.oid.ExtensionOID.OCSP_NO_CHECK`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001697
Paul Kehrer5d669662017-09-11 09:16:34 +08001698
1699.. class:: TLSFeature(features)
1700
1701 .. versionadded:: 2.1
1702
1703 The TLS Feature extension is defined in :rfc:`7633` and is used in
1704 certificates for OCSP Must-Staple. The object is iterable to get every
1705 element.
1706
1707 :param list features: A list of features to enable from the
1708 :class:`~cryptography.x509.TLSFeatureType` enum. At this time only
1709 ``status_request`` or ``status_request_v2`` are allowed.
1710
1711 .. attribute:: oid
1712
1713 :type: :class:`ObjectIdentifier`
1714
1715 Returns :attr:`~cryptography.x509.oid.ExtensionOID.TLS_FEATURE`.
1716
1717.. class:: TLSFeatureType
1718
1719 .. versionadded:: 2.1
1720
1721 An enumeration of TLS Feature types.
1722
1723 .. attribute:: status_request
1724
1725 This feature type is defined in :rfc:`6066` and, when embedded in
1726 an X.509 certificate, signals to the client that it should require
1727 a stapled OCSP response in the TLS handshake. Commonly known as OCSP
1728 Must-Staple in certificates.
1729
1730 .. attribute:: status_request_v2
1731
1732 This feature type is defined in :rfc:`6961`. This value is not
1733 commonly used and if you want to enable OCSP Must-Staple you should
1734 use ``status_request``.
1735
1736
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001737.. class:: NameConstraints(permitted_subtrees, excluded_subtrees)
Paul Kehrere0017be2015-05-17 20:39:40 -06001738
1739 .. versionadded:: 1.0
1740
1741 The name constraints extension, which only has meaning in a CA certificate,
1742 defines a name space within which all subject names in certificates issued
1743 beneath the CA certificate must (or must not) be in. For specific details
1744 on the way this extension should be processed see :rfc:`5280`.
1745
Paul Kehrer822f3d32015-08-06 11:47:32 +01001746 .. attribute:: oid
1747
1748 .. versionadded:: 1.0
1749
1750 :type: :class:`ObjectIdentifier`
1751
Paul Kehrere27f6582015-08-10 18:33:38 -05001752 Returns :attr:`~cryptography.x509.oid.ExtensionOID.NAME_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001753
Paul Kehrere0017be2015-05-17 20:39:40 -06001754 .. attribute:: permitted_subtrees
1755
1756 :type: list of :class:`GeneralName` objects or None
1757
1758 The set of permitted name patterns. If a name matches this and an
1759 element in ``excluded_subtrees`` it is invalid. At least one of
1760 ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None.
1761
1762 .. attribute:: excluded_subtrees
1763
1764 :type: list of :class:`GeneralName` objects or None
1765
1766 Any name matching a restriction in the ``excluded_subtrees`` field is
1767 invalid regardless of information appearing in the
1768 ``permitted_subtrees``. At least one of ``permitted_subtrees`` and
1769 ``excluded_subtrees`` will be non-None.
1770
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001771.. class:: AuthorityKeyIdentifier(key_identifier, authority_cert_issuer, authority_cert_serial_number)
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001772
1773 .. versionadded:: 0.9
1774
1775 The authority key identifier extension provides a means of identifying the
1776 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001777 This extension is typically used to assist in determining the appropriate
1778 certificate chain. For more information about generation and use of this
1779 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001780
Paul Kehrer822f3d32015-08-06 11:47:32 +01001781 .. attribute:: oid
1782
1783 .. versionadded:: 1.0
1784
1785 :type: :class:`ObjectIdentifier`
1786
Paul Kehrere27f6582015-08-10 18:33:38 -05001787 Returns
1788 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001789
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001790 .. attribute:: key_identifier
1791
1792 :type: bytes
1793
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001794 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001795 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001796
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001797 .. attribute:: authority_cert_issuer
1798
Thom Dixon488c0482018-05-18 03:55:29 -07001799 :type: A list of :class:`GeneralName` instances or None
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001800
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001801 The :class:`Name` of the issuer's issuer.
1802
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001803 .. attribute:: authority_cert_serial_number
1804
1805 :type: int or None
1806
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001807 The serial number of the issuer's issuer.
1808
Paul Kehrer253929a2015-08-05 17:30:39 +01001809 .. classmethod:: from_issuer_public_key(public_key)
1810
1811 .. versionadded:: 1.0
1812
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001813 .. note::
1814
1815 This method should be used if the issuer certificate does not
1816 contain a :class:`~cryptography.x509.SubjectKeyIdentifier`.
1817 Otherwise, use
1818 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier`.
1819
Paul Kehrer253929a2015-08-05 17:30:39 +01001820 Creates a new AuthorityKeyIdentifier instance using the public key
1821 provided to generate the appropriate digest. This should be the
Paul Kehrer26ac47f2015-08-08 15:20:52 -05001822 **issuer's public key**. The resulting object will contain
1823 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1824 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1825 and
1826 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1827 will be None.
1828 The generated ``key_identifier`` is the SHA1 hash of the ``subjectPublicKey``
1829 ASN.1 bit string. This is the first recommendation in :rfc:`5280`
Paul Kehrer253929a2015-08-05 17:30:39 +01001830 section 4.2.1.2.
1831
Paul Kehrercc671822015-08-08 15:41:54 -05001832 :param public_key: One of
1833 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1834 ,
1835 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1836 , or
1837 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
Paul Kehrer253929a2015-08-05 17:30:39 +01001838
1839 .. doctest::
1840
1841 >>> from cryptography import x509
1842 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001843 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1844 >>> x509.AuthorityKeyIdentifier.from_issuer_public_key(issuer_cert.public_key())
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001845 <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 +01001846
Paul Kehrer61ff3562016-03-11 22:51:27 -04001847 .. classmethod:: from_issuer_subject_key_identifier(ski)
1848
1849 .. versionadded:: 1.3
1850
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001851 .. note::
1852 This method should be used if the issuer certificate contains a
1853 :class:`~cryptography.x509.SubjectKeyIdentifier`. Otherwise, use
1854 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_public_key`.
1855
Paul Kehrer61ff3562016-03-11 22:51:27 -04001856 Creates a new AuthorityKeyIdentifier instance using the
1857 SubjectKeyIdentifier from the issuer certificate. The resulting object
1858 will contain
1859 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1860 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1861 and
1862 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1863 will be None.
1864
1865 :param ski: The
1866 :class:`~cryptography.x509.SubjectKeyIdentifier` from the issuer
1867 certificate.
1868
1869 .. doctest::
1870
1871 >>> from cryptography import x509
1872 >>> from cryptography.hazmat.backends import default_backend
1873 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1874 >>> ski = issuer_cert.extensions.get_extension_for_class(x509.SubjectKeyIdentifier)
1875 >>> x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier(ski)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001876 <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 -04001877
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001878.. class:: SubjectKeyIdentifier(digest)
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001879
1880 .. versionadded:: 0.9
1881
1882 The subject key identifier extension provides a means of identifying
1883 certificates that contain a particular public key.
1884
Paul Kehrer822f3d32015-08-06 11:47:32 +01001885 .. attribute:: oid
1886
1887 .. versionadded:: 1.0
1888
1889 :type: :class:`ObjectIdentifier`
1890
Paul Kehrere27f6582015-08-10 18:33:38 -05001891 Returns
1892 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001893
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001894 .. attribute:: digest
1895
1896 :type: bytes
1897
1898 The binary value of the identifier.
1899
Paul Kehrerd4a7f062015-08-05 18:32:18 +01001900 .. classmethod:: from_public_key(public_key)
Paul Kehrerf22f6122015-08-05 12:57:13 +01001901
1902 .. versionadded:: 1.0
1903
1904 Creates a new SubjectKeyIdentifier instance using the public key
1905 provided to generate the appropriate digest. This should be the public
Paul Kehrereb9ec002015-08-08 10:03:02 -05001906 key that is in the certificate. The generated digest is the SHA1 hash
1907 of the ``subjectPublicKey`` ASN.1 bit string. This is the first
1908 recommendation in :rfc:`5280` section 4.2.1.2.
Paul Kehrerf22f6122015-08-05 12:57:13 +01001909
1910 :param public_key: One of
1911 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1912 ,
1913 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1914 , or
1915 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
1916
Paul Kehrer253929a2015-08-05 17:30:39 +01001917 .. doctest::
1918
1919 >>> from cryptography import x509
1920 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001921 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
1922 >>> x509.SubjectKeyIdentifier.from_public_key(csr.public_key())
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001923 <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 +01001924
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001925.. class:: SubjectAlternativeName(general_names)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001926
1927 .. versionadded:: 0.9
1928
1929 Subject alternative name is an X.509 extension that provides a list of
1930 :ref:`general name <general_name_classes>` instances that provide a set
1931 of identities for which the certificate is valid. The object is iterable to
1932 get every element.
1933
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001934 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001935
Paul Kehrer822f3d32015-08-06 11:47:32 +01001936 .. attribute:: oid
1937
1938 .. versionadded:: 1.0
1939
1940 :type: :class:`ObjectIdentifier`
1941
Paul Kehrere27f6582015-08-10 18:33:38 -05001942 Returns
1943 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001944
Paul Kehrer31bdf792015-03-25 14:11:00 -05001945 .. method:: get_values_for_type(type)
1946
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03001947 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer31bdf792015-03-25 14:11:00 -05001948 :ref:`general name classes <general_name_classes>`.
1949
1950 :returns: A list of values extracted from the matched general names.
Joshua Taubererd2afad32015-07-06 22:37:53 +00001951 The type of the returned values depends on the :class:`GeneralName`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001952
Paul Kehrer93ae8052015-05-02 23:18:09 -05001953 .. doctest::
1954
1955 >>> from cryptography import x509
1956 >>> from cryptography.hazmat.backends import default_backend
1957 >>> from cryptography.hazmat.primitives import hashes
1958 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend())
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001959 >>> # Get the subjectAltName extension from the certificate
Paul Kehrere27f6582015-08-10 18:33:38 -05001960 >>> ext = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001961 >>> # Get the dNSName entries from the SAN extension
1962 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001963 ['www.cryptography.io', 'cryptography.io']
Paul Kehrer93ae8052015-05-02 23:18:09 -05001964
Paul Kehrer8cf26422015-03-21 09:50:24 -05001965
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001966.. class:: IssuerAlternativeName(general_names)
Paul Kehrer99125c92015-06-07 18:37:10 -05001967
1968 .. versionadded:: 1.0
1969
1970 Issuer alternative name is an X.509 extension that provides a list of
1971 :ref:`general name <general_name_classes>` instances that provide a set
1972 of identities for the certificate issuer. The object is iterable to
1973 get every element.
1974
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001975 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001976
Paul Kehrer822f3d32015-08-06 11:47:32 +01001977 .. attribute:: oid
1978
1979 .. versionadded:: 1.0
1980
1981 :type: :class:`ObjectIdentifier`
1982
Paul Kehrere27f6582015-08-10 18:33:38 -05001983 Returns
1984 :attr:`~cryptography.x509.oid.ExtensionOID.ISSUER_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001985
Paul Kehrer99125c92015-06-07 18:37:10 -05001986 .. method:: get_values_for_type(type)
1987
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03001988 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer99125c92015-06-07 18:37:10 -05001989 :ref:`general name classes <general_name_classes>`.
1990
1991 :returns: A list of values extracted from the matched general names.
1992
1993
Alex Gaynor6a0718f2017-06-04 13:36:58 -04001994.. class:: PrecertificateSignedCertificateTimestamps(scts)
1995
1996 .. versionadded:: 2.0
1997
1998 This extension contains
1999 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2000 instances which were issued for the pre-certificate corresponding to this
2001 certificate. These can be used to verify that the certificate is included
2002 in a public Certificate Transparency log.
2003
2004 It is an iterable containing one or more
2005 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2006 objects.
2007
2008 :param list scts: A ``list`` of
2009 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
2010 objects.
2011
2012 .. attribute:: oid
2013
2014 :type: :class:`ObjectIdentifier`
2015
2016 Returns
2017 :attr:`~cryptography.x509.oid.ExtensionOID.PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS`.
2018
2019
Alex Gaynordd6b78b2018-08-31 18:25:52 -05002020.. class:: PrecertPoison()
2021
2022 .. versionadded:: 2.4
2023
2024 This extension indicates that the certificate should not be treated as a
2025 certificate for the purposes of validation, but is instead for submission
2026 to a certificate transparency log in order to obtain SCTs which will be
2027 embedded in a :class:`PrecertificateSignedCertificateTimestamps` extension
2028 on the final certificate.
2029
2030 .. attribute:: oid
2031
2032 :type: :class:`ObjectIdentifier`
2033
2034 Returns :attr:`~cryptography.x509.oid.ExtensionOID.PRECERT_POISON`.
2035
2036
Paul Kehrer5e3cc982017-09-22 21:29:36 +08002037.. class:: DeltaCRLIndicator(crl_number)
2038
2039 .. versionadded:: 2.1
2040
2041 The delta CRL indicator is a CRL extension that identifies a CRL as being
2042 a delta CRL. Delta CRLs contain updates to revocation information
2043 previously distributed, rather than all the information that would appear
2044 in a complete CRL.
2045
2046 :param int crl_number: The CRL number of the complete CRL that the
2047 delta CRL is updating.
2048
2049 .. attribute:: oid
2050
2051 :type: :class:`ObjectIdentifier`
2052
2053 Returns
2054 :attr:`~cryptography.x509.oid.ExtensionOID.DELTA_CRL_INDICATOR`.
2055
2056 .. attribute:: crl_number
2057
2058 :type: int
2059
2060
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002061.. class:: AuthorityInformationAccess(descriptions)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002062
2063 .. versionadded:: 0.9
2064
2065 The authority information access extension indicates how to access
2066 information and services for the issuer of the certificate in which
2067 the extension appears. Information and services may include online
2068 validation services (such as OCSP) and issuer data. It is an iterable,
Paul Kehrere27f6582015-08-10 18:33:38 -05002069 containing one or more :class:`~cryptography.x509.AccessDescription`
2070 instances.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002071
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002072 :param list descriptions: A list of :class:`AccessDescription` objects.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002073
Paul Kehrer822f3d32015-08-06 11:47:32 +01002074 .. attribute:: oid
2075
2076 .. versionadded:: 1.0
2077
2078 :type: :class:`ObjectIdentifier`
2079
Paul Kehrere27f6582015-08-10 18:33:38 -05002080 Returns
2081 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_INFORMATION_ACCESS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002082
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002083
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002084.. class:: AccessDescription(access_method, access_location)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002085
Paul Kehrer5a485522015-05-06 00:29:12 -05002086 .. versionadded:: 0.9
2087
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002088 .. attribute:: access_method
2089
2090 :type: :class:`ObjectIdentifier`
2091
Paul Kehrerf506bca2015-05-02 22:31:47 -05002092 The access method defines what the ``access_location`` means. It must
Paul Kehrere27f6582015-08-10 18:33:38 -05002093 be either
2094 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP` or
2095 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`.
2096 If it is
2097 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP`
2098 the access location will be where to obtain OCSP
2099 information for the certificate. If it is
2100 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`
2101 the access location will provide additional information about the
2102 issuing certificate.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002103
2104 .. attribute:: access_location
2105
2106 :type: :class:`GeneralName`
2107
Paul Kehrerf506bca2015-05-02 22:31:47 -05002108 Where to access the information defined by the access method.
2109
Paul Kehrerb76bcf82017-09-24 08:44:12 +08002110.. class:: FreshestCRL(distribution_points)
2111
2112 .. versionadded:: 2.1
2113
2114 The freshest CRL extension (also known as Delta CRL Distribution Point)
2115 identifies how delta CRL information is obtained. It is an iterable,
2116 containing one or more :class:`DistributionPoint` instances.
2117
2118 :param list distribution_points: A list of :class:`DistributionPoint`
2119 instances.
2120
2121 .. attribute:: oid
2122
2123 :type: :class:`ObjectIdentifier`
2124
2125 Returns
2126 :attr:`~cryptography.x509.oid.ExtensionOID.FRESHEST_CRL`.
2127
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002128.. class:: CRLDistributionPoints(distribution_points)
Paul Kehrer5a485522015-05-06 00:29:12 -05002129
2130 .. versionadded:: 0.9
2131
2132 The CRL distribution points extension identifies how CRL information is
2133 obtained. It is an iterable, containing one or more
2134 :class:`DistributionPoint` instances.
2135
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002136 :param list distribution_points: A list of :class:`DistributionPoint`
2137 instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002138
Paul Kehrer822f3d32015-08-06 11:47:32 +01002139 .. attribute:: oid
2140
2141 .. versionadded:: 1.0
2142
2143 :type: :class:`ObjectIdentifier`
2144
Paul Kehrere27f6582015-08-10 18:33:38 -05002145 Returns
2146 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_DISTRIBUTION_POINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002147
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002148.. class:: DistributionPoint(full_name, relative_name, reasons, crl_issuer)
Paul Kehrer5a485522015-05-06 00:29:12 -05002149
2150 .. versionadded:: 0.9
2151
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002152 .. attribute:: full_name
Paul Kehrer5a485522015-05-06 00:29:12 -05002153
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002154 :type: list of :class:`GeneralName` instances or None
Paul Kehrer5a485522015-05-06 00:29:12 -05002155
Paul Kehrerf2c072b2015-05-09 17:04:28 -05002156 This field describes methods to retrieve the CRL. At most one of
2157 ``full_name`` or ``relative_name`` will be non-None.
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002158
2159 .. attribute:: relative_name
2160
Fraser Tweedale02467dd2016-11-07 15:54:04 +10002161 :type: :class:`RelativeDistinguishedName` or None
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002162
2163 This field describes methods to retrieve the CRL relative to the CRL
Paul Kehrerf2c072b2015-05-09 17:04:28 -05002164 issuer. At most one of ``full_name`` or ``relative_name`` will be
2165 non-None.
Paul Kehrer5a485522015-05-06 00:29:12 -05002166
Fraser Tweedale02467dd2016-11-07 15:54:04 +10002167 .. versionchanged:: 1.6
2168 Changed from :class:`Name` to :class:`RelativeDistinguishedName`.
2169
Paul Kehrer5a485522015-05-06 00:29:12 -05002170 .. attribute:: crl_issuer
2171
2172 :type: list of :class:`GeneralName` instances or None
2173
2174 Information about the issuer of the CRL.
2175
2176 .. attribute:: reasons
2177
Paul Kehrer3fd02602015-05-09 19:46:13 -05002178 :type: frozenset of :class:`ReasonFlags` or None
Paul Kehrer5a485522015-05-06 00:29:12 -05002179
2180 The reasons a given distribution point may be used for when performing
2181 revocation checks.
2182
2183.. class:: ReasonFlags
2184
2185 .. versionadded:: 0.9
2186
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002187 An enumeration for CRL reasons.
2188
2189 .. attribute:: unspecified
2190
2191 It is unspecified why the certificate was revoked. This reason cannot
2192 be used as a reason flag in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05002193
2194 .. attribute:: key_compromise
2195
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002196 This reason indicates that the private key was compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05002197
2198 .. attribute:: ca_compromise
2199
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002200 This reason indicates that the CA issuing the certificate was
2201 compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05002202
2203 .. attribute:: affiliation_changed
2204
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002205 This reason indicates that the subject's name or other information has
2206 changed.
Paul Kehrer5a485522015-05-06 00:29:12 -05002207
2208 .. attribute:: superseded
2209
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002210 This reason indicates that a certificate has been superseded.
Paul Kehrer5a485522015-05-06 00:29:12 -05002211
2212 .. attribute:: cessation_of_operation
2213
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002214 This reason indicates that the certificate is no longer required.
Paul Kehrer5a485522015-05-06 00:29:12 -05002215
2216 .. attribute:: certificate_hold
2217
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002218 This reason indicates that the certificate is on hold.
Paul Kehrer5a485522015-05-06 00:29:12 -05002219
2220 .. attribute:: privilege_withdrawn
2221
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002222 This reason indicates that the privilege granted by this certificate
2223 have been withdrawn.
Paul Kehrer5a485522015-05-06 00:29:12 -05002224
2225 .. attribute:: aa_compromise
2226
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002227 When an attribute authority has been compromised.
2228
2229 .. attribute:: remove_from_crl
2230
2231 This reason indicates that the certificate was on hold and should be
2232 removed from the CRL. This reason cannot be used as a reason flag
2233 in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05002234
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002235.. class:: InhibitAnyPolicy(skip_certs)
Paul Kehrer16fae762015-05-01 23:14:20 -05002236
2237 .. versionadded:: 1.0
2238
2239 The inhibit ``anyPolicy`` extension indicates that the special OID
Paul Kehrere27f6582015-08-10 18:33:38 -05002240 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY`, is not
2241 considered an explicit match for other :class:`CertificatePolicies` except
2242 when it appears in an intermediate self-issued CA certificate. The value
2243 indicates the number of additional non-self-issued certificates that may
2244 appear in the path before
2245 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` is no
2246 longer permitted. For example, a value of one indicates that
2247 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` may be
2248 processed in certificates issued by the subject of this certificate, but
2249 not in additional certificates in the path.
Paul Kehrer16fae762015-05-01 23:14:20 -05002250
Paul Kehrer822f3d32015-08-06 11:47:32 +01002251 .. attribute:: oid
2252
2253 .. versionadded:: 1.0
2254
2255 :type: :class:`ObjectIdentifier`
2256
Paul Kehrere27f6582015-08-10 18:33:38 -05002257 Returns
2258 :attr:`~cryptography.x509.oid.ExtensionOID.INHIBIT_ANY_POLICY`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002259
Paul Kehrer16fae762015-05-01 23:14:20 -05002260 .. attribute:: skip_certs
2261
2262 :type: int
2263
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002264.. class:: PolicyConstraints
2265
2266 .. versionadded:: 1.3
2267
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002268 The policy constraints extension is used to inhibit policy mapping or
2269 require that each certificate in a chain contain an acceptable policy
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002270 identifier. For more information about the use of this extension see
2271 :rfc:`5280`.
2272
Paul Kehrer159b3b52016-02-26 08:27:22 -06002273 .. attribute:: oid
2274
2275 :type: :class:`ObjectIdentifier`
2276
2277 Returns :attr:`~cryptography.x509.oid.ExtensionOID.POLICY_CONSTRAINTS`.
2278
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002279 .. attribute:: require_explicit_policy
2280
2281 :type: int or None
2282
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002283 If this field is not None, the value indicates the number of additional
2284 certificates that may appear in the chain before an explicit policy is
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002285 required for the entire path. When an explicit policy is required, it
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002286 is necessary for all certificates in the chain to contain an acceptable
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002287 policy identifier in the certificate policies extension. An
2288 acceptable policy identifier is the identifier of a policy required
2289 by the user of the certification path or the identifier of a policy
2290 that has been declared equivalent through policy mapping.
2291
2292 .. attribute:: inhibit_policy_mapping
2293
2294 :type: int or None
2295
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002296 If this field is not None, the value indicates the number of additional
2297 certificates that may appear in the chain before policy mapping is no
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002298 longer permitted. For example, a value of one indicates that policy
2299 mapping may be processed in certificates issued by the subject of this
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002300 certificate, but not in additional certificates in the chain.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002301
Paul Kehrer3b95cd72015-12-22 21:40:20 -06002302.. class:: CRLNumber(crl_number)
2303
2304 .. versionadded:: 1.2
2305
Paul Kehrere32b9942015-12-22 22:26:53 -06002306 The CRL number is a CRL extension that conveys a monotonically increasing
2307 sequence number for a given CRL scope and CRL issuer. This extension allows
2308 users to easily determine when a particular CRL supersedes another CRL.
2309 :rfc:`5280` requires that this extension be present in conforming CRLs.
Paul Kehrer3b95cd72015-12-22 21:40:20 -06002310
2311 .. attribute:: oid
2312
2313 :type: :class:`ObjectIdentifier`
2314
2315 Returns
2316 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_NUMBER`.
2317
2318 .. attribute:: crl_number
2319
2320 :type: int
2321
Paul Kehrer14fd6972015-12-30 10:58:25 -06002322.. class:: UnrecognizedExtension
2323
2324 .. versionadded:: 1.2
2325
Alex Gaynord08ddd52017-05-20 09:01:54 -07002326 A generic extension class used to hold the raw value of extensions that
2327 ``cryptography`` does not know how to parse.
Paul Kehrer14fd6972015-12-30 10:58:25 -06002328
2329 .. attribute:: oid
2330
2331 :type: :class:`ObjectIdentifier`
2332
2333 Returns the OID associated with this extension.
2334
2335 .. attribute:: value
2336
Paul Kehreredfedc12018-09-14 18:24:20 -04002337 :type: bytes
Paul Kehrer14fd6972015-12-30 10:58:25 -06002338
2339 Returns the DER encoded bytes payload of the extension.
2340
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002341.. class:: CertificatePolicies(policies)
Paul Kehrer0d210922015-04-28 17:31:07 -05002342
2343 .. versionadded:: 0.9
2344
Paul Kehrer2e879742015-05-02 23:09:56 -05002345 The certificate policies extension is an iterable, containing one or more
2346 :class:`PolicyInformation` instances.
Paul Kehrer0d210922015-04-28 17:31:07 -05002347
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002348 :param list policies: A list of :class:`PolicyInformation` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002349
Paul Kehrer822f3d32015-08-06 11:47:32 +01002350 .. attribute:: oid
2351
2352 .. versionadded:: 1.0
2353
2354 :type: :class:`ObjectIdentifier`
2355
Paul Kehrere27f6582015-08-10 18:33:38 -05002356 Returns
2357 :attr:`~cryptography.x509.oid.ExtensionOID.CERTIFICATE_POLICIES`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002358
Paul Kehrer0d210922015-04-28 17:31:07 -05002359Certificate Policies Classes
2360~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2361
2362These classes may be present within a :class:`CertificatePolicies` instance.
2363
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002364.. class:: PolicyInformation(policy_identifier, policy_qualifiers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002365
2366 .. versionadded:: 0.9
2367
2368 Contains a policy identifier and an optional list of qualifiers.
2369
2370 .. attribute:: policy_identifier
2371
2372 :type: :class:`ObjectIdentifier`
2373
2374 .. attribute:: policy_qualifiers
2375
2376 :type: list
2377
Paul Kehrerba35b3b2015-05-10 13:07:59 -05002378 A list consisting of :term:`text` and/or :class:`UserNotice` objects.
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002379 If the value is text it is a pointer to the practice statement
2380 published by the certificate authority. If it is a user notice it is
2381 meant for display to the relying party when the certificate is
2382 used.
Paul Kehrer2e879742015-05-02 23:09:56 -05002383
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002384.. class:: UserNotice(notice_reference, explicit_text)
Paul Kehrer0d210922015-04-28 17:31:07 -05002385
2386 .. versionadded:: 0.9
2387
Paul Kehrer2e879742015-05-02 23:09:56 -05002388 User notices are intended for display to a relying party when a certificate
2389 is used. In practice, few if any UIs expose this data and it is a rarely
2390 encoded component.
2391
Paul Kehrer0d210922015-04-28 17:31:07 -05002392 .. attribute:: notice_reference
2393
2394 :type: :class:`NoticeReference` or None
2395
Paul Kehrer2e879742015-05-02 23:09:56 -05002396 The notice reference field names an organization and identifies,
2397 by number, a particular statement prepared by that organization.
2398
Paul Kehrer0d210922015-04-28 17:31:07 -05002399 .. attribute:: explicit_text
2400
Paul Kehrer2e879742015-05-02 23:09:56 -05002401 This field includes an arbitrary textual statement directly in the
2402 certificate.
2403
Paul Kehrer0d210922015-04-28 17:31:07 -05002404 :type: :term:`text`
2405
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002406.. class:: NoticeReference(organization, notice_numbers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002407
Paul Kehrer2e879742015-05-02 23:09:56 -05002408 Notice reference can name an organization and provide information about
2409 notices related to the certificate. For example, it might identify the
2410 organization name and notice number 1. Application software could
2411 have a notice file containing the current set of notices for the named
2412 organization; the application would then extract the notice text from the
2413 file and display it. In practice this is rarely seen.
2414
Paul Kehrer0d210922015-04-28 17:31:07 -05002415 .. versionadded:: 0.9
2416
2417 .. attribute:: organization
2418
Paul Kehrer66c61702015-05-12 16:39:18 -05002419 :type: :term:`text`
Paul Kehrer0d210922015-04-28 17:31:07 -05002420
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002421 .. attribute:: notice_numbers
Paul Kehrer0d210922015-04-28 17:31:07 -05002422
Paul Kehrer66c61702015-05-12 16:39:18 -05002423 :type: list
Paul Kehrer0d210922015-04-28 17:31:07 -05002424
Paul Kehrer66c61702015-05-12 16:39:18 -05002425 A list of integers.
Paul Kehrer0d210922015-04-28 17:31:07 -05002426
Paul Kehrere5f152b2015-12-25 23:55:47 -06002427.. _crl_entry_extensions:
2428
Paul Kehrer49bb7562015-12-25 16:17:40 -06002429CRL Entry Extensions
2430~~~~~~~~~~~~~~~~~~~~
2431
2432These extensions are only valid within a :class:`RevokedCertificate` object.
2433
2434.. class:: CertificateIssuer(general_names)
2435
2436 .. versionadded:: 1.2
2437
2438 The certificate issuer is an extension that is only valid inside
2439 :class:`~cryptography.x509.RevokedCertificate` objects. If the
2440 ``indirectCRL`` property of the parent CRL's IssuingDistributionPoint
2441 extension is set, then this extension identifies the certificate issuer
2442 associated with the revoked certificate. The object is iterable to get
2443 every element.
2444
2445 :param list general_names: A list of :class:`GeneralName` instances.
2446
2447 .. attribute:: oid
2448
2449 :type: :class:`ObjectIdentifier`
2450
2451 Returns
2452 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CERTIFICATE_ISSUER`.
2453
2454 .. method:: get_values_for_type(type)
2455
2456 :param type: A :class:`GeneralName` instance. This is one of the
2457 :ref:`general name classes <general_name_classes>`.
2458
2459 :returns: A list of values extracted from the matched general names.
2460 The type of the returned values depends on the :class:`GeneralName`.
2461
Paul Kehrer7058ece2015-12-25 22:28:29 -06002462.. class:: CRLReason(reason)
2463
2464 .. versionadded:: 1.2
2465
2466 CRL reason (also known as ``reasonCode``) is an extension that is only
2467 valid inside :class:`~cryptography.x509.RevokedCertificate` objects. It
2468 identifies a reason for the certificate revocation.
2469
Paul Kehrerce4d0842017-09-20 22:14:26 +08002470 :param reason: An element from :class:`~cryptography.x509.ReasonFlags`.
Paul Kehrer7058ece2015-12-25 22:28:29 -06002471
2472 .. attribute:: oid
2473
2474 :type: :class:`ObjectIdentifier`
2475
2476 Returns
2477 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CRL_REASON`.
2478
2479 .. attribute:: reason
2480
2481 :type: An element from :class:`~cryptography.x509.ReasonFlags`
2482
Paul Kehrer23c0bbc2015-12-25 22:35:19 -06002483.. class:: InvalidityDate(invalidity_date)
2484
2485 .. versionadded:: 1.2
2486
2487 Invalidity date is an extension that is only valid inside
2488 :class:`~cryptography.x509.RevokedCertificate` objects. It provides
2489 the date on which it is known or suspected that the private key was
2490 compromised or that the certificate otherwise became invalid.
2491 This date may be earlier than the revocation date in the CRL entry,
2492 which is the date at which the CA processed the revocation.
2493
2494 :param invalidity_date: The :class:`datetime.datetime` when it is known
2495 or suspected that the private key was compromised.
2496
2497 .. attribute:: oid
2498
2499 :type: :class:`ObjectIdentifier`
2500
2501 Returns
2502 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.INVALIDITY_DATE`.
2503
2504 .. attribute:: invalidity_date
2505
2506 :type: :class:`datetime.datetime`
2507
Paul Kehrer09403102018-09-09 21:57:21 -05002508OCSP Extensions
2509~~~~~~~~~~~~~~~
2510
2511.. class:: OCSPNonce(nonce)
2512
2513 .. versionadded:: 2.4
2514
2515 OCSP nonce is an extension that is only valid inside
2516 :class:`~cryptography.x509.ocsp.OCSPRequest` and
2517 :class:`~cryptography.x509.ocsp.OCSPResponse` objects. The nonce
2518 cryptographically binds a request and a response to prevent replay attacks.
2519 In practice nonces are rarely used in OCSP due to the desire to precompute
2520 OCSP responses at large scale.
2521
2522 .. attribute:: oid
2523
2524 :type: :class:`ObjectIdentifier`
2525
2526 Returns
2527 :attr:`~cryptography.x509.oid.OCSPExtensionOID.NONCE`.
2528
2529 .. attribute:: nonce
2530
2531 :type: bytes
Paul Kehrer49bb7562015-12-25 16:17:40 -06002532
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002533Object Identifiers
2534~~~~~~~~~~~~~~~~~~
2535
Paul Kehrer4bb46492015-02-07 16:59:14 -06002536X.509 elements are frequently identified by :class:`ObjectIdentifier`
2537instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002538
Paul Kehrere27f6582015-08-10 18:33:38 -05002539.. currentmodule:: cryptography.x509.oid
Paul Kehrer56da2a52015-02-11 23:35:07 -06002540
Paul Kehrere27f6582015-08-10 18:33:38 -05002541.. class:: NameOID
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002542
Paul Kehrere27f6582015-08-10 18:33:38 -05002543 These OIDs are typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06002544
Paul Kehrere27f6582015-08-10 18:33:38 -05002545 .. versionadded:: 1.0
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002546
Paul Kehrere27f6582015-08-10 18:33:38 -05002547 .. attribute:: COMMON_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002548
Paul Kehrere27f6582015-08-10 18:33:38 -05002549 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
2550 name would be encoded here for server certificates. :rfc:`2818`
2551 deprecates this practice and names of that type should now be located
2552 in a :class:`~cryptography.x509.SubjectAlternativeName` extension.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002553
Paul Kehrere27f6582015-08-10 18:33:38 -05002554 .. attribute:: COUNTRY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002555
Paul Kehrere27f6582015-08-10 18:33:38 -05002556 Corresponds to the dotted string ``"2.5.4.6"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002557
Paul Kehrere27f6582015-08-10 18:33:38 -05002558 .. attribute:: LOCALITY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002559
Paul Kehrere27f6582015-08-10 18:33:38 -05002560 Corresponds to the dotted string ``"2.5.4.7"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002561
Paul Kehrere27f6582015-08-10 18:33:38 -05002562 .. attribute:: STATE_OR_PROVINCE_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002563
Paul Kehrere27f6582015-08-10 18:33:38 -05002564 Corresponds to the dotted string ``"2.5.4.8"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002565
Paul Kehrerc3b8ff62016-11-11 17:38:59 -08002566 .. attribute:: STREET_ADDRESS
2567
2568 .. versionadded:: 1.6
2569
2570 Corresponds to the dotted string ``"2.5.4.9"``.
2571
Paul Kehrere27f6582015-08-10 18:33:38 -05002572 .. attribute:: ORGANIZATION_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002573
Paul Kehrere27f6582015-08-10 18:33:38 -05002574 Corresponds to the dotted string ``"2.5.4.10"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002575
Paul Kehrere27f6582015-08-10 18:33:38 -05002576 .. attribute:: ORGANIZATIONAL_UNIT_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002577
Paul Kehrere27f6582015-08-10 18:33:38 -05002578 Corresponds to the dotted string ``"2.5.4.11"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002579
Paul Kehrere27f6582015-08-10 18:33:38 -05002580 .. attribute:: SERIAL_NUMBER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002581
Paul Kehrere27f6582015-08-10 18:33:38 -05002582 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from
2583 the serial number of the certificate itself (which can be obtained with
Chelsea Winfreee295f3a2016-06-02 21:15:54 -07002584 :func:`~cryptography.x509.Certificate.serial_number`).
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002585
Paul Kehrere27f6582015-08-10 18:33:38 -05002586 .. attribute:: SURNAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002587
Paul Kehrere27f6582015-08-10 18:33:38 -05002588 Corresponds to the dotted string ``"2.5.4.4"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002589
Paul Kehrere27f6582015-08-10 18:33:38 -05002590 .. attribute:: GIVEN_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002591
Paul Kehrere27f6582015-08-10 18:33:38 -05002592 Corresponds to the dotted string ``"2.5.4.42"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002593
Paul Kehrere27f6582015-08-10 18:33:38 -05002594 .. attribute:: TITLE
Paul Kehrer858b9b72015-02-05 09:50:31 -06002595
Paul Kehrere27f6582015-08-10 18:33:38 -05002596 Corresponds to the dotted string ``"2.5.4.12"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002597
Paul Kehrere27f6582015-08-10 18:33:38 -05002598 .. attribute:: GENERATION_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002599
Paul Kehrere27f6582015-08-10 18:33:38 -05002600 Corresponds to the dotted string ``"2.5.4.44"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002601
Paul Kehrerc7ab9312016-11-12 05:00:42 -08002602 .. attribute:: X500_UNIQUE_IDENTIFIER
Paul Kehrerc3b8ff62016-11-11 17:38:59 -08002603
2604 .. versionadded:: 1.6
2605
2606 Corresponds to the dotted string ``"2.5.4.45"``.
2607
Paul Kehrere27f6582015-08-10 18:33:38 -05002608 .. attribute:: DN_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002609
Paul Kehrere27f6582015-08-10 18:33:38 -05002610 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
2611 disambiguating information to add to the relative distinguished name of an
2612 entry. See :rfc:`2256`.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002613
Paul Kehrere27f6582015-08-10 18:33:38 -05002614 .. attribute:: PSEUDONYM
Paul Kehrer858b9b72015-02-05 09:50:31 -06002615
Paul Kehrere27f6582015-08-10 18:33:38 -05002616 Corresponds to the dotted string ``"2.5.4.65"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002617
Paul Kehrer36d5cd62016-11-19 22:05:26 +08002618 .. attribute:: USER_ID
2619
2620 .. versionadded:: 1.6
2621
2622 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.1"``.
2623
Paul Kehrere27f6582015-08-10 18:33:38 -05002624 .. attribute:: DOMAIN_COMPONENT
Paul Kehrer858b9b72015-02-05 09:50:31 -06002625
Paul Kehrere27f6582015-08-10 18:33:38 -05002626 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
2627 holding one component of a domain name. See :rfc:`4519`.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002628
Paul Kehrere27f6582015-08-10 18:33:38 -05002629 .. attribute:: EMAIL_ADDRESS
Paul Kehrer56da2a52015-02-11 23:35:07 -06002630
Paul Kehrere27f6582015-08-10 18:33:38 -05002631 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002632
Alex Gaynor1d3f2bf2015-12-19 12:15:09 -05002633 .. attribute:: JURISDICTION_COUNTRY_NAME
2634
2635 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.3"``.
2636
Alex Gaynor45e507f2015-12-19 13:44:23 -05002637 .. attribute:: JURISDICTION_LOCALITY_NAME
2638
2639 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.1"``.
2640
2641 .. attribute:: JURISDICTION_STATE_OR_PROVINCE_NAME
2642
2643 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.2"``.
2644
Alex Gaynora2293c82015-12-19 20:49:15 -05002645 .. attribute:: BUSINESS_CATEGORY
2646
2647 Corresponds to the dotted string ``"2.5.4.15"``.
2648
Paul Kehrer36d5cd62016-11-19 22:05:26 +08002649 .. attribute:: POSTAL_ADDRESS
2650
2651 .. versionadded:: 1.6
2652
2653 Corresponds to the dotted string ``"2.5.4.16"``.
2654
2655 .. attribute:: POSTAL_CODE
2656
2657 .. versionadded:: 1.6
2658
2659 Corresponds to the dotted string ``"2.5.4.17"``.
2660
Paul Kehrer56da2a52015-02-11 23:35:07 -06002661
Paul Kehrere27f6582015-08-10 18:33:38 -05002662.. class:: SignatureAlgorithmOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002663
Paul Kehrere27f6582015-08-10 18:33:38 -05002664 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002665
Paul Kehrere27f6582015-08-10 18:33:38 -05002666 .. attribute:: RSA_WITH_MD5
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.4"``. This is
2669 an MD5 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_SHA1
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.5"``. This is
2674 a SHA1 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_SHA224
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.14"``. This is
2679 a SHA224 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002680
Paul Kehrere27f6582015-08-10 18:33:38 -05002681 .. attribute:: RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002682
Paul Kehrere27f6582015-08-10 18:33:38 -05002683 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
2684 a SHA256 digest signed by an RSA key.
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002685
Paul Kehrere27f6582015-08-10 18:33:38 -05002686 .. attribute:: RSA_WITH_SHA384
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002687
Paul Kehrere27f6582015-08-10 18:33:38 -05002688 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
2689 a SHA384 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002690
Paul Kehrere27f6582015-08-10 18:33:38 -05002691 .. attribute:: RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -06002692
Paul Kehrere27f6582015-08-10 18:33:38 -05002693 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
2694 a SHA512 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002695
Marti Raudsepp33678062018-06-30 02:27:28 +03002696 .. attribute:: RSASSA_PSS
2697
2698 .. versionadded:: 2.3
2699
2700 Corresponds to the dotted string ``"1.2.840.113549.1.1.10"``. This is
2701 signed by an RSA key using the Probabilistic Signature Scheme (PSS)
2702 padding from RFC 4055. The hash function and padding are defined by
2703 signature algorithm parameters.
2704
Paul Kehrere27f6582015-08-10 18:33:38 -05002705 .. attribute:: ECDSA_WITH_SHA1
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.1"``. This is a SHA1
2708 digest signed by an ECDSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002709
Paul Kehrere27f6582015-08-10 18:33:38 -05002710 .. attribute:: ECDSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002711
Paul Kehrere27f6582015-08-10 18:33:38 -05002712 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
2713 a SHA224 digest signed by an ECDSA key.
2714
2715 .. attribute:: ECDSA_WITH_SHA256
2716
2717 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
2718 a SHA256 digest signed by an ECDSA key.
2719
2720 .. attribute:: ECDSA_WITH_SHA384
2721
2722 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
2723 a SHA384 digest signed by an ECDSA key.
2724
2725 .. attribute:: ECDSA_WITH_SHA512
2726
2727 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
2728 a SHA512 digest signed by an ECDSA key.
2729
2730 .. attribute:: DSA_WITH_SHA1
2731
2732 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
2733 a SHA1 digest signed by a DSA key.
2734
2735 .. attribute:: DSA_WITH_SHA224
2736
2737 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
2738 a SHA224 digest signed by a DSA key.
2739
2740 .. attribute:: DSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002741
Paul Kehrere27f6582015-08-10 18:33:38 -05002742 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
2743 a SHA256 digest signed by a DSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002744
Paul Kehrer56da2a52015-02-11 23:35:07 -06002745
Paul Kehrere27f6582015-08-10 18:33:38 -05002746.. class:: ExtendedKeyUsageOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002747
Paul Kehrere27f6582015-08-10 18:33:38 -05002748 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002749
Paul Kehrere27f6582015-08-10 18:33:38 -05002750 .. attribute:: SERVER_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002751
Paul Kehrere27f6582015-08-10 18:33:38 -05002752 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used
2753 to denote that a certificate may be used for TLS web server
2754 authentication.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002755
Paul Kehrere27f6582015-08-10 18:33:38 -05002756 .. attribute:: CLIENT_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002757
Paul Kehrere27f6582015-08-10 18:33:38 -05002758 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used
2759 to denote that a certificate may be used for TLS web client
2760 authentication.
Paul Kehrerffa2a152015-03-31 08:18:25 -05002761
Paul Kehrere27f6582015-08-10 18:33:38 -05002762 .. attribute:: CODE_SIGNING
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.3"``. This is used
2765 to denote that a certificate may be used for code signing.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002766
Paul Kehrere27f6582015-08-10 18:33:38 -05002767 .. attribute:: EMAIL_PROTECTION
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.4"``. This is used
2770 to denote that a certificate may be used for email protection.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002771
Paul Kehrere27f6582015-08-10 18:33:38 -05002772 .. attribute:: TIME_STAMPING
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.8"``. This is used
2775 to denote that a certificate may be used for time stamping.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002776
Paul Kehrere27f6582015-08-10 18:33:38 -05002777 .. attribute:: OCSP_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002778
Paul Kehrere27f6582015-08-10 18:33:38 -05002779 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used
2780 to denote that a certificate may be used for signing OCSP responses.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002781
Alex Gaynorb7912ee2017-07-03 10:07:02 -04002782 .. attribute:: ANY_EXTENDED_KEY_USAGE
2783
2784 .. versionadded:: 2.0
2785
2786 Corresponds to the dotted string ``"2.5.29.37.0"``. This is used to
2787 denote that a certificate may be used for _any_ purposes.
2788
Paul Kehrere1513fa2015-03-30 23:08:17 -05002789
Paul Kehrere27f6582015-08-10 18:33:38 -05002790.. class:: AuthorityInformationAccessOID
Paul Kehrere1513fa2015-03-30 23:08:17 -05002791
Paul Kehrere27f6582015-08-10 18:33:38 -05002792 .. versionadded:: 1.0
Paul Kehrere1513fa2015-03-30 23:08:17 -05002793
Paul Kehrere27f6582015-08-10 18:33:38 -05002794 .. attribute:: OCSP
Paul Kehrere1513fa2015-03-30 23:08:17 -05002795
Paul Kehrere27f6582015-08-10 18:33:38 -05002796 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
2797 identifier for OCSP data in
2798 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002799
Paul Kehrere27f6582015-08-10 18:33:38 -05002800 .. attribute:: CA_ISSUERS
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002801
Paul Kehrere27f6582015-08-10 18:33:38 -05002802 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
2803 identifier for CA issuer data in
2804 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002805
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002806
Paul Kehrere27f6582015-08-10 18:33:38 -05002807.. class:: CertificatePoliciesOID
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002808
Paul Kehrere27f6582015-08-10 18:33:38 -05002809 .. versionadded:: 1.0
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002810
Paul Kehrere27f6582015-08-10 18:33:38 -05002811 .. attribute:: CPS_QUALIFIER
Paul Kehrer2e879742015-05-02 23:09:56 -05002812
Paul Kehrere27f6582015-08-10 18:33:38 -05002813 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05002814
Paul Kehrere27f6582015-08-10 18:33:38 -05002815 .. attribute:: CPS_USER_NOTICE
Paul Kehrer2e879742015-05-02 23:09:56 -05002816
Paul Kehrere27f6582015-08-10 18:33:38 -05002817 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05002818
Paul Kehrere27f6582015-08-10 18:33:38 -05002819 .. attribute:: ANY_POLICY
Paul Kehrer2e879742015-05-02 23:09:56 -05002820
Paul Kehrere27f6582015-08-10 18:33:38 -05002821 Corresponds to the dotted string ``"2.5.29.32.0"``.
Paul Kehrer16fae762015-05-01 23:14:20 -05002822
Paul Kehrer16fae762015-05-01 23:14:20 -05002823
Paul Kehrere27f6582015-08-10 18:33:38 -05002824.. class:: ExtensionOID
Paul Kehrer5553d572015-03-23 21:08:01 -05002825
Paul Kehrere27f6582015-08-10 18:33:38 -05002826 .. versionadded:: 1.0
Paul Kehrer2bb94642015-03-21 09:54:17 -05002827
Paul Kehrere27f6582015-08-10 18:33:38 -05002828 .. attribute:: BASIC_CONSTRAINTS
Paul Kehrer2bb94642015-03-21 09:54:17 -05002829
Paul Kehrere27f6582015-08-10 18:33:38 -05002830 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
2831 :class:`~cryptography.x509.BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05002832
Paul Kehrere27f6582015-08-10 18:33:38 -05002833 .. attribute:: KEY_USAGE
Paul Kehrercecbbba2015-03-30 14:58:38 -05002834
Paul Kehrere27f6582015-08-10 18:33:38 -05002835 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
2836 :class:`~cryptography.x509.KeyUsage` extension type.
Paul Kehrercecbbba2015-03-30 14:58:38 -05002837
Paul Kehrere27f6582015-08-10 18:33:38 -05002838 .. attribute:: SUBJECT_ALTERNATIVE_NAME
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002839
Paul Kehrere27f6582015-08-10 18:33:38 -05002840 Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the
2841 :class:`~cryptography.x509.SubjectAlternativeName` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002842
Paul Kehrere27f6582015-08-10 18:33:38 -05002843 .. attribute:: ISSUER_ALTERNATIVE_NAME
Paul Kehrer99125c92015-06-07 18:37:10 -05002844
Paul Kehrere27f6582015-08-10 18:33:38 -05002845 Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the
2846 :class:`~cryptography.x509.IssuerAlternativeName` extension type.
Paul Kehrer99125c92015-06-07 18:37:10 -05002847
Paul Kehrere27f6582015-08-10 18:33:38 -05002848 .. attribute:: SUBJECT_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002849
Paul Kehrere27f6582015-08-10 18:33:38 -05002850 Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the
2851 :class:`~cryptography.x509.SubjectKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002852
Paul Kehrere27f6582015-08-10 18:33:38 -05002853 .. attribute:: NAME_CONSTRAINTS
Paul Kehrere0017be2015-05-17 20:39:40 -06002854
Paul Kehrere27f6582015-08-10 18:33:38 -05002855 Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the
2856 :class:`~cryptography.x509.NameConstraints` extension type.
Paul Kehrere0017be2015-05-17 20:39:40 -06002857
Paul Kehrere27f6582015-08-10 18:33:38 -05002858 .. attribute:: CRL_DISTRIBUTION_POINTS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002859
Paul Kehrere27f6582015-08-10 18:33:38 -05002860 Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the
2861 :class:`~cryptography.x509.CRLDistributionPoints` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002862
Paul Kehrere27f6582015-08-10 18:33:38 -05002863 .. attribute:: CERTIFICATE_POLICIES
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002864
Paul Kehrere27f6582015-08-10 18:33:38 -05002865 Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the
2866 :class:`~cryptography.x509.CertificatePolicies` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002867
Paul Kehrere27f6582015-08-10 18:33:38 -05002868 .. attribute:: AUTHORITY_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002869
Paul Kehrere27f6582015-08-10 18:33:38 -05002870 Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the
2871 :class:`~cryptography.x509.AuthorityKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002872
Paul Kehrere27f6582015-08-10 18:33:38 -05002873 .. attribute:: EXTENDED_KEY_USAGE
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002874
Paul Kehrere27f6582015-08-10 18:33:38 -05002875 Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the
2876 :class:`~cryptography.x509.ExtendedKeyUsage` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002877
Paul Kehrere27f6582015-08-10 18:33:38 -05002878 .. attribute:: AUTHORITY_INFORMATION_ACCESS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002879
Paul Kehrere27f6582015-08-10 18:33:38 -05002880 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier
2881 for the :class:`~cryptography.x509.AuthorityInformationAccess` extension
2882 type.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002883
Paul Kehrere27f6582015-08-10 18:33:38 -05002884 .. attribute:: INHIBIT_ANY_POLICY
Paul Kehrerb33de932015-08-06 23:41:05 +01002885
Paul Kehrere27f6582015-08-10 18:33:38 -05002886 Corresponds to the dotted string ``"2.5.29.54"``. The identifier
2887 for the :class:`~cryptography.x509.InhibitAnyPolicy` extension type.
Paul Kehrerb33de932015-08-06 23:41:05 +01002888
Paul Kehrere27f6582015-08-10 18:33:38 -05002889 .. attribute:: OCSP_NO_CHECK
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002890
Paul Kehrere27f6582015-08-10 18:33:38 -05002891 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The
2892 identifier for the :class:`~cryptography.x509.OCSPNoCheck` extension
2893 type.
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002894
Paul Kehrer5d669662017-09-11 09:16:34 +08002895 .. attribute:: TLS_FEATURE
2896
2897 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.24"``. The
2898 identifier for the :class:`~cryptography.x509.TLSFeature` extension
2899 type.
2900
Paul Kehrer51f39cb2015-12-21 21:17:39 -06002901 .. attribute:: CRL_NUMBER
2902
2903 Corresponds to the dotted string ``"2.5.29.20"``. The identifier for
2904 the ``CRLNumber`` extension type. This extension only has meaning
2905 for certificate revocation lists.
2906
Paul Kehrer5e3cc982017-09-22 21:29:36 +08002907 .. attribute:: DELTA_CRL_INDICATOR
2908
2909 .. versionadded:: 2.1
2910
2911 Corresponds to the dotted string ``"2.5.29.27"``. The identifier for
2912 the ``DeltaCRLIndicator`` extension type. This extension only has
2913 meaning for certificate revocation lists.
2914
Alex Gaynor9bab0ed2017-03-20 09:50:52 -04002915 .. attribute:: PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS
2916
2917 .. versionadded:: 1.9
2918
2919 Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.2"``.
2920
Alex Gaynordd6b78b2018-08-31 18:25:52 -05002921 .. attribute:: PRECERT_POISON
2922
2923 .. versionadded:: 2.4
2924
2925 Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.3"``.
2926
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002927 .. attribute:: POLICY_CONSTRAINTS
2928
2929 Corresponds to the dotted string ``"2.5.29.36"``. The identifier for the
Paul Kehrer20f0df52016-02-26 08:37:13 -06002930 :class:`~cryptography.x509.PolicyConstraints` extension type.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002931
Paul Kehrerb76bcf82017-09-24 08:44:12 +08002932 .. attribute:: FRESHEST_CRL
2933
2934 Corresponds to the dotted string ``"2.5.29.46"``. The identifier for the
2935 :class:`~cryptography.x509.FreshestCRL` extension type.
2936
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002937
Paul Kehrerc6242dc2015-12-25 16:36:46 -06002938.. class:: CRLEntryExtensionOID
2939
2940 .. versionadded:: 1.2
2941
2942 .. attribute:: CERTIFICATE_ISSUER
2943
2944 Corresponds to the dotted string ``"2.5.29.29"``.
2945
2946 .. attribute:: CRL_REASON
2947
2948 Corresponds to the dotted string ``"2.5.29.21"``.
2949
2950 .. attribute:: INVALIDITY_DATE
2951
2952 Corresponds to the dotted string ``"2.5.29.24"``.
2953
Paul Kehrer09403102018-09-09 21:57:21 -05002954
2955.. class:: OCSPExtensionOID
2956
2957 .. versionadded:: 2.4
2958
2959 .. attribute:: NONCE
2960
2961 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.2"``.
2962
Paul Kehrer8b89bcc2016-09-03 11:31:43 -05002963Helper Functions
2964~~~~~~~~~~~~~~~~
2965.. currentmodule:: cryptography.x509
2966
2967.. function:: random_serial_number()
2968
2969 .. versionadded:: 1.6
2970
2971 Generates a random serial number suitable for use when constructing
2972 certificates.
2973
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002974Exceptions
2975~~~~~~~~~~
Paul Kehrere27f6582015-08-10 18:33:38 -05002976.. currentmodule:: cryptography.x509
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002977
Paul Kehrere76cd272014-12-14 19:00:51 -06002978.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10002979
2980 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10002981
Paul Kehrerd5cccf72014-12-15 17:20:33 -06002982 .. attribute:: parsed_version
2983
Paul Kehrerbbffc402014-12-17 13:33:55 -06002984 :type: int
2985
2986 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06002987
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05002988.. class:: DuplicateExtension
2989
2990 This is raised when more than one X.509 extension of the same type is
2991 found within a certificate.
2992
2993 .. attribute:: oid
2994
2995 :type: :class:`ObjectIdentifier`
2996
2997 Returns the OID.
2998
Paul Kehrerfa56a232015-03-17 13:14:03 -05002999.. class:: ExtensionNotFound
3000
3001 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
3002 an extension OID that is not present in the certificate.
3003
3004 .. attribute:: oid
3005
3006 :type: :class:`ObjectIdentifier`
3007
3008 Returns the OID.
3009
Paul Kehrer9089c912015-04-20 22:15:20 -05003010.. class:: UnsupportedGeneralNameType
3011
3012 This is raised when a certificate contains an unsupported general name
3013 type in an extension.
3014
Paul Kehrerbed07352015-04-21 08:31:10 -05003015 .. attribute:: type
3016
Paul Kehrer0a621bf2015-04-22 09:22:56 -05003017 :type: int
3018
3019 The integer value of the unsupported type. The complete list of
3020 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05003021
Paul Kehrer016e08a2014-11-26 09:41:18 -10003022
Paul Kehrerc7c9a432015-04-19 09:20:13 -05003023.. _`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 -05003024.. _`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 -05003025.. _`CABForum Guidelines`: https://cabforum.org/baseline-requirements-documents/