Alex Gaynor | 4af5b37 | 2015-07-12 10:30:59 -0500 | [diff] [blame] | 1 | X.509 Reference |
| 2 | =============== |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 3 | |
Paul Kehrer | a9d78c1 | 2014-11-26 10:59:03 -1000 | [diff] [blame] | 4 | .. currentmodule:: cryptography.x509 |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 5 | |
Paul Kehrer | d26c4db | 2015-03-15 15:36:24 -0500 | [diff] [blame] | 6 | .. testsetup:: |
| 7 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 8 | 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 Kehrer | d26c4db | 2015-03-15 15:36:24 -0500 | [diff] [blame] | 23 | 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 Kehrer | d3dafbd | 2015-03-15 16:24:18 -0500 | [diff] [blame] | 44 | 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 Kehrer | 93ae805 | 2015-05-02 23:18:09 -0500 | [diff] [blame] | 68 | 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 | |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 104 | Loading Certificates |
| 105 | ~~~~~~~~~~~~~~~~~~~~ |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 106 | |
| 107 | .. function:: load_pem_x509_certificate(data, backend) |
| 108 | |
| 109 | .. versionadded:: 0.7 |
| 110 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 111 | Deserialize a certificate from PEM encoded data. PEM certificates are |
| 112 | base64 decoded and have delimiters that look like |
| 113 | ``-----BEGIN CERTIFICATE-----``. |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 114 | |
| 115 | :param bytes data: The PEM encoded certificate data. |
| 116 | |
| 117 | :param backend: A backend supporting the |
| 118 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 119 | interface. |
| 120 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 121 | :returns: An instance of :class:`~cryptography.x509.Certificate`. |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 122 | |
Alex Gaynor | 5ce1404 | 2016-05-29 13:13:46 -0400 | [diff] [blame] | 123 | .. doctest:: |
| 124 | |
| 125 | >>> from cryptography import x509 |
| 126 | >>> from cryptography.hazmat.backends import default_backend |
| 127 | >>> cert = x509.load_pem_x509_certificate(pem_data, default_backend()) |
Chelsea Winfree | e295f3a | 2016-06-02 21:15:54 -0700 | [diff] [blame] | 128 | >>> cert.serial_number |
Alex Gaynor | 5ce1404 | 2016-05-29 13:13:46 -0400 | [diff] [blame] | 129 | 2 |
| 130 | |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 131 | .. function:: load_der_x509_certificate(data, backend) |
| 132 | |
| 133 | .. versionadded:: 0.7 |
| 134 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 135 | Deserialize a certificate from DER encoded data. DER is a binary format |
Paul Kehrer | 92aac38 | 2014-12-15 16:25:28 -0600 | [diff] [blame] | 136 | and is commonly found in files with the ``.cer`` extension (although file |
| 137 | extensions are not a guarantee of encoding type). |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 138 | |
| 139 | :param bytes data: The DER encoded certificate data. |
| 140 | |
| 141 | :param backend: A backend supporting the |
| 142 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 143 | interface. |
| 144 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 145 | :returns: An instance of :class:`~cryptography.x509.Certificate`. |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 146 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 147 | Loading Certificate Revocation Lists |
| 148 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 149 | |
| 150 | .. function:: load_pem_x509_crl(data, backend) |
| 151 | |
| 152 | .. versionadded:: 1.1 |
| 153 | |
| 154 | Deserialize a certificate revocation list (CRL) from PEM encoded data. PEM |
| 155 | requests are base64 decoded and have delimiters that look like |
Erik Trauschke | 32bbfe0 | 2015-10-21 08:04:55 -0700 | [diff] [blame] | 156 | ``-----BEGIN X509 CRL-----``. |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 157 | |
| 158 | :param bytes data: The PEM encoded request data. |
| 159 | |
| 160 | :param backend: A backend supporting the |
| 161 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 162 | interface. |
| 163 | |
| 164 | :returns: An instance of |
| 165 | :class:`~cryptography.x509.CertificateRevocationList`. |
| 166 | |
Alex Gaynor | 5ce1404 | 2016-05-29 13:13:46 -0400 | [diff] [blame] | 167 | .. doctest:: |
| 168 | |
| 169 | >>> from cryptography import x509 |
| 170 | >>> from cryptography.hazmat.backends import default_backend |
| 171 | >>> from cryptography.hazmat.primitives import hashes |
| 172 | >>> crl = x509.load_pem_x509_crl(pem_crl_data, default_backend()) |
| 173 | >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256) |
| 174 | True |
| 175 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 176 | .. function:: load_der_x509_crl(data, backend) |
| 177 | |
| 178 | .. versionadded:: 1.1 |
| 179 | |
| 180 | Deserialize a certificate revocation list (CRL) from DER encoded data. DER |
| 181 | is a binary format. |
| 182 | |
| 183 | :param bytes data: The DER encoded request data. |
| 184 | |
| 185 | :param backend: A backend supporting the |
| 186 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 187 | interface. |
| 188 | |
| 189 | :returns: An instance of |
| 190 | :class:`~cryptography.x509.CertificateRevocationList`. |
| 191 | |
Paul Kehrer | a1a1f23 | 2015-03-15 15:34:35 -0500 | [diff] [blame] | 192 | Loading Certificate Signing Requests |
| 193 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 194 | |
Paul Kehrer | 31e3988 | 2015-03-11 11:37:04 -0500 | [diff] [blame] | 195 | .. function:: load_pem_x509_csr(data, backend) |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 196 | |
| 197 | .. versionadded:: 0.9 |
| 198 | |
Paul Kehrer | a1a1f23 | 2015-03-15 15:34:35 -0500 | [diff] [blame] | 199 | Deserialize a certificate signing request (CSR) from PEM encoded data. PEM |
Paul Kehrer | 5aadb9c | 2015-03-11 20:48:42 -0500 | [diff] [blame] | 200 | requests are base64 decoded and have delimiters that look like |
Paul Kehrer | d3dafbd | 2015-03-15 16:24:18 -0500 | [diff] [blame] | 201 | ``-----BEGIN CERTIFICATE REQUEST-----``. This format is also known as |
| 202 | PKCS#10. |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 203 | |
| 204 | :param bytes data: The PEM encoded request data. |
| 205 | |
| 206 | :param backend: A backend supporting the |
| 207 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 208 | interface. |
| 209 | |
Paul Kehrer | a1a1f23 | 2015-03-15 15:34:35 -0500 | [diff] [blame] | 210 | :returns: An instance of |
| 211 | :class:`~cryptography.x509.CertificateSigningRequest`. |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 212 | |
Alex Gaynor | 5ce1404 | 2016-05-29 13:13:46 -0400 | [diff] [blame] | 213 | .. doctest:: |
| 214 | |
| 215 | >>> from cryptography import x509 |
| 216 | >>> from cryptography.hazmat.backends import default_backend |
| 217 | >>> from cryptography.hazmat.primitives import hashes |
| 218 | >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend()) |
| 219 | >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1) |
| 220 | True |
| 221 | |
Paul Kehrer | 1effb6e | 2015-03-30 15:05:59 -0500 | [diff] [blame] | 222 | .. function:: load_der_x509_csr(data, backend) |
| 223 | |
| 224 | .. versionadded:: 0.9 |
| 225 | |
| 226 | Deserialize a certificate signing request (CSR) from DER encoded data. DER |
| 227 | is a binary format and is not commonly used with CSRs. |
| 228 | |
| 229 | :param bytes data: The DER encoded request data. |
| 230 | |
| 231 | :param backend: A backend supporting the |
| 232 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 233 | interface. |
| 234 | |
| 235 | :returns: An instance of |
| 236 | :class:`~cryptography.x509.CertificateSigningRequest`. |
| 237 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 238 | X.509 Certificate Object |
| 239 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 240 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 241 | .. class:: Certificate |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 242 | |
| 243 | .. versionadded:: 0.7 |
| 244 | |
| 245 | .. attribute:: version |
| 246 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 247 | :type: :class:`~cryptography.x509.Version` |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 248 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 249 | The certificate version as an enumeration. Version 3 certificates are |
| 250 | the latest version and also the only type you should see in practice. |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 251 | |
Alex Gaynor | 89c4dc8 | 2014-12-16 16:49:33 -0800 | [diff] [blame] | 252 | :raises cryptography.x509.InvalidVersion: If the version in the |
Alex Gaynor | 6d7ab4c | 2014-12-16 16:50:33 -0800 | [diff] [blame] | 253 | certificate is not a known |
| 254 | :class:`X.509 version <cryptography.x509.Version>`. |
Paul Kehrer | 92aac38 | 2014-12-15 16:25:28 -0600 | [diff] [blame] | 255 | |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 256 | .. doctest:: |
| 257 | |
| 258 | >>> cert.version |
| 259 | <Version.v3: 2> |
| 260 | |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 261 | .. method:: fingerprint(algorithm) |
| 262 | |
| 263 | :param algorithm: The |
Paul Kehrer | 601278a | 2015-02-12 12:51:00 -0600 | [diff] [blame] | 264 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 265 | that will be used to generate the fingerprint. |
| 266 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 267 | :return bytes: The fingerprint using the supplied hash algorithm, as |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 268 | bytes. |
| 269 | |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 270 | .. doctest:: |
| 271 | |
| 272 | >>> from cryptography.hazmat.primitives import hashes |
| 273 | >>> cert.fingerprint(hashes.SHA256()) |
Paul Kehrer | 78a8150 | 2014-12-16 14:47:52 -0600 | [diff] [blame] | 274 | '\x86\xd2\x187Gc\xfc\xe7}[+E9\x8d\xb4\x8f\x10\xe5S\xda\x18u\xbe}a\x03\x08[\xac\xa04?' |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 275 | |
Chelsea Winfree | e295f3a | 2016-06-02 21:15:54 -0700 | [diff] [blame] | 276 | .. attribute:: serial_number |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 277 | |
| 278 | :type: int |
| 279 | |
| 280 | The serial as a Python integer. |
| 281 | |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 282 | .. doctest:: |
| 283 | |
Chelsea Winfree | e295f3a | 2016-06-02 21:15:54 -0700 | [diff] [blame] | 284 | >>> cert.serial_number |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 285 | 2 |
| 286 | |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 287 | .. method:: public_key() |
| 288 | |
Alex Gaynor | 4c2561a | 2015-10-12 23:53:39 -0400 | [diff] [blame] | 289 | The public key associated with the certificate. |
| 290 | |
| 291 | :returns: |
Alex Stapleton | f79c231 | 2014-12-30 12:50:14 +0000 | [diff] [blame] | 292 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or |
Paul Kehrer | 45efdbc | 2015-02-12 10:58:22 -0600 | [diff] [blame] | 293 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or |
| 294 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey` |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 295 | |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 296 | .. doctest:: |
| 297 | |
Alex Stapleton | f79c231 | 2014-12-30 12:50:14 +0000 | [diff] [blame] | 298 | >>> from cryptography.hazmat.primitives.asymmetric import rsa |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 299 | >>> public_key = cert.public_key() |
Alex Stapleton | f79c231 | 2014-12-30 12:50:14 +0000 | [diff] [blame] | 300 | >>> isinstance(public_key, rsa.RSAPublicKey) |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 301 | True |
| 302 | |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 303 | .. attribute:: not_valid_before |
| 304 | |
| 305 | :type: :class:`datetime.datetime` |
| 306 | |
Paul Kehrer | 78a8150 | 2014-12-16 14:47:52 -0600 | [diff] [blame] | 307 | A naïve datetime representing the beginning of the validity period for |
| 308 | the certificate in UTC. This value is inclusive. |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 309 | |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 310 | .. doctest:: |
| 311 | |
| 312 | >>> cert.not_valid_before |
| 313 | datetime.datetime(2010, 1, 1, 8, 30) |
| 314 | |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 315 | .. attribute:: not_valid_after |
| 316 | |
| 317 | :type: :class:`datetime.datetime` |
| 318 | |
Paul Kehrer | 78a8150 | 2014-12-16 14:47:52 -0600 | [diff] [blame] | 319 | A naïve datetime representing the end of the validity period for the |
| 320 | certificate in UTC. This value is inclusive. |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 321 | |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 322 | .. doctest:: |
| 323 | |
| 324 | >>> cert.not_valid_after |
| 325 | datetime.datetime(2030, 12, 31, 8, 30) |
| 326 | |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 327 | .. attribute:: issuer |
| 328 | |
| 329 | .. versionadded:: 0.8 |
| 330 | |
| 331 | :type: :class:`Name` |
| 332 | |
| 333 | The :class:`Name` of the issuer. |
| 334 | |
| 335 | .. attribute:: subject |
| 336 | |
| 337 | .. versionadded:: 0.8 |
| 338 | |
| 339 | :type: :class:`Name` |
| 340 | |
| 341 | The :class:`Name` of the subject. |
| 342 | |
Paul Kehrer | 8802a5b | 2015-02-13 12:06:57 -0600 | [diff] [blame] | 343 | .. attribute:: signature_hash_algorithm |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 344 | |
Paul Kehrer | 8802a5b | 2015-02-13 12:06:57 -0600 | [diff] [blame] | 345 | :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 346 | |
Paul Kehrer | e612ec7 | 2015-02-16 14:33:35 -0600 | [diff] [blame] | 347 | Returns the |
Paul Kehrer | 71d40c6 | 2015-02-19 08:21:04 -0600 | [diff] [blame] | 348 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which |
Paul Kehrer | 1a7ba87 | 2015-02-19 18:09:05 -0600 | [diff] [blame] | 349 | was used in signing this certificate. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 350 | |
| 351 | .. doctest:: |
| 352 | |
Paul Kehrer | 8802a5b | 2015-02-13 12:06:57 -0600 | [diff] [blame] | 353 | >>> from cryptography.hazmat.primitives import hashes |
| 354 | >>> isinstance(cert.signature_hash_algorithm, hashes.SHA256) |
| 355 | True |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 356 | |
Paul Kehrer | c7b29b8 | 2016-09-01 09:17:21 +0800 | [diff] [blame] | 357 | .. attribute:: signature_algorithm_oid |
| 358 | |
| 359 | .. versionadded:: 1.6 |
| 360 | |
| 361 | :type: :class:`ObjectIdentifier` |
| 362 | |
| 363 | Returns the :class:`ObjectIdentifier` of the signature algorithm used |
| 364 | to sign the certificate. This will be one of the OIDs from |
| 365 | :class:`~cryptography.x509.oid.SignatureAlgorithmOID`. |
| 366 | |
| 367 | |
| 368 | .. doctest:: |
| 369 | |
| 370 | >>> cert.signature_algorithm_oid |
| 371 | <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)> |
| 372 | |
Paul Kehrer | fbb7ac8 | 2015-03-16 19:26:29 -0500 | [diff] [blame] | 373 | .. attribute:: extensions |
| 374 | |
| 375 | :type: :class:`Extensions` |
| 376 | |
| 377 | The extensions encoded in the certificate. |
| 378 | |
| 379 | :raises cryptography.x509.DuplicateExtension: If more than one |
| 380 | extension of the same type is found within the certificate. |
| 381 | |
Paul Kehrer | d8fc0be | 2015-04-21 08:31:10 -0500 | [diff] [blame] | 382 | :raises cryptography.x509.UnsupportedExtension: If the certificate |
| 383 | contains an extension that is not supported. |
| 384 | |
Paul Kehrer | bed0735 | 2015-04-21 08:31:10 -0500 | [diff] [blame] | 385 | :raises cryptography.x509.UnsupportedGeneralNameType: If an extension |
| 386 | contains a general name that is not supported. |
| 387 | |
Paul Kehrer | b896881 | 2015-05-15 09:01:34 -0700 | [diff] [blame] | 388 | :raises UnicodeError: If an extension contains IDNA encoding that is |
| 389 | invalid or not compliant with IDNA 2008. |
| 390 | |
Paul Kehrer | fa56a23 | 2015-03-17 13:14:03 -0500 | [diff] [blame] | 391 | .. doctest:: |
| 392 | |
| 393 | >>> for ext in cert.extensions: |
| 394 | ... print(ext) |
Paul Kehrer | d774de9 | 2015-05-03 10:52:25 -0500 | [diff] [blame] | 395 | <Extension(oid=<ObjectIdentifier(oid=2.5.29.35, name=authorityKeyIdentifier)>, critical=False, value=<AuthorityKeyIdentifier(key_identifier='\xe4}_\xd1\\\x95\x86\x08,\x05\xae\xbeu\xb6e\xa7\xd9]\xa8f', authority_cert_issuer=None, authority_cert_serial_number=None)>)> |
Paul Kehrer | cbfb101 | 2015-04-10 20:57:20 -0400 | [diff] [blame] | 396 | <Extension(oid=<ObjectIdentifier(oid=2.5.29.14, name=subjectKeyIdentifier)>, critical=False, value=<SubjectKeyIdentifier(digest='X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9')>)> |
Paul Kehrer | b511ba8 | 2015-04-15 11:22:48 -0400 | [diff] [blame] | 397 | <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 Kehrer | 2008d9c | 2015-05-12 22:19:56 -0500 | [diff] [blame] | 398 | <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 Kehrer | fa56a23 | 2015-03-17 13:14:03 -0500 | [diff] [blame] | 399 | <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)> |
| 400 | |
Paul Kehrer | d91e7c1 | 2015-10-01 16:50:42 -0500 | [diff] [blame] | 401 | .. attribute:: signature |
| 402 | |
| 403 | .. versionadded:: 1.2 |
| 404 | |
| 405 | :type: bytes |
| 406 | |
| 407 | The bytes of the certificate's signature. |
| 408 | |
Paul Kehrer | d289805 | 2015-11-03 22:00:41 +0900 | [diff] [blame] | 409 | .. attribute:: tbs_certificate_bytes |
Paul Kehrer | d91e7c1 | 2015-10-01 16:50:42 -0500 | [diff] [blame] | 410 | |
| 411 | .. versionadded:: 1.2 |
| 412 | |
| 413 | :type: bytes |
| 414 | |
| 415 | The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed |
| 416 | and then signed by the private key of the certificate's issuer. This |
| 417 | data may be used to validate a signature, but use extreme caution as |
| 418 | certificate validation is a complex problem that involves much more |
| 419 | than just signature checks. |
| 420 | |
Andre Caron | a8aded6 | 2015-05-19 20:11:57 -0400 | [diff] [blame] | 421 | .. method:: public_bytes(encoding) |
| 422 | |
Alex Gaynor | d0b376b | 2015-07-05 13:58:12 -0400 | [diff] [blame] | 423 | .. versionadded:: 1.0 |
| 424 | |
Andre Caron | a8aded6 | 2015-05-19 20:11:57 -0400 | [diff] [blame] | 425 | :param encoding: The |
| 426 | :class:`~cryptography.hazmat.primitives.serialization.Encoding` |
| 427 | that will be used to serialize the certificate. |
| 428 | |
| 429 | :return bytes: The data that can be written to a file or sent |
| 430 | over the network to be verified by clients. |
| 431 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 432 | X.509 CRL (Certificate Revocation List) Object |
| 433 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 434 | |
| 435 | .. class:: CertificateRevocationList |
| 436 | |
| 437 | .. versionadded:: 1.0 |
| 438 | |
Erik Trauschke | 3cdabaf | 2015-10-13 09:42:53 -0700 | [diff] [blame] | 439 | A CertificateRevocationList is an object representing a list of revoked |
| 440 | certificates. The object is iterable and will yield the RevokedCertificate |
| 441 | objects stored in this CRL. |
| 442 | |
| 443 | .. doctest:: |
Erik Trauschke | b14f7d1 | 2015-10-13 09:55:39 -0700 | [diff] [blame] | 444 | |
Erik Trauschke | 3cdabaf | 2015-10-13 09:42:53 -0700 | [diff] [blame] | 445 | >>> len(crl) |
| 446 | 1 |
Paul Kehrer | dcdf967 | 2015-10-21 20:27:28 -0500 | [diff] [blame] | 447 | >>> revoked_certificate = crl[0] |
| 448 | >>> type(revoked_certificate) |
Erik Trauschke | 3cdabaf | 2015-10-13 09:42:53 -0700 | [diff] [blame] | 449 | <class 'cryptography.hazmat.backends.openssl.x509._RevokedCertificate'> |
| 450 | >>> for r in crl: |
| 451 | ... print(r.serial_number) |
| 452 | 0 |
| 453 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 454 | .. method:: fingerprint(algorithm) |
| 455 | |
| 456 | :param algorithm: The |
| 457 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
| 458 | that will be used to generate the fingerprint. |
| 459 | |
| 460 | :return bytes: The fingerprint using the supplied hash algorithm, as |
| 461 | bytes. |
| 462 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 463 | .. doctest:: |
| 464 | |
| 465 | >>> from cryptography.hazmat.primitives import hashes |
| 466 | >>> crl.fingerprint(hashes.SHA256()) |
| 467 | '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' |
| 468 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 469 | .. attribute:: signature_hash_algorithm |
| 470 | |
| 471 | :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
| 472 | |
| 473 | Returns the |
| 474 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which |
| 475 | was used in signing this CRL. |
| 476 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 477 | .. doctest:: |
| 478 | |
| 479 | >>> from cryptography.hazmat.primitives import hashes |
| 480 | >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256) |
| 481 | True |
| 482 | |
Paul Kehrer | c7b29b8 | 2016-09-01 09:17:21 +0800 | [diff] [blame] | 483 | .. attribute:: signature_algorithm_oid |
| 484 | |
| 485 | .. versionadded:: 1.6 |
| 486 | |
| 487 | :type: :class:`ObjectIdentifier` |
| 488 | |
| 489 | Returns the :class:`ObjectIdentifier` of the signature algorithm used |
| 490 | to sign the CRL. This will be one of the OIDs from |
| 491 | :class:`~cryptography.x509.oid.SignatureAlgorithmOID`. |
| 492 | |
| 493 | .. doctest:: |
| 494 | |
| 495 | >>> crl.signature_algorithm_oid |
| 496 | <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)> |
| 497 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 498 | .. attribute:: issuer |
| 499 | |
| 500 | :type: :class:`Name` |
| 501 | |
| 502 | The :class:`Name` of the issuer. |
| 503 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 504 | .. doctest:: |
| 505 | |
| 506 | >>> crl.issuer |
| 507 | <Name([<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>, <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'cryptography.io')>])> |
| 508 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 509 | .. attribute:: next_update |
| 510 | |
| 511 | :type: :class:`datetime.datetime` |
| 512 | |
| 513 | A naïve datetime representing when the next update to this CRL is |
| 514 | expected. |
| 515 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 516 | .. doctest:: |
| 517 | |
| 518 | >>> crl.next_update |
| 519 | datetime.datetime(2016, 1, 1, 0, 0) |
| 520 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 521 | .. attribute:: last_update |
| 522 | |
| 523 | :type: :class:`datetime.datetime` |
| 524 | |
| 525 | A naïve datetime representing when the this CRL was last updated. |
| 526 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 527 | .. doctest:: |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 528 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 529 | >>> crl.last_update |
| 530 | datetime.datetime(2015, 1, 1, 0, 0) |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 531 | |
| 532 | .. attribute:: extensions |
| 533 | |
| 534 | :type: :class:`Extensions` |
| 535 | |
| 536 | The extensions encoded in the CRL. |
| 537 | |
Erik Trauschke | 6abe2bb | 2015-11-19 10:27:01 -0800 | [diff] [blame] | 538 | .. attribute:: signature |
| 539 | |
| 540 | .. versionadded:: 1.2 |
| 541 | |
| 542 | :type: bytes |
| 543 | |
| 544 | The bytes of the CRL's signature. |
| 545 | |
| 546 | .. attribute:: tbs_certlist_bytes |
| 547 | |
| 548 | .. versionadded:: 1.2 |
| 549 | |
| 550 | :type: bytes |
| 551 | |
| 552 | The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed |
| 553 | and then signed by the private key of the CRL's issuer. This data may be |
| 554 | used to validate a signature, but use extreme caution as CRL validation |
| 555 | is a complex problem that involves much more than just signature checks. |
| 556 | |
Paul Kehrer | 54a837d | 2015-12-20 23:42:32 -0600 | [diff] [blame] | 557 | .. method:: public_bytes(encoding) |
| 558 | |
| 559 | .. versionadded:: 1.2 |
| 560 | |
| 561 | :param encoding: The |
| 562 | :class:`~cryptography.hazmat.primitives.serialization.Encoding` |
| 563 | that will be used to serialize the certificate revocation list. |
| 564 | |
| 565 | :return bytes: The data that can be written to a file or sent |
| 566 | over the network and used as part of a certificate verification |
| 567 | process. |
| 568 | |
Erik Trauschke | 6abe2bb | 2015-11-19 10:27:01 -0800 | [diff] [blame] | 569 | |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 570 | X.509 Certificate Builder |
| 571 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 572 | |
| 573 | .. class:: CertificateBuilder |
| 574 | |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 575 | .. versionadded:: 1.0 |
| 576 | |
| 577 | .. doctest:: |
| 578 | |
| 579 | >>> from cryptography import x509 |
| 580 | >>> from cryptography.hazmat.backends import default_backend |
| 581 | >>> from cryptography.hazmat.primitives import hashes |
| 582 | >>> from cryptography.hazmat.primitives.asymmetric import rsa |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 583 | >>> from cryptography.x509.oid import NameOID |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 584 | >>> import datetime |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 585 | >>> one_day = datetime.timedelta(1, 0, 0) |
| 586 | >>> private_key = rsa.generate_private_key( |
| 587 | ... public_exponent=65537, |
| 588 | ... key_size=2048, |
| 589 | ... backend=default_backend() |
| 590 | ... ) |
Cory Benfield | c47b252 | 2015-12-07 15:25:12 +0000 | [diff] [blame] | 591 | >>> public_key = private_key.public_key() |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 592 | >>> builder = x509.CertificateBuilder() |
| 593 | >>> builder = builder.subject_name(x509.Name([ |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 594 | ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'), |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 595 | ... ])) |
| 596 | >>> builder = builder.issuer_name(x509.Name([ |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 597 | ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'), |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 598 | ... ])) |
| 599 | >>> builder = builder.not_valid_before(datetime.datetime.today() - one_day) |
| 600 | >>> builder = builder.not_valid_after(datetime.datetime(2018, 8, 2)) |
Paul Kehrer | 8b89bcc | 2016-09-03 11:31:43 -0500 | [diff] [blame] | 601 | >>> builder = builder.serial_number(x509.random_serial_number()) |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 602 | >>> builder = builder.public_key(public_key) |
| 603 | >>> builder = builder.add_extension( |
| 604 | ... x509.BasicConstraints(ca=False, path_length=None), critical=True, |
| 605 | ... ) |
| 606 | >>> certificate = builder.sign( |
| 607 | ... private_key=private_key, algorithm=hashes.SHA256(), |
| 608 | ... backend=default_backend() |
| 609 | ... ) |
| 610 | >>> isinstance(certificate, x509.Certificate) |
| 611 | True |
| 612 | |
Ian Cordasco | 0092a0b | 2015-07-18 21:46:41 -0500 | [diff] [blame] | 613 | .. method:: issuer_name(name) |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 614 | |
| 615 | Sets the issuer's distinguished name. |
| 616 | |
Ian Cordasco | c9682ad | 2015-08-01 12:11:13 -0500 | [diff] [blame] | 617 | :param name: The :class:`~cryptography.x509.Name` that describes the |
| 618 | issuer (CA). |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 619 | |
Ian Cordasco | 0092a0b | 2015-07-18 21:46:41 -0500 | [diff] [blame] | 620 | .. method:: subject_name(name) |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 621 | |
| 622 | Sets the subject's distinguished name. |
| 623 | |
Ian Cordasco | c9682ad | 2015-08-01 12:11:13 -0500 | [diff] [blame] | 624 | :param name: The :class:`~cryptography.x509.Name` that describes the |
Ian Cordasco | 85fc4d5 | 2015-08-01 20:29:31 -0500 | [diff] [blame] | 625 | subject. |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 626 | |
Ian Cordasco | 0092a0b | 2015-07-18 21:46:41 -0500 | [diff] [blame] | 627 | .. method:: public_key(public_key) |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 628 | |
| 629 | Sets the subject's public key. |
| 630 | |
Ian Cordasco | 8f57142 | 2015-08-02 11:31:08 -0500 | [diff] [blame] | 631 | :param public_key: The subject's public key. This can be one of |
| 632 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`, |
| 633 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or |
| 634 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey` |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 635 | |
Ian Cordasco | 0092a0b | 2015-07-18 21:46:41 -0500 | [diff] [blame] | 636 | .. method:: serial_number(serial_number) |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 637 | |
| 638 | Sets the certificate's serial number (an integer). The CA's policy |
Paul Kehrer | 8b89bcc | 2016-09-03 11:31:43 -0500 | [diff] [blame] | 639 | determines how it attributes serial numbers to certificates. This |
| 640 | number must uniquely identify the certificate given the issuer. |
| 641 | `CABForum Guidelines`_ require entropy in the serial number |
| 642 | to provide protection against hash collision attacks. For more |
| 643 | information on secure random number generation, see |
| 644 | :doc:`/random-numbers`. |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 645 | |
| 646 | :param serial_number: Integer number that will be used by the CA to |
| 647 | identify this certificate (most notably during certificate |
Paul Kehrer | 8b89bcc | 2016-09-03 11:31:43 -0500 | [diff] [blame] | 648 | revocation checking). Users should consider using |
| 649 | :func:`~cryptography.x509.random_serial_number` when possible. |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 650 | |
Ian Cordasco | 0092a0b | 2015-07-18 21:46:41 -0500 | [diff] [blame] | 651 | .. method:: not_valid_before(time) |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 652 | |
| 653 | Sets the certificate's activation time. This is the time from which |
| 654 | clients can start trusting the certificate. It may be different from |
| 655 | the time at which the certificate was created. |
| 656 | |
Ian Cordasco | 17c8900 | 2015-08-02 21:13:59 -0500 | [diff] [blame] | 657 | :param time: The :class:`datetime.datetime` object (in UTC) that marks the |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 658 | activation time for the certificate. The certificate may not be |
| 659 | trusted clients if it is used before this time. |
| 660 | |
Ian Cordasco | 0092a0b | 2015-07-18 21:46:41 -0500 | [diff] [blame] | 661 | .. method:: not_valid_after(time) |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 662 | |
| 663 | Sets the certificate's expiration time. This is the time from which |
| 664 | clients should no longer trust the certificate. The CA's policy will |
| 665 | determine how long the certificate should remain in use. |
| 666 | |
Ian Cordasco | 17c8900 | 2015-08-02 21:13:59 -0500 | [diff] [blame] | 667 | :param time: The :class:`datetime.datetime` object (in UTC) that marks the |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 668 | expiration time for the certificate. The certificate may not be |
| 669 | trusted clients if it is used after this time. |
| 670 | |
Ian Cordasco | 17c8900 | 2015-08-02 21:13:59 -0500 | [diff] [blame] | 671 | .. method:: add_extension(extension, critical) |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 672 | |
| 673 | Adds an X.509 extension to the certificate. |
| 674 | |
Paul Kehrer | 2c145cc | 2015-10-02 11:27:21 -0500 | [diff] [blame] | 675 | :param extension: An extension conforming to the |
| 676 | :class:`~cryptography.x509.ExtensionType` interface. |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 677 | |
Ian Cordasco | 17c8900 | 2015-08-02 21:13:59 -0500 | [diff] [blame] | 678 | :param critical: Set to ``True`` if the extension must be understood and |
| 679 | handled by whoever reads the certificate. |
| 680 | |
Paul Kehrer | 9add80e | 2015-08-03 17:53:14 +0100 | [diff] [blame] | 681 | .. method:: sign(private_key, algorithm, backend) |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 682 | |
| 683 | Sign the certificate using the CA's private key. |
| 684 | |
Ian Cordasco | c5e1c25 | 2015-07-31 23:33:35 -0500 | [diff] [blame] | 685 | :param private_key: The |
| 686 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`, |
| 687 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or |
| 688 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey` |
| 689 | that will be used to sign the certificate. |
| 690 | |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 691 | :param algorithm: The |
| 692 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that |
| 693 | will be used to generate the signature. |
| 694 | |
Paul Kehrer | 9add80e | 2015-08-03 17:53:14 +0100 | [diff] [blame] | 695 | :param backend: Backend that will be used to build the certificate. |
| 696 | Must support the |
| 697 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 698 | interface. |
| 699 | |
Benjamin Peterson | 9ed312b | 2015-10-12 20:51:34 -0700 | [diff] [blame] | 700 | :returns: :class:`~cryptography.x509.Certificate` |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 701 | |
| 702 | |
Paul Kehrer | 5aadb9c | 2015-03-11 20:48:42 -0500 | [diff] [blame] | 703 | X.509 CSR (Certificate Signing Request) Object |
| 704 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 705 | |
Paul Kehrer | a1a1f23 | 2015-03-15 15:34:35 -0500 | [diff] [blame] | 706 | .. class:: CertificateSigningRequest |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 707 | |
| 708 | .. versionadded:: 0.9 |
| 709 | |
| 710 | .. method:: public_key() |
| 711 | |
Alex Gaynor | 4c2561a | 2015-10-12 23:53:39 -0400 | [diff] [blame] | 712 | The public key associated with the request. |
| 713 | |
| 714 | :returns: |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 715 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or |
| 716 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or |
| 717 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey` |
| 718 | |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 719 | .. doctest:: |
| 720 | |
| 721 | >>> from cryptography.hazmat.primitives.asymmetric import rsa |
Paul Kehrer | a1a1f23 | 2015-03-15 15:34:35 -0500 | [diff] [blame] | 722 | >>> public_key = csr.public_key() |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 723 | >>> isinstance(public_key, rsa.RSAPublicKey) |
| 724 | True |
| 725 | |
| 726 | .. attribute:: subject |
| 727 | |
| 728 | :type: :class:`Name` |
| 729 | |
| 730 | The :class:`Name` of the subject. |
| 731 | |
| 732 | .. attribute:: signature_hash_algorithm |
| 733 | |
| 734 | :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
| 735 | |
| 736 | Returns the |
| 737 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which |
| 738 | was used in signing this request. |
| 739 | |
| 740 | .. doctest:: |
| 741 | |
| 742 | >>> from cryptography.hazmat.primitives import hashes |
Paul Kehrer | a1a1f23 | 2015-03-15 15:34:35 -0500 | [diff] [blame] | 743 | >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1) |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 744 | True |
| 745 | |
Paul Kehrer | c7b29b8 | 2016-09-01 09:17:21 +0800 | [diff] [blame] | 746 | .. attribute:: signature_algorithm_oid |
| 747 | |
| 748 | .. versionadded:: 1.6 |
| 749 | |
| 750 | :type: :class:`ObjectIdentifier` |
| 751 | |
| 752 | Returns the :class:`ObjectIdentifier` of the signature algorithm used |
| 753 | to sign the request. This will be one of the OIDs from |
| 754 | :class:`~cryptography.x509.oid.SignatureAlgorithmOID`. |
| 755 | |
| 756 | .. doctest:: |
| 757 | |
| 758 | >>> csr.signature_algorithm_oid |
| 759 | <ObjectIdentifier(oid=1.2.840.113549.1.1.5, name=sha1WithRSAEncryption)> |
| 760 | |
Paul Kehrer | c4e6194 | 2015-08-01 21:21:13 +0100 | [diff] [blame] | 761 | .. attribute:: extensions |
| 762 | |
| 763 | :type: :class:`Extensions` |
| 764 | |
| 765 | The extensions encoded in the certificate signing request. |
| 766 | |
| 767 | :raises cryptography.x509.DuplicateExtension: If more than one |
Paul Kehrer | 24283d2 | 2015-08-01 21:31:19 +0100 | [diff] [blame] | 768 | extension of the same type is found within the certificate signing request. |
Paul Kehrer | c4e6194 | 2015-08-01 21:21:13 +0100 | [diff] [blame] | 769 | |
Paul Kehrer | 24283d2 | 2015-08-01 21:31:19 +0100 | [diff] [blame] | 770 | :raises cryptography.x509.UnsupportedExtension: If the certificate signing request |
Paul Kehrer | c4e6194 | 2015-08-01 21:21:13 +0100 | [diff] [blame] | 771 | contains an extension that is not supported. |
| 772 | |
| 773 | :raises cryptography.x509.UnsupportedGeneralNameType: If an extension |
| 774 | contains a general name that is not supported. |
| 775 | |
| 776 | :raises UnicodeError: If an extension contains IDNA encoding that is |
| 777 | invalid or not compliant with IDNA 2008. |
| 778 | |
| 779 | |
Andre Caron | 476c5df | 2015-05-18 10:23:28 -0400 | [diff] [blame] | 780 | .. method:: public_bytes(encoding) |
| 781 | |
Alex Gaynor | d0b376b | 2015-07-05 13:58:12 -0400 | [diff] [blame] | 782 | .. versionadded:: 1.0 |
| 783 | |
Andre Caron | 476c5df | 2015-05-18 10:23:28 -0400 | [diff] [blame] | 784 | :param encoding: The |
| 785 | :class:`~cryptography.hazmat.primitives.serialization.Encoding` |
| 786 | that will be used to serialize the certificate request. |
| 787 | |
| 788 | :return bytes: The data that can be written to a file or sent |
| 789 | over the network to be signed by the certificate |
| 790 | authority. |
| 791 | |
Paul Kehrer | ab20939 | 2015-12-01 14:50:31 -0600 | [diff] [blame] | 792 | .. attribute:: signature |
| 793 | |
| 794 | .. versionadded:: 1.2 |
| 795 | |
| 796 | :type: bytes |
| 797 | |
| 798 | The bytes of the certificate signing request's signature. |
| 799 | |
| 800 | .. attribute:: tbs_certrequest_bytes |
| 801 | |
| 802 | .. versionadded:: 1.2 |
| 803 | |
| 804 | :type: bytes |
| 805 | |
| 806 | The DER encoded bytes payload (as defined by :rfc:`2986`) that is |
| 807 | hashed and then signed by the private key (corresponding to the public |
| 808 | key embedded in the CSR). This data may be used to validate the CSR |
| 809 | signature. |
| 810 | |
Joern Heissler | fbda8ce | 2016-01-18 00:24:44 +0100 | [diff] [blame] | 811 | .. attribute:: is_signature_valid |
Joern Heissler | 1bd77e2 | 2016-01-13 22:51:37 +0100 | [diff] [blame] | 812 | |
| 813 | .. versionadded:: 1.3 |
| 814 | |
Joern Heissler | fbda8ce | 2016-01-18 00:24:44 +0100 | [diff] [blame] | 815 | Returns True if the CSR signature is correct, False otherwise. |
Joern Heissler | 1bd77e2 | 2016-01-13 22:51:37 +0100 | [diff] [blame] | 816 | |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 817 | X.509 Certificate Revocation List Builder |
| 818 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 819 | |
| 820 | .. class:: CertificateRevocationListBuilder |
| 821 | |
| 822 | .. versionadded:: 1.2 |
| 823 | |
| 824 | .. doctest:: |
| 825 | |
| 826 | >>> from cryptography import x509 |
| 827 | >>> from cryptography.hazmat.backends import default_backend |
| 828 | >>> from cryptography.hazmat.primitives import hashes |
| 829 | >>> from cryptography.hazmat.primitives.asymmetric import rsa |
| 830 | >>> from cryptography.x509.oid import NameOID |
| 831 | >>> import datetime |
| 832 | >>> one_day = datetime.timedelta(1, 0, 0) |
| 833 | >>> private_key = rsa.generate_private_key( |
| 834 | ... public_exponent=65537, |
| 835 | ... key_size=2048, |
| 836 | ... backend=default_backend() |
| 837 | ... ) |
| 838 | >>> builder = x509.CertificateRevocationListBuilder() |
| 839 | >>> builder = builder.issuer_name(x509.Name([ |
| 840 | ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io CA'), |
| 841 | ... ])) |
| 842 | >>> builder = builder.last_update(datetime.datetime.today()) |
| 843 | >>> builder = builder.next_update(datetime.datetime.today() + one_day) |
Paul Kehrer | 4c7fd5f | 2015-12-25 13:40:55 -0600 | [diff] [blame] | 844 | >>> revoked_cert = x509.RevokedCertificateBuilder().serial_number( |
| 845 | ... 333 |
| 846 | ... ).revocation_date( |
| 847 | ... datetime.datetime.today() |
| 848 | ... ).build(default_backend()) |
| 849 | >>> builder = builder.add_revoked_certificate(revoked_cert) |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 850 | >>> crl = builder.sign( |
| 851 | ... private_key=private_key, algorithm=hashes.SHA256(), |
| 852 | ... backend=default_backend() |
| 853 | ... ) |
Paul Kehrer | 4c7fd5f | 2015-12-25 13:40:55 -0600 | [diff] [blame] | 854 | >>> len(crl) |
| 855 | 1 |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 856 | |
| 857 | .. method:: issuer_name(name) |
| 858 | |
| 859 | Sets the issuer's distinguished name. |
| 860 | |
| 861 | :param name: The :class:`~cryptography.x509.Name` that describes the |
| 862 | issuer (CA). |
| 863 | |
| 864 | .. method:: last_update(time) |
| 865 | |
Paul Kehrer | 0325b9d | 2015-12-24 19:19:59 -0600 | [diff] [blame] | 866 | Sets this CRL's activation time. This is the time from which |
| 867 | clients can start trusting this CRL. It may be different from |
| 868 | the time at which this CRL was created. This is also known as the |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 869 | ``thisUpdate`` time. |
| 870 | |
Paul Kehrer | 0325b9d | 2015-12-24 19:19:59 -0600 | [diff] [blame] | 871 | :param time: The :class:`datetime.datetime` object (in UTC) that marks |
| 872 | the activation time for this CRL. The CRL may not be trusted if it |
| 873 | is used before this time. |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 874 | |
| 875 | .. method:: next_update(time) |
| 876 | |
Paul Kehrer | 0325b9d | 2015-12-24 19:19:59 -0600 | [diff] [blame] | 877 | Sets this CRL's next update time. This is the time by which |
| 878 | a new CRL will be issued. The CA is allowed to issue a new CRL before |
| 879 | this date, however clients are not required to check for it. |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 880 | |
Paul Kehrer | 0325b9d | 2015-12-24 19:19:59 -0600 | [diff] [blame] | 881 | :param time: The :class:`datetime.datetime` object (in UTC) that marks |
| 882 | the next update time for this CRL. |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 883 | |
Paul Kehrer | 426b48d | 2015-12-24 20:50:43 -0600 | [diff] [blame] | 884 | .. method:: add_extension(extension, critical) |
| 885 | |
| 886 | Adds an X.509 extension to this CRL. |
| 887 | |
| 888 | :param extension: An extension with the |
| 889 | :class:`~cryptography.x509.ExtensionType` interface. |
| 890 | |
| 891 | :param critical: Set to ``True`` if the extension must be understood and |
| 892 | handled by whoever reads the CRL. |
| 893 | |
Paul Kehrer | 4c7fd5f | 2015-12-25 13:40:55 -0600 | [diff] [blame] | 894 | .. method:: add_revoked_certificate(revoked_certificate) |
| 895 | |
| 896 | Adds a revoked certificate to this CRL. |
| 897 | |
| 898 | :param revoked_certificate: An instance of |
| 899 | :class:`~cryptography.x509.RevokedCertificate`. These can be |
| 900 | obtained from an existing CRL or created with |
| 901 | :class:`~cryptography.x509.RevokedCertificateBuilder`. |
| 902 | |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 903 | .. method:: sign(private_key, algorithm, backend) |
| 904 | |
Paul Kehrer | 0325b9d | 2015-12-24 19:19:59 -0600 | [diff] [blame] | 905 | Sign this CRL using the CA's private key. |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 906 | |
| 907 | :param private_key: The |
| 908 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`, |
| 909 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or |
| 910 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey` |
| 911 | that will be used to sign the certificate. |
| 912 | |
| 913 | :param algorithm: The |
| 914 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that |
| 915 | will be used to generate the signature. |
| 916 | |
| 917 | :param backend: Backend that will be used to build the CRL. |
| 918 | Must support the |
| 919 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 920 | interface. |
| 921 | |
| 922 | :returns: :class:`~cryptography.x509.CertificateRevocationList` |
| 923 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 924 | X.509 Revoked Certificate Object |
Erik Trauschke | c5a8d17 | 2015-05-28 10:24:25 -0700 | [diff] [blame] | 925 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 926 | |
| 927 | .. class:: RevokedCertificate |
| 928 | |
| 929 | .. versionadded:: 1.0 |
| 930 | |
| 931 | .. attribute:: serial_number |
| 932 | |
| 933 | :type: :class:`int` |
| 934 | |
| 935 | An integer representing the serial number of the revoked certificate. |
| 936 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 937 | .. doctest:: |
| 938 | |
Erik Trauschke | 3cdabaf | 2015-10-13 09:42:53 -0700 | [diff] [blame] | 939 | >>> revoked_certificate.serial_number |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 940 | 0 |
| 941 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 942 | .. attribute:: revocation_date |
| 943 | |
| 944 | :type: :class:`datetime.datetime` |
| 945 | |
| 946 | A naïve datetime representing the date this certificates was revoked. |
| 947 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 948 | .. doctest:: |
| 949 | |
Erik Trauschke | 77f5a25 | 2015-10-14 08:06:38 -0700 | [diff] [blame] | 950 | >>> revoked_certificate.revocation_date |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 951 | datetime.datetime(2015, 1, 1, 0, 0) |
| 952 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 953 | .. attribute:: extensions |
| 954 | |
| 955 | :type: :class:`Extensions` |
| 956 | |
| 957 | The extensions encoded in the revoked certificate. |
Andre Caron | 476c5df | 2015-05-18 10:23:28 -0400 | [diff] [blame] | 958 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 959 | .. doctest:: |
| 960 | |
Erik Trauschke | 77f5a25 | 2015-10-14 08:06:38 -0700 | [diff] [blame] | 961 | >>> for ext in revoked_certificate.extensions: |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 962 | ... print(ext) |
Paul Kehrer | 23c0bbc | 2015-12-25 22:35:19 -0600 | [diff] [blame] | 963 | <Extension(oid=<ObjectIdentifier(oid=2.5.29.24, name=invalidityDate)>, critical=False, value=<InvalidityDate(invalidity_date=2015-01-01 00:00:00)>)> |
Paul Kehrer | 7058ece | 2015-12-25 22:28:29 -0600 | [diff] [blame] | 964 | <Extension(oid=<ObjectIdentifier(oid=2.5.29.21, name=cRLReason)>, critical=False, value=<CRLReason(reason=ReasonFlags.key_compromise)>)> |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 965 | |
Paul Kehrer | c33ffd7 | 2015-12-25 10:59:22 -0600 | [diff] [blame] | 966 | X.509 Revoked Certificate Builder |
| 967 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 968 | |
| 969 | .. class:: RevokedCertificateBuilder |
| 970 | |
| 971 | This class is used to create :class:`~cryptography.x509.RevokedCertificate` |
| 972 | objects that can be used with the |
| 973 | :class:`~cryptography.x509.CertificateRevocationListBuilder`. |
| 974 | |
| 975 | .. versionadded:: 1.2 |
| 976 | |
| 977 | .. doctest:: |
| 978 | |
| 979 | >>> from cryptography import x509 |
| 980 | >>> from cryptography.hazmat.backends import default_backend |
| 981 | >>> import datetime |
| 982 | >>> builder = x509.RevokedCertificateBuilder() |
| 983 | >>> builder = builder.revocation_date(datetime.datetime.today()) |
| 984 | >>> builder = builder.serial_number(3333) |
| 985 | >>> revoked_certificate = builder.build(default_backend()) |
| 986 | >>> isinstance(revoked_certificate, x509.RevokedCertificate) |
| 987 | True |
| 988 | |
| 989 | .. method:: serial_number(serial_number) |
| 990 | |
| 991 | Sets the revoked certificate's serial number. |
| 992 | |
| 993 | :param serial_number: Integer number that is used to identify the |
| 994 | revoked certificate. |
| 995 | |
| 996 | .. method:: revocation_date(time) |
| 997 | |
| 998 | Sets the certificate's revocation date. |
| 999 | |
| 1000 | :param time: The :class:`datetime.datetime` object (in UTC) that marks the |
| 1001 | revocation time for the certificate. |
| 1002 | |
Paul Kehrer | e5f152b | 2015-12-25 23:55:47 -0600 | [diff] [blame] | 1003 | .. method:: add_extension(extension, critical) |
| 1004 | |
| 1005 | Adds an X.509 extension to this revoked certificate. |
| 1006 | |
| 1007 | :param extension: An instance of one of the |
| 1008 | :ref:`CRL entry extensions <crl_entry_extensions>`. |
| 1009 | |
| 1010 | :param critical: Set to ``True`` if the extension must be understood and |
| 1011 | handled. |
| 1012 | |
Paul Kehrer | c33ffd7 | 2015-12-25 10:59:22 -0600 | [diff] [blame] | 1013 | .. method:: build(backend) |
| 1014 | |
| 1015 | Create a revoked certificate object using the provided backend. |
| 1016 | |
| 1017 | :param backend: Backend that will be used to build the revoked |
| 1018 | certificate. Must support the |
| 1019 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 1020 | interface. |
| 1021 | |
| 1022 | :returns: :class:`~cryptography.x509.RevokedCertificate` |
| 1023 | |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1024 | X.509 CSR (Certificate Signing Request) Builder Object |
| 1025 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1026 | |
| 1027 | .. class:: CertificateSigningRequestBuilder |
| 1028 | |
Andre Caron | d259ee5 | 2015-06-02 23:47:11 -0400 | [diff] [blame] | 1029 | .. versionadded:: 1.0 |
| 1030 | |
| 1031 | .. doctest:: |
| 1032 | |
| 1033 | >>> from cryptography import x509 |
| 1034 | >>> from cryptography.hazmat.backends import default_backend |
| 1035 | >>> from cryptography.hazmat.primitives import hashes |
| 1036 | >>> from cryptography.hazmat.primitives.asymmetric import rsa |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1037 | >>> from cryptography.x509.oid import NameOID |
Andre Caron | d259ee5 | 2015-06-02 23:47:11 -0400 | [diff] [blame] | 1038 | >>> private_key = rsa.generate_private_key( |
| 1039 | ... public_exponent=65537, |
| 1040 | ... key_size=2048, |
| 1041 | ... backend=default_backend() |
| 1042 | ... ) |
| 1043 | >>> builder = x509.CertificateSigningRequestBuilder() |
Andre Caron | a9a5117 | 2015-06-06 20:18:44 -0400 | [diff] [blame] | 1044 | >>> builder = builder.subject_name(x509.Name([ |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1045 | ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'), |
Andre Caron | d259ee5 | 2015-06-02 23:47:11 -0400 | [diff] [blame] | 1046 | ... ])) |
Ian Cordasco | f06b6be | 2015-06-21 10:09:18 -0500 | [diff] [blame] | 1047 | >>> builder = builder.add_extension( |
Ian Cordasco | 0112b02 | 2015-06-16 17:51:18 -0500 | [diff] [blame] | 1048 | ... x509.BasicConstraints(ca=False, path_length=None), critical=True, |
Andre Caron | 472fd69 | 2015-06-06 20:04:44 -0400 | [diff] [blame] | 1049 | ... ) |
Andre Caron | d259ee5 | 2015-06-02 23:47:11 -0400 | [diff] [blame] | 1050 | >>> request = builder.sign( |
Alex Gaynor | de9e584 | 2015-06-26 20:11:23 -0400 | [diff] [blame] | 1051 | ... private_key, hashes.SHA256(), default_backend() |
Andre Caron | d259ee5 | 2015-06-02 23:47:11 -0400 | [diff] [blame] | 1052 | ... ) |
| 1053 | >>> isinstance(request, x509.CertificateSigningRequest) |
| 1054 | True |
| 1055 | |
Andre Caron | a9a5117 | 2015-06-06 20:18:44 -0400 | [diff] [blame] | 1056 | .. method:: subject_name(name) |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1057 | |
Andre Caron | 341ff85 | 2015-06-06 20:14:31 -0400 | [diff] [blame] | 1058 | :param name: The :class:`~cryptography.x509.Name` of the certificate |
| 1059 | subject. |
| 1060 | :returns: A new |
| 1061 | :class:`~cryptography.x509.CertificateSigningRequestBuilder`. |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1062 | |
Ian Cordasco | f06b6be | 2015-06-21 10:09:18 -0500 | [diff] [blame] | 1063 | .. method:: add_extension(extension, critical) |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1064 | |
Paul Kehrer | 2c145cc | 2015-10-02 11:27:21 -0500 | [diff] [blame] | 1065 | :param extension: An extension conforming to the |
| 1066 | :class:`~cryptography.x509.ExtensionType` interface. |
Andre Caron | 472fd69 | 2015-06-06 20:04:44 -0400 | [diff] [blame] | 1067 | :param critical: Set to `True` if the extension must be understood and |
| 1068 | handled by whoever reads the certificate. |
Andre Caron | 341ff85 | 2015-06-06 20:14:31 -0400 | [diff] [blame] | 1069 | :returns: A new |
| 1070 | :class:`~cryptography.x509.CertificateSigningRequestBuilder`. |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1071 | |
Alex Gaynor | b3b0fbe | 2015-06-26 19:57:18 -0400 | [diff] [blame] | 1072 | .. method:: sign(private_key, algorithm, backend) |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1073 | |
| 1074 | :param backend: Backend that will be used to sign the request. |
| 1075 | Must support the |
| 1076 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 1077 | interface. |
| 1078 | |
| 1079 | :param private_key: The |
Andre Caron | 24f9bf4 | 2015-06-06 20:14:54 -0400 | [diff] [blame] | 1080 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`, |
| 1081 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or |
| 1082 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey` |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1083 | that will be used to sign the request. When the request is |
| 1084 | signed by a certificate authority, the private key's associated |
| 1085 | public key will be stored in the resulting certificate. |
| 1086 | |
| 1087 | :param algorithm: The |
| 1088 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
| 1089 | that will be used to generate the request signature. |
| 1090 | |
Andre Caron | 341ff85 | 2015-06-06 20:14:31 -0400 | [diff] [blame] | 1091 | :returns: A new |
| 1092 | :class:`~cryptography.x509.CertificateSigningRequest`. |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1093 | |
| 1094 | |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 1095 | .. class:: Name |
| 1096 | |
| 1097 | .. versionadded:: 0.8 |
| 1098 | |
Paul Kehrer | 53d8d49 | 2015-02-13 18:47:30 -0600 | [diff] [blame] | 1099 | An X509 Name is an ordered list of attributes. The object is iterable to |
Paul Kehrer | d21596e | 2015-02-14 09:17:26 -0600 | [diff] [blame] | 1100 | get every attribute or you can use :meth:`Name.get_attributes_for_oid` to |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 1101 | obtain the specific type you want. Names are sometimes represented as a |
Paul Kehrer | 53d8d49 | 2015-02-13 18:47:30 -0600 | [diff] [blame] | 1102 | slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or |
| 1103 | ``CN=mydomain.com, O=My Org, C=US``). |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 1104 | |
Paul Kehrer | 53d8d49 | 2015-02-13 18:47:30 -0600 | [diff] [blame] | 1105 | .. doctest:: |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 1106 | |
Paul Kehrer | 8b21a4a | 2015-02-14 07:56:36 -0600 | [diff] [blame] | 1107 | >>> len(cert.subject) |
Paul Kehrer | 53d8d49 | 2015-02-13 18:47:30 -0600 | [diff] [blame] | 1108 | 3 |
Paul Kehrer | 8b21a4a | 2015-02-14 07:56:36 -0600 | [diff] [blame] | 1109 | >>> for attribute in cert.subject: |
| 1110 | ... print(attribute) |
| 1111 | <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')> |
| 1112 | <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'Test Certificates 2011')> |
| 1113 | <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')> |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 1114 | |
Paul Kehrer | e901d64 | 2015-02-11 18:50:58 -0600 | [diff] [blame] | 1115 | .. method:: get_attributes_for_oid(oid) |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 1116 | |
Paul Kehrer | e901d64 | 2015-02-11 18:50:58 -0600 | [diff] [blame] | 1117 | :param oid: An :class:`ObjectIdentifier` instance. |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 1118 | |
Paul Kehrer | e901d64 | 2015-02-11 18:50:58 -0600 | [diff] [blame] | 1119 | :returns: A list of :class:`NameAttribute` instances that match the |
| 1120 | OID provided. If nothing matches an empty list will be returned. |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 1121 | |
| 1122 | .. doctest:: |
| 1123 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1124 | >>> cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME) |
Paul Kehrer | e901d64 | 2015-02-11 18:50:58 -0600 | [diff] [blame] | 1125 | [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>] |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 1126 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 1127 | .. class:: Version |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 1128 | |
| 1129 | .. versionadded:: 0.7 |
| 1130 | |
| 1131 | An enumeration for X.509 versions. |
| 1132 | |
| 1133 | .. attribute:: v1 |
| 1134 | |
| 1135 | For version 1 X.509 certificates. |
| 1136 | |
| 1137 | .. attribute:: v3 |
| 1138 | |
| 1139 | For version 3 X.509 certificates. |
| 1140 | |
Paul Kehrer | 806bfb2 | 2015-02-02 17:05:24 -0600 | [diff] [blame] | 1141 | .. class:: NameAttribute |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 1142 | |
| 1143 | .. versionadded:: 0.8 |
| 1144 | |
Paul Kehrer | 834d22f | 2015-02-06 11:01:07 -0600 | [diff] [blame] | 1145 | An X.509 name consists of a list of NameAttribute instances. |
Paul Kehrer | 5b0a8d6 | 2015-01-30 20:05:55 -0600 | [diff] [blame] | 1146 | |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 1147 | .. attribute:: oid |
| 1148 | |
| 1149 | :type: :class:`ObjectIdentifier` |
| 1150 | |
| 1151 | The attribute OID. |
| 1152 | |
| 1153 | .. attribute:: value |
| 1154 | |
Paul Kehrer | d5852cb | 2015-01-30 08:25:23 -0600 | [diff] [blame] | 1155 | :type: :term:`text` |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 1156 | |
| 1157 | The value of the attribute. |
| 1158 | |
| 1159 | .. class:: ObjectIdentifier |
| 1160 | |
| 1161 | .. versionadded:: 0.8 |
| 1162 | |
Paul Kehrer | 5b0a8d6 | 2015-01-30 20:05:55 -0600 | [diff] [blame] | 1163 | Object identifiers (frequently seen abbreviated as OID) identify the type |
Paul Kehrer | 806bfb2 | 2015-02-02 17:05:24 -0600 | [diff] [blame] | 1164 | of a value (see: :class:`NameAttribute`). |
Paul Kehrer | 5b0a8d6 | 2015-01-30 20:05:55 -0600 | [diff] [blame] | 1165 | |
Paul Kehrer | d44f9a6 | 2015-02-04 14:47:34 -0600 | [diff] [blame] | 1166 | .. attribute:: dotted_string |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 1167 | |
| 1168 | :type: :class:`str` |
| 1169 | |
Paul Kehrer | fedf4f4 | 2015-02-06 11:22:07 -0600 | [diff] [blame] | 1170 | The dotted string value of the OID (e.g. ``"2.5.4.3"``) |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 1171 | |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1172 | .. _general_name_classes: |
| 1173 | |
| 1174 | General Name Classes |
| 1175 | ~~~~~~~~~~~~~~~~~~~~ |
| 1176 | |
| 1177 | .. class:: GeneralName |
| 1178 | |
| 1179 | .. versionadded:: 0.9 |
| 1180 | |
| 1181 | This is the generic interface that all the following classes are registered |
| 1182 | against. |
| 1183 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1184 | .. class:: RFC822Name(value) |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1185 | |
| 1186 | .. versionadded:: 0.9 |
| 1187 | |
| 1188 | This corresponds to an email address. For example, ``user@example.com``. |
| 1189 | |
| 1190 | .. attribute:: value |
| 1191 | |
| 1192 | :type: :term:`text` |
| 1193 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1194 | .. class:: DNSName(value) |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1195 | |
| 1196 | .. versionadded:: 0.9 |
| 1197 | |
| 1198 | This corresponds to a domain name. For example, ``cryptography.io``. |
| 1199 | |
| 1200 | .. attribute:: value |
| 1201 | |
| 1202 | :type: :term:`text` |
| 1203 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1204 | .. class:: DirectoryName(value) |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1205 | |
| 1206 | .. versionadded:: 0.9 |
| 1207 | |
| 1208 | This corresponds to a directory name. |
| 1209 | |
| 1210 | .. attribute:: value |
| 1211 | |
| 1212 | :type: :class:`Name` |
| 1213 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1214 | .. class:: UniformResourceIdentifier(value) |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1215 | |
| 1216 | .. versionadded:: 0.9 |
| 1217 | |
| 1218 | This corresponds to a uniform resource identifier. For example, |
Paul Kehrer | b8ef82e | 2015-04-22 16:04:24 -0500 | [diff] [blame] | 1219 | ``https://cryptography.io``. The URI is parsed and IDNA decoded (see |
| 1220 | :rfc:`5895`). |
| 1221 | |
| 1222 | .. note:: |
| 1223 | |
| 1224 | URIs that do not contain ``://`` in them will not be decoded. |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1225 | |
| 1226 | .. attribute:: value |
| 1227 | |
| 1228 | :type: :term:`text` |
| 1229 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1230 | .. class:: IPAddress(value) |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1231 | |
| 1232 | .. versionadded:: 0.9 |
| 1233 | |
| 1234 | This corresponds to an IP address. |
| 1235 | |
| 1236 | .. attribute:: value |
| 1237 | |
Paul Kehrer | eb17793 | 2015-05-17 18:33:33 -0700 | [diff] [blame] | 1238 | :type: :class:`~ipaddress.IPv4Address`, |
| 1239 | :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`, |
| 1240 | or :class:`~ipaddress.IPv6Network`. |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1241 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1242 | .. class:: RegisteredID(value) |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1243 | |
| 1244 | .. versionadded:: 0.9 |
| 1245 | |
| 1246 | This corresponds to a registered ID. |
| 1247 | |
| 1248 | .. attribute:: value |
| 1249 | |
| 1250 | :type: :class:`ObjectIdentifier` |
| 1251 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1252 | .. class:: OtherName(type_id, value) |
Joshua Tauberer | 2ee5e3c | 2015-07-04 20:09:46 +0000 | [diff] [blame] | 1253 | |
| 1254 | .. versionadded:: 1.0 |
| 1255 | |
Joshua Tauberer | 18b6fc8 | 2015-07-05 21:44:51 +0000 | [diff] [blame] | 1256 | This corresponds to an ``otherName.`` An ``otherName`` has a type identifier and a value represented in binary DER format. |
Joshua Tauberer | 2ee5e3c | 2015-07-04 20:09:46 +0000 | [diff] [blame] | 1257 | |
| 1258 | .. attribute:: type_id |
| 1259 | |
| 1260 | :type: :class:`ObjectIdentifier` |
| 1261 | |
| 1262 | .. attribute:: value |
| 1263 | |
| 1264 | :type: `bytes` |
| 1265 | |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1266 | X.509 Extensions |
| 1267 | ~~~~~~~~~~~~~~~~ |
| 1268 | |
Paul Kehrer | fbb7ac8 | 2015-03-16 19:26:29 -0500 | [diff] [blame] | 1269 | .. class:: Extensions |
| 1270 | |
| 1271 | .. versionadded:: 0.9 |
| 1272 | |
| 1273 | An X.509 Extensions instance is an ordered list of extensions. The object |
| 1274 | is iterable to get every extension. |
| 1275 | |
Paul Kehrer | fa56a23 | 2015-03-17 13:14:03 -0500 | [diff] [blame] | 1276 | .. method:: get_extension_for_oid(oid) |
| 1277 | |
| 1278 | :param oid: An :class:`ObjectIdentifier` instance. |
| 1279 | |
| 1280 | :returns: An instance of the extension class. |
| 1281 | |
| 1282 | :raises cryptography.x509.ExtensionNotFound: If the certificate does |
| 1283 | not have the extension requested. |
| 1284 | |
Paul Kehrer | fa56a23 | 2015-03-17 13:14:03 -0500 | [diff] [blame] | 1285 | .. doctest:: |
| 1286 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1287 | >>> from cryptography.x509.oid import ExtensionOID |
| 1288 | >>> cert.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS) |
Paul Kehrer | fa56a23 | 2015-03-17 13:14:03 -0500 | [diff] [blame] | 1289 | <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)> |
| 1290 | |
Phoebe Queen | 019b7f8 | 2015-08-12 03:52:03 +0100 | [diff] [blame] | 1291 | .. method:: get_extension_for_class(extclass) |
| 1292 | |
Phoebe Queen | 6a603eb | 2015-08-12 14:14:49 +0100 | [diff] [blame] | 1293 | .. versionadded:: 1.1 |
| 1294 | |
Phoebe Queen | 019b7f8 | 2015-08-12 03:52:03 +0100 | [diff] [blame] | 1295 | :param extclass: An extension class. |
| 1296 | |
| 1297 | :returns: An instance of the extension class. |
| 1298 | |
| 1299 | :raises cryptography.x509.ExtensionNotFound: If the certificate does |
| 1300 | not have the extension requested. |
| 1301 | |
| 1302 | .. doctest:: |
| 1303 | |
| 1304 | >>> from cryptography import x509 |
| 1305 | >>> cert.extensions.get_extension_for_class(x509.BasicConstraints) |
| 1306 | <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)> |
| 1307 | |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1308 | .. class:: Extension |
| 1309 | |
| 1310 | .. versionadded:: 0.9 |
| 1311 | |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame] | 1312 | .. attribute:: oid |
| 1313 | |
| 1314 | :type: :class:`ObjectIdentifier` |
| 1315 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1316 | One of the :class:`~cryptography.x509.oid.ExtensionOID` OIDs. |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1317 | |
| 1318 | .. attribute:: critical |
| 1319 | |
| 1320 | :type: bool |
| 1321 | |
Paul Kehrer | 58b7569 | 2015-03-22 23:24:58 -0500 | [diff] [blame] | 1322 | Determines whether a given extension is critical or not. :rfc:`5280` |
| 1323 | requires that "A certificate-using system MUST reject the certificate |
| 1324 | if it encounters a critical extension it does not recognize or a |
| 1325 | critical extension that contains information that it cannot process". |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1326 | |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame] | 1327 | .. attribute:: value |
| 1328 | |
| 1329 | Returns an instance of the extension type corresponding to the OID. |
| 1330 | |
Paul Kehrer | 14f0bd0 | 2015-08-06 11:55:18 +0100 | [diff] [blame] | 1331 | .. class:: ExtensionType |
| 1332 | |
| 1333 | .. versionadded:: 1.0 |
| 1334 | |
| 1335 | This is the interface against which all the following extension types are |
| 1336 | registered. |
| 1337 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1338 | .. class:: KeyUsage(digital_signature, content_commitment, key_encipherment, data_encipherment, key_agreement, key_cert_sign, crl_sign, encipher_only, decipher_only) |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1339 | |
| 1340 | .. versionadded:: 0.9 |
| 1341 | |
| 1342 | The key usage extension defines the purpose of the key contained in the |
| 1343 | certificate. The usage restriction might be employed when a key that could |
Paul Kehrer | b33de93 | 2015-08-06 23:41:05 +0100 | [diff] [blame] | 1344 | be used for more than one operation is to be restricted. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1345 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1346 | .. attribute:: oid |
| 1347 | |
| 1348 | .. versionadded:: 1.0 |
| 1349 | |
| 1350 | :type: :class:`ObjectIdentifier` |
| 1351 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1352 | Returns :attr:`~cryptography.x509.oid.ExtensionOID.KEY_USAGE`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1353 | |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1354 | .. attribute:: digital_signature |
| 1355 | |
| 1356 | :type: bool |
| 1357 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1358 | This purpose is set to true when the subject public key is used for verifying |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1359 | digital signatures, other than signatures on certificates |
| 1360 | (``key_cert_sign``) and CRLs (``crl_sign``). |
| 1361 | |
| 1362 | .. attribute:: content_commitment |
| 1363 | |
| 1364 | :type: bool |
| 1365 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1366 | This purpose is set to true when the subject public key is used for verifying |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1367 | digital signatures, other than signatures on certificates |
| 1368 | (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a |
| 1369 | non-repudiation service that protects against the signing entity |
| 1370 | falsely denying some action. In the case of later conflict, a |
| 1371 | reliable third party may determine the authenticity of the signed |
| 1372 | data. This was called ``non_repudiation`` in older revisions of the |
| 1373 | X.509 specification. |
| 1374 | |
| 1375 | .. attribute:: key_encipherment |
| 1376 | |
| 1377 | :type: bool |
| 1378 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1379 | This purpose is set to true when the subject public key is used for |
| 1380 | enciphering private or secret keys. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1381 | |
| 1382 | .. attribute:: data_encipherment |
| 1383 | |
| 1384 | :type: bool |
| 1385 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1386 | This purpose is set to true when the subject public key is used for |
| 1387 | directly enciphering raw user data without the use of an intermediate |
| 1388 | symmetric cipher. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1389 | |
| 1390 | .. attribute:: key_agreement |
| 1391 | |
| 1392 | :type: bool |
| 1393 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1394 | This purpose is set to true when the subject public key is used for key |
| 1395 | agreement. For example, when a Diffie-Hellman key is to be used for |
| 1396 | key management, then this purpose is set to true. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1397 | |
| 1398 | .. attribute:: key_cert_sign |
| 1399 | |
| 1400 | :type: bool |
| 1401 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1402 | This purpose is set to true when the subject public key is used for |
| 1403 | verifying signatures on public key certificates. If this purpose is set |
| 1404 | to true then ``ca`` must be true in the :class:`BasicConstraints` |
| 1405 | extension. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1406 | |
| 1407 | .. attribute:: crl_sign |
| 1408 | |
| 1409 | :type: bool |
| 1410 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1411 | This purpose is set to true when the subject public key is used for |
| 1412 | verifying signatures on certificate revocation lists. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1413 | |
| 1414 | .. attribute:: encipher_only |
| 1415 | |
| 1416 | :type: bool |
| 1417 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1418 | When this purposes is set to true and the ``key_agreement`` purpose is |
| 1419 | also set, the subject public key may be used only for enciphering data |
| 1420 | while performing key agreement. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1421 | |
| 1422 | :raises ValueError: This is raised if accessed when ``key_agreement`` |
| 1423 | is false. |
| 1424 | |
| 1425 | .. attribute:: decipher_only |
| 1426 | |
| 1427 | :type: bool |
| 1428 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1429 | When this purposes is set to true and the ``key_agreement`` purpose is |
| 1430 | also set, the subject public key may be used only for deciphering data |
| 1431 | while performing key agreement. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1432 | |
| 1433 | :raises ValueError: This is raised if accessed when ``key_agreement`` |
| 1434 | is false. |
| 1435 | |
| 1436 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1437 | .. class:: BasicConstraints(ca, path_length) |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1438 | |
| 1439 | .. versionadded:: 0.9 |
| 1440 | |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame] | 1441 | Basic constraints is an X.509 extension type that defines whether a given |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1442 | certificate is allowed to sign additional certificates and what path |
Paul Kehrer | b33de93 | 2015-08-06 23:41:05 +0100 | [diff] [blame] | 1443 | length restrictions may exist. |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1444 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1445 | .. attribute:: oid |
| 1446 | |
| 1447 | .. versionadded:: 1.0 |
| 1448 | |
| 1449 | :type: :class:`ObjectIdentifier` |
| 1450 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1451 | Returns :attr:`~cryptography.x509.oid.ExtensionOID.BASIC_CONSTRAINTS`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1452 | |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1453 | .. attribute:: ca |
| 1454 | |
| 1455 | :type: bool |
| 1456 | |
| 1457 | Whether the certificate can sign certificates. |
| 1458 | |
| 1459 | .. attribute:: path_length |
| 1460 | |
Paul Kehrer | fd1444c | 2015-03-21 19:47:05 -0500 | [diff] [blame] | 1461 | :type: int or None |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1462 | |
| 1463 | The maximum path length for certificates subordinate to this |
| 1464 | certificate. This attribute only has meaning if ``ca`` is true. |
| 1465 | If ``ca`` is true then a path length of None means there's no |
| 1466 | restriction on the number of subordinate CAs in the certificate chain. |
Alex Gaynor | 99c5f15 | 2015-05-03 10:01:04 -0400 | [diff] [blame] | 1467 | If it is zero or greater then it defines the maximum length for a |
| 1468 | subordinate CA's certificate chain. For example, a ``path_length`` of 1 |
| 1469 | means the certificate can sign a subordinate CA, but the subordinate CA |
| 1470 | is not allowed to create subordinates with ``ca`` set to true. |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1471 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1472 | .. class:: ExtendedKeyUsage(usages) |
Paul Kehrer | ffa2a15 | 2015-03-31 08:18:25 -0500 | [diff] [blame] | 1473 | |
| 1474 | .. versionadded:: 0.9 |
| 1475 | |
| 1476 | This extension indicates one or more purposes for which the certified |
| 1477 | public key may be used, in addition to or in place of the basic |
| 1478 | purposes indicated in the key usage extension. The object is |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1479 | iterable to obtain the list of |
| 1480 | :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs present. |
Paul Kehrer | ffa2a15 | 2015-03-31 08:18:25 -0500 | [diff] [blame] | 1481 | |
Paul Kehrer | 1cb9e55 | 2015-10-28 09:37:29 +0900 | [diff] [blame] | 1482 | :param list usages: A list of |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1483 | :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs. |
| 1484 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1485 | .. attribute:: oid |
| 1486 | |
| 1487 | .. versionadded:: 1.0 |
| 1488 | |
| 1489 | :type: :class:`ObjectIdentifier` |
| 1490 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1491 | Returns :attr:`~cryptography.x509.oid.ExtensionOID.EXTENDED_KEY_USAGE`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1492 | |
| 1493 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1494 | .. class:: OCSPNoCheck() |
Paul Kehrer | 4a1038e | 2015-05-18 10:28:31 -0700 | [diff] [blame] | 1495 | |
Paul Kehrer | 506a215 | 2015-05-26 08:01:18 -0500 | [diff] [blame] | 1496 | .. versionadded:: 1.0 |
Paul Kehrer | 4a1038e | 2015-05-18 10:28:31 -0700 | [diff] [blame] | 1497 | |
| 1498 | This presence of this extension indicates that an OCSP client can trust a |
| 1499 | responder for the lifetime of the responder's certificate. CAs issuing |
| 1500 | such a certificate should realize that a compromise of the responder's key |
| 1501 | is as serious as the compromise of a CA key used to sign CRLs, at least for |
| 1502 | the validity period of this certificate. CA's may choose to issue this type |
| 1503 | of certificate with a very short lifetime and renew it frequently. This |
| 1504 | extension is only relevant when the certificate is an authorized OCSP |
| 1505 | responder. |
| 1506 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1507 | .. attribute:: oid |
| 1508 | |
| 1509 | .. versionadded:: 1.0 |
| 1510 | |
| 1511 | :type: :class:`ObjectIdentifier` |
| 1512 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1513 | Returns :attr:`~cryptography.x509.oid.ExtensionOID.OCSP_NO_CHECK`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1514 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1515 | .. class:: NameConstraints(permitted_subtrees, excluded_subtrees) |
Paul Kehrer | e0017be | 2015-05-17 20:39:40 -0600 | [diff] [blame] | 1516 | |
| 1517 | .. versionadded:: 1.0 |
| 1518 | |
| 1519 | The name constraints extension, which only has meaning in a CA certificate, |
| 1520 | defines a name space within which all subject names in certificates issued |
| 1521 | beneath the CA certificate must (or must not) be in. For specific details |
| 1522 | on the way this extension should be processed see :rfc:`5280`. |
| 1523 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1524 | .. attribute:: oid |
| 1525 | |
| 1526 | .. versionadded:: 1.0 |
| 1527 | |
| 1528 | :type: :class:`ObjectIdentifier` |
| 1529 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1530 | Returns :attr:`~cryptography.x509.oid.ExtensionOID.NAME_CONSTRAINTS`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1531 | |
Paul Kehrer | e0017be | 2015-05-17 20:39:40 -0600 | [diff] [blame] | 1532 | .. attribute:: permitted_subtrees |
| 1533 | |
| 1534 | :type: list of :class:`GeneralName` objects or None |
| 1535 | |
| 1536 | The set of permitted name patterns. If a name matches this and an |
| 1537 | element in ``excluded_subtrees`` it is invalid. At least one of |
| 1538 | ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None. |
| 1539 | |
| 1540 | .. attribute:: excluded_subtrees |
| 1541 | |
| 1542 | :type: list of :class:`GeneralName` objects or None |
| 1543 | |
| 1544 | Any name matching a restriction in the ``excluded_subtrees`` field is |
| 1545 | invalid regardless of information appearing in the |
| 1546 | ``permitted_subtrees``. At least one of ``permitted_subtrees`` and |
| 1547 | ``excluded_subtrees`` will be non-None. |
| 1548 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1549 | .. class:: AuthorityKeyIdentifier(key_identifier, authority_cert_issuer, authority_cert_serial_number) |
Paul Kehrer | 2eb4ed9 | 2015-04-11 15:33:45 -0400 | [diff] [blame] | 1550 | |
| 1551 | .. versionadded:: 0.9 |
| 1552 | |
| 1553 | The authority key identifier extension provides a means of identifying the |
| 1554 | public key corresponding to the private key used to sign a certificate. |
Paul Kehrer | 8c8cd72 | 2015-04-19 09:15:04 -0500 | [diff] [blame] | 1555 | This extension is typically used to assist in determining the appropriate |
| 1556 | certificate chain. For more information about generation and use of this |
| 1557 | extension see `RFC 5280 section 4.2.1.1`_. |
Paul Kehrer | 2eb4ed9 | 2015-04-11 15:33:45 -0400 | [diff] [blame] | 1558 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1559 | .. attribute:: oid |
| 1560 | |
| 1561 | .. versionadded:: 1.0 |
| 1562 | |
| 1563 | :type: :class:`ObjectIdentifier` |
| 1564 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1565 | Returns |
| 1566 | :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_KEY_IDENTIFIER`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1567 | |
Paul Kehrer | 2eb4ed9 | 2015-04-11 15:33:45 -0400 | [diff] [blame] | 1568 | .. attribute:: key_identifier |
| 1569 | |
| 1570 | :type: bytes |
| 1571 | |
Paul Kehrer | 9104b1d | 2015-04-18 09:23:44 -0500 | [diff] [blame] | 1572 | A value derived from the public key used to verify the certificate's |
Paul Kehrer | 8c8cd72 | 2015-04-19 09:15:04 -0500 | [diff] [blame] | 1573 | signature. |
Paul Kehrer | 9104b1d | 2015-04-18 09:23:44 -0500 | [diff] [blame] | 1574 | |
Paul Kehrer | 2eb4ed9 | 2015-04-11 15:33:45 -0400 | [diff] [blame] | 1575 | .. attribute:: authority_cert_issuer |
| 1576 | |
| 1577 | :type: :class:`Name` or None |
| 1578 | |
Paul Kehrer | 9104b1d | 2015-04-18 09:23:44 -0500 | [diff] [blame] | 1579 | The :class:`Name` of the issuer's issuer. |
| 1580 | |
Paul Kehrer | 2eb4ed9 | 2015-04-11 15:33:45 -0400 | [diff] [blame] | 1581 | .. attribute:: authority_cert_serial_number |
| 1582 | |
| 1583 | :type: int or None |
| 1584 | |
Paul Kehrer | 9104b1d | 2015-04-18 09:23:44 -0500 | [diff] [blame] | 1585 | The serial number of the issuer's issuer. |
| 1586 | |
Paul Kehrer | 253929a | 2015-08-05 17:30:39 +0100 | [diff] [blame] | 1587 | .. classmethod:: from_issuer_public_key(public_key) |
| 1588 | |
| 1589 | .. versionadded:: 1.0 |
| 1590 | |
Paul Kehrer | 2d8e574 | 2016-03-12 09:27:55 -0400 | [diff] [blame] | 1591 | .. note:: |
| 1592 | |
| 1593 | This method should be used if the issuer certificate does not |
| 1594 | contain a :class:`~cryptography.x509.SubjectKeyIdentifier`. |
| 1595 | Otherwise, use |
| 1596 | :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier`. |
| 1597 | |
Paul Kehrer | 253929a | 2015-08-05 17:30:39 +0100 | [diff] [blame] | 1598 | Creates a new AuthorityKeyIdentifier instance using the public key |
| 1599 | provided to generate the appropriate digest. This should be the |
Paul Kehrer | 26ac47f | 2015-08-08 15:20:52 -0500 | [diff] [blame] | 1600 | **issuer's public key**. The resulting object will contain |
| 1601 | :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but |
| 1602 | :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer` |
| 1603 | and |
| 1604 | :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number` |
| 1605 | will be None. |
| 1606 | The generated ``key_identifier`` is the SHA1 hash of the ``subjectPublicKey`` |
| 1607 | ASN.1 bit string. This is the first recommendation in :rfc:`5280` |
Paul Kehrer | 253929a | 2015-08-05 17:30:39 +0100 | [diff] [blame] | 1608 | section 4.2.1.2. |
| 1609 | |
Paul Kehrer | cc67182 | 2015-08-08 15:41:54 -0500 | [diff] [blame] | 1610 | :param public_key: One of |
| 1611 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` |
| 1612 | , |
| 1613 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` |
| 1614 | , or |
| 1615 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`. |
Paul Kehrer | 253929a | 2015-08-05 17:30:39 +0100 | [diff] [blame] | 1616 | |
| 1617 | .. doctest:: |
| 1618 | |
| 1619 | >>> from cryptography import x509 |
| 1620 | >>> from cryptography.hazmat.backends import default_backend |
Paul Kehrer | cc67182 | 2015-08-08 15:41:54 -0500 | [diff] [blame] | 1621 | >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend()) |
| 1622 | >>> x509.AuthorityKeyIdentifier.from_issuer_public_key(issuer_cert.public_key()) |
Paul Kehrer | 253929a | 2015-08-05 17:30:39 +0100 | [diff] [blame] | 1623 | <AuthorityKeyIdentifier(key_identifier='X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9', authority_cert_issuer=None, authority_cert_serial_number=None)> |
| 1624 | |
Paul Kehrer | 61ff356 | 2016-03-11 22:51:27 -0400 | [diff] [blame] | 1625 | .. classmethod:: from_issuer_subject_key_identifier(ski) |
| 1626 | |
| 1627 | .. versionadded:: 1.3 |
| 1628 | |
Paul Kehrer | 2d8e574 | 2016-03-12 09:27:55 -0400 | [diff] [blame] | 1629 | .. note:: |
| 1630 | This method should be used if the issuer certificate contains a |
| 1631 | :class:`~cryptography.x509.SubjectKeyIdentifier`. Otherwise, use |
| 1632 | :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_public_key`. |
| 1633 | |
Paul Kehrer | 61ff356 | 2016-03-11 22:51:27 -0400 | [diff] [blame] | 1634 | Creates a new AuthorityKeyIdentifier instance using the |
| 1635 | SubjectKeyIdentifier from the issuer certificate. The resulting object |
| 1636 | will contain |
| 1637 | :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but |
| 1638 | :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer` |
| 1639 | and |
| 1640 | :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number` |
| 1641 | will be None. |
| 1642 | |
| 1643 | :param ski: The |
| 1644 | :class:`~cryptography.x509.SubjectKeyIdentifier` from the issuer |
| 1645 | certificate. |
| 1646 | |
| 1647 | .. doctest:: |
| 1648 | |
| 1649 | >>> from cryptography import x509 |
| 1650 | >>> from cryptography.hazmat.backends import default_backend |
| 1651 | >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend()) |
| 1652 | >>> ski = issuer_cert.extensions.get_extension_for_class(x509.SubjectKeyIdentifier) |
| 1653 | >>> x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier(ski) |
| 1654 | <AuthorityKeyIdentifier(key_identifier='X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9', authority_cert_issuer=None, authority_cert_serial_number=None)> |
| 1655 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1656 | .. class:: SubjectKeyIdentifier(digest) |
Paul Kehrer | 1eb82a6 | 2015-03-31 20:00:33 -0500 | [diff] [blame] | 1657 | |
| 1658 | .. versionadded:: 0.9 |
| 1659 | |
| 1660 | The subject key identifier extension provides a means of identifying |
| 1661 | certificates that contain a particular public key. |
| 1662 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1663 | .. attribute:: oid |
| 1664 | |
| 1665 | .. versionadded:: 1.0 |
| 1666 | |
| 1667 | :type: :class:`ObjectIdentifier` |
| 1668 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1669 | Returns |
| 1670 | :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1671 | |
Paul Kehrer | 1eb82a6 | 2015-03-31 20:00:33 -0500 | [diff] [blame] | 1672 | .. attribute:: digest |
| 1673 | |
| 1674 | :type: bytes |
| 1675 | |
| 1676 | The binary value of the identifier. |
| 1677 | |
Paul Kehrer | d4a7f06 | 2015-08-05 18:32:18 +0100 | [diff] [blame] | 1678 | .. classmethod:: from_public_key(public_key) |
Paul Kehrer | f22f612 | 2015-08-05 12:57:13 +0100 | [diff] [blame] | 1679 | |
| 1680 | .. versionadded:: 1.0 |
| 1681 | |
| 1682 | Creates a new SubjectKeyIdentifier instance using the public key |
| 1683 | provided to generate the appropriate digest. This should be the public |
Paul Kehrer | eb9ec00 | 2015-08-08 10:03:02 -0500 | [diff] [blame] | 1684 | key that is in the certificate. The generated digest is the SHA1 hash |
| 1685 | of the ``subjectPublicKey`` ASN.1 bit string. This is the first |
| 1686 | recommendation in :rfc:`5280` section 4.2.1.2. |
Paul Kehrer | f22f612 | 2015-08-05 12:57:13 +0100 | [diff] [blame] | 1687 | |
| 1688 | :param public_key: One of |
| 1689 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` |
| 1690 | , |
| 1691 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` |
| 1692 | , or |
| 1693 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`. |
| 1694 | |
Paul Kehrer | 253929a | 2015-08-05 17:30:39 +0100 | [diff] [blame] | 1695 | .. doctest:: |
| 1696 | |
| 1697 | >>> from cryptography import x509 |
| 1698 | >>> from cryptography.hazmat.backends import default_backend |
Paul Kehrer | cc67182 | 2015-08-08 15:41:54 -0500 | [diff] [blame] | 1699 | >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend()) |
| 1700 | >>> x509.SubjectKeyIdentifier.from_public_key(csr.public_key()) |
| 1701 | <SubjectKeyIdentifier(digest='\xdb\xaa\xf0\x06\x11\xdbD\xfe\xbf\x93\x03\x8av\x88WP7\xa6\x91\xf7')> |
Paul Kehrer | 253929a | 2015-08-05 17:30:39 +0100 | [diff] [blame] | 1702 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1703 | .. class:: SubjectAlternativeName(general_names) |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1704 | |
| 1705 | .. versionadded:: 0.9 |
| 1706 | |
| 1707 | Subject alternative name is an X.509 extension that provides a list of |
| 1708 | :ref:`general name <general_name_classes>` instances that provide a set |
| 1709 | of identities for which the certificate is valid. The object is iterable to |
| 1710 | get every element. |
| 1711 | |
Paul Kehrer | 1cb9e55 | 2015-10-28 09:37:29 +0900 | [diff] [blame] | 1712 | :param list general_names: A list of :class:`GeneralName` instances. |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1713 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1714 | .. attribute:: oid |
| 1715 | |
| 1716 | .. versionadded:: 1.0 |
| 1717 | |
| 1718 | :type: :class:`ObjectIdentifier` |
| 1719 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1720 | Returns |
| 1721 | :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_ALTERNATIVE_NAME`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1722 | |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1723 | .. method:: get_values_for_type(type) |
| 1724 | |
Gabriel Orisaka | 617fe4b | 2016-07-31 10:49:59 -0300 | [diff] [blame] | 1725 | :param type: A :class:`GeneralName` instance. This is one of the |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1726 | :ref:`general name classes <general_name_classes>`. |
| 1727 | |
| 1728 | :returns: A list of values extracted from the matched general names. |
Joshua Tauberer | d2afad3 | 2015-07-06 22:37:53 +0000 | [diff] [blame] | 1729 | The type of the returned values depends on the :class:`GeneralName`. |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1730 | |
Paul Kehrer | 93ae805 | 2015-05-02 23:18:09 -0500 | [diff] [blame] | 1731 | .. doctest:: |
| 1732 | |
| 1733 | >>> from cryptography import x509 |
| 1734 | >>> from cryptography.hazmat.backends import default_backend |
| 1735 | >>> from cryptography.hazmat.primitives import hashes |
| 1736 | >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend()) |
Paul Kehrer | d0cd507 | 2015-05-02 23:27:00 -0500 | [diff] [blame] | 1737 | >>> # Get the subjectAltName extension from the certificate |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1738 | >>> ext = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME) |
Paul Kehrer | d0cd507 | 2015-05-02 23:27:00 -0500 | [diff] [blame] | 1739 | >>> # Get the dNSName entries from the SAN extension |
| 1740 | >>> ext.value.get_values_for_type(x509.DNSName) |
Paul Kehrer | 93ae805 | 2015-05-02 23:18:09 -0500 | [diff] [blame] | 1741 | [u'www.cryptography.io', u'cryptography.io'] |
| 1742 | |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1743 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1744 | .. class:: IssuerAlternativeName(general_names) |
Paul Kehrer | 99125c9 | 2015-06-07 18:37:10 -0500 | [diff] [blame] | 1745 | |
| 1746 | .. versionadded:: 1.0 |
| 1747 | |
| 1748 | Issuer alternative name is an X.509 extension that provides a list of |
| 1749 | :ref:`general name <general_name_classes>` instances that provide a set |
| 1750 | of identities for the certificate issuer. The object is iterable to |
| 1751 | get every element. |
| 1752 | |
Paul Kehrer | 1cb9e55 | 2015-10-28 09:37:29 +0900 | [diff] [blame] | 1753 | :param list general_names: A list of :class:`GeneralName` instances. |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1754 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1755 | .. attribute:: oid |
| 1756 | |
| 1757 | .. versionadded:: 1.0 |
| 1758 | |
| 1759 | :type: :class:`ObjectIdentifier` |
| 1760 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1761 | Returns |
| 1762 | :attr:`~cryptography.x509.oid.ExtensionOID.ISSUER_ALTERNATIVE_NAME`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1763 | |
Paul Kehrer | 99125c9 | 2015-06-07 18:37:10 -0500 | [diff] [blame] | 1764 | .. method:: get_values_for_type(type) |
| 1765 | |
Gabriel Orisaka | 617fe4b | 2016-07-31 10:49:59 -0300 | [diff] [blame] | 1766 | :param type: A :class:`GeneralName` instance. This is one of the |
Paul Kehrer | 99125c9 | 2015-06-07 18:37:10 -0500 | [diff] [blame] | 1767 | :ref:`general name classes <general_name_classes>`. |
| 1768 | |
| 1769 | :returns: A list of values extracted from the matched general names. |
| 1770 | |
| 1771 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1772 | .. class:: AuthorityInformationAccess(descriptions) |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 1773 | |
| 1774 | .. versionadded:: 0.9 |
| 1775 | |
| 1776 | The authority information access extension indicates how to access |
| 1777 | information and services for the issuer of the certificate in which |
| 1778 | the extension appears. Information and services may include online |
| 1779 | validation services (such as OCSP) and issuer data. It is an iterable, |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1780 | containing one or more :class:`~cryptography.x509.AccessDescription` |
| 1781 | instances. |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 1782 | |
Paul Kehrer | 1cb9e55 | 2015-10-28 09:37:29 +0900 | [diff] [blame] | 1783 | :param list descriptions: A list of :class:`AccessDescription` objects. |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1784 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1785 | .. attribute:: oid |
| 1786 | |
| 1787 | .. versionadded:: 1.0 |
| 1788 | |
| 1789 | :type: :class:`ObjectIdentifier` |
| 1790 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1791 | Returns |
| 1792 | :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_INFORMATION_ACCESS`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1793 | |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 1794 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1795 | .. class:: AccessDescription(access_method, access_location) |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 1796 | |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 1797 | .. versionadded:: 0.9 |
| 1798 | |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 1799 | .. attribute:: access_method |
| 1800 | |
| 1801 | :type: :class:`ObjectIdentifier` |
| 1802 | |
Paul Kehrer | f506bca | 2015-05-02 22:31:47 -0500 | [diff] [blame] | 1803 | The access method defines what the ``access_location`` means. It must |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1804 | be either |
| 1805 | :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP` or |
| 1806 | :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`. |
| 1807 | If it is |
| 1808 | :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP` |
| 1809 | the access location will be where to obtain OCSP |
| 1810 | information for the certificate. If it is |
| 1811 | :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS` |
| 1812 | the access location will provide additional information about the |
| 1813 | issuing certificate. |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 1814 | |
| 1815 | .. attribute:: access_location |
| 1816 | |
| 1817 | :type: :class:`GeneralName` |
| 1818 | |
Paul Kehrer | f506bca | 2015-05-02 22:31:47 -0500 | [diff] [blame] | 1819 | Where to access the information defined by the access method. |
| 1820 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1821 | .. class:: CRLDistributionPoints(distribution_points) |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 1822 | |
| 1823 | .. versionadded:: 0.9 |
| 1824 | |
| 1825 | The CRL distribution points extension identifies how CRL information is |
| 1826 | obtained. It is an iterable, containing one or more |
| 1827 | :class:`DistributionPoint` instances. |
| 1828 | |
Paul Kehrer | 1cb9e55 | 2015-10-28 09:37:29 +0900 | [diff] [blame] | 1829 | :param list distribution_points: A list of :class:`DistributionPoint` |
| 1830 | instances. |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1831 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1832 | .. attribute:: oid |
| 1833 | |
| 1834 | .. versionadded:: 1.0 |
| 1835 | |
| 1836 | :type: :class:`ObjectIdentifier` |
| 1837 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1838 | Returns |
| 1839 | :attr:`~cryptography.x509.oid.ExtensionOID.CRL_DISTRIBUTION_POINTS`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1840 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1841 | .. class:: DistributionPoint(full_name, relative_name, reasons, crl_issuer) |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 1842 | |
| 1843 | .. versionadded:: 0.9 |
| 1844 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 1845 | .. attribute:: full_name |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 1846 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 1847 | :type: list of :class:`GeneralName` instances or None |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 1848 | |
Paul Kehrer | f2c072b | 2015-05-09 17:04:28 -0500 | [diff] [blame] | 1849 | This field describes methods to retrieve the CRL. At most one of |
| 1850 | ``full_name`` or ``relative_name`` will be non-None. |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 1851 | |
| 1852 | .. attribute:: relative_name |
| 1853 | |
| 1854 | :type: :class:`Name` or None |
| 1855 | |
| 1856 | This field describes methods to retrieve the CRL relative to the CRL |
Paul Kehrer | f2c072b | 2015-05-09 17:04:28 -0500 | [diff] [blame] | 1857 | issuer. At most one of ``full_name`` or ``relative_name`` will be |
| 1858 | non-None. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 1859 | |
| 1860 | .. attribute:: crl_issuer |
| 1861 | |
| 1862 | :type: list of :class:`GeneralName` instances or None |
| 1863 | |
| 1864 | Information about the issuer of the CRL. |
| 1865 | |
| 1866 | .. attribute:: reasons |
| 1867 | |
Paul Kehrer | 3fd0260 | 2015-05-09 19:46:13 -0500 | [diff] [blame] | 1868 | :type: frozenset of :class:`ReasonFlags` or None |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 1869 | |
| 1870 | The reasons a given distribution point may be used for when performing |
| 1871 | revocation checks. |
| 1872 | |
| 1873 | .. class:: ReasonFlags |
| 1874 | |
| 1875 | .. versionadded:: 0.9 |
| 1876 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 1877 | An enumeration for CRL reasons. |
| 1878 | |
| 1879 | .. attribute:: unspecified |
| 1880 | |
| 1881 | It is unspecified why the certificate was revoked. This reason cannot |
| 1882 | be used as a reason flag in a :class:`DistributionPoint`. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 1883 | |
| 1884 | .. attribute:: key_compromise |
| 1885 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 1886 | This reason indicates that the private key was compromised. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 1887 | |
| 1888 | .. attribute:: ca_compromise |
| 1889 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 1890 | This reason indicates that the CA issuing the certificate was |
| 1891 | compromised. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 1892 | |
| 1893 | .. attribute:: affiliation_changed |
| 1894 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 1895 | This reason indicates that the subject's name or other information has |
| 1896 | changed. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 1897 | |
| 1898 | .. attribute:: superseded |
| 1899 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 1900 | This reason indicates that a certificate has been superseded. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 1901 | |
| 1902 | .. attribute:: cessation_of_operation |
| 1903 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 1904 | This reason indicates that the certificate is no longer required. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 1905 | |
| 1906 | .. attribute:: certificate_hold |
| 1907 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 1908 | This reason indicates that the certificate is on hold. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 1909 | |
| 1910 | .. attribute:: privilege_withdrawn |
| 1911 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 1912 | This reason indicates that the privilege granted by this certificate |
| 1913 | have been withdrawn. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 1914 | |
| 1915 | .. attribute:: aa_compromise |
| 1916 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 1917 | When an attribute authority has been compromised. |
| 1918 | |
| 1919 | .. attribute:: remove_from_crl |
| 1920 | |
| 1921 | This reason indicates that the certificate was on hold and should be |
| 1922 | removed from the CRL. This reason cannot be used as a reason flag |
| 1923 | in a :class:`DistributionPoint`. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 1924 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1925 | .. class:: InhibitAnyPolicy(skip_certs) |
Paul Kehrer | 16fae76 | 2015-05-01 23:14:20 -0500 | [diff] [blame] | 1926 | |
| 1927 | .. versionadded:: 1.0 |
| 1928 | |
| 1929 | The inhibit ``anyPolicy`` extension indicates that the special OID |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1930 | :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY`, is not |
| 1931 | considered an explicit match for other :class:`CertificatePolicies` except |
| 1932 | when it appears in an intermediate self-issued CA certificate. The value |
| 1933 | indicates the number of additional non-self-issued certificates that may |
| 1934 | appear in the path before |
| 1935 | :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` is no |
| 1936 | longer permitted. For example, a value of one indicates that |
| 1937 | :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` may be |
| 1938 | processed in certificates issued by the subject of this certificate, but |
| 1939 | not in additional certificates in the path. |
Paul Kehrer | 16fae76 | 2015-05-01 23:14:20 -0500 | [diff] [blame] | 1940 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1941 | .. attribute:: oid |
| 1942 | |
| 1943 | .. versionadded:: 1.0 |
| 1944 | |
| 1945 | :type: :class:`ObjectIdentifier` |
| 1946 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1947 | Returns |
| 1948 | :attr:`~cryptography.x509.oid.ExtensionOID.INHIBIT_ANY_POLICY`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1949 | |
Paul Kehrer | 16fae76 | 2015-05-01 23:14:20 -0500 | [diff] [blame] | 1950 | .. attribute:: skip_certs |
| 1951 | |
| 1952 | :type: int |
| 1953 | |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 1954 | .. class:: PolicyConstraints |
| 1955 | |
| 1956 | .. versionadded:: 1.3 |
| 1957 | |
Paul Kehrer | 648c0fb | 2016-02-26 16:10:36 -0600 | [diff] [blame] | 1958 | The policy constraints extension is used to inhibit policy mapping or |
| 1959 | require that each certificate in a chain contain an acceptable policy |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 1960 | identifier. For more information about the use of this extension see |
| 1961 | :rfc:`5280`. |
| 1962 | |
Paul Kehrer | 159b3b5 | 2016-02-26 08:27:22 -0600 | [diff] [blame] | 1963 | .. attribute:: oid |
| 1964 | |
| 1965 | :type: :class:`ObjectIdentifier` |
| 1966 | |
| 1967 | Returns :attr:`~cryptography.x509.oid.ExtensionOID.POLICY_CONSTRAINTS`. |
| 1968 | |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 1969 | .. attribute:: require_explicit_policy |
| 1970 | |
| 1971 | :type: int or None |
| 1972 | |
Paul Kehrer | 648c0fb | 2016-02-26 16:10:36 -0600 | [diff] [blame] | 1973 | If this field is not None, the value indicates the number of additional |
| 1974 | certificates that may appear in the chain before an explicit policy is |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 1975 | required for the entire path. When an explicit policy is required, it |
Paul Kehrer | 648c0fb | 2016-02-26 16:10:36 -0600 | [diff] [blame] | 1976 | is necessary for all certificates in the chain to contain an acceptable |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 1977 | policy identifier in the certificate policies extension. An |
| 1978 | acceptable policy identifier is the identifier of a policy required |
| 1979 | by the user of the certification path or the identifier of a policy |
| 1980 | that has been declared equivalent through policy mapping. |
| 1981 | |
| 1982 | .. attribute:: inhibit_policy_mapping |
| 1983 | |
| 1984 | :type: int or None |
| 1985 | |
Paul Kehrer | 648c0fb | 2016-02-26 16:10:36 -0600 | [diff] [blame] | 1986 | If this field is not None, the value indicates the number of additional |
| 1987 | certificates that may appear in the chain before policy mapping is no |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 1988 | longer permitted. For example, a value of one indicates that policy |
| 1989 | mapping may be processed in certificates issued by the subject of this |
Paul Kehrer | 648c0fb | 2016-02-26 16:10:36 -0600 | [diff] [blame] | 1990 | certificate, but not in additional certificates in the chain. |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 1991 | |
Paul Kehrer | 3b95cd7 | 2015-12-22 21:40:20 -0600 | [diff] [blame] | 1992 | .. class:: CRLNumber(crl_number) |
| 1993 | |
| 1994 | .. versionadded:: 1.2 |
| 1995 | |
Paul Kehrer | e32b994 | 2015-12-22 22:26:53 -0600 | [diff] [blame] | 1996 | The CRL number is a CRL extension that conveys a monotonically increasing |
| 1997 | sequence number for a given CRL scope and CRL issuer. This extension allows |
| 1998 | users to easily determine when a particular CRL supersedes another CRL. |
| 1999 | :rfc:`5280` requires that this extension be present in conforming CRLs. |
Paul Kehrer | 3b95cd7 | 2015-12-22 21:40:20 -0600 | [diff] [blame] | 2000 | |
| 2001 | .. attribute:: oid |
| 2002 | |
| 2003 | :type: :class:`ObjectIdentifier` |
| 2004 | |
| 2005 | Returns |
| 2006 | :attr:`~cryptography.x509.oid.ExtensionOID.CRL_NUMBER`. |
| 2007 | |
| 2008 | .. attribute:: crl_number |
| 2009 | |
| 2010 | :type: int |
| 2011 | |
Paul Kehrer | 14fd697 | 2015-12-30 10:58:25 -0600 | [diff] [blame] | 2012 | .. class:: UnrecognizedExtension |
| 2013 | |
| 2014 | .. versionadded:: 1.2 |
| 2015 | |
| 2016 | A generic extension class used to hold the raw value of **non-critical** |
| 2017 | extensions that ``cryptography`` does not know how to parse. Extensions |
Paul Kehrer | 1628b5c | 2015-12-30 14:59:44 -0600 | [diff] [blame] | 2018 | marked critical will raise |
Paul Kehrer | 14fd697 | 2015-12-30 10:58:25 -0600 | [diff] [blame] | 2019 | :class:`~cryptography.x509.UnsupportedExtension`. |
| 2020 | |
| 2021 | .. attribute:: oid |
| 2022 | |
| 2023 | :type: :class:`ObjectIdentifier` |
| 2024 | |
| 2025 | Returns the OID associated with this extension. |
| 2026 | |
| 2027 | .. attribute:: value |
| 2028 | |
| 2029 | :type: byte |
| 2030 | |
| 2031 | Returns the DER encoded bytes payload of the extension. |
| 2032 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2033 | .. class:: CertificatePolicies(policies) |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2034 | |
| 2035 | .. versionadded:: 0.9 |
| 2036 | |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2037 | The certificate policies extension is an iterable, containing one or more |
| 2038 | :class:`PolicyInformation` instances. |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2039 | |
Paul Kehrer | 1cb9e55 | 2015-10-28 09:37:29 +0900 | [diff] [blame] | 2040 | :param list policies: A list of :class:`PolicyInformation` instances. |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2041 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 2042 | .. attribute:: oid |
| 2043 | |
| 2044 | .. versionadded:: 1.0 |
| 2045 | |
| 2046 | :type: :class:`ObjectIdentifier` |
| 2047 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2048 | Returns |
| 2049 | :attr:`~cryptography.x509.oid.ExtensionOID.CERTIFICATE_POLICIES`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 2050 | |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2051 | Certificate Policies Classes |
| 2052 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2053 | |
| 2054 | These classes may be present within a :class:`CertificatePolicies` instance. |
| 2055 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2056 | .. class:: PolicyInformation(policy_identifier, policy_qualifiers) |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2057 | |
| 2058 | .. versionadded:: 0.9 |
| 2059 | |
| 2060 | Contains a policy identifier and an optional list of qualifiers. |
| 2061 | |
| 2062 | .. attribute:: policy_identifier |
| 2063 | |
| 2064 | :type: :class:`ObjectIdentifier` |
| 2065 | |
| 2066 | .. attribute:: policy_qualifiers |
| 2067 | |
| 2068 | :type: list |
| 2069 | |
Paul Kehrer | ba35b3b | 2015-05-10 13:07:59 -0500 | [diff] [blame] | 2070 | A list consisting of :term:`text` and/or :class:`UserNotice` objects. |
Paul Kehrer | 3f8ddeb | 2015-05-11 00:25:36 -0500 | [diff] [blame] | 2071 | If the value is text it is a pointer to the practice statement |
| 2072 | published by the certificate authority. If it is a user notice it is |
| 2073 | meant for display to the relying party when the certificate is |
| 2074 | used. |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2075 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2076 | .. class:: UserNotice(notice_reference, explicit_text) |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2077 | |
| 2078 | .. versionadded:: 0.9 |
| 2079 | |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2080 | User notices are intended for display to a relying party when a certificate |
| 2081 | is used. In practice, few if any UIs expose this data and it is a rarely |
| 2082 | encoded component. |
| 2083 | |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2084 | .. attribute:: notice_reference |
| 2085 | |
| 2086 | :type: :class:`NoticeReference` or None |
| 2087 | |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2088 | The notice reference field names an organization and identifies, |
| 2089 | by number, a particular statement prepared by that organization. |
| 2090 | |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2091 | .. attribute:: explicit_text |
| 2092 | |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2093 | This field includes an arbitrary textual statement directly in the |
| 2094 | certificate. |
| 2095 | |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2096 | :type: :term:`text` |
| 2097 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2098 | .. class:: NoticeReference(organization, notice_numbers) |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2099 | |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2100 | Notice reference can name an organization and provide information about |
| 2101 | notices related to the certificate. For example, it might identify the |
| 2102 | organization name and notice number 1. Application software could |
| 2103 | have a notice file containing the current set of notices for the named |
| 2104 | organization; the application would then extract the notice text from the |
| 2105 | file and display it. In practice this is rarely seen. |
| 2106 | |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2107 | .. versionadded:: 0.9 |
| 2108 | |
| 2109 | .. attribute:: organization |
| 2110 | |
Paul Kehrer | 66c6170 | 2015-05-12 16:39:18 -0500 | [diff] [blame] | 2111 | :type: :term:`text` |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2112 | |
Paul Kehrer | 3f8ddeb | 2015-05-11 00:25:36 -0500 | [diff] [blame] | 2113 | .. attribute:: notice_numbers |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2114 | |
Paul Kehrer | 66c6170 | 2015-05-12 16:39:18 -0500 | [diff] [blame] | 2115 | :type: list |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2116 | |
Paul Kehrer | 66c6170 | 2015-05-12 16:39:18 -0500 | [diff] [blame] | 2117 | A list of integers. |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2118 | |
Paul Kehrer | e5f152b | 2015-12-25 23:55:47 -0600 | [diff] [blame] | 2119 | .. _crl_entry_extensions: |
| 2120 | |
Paul Kehrer | 49bb756 | 2015-12-25 16:17:40 -0600 | [diff] [blame] | 2121 | CRL Entry Extensions |
| 2122 | ~~~~~~~~~~~~~~~~~~~~ |
| 2123 | |
| 2124 | These extensions are only valid within a :class:`RevokedCertificate` object. |
| 2125 | |
| 2126 | .. class:: CertificateIssuer(general_names) |
| 2127 | |
| 2128 | .. versionadded:: 1.2 |
| 2129 | |
| 2130 | The certificate issuer is an extension that is only valid inside |
| 2131 | :class:`~cryptography.x509.RevokedCertificate` objects. If the |
| 2132 | ``indirectCRL`` property of the parent CRL's IssuingDistributionPoint |
| 2133 | extension is set, then this extension identifies the certificate issuer |
| 2134 | associated with the revoked certificate. The object is iterable to get |
| 2135 | every element. |
| 2136 | |
| 2137 | :param list general_names: A list of :class:`GeneralName` instances. |
| 2138 | |
| 2139 | .. attribute:: oid |
| 2140 | |
| 2141 | :type: :class:`ObjectIdentifier` |
| 2142 | |
| 2143 | Returns |
| 2144 | :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CERTIFICATE_ISSUER`. |
| 2145 | |
| 2146 | .. method:: get_values_for_type(type) |
| 2147 | |
| 2148 | :param type: A :class:`GeneralName` instance. This is one of the |
| 2149 | :ref:`general name classes <general_name_classes>`. |
| 2150 | |
| 2151 | :returns: A list of values extracted from the matched general names. |
| 2152 | The type of the returned values depends on the :class:`GeneralName`. |
| 2153 | |
Paul Kehrer | 7058ece | 2015-12-25 22:28:29 -0600 | [diff] [blame] | 2154 | .. class:: CRLReason(reason) |
| 2155 | |
| 2156 | .. versionadded:: 1.2 |
| 2157 | |
| 2158 | CRL reason (also known as ``reasonCode``) is an extension that is only |
| 2159 | valid inside :class:`~cryptography.x509.RevokedCertificate` objects. It |
| 2160 | identifies a reason for the certificate revocation. |
| 2161 | |
| 2162 | :param reason: A value from the |
| 2163 | :class:`~cryptography.x509.oid.CRLEntryExtensionOID` enum. |
| 2164 | |
| 2165 | .. attribute:: oid |
| 2166 | |
| 2167 | :type: :class:`ObjectIdentifier` |
| 2168 | |
| 2169 | Returns |
| 2170 | :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CRL_REASON`. |
| 2171 | |
| 2172 | .. attribute:: reason |
| 2173 | |
| 2174 | :type: An element from :class:`~cryptography.x509.ReasonFlags` |
| 2175 | |
Paul Kehrer | 23c0bbc | 2015-12-25 22:35:19 -0600 | [diff] [blame] | 2176 | .. class:: InvalidityDate(invalidity_date) |
| 2177 | |
| 2178 | .. versionadded:: 1.2 |
| 2179 | |
| 2180 | Invalidity date is an extension that is only valid inside |
| 2181 | :class:`~cryptography.x509.RevokedCertificate` objects. It provides |
| 2182 | the date on which it is known or suspected that the private key was |
| 2183 | compromised or that the certificate otherwise became invalid. |
| 2184 | This date may be earlier than the revocation date in the CRL entry, |
| 2185 | which is the date at which the CA processed the revocation. |
| 2186 | |
| 2187 | :param invalidity_date: The :class:`datetime.datetime` when it is known |
| 2188 | or suspected that the private key was compromised. |
| 2189 | |
| 2190 | .. attribute:: oid |
| 2191 | |
| 2192 | :type: :class:`ObjectIdentifier` |
| 2193 | |
| 2194 | Returns |
| 2195 | :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.INVALIDITY_DATE`. |
| 2196 | |
| 2197 | .. attribute:: invalidity_date |
| 2198 | |
| 2199 | :type: :class:`datetime.datetime` |
| 2200 | |
Paul Kehrer | 49bb756 | 2015-12-25 16:17:40 -0600 | [diff] [blame] | 2201 | |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2202 | Object Identifiers |
| 2203 | ~~~~~~~~~~~~~~~~~~ |
| 2204 | |
Paul Kehrer | 4bb4649 | 2015-02-07 16:59:14 -0600 | [diff] [blame] | 2205 | X.509 elements are frequently identified by :class:`ObjectIdentifier` |
| 2206 | instances. The following common OIDs are available as constants. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2207 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2208 | .. currentmodule:: cryptography.x509.oid |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2209 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2210 | .. class:: NameOID |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2211 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2212 | These OIDs are typically seen in X.509 names. |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2213 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2214 | .. versionadded:: 1.0 |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2215 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2216 | .. attribute:: COMMON_NAME |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2217 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2218 | Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain |
| 2219 | name would be encoded here for server certificates. :rfc:`2818` |
| 2220 | deprecates this practice and names of that type should now be located |
| 2221 | in a :class:`~cryptography.x509.SubjectAlternativeName` extension. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2222 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2223 | .. attribute:: COUNTRY_NAME |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2224 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2225 | Corresponds to the dotted string ``"2.5.4.6"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2226 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2227 | .. attribute:: LOCALITY_NAME |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2228 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2229 | Corresponds to the dotted string ``"2.5.4.7"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2230 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2231 | .. attribute:: STATE_OR_PROVINCE_NAME |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2232 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2233 | Corresponds to the dotted string ``"2.5.4.8"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2234 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2235 | .. attribute:: ORGANIZATION_NAME |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2236 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2237 | Corresponds to the dotted string ``"2.5.4.10"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2238 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2239 | .. attribute:: ORGANIZATIONAL_UNIT_NAME |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2240 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2241 | Corresponds to the dotted string ``"2.5.4.11"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2242 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2243 | .. attribute:: SERIAL_NUMBER |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2244 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2245 | Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from |
| 2246 | the serial number of the certificate itself (which can be obtained with |
Chelsea Winfree | e295f3a | 2016-06-02 21:15:54 -0700 | [diff] [blame] | 2247 | :func:`~cryptography.x509.Certificate.serial_number`). |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2248 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2249 | .. attribute:: SURNAME |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2250 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2251 | Corresponds to the dotted string ``"2.5.4.4"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2252 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2253 | .. attribute:: GIVEN_NAME |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2254 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2255 | Corresponds to the dotted string ``"2.5.4.42"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2256 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2257 | .. attribute:: TITLE |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2258 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2259 | Corresponds to the dotted string ``"2.5.4.12"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2260 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2261 | .. attribute:: GENERATION_QUALIFIER |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2262 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2263 | Corresponds to the dotted string ``"2.5.4.44"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2264 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2265 | .. attribute:: DN_QUALIFIER |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2266 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2267 | Corresponds to the dotted string ``"2.5.4.46"``. This specifies |
| 2268 | disambiguating information to add to the relative distinguished name of an |
| 2269 | entry. See :rfc:`2256`. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2270 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2271 | .. attribute:: PSEUDONYM |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2272 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2273 | Corresponds to the dotted string ``"2.5.4.65"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2274 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2275 | .. attribute:: DOMAIN_COMPONENT |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2276 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2277 | Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string |
| 2278 | holding one component of a domain name. See :rfc:`4519`. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2279 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2280 | .. attribute:: EMAIL_ADDRESS |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2281 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2282 | Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2283 | |
Alex Gaynor | 1d3f2bf | 2015-12-19 12:15:09 -0500 | [diff] [blame] | 2284 | .. attribute:: JURISDICTION_COUNTRY_NAME |
| 2285 | |
| 2286 | Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.3"``. |
| 2287 | |
Alex Gaynor | 45e507f | 2015-12-19 13:44:23 -0500 | [diff] [blame] | 2288 | .. attribute:: JURISDICTION_LOCALITY_NAME |
| 2289 | |
| 2290 | Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.1"``. |
| 2291 | |
| 2292 | .. attribute:: JURISDICTION_STATE_OR_PROVINCE_NAME |
| 2293 | |
| 2294 | Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.2"``. |
| 2295 | |
Alex Gaynor | a2293c8 | 2015-12-19 20:49:15 -0500 | [diff] [blame] | 2296 | .. attribute:: BUSINESS_CATEGORY |
| 2297 | |
| 2298 | Corresponds to the dotted string ``"2.5.4.15"``. |
| 2299 | |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2300 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2301 | .. class:: SignatureAlgorithmOID |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2302 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2303 | .. versionadded:: 1.0 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2304 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2305 | .. attribute:: RSA_WITH_MD5 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2306 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2307 | Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is |
| 2308 | an MD5 digest signed by an RSA key. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2309 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2310 | .. attribute:: RSA_WITH_SHA1 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2311 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2312 | Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is |
| 2313 | a SHA1 digest signed by an RSA key. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2314 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2315 | .. attribute:: RSA_WITH_SHA224 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2316 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2317 | Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is |
| 2318 | a SHA224 digest signed by an RSA key. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2319 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2320 | .. attribute:: RSA_WITH_SHA256 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2321 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2322 | Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is |
| 2323 | a SHA256 digest signed by an RSA key. |
Alex Gaynor | 3aadabf | 2015-06-23 22:06:21 -0400 | [diff] [blame] | 2324 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2325 | .. attribute:: RSA_WITH_SHA384 |
Alex Gaynor | 3aadabf | 2015-06-23 22:06:21 -0400 | [diff] [blame] | 2326 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2327 | Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is |
| 2328 | a SHA384 digest signed by an RSA key. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2329 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2330 | .. attribute:: RSA_WITH_SHA512 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2331 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2332 | Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is |
| 2333 | a SHA512 digest signed by an RSA key. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2334 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2335 | .. attribute:: ECDSA_WITH_SHA1 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2336 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2337 | Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1 |
| 2338 | digest signed by an ECDSA key. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2339 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2340 | .. attribute:: ECDSA_WITH_SHA224 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2341 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2342 | Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is |
| 2343 | a SHA224 digest signed by an ECDSA key. |
| 2344 | |
| 2345 | .. attribute:: ECDSA_WITH_SHA256 |
| 2346 | |
| 2347 | Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is |
| 2348 | a SHA256 digest signed by an ECDSA key. |
| 2349 | |
| 2350 | .. attribute:: ECDSA_WITH_SHA384 |
| 2351 | |
| 2352 | Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is |
| 2353 | a SHA384 digest signed by an ECDSA key. |
| 2354 | |
| 2355 | .. attribute:: ECDSA_WITH_SHA512 |
| 2356 | |
| 2357 | Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is |
| 2358 | a SHA512 digest signed by an ECDSA key. |
| 2359 | |
| 2360 | .. attribute:: DSA_WITH_SHA1 |
| 2361 | |
| 2362 | Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is |
| 2363 | a SHA1 digest signed by a DSA key. |
| 2364 | |
| 2365 | .. attribute:: DSA_WITH_SHA224 |
| 2366 | |
| 2367 | Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is |
| 2368 | a SHA224 digest signed by a DSA key. |
| 2369 | |
| 2370 | .. attribute:: DSA_WITH_SHA256 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2371 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2372 | Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is |
| 2373 | a SHA256 digest signed by a DSA key. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2374 | |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2375 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2376 | .. class:: ExtendedKeyUsageOID |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2377 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2378 | .. versionadded:: 1.0 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2379 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2380 | .. attribute:: SERVER_AUTH |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2381 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2382 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used |
| 2383 | to denote that a certificate may be used for TLS web server |
| 2384 | authentication. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2385 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2386 | .. attribute:: CLIENT_AUTH |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2387 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2388 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used |
| 2389 | to denote that a certificate may be used for TLS web client |
| 2390 | authentication. |
Paul Kehrer | ffa2a15 | 2015-03-31 08:18:25 -0500 | [diff] [blame] | 2391 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2392 | .. attribute:: CODE_SIGNING |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2393 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2394 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used |
| 2395 | to denote that a certificate may be used for code signing. |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2396 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2397 | .. attribute:: EMAIL_PROTECTION |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2398 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2399 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used |
| 2400 | to denote that a certificate may be used for email protection. |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2401 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2402 | .. attribute:: TIME_STAMPING |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2403 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2404 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used |
| 2405 | to denote that a certificate may be used for time stamping. |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2406 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2407 | .. attribute:: OCSP_SIGNING |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2408 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2409 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used |
| 2410 | to denote that a certificate may be used for signing OCSP responses. |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2411 | |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2412 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2413 | .. class:: AuthorityInformationAccessOID |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2414 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2415 | .. versionadded:: 1.0 |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2416 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2417 | .. attribute:: OCSP |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2418 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2419 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the |
| 2420 | identifier for OCSP data in |
| 2421 | :class:`~cryptography.x509.AccessDescription` objects. |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2422 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2423 | .. attribute:: CA_ISSUERS |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 2424 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2425 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the |
| 2426 | identifier for CA issuer data in |
| 2427 | :class:`~cryptography.x509.AccessDescription` objects. |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 2428 | |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 2429 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2430 | .. class:: CertificatePoliciesOID |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 2431 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2432 | .. versionadded:: 1.0 |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 2433 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2434 | .. attribute:: CPS_QUALIFIER |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2435 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2436 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``. |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2437 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2438 | .. attribute:: CPS_USER_NOTICE |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2439 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2440 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``. |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2441 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2442 | .. attribute:: ANY_POLICY |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2443 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2444 | Corresponds to the dotted string ``"2.5.29.32.0"``. |
Paul Kehrer | 16fae76 | 2015-05-01 23:14:20 -0500 | [diff] [blame] | 2445 | |
Paul Kehrer | 16fae76 | 2015-05-01 23:14:20 -0500 | [diff] [blame] | 2446 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2447 | .. class:: ExtensionOID |
Paul Kehrer | 5553d57 | 2015-03-23 21:08:01 -0500 | [diff] [blame] | 2448 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2449 | .. versionadded:: 1.0 |
Paul Kehrer | 2bb9464 | 2015-03-21 09:54:17 -0500 | [diff] [blame] | 2450 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2451 | .. attribute:: BASIC_CONSTRAINTS |
Paul Kehrer | 2bb9464 | 2015-03-21 09:54:17 -0500 | [diff] [blame] | 2452 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2453 | Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the |
| 2454 | :class:`~cryptography.x509.BasicConstraints` extension type. |
Paul Kehrer | 2bb9464 | 2015-03-21 09:54:17 -0500 | [diff] [blame] | 2455 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2456 | .. attribute:: KEY_USAGE |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 2457 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2458 | Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the |
| 2459 | :class:`~cryptography.x509.KeyUsage` extension type. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 2460 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2461 | .. attribute:: SUBJECT_ALTERNATIVE_NAME |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 2462 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2463 | Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the |
| 2464 | :class:`~cryptography.x509.SubjectAlternativeName` extension type. |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 2465 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2466 | .. attribute:: ISSUER_ALTERNATIVE_NAME |
Paul Kehrer | 99125c9 | 2015-06-07 18:37:10 -0500 | [diff] [blame] | 2467 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2468 | Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the |
| 2469 | :class:`~cryptography.x509.IssuerAlternativeName` extension type. |
Paul Kehrer | 99125c9 | 2015-06-07 18:37:10 -0500 | [diff] [blame] | 2470 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2471 | .. attribute:: SUBJECT_KEY_IDENTIFIER |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 2472 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2473 | Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the |
| 2474 | :class:`~cryptography.x509.SubjectKeyIdentifier` extension type. |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 2475 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2476 | .. attribute:: NAME_CONSTRAINTS |
Paul Kehrer | e0017be | 2015-05-17 20:39:40 -0600 | [diff] [blame] | 2477 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2478 | Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the |
| 2479 | :class:`~cryptography.x509.NameConstraints` extension type. |
Paul Kehrer | e0017be | 2015-05-17 20:39:40 -0600 | [diff] [blame] | 2480 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2481 | .. attribute:: CRL_DISTRIBUTION_POINTS |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 2482 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2483 | Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the |
| 2484 | :class:`~cryptography.x509.CRLDistributionPoints` extension type. |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 2485 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2486 | .. attribute:: CERTIFICATE_POLICIES |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 2487 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2488 | Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the |
| 2489 | :class:`~cryptography.x509.CertificatePolicies` extension type. |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 2490 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2491 | .. attribute:: AUTHORITY_KEY_IDENTIFIER |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 2492 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2493 | Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the |
| 2494 | :class:`~cryptography.x509.AuthorityKeyIdentifier` extension type. |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 2495 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2496 | .. attribute:: EXTENDED_KEY_USAGE |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 2497 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2498 | Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the |
| 2499 | :class:`~cryptography.x509.ExtendedKeyUsage` extension type. |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 2500 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2501 | .. attribute:: AUTHORITY_INFORMATION_ACCESS |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 2502 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2503 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier |
| 2504 | for the :class:`~cryptography.x509.AuthorityInformationAccess` extension |
| 2505 | type. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2506 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2507 | .. attribute:: INHIBIT_ANY_POLICY |
Paul Kehrer | b33de93 | 2015-08-06 23:41:05 +0100 | [diff] [blame] | 2508 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2509 | Corresponds to the dotted string ``"2.5.29.54"``. The identifier |
| 2510 | for the :class:`~cryptography.x509.InhibitAnyPolicy` extension type. |
Paul Kehrer | b33de93 | 2015-08-06 23:41:05 +0100 | [diff] [blame] | 2511 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2512 | .. attribute:: OCSP_NO_CHECK |
Paul Kehrer | 4a1038e | 2015-05-18 10:28:31 -0700 | [diff] [blame] | 2513 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2514 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The |
| 2515 | identifier for the :class:`~cryptography.x509.OCSPNoCheck` extension |
| 2516 | type. |
Paul Kehrer | 4a1038e | 2015-05-18 10:28:31 -0700 | [diff] [blame] | 2517 | |
Paul Kehrer | 51f39cb | 2015-12-21 21:17:39 -0600 | [diff] [blame] | 2518 | .. attribute:: CRL_NUMBER |
| 2519 | |
| 2520 | Corresponds to the dotted string ``"2.5.29.20"``. The identifier for |
| 2521 | the ``CRLNumber`` extension type. This extension only has meaning |
| 2522 | for certificate revocation lists. |
| 2523 | |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 2524 | .. attribute:: POLICY_CONSTRAINTS |
| 2525 | |
| 2526 | Corresponds to the dotted string ``"2.5.29.36"``. The identifier for the |
Paul Kehrer | 20f0df5 | 2016-02-26 08:37:13 -0600 | [diff] [blame] | 2527 | :class:`~cryptography.x509.PolicyConstraints` extension type. |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 2528 | |
| 2529 | |
Paul Kehrer | c6242dc | 2015-12-25 16:36:46 -0600 | [diff] [blame] | 2530 | .. class:: CRLEntryExtensionOID |
| 2531 | |
| 2532 | .. versionadded:: 1.2 |
| 2533 | |
| 2534 | .. attribute:: CERTIFICATE_ISSUER |
| 2535 | |
| 2536 | Corresponds to the dotted string ``"2.5.29.29"``. |
| 2537 | |
| 2538 | .. attribute:: CRL_REASON |
| 2539 | |
| 2540 | Corresponds to the dotted string ``"2.5.29.21"``. |
| 2541 | |
| 2542 | .. attribute:: INVALIDITY_DATE |
| 2543 | |
| 2544 | Corresponds to the dotted string ``"2.5.29.24"``. |
| 2545 | |
Paul Kehrer | 8b89bcc | 2016-09-03 11:31:43 -0500 | [diff] [blame] | 2546 | Helper Functions |
| 2547 | ~~~~~~~~~~~~~~~~ |
| 2548 | .. currentmodule:: cryptography.x509 |
| 2549 | |
| 2550 | .. function:: random_serial_number() |
| 2551 | |
| 2552 | .. versionadded:: 1.6 |
| 2553 | |
| 2554 | Generates a random serial number suitable for use when constructing |
| 2555 | certificates. |
| 2556 | |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2557 | Exceptions |
| 2558 | ~~~~~~~~~~ |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2559 | .. currentmodule:: cryptography.x509 |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2560 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 2561 | .. class:: InvalidVersion |
Paul Kehrer | a68fd33 | 2014-11-27 07:08:40 -1000 | [diff] [blame] | 2562 | |
| 2563 | This is raised when an X.509 certificate has an invalid version number. |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 2564 | |
Paul Kehrer | d5cccf7 | 2014-12-15 17:20:33 -0600 | [diff] [blame] | 2565 | .. attribute:: parsed_version |
| 2566 | |
Paul Kehrer | bbffc40 | 2014-12-17 13:33:55 -0600 | [diff] [blame] | 2567 | :type: int |
| 2568 | |
| 2569 | Returns the raw version that was parsed from the certificate. |
Paul Kehrer | d5cccf7 | 2014-12-15 17:20:33 -0600 | [diff] [blame] | 2570 | |
Paul Kehrer | fbb7ac8 | 2015-03-16 19:26:29 -0500 | [diff] [blame] | 2571 | .. class:: DuplicateExtension |
| 2572 | |
| 2573 | This is raised when more than one X.509 extension of the same type is |
| 2574 | found within a certificate. |
| 2575 | |
| 2576 | .. attribute:: oid |
| 2577 | |
| 2578 | :type: :class:`ObjectIdentifier` |
| 2579 | |
| 2580 | Returns the OID. |
| 2581 | |
| 2582 | .. class:: UnsupportedExtension |
| 2583 | |
Paul Kehrer | 58ddc11 | 2015-12-30 20:19:00 -0600 | [diff] [blame] | 2584 | This is raised when a certificate contains an unsupported extension type |
Paul Kehrer | f5bc3eb | 2015-12-30 20:54:15 -0600 | [diff] [blame] | 2585 | that is marked ``critical``. |
Paul Kehrer | fbb7ac8 | 2015-03-16 19:26:29 -0500 | [diff] [blame] | 2586 | |
| 2587 | .. attribute:: oid |
| 2588 | |
| 2589 | :type: :class:`ObjectIdentifier` |
| 2590 | |
| 2591 | Returns the OID. |
| 2592 | |
Paul Kehrer | fa56a23 | 2015-03-17 13:14:03 -0500 | [diff] [blame] | 2593 | .. class:: ExtensionNotFound |
| 2594 | |
| 2595 | This is raised when calling :meth:`Extensions.get_extension_for_oid` with |
| 2596 | an extension OID that is not present in the certificate. |
| 2597 | |
| 2598 | .. attribute:: oid |
| 2599 | |
| 2600 | :type: :class:`ObjectIdentifier` |
| 2601 | |
| 2602 | Returns the OID. |
| 2603 | |
Paul Kehrer | 9089c91 | 2015-04-20 22:15:20 -0500 | [diff] [blame] | 2604 | .. class:: UnsupportedGeneralNameType |
| 2605 | |
| 2606 | This is raised when a certificate contains an unsupported general name |
| 2607 | type in an extension. |
| 2608 | |
Paul Kehrer | bed0735 | 2015-04-21 08:31:10 -0500 | [diff] [blame] | 2609 | .. attribute:: type |
| 2610 | |
Paul Kehrer | 0a621bf | 2015-04-22 09:22:56 -0500 | [diff] [blame] | 2611 | :type: int |
| 2612 | |
| 2613 | The integer value of the unsupported type. The complete list of |
| 2614 | types can be found in `RFC 5280 section 4.2.1.6`_. |
Paul Kehrer | bed0735 | 2015-04-21 08:31:10 -0500 | [diff] [blame] | 2615 | |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 2616 | |
Paul Kehrer | c7c9a43 | 2015-04-19 09:20:13 -0500 | [diff] [blame] | 2617 | .. _`RFC 5280 section 4.2.1.1`: https://tools.ietf.org/html/rfc5280#section-4.2.1.1 |
Paul Kehrer | 0a621bf | 2015-04-22 09:22:56 -0500 | [diff] [blame] | 2618 | .. _`RFC 5280 section 4.2.1.6`: https://tools.ietf.org/html/rfc5280#section-4.2.1.6 |
Paul Kehrer | 8b89bcc | 2016-09-03 11:31:43 -0500 | [diff] [blame] | 2619 | .. _`CABForum Guidelines`: https://cabforum.org/baseline-requirements-documents/ |