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----- |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 25 | MIICcDCCAVgCAQAwDTELMAkGA1UEBhMCVVMwggEiMA0GCSqGSIb3DQEBAQUAA4IB |
| 26 | DwAwggEKAoIBAQCb+ec0zYAYLzk/MDdDJYvzdvEO2ZUrBYM6z1r8NedwpJfxUWqC |
| 27 | hvK1cpc9EbQeCwS1eooTIGoNveeCrwL+pWdmf1sh6gz7SsxdN/07nyhSM8M6Xkec |
| 28 | +tGrjyi1H/N1afwWXox3WcvBNbxu3Df5RKLDb0yt9aqhmJylbl/tbvgJesXymwmp |
| 29 | Rc1vXL0fOedUtuAJ3xQ15M0pgLF8qDn4lySJz25x76pMYPeN5/a7x+SR/jj81kep |
| 30 | VaVpuh/2hePV5uwUX3uWoj5sAkrBCifi4NPge0Npd6KeKVvXytLOymH/4+WvV719 |
| 31 | wCO+MyrkhpdHSakJDTIaQIxsqVeVVKdPLAPJAgMBAAGgHjAcBgkqhkiG9w0BCQcx |
| 32 | DwwNY2hhbGxlbmdlIG1lITANBgkqhkiG9w0BAQsFAAOCAQEAMmgeSa8szbjPFD/4 |
| 33 | vcPBr/vBEROFGgL8mX3o5pF9gpr7nRjhLKBkgJvlRm6Ma3Xvdfc/r5Hp2ZBTA7sZ |
| 34 | ZYhyeezGfCQN/Qhda1v+sCwG58IjvGfCSS7Y5tGlEBQ4MDf0Q7PYPSxaNUEBH7vo |
| 35 | +M7U+nFuNSmyWlt6SFBSkohZkWoVSGx3KsAO+SAHYZ7JtqsAS/dm7Dflp8KxeDg7 |
| 36 | wzGBDQRpGF4CpI1VQjGSJQXSEdD+J7mtvBEOD34abRfV6zOUGzOOo3NWE6wNpYgt |
| 37 | 0A7gVlzSYpdwqjBdvACfXR2r/mu+4KkAvYh8WwCiTcYgGjl2pT1bO4hEmcJ0RSWy |
| 38 | /fGD8Q== |
Paul Kehrer | d26c4db | 2015-03-15 15:36:24 -0500 | [diff] [blame] | 39 | -----END CERTIFICATE REQUEST----- |
| 40 | """.strip() |
| 41 | |
Paul Kehrer | d3dafbd | 2015-03-15 16:24:18 -0500 | [diff] [blame] | 42 | pem_data = b""" |
| 43 | -----BEGIN CERTIFICATE----- |
| 44 | MIIDfDCCAmSgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJVUzEf |
| 45 | MB0GA1UEChMWVGVzdCBDZXJ0aWZpY2F0ZXMgMjAxMTEVMBMGA1UEAxMMVHJ1c3Qg |
| 46 | QW5jaG9yMB4XDTEwMDEwMTA4MzAwMFoXDTMwMTIzMTA4MzAwMFowQDELMAkGA1UE |
| 47 | BhMCVVMxHzAdBgNVBAoTFlRlc3QgQ2VydGlmaWNhdGVzIDIwMTExEDAOBgNVBAMT |
| 48 | B0dvb2QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCQWJpHYo37 |
| 49 | Xfb7oJSPe+WvfTlzIG21WQ7MyMbGtK/m8mejCzR6c+f/pJhEH/OcDSMsXq8h5kXa |
| 50 | BGqWK+vSwD/Pzp5OYGptXmGPcthDtAwlrafkGOS4GqIJ8+k9XGKs+vQUXJKsOk47 |
| 51 | RuzD6PZupq4s16xaLVqYbUC26UcY08GpnoLNHJZS/EmXw1ZZ3d4YZjNlpIpWFNHn |
| 52 | UGmdiGKXUPX/9H0fVjIAaQwjnGAbpgyCumWgzIwPpX+ElFOUr3z7BoVnFKhIXze+ |
| 53 | VmQGSWxZxvWDUN90Ul0tLEpLgk3OVxUB4VUGuf15OJOpgo1xibINPmWt14Vda2N9 |
| 54 | yrNKloJGZNqLAgMBAAGjfDB6MB8GA1UdIwQYMBaAFOR9X9FclYYILAWuvnW2ZafZ |
| 55 | XahmMB0GA1UdDgQWBBRYAYQkG7wrUpRKPaUQchRR9a86yTAOBgNVHQ8BAf8EBAMC |
| 56 | AQYwFwYDVR0gBBAwDjAMBgpghkgBZQMCATABMA8GA1UdEwEB/wQFMAMBAf8wDQYJ |
| 57 | KoZIhvcNAQELBQADggEBADWHlxbmdTXNwBL/llwhQqwnazK7CC2WsXBBqgNPWj7m |
| 58 | tvQ+aLG8/50Qc2Sun7o2VnwF9D18UUe8Gj3uPUYH+oSI1vDdyKcjmMbKRU4rk0eo |
| 59 | 3UHNDXwqIVc9CQS9smyV+x1HCwL4TTrq+LXLKx/qVij0Yqk+UJfAtrg2jnYKXsCu |
| 60 | FMBQQnWCGrwa1g1TphRp/RmYHnMynYFmZrXtzFz+U9XEA7C+gPq4kqDI/iVfIT1s |
| 61 | 6lBtdB50lrDVwl2oYfAvW/6sC2se2QleZidUmrziVNP4oEeXINokU6T6p//HM1FG |
| 62 | QYw2jOvpKcKtWCSAnegEbgsGYzATKjmPJPJ0npHFqzM= |
| 63 | -----END CERTIFICATE----- |
| 64 | """.strip() |
| 65 | |
Paul Kehrer | 93ae805 | 2015-05-02 23:18:09 -0500 | [diff] [blame] | 66 | cryptography_cert_pem = b""" |
| 67 | -----BEGIN CERTIFICATE----- |
| 68 | MIIFvTCCBKWgAwIBAgICPyAwDQYJKoZIhvcNAQELBQAwRzELMAkGA1UEBhMCVVMx |
| 69 | FjAUBgNVBAoTDUdlb1RydXN0IEluYy4xIDAeBgNVBAMTF1JhcGlkU1NMIFNIQTI1 |
| 70 | NiBDQSAtIEczMB4XDTE0MTAxNTEyMDkzMloXDTE4MTExNjAxMTUwM1owgZcxEzAR |
| 71 | BgNVBAsTCkdUNDg3NDI5NjUxMTAvBgNVBAsTKFNlZSB3d3cucmFwaWRzc2wuY29t |
| 72 | L3Jlc291cmNlcy9jcHMgKGMpMTQxLzAtBgNVBAsTJkRvbWFpbiBDb250cm9sIFZh |
| 73 | bGlkYXRlZCAtIFJhcGlkU1NMKFIpMRwwGgYDVQQDExN3d3cuY3J5cHRvZ3JhcGh5 |
| 74 | LmlvMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAom/FebKJIot7Sp3s |
| 75 | itG1sicpe3thCssjI+g1JDAS7I3GLVNmbms1DOdIIqwf01gZkzzXBN2+9sOnyRaR |
| 76 | PPfCe1jTr3dk2y6rPE559vPa1nZQkhlzlhMhlPyjaT+S7g4Tio4qV2sCBZU01DZJ |
| 77 | CaksfohN+5BNVWoJzTbOcrHOEJ+M8B484KlBCiSxqf9cyNQKru4W3bHaCVNVJ8eu |
| 78 | 6i6KyhzLa0L7yK3LXwwXVs583C0/vwFhccGWsFODqD/9xHUzsBIshE8HKjdjDi7Y |
| 79 | 3BFQzVUQFjBB50NSZfAA/jcdt1blxJouc7z9T8Oklh+V5DDBowgAsrT4b6Z2Fq6/ |
| 80 | r7D1GqivLK/ypUQmxq2WXWAUBb/Q6xHgxASxI4Br+CByIUQJsm8L2jzc7k+mF4hW |
| 81 | ltAIUkbo8fGiVnat0505YJgxWEDKOLc4Gda6d/7GVd5AvKrz242bUqeaWo6e4MTx |
| 82 | diku2Ma3rhdcr044Qvfh9hGyjqNjvhWY/I+VRWgihU7JrYvgwFdJqsQ5eiKT4OHi |
| 83 | gsejvWwkZzDtiQ+aQTrzM1FsY2swJBJsLSX4ofohlVRlIJCn/ME+XErj553431Lu |
| 84 | YQ5SzMd3nXzN78Vj6qzTfMUUY72UoT1/AcFiUMobgIqrrmwuNxfrkbVE2b6Bga74 |
| 85 | FsJX63prvrJ41kuHK/16RQBM7fcCAwEAAaOCAWAwggFcMB8GA1UdIwQYMBaAFMOc |
| 86 | 8/zTRgg0u85Gf6B8W/PiCMtZMFcGCCsGAQUFBwEBBEswSTAfBggrBgEFBQcwAYYT |
| 87 | aHR0cDovL2d2LnN5bWNkLmNvbTAmBggrBgEFBQcwAoYaaHR0cDovL2d2LnN5bWNi |
| 88 | LmNvbS9ndi5jcnQwDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUFBwMB |
| 89 | BggrBgEFBQcDAjAvBgNVHREEKDAmghN3d3cuY3J5cHRvZ3JhcGh5Lmlvgg9jcnlw |
| 90 | dG9ncmFwaHkuaW8wKwYDVR0fBCQwIjAgoB6gHIYaaHR0cDovL2d2LnN5bWNiLmNv |
| 91 | bS9ndi5jcmwwDAYDVR0TAQH/BAIwADBFBgNVHSAEPjA8MDoGCmCGSAGG+EUBBzYw |
| 92 | LDAqBggrBgEFBQcCARYeaHR0cHM6Ly93d3cucmFwaWRzc2wuY29tL2xlZ2FsMA0G |
| 93 | CSqGSIb3DQEBCwUAA4IBAQAzIYO2jx7h17FBT74tJ2zbV9OKqGb7QF8y3wUtP4xc |
| 94 | dH80vprI/Cfji8s86kr77aAvAqjDjaVjHn7UzebhSUivvRPmfzRgyWBacomnXTSt |
| 95 | Xlt2dp2nDQuwGyK2vB7dMfKnQAkxwq1sYUXznB8i0IhhCAoXp01QGPKq51YoIlnF |
| 96 | 7DRMk6iEaL1SJbkIrLsCQyZFDf0xtfW9DqXugMMLoxeCsBhZJQzNyS2ryirrv9LH |
| 97 | aK3+6IZjrcyy9bkpz/gzJucyhU+75c4My/mnRCrtItRbCQuiI5pd5poDowm+HH9i |
| 98 | GVI9+0lAFwxOUnOnwsoI40iOoxjLMGB+CgFLKCGUcWxP |
| 99 | -----END CERTIFICATE----- |
| 100 | """.strip() |
| 101 | |
g_goessel | 16f746f | 2018-10-10 04:13:41 +0200 | [diff] [blame] | 102 | pem_issuer_public_key = b""" |
| 103 | -----BEGIN RSA PUBLIC KEY----- |
| 104 | MIICCgKCAgEAyYcqyuT6oQxpvg/VSn2Zc68wZ823D0VAJ2woramFx+2KPWB7B7Ot |
| 105 | tVSNRfm0OxJOU3TFAoep54Z2wgOoz0zRmeW6/7gvIuBKp2TW0qZAt3l9sgpE29iw |
| 106 | CsoZQlMrLKiDPzCC6Fptk+YPSST9sqwhWDKK1QvOg68DKRxTpEek1hBpC0XRsnuX |
| 107 | fvJJQqP39vxzpA0PsicI/wrvWX3vO8z+j9+botPerbeamoeHCsc0xgTLyIygWysB |
| 108 | rNskxlzC2U4Kw6mQhGghlLReo1rFsO2/hLTnvLs+Y1lQhnFeOKCx1WVXhzBIyO9B |
| 109 | dVVH5Cinb5wBNKvxbevRf4icdWcwtknmgKf69xj7yvFjt/vft74BB1Y5ltLYFmEb |
| 110 | 0JBxm5MAJfW4YnMQr0AxdjOhjHq4MN7X4ZzwEpJaYJdRmvMsMGN88cyjYPxsaOG+ |
| 111 | dZ/E9MmTjh0gnTjyD4gmsvR/gtTR/XFJ2wkbnnL1RyxNi6j2UW8C7tpNv0TIuArx |
| 112 | 3SHGPZN0WsaKTxZPb0L/ob1WBT0mhiq1GzB431cXgbxyh8EdKk+xSptA3V+ca2V2 |
| 113 | NuXlJIJaOoPMj/qjDW4I/peKGnk9tLknJ0hpRzz11j77pJsV0dGoGKVHIR2oZqT5 |
| 114 | 0ZJJb5DXNbiTnspKLNmBt0YlNiXtlCIPxVUkhL141FuCLc8h6FjD6E0CAwEAAQ== |
| 115 | -----END RSA PUBLIC KEY----- |
| 116 | """.strip() |
| 117 | |
| 118 | pem_data_to_check = b""" |
| 119 | -----BEGIN CERTIFICATE----- |
| 120 | MIIErjCCApagAwIBAgIUUrUZsZrrBmRD2hvRuspp+lPsZXcwDQYJKoZIhvcNAQEN |
| 121 | BQAwETEPMA0GA1UEAwwGSXNzdWVyMB4XDTE4MTAwODEzNDg1NFoXDTE4MTAxODEz |
| 122 | NDg1NFowETEPMA0GA1UEAwwGSXNzdWVyMIICIjANBgkqhkiG9w0BAQEFAAOCAg8A |
| 123 | MIICCgKCAgEAyYcqyuT6oQxpvg/VSn2Zc68wZ823D0VAJ2woramFx+2KPWB7B7Ot |
| 124 | tVSNRfm0OxJOU3TFAoep54Z2wgOoz0zRmeW6/7gvIuBKp2TW0qZAt3l9sgpE29iw |
| 125 | CsoZQlMrLKiDPzCC6Fptk+YPSST9sqwhWDKK1QvOg68DKRxTpEek1hBpC0XRsnuX |
| 126 | fvJJQqP39vxzpA0PsicI/wrvWX3vO8z+j9+botPerbeamoeHCsc0xgTLyIygWysB |
| 127 | rNskxlzC2U4Kw6mQhGghlLReo1rFsO2/hLTnvLs+Y1lQhnFeOKCx1WVXhzBIyO9B |
| 128 | dVVH5Cinb5wBNKvxbevRf4icdWcwtknmgKf69xj7yvFjt/vft74BB1Y5ltLYFmEb |
| 129 | 0JBxm5MAJfW4YnMQr0AxdjOhjHq4MN7X4ZzwEpJaYJdRmvMsMGN88cyjYPxsaOG+ |
| 130 | dZ/E9MmTjh0gnTjyD4gmsvR/gtTR/XFJ2wkbnnL1RyxNi6j2UW8C7tpNv0TIuArx |
| 131 | 3SHGPZN0WsaKTxZPb0L/ob1WBT0mhiq1GzB431cXgbxyh8EdKk+xSptA3V+ca2V2 |
| 132 | NuXlJIJaOoPMj/qjDW4I/peKGnk9tLknJ0hpRzz11j77pJsV0dGoGKVHIR2oZqT5 |
| 133 | 0ZJJb5DXNbiTnspKLNmBt0YlNiXtlCIPxVUkhL141FuCLc8h6FjD6E0CAwEAATAN |
| 134 | BgkqhkiG9w0BAQ0FAAOCAgEAVFzNKhEpkH8V8l0NEBAZHNi1e+lcg35fZZ9plqcw |
| 135 | Pvk+6M7LW0KD0QWYQWm/dJme4DFsM7lh5u4/m+H4yS7/RP9pads9YwBudchvGR1c |
| 136 | S4CCrRAmO8/A0vpQJcEwdS7fdYShBsqMrZ2TvzceVn2dvQbxB6pLkK7KIbDPVJA2 |
| 137 | HXFFXe2npHmdc80iTz2ShbdVSvyPvk6vc6NFFCg6lSQFuif3vV0+aYqi6DXv4h92 |
| 138 | 9qAdES8ZLDfDulxyajyPbtF35f2Of99CumP5UzG4RQbvtI8gShuK1YFYe2sWJFE0 |
| 139 | MgSsqGCbl5mcrWxm9YxysRKMZ+Hc4tnkvfmG6GsKtp8u/5pG11XgxXaQl4fZ7JNa |
| 140 | QFuD5gEXkEC1mCnhWlnguJgjQlpKadMOORmVTqG9dNQ6GEsha+XWpinm5L9fEZuA |
| 141 | F88nNyubKLwEl68N7WWWKQlIl4q8Pe5FEp1pd9rLjOW4gzgYBccIfBK3oMC7uFJg |
| 142 | a/9GeOKPiq90UMrCI+CAsIbzuPOaAp3g69JonuDwcs4cu8ui1udxs9q7ox3qSWGZ |
| 143 | G1U/hmwvZH9kfIv5BKIzNLy4oxXPDJ7MZIBsxVxaNv8KUQ/JLtpVJa3oYqEx18+V |
| 144 | JNr8Pr3y61X8pLmJnaCu+ixshiy2gjxXxDFBVEEt1G9JHrSs3R+yvcHxCrM3+ian |
| 145 | Nh4= |
| 146 | -----END CERTIFICATE----- |
| 147 | """.strip() |
| 148 | |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 149 | Loading Certificates |
| 150 | ~~~~~~~~~~~~~~~~~~~~ |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 151 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 152 | .. function:: load_pem_x509_certificate(data, backend=None) |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 153 | |
| 154 | .. versionadded:: 0.7 |
| 155 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 156 | Deserialize a certificate from PEM encoded data. PEM certificates are |
| 157 | base64 decoded and have delimiters that look like |
| 158 | ``-----BEGIN CERTIFICATE-----``. |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 159 | |
| 160 | :param bytes data: The PEM encoded certificate data. |
| 161 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 162 | :param backend: An optional backend supporting the |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 163 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 164 | interface. |
| 165 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 166 | :returns: An instance of :class:`~cryptography.x509.Certificate`. |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 167 | |
Alex Gaynor | 5ce1404 | 2016-05-29 13:13:46 -0400 | [diff] [blame] | 168 | .. doctest:: |
| 169 | |
| 170 | >>> from cryptography import x509 |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 171 | >>> cert = x509.load_pem_x509_certificate(pem_data) |
Chelsea Winfree | e295f3a | 2016-06-02 21:15:54 -0700 | [diff] [blame] | 172 | >>> cert.serial_number |
Alex Gaynor | 5ce1404 | 2016-05-29 13:13:46 -0400 | [diff] [blame] | 173 | 2 |
| 174 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 175 | .. function:: load_der_x509_certificate(data, backend=None) |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 176 | |
| 177 | .. versionadded:: 0.7 |
| 178 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 179 | Deserialize a certificate from DER encoded data. DER is a binary format |
Paul Kehrer | 92aac38 | 2014-12-15 16:25:28 -0600 | [diff] [blame] | 180 | and is commonly found in files with the ``.cer`` extension (although file |
| 181 | extensions are not a guarantee of encoding type). |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 182 | |
| 183 | :param bytes data: The DER encoded certificate data. |
| 184 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 185 | :param backend: An optional backend supporting the |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 186 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 187 | interface. |
| 188 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 189 | :returns: An instance of :class:`~cryptography.x509.Certificate`. |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 190 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 191 | Loading Certificate Revocation Lists |
| 192 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 193 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 194 | .. function:: load_pem_x509_crl(data, backend=None) |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 195 | |
| 196 | .. versionadded:: 1.1 |
| 197 | |
| 198 | Deserialize a certificate revocation list (CRL) from PEM encoded data. PEM |
| 199 | requests are base64 decoded and have delimiters that look like |
Erik Trauschke | 32bbfe0 | 2015-10-21 08:04:55 -0700 | [diff] [blame] | 200 | ``-----BEGIN X509 CRL-----``. |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 201 | |
| 202 | :param bytes data: The PEM encoded request data. |
| 203 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 204 | :param backend: An optional backend supporting the |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 205 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 206 | interface. |
| 207 | |
| 208 | :returns: An instance of |
| 209 | :class:`~cryptography.x509.CertificateRevocationList`. |
| 210 | |
Alex Gaynor | 5ce1404 | 2016-05-29 13:13:46 -0400 | [diff] [blame] | 211 | .. doctest:: |
| 212 | |
| 213 | >>> from cryptography import x509 |
Alex Gaynor | 5ce1404 | 2016-05-29 13:13:46 -0400 | [diff] [blame] | 214 | >>> from cryptography.hazmat.primitives import hashes |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 215 | >>> crl = x509.load_pem_x509_crl(pem_crl_data) |
Alex Gaynor | 5ce1404 | 2016-05-29 13:13:46 -0400 | [diff] [blame] | 216 | >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256) |
| 217 | True |
| 218 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 219 | .. function:: load_der_x509_crl(data, backend=None) |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 220 | |
| 221 | .. versionadded:: 1.1 |
| 222 | |
| 223 | Deserialize a certificate revocation list (CRL) from DER encoded data. DER |
| 224 | is a binary format. |
| 225 | |
| 226 | :param bytes data: The DER encoded request data. |
| 227 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 228 | :param backend: An optional backend supporting the |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 229 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 230 | interface. |
| 231 | |
| 232 | :returns: An instance of |
| 233 | :class:`~cryptography.x509.CertificateRevocationList`. |
| 234 | |
Paul Kehrer | a1a1f23 | 2015-03-15 15:34:35 -0500 | [diff] [blame] | 235 | Loading Certificate Signing Requests |
| 236 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 237 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 238 | .. function:: load_pem_x509_csr(data, backend=None) |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 239 | |
| 240 | .. versionadded:: 0.9 |
| 241 | |
Paul Kehrer | a1a1f23 | 2015-03-15 15:34:35 -0500 | [diff] [blame] | 242 | Deserialize a certificate signing request (CSR) from PEM encoded data. PEM |
Paul Kehrer | 5aadb9c | 2015-03-11 20:48:42 -0500 | [diff] [blame] | 243 | requests are base64 decoded and have delimiters that look like |
Paul Kehrer | d3dafbd | 2015-03-15 16:24:18 -0500 | [diff] [blame] | 244 | ``-----BEGIN CERTIFICATE REQUEST-----``. This format is also known as |
| 245 | PKCS#10. |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 246 | |
| 247 | :param bytes data: The PEM encoded request data. |
| 248 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 249 | :param backend: An optional backend supporting the |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 250 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 251 | interface. |
| 252 | |
Paul Kehrer | a1a1f23 | 2015-03-15 15:34:35 -0500 | [diff] [blame] | 253 | :returns: An instance of |
| 254 | :class:`~cryptography.x509.CertificateSigningRequest`. |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 255 | |
Alex Gaynor | 5ce1404 | 2016-05-29 13:13:46 -0400 | [diff] [blame] | 256 | .. doctest:: |
| 257 | |
| 258 | >>> from cryptography import x509 |
Alex Gaynor | 5ce1404 | 2016-05-29 13:13:46 -0400 | [diff] [blame] | 259 | >>> from cryptography.hazmat.primitives import hashes |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 260 | >>> csr = x509.load_pem_x509_csr(pem_req_data) |
| 261 | >>> isinstance(csr.signature_hash_algorithm, hashes.SHA256) |
Alex Gaynor | 5ce1404 | 2016-05-29 13:13:46 -0400 | [diff] [blame] | 262 | True |
| 263 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 264 | .. function:: load_der_x509_csr(data, backend=None) |
Paul Kehrer | 1effb6e | 2015-03-30 15:05:59 -0500 | [diff] [blame] | 265 | |
| 266 | .. versionadded:: 0.9 |
| 267 | |
| 268 | Deserialize a certificate signing request (CSR) from DER encoded data. DER |
| 269 | is a binary format and is not commonly used with CSRs. |
| 270 | |
| 271 | :param bytes data: The DER encoded request data. |
| 272 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 273 | :param backend: An optional backend supporting the |
Paul Kehrer | 1effb6e | 2015-03-30 15:05:59 -0500 | [diff] [blame] | 274 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 275 | interface. |
| 276 | |
| 277 | :returns: An instance of |
| 278 | :class:`~cryptography.x509.CertificateSigningRequest`. |
| 279 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 280 | X.509 Certificate Object |
| 281 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 282 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 283 | .. class:: Certificate |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 284 | |
| 285 | .. versionadded:: 0.7 |
| 286 | |
| 287 | .. attribute:: version |
| 288 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 289 | :type: :class:`~cryptography.x509.Version` |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 290 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 291 | The certificate version as an enumeration. Version 3 certificates are |
| 292 | 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] | 293 | |
Alex Gaynor | 89c4dc8 | 2014-12-16 16:49:33 -0800 | [diff] [blame] | 294 | :raises cryptography.x509.InvalidVersion: If the version in the |
Alex Gaynor | 6d7ab4c | 2014-12-16 16:50:33 -0800 | [diff] [blame] | 295 | certificate is not a known |
| 296 | :class:`X.509 version <cryptography.x509.Version>`. |
Paul Kehrer | 92aac38 | 2014-12-15 16:25:28 -0600 | [diff] [blame] | 297 | |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 298 | .. doctest:: |
| 299 | |
| 300 | >>> cert.version |
| 301 | <Version.v3: 2> |
| 302 | |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 303 | .. method:: fingerprint(algorithm) |
| 304 | |
| 305 | :param algorithm: The |
Paul Kehrer | 601278a | 2015-02-12 12:51:00 -0600 | [diff] [blame] | 306 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 307 | that will be used to generate the fingerprint. |
| 308 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 309 | :return bytes: The fingerprint using the supplied hash algorithm, as |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 310 | bytes. |
| 311 | |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 312 | .. doctest:: |
| 313 | |
| 314 | >>> from cryptography.hazmat.primitives import hashes |
| 315 | >>> cert.fingerprint(hashes.SHA256()) |
Paul Kehrer | 056c9dd | 2018-05-12 15:17:06 -0400 | [diff] [blame] | 316 | b'\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] | 317 | |
Chelsea Winfree | e295f3a | 2016-06-02 21:15:54 -0700 | [diff] [blame] | 318 | .. attribute:: serial_number |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 319 | |
| 320 | :type: int |
| 321 | |
| 322 | The serial as a Python integer. |
| 323 | |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 324 | .. doctest:: |
| 325 | |
Chelsea Winfree | e295f3a | 2016-06-02 21:15:54 -0700 | [diff] [blame] | 326 | >>> cert.serial_number |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 327 | 2 |
| 328 | |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 329 | .. method:: public_key() |
| 330 | |
Alex Gaynor | 4c2561a | 2015-10-12 23:53:39 -0400 | [diff] [blame] | 331 | The public key associated with the certificate. |
| 332 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 333 | :returns: One of |
| 334 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`, |
| 335 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`, |
| 336 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`, |
| 337 | :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey` or |
| 338 | :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PublicKey` |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 339 | |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 340 | .. doctest:: |
| 341 | |
Alex Stapleton | f79c231 | 2014-12-30 12:50:14 +0000 | [diff] [blame] | 342 | >>> from cryptography.hazmat.primitives.asymmetric import rsa |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 343 | >>> public_key = cert.public_key() |
Alex Stapleton | f79c231 | 2014-12-30 12:50:14 +0000 | [diff] [blame] | 344 | >>> isinstance(public_key, rsa.RSAPublicKey) |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 345 | True |
| 346 | |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 347 | .. attribute:: not_valid_before |
| 348 | |
| 349 | :type: :class:`datetime.datetime` |
| 350 | |
Paul Kehrer | 78a8150 | 2014-12-16 14:47:52 -0600 | [diff] [blame] | 351 | A naïve datetime representing the beginning of the validity period for |
| 352 | the certificate in UTC. This value is inclusive. |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 353 | |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 354 | .. doctest:: |
| 355 | |
| 356 | >>> cert.not_valid_before |
| 357 | datetime.datetime(2010, 1, 1, 8, 30) |
| 358 | |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 359 | .. attribute:: not_valid_after |
| 360 | |
| 361 | :type: :class:`datetime.datetime` |
| 362 | |
Paul Kehrer | 78a8150 | 2014-12-16 14:47:52 -0600 | [diff] [blame] | 363 | A naïve datetime representing the end of the validity period for the |
| 364 | certificate in UTC. This value is inclusive. |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 365 | |
Paul Kehrer | cc8a26e | 2014-12-16 12:40:16 -0600 | [diff] [blame] | 366 | .. doctest:: |
| 367 | |
| 368 | >>> cert.not_valid_after |
| 369 | datetime.datetime(2030, 12, 31, 8, 30) |
| 370 | |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 371 | .. attribute:: issuer |
| 372 | |
| 373 | .. versionadded:: 0.8 |
| 374 | |
| 375 | :type: :class:`Name` |
| 376 | |
| 377 | The :class:`Name` of the issuer. |
| 378 | |
| 379 | .. attribute:: subject |
| 380 | |
| 381 | .. versionadded:: 0.8 |
| 382 | |
| 383 | :type: :class:`Name` |
| 384 | |
| 385 | The :class:`Name` of the subject. |
| 386 | |
Paul Kehrer | 8802a5b | 2015-02-13 12:06:57 -0600 | [diff] [blame] | 387 | .. attribute:: signature_hash_algorithm |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 388 | |
Paul Kehrer | 8802a5b | 2015-02-13 12:06:57 -0600 | [diff] [blame] | 389 | :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 390 | |
Paul Kehrer | e612ec7 | 2015-02-16 14:33:35 -0600 | [diff] [blame] | 391 | Returns the |
Paul Kehrer | 71d40c6 | 2015-02-19 08:21:04 -0600 | [diff] [blame] | 392 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 393 | was used in signing this certificate. Can be ``None`` if signature |
| 394 | did not use separate hash |
| 395 | (:attr:`~cryptography.x509.oid.SignatureAlgorithmOID.ED25519`, |
| 396 | :attr:`~cryptography.x509.oid.SignatureAlgorithmOID.ED448`). |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 397 | |
| 398 | .. doctest:: |
| 399 | |
Paul Kehrer | 8802a5b | 2015-02-13 12:06:57 -0600 | [diff] [blame] | 400 | >>> from cryptography.hazmat.primitives import hashes |
| 401 | >>> isinstance(cert.signature_hash_algorithm, hashes.SHA256) |
| 402 | True |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 403 | |
Paul Kehrer | c7b29b8 | 2016-09-01 09:17:21 +0800 | [diff] [blame] | 404 | .. attribute:: signature_algorithm_oid |
| 405 | |
| 406 | .. versionadded:: 1.6 |
| 407 | |
| 408 | :type: :class:`ObjectIdentifier` |
| 409 | |
| 410 | Returns the :class:`ObjectIdentifier` of the signature algorithm used |
| 411 | to sign the certificate. This will be one of the OIDs from |
| 412 | :class:`~cryptography.x509.oid.SignatureAlgorithmOID`. |
| 413 | |
| 414 | |
| 415 | .. doctest:: |
| 416 | |
| 417 | >>> cert.signature_algorithm_oid |
| 418 | <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)> |
| 419 | |
Paul Kehrer | fbb7ac8 | 2015-03-16 19:26:29 -0500 | [diff] [blame] | 420 | .. attribute:: extensions |
| 421 | |
| 422 | :type: :class:`Extensions` |
| 423 | |
| 424 | The extensions encoded in the certificate. |
| 425 | |
| 426 | :raises cryptography.x509.DuplicateExtension: If more than one |
| 427 | extension of the same type is found within the certificate. |
| 428 | |
Paul Kehrer | bed0735 | 2015-04-21 08:31:10 -0500 | [diff] [blame] | 429 | :raises cryptography.x509.UnsupportedGeneralNameType: If an extension |
| 430 | contains a general name that is not supported. |
| 431 | |
Paul Kehrer | fa56a23 | 2015-03-17 13:14:03 -0500 | [diff] [blame] | 432 | .. doctest:: |
| 433 | |
| 434 | >>> for ext in cert.extensions: |
| 435 | ... print(ext) |
Paul Kehrer | 056c9dd | 2018-05-12 15:17:06 -0400 | [diff] [blame] | 436 | <Extension(oid=<ObjectIdentifier(oid=2.5.29.35, name=authorityKeyIdentifier)>, critical=False, value=<AuthorityKeyIdentifier(key_identifier=b'\xe4}_\xd1\\\x95\x86\x08,\x05\xae\xbeu\xb6e\xa7\xd9]\xa8f', authority_cert_issuer=None, authority_cert_serial_number=None)>)> |
| 437 | <Extension(oid=<ObjectIdentifier(oid=2.5.29.14, name=subjectKeyIdentifier)>, critical=False, value=<SubjectKeyIdentifier(digest=b'X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9')>)> |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 438 | <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=False, decipher_only=False)>)> |
Paul Kehrer | 2008d9c | 2015-05-12 22:19:56 -0500 | [diff] [blame] | 439 | <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] | 440 | <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)> |
| 441 | |
Paul Kehrer | d91e7c1 | 2015-10-01 16:50:42 -0500 | [diff] [blame] | 442 | .. attribute:: signature |
| 443 | |
| 444 | .. versionadded:: 1.2 |
| 445 | |
| 446 | :type: bytes |
| 447 | |
| 448 | The bytes of the certificate's signature. |
| 449 | |
Paul Kehrer | d289805 | 2015-11-03 22:00:41 +0900 | [diff] [blame] | 450 | .. attribute:: tbs_certificate_bytes |
Paul Kehrer | d91e7c1 | 2015-10-01 16:50:42 -0500 | [diff] [blame] | 451 | |
| 452 | .. versionadded:: 1.2 |
| 453 | |
| 454 | :type: bytes |
| 455 | |
| 456 | The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed |
| 457 | and then signed by the private key of the certificate's issuer. This |
| 458 | data may be used to validate a signature, but use extreme caution as |
| 459 | certificate validation is a complex problem that involves much more |
| 460 | than just signature checks. |
| 461 | |
Paul Kehrer | 838bc4a | 2018-10-10 12:02:55 +0800 | [diff] [blame] | 462 | To validate the signature on a certificate you can do the following. |
| 463 | Note: This only verifies that the certificate was signed with the |
| 464 | private key associated with the public key provided and does not |
| 465 | perform any of the other checks needed for secure certificate |
| 466 | validation. Additionally, this example will only work for RSA public |
| 467 | keys with ``PKCS1v15`` signatures, and so it can't be used for general |
| 468 | purpose signature verification. |
g_goessel | 16f746f | 2018-10-10 04:13:41 +0200 | [diff] [blame] | 469 | |
| 470 | .. doctest:: |
| 471 | |
| 472 | >>> from cryptography.hazmat.primitives.serialization import load_pem_public_key |
| 473 | >>> from cryptography.hazmat.primitives.asymmetric import padding |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 474 | >>> issuer_public_key = load_pem_public_key(pem_issuer_public_key) |
| 475 | >>> cert_to_check = x509.load_pem_x509_certificate(pem_data_to_check) |
g_goessel | 16f746f | 2018-10-10 04:13:41 +0200 | [diff] [blame] | 476 | >>> issuer_public_key.verify( |
Alex Gaynor | 6460228 | 2018-10-09 23:03:55 -0400 | [diff] [blame] | 477 | ... cert_to_check.signature, |
| 478 | ... cert_to_check.tbs_certificate_bytes, |
| 479 | ... # Depends on the algorithm used to create the certificate |
| 480 | ... padding.PKCS1v15(), |
| 481 | ... cert_to_check.signature_hash_algorithm, |
g_goessel | 16f746f | 2018-10-10 04:13:41 +0200 | [diff] [blame] | 482 | ... ) |
| 483 | |
| 484 | An |
| 485 | :class:`~cryptography.exceptions.InvalidSignature` |
| 486 | exception will be raised if the signature fails to verify. |
| 487 | |
Andre Caron | a8aded6 | 2015-05-19 20:11:57 -0400 | [diff] [blame] | 488 | .. method:: public_bytes(encoding) |
| 489 | |
Alex Gaynor | d0b376b | 2015-07-05 13:58:12 -0400 | [diff] [blame] | 490 | .. versionadded:: 1.0 |
| 491 | |
Andre Caron | a8aded6 | 2015-05-19 20:11:57 -0400 | [diff] [blame] | 492 | :param encoding: The |
| 493 | :class:`~cryptography.hazmat.primitives.serialization.Encoding` |
| 494 | that will be used to serialize the certificate. |
| 495 | |
| 496 | :return bytes: The data that can be written to a file or sent |
| 497 | over the network to be verified by clients. |
| 498 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 499 | X.509 CRL (Certificate Revocation List) Object |
| 500 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 501 | |
| 502 | .. class:: CertificateRevocationList |
| 503 | |
| 504 | .. versionadded:: 1.0 |
| 505 | |
Erik Trauschke | 3cdabaf | 2015-10-13 09:42:53 -0700 | [diff] [blame] | 506 | A CertificateRevocationList is an object representing a list of revoked |
| 507 | certificates. The object is iterable and will yield the RevokedCertificate |
| 508 | objects stored in this CRL. |
| 509 | |
| 510 | .. doctest:: |
Erik Trauschke | b14f7d1 | 2015-10-13 09:55:39 -0700 | [diff] [blame] | 511 | |
Erik Trauschke | 3cdabaf | 2015-10-13 09:42:53 -0700 | [diff] [blame] | 512 | >>> len(crl) |
| 513 | 1 |
Paul Kehrer | dcdf967 | 2015-10-21 20:27:28 -0500 | [diff] [blame] | 514 | >>> revoked_certificate = crl[0] |
| 515 | >>> type(revoked_certificate) |
Erik Trauschke | 3cdabaf | 2015-10-13 09:42:53 -0700 | [diff] [blame] | 516 | <class 'cryptography.hazmat.backends.openssl.x509._RevokedCertificate'> |
| 517 | >>> for r in crl: |
| 518 | ... print(r.serial_number) |
| 519 | 0 |
| 520 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 521 | .. method:: fingerprint(algorithm) |
| 522 | |
| 523 | :param algorithm: The |
| 524 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
| 525 | that will be used to generate the fingerprint. |
| 526 | |
| 527 | :return bytes: The fingerprint using the supplied hash algorithm, as |
| 528 | bytes. |
| 529 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 530 | .. doctest:: |
| 531 | |
| 532 | >>> from cryptography.hazmat.primitives import hashes |
| 533 | >>> crl.fingerprint(hashes.SHA256()) |
Paul Kehrer | 056c9dd | 2018-05-12 15:17:06 -0400 | [diff] [blame] | 534 | b'e\xcf.\xc4:\x83?1\xdc\xf3\xfc\x95\xd7\xb3\x87\xb3\x8e\xf8\xb93!\x87\x07\x9d\x1b\xb4!\xb9\xe4W\xf4\x1f' |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 535 | |
Paul Kehrer | 5d18740 | 2018-07-16 20:49:51 +0530 | [diff] [blame] | 536 | .. method:: get_revoked_certificate_by_serial_number(serial_number) |
| 537 | |
| 538 | .. versionadded:: 2.3 |
| 539 | |
| 540 | :param serial_number: The serial as a Python integer. |
| 541 | :returns: :class:`~cryptography.x509.RevokedCertificate` if the |
| 542 | ``serial_number`` is present in the CRL or ``None`` if it |
| 543 | is not. |
| 544 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 545 | .. attribute:: signature_hash_algorithm |
| 546 | |
| 547 | :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
| 548 | |
| 549 | Returns the |
| 550 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 551 | was used in signing this CRL. Can be ``None`` if signature |
| 552 | did not use separate hash |
| 553 | (:attr:`~cryptography.x509.oid.SignatureAlgorithmOID.ED25519`, |
| 554 | :attr:`~cryptography.x509.oid.SignatureAlgorithmOID.ED448`). |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 555 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 556 | .. doctest:: |
| 557 | |
| 558 | >>> from cryptography.hazmat.primitives import hashes |
| 559 | >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256) |
| 560 | True |
| 561 | |
Paul Kehrer | c7b29b8 | 2016-09-01 09:17:21 +0800 | [diff] [blame] | 562 | .. attribute:: signature_algorithm_oid |
| 563 | |
| 564 | .. versionadded:: 1.6 |
| 565 | |
| 566 | :type: :class:`ObjectIdentifier` |
| 567 | |
| 568 | Returns the :class:`ObjectIdentifier` of the signature algorithm used |
| 569 | to sign the CRL. This will be one of the OIDs from |
| 570 | :class:`~cryptography.x509.oid.SignatureAlgorithmOID`. |
| 571 | |
| 572 | .. doctest:: |
| 573 | |
| 574 | >>> crl.signature_algorithm_oid |
| 575 | <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)> |
| 576 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 577 | .. attribute:: issuer |
| 578 | |
| 579 | :type: :class:`Name` |
| 580 | |
| 581 | The :class:`Name` of the issuer. |
| 582 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 583 | .. doctest:: |
| 584 | |
| 585 | >>> crl.issuer |
Marti Raudsepp | 8241557 | 2018-12-18 01:26:40 +0200 | [diff] [blame] | 586 | <Name(C=US,CN=cryptography.io)> |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 587 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 588 | .. attribute:: next_update |
| 589 | |
| 590 | :type: :class:`datetime.datetime` |
| 591 | |
| 592 | A naïve datetime representing when the next update to this CRL is |
| 593 | expected. |
| 594 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 595 | .. doctest:: |
| 596 | |
| 597 | >>> crl.next_update |
| 598 | datetime.datetime(2016, 1, 1, 0, 0) |
| 599 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 600 | .. attribute:: last_update |
| 601 | |
| 602 | :type: :class:`datetime.datetime` |
| 603 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 604 | A naïve datetime representing when this CRL was last updated. |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 605 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 606 | .. doctest:: |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 607 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 608 | >>> crl.last_update |
| 609 | datetime.datetime(2015, 1, 1, 0, 0) |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 610 | |
| 611 | .. attribute:: extensions |
| 612 | |
| 613 | :type: :class:`Extensions` |
| 614 | |
| 615 | The extensions encoded in the CRL. |
| 616 | |
Erik Trauschke | 6abe2bb | 2015-11-19 10:27:01 -0800 | [diff] [blame] | 617 | .. attribute:: signature |
| 618 | |
| 619 | .. versionadded:: 1.2 |
| 620 | |
| 621 | :type: bytes |
| 622 | |
| 623 | The bytes of the CRL's signature. |
| 624 | |
| 625 | .. attribute:: tbs_certlist_bytes |
| 626 | |
| 627 | .. versionadded:: 1.2 |
| 628 | |
| 629 | :type: bytes |
| 630 | |
| 631 | The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed |
| 632 | and then signed by the private key of the CRL's issuer. This data may be |
| 633 | used to validate a signature, but use extreme caution as CRL validation |
| 634 | is a complex problem that involves much more than just signature checks. |
| 635 | |
Paul Kehrer | 54a837d | 2015-12-20 23:42:32 -0600 | [diff] [blame] | 636 | .. method:: public_bytes(encoding) |
| 637 | |
| 638 | .. versionadded:: 1.2 |
| 639 | |
| 640 | :param encoding: The |
| 641 | :class:`~cryptography.hazmat.primitives.serialization.Encoding` |
| 642 | that will be used to serialize the certificate revocation list. |
| 643 | |
| 644 | :return bytes: The data that can be written to a file or sent |
| 645 | over the network and used as part of a certificate verification |
| 646 | process. |
| 647 | |
Vincent Pelletier | 6c02ee8 | 2017-08-12 22:05:00 +0900 | [diff] [blame] | 648 | .. method:: is_signature_valid(public_key) |
| 649 | |
| 650 | .. versionadded:: 2.1 |
| 651 | |
Paul Kehrer | f944c40 | 2017-08-12 08:52:55 -0500 | [diff] [blame] | 652 | .. warning:: |
| 653 | |
| 654 | Checking the validity of the signature on the CRL is insufficient |
| 655 | to know if the CRL should be trusted. More details are available |
| 656 | in :rfc:`5280`. |
| 657 | |
Vincent Pelletier | 6c02ee8 | 2017-08-12 22:05:00 +0900 | [diff] [blame] | 658 | Returns True if the CRL signature is correct for given public key, |
| 659 | False otherwise. |
Erik Trauschke | 6abe2bb | 2015-11-19 10:27:01 -0800 | [diff] [blame] | 660 | |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 661 | X.509 Certificate Builder |
| 662 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 663 | |
| 664 | .. class:: CertificateBuilder |
| 665 | |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 666 | .. versionadded:: 1.0 |
| 667 | |
| 668 | .. doctest:: |
| 669 | |
| 670 | >>> from cryptography import x509 |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 671 | >>> from cryptography.hazmat.primitives import hashes |
| 672 | >>> from cryptography.hazmat.primitives.asymmetric import rsa |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 673 | >>> from cryptography.x509.oid import NameOID |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 674 | >>> import datetime |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 675 | >>> one_day = datetime.timedelta(1, 0, 0) |
| 676 | >>> private_key = rsa.generate_private_key( |
| 677 | ... public_exponent=65537, |
| 678 | ... key_size=2048, |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 679 | ... ) |
Cory Benfield | c47b252 | 2015-12-07 15:25:12 +0000 | [diff] [blame] | 680 | >>> public_key = private_key.public_key() |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 681 | >>> builder = x509.CertificateBuilder() |
| 682 | >>> builder = builder.subject_name(x509.Name([ |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 683 | ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'), |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 684 | ... ])) |
| 685 | >>> builder = builder.issuer_name(x509.Name([ |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 686 | ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'), |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 687 | ... ])) |
| 688 | >>> builder = builder.not_valid_before(datetime.datetime.today() - one_day) |
Alex Gaynor | cdd3585 | 2018-08-05 18:17:35 -0400 | [diff] [blame] | 689 | >>> builder = builder.not_valid_after(datetime.datetime.today() + (one_day * 30)) |
Paul Kehrer | 8b89bcc | 2016-09-03 11:31:43 -0500 | [diff] [blame] | 690 | >>> builder = builder.serial_number(x509.random_serial_number()) |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 691 | >>> builder = builder.public_key(public_key) |
| 692 | >>> builder = builder.add_extension( |
Paul Kehrer | 1bab7bc | 2017-01-18 13:44:40 +0800 | [diff] [blame] | 693 | ... x509.SubjectAlternativeName( |
Paul Kehrer | ed32105 | 2017-10-11 08:11:44 +0800 | [diff] [blame] | 694 | ... [x509.DNSName(u'cryptography.io')] |
Paul Kehrer | 1bab7bc | 2017-01-18 13:44:40 +0800 | [diff] [blame] | 695 | ... ), |
| 696 | ... critical=False |
| 697 | ... ) |
| 698 | >>> builder = builder.add_extension( |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 699 | ... x509.BasicConstraints(ca=False, path_length=None), critical=True, |
| 700 | ... ) |
| 701 | >>> certificate = builder.sign( |
| 702 | ... private_key=private_key, algorithm=hashes.SHA256(), |
Ian Cordasco | 1517a4b | 2015-08-02 22:11:19 -0500 | [diff] [blame] | 703 | ... ) |
| 704 | >>> isinstance(certificate, x509.Certificate) |
| 705 | True |
| 706 | |
Ian Cordasco | 0092a0b | 2015-07-18 21:46:41 -0500 | [diff] [blame] | 707 | .. method:: issuer_name(name) |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 708 | |
| 709 | Sets the issuer's distinguished name. |
| 710 | |
Ian Cordasco | c9682ad | 2015-08-01 12:11:13 -0500 | [diff] [blame] | 711 | :param name: The :class:`~cryptography.x509.Name` that describes the |
| 712 | issuer (CA). |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 713 | |
Ian Cordasco | 0092a0b | 2015-07-18 21:46:41 -0500 | [diff] [blame] | 714 | .. method:: subject_name(name) |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 715 | |
| 716 | Sets the subject's distinguished name. |
| 717 | |
Ian Cordasco | c9682ad | 2015-08-01 12:11:13 -0500 | [diff] [blame] | 718 | :param name: The :class:`~cryptography.x509.Name` that describes the |
Ian Cordasco | 85fc4d5 | 2015-08-01 20:29:31 -0500 | [diff] [blame] | 719 | subject. |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 720 | |
Ian Cordasco | 0092a0b | 2015-07-18 21:46:41 -0500 | [diff] [blame] | 721 | .. method:: public_key(public_key) |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 722 | |
| 723 | Sets the subject's public key. |
| 724 | |
Ian Cordasco | 8f57142 | 2015-08-02 11:31:08 -0500 | [diff] [blame] | 725 | :param public_key: The subject's public key. This can be one of |
| 726 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`, |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 727 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`, |
| 728 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`, |
| 729 | :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey` or |
| 730 | :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PublicKey`. |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 731 | |
Ian Cordasco | 0092a0b | 2015-07-18 21:46:41 -0500 | [diff] [blame] | 732 | .. method:: serial_number(serial_number) |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 733 | |
| 734 | Sets the certificate's serial number (an integer). The CA's policy |
Paul Kehrer | 8b89bcc | 2016-09-03 11:31:43 -0500 | [diff] [blame] | 735 | determines how it attributes serial numbers to certificates. This |
| 736 | number must uniquely identify the certificate given the issuer. |
| 737 | `CABForum Guidelines`_ require entropy in the serial number |
| 738 | to provide protection against hash collision attacks. For more |
| 739 | information on secure random number generation, see |
| 740 | :doc:`/random-numbers`. |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 741 | |
| 742 | :param serial_number: Integer number that will be used by the CA to |
| 743 | identify this certificate (most notably during certificate |
Paul Kehrer | 8b89bcc | 2016-09-03 11:31:43 -0500 | [diff] [blame] | 744 | revocation checking). Users should consider using |
| 745 | :func:`~cryptography.x509.random_serial_number` when possible. |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 746 | |
Ian Cordasco | 0092a0b | 2015-07-18 21:46:41 -0500 | [diff] [blame] | 747 | .. method:: not_valid_before(time) |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 748 | |
| 749 | Sets the certificate's activation time. This is the time from which |
| 750 | clients can start trusting the certificate. It may be different from |
| 751 | the time at which the certificate was created. |
| 752 | |
Ian Cordasco | 17c8900 | 2015-08-02 21:13:59 -0500 | [diff] [blame] | 753 | :param time: The :class:`datetime.datetime` object (in UTC) that marks the |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 754 | activation time for the certificate. The certificate may not be |
| 755 | trusted clients if it is used before this time. |
| 756 | |
Ian Cordasco | 0092a0b | 2015-07-18 21:46:41 -0500 | [diff] [blame] | 757 | .. method:: not_valid_after(time) |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 758 | |
| 759 | Sets the certificate's expiration time. This is the time from which |
| 760 | clients should no longer trust the certificate. The CA's policy will |
| 761 | determine how long the certificate should remain in use. |
| 762 | |
Ian Cordasco | 17c8900 | 2015-08-02 21:13:59 -0500 | [diff] [blame] | 763 | :param time: The :class:`datetime.datetime` object (in UTC) that marks the |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 764 | expiration time for the certificate. The certificate may not be |
| 765 | trusted clients if it is used after this time. |
| 766 | |
Ian Cordasco | 17c8900 | 2015-08-02 21:13:59 -0500 | [diff] [blame] | 767 | .. method:: add_extension(extension, critical) |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 768 | |
| 769 | Adds an X.509 extension to the certificate. |
| 770 | |
Paul Kehrer | 2c145cc | 2015-10-02 11:27:21 -0500 | [diff] [blame] | 771 | :param extension: An extension conforming to the |
| 772 | :class:`~cryptography.x509.ExtensionType` interface. |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 773 | |
Ian Cordasco | 17c8900 | 2015-08-02 21:13:59 -0500 | [diff] [blame] | 774 | :param critical: Set to ``True`` if the extension must be understood and |
| 775 | handled by whoever reads the certificate. |
| 776 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 777 | .. method:: sign(private_key, algorithm, backend=None) |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 778 | |
| 779 | Sign the certificate using the CA's private key. |
| 780 | |
Ian Cordasco | c5e1c25 | 2015-07-31 23:33:35 -0500 | [diff] [blame] | 781 | :param private_key: The |
| 782 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`, |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 783 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey`, |
| 784 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`, |
| 785 | :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey` or |
| 786 | :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PrivateKey` |
Ian Cordasco | c5e1c25 | 2015-07-31 23:33:35 -0500 | [diff] [blame] | 787 | that will be used to sign the certificate. |
| 788 | |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 789 | :param algorithm: The |
| 790 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 791 | will be used to generate the signature. This must be ``None`` if |
| 792 | the ``private_key`` is an |
| 793 | :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey` |
| 794 | or an |
| 795 | :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PrivateKey` |
| 796 | and an instance of a |
| 797 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
| 798 | otherwise. |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 799 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 800 | :param backend: An optional backend used to build the certificate. |
Paul Kehrer | 9add80e | 2015-08-03 17:53:14 +0100 | [diff] [blame] | 801 | Must support the |
| 802 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 803 | interface. |
| 804 | |
Benjamin Peterson | 9ed312b | 2015-10-12 20:51:34 -0700 | [diff] [blame] | 805 | :returns: :class:`~cryptography.x509.Certificate` |
Andre Caron | 9bbfcea | 2015-05-18 20:55:29 -0400 | [diff] [blame] | 806 | |
| 807 | |
Paul Kehrer | 5aadb9c | 2015-03-11 20:48:42 -0500 | [diff] [blame] | 808 | X.509 CSR (Certificate Signing Request) Object |
| 809 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 810 | |
Paul Kehrer | a1a1f23 | 2015-03-15 15:34:35 -0500 | [diff] [blame] | 811 | .. class:: CertificateSigningRequest |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 812 | |
| 813 | .. versionadded:: 0.9 |
| 814 | |
| 815 | .. method:: public_key() |
| 816 | |
Alex Gaynor | 4c2561a | 2015-10-12 23:53:39 -0400 | [diff] [blame] | 817 | The public key associated with the request. |
| 818 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 819 | :returns: One of |
| 820 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`, |
| 821 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`, |
| 822 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`, |
| 823 | :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey` or |
| 824 | :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PublicKey`. |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 825 | |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 826 | .. doctest:: |
| 827 | |
| 828 | >>> from cryptography.hazmat.primitives.asymmetric import rsa |
Paul Kehrer | a1a1f23 | 2015-03-15 15:34:35 -0500 | [diff] [blame] | 829 | >>> public_key = csr.public_key() |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 830 | >>> isinstance(public_key, rsa.RSAPublicKey) |
| 831 | True |
| 832 | |
| 833 | .. attribute:: subject |
| 834 | |
| 835 | :type: :class:`Name` |
| 836 | |
| 837 | The :class:`Name` of the subject. |
| 838 | |
| 839 | .. attribute:: signature_hash_algorithm |
| 840 | |
| 841 | :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
| 842 | |
| 843 | Returns the |
| 844 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 845 | was used in signing this request. Can be ``None`` if signature |
| 846 | did not use separate hash |
| 847 | (:attr:`~cryptography.x509.oid.SignatureAlgorithmOID.ED25519`, |
| 848 | :attr:`~cryptography.x509.oid.SignatureAlgorithmOID.ED448`). |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 849 | |
| 850 | .. doctest:: |
| 851 | |
| 852 | >>> from cryptography.hazmat.primitives import hashes |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 853 | >>> isinstance(csr.signature_hash_algorithm, hashes.SHA256) |
Paul Kehrer | dc480ad | 2015-02-23 12:14:54 -0600 | [diff] [blame] | 854 | True |
| 855 | |
Paul Kehrer | c7b29b8 | 2016-09-01 09:17:21 +0800 | [diff] [blame] | 856 | .. attribute:: signature_algorithm_oid |
| 857 | |
| 858 | .. versionadded:: 1.6 |
| 859 | |
| 860 | :type: :class:`ObjectIdentifier` |
| 861 | |
| 862 | Returns the :class:`ObjectIdentifier` of the signature algorithm used |
| 863 | to sign the request. This will be one of the OIDs from |
| 864 | :class:`~cryptography.x509.oid.SignatureAlgorithmOID`. |
| 865 | |
| 866 | .. doctest:: |
| 867 | |
| 868 | >>> csr.signature_algorithm_oid |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 869 | <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)> |
Paul Kehrer | c7b29b8 | 2016-09-01 09:17:21 +0800 | [diff] [blame] | 870 | |
Paul Kehrer | c4e6194 | 2015-08-01 21:21:13 +0100 | [diff] [blame] | 871 | .. attribute:: extensions |
| 872 | |
| 873 | :type: :class:`Extensions` |
| 874 | |
| 875 | The extensions encoded in the certificate signing request. |
| 876 | |
| 877 | :raises cryptography.x509.DuplicateExtension: If more than one |
Paul Kehrer | 24283d2 | 2015-08-01 21:31:19 +0100 | [diff] [blame] | 878 | extension of the same type is found within the certificate signing request. |
Paul Kehrer | c4e6194 | 2015-08-01 21:21:13 +0100 | [diff] [blame] | 879 | |
Paul Kehrer | c4e6194 | 2015-08-01 21:21:13 +0100 | [diff] [blame] | 880 | :raises cryptography.x509.UnsupportedGeneralNameType: If an extension |
| 881 | contains a general name that is not supported. |
| 882 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 883 | .. method:: get_attribute_for_oid(oid) |
Paul Kehrer | c4e6194 | 2015-08-01 21:21:13 +0100 | [diff] [blame] | 884 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 885 | .. versionadded:: 3.0 |
| 886 | |
| 887 | :param oid: An :class:`ObjectIdentifier` instance. |
| 888 | |
| 889 | :returns: The bytes value of the attribute or an exception if not |
| 890 | found. |
| 891 | |
| 892 | :raises cryptography.x509.AttributeNotFound: If the request does |
| 893 | not have the attribute requested. |
Paul Kehrer | c4e6194 | 2015-08-01 21:21:13 +0100 | [diff] [blame] | 894 | |
Andre Caron | 476c5df | 2015-05-18 10:23:28 -0400 | [diff] [blame] | 895 | .. method:: public_bytes(encoding) |
| 896 | |
Alex Gaynor | d0b376b | 2015-07-05 13:58:12 -0400 | [diff] [blame] | 897 | .. versionadded:: 1.0 |
| 898 | |
Andre Caron | 476c5df | 2015-05-18 10:23:28 -0400 | [diff] [blame] | 899 | :param encoding: The |
| 900 | :class:`~cryptography.hazmat.primitives.serialization.Encoding` |
| 901 | that will be used to serialize the certificate request. |
| 902 | |
| 903 | :return bytes: The data that can be written to a file or sent |
| 904 | over the network to be signed by the certificate |
| 905 | authority. |
| 906 | |
Paul Kehrer | ab20939 | 2015-12-01 14:50:31 -0600 | [diff] [blame] | 907 | .. attribute:: signature |
| 908 | |
| 909 | .. versionadded:: 1.2 |
| 910 | |
| 911 | :type: bytes |
| 912 | |
| 913 | The bytes of the certificate signing request's signature. |
| 914 | |
| 915 | .. attribute:: tbs_certrequest_bytes |
| 916 | |
| 917 | .. versionadded:: 1.2 |
| 918 | |
| 919 | :type: bytes |
| 920 | |
| 921 | The DER encoded bytes payload (as defined by :rfc:`2986`) that is |
| 922 | hashed and then signed by the private key (corresponding to the public |
| 923 | key embedded in the CSR). This data may be used to validate the CSR |
| 924 | signature. |
| 925 | |
Joern Heissler | fbda8ce | 2016-01-18 00:24:44 +0100 | [diff] [blame] | 926 | .. attribute:: is_signature_valid |
Joern Heissler | 1bd77e2 | 2016-01-13 22:51:37 +0100 | [diff] [blame] | 927 | |
| 928 | .. versionadded:: 1.3 |
| 929 | |
Joern Heissler | fbda8ce | 2016-01-18 00:24:44 +0100 | [diff] [blame] | 930 | Returns True if the CSR signature is correct, False otherwise. |
Joern Heissler | 1bd77e2 | 2016-01-13 22:51:37 +0100 | [diff] [blame] | 931 | |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 932 | X.509 Certificate Revocation List Builder |
| 933 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 934 | |
| 935 | .. class:: CertificateRevocationListBuilder |
| 936 | |
| 937 | .. versionadded:: 1.2 |
| 938 | |
| 939 | .. doctest:: |
| 940 | |
| 941 | >>> from cryptography import x509 |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 942 | >>> from cryptography.hazmat.primitives import hashes |
| 943 | >>> from cryptography.hazmat.primitives.asymmetric import rsa |
| 944 | >>> from cryptography.x509.oid import NameOID |
| 945 | >>> import datetime |
| 946 | >>> one_day = datetime.timedelta(1, 0, 0) |
| 947 | >>> private_key = rsa.generate_private_key( |
| 948 | ... public_exponent=65537, |
| 949 | ... key_size=2048, |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 950 | ... ) |
| 951 | >>> builder = x509.CertificateRevocationListBuilder() |
| 952 | >>> builder = builder.issuer_name(x509.Name([ |
| 953 | ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io CA'), |
| 954 | ... ])) |
| 955 | >>> builder = builder.last_update(datetime.datetime.today()) |
| 956 | >>> builder = builder.next_update(datetime.datetime.today() + one_day) |
Paul Kehrer | 4c7fd5f | 2015-12-25 13:40:55 -0600 | [diff] [blame] | 957 | >>> revoked_cert = x509.RevokedCertificateBuilder().serial_number( |
| 958 | ... 333 |
| 959 | ... ).revocation_date( |
| 960 | ... datetime.datetime.today() |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 961 | ... ).build() |
Paul Kehrer | 4c7fd5f | 2015-12-25 13:40:55 -0600 | [diff] [blame] | 962 | >>> builder = builder.add_revoked_certificate(revoked_cert) |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 963 | >>> crl = builder.sign( |
| 964 | ... private_key=private_key, algorithm=hashes.SHA256(), |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 965 | ... ) |
Paul Kehrer | 4c7fd5f | 2015-12-25 13:40:55 -0600 | [diff] [blame] | 966 | >>> len(crl) |
| 967 | 1 |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 968 | |
| 969 | .. method:: issuer_name(name) |
| 970 | |
| 971 | Sets the issuer's distinguished name. |
| 972 | |
| 973 | :param name: The :class:`~cryptography.x509.Name` that describes the |
| 974 | issuer (CA). |
| 975 | |
| 976 | .. method:: last_update(time) |
| 977 | |
Paul Kehrer | 0325b9d | 2015-12-24 19:19:59 -0600 | [diff] [blame] | 978 | Sets this CRL's activation time. This is the time from which |
| 979 | clients can start trusting this CRL. It may be different from |
| 980 | 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] | 981 | ``thisUpdate`` time. |
| 982 | |
Paul Kehrer | 0325b9d | 2015-12-24 19:19:59 -0600 | [diff] [blame] | 983 | :param time: The :class:`datetime.datetime` object (in UTC) that marks |
| 984 | the activation time for this CRL. The CRL may not be trusted if it |
| 985 | is used before this time. |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 986 | |
| 987 | .. method:: next_update(time) |
| 988 | |
Paul Kehrer | 0325b9d | 2015-12-24 19:19:59 -0600 | [diff] [blame] | 989 | Sets this CRL's next update time. This is the time by which |
| 990 | a new CRL will be issued. The CA is allowed to issue a new CRL before |
| 991 | this date, however clients are not required to check for it. |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 992 | |
Paul Kehrer | 0325b9d | 2015-12-24 19:19:59 -0600 | [diff] [blame] | 993 | :param time: The :class:`datetime.datetime` object (in UTC) that marks |
| 994 | the next update time for this CRL. |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 995 | |
Paul Kehrer | 426b48d | 2015-12-24 20:50:43 -0600 | [diff] [blame] | 996 | .. method:: add_extension(extension, critical) |
| 997 | |
| 998 | Adds an X.509 extension to this CRL. |
| 999 | |
| 1000 | :param extension: An extension with the |
| 1001 | :class:`~cryptography.x509.ExtensionType` interface. |
| 1002 | |
| 1003 | :param critical: Set to ``True`` if the extension must be understood and |
| 1004 | handled by whoever reads the CRL. |
| 1005 | |
Paul Kehrer | 4c7fd5f | 2015-12-25 13:40:55 -0600 | [diff] [blame] | 1006 | .. method:: add_revoked_certificate(revoked_certificate) |
| 1007 | |
| 1008 | Adds a revoked certificate to this CRL. |
| 1009 | |
| 1010 | :param revoked_certificate: An instance of |
| 1011 | :class:`~cryptography.x509.RevokedCertificate`. These can be |
| 1012 | obtained from an existing CRL or created with |
| 1013 | :class:`~cryptography.x509.RevokedCertificateBuilder`. |
| 1014 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1015 | .. method:: sign(private_key, algorithm, backend=None) |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 1016 | |
Paul Kehrer | 0325b9d | 2015-12-24 19:19:59 -0600 | [diff] [blame] | 1017 | Sign this CRL using the CA's private key. |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 1018 | |
| 1019 | :param private_key: The |
| 1020 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`, |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1021 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey`, |
| 1022 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`, |
| 1023 | :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey` or |
| 1024 | :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PrivateKey` |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 1025 | that will be used to sign the certificate. |
| 1026 | |
| 1027 | :param algorithm: The |
| 1028 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that |
| 1029 | will be used to generate the signature. |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1030 | This must be ``None`` if the ``private_key`` is an |
| 1031 | :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey` |
| 1032 | or an |
| 1033 | :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PrivateKey` |
| 1034 | and an instance of a |
| 1035 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
| 1036 | otherwise. |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 1037 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1038 | :param backend: An optional backend used to build the CRL. |
Paul Kehrer | bfac2d1 | 2015-12-19 23:32:08 -0600 | [diff] [blame] | 1039 | Must support the |
| 1040 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 1041 | interface. |
| 1042 | |
| 1043 | :returns: :class:`~cryptography.x509.CertificateRevocationList` |
| 1044 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 1045 | X.509 Revoked Certificate Object |
Erik Trauschke | c5a8d17 | 2015-05-28 10:24:25 -0700 | [diff] [blame] | 1046 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 1047 | |
| 1048 | .. class:: RevokedCertificate |
| 1049 | |
| 1050 | .. versionadded:: 1.0 |
| 1051 | |
| 1052 | .. attribute:: serial_number |
| 1053 | |
| 1054 | :type: :class:`int` |
| 1055 | |
| 1056 | An integer representing the serial number of the revoked certificate. |
| 1057 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 1058 | .. doctest:: |
| 1059 | |
Erik Trauschke | 3cdabaf | 2015-10-13 09:42:53 -0700 | [diff] [blame] | 1060 | >>> revoked_certificate.serial_number |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 1061 | 0 |
| 1062 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 1063 | .. attribute:: revocation_date |
| 1064 | |
| 1065 | :type: :class:`datetime.datetime` |
| 1066 | |
| 1067 | A naïve datetime representing the date this certificates was revoked. |
| 1068 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 1069 | .. doctest:: |
| 1070 | |
Erik Trauschke | 77f5a25 | 2015-10-14 08:06:38 -0700 | [diff] [blame] | 1071 | >>> revoked_certificate.revocation_date |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 1072 | datetime.datetime(2015, 1, 1, 0, 0) |
| 1073 | |
Erik Trauschke | 2dcce90 | 2015-05-14 16:12:24 -0700 | [diff] [blame] | 1074 | .. attribute:: extensions |
| 1075 | |
| 1076 | :type: :class:`Extensions` |
| 1077 | |
| 1078 | The extensions encoded in the revoked certificate. |
Andre Caron | 476c5df | 2015-05-18 10:23:28 -0400 | [diff] [blame] | 1079 | |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 1080 | .. doctest:: |
| 1081 | |
Erik Trauschke | 77f5a25 | 2015-10-14 08:06:38 -0700 | [diff] [blame] | 1082 | >>> for ext in revoked_certificate.extensions: |
Erik Trauschke | dc57040 | 2015-09-24 20:24:28 -0700 | [diff] [blame] | 1083 | ... print(ext) |
Paul Kehrer | 23c0bbc | 2015-12-25 22:35:19 -0600 | [diff] [blame] | 1084 | <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] | 1085 | <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] | 1086 | |
Paul Kehrer | c33ffd7 | 2015-12-25 10:59:22 -0600 | [diff] [blame] | 1087 | X.509 Revoked Certificate Builder |
| 1088 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1089 | |
| 1090 | .. class:: RevokedCertificateBuilder |
| 1091 | |
| 1092 | This class is used to create :class:`~cryptography.x509.RevokedCertificate` |
| 1093 | objects that can be used with the |
| 1094 | :class:`~cryptography.x509.CertificateRevocationListBuilder`. |
| 1095 | |
| 1096 | .. versionadded:: 1.2 |
| 1097 | |
| 1098 | .. doctest:: |
| 1099 | |
| 1100 | >>> from cryptography import x509 |
Paul Kehrer | c33ffd7 | 2015-12-25 10:59:22 -0600 | [diff] [blame] | 1101 | >>> import datetime |
| 1102 | >>> builder = x509.RevokedCertificateBuilder() |
| 1103 | >>> builder = builder.revocation_date(datetime.datetime.today()) |
| 1104 | >>> builder = builder.serial_number(3333) |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1105 | >>> revoked_certificate = builder.build() |
Paul Kehrer | c33ffd7 | 2015-12-25 10:59:22 -0600 | [diff] [blame] | 1106 | >>> isinstance(revoked_certificate, x509.RevokedCertificate) |
| 1107 | True |
| 1108 | |
| 1109 | .. method:: serial_number(serial_number) |
| 1110 | |
| 1111 | Sets the revoked certificate's serial number. |
| 1112 | |
| 1113 | :param serial_number: Integer number that is used to identify the |
| 1114 | revoked certificate. |
| 1115 | |
| 1116 | .. method:: revocation_date(time) |
| 1117 | |
| 1118 | Sets the certificate's revocation date. |
| 1119 | |
| 1120 | :param time: The :class:`datetime.datetime` object (in UTC) that marks the |
| 1121 | revocation time for the certificate. |
| 1122 | |
Paul Kehrer | e5f152b | 2015-12-25 23:55:47 -0600 | [diff] [blame] | 1123 | .. method:: add_extension(extension, critical) |
| 1124 | |
| 1125 | Adds an X.509 extension to this revoked certificate. |
| 1126 | |
| 1127 | :param extension: An instance of one of the |
| 1128 | :ref:`CRL entry extensions <crl_entry_extensions>`. |
| 1129 | |
| 1130 | :param critical: Set to ``True`` if the extension must be understood and |
| 1131 | handled. |
| 1132 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1133 | .. method:: build(backend=None) |
Paul Kehrer | c33ffd7 | 2015-12-25 10:59:22 -0600 | [diff] [blame] | 1134 | |
| 1135 | Create a revoked certificate object using the provided backend. |
| 1136 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1137 | :param backend: An optional backend used to build the revoked |
Paul Kehrer | c33ffd7 | 2015-12-25 10:59:22 -0600 | [diff] [blame] | 1138 | certificate. Must support the |
| 1139 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 1140 | interface. |
| 1141 | |
| 1142 | :returns: :class:`~cryptography.x509.RevokedCertificate` |
| 1143 | |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1144 | X.509 CSR (Certificate Signing Request) Builder Object |
| 1145 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1146 | |
| 1147 | .. class:: CertificateSigningRequestBuilder |
| 1148 | |
Andre Caron | d259ee5 | 2015-06-02 23:47:11 -0400 | [diff] [blame] | 1149 | .. versionadded:: 1.0 |
| 1150 | |
| 1151 | .. doctest:: |
| 1152 | |
| 1153 | >>> from cryptography import x509 |
Andre Caron | d259ee5 | 2015-06-02 23:47:11 -0400 | [diff] [blame] | 1154 | >>> from cryptography.hazmat.primitives import hashes |
| 1155 | >>> from cryptography.hazmat.primitives.asymmetric import rsa |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1156 | >>> from cryptography.x509.oid import AttributeOID, NameOID |
Andre Caron | d259ee5 | 2015-06-02 23:47:11 -0400 | [diff] [blame] | 1157 | >>> private_key = rsa.generate_private_key( |
| 1158 | ... public_exponent=65537, |
| 1159 | ... key_size=2048, |
Andre Caron | d259ee5 | 2015-06-02 23:47:11 -0400 | [diff] [blame] | 1160 | ... ) |
| 1161 | >>> builder = x509.CertificateSigningRequestBuilder() |
Andre Caron | a9a5117 | 2015-06-06 20:18:44 -0400 | [diff] [blame] | 1162 | >>> builder = builder.subject_name(x509.Name([ |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1163 | ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'), |
Andre Caron | d259ee5 | 2015-06-02 23:47:11 -0400 | [diff] [blame] | 1164 | ... ])) |
Ian Cordasco | f06b6be | 2015-06-21 10:09:18 -0500 | [diff] [blame] | 1165 | >>> builder = builder.add_extension( |
Ian Cordasco | 0112b02 | 2015-06-16 17:51:18 -0500 | [diff] [blame] | 1166 | ... x509.BasicConstraints(ca=False, path_length=None), critical=True, |
Andre Caron | 472fd69 | 2015-06-06 20:04:44 -0400 | [diff] [blame] | 1167 | ... ) |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1168 | >>> builder = builder.add_attribute( |
| 1169 | ... AttributeOID.CHALLENGE_PASSWORD, b"changeit" |
| 1170 | ... ) |
Andre Caron | d259ee5 | 2015-06-02 23:47:11 -0400 | [diff] [blame] | 1171 | >>> request = builder.sign( |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1172 | ... private_key, hashes.SHA256() |
Andre Caron | d259ee5 | 2015-06-02 23:47:11 -0400 | [diff] [blame] | 1173 | ... ) |
| 1174 | >>> isinstance(request, x509.CertificateSigningRequest) |
| 1175 | True |
| 1176 | |
Andre Caron | a9a5117 | 2015-06-06 20:18:44 -0400 | [diff] [blame] | 1177 | .. method:: subject_name(name) |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1178 | |
Andre Caron | 341ff85 | 2015-06-06 20:14:31 -0400 | [diff] [blame] | 1179 | :param name: The :class:`~cryptography.x509.Name` of the certificate |
| 1180 | subject. |
| 1181 | :returns: A new |
| 1182 | :class:`~cryptography.x509.CertificateSigningRequestBuilder`. |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1183 | |
Ian Cordasco | f06b6be | 2015-06-21 10:09:18 -0500 | [diff] [blame] | 1184 | .. method:: add_extension(extension, critical) |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1185 | |
Paul Kehrer | 2c145cc | 2015-10-02 11:27:21 -0500 | [diff] [blame] | 1186 | :param extension: An extension conforming to the |
| 1187 | :class:`~cryptography.x509.ExtensionType` interface. |
Andre Caron | 472fd69 | 2015-06-06 20:04:44 -0400 | [diff] [blame] | 1188 | :param critical: Set to `True` if the extension must be understood and |
| 1189 | handled by whoever reads the certificate. |
Andre Caron | 341ff85 | 2015-06-06 20:14:31 -0400 | [diff] [blame] | 1190 | :returns: A new |
| 1191 | :class:`~cryptography.x509.CertificateSigningRequestBuilder`. |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1192 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1193 | .. method:: add_attribute(oid, value) |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1194 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1195 | .. versionadded:: 3.0 |
| 1196 | |
| 1197 | :param oid: An :class:`ObjectIdentifier` instance. |
| 1198 | :param value: The value of the attribute. |
| 1199 | :type value: bytes |
| 1200 | :returns: A new |
| 1201 | :class:`~cryptography.x509.CertificateSigningRequestBuilder`. |
| 1202 | |
| 1203 | .. method:: sign(private_key, algorithm, backend=None) |
| 1204 | |
| 1205 | :param backend: An optional backend used to sign the request. |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1206 | Must support the |
| 1207 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 1208 | interface. |
| 1209 | |
| 1210 | :param private_key: The |
Andre Caron | 24f9bf4 | 2015-06-06 20:14:54 -0400 | [diff] [blame] | 1211 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`, |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1212 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey`, |
| 1213 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`, |
| 1214 | :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey` or |
| 1215 | :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PrivateKey` |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1216 | that will be used to sign the request. When the request is |
| 1217 | signed by a certificate authority, the private key's associated |
| 1218 | public key will be stored in the resulting certificate. |
| 1219 | |
| 1220 | :param algorithm: The |
| 1221 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
| 1222 | that will be used to generate the request signature. |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1223 | This must be ``None`` if the ``private_key`` is an |
| 1224 | :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey` |
| 1225 | or an |
| 1226 | :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PrivateKey` |
| 1227 | and an instance of a |
| 1228 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
| 1229 | otherwise. |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1230 | |
Andre Caron | 341ff85 | 2015-06-06 20:14:31 -0400 | [diff] [blame] | 1231 | :returns: A new |
| 1232 | :class:`~cryptography.x509.CertificateSigningRequest`. |
Andre Caron | 0ef595f | 2015-05-18 13:53:43 -0400 | [diff] [blame] | 1233 | |
| 1234 | |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 1235 | .. class:: Name |
| 1236 | |
| 1237 | .. versionadded:: 0.8 |
| 1238 | |
Paul Kehrer | 53d8d49 | 2015-02-13 18:47:30 -0600 | [diff] [blame] | 1239 | 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] | 1240 | 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] | 1241 | obtain the specific type you want. Names are sometimes represented as a |
Paul Kehrer | 53d8d49 | 2015-02-13 18:47:30 -0600 | [diff] [blame] | 1242 | slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or |
Marti Raudsepp | 8241557 | 2018-12-18 01:26:40 +0200 | [diff] [blame] | 1243 | ``CN=mydomain.com,O=My Org,C=US``). |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 1244 | |
Fraser Tweedale | 01ee6f5 | 2016-11-12 01:28:56 +1000 | [diff] [blame] | 1245 | Technically, a Name is a list of *sets* of attributes, called *Relative |
| 1246 | Distinguished Names* or *RDNs*, although multi-valued RDNs are rarely |
| 1247 | encountered. The iteration order of values within a multi-valued RDN is |
Marti Raudsepp | 9e1873a | 2018-07-09 16:11:18 +0300 | [diff] [blame] | 1248 | preserved. If you need to handle multi-valued RDNs, the ``rdns`` property |
Fraser Tweedale | 01ee6f5 | 2016-11-12 01:28:56 +1000 | [diff] [blame] | 1249 | gives access to an ordered list of :class:`RelativeDistinguishedName` |
| 1250 | objects. |
| 1251 | |
| 1252 | A Name can be initialized with an iterable of :class:`NameAttribute` (the |
| 1253 | common case where each RDN has a single attribute) or an iterable of |
| 1254 | :class:`RelativeDistinguishedName` objects (in the rare case of |
| 1255 | multi-valued RDNs). |
| 1256 | |
Paul Kehrer | 53d8d49 | 2015-02-13 18:47:30 -0600 | [diff] [blame] | 1257 | .. doctest:: |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 1258 | |
Paul Kehrer | 8b21a4a | 2015-02-14 07:56:36 -0600 | [diff] [blame] | 1259 | >>> len(cert.subject) |
Paul Kehrer | 53d8d49 | 2015-02-13 18:47:30 -0600 | [diff] [blame] | 1260 | 3 |
Paul Kehrer | 8b21a4a | 2015-02-14 07:56:36 -0600 | [diff] [blame] | 1261 | >>> for attribute in cert.subject: |
| 1262 | ... print(attribute) |
Paul Kehrer | 056c9dd | 2018-05-12 15:17:06 -0400 | [diff] [blame] | 1263 | <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')> |
| 1264 | <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value='Test Certificates 2011')> |
| 1265 | <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='Good CA')> |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 1266 | |
Fraser Tweedale | 01ee6f5 | 2016-11-12 01:28:56 +1000 | [diff] [blame] | 1267 | .. attribute:: rdns |
| 1268 | |
| 1269 | .. versionadded:: 1.6 |
| 1270 | |
| 1271 | :type: list of :class:`RelativeDistinguishedName` |
| 1272 | |
Paul Kehrer | e901d64 | 2015-02-11 18:50:58 -0600 | [diff] [blame] | 1273 | .. method:: get_attributes_for_oid(oid) |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 1274 | |
Paul Kehrer | e901d64 | 2015-02-11 18:50:58 -0600 | [diff] [blame] | 1275 | :param oid: An :class:`ObjectIdentifier` instance. |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 1276 | |
Paul Kehrer | e901d64 | 2015-02-11 18:50:58 -0600 | [diff] [blame] | 1277 | :returns: A list of :class:`NameAttribute` instances that match the |
| 1278 | OID provided. If nothing matches an empty list will be returned. |
Paul Kehrer | 719d536 | 2015-01-01 20:03:52 -0600 | [diff] [blame] | 1279 | |
| 1280 | .. doctest:: |
| 1281 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1282 | >>> cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME) |
Paul Kehrer | 056c9dd | 2018-05-12 15:17:06 -0400 | [diff] [blame] | 1283 | [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='Good CA')>] |
Paul Kehrer | b2de948 | 2014-12-11 14:54:48 -0600 | [diff] [blame] | 1284 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1285 | .. method:: public_bytes(backend=None) |
Paul Kehrer | 3a15b03 | 2016-11-13 14:30:11 -0800 | [diff] [blame] | 1286 | |
| 1287 | .. versionadded:: 1.6 |
| 1288 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1289 | :param backend: An optional backend supporting the |
Paul Kehrer | 3a15b03 | 2016-11-13 14:30:11 -0800 | [diff] [blame] | 1290 | :class:`~cryptography.hazmat.backends.interfaces.X509Backend` |
| 1291 | interface. |
| 1292 | |
| 1293 | :return bytes: The DER encoded name. |
| 1294 | |
Marti Raudsepp | c3d38b5 | 2018-12-08 03:26:07 +0200 | [diff] [blame] | 1295 | .. method:: rfc4514_string() |
| 1296 | |
| 1297 | .. versionadded:: 2.5 |
| 1298 | |
Alex Gaynor | e5463cc | 2019-01-18 15:19:34 -0600 | [diff] [blame] | 1299 | :return str: Format the given name as a :rfc:`4514` Distinguished Name |
Marti Raudsepp | 8241557 | 2018-12-18 01:26:40 +0200 | [diff] [blame] | 1300 | string, for example ``CN=mydomain.com,O=My Org,C=US``. |
Marti Raudsepp | c3d38b5 | 2018-12-08 03:26:07 +0200 | [diff] [blame] | 1301 | |
| 1302 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 1303 | .. class:: Version |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 1304 | |
| 1305 | .. versionadded:: 0.7 |
| 1306 | |
| 1307 | An enumeration for X.509 versions. |
| 1308 | |
| 1309 | .. attribute:: v1 |
| 1310 | |
| 1311 | For version 1 X.509 certificates. |
| 1312 | |
| 1313 | .. attribute:: v3 |
| 1314 | |
| 1315 | For version 3 X.509 certificates. |
| 1316 | |
Paul Kehrer | 806bfb2 | 2015-02-02 17:05:24 -0600 | [diff] [blame] | 1317 | .. class:: NameAttribute |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 1318 | |
| 1319 | .. versionadded:: 0.8 |
| 1320 | |
Fraser Tweedale | 01ee6f5 | 2016-11-12 01:28:56 +1000 | [diff] [blame] | 1321 | An X.509 name consists of a list of :class:`RelativeDistinguishedName` |
| 1322 | instances, which consist of a set of :class:`NameAttribute` instances. |
Paul Kehrer | 5b0a8d6 | 2015-01-30 20:05:55 -0600 | [diff] [blame] | 1323 | |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 1324 | .. attribute:: oid |
| 1325 | |
| 1326 | :type: :class:`ObjectIdentifier` |
| 1327 | |
| 1328 | The attribute OID. |
| 1329 | |
| 1330 | .. attribute:: value |
| 1331 | |
Paul Kehrer | d5852cb | 2015-01-30 08:25:23 -0600 | [diff] [blame] | 1332 | :type: :term:`text` |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 1333 | |
| 1334 | The value of the attribute. |
| 1335 | |
Marti Raudsepp | c3d38b5 | 2018-12-08 03:26:07 +0200 | [diff] [blame] | 1336 | .. method:: rfc4514_string() |
| 1337 | |
| 1338 | .. versionadded:: 2.5 |
| 1339 | |
Alex Gaynor | e5463cc | 2019-01-18 15:19:34 -0600 | [diff] [blame] | 1340 | :return str: Format the given attribute as a :rfc:`4514` Distinguished |
Marti Raudsepp | c3d38b5 | 2018-12-08 03:26:07 +0200 | [diff] [blame] | 1341 | Name string. |
| 1342 | |
Fraser Tweedale | 02467dd | 2016-11-07 15:54:04 +1000 | [diff] [blame] | 1343 | |
| 1344 | .. class:: RelativeDistinguishedName(attributes) |
| 1345 | |
| 1346 | .. versionadded:: 1.6 |
| 1347 | |
| 1348 | A relative distinguished name is a non-empty set of name attributes. The |
Marti Raudsepp | 9e1873a | 2018-07-09 16:11:18 +0300 | [diff] [blame] | 1349 | object is iterable to get every attribute, preserving the original order. |
| 1350 | Passing duplicate attributes to the constructor raises ``ValueError``. |
Fraser Tweedale | 02467dd | 2016-11-07 15:54:04 +1000 | [diff] [blame] | 1351 | |
| 1352 | .. method:: get_attributes_for_oid(oid) |
| 1353 | |
| 1354 | :param oid: An :class:`ObjectIdentifier` instance. |
| 1355 | |
| 1356 | :returns: A list of :class:`NameAttribute` instances that match the OID |
| 1357 | provided. The list should contain zero or one values. |
| 1358 | |
Marti Raudsepp | c3d38b5 | 2018-12-08 03:26:07 +0200 | [diff] [blame] | 1359 | .. method:: rfc4514_string() |
| 1360 | |
| 1361 | .. versionadded:: 2.5 |
| 1362 | |
Alex Gaynor | e5463cc | 2019-01-18 15:19:34 -0600 | [diff] [blame] | 1363 | :return str: Format the given RDN set as a :rfc:`4514` Distinguished |
Marti Raudsepp | c3d38b5 | 2018-12-08 03:26:07 +0200 | [diff] [blame] | 1364 | Name string. |
| 1365 | |
Fraser Tweedale | 02467dd | 2016-11-07 15:54:04 +1000 | [diff] [blame] | 1366 | |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 1367 | .. class:: ObjectIdentifier |
| 1368 | |
| 1369 | .. versionadded:: 0.8 |
| 1370 | |
Paul Kehrer | 5b0a8d6 | 2015-01-30 20:05:55 -0600 | [diff] [blame] | 1371 | Object identifiers (frequently seen abbreviated as OID) identify the type |
Paul Kehrer | 806bfb2 | 2015-02-02 17:05:24 -0600 | [diff] [blame] | 1372 | of a value (see: :class:`NameAttribute`). |
Paul Kehrer | 5b0a8d6 | 2015-01-30 20:05:55 -0600 | [diff] [blame] | 1373 | |
Paul Kehrer | d44f9a6 | 2015-02-04 14:47:34 -0600 | [diff] [blame] | 1374 | .. attribute:: dotted_string |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 1375 | |
| 1376 | :type: :class:`str` |
| 1377 | |
Paul Kehrer | fedf4f4 | 2015-02-06 11:22:07 -0600 | [diff] [blame] | 1378 | 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] | 1379 | |
Marti Raudsepp | c3d38b5 | 2018-12-08 03:26:07 +0200 | [diff] [blame] | 1380 | |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1381 | .. _general_name_classes: |
| 1382 | |
| 1383 | General Name Classes |
| 1384 | ~~~~~~~~~~~~~~~~~~~~ |
| 1385 | |
| 1386 | .. class:: GeneralName |
| 1387 | |
| 1388 | .. versionadded:: 0.9 |
| 1389 | |
| 1390 | This is the generic interface that all the following classes are registered |
| 1391 | against. |
| 1392 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1393 | .. class:: RFC822Name(value) |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1394 | |
| 1395 | .. versionadded:: 0.9 |
| 1396 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1397 | .. versionchanged:: 3.1 |
Paul Kehrer | 3e15ca5 | 2017-08-01 21:21:19 -0500 | [diff] [blame] | 1398 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1399 | :term:`U-label` support has been removed. Encode them to |
| 1400 | :term:`A-label` before use. |
Paul Kehrer | 1b86dc5 | 2017-09-20 23:42:34 +0800 | [diff] [blame] | 1401 | |
| 1402 | This corresponds to an email address. For example, ``user@example.com``. |
| 1403 | |
Paul Kehrer | e885bd6 | 2017-10-11 20:29:23 +0800 | [diff] [blame] | 1404 | :param value: The email address. If the address contains an |
Paul Kehrer | 1b86dc5 | 2017-09-20 23:42:34 +0800 | [diff] [blame] | 1405 | internationalized domain name then it must be encoded to an |
Paul Kehrer | e885bd6 | 2017-10-11 20:29:23 +0800 | [diff] [blame] | 1406 | :term:`A-label` string before being passed. |
Paul Kehrer | 1b86dc5 | 2017-09-20 23:42:34 +0800 | [diff] [blame] | 1407 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1408 | :raises ValueError: If the provided string is not an :term:`A-label`. |
| 1409 | |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1410 | .. attribute:: value |
| 1411 | |
| 1412 | :type: :term:`text` |
| 1413 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1414 | .. class:: DNSName(value) |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1415 | |
| 1416 | .. versionadded:: 0.9 |
| 1417 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1418 | .. versionchanged:: 3.1 |
Paul Kehrer | 1b86dc5 | 2017-09-20 23:42:34 +0800 | [diff] [blame] | 1419 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1420 | :term:`U-label` support has been removed. Encode them to |
| 1421 | :term:`A-label` before use. |
Paul Kehrer | 1b86dc5 | 2017-09-20 23:42:34 +0800 | [diff] [blame] | 1422 | |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1423 | This corresponds to a domain name. For example, ``cryptography.io``. |
| 1424 | |
Paul Kehrer | e885bd6 | 2017-10-11 20:29:23 +0800 | [diff] [blame] | 1425 | :param value: The domain name. If it is an internationalized domain |
| 1426 | name then it must be encoded to an :term:`A-label` string before being |
| 1427 | passed. |
Paul Kehrer | 1b86dc5 | 2017-09-20 23:42:34 +0800 | [diff] [blame] | 1428 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1429 | :raises ValueError: If the provided string is not an :term:`A-label`. |
| 1430 | |
Paul Kehrer | e885bd6 | 2017-10-11 20:29:23 +0800 | [diff] [blame] | 1431 | :type: :term:`text` |
Paul Kehrer | 1b86dc5 | 2017-09-20 23:42:34 +0800 | [diff] [blame] | 1432 | |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1433 | .. attribute:: value |
| 1434 | |
| 1435 | :type: :term:`text` |
| 1436 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1437 | .. class:: DirectoryName(value) |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1438 | |
| 1439 | .. versionadded:: 0.9 |
| 1440 | |
| 1441 | This corresponds to a directory name. |
| 1442 | |
| 1443 | .. attribute:: value |
| 1444 | |
| 1445 | :type: :class:`Name` |
| 1446 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1447 | .. class:: UniformResourceIdentifier(value) |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1448 | |
| 1449 | .. versionadded:: 0.9 |
| 1450 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1451 | .. versionchanged:: 3.1 |
Paul Kehrer | b8ef82e | 2015-04-22 16:04:24 -0500 | [diff] [blame] | 1452 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1453 | :term:`U-label` support has been removed. Encode them to |
| 1454 | :term:`A-label` before use. |
Paul Kehrer | 1b86dc5 | 2017-09-20 23:42:34 +0800 | [diff] [blame] | 1455 | |
| 1456 | This corresponds to a uniform resource identifier. For example, |
| 1457 | ``https://cryptography.io``. |
| 1458 | |
Paul Kehrer | e885bd6 | 2017-10-11 20:29:23 +0800 | [diff] [blame] | 1459 | :param value: The URI. If it contains an internationalized domain |
| 1460 | name then it must be encoded to an :term:`A-label` string before |
| 1461 | being passed. |
Paul Kehrer | 1b86dc5 | 2017-09-20 23:42:34 +0800 | [diff] [blame] | 1462 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1463 | :raises ValueError: If the provided string is not an :term:`A-label`. |
| 1464 | |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1465 | .. attribute:: value |
| 1466 | |
| 1467 | :type: :term:`text` |
| 1468 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1469 | .. class:: IPAddress(value) |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1470 | |
| 1471 | .. versionadded:: 0.9 |
| 1472 | |
| 1473 | This corresponds to an IP address. |
| 1474 | |
| 1475 | .. attribute:: value |
| 1476 | |
Paul Kehrer | eb17793 | 2015-05-17 18:33:33 -0700 | [diff] [blame] | 1477 | :type: :class:`~ipaddress.IPv4Address`, |
| 1478 | :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`, |
| 1479 | or :class:`~ipaddress.IPv6Network`. |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1480 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1481 | .. class:: RegisteredID(value) |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1482 | |
| 1483 | .. versionadded:: 0.9 |
| 1484 | |
| 1485 | This corresponds to a registered ID. |
| 1486 | |
| 1487 | .. attribute:: value |
| 1488 | |
| 1489 | :type: :class:`ObjectIdentifier` |
| 1490 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1491 | .. class:: OtherName(type_id, value) |
Joshua Tauberer | 2ee5e3c | 2015-07-04 20:09:46 +0000 | [diff] [blame] | 1492 | |
| 1493 | .. versionadded:: 1.0 |
| 1494 | |
Joshua Tauberer | 18b6fc8 | 2015-07-05 21:44:51 +0000 | [diff] [blame] | 1495 | 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] | 1496 | |
| 1497 | .. attribute:: type_id |
| 1498 | |
| 1499 | :type: :class:`ObjectIdentifier` |
| 1500 | |
| 1501 | .. attribute:: value |
| 1502 | |
Paul Kehrer | edfedc1 | 2018-09-14 18:24:20 -0400 | [diff] [blame] | 1503 | :type: bytes |
Joshua Tauberer | 2ee5e3c | 2015-07-04 20:09:46 +0000 | [diff] [blame] | 1504 | |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1505 | X.509 Extensions |
| 1506 | ~~~~~~~~~~~~~~~~ |
| 1507 | |
Paul Kehrer | fbb7ac8 | 2015-03-16 19:26:29 -0500 | [diff] [blame] | 1508 | .. class:: Extensions |
| 1509 | |
| 1510 | .. versionadded:: 0.9 |
| 1511 | |
| 1512 | An X.509 Extensions instance is an ordered list of extensions. The object |
| 1513 | is iterable to get every extension. |
| 1514 | |
Paul Kehrer | fa56a23 | 2015-03-17 13:14:03 -0500 | [diff] [blame] | 1515 | .. method:: get_extension_for_oid(oid) |
| 1516 | |
| 1517 | :param oid: An :class:`ObjectIdentifier` instance. |
| 1518 | |
| 1519 | :returns: An instance of the extension class. |
| 1520 | |
| 1521 | :raises cryptography.x509.ExtensionNotFound: If the certificate does |
| 1522 | not have the extension requested. |
| 1523 | |
Paul Kehrer | fa56a23 | 2015-03-17 13:14:03 -0500 | [diff] [blame] | 1524 | .. doctest:: |
| 1525 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1526 | >>> from cryptography.x509.oid import ExtensionOID |
| 1527 | >>> cert.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS) |
Paul Kehrer | fa56a23 | 2015-03-17 13:14:03 -0500 | [diff] [blame] | 1528 | <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)> |
| 1529 | |
Phoebe Queen | 019b7f8 | 2015-08-12 03:52:03 +0100 | [diff] [blame] | 1530 | .. method:: get_extension_for_class(extclass) |
| 1531 | |
Phoebe Queen | 6a603eb | 2015-08-12 14:14:49 +0100 | [diff] [blame] | 1532 | .. versionadded:: 1.1 |
| 1533 | |
Phoebe Queen | 019b7f8 | 2015-08-12 03:52:03 +0100 | [diff] [blame] | 1534 | :param extclass: An extension class. |
| 1535 | |
| 1536 | :returns: An instance of the extension class. |
| 1537 | |
| 1538 | :raises cryptography.x509.ExtensionNotFound: If the certificate does |
| 1539 | not have the extension requested. |
| 1540 | |
| 1541 | .. doctest:: |
| 1542 | |
| 1543 | >>> from cryptography import x509 |
| 1544 | >>> cert.extensions.get_extension_for_class(x509.BasicConstraints) |
| 1545 | <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)> |
| 1546 | |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1547 | .. class:: Extension |
| 1548 | |
| 1549 | .. versionadded:: 0.9 |
| 1550 | |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame] | 1551 | .. attribute:: oid |
| 1552 | |
| 1553 | :type: :class:`ObjectIdentifier` |
| 1554 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1555 | One of the :class:`~cryptography.x509.oid.ExtensionOID` OIDs. |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1556 | |
| 1557 | .. attribute:: critical |
| 1558 | |
| 1559 | :type: bool |
| 1560 | |
Paul Kehrer | 58b7569 | 2015-03-22 23:24:58 -0500 | [diff] [blame] | 1561 | Determines whether a given extension is critical or not. :rfc:`5280` |
| 1562 | requires that "A certificate-using system MUST reject the certificate |
| 1563 | if it encounters a critical extension it does not recognize or a |
| 1564 | critical extension that contains information that it cannot process". |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1565 | |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame] | 1566 | .. attribute:: value |
| 1567 | |
| 1568 | Returns an instance of the extension type corresponding to the OID. |
| 1569 | |
Paul Kehrer | 14f0bd0 | 2015-08-06 11:55:18 +0100 | [diff] [blame] | 1570 | .. class:: ExtensionType |
| 1571 | |
| 1572 | .. versionadded:: 1.0 |
| 1573 | |
| 1574 | This is the interface against which all the following extension types are |
| 1575 | registered. |
| 1576 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1577 | .. 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] | 1578 | |
| 1579 | .. versionadded:: 0.9 |
| 1580 | |
| 1581 | The key usage extension defines the purpose of the key contained in the |
| 1582 | certificate. The usage restriction might be employed when a key that could |
Paul Kehrer | b33de93 | 2015-08-06 23:41:05 +0100 | [diff] [blame] | 1583 | be used for more than one operation is to be restricted. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1584 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1585 | .. attribute:: oid |
| 1586 | |
| 1587 | .. versionadded:: 1.0 |
| 1588 | |
| 1589 | :type: :class:`ObjectIdentifier` |
| 1590 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1591 | Returns :attr:`~cryptography.x509.oid.ExtensionOID.KEY_USAGE`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1592 | |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1593 | .. attribute:: digital_signature |
| 1594 | |
| 1595 | :type: bool |
| 1596 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1597 | 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] | 1598 | digital signatures, other than signatures on certificates |
| 1599 | (``key_cert_sign``) and CRLs (``crl_sign``). |
| 1600 | |
| 1601 | .. attribute:: content_commitment |
| 1602 | |
| 1603 | :type: bool |
| 1604 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1605 | 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] | 1606 | digital signatures, other than signatures on certificates |
| 1607 | (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a |
| 1608 | non-repudiation service that protects against the signing entity |
| 1609 | falsely denying some action. In the case of later conflict, a |
| 1610 | reliable third party may determine the authenticity of the signed |
| 1611 | data. This was called ``non_repudiation`` in older revisions of the |
| 1612 | X.509 specification. |
| 1613 | |
| 1614 | .. attribute:: key_encipherment |
| 1615 | |
| 1616 | :type: bool |
| 1617 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1618 | This purpose is set to true when the subject public key is used for |
| 1619 | enciphering private or secret keys. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1620 | |
| 1621 | .. attribute:: data_encipherment |
| 1622 | |
| 1623 | :type: bool |
| 1624 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1625 | This purpose is set to true when the subject public key is used for |
| 1626 | directly enciphering raw user data without the use of an intermediate |
| 1627 | symmetric cipher. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1628 | |
| 1629 | .. attribute:: key_agreement |
| 1630 | |
| 1631 | :type: bool |
| 1632 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1633 | This purpose is set to true when the subject public key is used for key |
| 1634 | agreement. For example, when a Diffie-Hellman key is to be used for |
| 1635 | key management, then this purpose is set to true. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1636 | |
| 1637 | .. attribute:: key_cert_sign |
| 1638 | |
| 1639 | :type: bool |
| 1640 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1641 | This purpose is set to true when the subject public key is used for |
| 1642 | verifying signatures on public key certificates. If this purpose is set |
| 1643 | to true then ``ca`` must be true in the :class:`BasicConstraints` |
| 1644 | extension. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1645 | |
| 1646 | .. attribute:: crl_sign |
| 1647 | |
| 1648 | :type: bool |
| 1649 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1650 | This purpose is set to true when the subject public key is used for |
| 1651 | verifying signatures on certificate revocation lists. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1652 | |
| 1653 | .. attribute:: encipher_only |
| 1654 | |
| 1655 | :type: bool |
| 1656 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1657 | When this purposes is set to true and the ``key_agreement`` purpose is |
| 1658 | also set, the subject public key may be used only for enciphering data |
| 1659 | while performing key agreement. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1660 | |
| 1661 | :raises ValueError: This is raised if accessed when ``key_agreement`` |
| 1662 | is false. |
| 1663 | |
| 1664 | .. attribute:: decipher_only |
| 1665 | |
| 1666 | :type: bool |
| 1667 | |
Paul Kehrer | 738407b | 2015-04-01 22:39:02 -0500 | [diff] [blame] | 1668 | When this purposes is set to true and the ``key_agreement`` purpose is |
| 1669 | also set, the subject public key may be used only for deciphering data |
| 1670 | while performing key agreement. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 1671 | |
| 1672 | :raises ValueError: This is raised if accessed when ``key_agreement`` |
| 1673 | is false. |
| 1674 | |
| 1675 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1676 | .. class:: BasicConstraints(ca, path_length) |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1677 | |
| 1678 | .. versionadded:: 0.9 |
| 1679 | |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame] | 1680 | 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] | 1681 | certificate is allowed to sign additional certificates and what path |
Paul Kehrer | b33de93 | 2015-08-06 23:41:05 +0100 | [diff] [blame] | 1682 | length restrictions may exist. |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1683 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1684 | .. attribute:: oid |
| 1685 | |
| 1686 | .. versionadded:: 1.0 |
| 1687 | |
| 1688 | :type: :class:`ObjectIdentifier` |
| 1689 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1690 | Returns :attr:`~cryptography.x509.oid.ExtensionOID.BASIC_CONSTRAINTS`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1691 | |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1692 | .. attribute:: ca |
| 1693 | |
| 1694 | :type: bool |
| 1695 | |
| 1696 | Whether the certificate can sign certificates. |
| 1697 | |
| 1698 | .. attribute:: path_length |
| 1699 | |
Paul Kehrer | fd1444c | 2015-03-21 19:47:05 -0500 | [diff] [blame] | 1700 | :type: int or None |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1701 | |
| 1702 | The maximum path length for certificates subordinate to this |
| 1703 | certificate. This attribute only has meaning if ``ca`` is true. |
| 1704 | If ``ca`` is true then a path length of None means there's no |
| 1705 | restriction on the number of subordinate CAs in the certificate chain. |
Alex Gaynor | 99c5f15 | 2015-05-03 10:01:04 -0400 | [diff] [blame] | 1706 | If it is zero or greater then it defines the maximum length for a |
| 1707 | subordinate CA's certificate chain. For example, a ``path_length`` of 1 |
| 1708 | means the certificate can sign a subordinate CA, but the subordinate CA |
| 1709 | is not allowed to create subordinates with ``ca`` set to true. |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1710 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1711 | .. class:: ExtendedKeyUsage(usages) |
Paul Kehrer | ffa2a15 | 2015-03-31 08:18:25 -0500 | [diff] [blame] | 1712 | |
| 1713 | .. versionadded:: 0.9 |
| 1714 | |
| 1715 | This extension indicates one or more purposes for which the certified |
| 1716 | public key may be used, in addition to or in place of the basic |
| 1717 | purposes indicated in the key usage extension. The object is |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1718 | iterable to obtain the list of |
| 1719 | :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs present. |
Paul Kehrer | ffa2a15 | 2015-03-31 08:18:25 -0500 | [diff] [blame] | 1720 | |
Paul Kehrer | 1cb9e55 | 2015-10-28 09:37:29 +0900 | [diff] [blame] | 1721 | :param list usages: A list of |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1722 | :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs. |
| 1723 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1724 | .. attribute:: oid |
| 1725 | |
| 1726 | .. versionadded:: 1.0 |
| 1727 | |
| 1728 | :type: :class:`ObjectIdentifier` |
| 1729 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1730 | Returns :attr:`~cryptography.x509.oid.ExtensionOID.EXTENDED_KEY_USAGE`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1731 | |
| 1732 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1733 | .. class:: OCSPNoCheck() |
Paul Kehrer | 4a1038e | 2015-05-18 10:28:31 -0700 | [diff] [blame] | 1734 | |
Paul Kehrer | 506a215 | 2015-05-26 08:01:18 -0500 | [diff] [blame] | 1735 | .. versionadded:: 1.0 |
Paul Kehrer | 4a1038e | 2015-05-18 10:28:31 -0700 | [diff] [blame] | 1736 | |
| 1737 | This presence of this extension indicates that an OCSP client can trust a |
| 1738 | responder for the lifetime of the responder's certificate. CAs issuing |
| 1739 | such a certificate should realize that a compromise of the responder's key |
| 1740 | is as serious as the compromise of a CA key used to sign CRLs, at least for |
| 1741 | the validity period of this certificate. CA's may choose to issue this type |
| 1742 | of certificate with a very short lifetime and renew it frequently. This |
| 1743 | extension is only relevant when the certificate is an authorized OCSP |
| 1744 | responder. |
| 1745 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1746 | .. attribute:: oid |
| 1747 | |
| 1748 | .. versionadded:: 1.0 |
| 1749 | |
| 1750 | :type: :class:`ObjectIdentifier` |
| 1751 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1752 | Returns :attr:`~cryptography.x509.oid.ExtensionOID.OCSP_NO_CHECK`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1753 | |
Paul Kehrer | 5d66966 | 2017-09-11 09:16:34 +0800 | [diff] [blame] | 1754 | |
| 1755 | .. class:: TLSFeature(features) |
| 1756 | |
| 1757 | .. versionadded:: 2.1 |
| 1758 | |
| 1759 | The TLS Feature extension is defined in :rfc:`7633` and is used in |
| 1760 | certificates for OCSP Must-Staple. The object is iterable to get every |
| 1761 | element. |
| 1762 | |
| 1763 | :param list features: A list of features to enable from the |
| 1764 | :class:`~cryptography.x509.TLSFeatureType` enum. At this time only |
| 1765 | ``status_request`` or ``status_request_v2`` are allowed. |
| 1766 | |
| 1767 | .. attribute:: oid |
| 1768 | |
| 1769 | :type: :class:`ObjectIdentifier` |
| 1770 | |
| 1771 | Returns :attr:`~cryptography.x509.oid.ExtensionOID.TLS_FEATURE`. |
| 1772 | |
| 1773 | .. class:: TLSFeatureType |
| 1774 | |
| 1775 | .. versionadded:: 2.1 |
| 1776 | |
| 1777 | An enumeration of TLS Feature types. |
| 1778 | |
| 1779 | .. attribute:: status_request |
| 1780 | |
| 1781 | This feature type is defined in :rfc:`6066` and, when embedded in |
| 1782 | an X.509 certificate, signals to the client that it should require |
| 1783 | a stapled OCSP response in the TLS handshake. Commonly known as OCSP |
| 1784 | Must-Staple in certificates. |
| 1785 | |
| 1786 | .. attribute:: status_request_v2 |
| 1787 | |
| 1788 | This feature type is defined in :rfc:`6961`. This value is not |
| 1789 | commonly used and if you want to enable OCSP Must-Staple you should |
| 1790 | use ``status_request``. |
| 1791 | |
| 1792 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1793 | .. class:: NameConstraints(permitted_subtrees, excluded_subtrees) |
Paul Kehrer | e0017be | 2015-05-17 20:39:40 -0600 | [diff] [blame] | 1794 | |
| 1795 | .. versionadded:: 1.0 |
| 1796 | |
| 1797 | The name constraints extension, which only has meaning in a CA certificate, |
| 1798 | defines a name space within which all subject names in certificates issued |
| 1799 | beneath the CA certificate must (or must not) be in. For specific details |
| 1800 | on the way this extension should be processed see :rfc:`5280`. |
| 1801 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1802 | .. attribute:: oid |
| 1803 | |
| 1804 | .. versionadded:: 1.0 |
| 1805 | |
| 1806 | :type: :class:`ObjectIdentifier` |
| 1807 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1808 | Returns :attr:`~cryptography.x509.oid.ExtensionOID.NAME_CONSTRAINTS`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1809 | |
Paul Kehrer | e0017be | 2015-05-17 20:39:40 -0600 | [diff] [blame] | 1810 | .. attribute:: permitted_subtrees |
| 1811 | |
| 1812 | :type: list of :class:`GeneralName` objects or None |
| 1813 | |
| 1814 | The set of permitted name patterns. If a name matches this and an |
| 1815 | element in ``excluded_subtrees`` it is invalid. At least one of |
| 1816 | ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None. |
| 1817 | |
| 1818 | .. attribute:: excluded_subtrees |
| 1819 | |
| 1820 | :type: list of :class:`GeneralName` objects or None |
| 1821 | |
| 1822 | Any name matching a restriction in the ``excluded_subtrees`` field is |
| 1823 | invalid regardless of information appearing in the |
| 1824 | ``permitted_subtrees``. At least one of ``permitted_subtrees`` and |
| 1825 | ``excluded_subtrees`` will be non-None. |
| 1826 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1827 | .. class:: AuthorityKeyIdentifier(key_identifier, authority_cert_issuer, authority_cert_serial_number) |
Paul Kehrer | 2eb4ed9 | 2015-04-11 15:33:45 -0400 | [diff] [blame] | 1828 | |
| 1829 | .. versionadded:: 0.9 |
| 1830 | |
| 1831 | The authority key identifier extension provides a means of identifying the |
| 1832 | public key corresponding to the private key used to sign a certificate. |
Paul Kehrer | 8c8cd72 | 2015-04-19 09:15:04 -0500 | [diff] [blame] | 1833 | This extension is typically used to assist in determining the appropriate |
| 1834 | certificate chain. For more information about generation and use of this |
| 1835 | extension see `RFC 5280 section 4.2.1.1`_. |
Paul Kehrer | 2eb4ed9 | 2015-04-11 15:33:45 -0400 | [diff] [blame] | 1836 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1837 | .. attribute:: oid |
| 1838 | |
| 1839 | .. versionadded:: 1.0 |
| 1840 | |
| 1841 | :type: :class:`ObjectIdentifier` |
| 1842 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1843 | Returns |
| 1844 | :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_KEY_IDENTIFIER`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1845 | |
Paul Kehrer | 2eb4ed9 | 2015-04-11 15:33:45 -0400 | [diff] [blame] | 1846 | .. attribute:: key_identifier |
| 1847 | |
| 1848 | :type: bytes |
| 1849 | |
Paul Kehrer | 9104b1d | 2015-04-18 09:23:44 -0500 | [diff] [blame] | 1850 | 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] | 1851 | signature. |
Paul Kehrer | 9104b1d | 2015-04-18 09:23:44 -0500 | [diff] [blame] | 1852 | |
Paul Kehrer | 2eb4ed9 | 2015-04-11 15:33:45 -0400 | [diff] [blame] | 1853 | .. attribute:: authority_cert_issuer |
| 1854 | |
Thom Dixon | 488c048 | 2018-05-18 03:55:29 -0700 | [diff] [blame] | 1855 | :type: A list of :class:`GeneralName` instances or None |
Paul Kehrer | 2eb4ed9 | 2015-04-11 15:33:45 -0400 | [diff] [blame] | 1856 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1857 | The :class:`GeneralName` (one or multiple) of the issuer's issuer. |
Paul Kehrer | 9104b1d | 2015-04-18 09:23:44 -0500 | [diff] [blame] | 1858 | |
Paul Kehrer | 2eb4ed9 | 2015-04-11 15:33:45 -0400 | [diff] [blame] | 1859 | .. attribute:: authority_cert_serial_number |
| 1860 | |
| 1861 | :type: int or None |
| 1862 | |
Paul Kehrer | 9104b1d | 2015-04-18 09:23:44 -0500 | [diff] [blame] | 1863 | The serial number of the issuer's issuer. |
| 1864 | |
Paul Kehrer | 253929a | 2015-08-05 17:30:39 +0100 | [diff] [blame] | 1865 | .. classmethod:: from_issuer_public_key(public_key) |
| 1866 | |
| 1867 | .. versionadded:: 1.0 |
| 1868 | |
Paul Kehrer | 2d8e574 | 2016-03-12 09:27:55 -0400 | [diff] [blame] | 1869 | .. note:: |
| 1870 | |
| 1871 | This method should be used if the issuer certificate does not |
| 1872 | contain a :class:`~cryptography.x509.SubjectKeyIdentifier`. |
| 1873 | Otherwise, use |
| 1874 | :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier`. |
| 1875 | |
Paul Kehrer | 253929a | 2015-08-05 17:30:39 +0100 | [diff] [blame] | 1876 | Creates a new AuthorityKeyIdentifier instance using the public key |
| 1877 | provided to generate the appropriate digest. This should be the |
Paul Kehrer | 26ac47f | 2015-08-08 15:20:52 -0500 | [diff] [blame] | 1878 | **issuer's public key**. The resulting object will contain |
| 1879 | :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but |
| 1880 | :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer` |
| 1881 | and |
| 1882 | :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number` |
| 1883 | will be None. |
| 1884 | The generated ``key_identifier`` is the SHA1 hash of the ``subjectPublicKey`` |
| 1885 | ASN.1 bit string. This is the first recommendation in :rfc:`5280` |
Paul Kehrer | 253929a | 2015-08-05 17:30:39 +0100 | [diff] [blame] | 1886 | section 4.2.1.2. |
| 1887 | |
Paul Kehrer | cc67182 | 2015-08-08 15:41:54 -0500 | [diff] [blame] | 1888 | :param public_key: One of |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1889 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`, |
| 1890 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`, |
| 1891 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`, |
| 1892 | :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey` or |
| 1893 | :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PublicKey`. |
Paul Kehrer | 253929a | 2015-08-05 17:30:39 +0100 | [diff] [blame] | 1894 | |
| 1895 | .. doctest:: |
| 1896 | |
| 1897 | >>> from cryptography import x509 |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1898 | >>> issuer_cert = x509.load_pem_x509_certificate(pem_data) |
Paul Kehrer | cc67182 | 2015-08-08 15:41:54 -0500 | [diff] [blame] | 1899 | >>> x509.AuthorityKeyIdentifier.from_issuer_public_key(issuer_cert.public_key()) |
Paul Kehrer | 056c9dd | 2018-05-12 15:17:06 -0400 | [diff] [blame] | 1900 | <AuthorityKeyIdentifier(key_identifier=b'X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9', authority_cert_issuer=None, authority_cert_serial_number=None)> |
Paul Kehrer | 253929a | 2015-08-05 17:30:39 +0100 | [diff] [blame] | 1901 | |
Paul Kehrer | 61ff356 | 2016-03-11 22:51:27 -0400 | [diff] [blame] | 1902 | .. classmethod:: from_issuer_subject_key_identifier(ski) |
| 1903 | |
| 1904 | .. versionadded:: 1.3 |
| 1905 | |
Paul Kehrer | 2d8e574 | 2016-03-12 09:27:55 -0400 | [diff] [blame] | 1906 | .. note:: |
| 1907 | This method should be used if the issuer certificate contains a |
| 1908 | :class:`~cryptography.x509.SubjectKeyIdentifier`. Otherwise, use |
| 1909 | :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_public_key`. |
| 1910 | |
Paul Kehrer | 61ff356 | 2016-03-11 22:51:27 -0400 | [diff] [blame] | 1911 | Creates a new AuthorityKeyIdentifier instance using the |
| 1912 | SubjectKeyIdentifier from the issuer certificate. The resulting object |
| 1913 | will contain |
| 1914 | :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but |
| 1915 | :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer` |
| 1916 | and |
| 1917 | :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number` |
| 1918 | will be None. |
| 1919 | |
| 1920 | :param ski: The |
| 1921 | :class:`~cryptography.x509.SubjectKeyIdentifier` from the issuer |
| 1922 | certificate. |
| 1923 | |
| 1924 | .. doctest:: |
| 1925 | |
| 1926 | >>> from cryptography import x509 |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1927 | >>> issuer_cert = x509.load_pem_x509_certificate(pem_data) |
| 1928 | >>> ski_ext = issuer_cert.extensions.get_extension_for_class(x509.SubjectKeyIdentifier) |
| 1929 | >>> x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier(ski_ext.value) |
Paul Kehrer | 056c9dd | 2018-05-12 15:17:06 -0400 | [diff] [blame] | 1930 | <AuthorityKeyIdentifier(key_identifier=b'X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9', authority_cert_issuer=None, authority_cert_serial_number=None)> |
Paul Kehrer | 61ff356 | 2016-03-11 22:51:27 -0400 | [diff] [blame] | 1931 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1932 | .. class:: SubjectKeyIdentifier(digest) |
Paul Kehrer | 1eb82a6 | 2015-03-31 20:00:33 -0500 | [diff] [blame] | 1933 | |
| 1934 | .. versionadded:: 0.9 |
| 1935 | |
| 1936 | The subject key identifier extension provides a means of identifying |
| 1937 | certificates that contain a particular public key. |
| 1938 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1939 | .. attribute:: oid |
| 1940 | |
| 1941 | .. versionadded:: 1.0 |
| 1942 | |
| 1943 | :type: :class:`ObjectIdentifier` |
| 1944 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1945 | Returns |
| 1946 | :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1947 | |
Paul Kehrer | 1eb82a6 | 2015-03-31 20:00:33 -0500 | [diff] [blame] | 1948 | .. attribute:: digest |
| 1949 | |
| 1950 | :type: bytes |
| 1951 | |
| 1952 | The binary value of the identifier. |
| 1953 | |
Paul Kehrer | d4a7f06 | 2015-08-05 18:32:18 +0100 | [diff] [blame] | 1954 | .. classmethod:: from_public_key(public_key) |
Paul Kehrer | f22f612 | 2015-08-05 12:57:13 +0100 | [diff] [blame] | 1955 | |
| 1956 | .. versionadded:: 1.0 |
| 1957 | |
| 1958 | Creates a new SubjectKeyIdentifier instance using the public key |
| 1959 | provided to generate the appropriate digest. This should be the public |
Paul Kehrer | eb9ec00 | 2015-08-08 10:03:02 -0500 | [diff] [blame] | 1960 | key that is in the certificate. The generated digest is the SHA1 hash |
| 1961 | of the ``subjectPublicKey`` ASN.1 bit string. This is the first |
| 1962 | recommendation in :rfc:`5280` section 4.2.1.2. |
Paul Kehrer | f22f612 | 2015-08-05 12:57:13 +0100 | [diff] [blame] | 1963 | |
| 1964 | :param public_key: One of |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1965 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`, |
| 1966 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`, |
| 1967 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`, |
| 1968 | :class:`~cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey` or |
| 1969 | :class:`~cryptography.hazmat.primitives.asymmetric.ed448.Ed448PublicKey`. |
Paul Kehrer | f22f612 | 2015-08-05 12:57:13 +0100 | [diff] [blame] | 1970 | |
Paul Kehrer | 253929a | 2015-08-05 17:30:39 +0100 | [diff] [blame] | 1971 | .. doctest:: |
| 1972 | |
| 1973 | >>> from cryptography import x509 |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1974 | >>> csr = x509.load_pem_x509_csr(pem_req_data) |
Paul Kehrer | cc67182 | 2015-08-08 15:41:54 -0500 | [diff] [blame] | 1975 | >>> x509.SubjectKeyIdentifier.from_public_key(csr.public_key()) |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 1976 | <SubjectKeyIdentifier(digest=b'\x8c"\x98\xe2\xb5\xbf]\xe8*2\xf8\xd2\'?\x00\xd2\xc7#\xe4c')> |
Paul Kehrer | 253929a | 2015-08-05 17:30:39 +0100 | [diff] [blame] | 1977 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1978 | .. class:: SubjectAlternativeName(general_names) |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1979 | |
| 1980 | .. versionadded:: 0.9 |
| 1981 | |
| 1982 | Subject alternative name is an X.509 extension that provides a list of |
| 1983 | :ref:`general name <general_name_classes>` instances that provide a set |
| 1984 | of identities for which the certificate is valid. The object is iterable to |
| 1985 | get every element. |
| 1986 | |
Paul Kehrer | 1cb9e55 | 2015-10-28 09:37:29 +0900 | [diff] [blame] | 1987 | :param list general_names: A list of :class:`GeneralName` instances. |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 1988 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1989 | .. attribute:: oid |
| 1990 | |
| 1991 | .. versionadded:: 1.0 |
| 1992 | |
| 1993 | :type: :class:`ObjectIdentifier` |
| 1994 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 1995 | Returns |
| 1996 | :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_ALTERNATIVE_NAME`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 1997 | |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 1998 | .. method:: get_values_for_type(type) |
| 1999 | |
Gabriel Orisaka | 617fe4b | 2016-07-31 10:49:59 -0300 | [diff] [blame] | 2000 | :param type: A :class:`GeneralName` instance. This is one of the |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 2001 | :ref:`general name classes <general_name_classes>`. |
| 2002 | |
| 2003 | :returns: A list of values extracted from the matched general names. |
Joshua Tauberer | d2afad3 | 2015-07-06 22:37:53 +0000 | [diff] [blame] | 2004 | The type of the returned values depends on the :class:`GeneralName`. |
Paul Kehrer | 31bdf79 | 2015-03-25 14:11:00 -0500 | [diff] [blame] | 2005 | |
Paul Kehrer | 93ae805 | 2015-05-02 23:18:09 -0500 | [diff] [blame] | 2006 | .. doctest:: |
| 2007 | |
| 2008 | >>> from cryptography import x509 |
Paul Kehrer | 93ae805 | 2015-05-02 23:18:09 -0500 | [diff] [blame] | 2009 | >>> from cryptography.hazmat.primitives import hashes |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 2010 | >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem) |
Paul Kehrer | d0cd507 | 2015-05-02 23:27:00 -0500 | [diff] [blame] | 2011 | >>> # Get the subjectAltName extension from the certificate |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2012 | >>> ext = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME) |
Paul Kehrer | d0cd507 | 2015-05-02 23:27:00 -0500 | [diff] [blame] | 2013 | >>> # Get the dNSName entries from the SAN extension |
| 2014 | >>> ext.value.get_values_for_type(x509.DNSName) |
Paul Kehrer | 056c9dd | 2018-05-12 15:17:06 -0400 | [diff] [blame] | 2015 | ['www.cryptography.io', 'cryptography.io'] |
Paul Kehrer | 93ae805 | 2015-05-02 23:18:09 -0500 | [diff] [blame] | 2016 | |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 2017 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2018 | .. class:: IssuerAlternativeName(general_names) |
Paul Kehrer | 99125c9 | 2015-06-07 18:37:10 -0500 | [diff] [blame] | 2019 | |
| 2020 | .. versionadded:: 1.0 |
| 2021 | |
| 2022 | Issuer alternative name is an X.509 extension that provides a list of |
| 2023 | :ref:`general name <general_name_classes>` instances that provide a set |
| 2024 | of identities for the certificate issuer. The object is iterable to |
| 2025 | get every element. |
| 2026 | |
Paul Kehrer | 1cb9e55 | 2015-10-28 09:37:29 +0900 | [diff] [blame] | 2027 | :param list general_names: A list of :class:`GeneralName` instances. |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2028 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 2029 | .. attribute:: oid |
| 2030 | |
| 2031 | .. versionadded:: 1.0 |
| 2032 | |
| 2033 | :type: :class:`ObjectIdentifier` |
| 2034 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2035 | Returns |
| 2036 | :attr:`~cryptography.x509.oid.ExtensionOID.ISSUER_ALTERNATIVE_NAME`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 2037 | |
Paul Kehrer | 99125c9 | 2015-06-07 18:37:10 -0500 | [diff] [blame] | 2038 | .. method:: get_values_for_type(type) |
| 2039 | |
Gabriel Orisaka | 617fe4b | 2016-07-31 10:49:59 -0300 | [diff] [blame] | 2040 | :param type: A :class:`GeneralName` instance. This is one of the |
Paul Kehrer | 99125c9 | 2015-06-07 18:37:10 -0500 | [diff] [blame] | 2041 | :ref:`general name classes <general_name_classes>`. |
| 2042 | |
| 2043 | :returns: A list of values extracted from the matched general names. |
| 2044 | |
| 2045 | |
Alex Gaynor | 6a0718f | 2017-06-04 13:36:58 -0400 | [diff] [blame] | 2046 | .. class:: PrecertificateSignedCertificateTimestamps(scts) |
| 2047 | |
| 2048 | .. versionadded:: 2.0 |
| 2049 | |
| 2050 | This extension contains |
| 2051 | :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp` |
| 2052 | instances which were issued for the pre-certificate corresponding to this |
| 2053 | certificate. These can be used to verify that the certificate is included |
| 2054 | in a public Certificate Transparency log. |
| 2055 | |
| 2056 | It is an iterable containing one or more |
| 2057 | :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp` |
| 2058 | objects. |
| 2059 | |
| 2060 | :param list scts: A ``list`` of |
| 2061 | :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp` |
| 2062 | objects. |
| 2063 | |
| 2064 | .. attribute:: oid |
| 2065 | |
| 2066 | :type: :class:`ObjectIdentifier` |
| 2067 | |
| 2068 | Returns |
| 2069 | :attr:`~cryptography.x509.oid.ExtensionOID.PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS`. |
| 2070 | |
| 2071 | |
Alex Gaynor | dd6b78b | 2018-08-31 18:25:52 -0500 | [diff] [blame] | 2072 | .. class:: PrecertPoison() |
| 2073 | |
| 2074 | .. versionadded:: 2.4 |
| 2075 | |
| 2076 | This extension indicates that the certificate should not be treated as a |
| 2077 | certificate for the purposes of validation, but is instead for submission |
| 2078 | to a certificate transparency log in order to obtain SCTs which will be |
| 2079 | embedded in a :class:`PrecertificateSignedCertificateTimestamps` extension |
| 2080 | on the final certificate. |
| 2081 | |
| 2082 | .. attribute:: oid |
| 2083 | |
| 2084 | :type: :class:`ObjectIdentifier` |
| 2085 | |
| 2086 | Returns :attr:`~cryptography.x509.oid.ExtensionOID.PRECERT_POISON`. |
| 2087 | |
| 2088 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 2089 | .. class:: SignedCertificateTimestamps(scts) |
| 2090 | |
| 2091 | .. versionadded:: 3.0 |
| 2092 | |
| 2093 | This extension contains |
| 2094 | :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp` |
| 2095 | instances. These can be used to verify that the certificate is included |
| 2096 | in a public Certificate Transparency log. This extension is only found |
| 2097 | in OCSP responses. For SCTs in an X.509 certificate see |
| 2098 | :class:`~cryptography.x509.PrecertificateSignedCertificateTimestamps`. |
| 2099 | |
| 2100 | It is an iterable containing one or more |
| 2101 | :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp` |
| 2102 | objects. |
| 2103 | |
| 2104 | :param list scts: A ``list`` of |
| 2105 | :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp` |
| 2106 | objects. |
| 2107 | |
| 2108 | .. attribute:: oid |
| 2109 | |
| 2110 | :type: :class:`ObjectIdentifier` |
| 2111 | |
| 2112 | Returns |
| 2113 | :attr:`~cryptography.x509.oid.ExtensionOID.SIGNED_CERTIFICATE_TIMESTAMPS`. |
| 2114 | |
| 2115 | |
Paul Kehrer | 5e3cc98 | 2017-09-22 21:29:36 +0800 | [diff] [blame] | 2116 | .. class:: DeltaCRLIndicator(crl_number) |
| 2117 | |
| 2118 | .. versionadded:: 2.1 |
| 2119 | |
| 2120 | The delta CRL indicator is a CRL extension that identifies a CRL as being |
| 2121 | a delta CRL. Delta CRLs contain updates to revocation information |
| 2122 | previously distributed, rather than all the information that would appear |
| 2123 | in a complete CRL. |
| 2124 | |
| 2125 | :param int crl_number: The CRL number of the complete CRL that the |
| 2126 | delta CRL is updating. |
| 2127 | |
| 2128 | .. attribute:: oid |
| 2129 | |
| 2130 | :type: :class:`ObjectIdentifier` |
| 2131 | |
| 2132 | Returns |
| 2133 | :attr:`~cryptography.x509.oid.ExtensionOID.DELTA_CRL_INDICATOR`. |
| 2134 | |
| 2135 | .. attribute:: crl_number |
| 2136 | |
| 2137 | :type: int |
| 2138 | |
| 2139 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2140 | .. class:: AuthorityInformationAccess(descriptions) |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 2141 | |
| 2142 | .. versionadded:: 0.9 |
| 2143 | |
| 2144 | The authority information access extension indicates how to access |
| 2145 | information and services for the issuer of the certificate in which |
| 2146 | the extension appears. Information and services may include online |
| 2147 | validation services (such as OCSP) and issuer data. It is an iterable, |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2148 | containing one or more :class:`~cryptography.x509.AccessDescription` |
| 2149 | instances. |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 2150 | |
Paul Kehrer | 1cb9e55 | 2015-10-28 09:37:29 +0900 | [diff] [blame] | 2151 | :param list descriptions: A list of :class:`AccessDescription` objects. |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2152 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 2153 | .. attribute:: oid |
| 2154 | |
| 2155 | .. versionadded:: 1.0 |
| 2156 | |
| 2157 | :type: :class:`ObjectIdentifier` |
| 2158 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2159 | Returns |
| 2160 | :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_INFORMATION_ACCESS`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 2161 | |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 2162 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 2163 | .. class:: SubjectInformationAccess(descriptions) |
| 2164 | |
| 2165 | .. versionadded:: 3.0 |
| 2166 | |
| 2167 | The subject information access extension indicates how to access |
| 2168 | information and services for the subject of the certificate in which |
| 2169 | the extension appears. When the subject is a CA, information and |
| 2170 | services may include certificate validation services and CA policy |
| 2171 | data. When the subject is an end entity, the information describes |
| 2172 | the type of services offered and how to access them. It is an iterable, |
| 2173 | containing one or more :class:`~cryptography.x509.AccessDescription` |
| 2174 | instances. |
| 2175 | |
| 2176 | :param list descriptions: A list of :class:`AccessDescription` objects. |
| 2177 | |
| 2178 | .. attribute:: oid |
| 2179 | |
| 2180 | :type: :class:`ObjectIdentifier` |
| 2181 | |
| 2182 | Returns |
| 2183 | :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_INFORMATION_ACCESS`. |
| 2184 | |
| 2185 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2186 | .. class:: AccessDescription(access_method, access_location) |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 2187 | |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2188 | .. versionadded:: 0.9 |
| 2189 | |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 2190 | .. attribute:: access_method |
| 2191 | |
| 2192 | :type: :class:`ObjectIdentifier` |
| 2193 | |
Paul Kehrer | f506bca | 2015-05-02 22:31:47 -0500 | [diff] [blame] | 2194 | The access method defines what the ``access_location`` means. It must |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 2195 | be |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2196 | :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP` or |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 2197 | :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS` |
| 2198 | when used with :class:`~cryptography.x509.AuthorityInformationAccess` |
| 2199 | or |
| 2200 | :attr:`~cryptography.x509.oid.SubjectInformationAccessOID.CA_REPOSITORY` |
| 2201 | when used with :class:`~cryptography.x509.SubjectInformationAccess`. |
| 2202 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2203 | If it is |
| 2204 | :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP` |
| 2205 | the access location will be where to obtain OCSP |
| 2206 | information for the certificate. If it is |
| 2207 | :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS` |
| 2208 | the access location will provide additional information about the |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 2209 | issuing certificate. Finally, if it is |
| 2210 | :attr:`~cryptography.x509.oid.SubjectInformationAccessOID.CA_REPOSITORY` |
| 2211 | the access location will be the location of the CA's repository. |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 2212 | |
| 2213 | .. attribute:: access_location |
| 2214 | |
| 2215 | :type: :class:`GeneralName` |
| 2216 | |
Paul Kehrer | f506bca | 2015-05-02 22:31:47 -0500 | [diff] [blame] | 2217 | Where to access the information defined by the access method. |
| 2218 | |
Paul Kehrer | b76bcf8 | 2017-09-24 08:44:12 +0800 | [diff] [blame] | 2219 | .. class:: FreshestCRL(distribution_points) |
| 2220 | |
| 2221 | .. versionadded:: 2.1 |
| 2222 | |
| 2223 | The freshest CRL extension (also known as Delta CRL Distribution Point) |
| 2224 | identifies how delta CRL information is obtained. It is an iterable, |
| 2225 | containing one or more :class:`DistributionPoint` instances. |
| 2226 | |
| 2227 | :param list distribution_points: A list of :class:`DistributionPoint` |
| 2228 | instances. |
| 2229 | |
| 2230 | .. attribute:: oid |
| 2231 | |
| 2232 | :type: :class:`ObjectIdentifier` |
| 2233 | |
| 2234 | Returns |
| 2235 | :attr:`~cryptography.x509.oid.ExtensionOID.FRESHEST_CRL`. |
| 2236 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2237 | .. class:: CRLDistributionPoints(distribution_points) |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2238 | |
| 2239 | .. versionadded:: 0.9 |
| 2240 | |
| 2241 | The CRL distribution points extension identifies how CRL information is |
| 2242 | obtained. It is an iterable, containing one or more |
| 2243 | :class:`DistributionPoint` instances. |
| 2244 | |
Paul Kehrer | 1cb9e55 | 2015-10-28 09:37:29 +0900 | [diff] [blame] | 2245 | :param list distribution_points: A list of :class:`DistributionPoint` |
| 2246 | instances. |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2247 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 2248 | .. attribute:: oid |
| 2249 | |
| 2250 | .. versionadded:: 1.0 |
| 2251 | |
| 2252 | :type: :class:`ObjectIdentifier` |
| 2253 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2254 | Returns |
| 2255 | :attr:`~cryptography.x509.oid.ExtensionOID.CRL_DISTRIBUTION_POINTS`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 2256 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2257 | .. class:: DistributionPoint(full_name, relative_name, reasons, crl_issuer) |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2258 | |
| 2259 | .. versionadded:: 0.9 |
| 2260 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 2261 | .. attribute:: full_name |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2262 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 2263 | :type: list of :class:`GeneralName` instances or None |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2264 | |
Paul Kehrer | f2c072b | 2015-05-09 17:04:28 -0500 | [diff] [blame] | 2265 | This field describes methods to retrieve the CRL. At most one of |
| 2266 | ``full_name`` or ``relative_name`` will be non-None. |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 2267 | |
| 2268 | .. attribute:: relative_name |
| 2269 | |
Fraser Tweedale | 02467dd | 2016-11-07 15:54:04 +1000 | [diff] [blame] | 2270 | :type: :class:`RelativeDistinguishedName` or None |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 2271 | |
| 2272 | This field describes methods to retrieve the CRL relative to the CRL |
Paul Kehrer | f2c072b | 2015-05-09 17:04:28 -0500 | [diff] [blame] | 2273 | issuer. At most one of ``full_name`` or ``relative_name`` will be |
| 2274 | non-None. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2275 | |
Fraser Tweedale | 02467dd | 2016-11-07 15:54:04 +1000 | [diff] [blame] | 2276 | .. versionchanged:: 1.6 |
| 2277 | Changed from :class:`Name` to :class:`RelativeDistinguishedName`. |
| 2278 | |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2279 | .. attribute:: crl_issuer |
| 2280 | |
| 2281 | :type: list of :class:`GeneralName` instances or None |
| 2282 | |
| 2283 | Information about the issuer of the CRL. |
| 2284 | |
| 2285 | .. attribute:: reasons |
| 2286 | |
Paul Kehrer | 3fd0260 | 2015-05-09 19:46:13 -0500 | [diff] [blame] | 2287 | :type: frozenset of :class:`ReasonFlags` or None |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2288 | |
| 2289 | The reasons a given distribution point may be used for when performing |
| 2290 | revocation checks. |
| 2291 | |
| 2292 | .. class:: ReasonFlags |
| 2293 | |
| 2294 | .. versionadded:: 0.9 |
| 2295 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 2296 | An enumeration for CRL reasons. |
| 2297 | |
| 2298 | .. attribute:: unspecified |
| 2299 | |
| 2300 | It is unspecified why the certificate was revoked. This reason cannot |
| 2301 | be used as a reason flag in a :class:`DistributionPoint`. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2302 | |
| 2303 | .. attribute:: key_compromise |
| 2304 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 2305 | This reason indicates that the private key was compromised. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2306 | |
| 2307 | .. attribute:: ca_compromise |
| 2308 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 2309 | This reason indicates that the CA issuing the certificate was |
| 2310 | compromised. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2311 | |
| 2312 | .. attribute:: affiliation_changed |
| 2313 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 2314 | This reason indicates that the subject's name or other information has |
| 2315 | changed. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2316 | |
| 2317 | .. attribute:: superseded |
| 2318 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 2319 | This reason indicates that a certificate has been superseded. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2320 | |
| 2321 | .. attribute:: cessation_of_operation |
| 2322 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 2323 | This reason indicates that the certificate is no longer required. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2324 | |
| 2325 | .. attribute:: certificate_hold |
| 2326 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 2327 | This reason indicates that the certificate is on hold. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2328 | |
| 2329 | .. attribute:: privilege_withdrawn |
| 2330 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 2331 | This reason indicates that the privilege granted by this certificate |
| 2332 | have been withdrawn. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2333 | |
| 2334 | .. attribute:: aa_compromise |
| 2335 | |
Paul Kehrer | 4e8dacd | 2015-05-09 10:38:23 -0500 | [diff] [blame] | 2336 | When an attribute authority has been compromised. |
| 2337 | |
| 2338 | .. attribute:: remove_from_crl |
| 2339 | |
| 2340 | This reason indicates that the certificate was on hold and should be |
| 2341 | removed from the CRL. This reason cannot be used as a reason flag |
| 2342 | in a :class:`DistributionPoint`. |
Paul Kehrer | 5a48552 | 2015-05-06 00:29:12 -0500 | [diff] [blame] | 2343 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2344 | .. class:: InhibitAnyPolicy(skip_certs) |
Paul Kehrer | 16fae76 | 2015-05-01 23:14:20 -0500 | [diff] [blame] | 2345 | |
| 2346 | .. versionadded:: 1.0 |
| 2347 | |
| 2348 | The inhibit ``anyPolicy`` extension indicates that the special OID |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2349 | :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY`, is not |
| 2350 | considered an explicit match for other :class:`CertificatePolicies` except |
| 2351 | when it appears in an intermediate self-issued CA certificate. The value |
| 2352 | indicates the number of additional non-self-issued certificates that may |
| 2353 | appear in the path before |
| 2354 | :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` is no |
| 2355 | longer permitted. For example, a value of one indicates that |
| 2356 | :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` may be |
| 2357 | processed in certificates issued by the subject of this certificate, but |
| 2358 | not in additional certificates in the path. |
Paul Kehrer | 16fae76 | 2015-05-01 23:14:20 -0500 | [diff] [blame] | 2359 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 2360 | .. attribute:: oid |
| 2361 | |
| 2362 | .. versionadded:: 1.0 |
| 2363 | |
| 2364 | :type: :class:`ObjectIdentifier` |
| 2365 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2366 | Returns |
| 2367 | :attr:`~cryptography.x509.oid.ExtensionOID.INHIBIT_ANY_POLICY`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 2368 | |
Paul Kehrer | 16fae76 | 2015-05-01 23:14:20 -0500 | [diff] [blame] | 2369 | .. attribute:: skip_certs |
| 2370 | |
| 2371 | :type: int |
| 2372 | |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 2373 | .. class:: PolicyConstraints |
| 2374 | |
| 2375 | .. versionadded:: 1.3 |
| 2376 | |
Paul Kehrer | 648c0fb | 2016-02-26 16:10:36 -0600 | [diff] [blame] | 2377 | The policy constraints extension is used to inhibit policy mapping or |
| 2378 | require that each certificate in a chain contain an acceptable policy |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 2379 | identifier. For more information about the use of this extension see |
| 2380 | :rfc:`5280`. |
| 2381 | |
Paul Kehrer | 159b3b5 | 2016-02-26 08:27:22 -0600 | [diff] [blame] | 2382 | .. attribute:: oid |
| 2383 | |
| 2384 | :type: :class:`ObjectIdentifier` |
| 2385 | |
| 2386 | Returns :attr:`~cryptography.x509.oid.ExtensionOID.POLICY_CONSTRAINTS`. |
| 2387 | |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 2388 | .. attribute:: require_explicit_policy |
| 2389 | |
| 2390 | :type: int or None |
| 2391 | |
Paul Kehrer | 648c0fb | 2016-02-26 16:10:36 -0600 | [diff] [blame] | 2392 | If this field is not None, the value indicates the number of additional |
| 2393 | certificates that may appear in the chain before an explicit policy is |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 2394 | required for the entire path. When an explicit policy is required, it |
Paul Kehrer | 648c0fb | 2016-02-26 16:10:36 -0600 | [diff] [blame] | 2395 | is necessary for all certificates in the chain to contain an acceptable |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 2396 | policy identifier in the certificate policies extension. An |
| 2397 | acceptable policy identifier is the identifier of a policy required |
| 2398 | by the user of the certification path or the identifier of a policy |
| 2399 | that has been declared equivalent through policy mapping. |
| 2400 | |
| 2401 | .. attribute:: inhibit_policy_mapping |
| 2402 | |
| 2403 | :type: int or None |
| 2404 | |
Paul Kehrer | 648c0fb | 2016-02-26 16:10:36 -0600 | [diff] [blame] | 2405 | If this field is not None, the value indicates the number of additional |
| 2406 | certificates that may appear in the chain before policy mapping is no |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 2407 | longer permitted. For example, a value of one indicates that policy |
| 2408 | mapping may be processed in certificates issued by the subject of this |
Paul Kehrer | 648c0fb | 2016-02-26 16:10:36 -0600 | [diff] [blame] | 2409 | certificate, but not in additional certificates in the chain. |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 2410 | |
Paul Kehrer | 3b95cd7 | 2015-12-22 21:40:20 -0600 | [diff] [blame] | 2411 | .. class:: CRLNumber(crl_number) |
| 2412 | |
| 2413 | .. versionadded:: 1.2 |
| 2414 | |
Paul Kehrer | e32b994 | 2015-12-22 22:26:53 -0600 | [diff] [blame] | 2415 | The CRL number is a CRL extension that conveys a monotonically increasing |
| 2416 | sequence number for a given CRL scope and CRL issuer. This extension allows |
| 2417 | users to easily determine when a particular CRL supersedes another CRL. |
| 2418 | :rfc:`5280` requires that this extension be present in conforming CRLs. |
Paul Kehrer | 3b95cd7 | 2015-12-22 21:40:20 -0600 | [diff] [blame] | 2419 | |
| 2420 | .. attribute:: oid |
| 2421 | |
| 2422 | :type: :class:`ObjectIdentifier` |
| 2423 | |
| 2424 | Returns |
| 2425 | :attr:`~cryptography.x509.oid.ExtensionOID.CRL_NUMBER`. |
| 2426 | |
| 2427 | .. attribute:: crl_number |
| 2428 | |
| 2429 | :type: int |
| 2430 | |
Paul Kehrer | eb3e2e0 | 2018-12-01 12:15:20 +0800 | [diff] [blame] | 2431 | .. class:: IssuingDistributionPoint(full_name, relative_name,\ |
| 2432 | only_contains_user_certs, only_contains_ca_certs, only_some_reasons,\ |
| 2433 | indirect_crl, only_contains_attribute_certs) |
| 2434 | |
| 2435 | .. versionadded:: 2.5 |
| 2436 | |
| 2437 | Issuing distribution point is a CRL extension that identifies the CRL |
| 2438 | distribution point and scope for a particular CRL. It indicates whether |
| 2439 | the CRL covers revocation for end entity certificates only, CA certificates |
| 2440 | only, attribute certificates only, or a limited set of reason codes. For |
| 2441 | specific details on the way this extension should be processed see |
| 2442 | :rfc:`5280`. |
| 2443 | |
| 2444 | .. attribute:: oid |
| 2445 | |
| 2446 | :type: :class:`ObjectIdentifier` |
| 2447 | |
| 2448 | Returns |
| 2449 | :attr:`~cryptography.x509.oid.ExtensionOID.ISSUING_DISTRIBUTION_POINT`. |
| 2450 | |
| 2451 | .. attribute:: only_contains_user_certs |
| 2452 | |
| 2453 | :type: bool |
| 2454 | |
| 2455 | Set to ``True`` if the CRL this extension is embedded within only |
| 2456 | contains information about user certificates. |
| 2457 | |
| 2458 | .. attribute:: only_contains_ca_certs |
| 2459 | |
| 2460 | :type: bool |
| 2461 | |
| 2462 | Set to ``True`` if the CRL this extension is embedded within only |
| 2463 | contains information about CA certificates. |
| 2464 | |
| 2465 | .. attribute:: indirect_crl |
| 2466 | |
| 2467 | :type: bool |
| 2468 | |
| 2469 | Set to ``True`` if the CRL this extension is embedded within includes |
| 2470 | certificates issued by one or more authorities other than the CRL |
| 2471 | issuer. |
| 2472 | |
| 2473 | .. attribute:: only_contains_attribute_certs |
| 2474 | |
| 2475 | :type: bool |
| 2476 | |
| 2477 | Set to ``True`` if the CRL this extension is embedded within only |
| 2478 | contains information about attribute certificates. |
| 2479 | |
| 2480 | .. attribute:: only_some_reasons |
| 2481 | |
| 2482 | :type: frozenset of :class:`ReasonFlags` or None |
| 2483 | |
| 2484 | The reasons for which the issuing distribution point is valid. None |
| 2485 | indicates that it is valid for all reasons. |
| 2486 | |
| 2487 | .. attribute:: full_name |
| 2488 | |
| 2489 | :type: list of :class:`GeneralName` instances or None |
| 2490 | |
| 2491 | This field describes methods to retrieve the CRL. At most one of |
| 2492 | ``full_name`` or ``relative_name`` will be non-None. |
| 2493 | |
| 2494 | .. attribute:: relative_name |
| 2495 | |
| 2496 | :type: :class:`RelativeDistinguishedName` or None |
| 2497 | |
| 2498 | This field describes methods to retrieve the CRL relative to the CRL |
| 2499 | issuer. At most one of ``full_name`` or ``relative_name`` will be |
| 2500 | non-None. |
| 2501 | |
Paul Kehrer | 14fd697 | 2015-12-30 10:58:25 -0600 | [diff] [blame] | 2502 | .. class:: UnrecognizedExtension |
| 2503 | |
| 2504 | .. versionadded:: 1.2 |
| 2505 | |
Alex Gaynor | d08ddd5 | 2017-05-20 09:01:54 -0700 | [diff] [blame] | 2506 | A generic extension class used to hold the raw value of extensions that |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 2507 | ``cryptography`` does not know how to parse. This can also be used when |
| 2508 | creating new certificates, CRLs, or OCSP requests and responses to encode |
| 2509 | extensions that ``cryptography`` does not know how to generate. |
Paul Kehrer | 14fd697 | 2015-12-30 10:58:25 -0600 | [diff] [blame] | 2510 | |
| 2511 | .. attribute:: oid |
| 2512 | |
| 2513 | :type: :class:`ObjectIdentifier` |
| 2514 | |
| 2515 | Returns the OID associated with this extension. |
| 2516 | |
| 2517 | .. attribute:: value |
| 2518 | |
Paul Kehrer | edfedc1 | 2018-09-14 18:24:20 -0400 | [diff] [blame] | 2519 | :type: bytes |
Paul Kehrer | 14fd697 | 2015-12-30 10:58:25 -0600 | [diff] [blame] | 2520 | |
| 2521 | Returns the DER encoded bytes payload of the extension. |
| 2522 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2523 | .. class:: CertificatePolicies(policies) |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2524 | |
| 2525 | .. versionadded:: 0.9 |
| 2526 | |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2527 | The certificate policies extension is an iterable, containing one or more |
| 2528 | :class:`PolicyInformation` instances. |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2529 | |
Paul Kehrer | 1cb9e55 | 2015-10-28 09:37:29 +0900 | [diff] [blame] | 2530 | :param list policies: A list of :class:`PolicyInformation` instances. |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2531 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 2532 | As an example of how ``CertificatePolicies`` might be used, if you wanted |
| 2533 | to check if a certificated contained the CAB Forum's "domain-validated" |
| 2534 | policy, you might write code like: |
| 2535 | |
| 2536 | .. code-block:: python |
| 2537 | |
| 2538 | def contains_domain_validated(policies): |
| 2539 | return any( |
| 2540 | policy.oid.dotted_string == "2.23.140.1.2.1" |
| 2541 | for policy in policies |
| 2542 | ) |
| 2543 | |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 2544 | .. attribute:: oid |
| 2545 | |
| 2546 | .. versionadded:: 1.0 |
| 2547 | |
| 2548 | :type: :class:`ObjectIdentifier` |
| 2549 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2550 | Returns |
| 2551 | :attr:`~cryptography.x509.oid.ExtensionOID.CERTIFICATE_POLICIES`. |
Paul Kehrer | 822f3d3 | 2015-08-06 11:47:32 +0100 | [diff] [blame] | 2552 | |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2553 | Certificate Policies Classes |
| 2554 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2555 | |
| 2556 | These classes may be present within a :class:`CertificatePolicies` instance. |
| 2557 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2558 | .. class:: PolicyInformation(policy_identifier, policy_qualifiers) |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2559 | |
| 2560 | .. versionadded:: 0.9 |
| 2561 | |
| 2562 | Contains a policy identifier and an optional list of qualifiers. |
| 2563 | |
| 2564 | .. attribute:: policy_identifier |
| 2565 | |
| 2566 | :type: :class:`ObjectIdentifier` |
| 2567 | |
| 2568 | .. attribute:: policy_qualifiers |
| 2569 | |
| 2570 | :type: list |
| 2571 | |
Paul Kehrer | ba35b3b | 2015-05-10 13:07:59 -0500 | [diff] [blame] | 2572 | A list consisting of :term:`text` and/or :class:`UserNotice` objects. |
Paul Kehrer | 3f8ddeb | 2015-05-11 00:25:36 -0500 | [diff] [blame] | 2573 | If the value is text it is a pointer to the practice statement |
| 2574 | published by the certificate authority. If it is a user notice it is |
| 2575 | meant for display to the relying party when the certificate is |
| 2576 | used. |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2577 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2578 | .. class:: UserNotice(notice_reference, explicit_text) |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2579 | |
| 2580 | .. versionadded:: 0.9 |
| 2581 | |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2582 | User notices are intended for display to a relying party when a certificate |
| 2583 | is used. In practice, few if any UIs expose this data and it is a rarely |
| 2584 | encoded component. |
| 2585 | |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2586 | .. attribute:: notice_reference |
| 2587 | |
| 2588 | :type: :class:`NoticeReference` or None |
| 2589 | |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2590 | The notice reference field names an organization and identifies, |
| 2591 | by number, a particular statement prepared by that organization. |
| 2592 | |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2593 | .. attribute:: explicit_text |
| 2594 | |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2595 | This field includes an arbitrary textual statement directly in the |
| 2596 | certificate. |
| 2597 | |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2598 | :type: :term:`text` |
| 2599 | |
Paul Kehrer | 47c32ba | 2015-10-28 09:12:07 +0900 | [diff] [blame] | 2600 | .. class:: NoticeReference(organization, notice_numbers) |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2601 | |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 2602 | Notice reference can name an organization and provide information about |
| 2603 | notices related to the certificate. For example, it might identify the |
| 2604 | organization name and notice number 1. Application software could |
| 2605 | have a notice file containing the current set of notices for the named |
| 2606 | organization; the application would then extract the notice text from the |
| 2607 | file and display it. In practice this is rarely seen. |
| 2608 | |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2609 | .. versionadded:: 0.9 |
| 2610 | |
| 2611 | .. attribute:: organization |
| 2612 | |
Paul Kehrer | 66c6170 | 2015-05-12 16:39:18 -0500 | [diff] [blame] | 2613 | :type: :term:`text` |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2614 | |
Paul Kehrer | 3f8ddeb | 2015-05-11 00:25:36 -0500 | [diff] [blame] | 2615 | .. attribute:: notice_numbers |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2616 | |
Paul Kehrer | 66c6170 | 2015-05-12 16:39:18 -0500 | [diff] [blame] | 2617 | :type: list |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2618 | |
Paul Kehrer | 66c6170 | 2015-05-12 16:39:18 -0500 | [diff] [blame] | 2619 | A list of integers. |
Paul Kehrer | 0d21092 | 2015-04-28 17:31:07 -0500 | [diff] [blame] | 2620 | |
Paul Kehrer | e5f152b | 2015-12-25 23:55:47 -0600 | [diff] [blame] | 2621 | .. _crl_entry_extensions: |
| 2622 | |
Paul Kehrer | 49bb756 | 2015-12-25 16:17:40 -0600 | [diff] [blame] | 2623 | CRL Entry Extensions |
| 2624 | ~~~~~~~~~~~~~~~~~~~~ |
| 2625 | |
| 2626 | These extensions are only valid within a :class:`RevokedCertificate` object. |
| 2627 | |
| 2628 | .. class:: CertificateIssuer(general_names) |
| 2629 | |
| 2630 | .. versionadded:: 1.2 |
| 2631 | |
| 2632 | The certificate issuer is an extension that is only valid inside |
| 2633 | :class:`~cryptography.x509.RevokedCertificate` objects. If the |
| 2634 | ``indirectCRL`` property of the parent CRL's IssuingDistributionPoint |
| 2635 | extension is set, then this extension identifies the certificate issuer |
| 2636 | associated with the revoked certificate. The object is iterable to get |
| 2637 | every element. |
| 2638 | |
| 2639 | :param list general_names: A list of :class:`GeneralName` instances. |
| 2640 | |
| 2641 | .. attribute:: oid |
| 2642 | |
| 2643 | :type: :class:`ObjectIdentifier` |
| 2644 | |
| 2645 | Returns |
| 2646 | :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CERTIFICATE_ISSUER`. |
| 2647 | |
| 2648 | .. method:: get_values_for_type(type) |
| 2649 | |
| 2650 | :param type: A :class:`GeneralName` instance. This is one of the |
| 2651 | :ref:`general name classes <general_name_classes>`. |
| 2652 | |
| 2653 | :returns: A list of values extracted from the matched general names. |
| 2654 | The type of the returned values depends on the :class:`GeneralName`. |
| 2655 | |
Paul Kehrer | 7058ece | 2015-12-25 22:28:29 -0600 | [diff] [blame] | 2656 | .. class:: CRLReason(reason) |
| 2657 | |
| 2658 | .. versionadded:: 1.2 |
| 2659 | |
| 2660 | CRL reason (also known as ``reasonCode``) is an extension that is only |
| 2661 | valid inside :class:`~cryptography.x509.RevokedCertificate` objects. It |
| 2662 | identifies a reason for the certificate revocation. |
| 2663 | |
Paul Kehrer | ce4d084 | 2017-09-20 22:14:26 +0800 | [diff] [blame] | 2664 | :param reason: An element from :class:`~cryptography.x509.ReasonFlags`. |
Paul Kehrer | 7058ece | 2015-12-25 22:28:29 -0600 | [diff] [blame] | 2665 | |
| 2666 | .. attribute:: oid |
| 2667 | |
| 2668 | :type: :class:`ObjectIdentifier` |
| 2669 | |
| 2670 | Returns |
| 2671 | :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CRL_REASON`. |
| 2672 | |
| 2673 | .. attribute:: reason |
| 2674 | |
| 2675 | :type: An element from :class:`~cryptography.x509.ReasonFlags` |
| 2676 | |
Paul Kehrer | 23c0bbc | 2015-12-25 22:35:19 -0600 | [diff] [blame] | 2677 | .. class:: InvalidityDate(invalidity_date) |
| 2678 | |
| 2679 | .. versionadded:: 1.2 |
| 2680 | |
| 2681 | Invalidity date is an extension that is only valid inside |
| 2682 | :class:`~cryptography.x509.RevokedCertificate` objects. It provides |
| 2683 | the date on which it is known or suspected that the private key was |
| 2684 | compromised or that the certificate otherwise became invalid. |
| 2685 | This date may be earlier than the revocation date in the CRL entry, |
| 2686 | which is the date at which the CA processed the revocation. |
| 2687 | |
| 2688 | :param invalidity_date: The :class:`datetime.datetime` when it is known |
| 2689 | or suspected that the private key was compromised. |
| 2690 | |
| 2691 | .. attribute:: oid |
| 2692 | |
| 2693 | :type: :class:`ObjectIdentifier` |
| 2694 | |
| 2695 | Returns |
| 2696 | :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.INVALIDITY_DATE`. |
| 2697 | |
| 2698 | .. attribute:: invalidity_date |
| 2699 | |
| 2700 | :type: :class:`datetime.datetime` |
| 2701 | |
Paul Kehrer | 0940310 | 2018-09-09 21:57:21 -0500 | [diff] [blame] | 2702 | OCSP Extensions |
| 2703 | ~~~~~~~~~~~~~~~ |
| 2704 | |
| 2705 | .. class:: OCSPNonce(nonce) |
| 2706 | |
| 2707 | .. versionadded:: 2.4 |
| 2708 | |
| 2709 | OCSP nonce is an extension that is only valid inside |
| 2710 | :class:`~cryptography.x509.ocsp.OCSPRequest` and |
| 2711 | :class:`~cryptography.x509.ocsp.OCSPResponse` objects. The nonce |
| 2712 | cryptographically binds a request and a response to prevent replay attacks. |
| 2713 | In practice nonces are rarely used in OCSP due to the desire to precompute |
| 2714 | OCSP responses at large scale. |
| 2715 | |
| 2716 | .. attribute:: oid |
| 2717 | |
| 2718 | :type: :class:`ObjectIdentifier` |
| 2719 | |
| 2720 | Returns |
| 2721 | :attr:`~cryptography.x509.oid.OCSPExtensionOID.NONCE`. |
| 2722 | |
| 2723 | .. attribute:: nonce |
| 2724 | |
| 2725 | :type: bytes |
Paul Kehrer | 49bb756 | 2015-12-25 16:17:40 -0600 | [diff] [blame] | 2726 | |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2727 | Object Identifiers |
| 2728 | ~~~~~~~~~~~~~~~~~~ |
| 2729 | |
Paul Kehrer | 4bb4649 | 2015-02-07 16:59:14 -0600 | [diff] [blame] | 2730 | X.509 elements are frequently identified by :class:`ObjectIdentifier` |
| 2731 | instances. The following common OIDs are available as constants. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2732 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2733 | .. currentmodule:: cryptography.x509.oid |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2734 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2735 | .. class:: NameOID |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2736 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2737 | These OIDs are typically seen in X.509 names. |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2738 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2739 | .. versionadded:: 1.0 |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2740 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2741 | .. attribute:: COMMON_NAME |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2742 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2743 | Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain |
| 2744 | name would be encoded here for server certificates. :rfc:`2818` |
| 2745 | deprecates this practice and names of that type should now be located |
| 2746 | in a :class:`~cryptography.x509.SubjectAlternativeName` extension. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2747 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2748 | .. attribute:: COUNTRY_NAME |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2749 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2750 | Corresponds to the dotted string ``"2.5.4.6"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2751 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2752 | .. attribute:: LOCALITY_NAME |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2753 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2754 | Corresponds to the dotted string ``"2.5.4.7"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2755 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2756 | .. attribute:: STATE_OR_PROVINCE_NAME |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2757 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2758 | Corresponds to the dotted string ``"2.5.4.8"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2759 | |
Paul Kehrer | c3b8ff6 | 2016-11-11 17:38:59 -0800 | [diff] [blame] | 2760 | .. attribute:: STREET_ADDRESS |
| 2761 | |
| 2762 | .. versionadded:: 1.6 |
| 2763 | |
| 2764 | Corresponds to the dotted string ``"2.5.4.9"``. |
| 2765 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2766 | .. attribute:: ORGANIZATION_NAME |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2767 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2768 | Corresponds to the dotted string ``"2.5.4.10"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2769 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2770 | .. attribute:: ORGANIZATIONAL_UNIT_NAME |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2771 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2772 | Corresponds to the dotted string ``"2.5.4.11"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2773 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2774 | .. attribute:: SERIAL_NUMBER |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2775 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2776 | Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from |
| 2777 | the serial number of the certificate itself (which can be obtained with |
Chelsea Winfree | e295f3a | 2016-06-02 21:15:54 -0700 | [diff] [blame] | 2778 | :func:`~cryptography.x509.Certificate.serial_number`). |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2779 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2780 | .. attribute:: SURNAME |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2781 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2782 | Corresponds to the dotted string ``"2.5.4.4"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2783 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2784 | .. attribute:: GIVEN_NAME |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2785 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2786 | Corresponds to the dotted string ``"2.5.4.42"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2787 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2788 | .. attribute:: TITLE |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2789 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2790 | Corresponds to the dotted string ``"2.5.4.12"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2791 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2792 | .. attribute:: GENERATION_QUALIFIER |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2793 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2794 | Corresponds to the dotted string ``"2.5.4.44"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2795 | |
Paul Kehrer | c7ab931 | 2016-11-12 05:00:42 -0800 | [diff] [blame] | 2796 | .. attribute:: X500_UNIQUE_IDENTIFIER |
Paul Kehrer | c3b8ff6 | 2016-11-11 17:38:59 -0800 | [diff] [blame] | 2797 | |
| 2798 | .. versionadded:: 1.6 |
| 2799 | |
| 2800 | Corresponds to the dotted string ``"2.5.4.45"``. |
| 2801 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2802 | .. attribute:: DN_QUALIFIER |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2803 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2804 | Corresponds to the dotted string ``"2.5.4.46"``. This specifies |
| 2805 | disambiguating information to add to the relative distinguished name of an |
| 2806 | entry. See :rfc:`2256`. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2807 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2808 | .. attribute:: PSEUDONYM |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2809 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2810 | Corresponds to the dotted string ``"2.5.4.65"``. |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 2811 | |
Paul Kehrer | 36d5cd6 | 2016-11-19 22:05:26 +0800 | [diff] [blame] | 2812 | .. attribute:: USER_ID |
| 2813 | |
| 2814 | .. versionadded:: 1.6 |
| 2815 | |
| 2816 | Corresponds to the dotted string ``"0.9.2342.19200300.100.1.1"``. |
| 2817 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2818 | .. attribute:: DOMAIN_COMPONENT |
Paul Kehrer | 858b9b7 | 2015-02-05 09:50:31 -0600 | [diff] [blame] | 2819 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2820 | Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string |
| 2821 | holding one component of a domain name. See :rfc:`4519`. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2822 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2823 | .. attribute:: EMAIL_ADDRESS |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2824 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2825 | Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2826 | |
Alex Gaynor | 1d3f2bf | 2015-12-19 12:15:09 -0500 | [diff] [blame] | 2827 | .. attribute:: JURISDICTION_COUNTRY_NAME |
| 2828 | |
| 2829 | Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.3"``. |
| 2830 | |
Alex Gaynor | 45e507f | 2015-12-19 13:44:23 -0500 | [diff] [blame] | 2831 | .. attribute:: JURISDICTION_LOCALITY_NAME |
| 2832 | |
| 2833 | Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.1"``. |
| 2834 | |
| 2835 | .. attribute:: JURISDICTION_STATE_OR_PROVINCE_NAME |
| 2836 | |
| 2837 | Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.2"``. |
| 2838 | |
Alex Gaynor | a2293c8 | 2015-12-19 20:49:15 -0500 | [diff] [blame] | 2839 | .. attribute:: BUSINESS_CATEGORY |
| 2840 | |
| 2841 | Corresponds to the dotted string ``"2.5.4.15"``. |
| 2842 | |
Paul Kehrer | 36d5cd6 | 2016-11-19 22:05:26 +0800 | [diff] [blame] | 2843 | .. attribute:: POSTAL_ADDRESS |
| 2844 | |
| 2845 | .. versionadded:: 1.6 |
| 2846 | |
| 2847 | Corresponds to the dotted string ``"2.5.4.16"``. |
| 2848 | |
| 2849 | .. attribute:: POSTAL_CODE |
| 2850 | |
| 2851 | .. versionadded:: 1.6 |
| 2852 | |
| 2853 | Corresponds to the dotted string ``"2.5.4.17"``. |
| 2854 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 2855 | .. attribute:: UNSTRUCTURED_NAME |
| 2856 | |
| 2857 | .. versionadded:: 3.0 |
| 2858 | |
| 2859 | Corresponds to the dotted string ``"1.2.840.113549.1.9.2"``. |
| 2860 | |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2861 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2862 | .. class:: SignatureAlgorithmOID |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2863 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2864 | .. versionadded:: 1.0 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2865 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2866 | .. attribute:: RSA_WITH_MD5 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2867 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2868 | Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is |
| 2869 | an MD5 digest signed by an RSA key. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2870 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2871 | .. attribute:: RSA_WITH_SHA1 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2872 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2873 | Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is |
| 2874 | a SHA1 digest signed by an RSA key. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2875 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2876 | .. attribute:: RSA_WITH_SHA224 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2877 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2878 | Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is |
| 2879 | a SHA224 digest signed by an RSA key. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2880 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2881 | .. attribute:: RSA_WITH_SHA256 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2882 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2883 | Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is |
| 2884 | a SHA256 digest signed by an RSA key. |
Alex Gaynor | 3aadabf | 2015-06-23 22:06:21 -0400 | [diff] [blame] | 2885 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2886 | .. attribute:: RSA_WITH_SHA384 |
Alex Gaynor | 3aadabf | 2015-06-23 22:06:21 -0400 | [diff] [blame] | 2887 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2888 | Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is |
| 2889 | a SHA384 digest signed by an RSA key. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2890 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2891 | .. attribute:: RSA_WITH_SHA512 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2892 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2893 | Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is |
| 2894 | a SHA512 digest signed by an RSA key. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2895 | |
Marti Raudsepp | 3367806 | 2018-06-30 02:27:28 +0300 | [diff] [blame] | 2896 | .. attribute:: RSASSA_PSS |
| 2897 | |
| 2898 | .. versionadded:: 2.3 |
| 2899 | |
| 2900 | Corresponds to the dotted string ``"1.2.840.113549.1.1.10"``. This is |
| 2901 | signed by an RSA key using the Probabilistic Signature Scheme (PSS) |
Alex Gaynor | e5463cc | 2019-01-18 15:19:34 -0600 | [diff] [blame] | 2902 | padding from :rfc:`4055`. The hash function and padding are defined by |
Marti Raudsepp | 3367806 | 2018-06-30 02:27:28 +0300 | [diff] [blame] | 2903 | signature algorithm parameters. |
| 2904 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2905 | .. attribute:: ECDSA_WITH_SHA1 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2906 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2907 | Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1 |
| 2908 | digest signed by an ECDSA key. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2909 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2910 | .. attribute:: ECDSA_WITH_SHA224 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2911 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2912 | Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is |
| 2913 | a SHA224 digest signed by an ECDSA key. |
| 2914 | |
| 2915 | .. attribute:: ECDSA_WITH_SHA256 |
| 2916 | |
| 2917 | Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is |
| 2918 | a SHA256 digest signed by an ECDSA key. |
| 2919 | |
| 2920 | .. attribute:: ECDSA_WITH_SHA384 |
| 2921 | |
| 2922 | Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is |
| 2923 | a SHA384 digest signed by an ECDSA key. |
| 2924 | |
| 2925 | .. attribute:: ECDSA_WITH_SHA512 |
| 2926 | |
| 2927 | Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is |
| 2928 | a SHA512 digest signed by an ECDSA key. |
| 2929 | |
| 2930 | .. attribute:: DSA_WITH_SHA1 |
| 2931 | |
| 2932 | Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is |
| 2933 | a SHA1 digest signed by a DSA key. |
| 2934 | |
| 2935 | .. attribute:: DSA_WITH_SHA224 |
| 2936 | |
| 2937 | Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is |
| 2938 | a SHA224 digest signed by a DSA key. |
| 2939 | |
| 2940 | .. attribute:: DSA_WITH_SHA256 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2941 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2942 | Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is |
| 2943 | a SHA256 digest signed by a DSA key. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2944 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 2945 | .. attribute:: ED25519 |
| 2946 | |
| 2947 | .. versionadded:: 2.8 |
| 2948 | |
| 2949 | Corresponds to the dotted string ``"1.3.101.112"``. This is a signature |
| 2950 | using an ed25519 key. |
| 2951 | |
| 2952 | .. attribute:: ED448 |
| 2953 | |
| 2954 | .. versionadded:: 2.8 |
| 2955 | |
| 2956 | Corresponds to the dotted string ``"1.3.101.113"``. This is a signature |
| 2957 | using an ed448 key. |
| 2958 | |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2959 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2960 | .. class:: ExtendedKeyUsageOID |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2961 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2962 | .. versionadded:: 1.0 |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2963 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2964 | .. attribute:: SERVER_AUTH |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2965 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2966 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used |
| 2967 | to denote that a certificate may be used for TLS web server |
| 2968 | authentication. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2969 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2970 | .. attribute:: CLIENT_AUTH |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 2971 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2972 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used |
| 2973 | to denote that a certificate may be used for TLS web client |
| 2974 | authentication. |
Paul Kehrer | ffa2a15 | 2015-03-31 08:18:25 -0500 | [diff] [blame] | 2975 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2976 | .. attribute:: CODE_SIGNING |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2977 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2978 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used |
| 2979 | to denote that a certificate may be used for code signing. |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2980 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2981 | .. attribute:: EMAIL_PROTECTION |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2982 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2983 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used |
| 2984 | to denote that a certificate may be used for email protection. |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2985 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2986 | .. attribute:: TIME_STAMPING |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2987 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2988 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used |
| 2989 | to denote that a certificate may be used for time stamping. |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2990 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2991 | .. attribute:: OCSP_SIGNING |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2992 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 2993 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used |
| 2994 | to denote that a certificate may be used for signing OCSP responses. |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 2995 | |
Alex Gaynor | b7912ee | 2017-07-03 10:07:02 -0400 | [diff] [blame] | 2996 | .. attribute:: ANY_EXTENDED_KEY_USAGE |
| 2997 | |
| 2998 | .. versionadded:: 2.0 |
| 2999 | |
| 3000 | Corresponds to the dotted string ``"2.5.29.37.0"``. This is used to |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 3001 | denote that a certificate may be used for _any_ purposes. However, |
| 3002 | :rfc:`5280` additionally notes that applications that require the |
| 3003 | presence of a particular purpose _MAY_ reject certificates that include |
| 3004 | the ``anyExtendedKeyUsage`` OID but not the particular OID expected for |
| 3005 | the application. Therefore, the presence of this OID does not mean a |
| 3006 | given application will accept the certificate for all purposes. |
Alex Gaynor | b7912ee | 2017-07-03 10:07:02 -0400 | [diff] [blame] | 3007 | |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 3008 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3009 | .. class:: AuthorityInformationAccessOID |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 3010 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3011 | .. versionadded:: 1.0 |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 3012 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3013 | .. attribute:: OCSP |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 3014 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3015 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the |
| 3016 | identifier for OCSP data in |
| 3017 | :class:`~cryptography.x509.AccessDescription` objects. |
Paul Kehrer | e1513fa | 2015-03-30 23:08:17 -0500 | [diff] [blame] | 3018 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3019 | .. attribute:: CA_ISSUERS |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 3020 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3021 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the |
| 3022 | identifier for CA issuer data in |
| 3023 | :class:`~cryptography.x509.AccessDescription` objects. |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 3024 | |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 3025 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 3026 | .. class:: SubjectInformationAccessOID |
| 3027 | |
| 3028 | .. versionadded:: 3.0 |
| 3029 | |
| 3030 | .. attribute:: CA_REPOSITORY |
| 3031 | |
| 3032 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.5"``. Used as the |
| 3033 | identifier for CA repository data in |
| 3034 | :class:`~cryptography.x509.AccessDescription` objects. |
| 3035 | |
| 3036 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3037 | .. class:: CertificatePoliciesOID |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 3038 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3039 | .. versionadded:: 1.0 |
Paul Kehrer | 3e6d558 | 2015-05-02 21:57:56 -0500 | [diff] [blame] | 3040 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3041 | .. attribute:: CPS_QUALIFIER |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 3042 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3043 | 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] | 3044 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3045 | .. attribute:: CPS_USER_NOTICE |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 3046 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3047 | 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] | 3048 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3049 | .. attribute:: ANY_POLICY |
Paul Kehrer | 2e87974 | 2015-05-02 23:09:56 -0500 | [diff] [blame] | 3050 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3051 | Corresponds to the dotted string ``"2.5.29.32.0"``. |
Paul Kehrer | 16fae76 | 2015-05-01 23:14:20 -0500 | [diff] [blame] | 3052 | |
Paul Kehrer | 16fae76 | 2015-05-01 23:14:20 -0500 | [diff] [blame] | 3053 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3054 | .. class:: ExtensionOID |
Paul Kehrer | 5553d57 | 2015-03-23 21:08:01 -0500 | [diff] [blame] | 3055 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3056 | .. versionadded:: 1.0 |
Paul Kehrer | 2bb9464 | 2015-03-21 09:54:17 -0500 | [diff] [blame] | 3057 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3058 | .. attribute:: BASIC_CONSTRAINTS |
Paul Kehrer | 2bb9464 | 2015-03-21 09:54:17 -0500 | [diff] [blame] | 3059 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3060 | Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the |
| 3061 | :class:`~cryptography.x509.BasicConstraints` extension type. |
Paul Kehrer | 2bb9464 | 2015-03-21 09:54:17 -0500 | [diff] [blame] | 3062 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3063 | .. attribute:: KEY_USAGE |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 3064 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3065 | Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the |
| 3066 | :class:`~cryptography.x509.KeyUsage` extension type. |
Paul Kehrer | cecbbba | 2015-03-30 14:58:38 -0500 | [diff] [blame] | 3067 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3068 | .. attribute:: SUBJECT_ALTERNATIVE_NAME |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 3069 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3070 | Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the |
| 3071 | :class:`~cryptography.x509.SubjectAlternativeName` extension type. |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 3072 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3073 | .. attribute:: ISSUER_ALTERNATIVE_NAME |
Paul Kehrer | 99125c9 | 2015-06-07 18:37:10 -0500 | [diff] [blame] | 3074 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3075 | Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the |
| 3076 | :class:`~cryptography.x509.IssuerAlternativeName` extension type. |
Paul Kehrer | 99125c9 | 2015-06-07 18:37:10 -0500 | [diff] [blame] | 3077 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3078 | .. attribute:: SUBJECT_KEY_IDENTIFIER |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 3079 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3080 | Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the |
| 3081 | :class:`~cryptography.x509.SubjectKeyIdentifier` extension type. |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 3082 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3083 | .. attribute:: NAME_CONSTRAINTS |
Paul Kehrer | e0017be | 2015-05-17 20:39:40 -0600 | [diff] [blame] | 3084 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3085 | Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the |
| 3086 | :class:`~cryptography.x509.NameConstraints` extension type. |
Paul Kehrer | e0017be | 2015-05-17 20:39:40 -0600 | [diff] [blame] | 3087 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3088 | .. attribute:: CRL_DISTRIBUTION_POINTS |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 3089 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3090 | Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the |
| 3091 | :class:`~cryptography.x509.CRLDistributionPoints` extension type. |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 3092 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3093 | .. attribute:: CERTIFICATE_POLICIES |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 3094 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3095 | Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the |
| 3096 | :class:`~cryptography.x509.CertificatePolicies` extension type. |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 3097 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3098 | .. attribute:: AUTHORITY_KEY_IDENTIFIER |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 3099 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3100 | Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the |
| 3101 | :class:`~cryptography.x509.AuthorityKeyIdentifier` extension type. |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 3102 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3103 | .. attribute:: EXTENDED_KEY_USAGE |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 3104 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3105 | Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the |
| 3106 | :class:`~cryptography.x509.ExtendedKeyUsage` extension type. |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 3107 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3108 | .. attribute:: AUTHORITY_INFORMATION_ACCESS |
Paul Kehrer | d4f632e | 2015-05-12 08:25:42 -0500 | [diff] [blame] | 3109 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3110 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier |
| 3111 | for the :class:`~cryptography.x509.AuthorityInformationAccess` extension |
| 3112 | type. |
Paul Kehrer | 56da2a5 | 2015-02-11 23:35:07 -0600 | [diff] [blame] | 3113 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 3114 | .. attribute:: SUBJECT_INFORMATION_ACCESS |
| 3115 | |
| 3116 | .. versionadded:: 3.0 |
| 3117 | |
| 3118 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.11"``. The |
| 3119 | identifier for the :class:`~cryptography.x509.SubjectInformationAccess` |
| 3120 | extension type. |
| 3121 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3122 | .. attribute:: INHIBIT_ANY_POLICY |
Paul Kehrer | b33de93 | 2015-08-06 23:41:05 +0100 | [diff] [blame] | 3123 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3124 | Corresponds to the dotted string ``"2.5.29.54"``. The identifier |
| 3125 | for the :class:`~cryptography.x509.InhibitAnyPolicy` extension type. |
Paul Kehrer | b33de93 | 2015-08-06 23:41:05 +0100 | [diff] [blame] | 3126 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3127 | .. attribute:: OCSP_NO_CHECK |
Paul Kehrer | 4a1038e | 2015-05-18 10:28:31 -0700 | [diff] [blame] | 3128 | |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3129 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The |
| 3130 | identifier for the :class:`~cryptography.x509.OCSPNoCheck` extension |
| 3131 | type. |
Paul Kehrer | 4a1038e | 2015-05-18 10:28:31 -0700 | [diff] [blame] | 3132 | |
Paul Kehrer | 5d66966 | 2017-09-11 09:16:34 +0800 | [diff] [blame] | 3133 | .. attribute:: TLS_FEATURE |
| 3134 | |
| 3135 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.24"``. The |
| 3136 | identifier for the :class:`~cryptography.x509.TLSFeature` extension |
| 3137 | type. |
| 3138 | |
Paul Kehrer | 51f39cb | 2015-12-21 21:17:39 -0600 | [diff] [blame] | 3139 | .. attribute:: CRL_NUMBER |
| 3140 | |
| 3141 | Corresponds to the dotted string ``"2.5.29.20"``. The identifier for |
| 3142 | the ``CRLNumber`` extension type. This extension only has meaning |
| 3143 | for certificate revocation lists. |
| 3144 | |
Paul Kehrer | 5e3cc98 | 2017-09-22 21:29:36 +0800 | [diff] [blame] | 3145 | .. attribute:: DELTA_CRL_INDICATOR |
| 3146 | |
| 3147 | .. versionadded:: 2.1 |
| 3148 | |
| 3149 | Corresponds to the dotted string ``"2.5.29.27"``. The identifier for |
| 3150 | the ``DeltaCRLIndicator`` extension type. This extension only has |
| 3151 | meaning for certificate revocation lists. |
| 3152 | |
Alex Gaynor | 9bab0ed | 2017-03-20 09:50:52 -0400 | [diff] [blame] | 3153 | .. attribute:: PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS |
| 3154 | |
| 3155 | .. versionadded:: 1.9 |
| 3156 | |
| 3157 | Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.2"``. |
| 3158 | |
Alex Gaynor | dd6b78b | 2018-08-31 18:25:52 -0500 | [diff] [blame] | 3159 | .. attribute:: PRECERT_POISON |
| 3160 | |
| 3161 | .. versionadded:: 2.4 |
| 3162 | |
| 3163 | Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.3"``. |
| 3164 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 3165 | .. attribute:: SIGNED_CERTIFICATE_TIMESTAMPS |
| 3166 | |
| 3167 | .. versionadded:: 3.0 |
| 3168 | |
| 3169 | Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.5"``. |
| 3170 | |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 3171 | .. attribute:: POLICY_CONSTRAINTS |
| 3172 | |
| 3173 | 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] | 3174 | :class:`~cryptography.x509.PolicyConstraints` extension type. |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 3175 | |
Paul Kehrer | b76bcf8 | 2017-09-24 08:44:12 +0800 | [diff] [blame] | 3176 | .. attribute:: FRESHEST_CRL |
| 3177 | |
| 3178 | Corresponds to the dotted string ``"2.5.29.46"``. The identifier for the |
| 3179 | :class:`~cryptography.x509.FreshestCRL` extension type. |
| 3180 | |
Paul Kehrer | 6e756ae | 2018-10-29 02:07:40 +0800 | [diff] [blame] | 3181 | .. attribute:: ISSUING_DISTRIBUTION_POINT |
| 3182 | |
| 3183 | .. versionadded:: 2.4 |
| 3184 | |
| 3185 | Corresponds to the dotted string ``"2.5.29.28"``. |
| 3186 | |
Paul Kehrer | 7e8fe9d | 2015-05-18 09:53:47 -0700 | [diff] [blame] | 3187 | |
Paul Kehrer | c6242dc | 2015-12-25 16:36:46 -0600 | [diff] [blame] | 3188 | .. class:: CRLEntryExtensionOID |
| 3189 | |
| 3190 | .. versionadded:: 1.2 |
| 3191 | |
| 3192 | .. attribute:: CERTIFICATE_ISSUER |
| 3193 | |
| 3194 | Corresponds to the dotted string ``"2.5.29.29"``. |
| 3195 | |
| 3196 | .. attribute:: CRL_REASON |
| 3197 | |
| 3198 | Corresponds to the dotted string ``"2.5.29.21"``. |
| 3199 | |
| 3200 | .. attribute:: INVALIDITY_DATE |
| 3201 | |
| 3202 | Corresponds to the dotted string ``"2.5.29.24"``. |
| 3203 | |
Paul Kehrer | 0940310 | 2018-09-09 21:57:21 -0500 | [diff] [blame] | 3204 | |
| 3205 | .. class:: OCSPExtensionOID |
| 3206 | |
| 3207 | .. versionadded:: 2.4 |
| 3208 | |
| 3209 | .. attribute:: NONCE |
| 3210 | |
| 3211 | Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.2"``. |
| 3212 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 3213 | |
| 3214 | .. class:: AttributeOID |
| 3215 | |
| 3216 | .. versionadded:: 3.0 |
| 3217 | |
| 3218 | .. attribute:: CHALLENGE_PASSWORD |
| 3219 | |
| 3220 | Corresponds to the dotted string ``"1.2.840.113549.1.9.7"``. |
| 3221 | |
| 3222 | .. attribute:: UNSTRUCTURED_NAME |
| 3223 | |
| 3224 | Corresponds to the dotted string ``"1.2.840.113549.1.9.2"``. |
| 3225 | |
Paul Kehrer | 8b89bcc | 2016-09-03 11:31:43 -0500 | [diff] [blame] | 3226 | Helper Functions |
| 3227 | ~~~~~~~~~~~~~~~~ |
| 3228 | .. currentmodule:: cryptography.x509 |
| 3229 | |
| 3230 | .. function:: random_serial_number() |
| 3231 | |
| 3232 | .. versionadded:: 1.6 |
| 3233 | |
| 3234 | Generates a random serial number suitable for use when constructing |
| 3235 | certificates. |
| 3236 | |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 3237 | Exceptions |
| 3238 | ~~~~~~~~~~ |
Paul Kehrer | e27f658 | 2015-08-10 18:33:38 -0500 | [diff] [blame] | 3239 | .. currentmodule:: cryptography.x509 |
Paul Kehrer | 912d3fb | 2015-01-29 11:19:22 -0600 | [diff] [blame] | 3240 | |
Paul Kehrer | e76cd27 | 2014-12-14 19:00:51 -0600 | [diff] [blame] | 3241 | .. class:: InvalidVersion |
Paul Kehrer | a68fd33 | 2014-11-27 07:08:40 -1000 | [diff] [blame] | 3242 | |
| 3243 | 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] | 3244 | |
Paul Kehrer | d5cccf7 | 2014-12-15 17:20:33 -0600 | [diff] [blame] | 3245 | .. attribute:: parsed_version |
| 3246 | |
Paul Kehrer | bbffc40 | 2014-12-17 13:33:55 -0600 | [diff] [blame] | 3247 | :type: int |
| 3248 | |
| 3249 | Returns the raw version that was parsed from the certificate. |
Paul Kehrer | d5cccf7 | 2014-12-15 17:20:33 -0600 | [diff] [blame] | 3250 | |
Paul Kehrer | fbb7ac8 | 2015-03-16 19:26:29 -0500 | [diff] [blame] | 3251 | .. class:: DuplicateExtension |
| 3252 | |
| 3253 | This is raised when more than one X.509 extension of the same type is |
| 3254 | found within a certificate. |
| 3255 | |
| 3256 | .. attribute:: oid |
| 3257 | |
| 3258 | :type: :class:`ObjectIdentifier` |
| 3259 | |
| 3260 | Returns the OID. |
| 3261 | |
Paul Kehrer | fa56a23 | 2015-03-17 13:14:03 -0500 | [diff] [blame] | 3262 | .. class:: ExtensionNotFound |
| 3263 | |
| 3264 | This is raised when calling :meth:`Extensions.get_extension_for_oid` with |
| 3265 | an extension OID that is not present in the certificate. |
| 3266 | |
| 3267 | .. attribute:: oid |
| 3268 | |
| 3269 | :type: :class:`ObjectIdentifier` |
| 3270 | |
| 3271 | Returns the OID. |
| 3272 | |
Lucia Li | c6ba99d | 2021-11-08 22:06:11 +0800 | [diff] [blame^] | 3273 | .. class:: AttributeNotFound |
| 3274 | |
| 3275 | This is raised when calling |
| 3276 | :meth:`CertificateSigningRequest.get_attribute_for_oid` with |
| 3277 | an attribute OID that is not present in the request. |
| 3278 | |
| 3279 | .. attribute:: oid |
| 3280 | |
| 3281 | :type: :class:`ObjectIdentifier` |
| 3282 | |
| 3283 | Returns the OID. |
| 3284 | |
Paul Kehrer | 9089c91 | 2015-04-20 22:15:20 -0500 | [diff] [blame] | 3285 | .. class:: UnsupportedGeneralNameType |
| 3286 | |
| 3287 | This is raised when a certificate contains an unsupported general name |
| 3288 | type in an extension. |
| 3289 | |
Paul Kehrer | bed0735 | 2015-04-21 08:31:10 -0500 | [diff] [blame] | 3290 | .. attribute:: type |
| 3291 | |
Paul Kehrer | 0a621bf | 2015-04-22 09:22:56 -0500 | [diff] [blame] | 3292 | :type: int |
| 3293 | |
| 3294 | The integer value of the unsupported type. The complete list of |
| 3295 | types can be found in `RFC 5280 section 4.2.1.6`_. |
Paul Kehrer | bed0735 | 2015-04-21 08:31:10 -0500 | [diff] [blame] | 3296 | |
Paul Kehrer | 016e08a | 2014-11-26 09:41:18 -1000 | [diff] [blame] | 3297 | |
Paul Kehrer | c7c9a43 | 2015-04-19 09:20:13 -0500 | [diff] [blame] | 3298 | .. _`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] | 3299 | .. _`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] | 3300 | .. _`CABForum Guidelines`: https://cabforum.org/baseline-requirements-documents/ |