Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(_ssl__SSLSocket_do_handshake__doc__, |
| 6 | "do_handshake($self, /)\n" |
| 7 | "--\n" |
| 8 | "\n"); |
| 9 | |
| 10 | #define _SSL__SSLSOCKET_DO_HANDSHAKE_METHODDEF \ |
| 11 | {"do_handshake", (PyCFunction)_ssl__SSLSocket_do_handshake, METH_NOARGS, _ssl__SSLSocket_do_handshake__doc__}, |
| 12 | |
| 13 | static PyObject * |
| 14 | _ssl__SSLSocket_do_handshake_impl(PySSLSocket *self); |
| 15 | |
| 16 | static PyObject * |
| 17 | _ssl__SSLSocket_do_handshake(PySSLSocket *self, PyObject *Py_UNUSED(ignored)) |
| 18 | { |
| 19 | return _ssl__SSLSocket_do_handshake_impl(self); |
| 20 | } |
| 21 | |
| 22 | PyDoc_STRVAR(_ssl__test_decode_cert__doc__, |
| 23 | "_test_decode_cert($module, path, /)\n" |
| 24 | "--\n" |
| 25 | "\n"); |
| 26 | |
| 27 | #define _SSL__TEST_DECODE_CERT_METHODDEF \ |
| 28 | {"_test_decode_cert", (PyCFunction)_ssl__test_decode_cert, METH_O, _ssl__test_decode_cert__doc__}, |
| 29 | |
| 30 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 31 | _ssl__test_decode_cert_impl(PyObject *module, PyObject *path); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 32 | |
| 33 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 34 | _ssl__test_decode_cert(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 35 | { |
| 36 | PyObject *return_value = NULL; |
| 37 | PyObject *path; |
| 38 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 39 | if (!PyUnicode_FSConverter(arg, &path)) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 40 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 41 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 42 | return_value = _ssl__test_decode_cert_impl(module, path); |
| 43 | |
| 44 | exit: |
| 45 | return return_value; |
| 46 | } |
| 47 | |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 48 | PyDoc_STRVAR(_ssl__SSLSocket_getpeercert__doc__, |
| 49 | "getpeercert($self, der=False, /)\n" |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 50 | "--\n" |
| 51 | "\n" |
| 52 | "Returns the certificate for the peer.\n" |
| 53 | "\n" |
| 54 | "If no certificate was provided, returns None. If a certificate was\n" |
| 55 | "provided, but not validated, returns an empty dictionary. Otherwise\n" |
| 56 | "returns a dict containing information about the peer certificate.\n" |
| 57 | "\n" |
| 58 | "If the optional argument is True, returns a DER-encoded copy of the\n" |
| 59 | "peer certificate, or None if no certificate was provided. This will\n" |
| 60 | "return the certificate even if it wasn\'t validated."); |
| 61 | |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 62 | #define _SSL__SSLSOCKET_GETPEERCERT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 63 | {"getpeercert", (PyCFunction)(void(*)(void))_ssl__SSLSocket_getpeercert, METH_FASTCALL, _ssl__SSLSocket_getpeercert__doc__}, |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 64 | |
| 65 | static PyObject * |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 66 | _ssl__SSLSocket_getpeercert_impl(PySSLSocket *self, int binary_mode); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 67 | |
| 68 | static PyObject * |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 69 | _ssl__SSLSocket_getpeercert(PySSLSocket *self, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 70 | { |
| 71 | PyObject *return_value = NULL; |
| 72 | int binary_mode = 0; |
| 73 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 74 | if (!_PyArg_CheckPositional("getpeercert", nargs, 0, 1)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 75 | goto exit; |
| 76 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 77 | if (nargs < 1) { |
| 78 | goto skip_optional; |
| 79 | } |
| 80 | binary_mode = PyObject_IsTrue(args[0]); |
| 81 | if (binary_mode < 0) { |
| 82 | goto exit; |
| 83 | } |
| 84 | skip_optional: |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 85 | return_value = _ssl__SSLSocket_getpeercert_impl(self, binary_mode); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 86 | |
| 87 | exit: |
| 88 | return return_value; |
| 89 | } |
| 90 | |
| 91 | PyDoc_STRVAR(_ssl__SSLSocket_shared_ciphers__doc__, |
| 92 | "shared_ciphers($self, /)\n" |
| 93 | "--\n" |
| 94 | "\n"); |
| 95 | |
| 96 | #define _SSL__SSLSOCKET_SHARED_CIPHERS_METHODDEF \ |
| 97 | {"shared_ciphers", (PyCFunction)_ssl__SSLSocket_shared_ciphers, METH_NOARGS, _ssl__SSLSocket_shared_ciphers__doc__}, |
| 98 | |
| 99 | static PyObject * |
| 100 | _ssl__SSLSocket_shared_ciphers_impl(PySSLSocket *self); |
| 101 | |
| 102 | static PyObject * |
| 103 | _ssl__SSLSocket_shared_ciphers(PySSLSocket *self, PyObject *Py_UNUSED(ignored)) |
| 104 | { |
| 105 | return _ssl__SSLSocket_shared_ciphers_impl(self); |
| 106 | } |
| 107 | |
| 108 | PyDoc_STRVAR(_ssl__SSLSocket_cipher__doc__, |
| 109 | "cipher($self, /)\n" |
| 110 | "--\n" |
| 111 | "\n"); |
| 112 | |
| 113 | #define _SSL__SSLSOCKET_CIPHER_METHODDEF \ |
| 114 | {"cipher", (PyCFunction)_ssl__SSLSocket_cipher, METH_NOARGS, _ssl__SSLSocket_cipher__doc__}, |
| 115 | |
| 116 | static PyObject * |
| 117 | _ssl__SSLSocket_cipher_impl(PySSLSocket *self); |
| 118 | |
| 119 | static PyObject * |
| 120 | _ssl__SSLSocket_cipher(PySSLSocket *self, PyObject *Py_UNUSED(ignored)) |
| 121 | { |
| 122 | return _ssl__SSLSocket_cipher_impl(self); |
| 123 | } |
| 124 | |
| 125 | PyDoc_STRVAR(_ssl__SSLSocket_version__doc__, |
| 126 | "version($self, /)\n" |
| 127 | "--\n" |
| 128 | "\n"); |
| 129 | |
| 130 | #define _SSL__SSLSOCKET_VERSION_METHODDEF \ |
| 131 | {"version", (PyCFunction)_ssl__SSLSocket_version, METH_NOARGS, _ssl__SSLSocket_version__doc__}, |
| 132 | |
| 133 | static PyObject * |
| 134 | _ssl__SSLSocket_version_impl(PySSLSocket *self); |
| 135 | |
| 136 | static PyObject * |
| 137 | _ssl__SSLSocket_version(PySSLSocket *self, PyObject *Py_UNUSED(ignored)) |
| 138 | { |
| 139 | return _ssl__SSLSocket_version_impl(self); |
| 140 | } |
| 141 | |
Christian Heimes | 29eab55 | 2018-02-25 12:31:33 +0100 | [diff] [blame] | 142 | #if (HAVE_NPN) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 143 | |
| 144 | PyDoc_STRVAR(_ssl__SSLSocket_selected_npn_protocol__doc__, |
| 145 | "selected_npn_protocol($self, /)\n" |
| 146 | "--\n" |
| 147 | "\n"); |
| 148 | |
| 149 | #define _SSL__SSLSOCKET_SELECTED_NPN_PROTOCOL_METHODDEF \ |
| 150 | {"selected_npn_protocol", (PyCFunction)_ssl__SSLSocket_selected_npn_protocol, METH_NOARGS, _ssl__SSLSocket_selected_npn_protocol__doc__}, |
| 151 | |
| 152 | static PyObject * |
| 153 | _ssl__SSLSocket_selected_npn_protocol_impl(PySSLSocket *self); |
| 154 | |
| 155 | static PyObject * |
| 156 | _ssl__SSLSocket_selected_npn_protocol(PySSLSocket *self, PyObject *Py_UNUSED(ignored)) |
| 157 | { |
| 158 | return _ssl__SSLSocket_selected_npn_protocol_impl(self); |
| 159 | } |
| 160 | |
Christian Heimes | 29eab55 | 2018-02-25 12:31:33 +0100 | [diff] [blame] | 161 | #endif /* (HAVE_NPN) */ |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 162 | |
Christian Heimes | 29eab55 | 2018-02-25 12:31:33 +0100 | [diff] [blame] | 163 | #if (HAVE_ALPN) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 164 | |
| 165 | PyDoc_STRVAR(_ssl__SSLSocket_selected_alpn_protocol__doc__, |
| 166 | "selected_alpn_protocol($self, /)\n" |
| 167 | "--\n" |
| 168 | "\n"); |
| 169 | |
| 170 | #define _SSL__SSLSOCKET_SELECTED_ALPN_PROTOCOL_METHODDEF \ |
| 171 | {"selected_alpn_protocol", (PyCFunction)_ssl__SSLSocket_selected_alpn_protocol, METH_NOARGS, _ssl__SSLSocket_selected_alpn_protocol__doc__}, |
| 172 | |
| 173 | static PyObject * |
| 174 | _ssl__SSLSocket_selected_alpn_protocol_impl(PySSLSocket *self); |
| 175 | |
| 176 | static PyObject * |
| 177 | _ssl__SSLSocket_selected_alpn_protocol(PySSLSocket *self, PyObject *Py_UNUSED(ignored)) |
| 178 | { |
| 179 | return _ssl__SSLSocket_selected_alpn_protocol_impl(self); |
| 180 | } |
| 181 | |
Christian Heimes | 29eab55 | 2018-02-25 12:31:33 +0100 | [diff] [blame] | 182 | #endif /* (HAVE_ALPN) */ |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 183 | |
| 184 | PyDoc_STRVAR(_ssl__SSLSocket_compression__doc__, |
| 185 | "compression($self, /)\n" |
| 186 | "--\n" |
| 187 | "\n"); |
| 188 | |
| 189 | #define _SSL__SSLSOCKET_COMPRESSION_METHODDEF \ |
| 190 | {"compression", (PyCFunction)_ssl__SSLSocket_compression, METH_NOARGS, _ssl__SSLSocket_compression__doc__}, |
| 191 | |
| 192 | static PyObject * |
| 193 | _ssl__SSLSocket_compression_impl(PySSLSocket *self); |
| 194 | |
| 195 | static PyObject * |
| 196 | _ssl__SSLSocket_compression(PySSLSocket *self, PyObject *Py_UNUSED(ignored)) |
| 197 | { |
| 198 | return _ssl__SSLSocket_compression_impl(self); |
| 199 | } |
| 200 | |
| 201 | PyDoc_STRVAR(_ssl__SSLSocket_write__doc__, |
| 202 | "write($self, b, /)\n" |
| 203 | "--\n" |
| 204 | "\n" |
| 205 | "Writes the bytes-like object b into the SSL object.\n" |
| 206 | "\n" |
| 207 | "Returns the number of bytes written."); |
| 208 | |
| 209 | #define _SSL__SSLSOCKET_WRITE_METHODDEF \ |
| 210 | {"write", (PyCFunction)_ssl__SSLSocket_write, METH_O, _ssl__SSLSocket_write__doc__}, |
| 211 | |
| 212 | static PyObject * |
| 213 | _ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b); |
| 214 | |
| 215 | static PyObject * |
| 216 | _ssl__SSLSocket_write(PySSLSocket *self, PyObject *arg) |
| 217 | { |
| 218 | PyObject *return_value = NULL; |
| 219 | Py_buffer b = {NULL, NULL}; |
| 220 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 221 | if (PyObject_GetBuffer(arg, &b, PyBUF_SIMPLE) != 0) { |
| 222 | goto exit; |
| 223 | } |
| 224 | if (!PyBuffer_IsContiguous(&b, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 225 | _PyArg_BadArgument("write", "argument", "contiguous buffer", arg); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 226 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 227 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 228 | return_value = _ssl__SSLSocket_write_impl(self, &b); |
| 229 | |
| 230 | exit: |
| 231 | /* Cleanup for b */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 232 | if (b.obj) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 233 | PyBuffer_Release(&b); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 234 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 235 | |
| 236 | return return_value; |
| 237 | } |
| 238 | |
| 239 | PyDoc_STRVAR(_ssl__SSLSocket_pending__doc__, |
| 240 | "pending($self, /)\n" |
| 241 | "--\n" |
| 242 | "\n" |
| 243 | "Returns the number of already decrypted bytes available for read, pending on the connection."); |
| 244 | |
| 245 | #define _SSL__SSLSOCKET_PENDING_METHODDEF \ |
| 246 | {"pending", (PyCFunction)_ssl__SSLSocket_pending, METH_NOARGS, _ssl__SSLSocket_pending__doc__}, |
| 247 | |
| 248 | static PyObject * |
| 249 | _ssl__SSLSocket_pending_impl(PySSLSocket *self); |
| 250 | |
| 251 | static PyObject * |
| 252 | _ssl__SSLSocket_pending(PySSLSocket *self, PyObject *Py_UNUSED(ignored)) |
| 253 | { |
| 254 | return _ssl__SSLSocket_pending_impl(self); |
| 255 | } |
| 256 | |
| 257 | PyDoc_STRVAR(_ssl__SSLSocket_read__doc__, |
| 258 | "read(size, [buffer])\n" |
| 259 | "Read up to size bytes from the SSL socket."); |
| 260 | |
| 261 | #define _SSL__SSLSOCKET_READ_METHODDEF \ |
| 262 | {"read", (PyCFunction)_ssl__SSLSocket_read, METH_VARARGS, _ssl__SSLSocket_read__doc__}, |
| 263 | |
| 264 | static PyObject * |
| 265 | _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1, |
| 266 | Py_buffer *buffer); |
| 267 | |
| 268 | static PyObject * |
| 269 | _ssl__SSLSocket_read(PySSLSocket *self, PyObject *args) |
| 270 | { |
| 271 | PyObject *return_value = NULL; |
| 272 | int len; |
| 273 | int group_right_1 = 0; |
| 274 | Py_buffer buffer = {NULL, NULL}; |
| 275 | |
| 276 | switch (PyTuple_GET_SIZE(args)) { |
| 277 | case 1: |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 278 | if (!PyArg_ParseTuple(args, "i:read", &len)) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 279 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 280 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 281 | break; |
| 282 | case 2: |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 283 | if (!PyArg_ParseTuple(args, "iw*:read", &len, &buffer)) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 284 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 285 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 286 | group_right_1 = 1; |
| 287 | break; |
| 288 | default: |
| 289 | PyErr_SetString(PyExc_TypeError, "_ssl._SSLSocket.read requires 1 to 2 arguments"); |
| 290 | goto exit; |
| 291 | } |
| 292 | return_value = _ssl__SSLSocket_read_impl(self, len, group_right_1, &buffer); |
| 293 | |
| 294 | exit: |
| 295 | /* Cleanup for buffer */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 296 | if (buffer.obj) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 297 | PyBuffer_Release(&buffer); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 298 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 299 | |
| 300 | return return_value; |
| 301 | } |
| 302 | |
| 303 | PyDoc_STRVAR(_ssl__SSLSocket_shutdown__doc__, |
| 304 | "shutdown($self, /)\n" |
| 305 | "--\n" |
| 306 | "\n" |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 307 | "Does the SSL shutdown handshake with the remote end."); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 308 | |
| 309 | #define _SSL__SSLSOCKET_SHUTDOWN_METHODDEF \ |
| 310 | {"shutdown", (PyCFunction)_ssl__SSLSocket_shutdown, METH_NOARGS, _ssl__SSLSocket_shutdown__doc__}, |
| 311 | |
| 312 | static PyObject * |
| 313 | _ssl__SSLSocket_shutdown_impl(PySSLSocket *self); |
| 314 | |
| 315 | static PyObject * |
| 316 | _ssl__SSLSocket_shutdown(PySSLSocket *self, PyObject *Py_UNUSED(ignored)) |
| 317 | { |
| 318 | return _ssl__SSLSocket_shutdown_impl(self); |
| 319 | } |
| 320 | |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 321 | PyDoc_STRVAR(_ssl__SSLSocket_get_channel_binding__doc__, |
| 322 | "get_channel_binding($self, /, cb_type=\'tls-unique\')\n" |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 323 | "--\n" |
| 324 | "\n" |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 325 | "Get channel binding data for current connection.\n" |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 326 | "\n" |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 327 | "Raise ValueError if the requested `cb_type` is not supported. Return bytes\n" |
| 328 | "of the data or None if the data is not available (e.g. before the handshake).\n" |
| 329 | "Only \'tls-unique\' channel binding data from RFC 5929 is supported."); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 330 | |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 331 | #define _SSL__SSLSOCKET_GET_CHANNEL_BINDING_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 332 | {"get_channel_binding", (PyCFunction)(void(*)(void))_ssl__SSLSocket_get_channel_binding, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLSocket_get_channel_binding__doc__}, |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 333 | |
| 334 | static PyObject * |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 335 | _ssl__SSLSocket_get_channel_binding_impl(PySSLSocket *self, |
| 336 | const char *cb_type); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 337 | |
| 338 | static PyObject * |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 339 | _ssl__SSLSocket_get_channel_binding(PySSLSocket *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 340 | { |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 341 | PyObject *return_value = NULL; |
| 342 | static const char * const _keywords[] = {"cb_type", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 343 | static _PyArg_Parser _parser = {NULL, _keywords, "get_channel_binding", 0}; |
| 344 | PyObject *argsbuf[1]; |
| 345 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 346 | const char *cb_type = "tls-unique"; |
| 347 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 348 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); |
| 349 | if (!args) { |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 350 | goto exit; |
| 351 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 352 | if (!noptargs) { |
| 353 | goto skip_optional_pos; |
| 354 | } |
| 355 | if (!PyUnicode_Check(args[0])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 356 | _PyArg_BadArgument("get_channel_binding", "argument 'cb_type'", "str", args[0]); |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 357 | goto exit; |
| 358 | } |
| 359 | Py_ssize_t cb_type_length; |
| 360 | cb_type = PyUnicode_AsUTF8AndSize(args[0], &cb_type_length); |
| 361 | if (cb_type == NULL) { |
| 362 | goto exit; |
| 363 | } |
| 364 | if (strlen(cb_type) != (size_t)cb_type_length) { |
| 365 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 366 | goto exit; |
| 367 | } |
| 368 | skip_optional_pos: |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 369 | return_value = _ssl__SSLSocket_get_channel_binding_impl(self, cb_type); |
| 370 | |
| 371 | exit: |
| 372 | return return_value; |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 373 | } |
| 374 | |
Christian Heimes | 9fb051f | 2018-09-23 08:32:31 +0200 | [diff] [blame] | 375 | PyDoc_STRVAR(_ssl__SSLSocket_verify_client_post_handshake__doc__, |
| 376 | "verify_client_post_handshake($self, /)\n" |
| 377 | "--\n" |
| 378 | "\n" |
| 379 | "Initiate TLS 1.3 post-handshake authentication"); |
| 380 | |
| 381 | #define _SSL__SSLSOCKET_VERIFY_CLIENT_POST_HANDSHAKE_METHODDEF \ |
| 382 | {"verify_client_post_handshake", (PyCFunction)_ssl__SSLSocket_verify_client_post_handshake, METH_NOARGS, _ssl__SSLSocket_verify_client_post_handshake__doc__}, |
| 383 | |
| 384 | static PyObject * |
| 385 | _ssl__SSLSocket_verify_client_post_handshake_impl(PySSLSocket *self); |
| 386 | |
| 387 | static PyObject * |
| 388 | _ssl__SSLSocket_verify_client_post_handshake(PySSLSocket *self, PyObject *Py_UNUSED(ignored)) |
| 389 | { |
| 390 | return _ssl__SSLSocket_verify_client_post_handshake_impl(self); |
| 391 | } |
| 392 | |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 393 | static PyObject * |
| 394 | _ssl__SSLContext_impl(PyTypeObject *type, int proto_version); |
| 395 | |
| 396 | static PyObject * |
| 397 | _ssl__SSLContext(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 398 | { |
| 399 | PyObject *return_value = NULL; |
| 400 | int proto_version; |
| 401 | |
Christian Heimes | 5c36da7 | 2020-11-20 09:40:12 +0100 | [diff] [blame^] | 402 | if ((type == PySSLContext_Type) && |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 403 | !_PyArg_NoKeywords("_SSLContext", kwargs)) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 404 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 405 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 406 | if (!_PyArg_CheckPositional("_SSLContext", PyTuple_GET_SIZE(args), 1, 1)) { |
| 407 | goto exit; |
| 408 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 409 | proto_version = _PyLong_AsInt(PyTuple_GET_ITEM(args, 0)); |
| 410 | if (proto_version == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 411 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 412 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 413 | return_value = _ssl__SSLContext_impl(type, proto_version); |
| 414 | |
| 415 | exit: |
| 416 | return return_value; |
| 417 | } |
| 418 | |
| 419 | PyDoc_STRVAR(_ssl__SSLContext_set_ciphers__doc__, |
| 420 | "set_ciphers($self, cipherlist, /)\n" |
| 421 | "--\n" |
| 422 | "\n"); |
| 423 | |
| 424 | #define _SSL__SSLCONTEXT_SET_CIPHERS_METHODDEF \ |
| 425 | {"set_ciphers", (PyCFunction)_ssl__SSLContext_set_ciphers, METH_O, _ssl__SSLContext_set_ciphers__doc__}, |
| 426 | |
| 427 | static PyObject * |
| 428 | _ssl__SSLContext_set_ciphers_impl(PySSLContext *self, const char *cipherlist); |
| 429 | |
| 430 | static PyObject * |
| 431 | _ssl__SSLContext_set_ciphers(PySSLContext *self, PyObject *arg) |
| 432 | { |
| 433 | PyObject *return_value = NULL; |
| 434 | const char *cipherlist; |
| 435 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 436 | if (!PyUnicode_Check(arg)) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 437 | _PyArg_BadArgument("set_ciphers", "argument", "str", arg); |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 438 | goto exit; |
| 439 | } |
| 440 | Py_ssize_t cipherlist_length; |
| 441 | cipherlist = PyUnicode_AsUTF8AndSize(arg, &cipherlist_length); |
| 442 | if (cipherlist == NULL) { |
| 443 | goto exit; |
| 444 | } |
| 445 | if (strlen(cipherlist) != (size_t)cipherlist_length) { |
| 446 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 447 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 448 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 449 | return_value = _ssl__SSLContext_set_ciphers_impl(self, cipherlist); |
| 450 | |
| 451 | exit: |
| 452 | return return_value; |
| 453 | } |
| 454 | |
Christian Heimes | 25bfcd5 | 2016-09-06 00:04:45 +0200 | [diff] [blame] | 455 | #if (OPENSSL_VERSION_NUMBER >= 0x10002000UL) |
| 456 | |
| 457 | PyDoc_STRVAR(_ssl__SSLContext_get_ciphers__doc__, |
| 458 | "get_ciphers($self, /)\n" |
| 459 | "--\n" |
| 460 | "\n"); |
| 461 | |
| 462 | #define _SSL__SSLCONTEXT_GET_CIPHERS_METHODDEF \ |
| 463 | {"get_ciphers", (PyCFunction)_ssl__SSLContext_get_ciphers, METH_NOARGS, _ssl__SSLContext_get_ciphers__doc__}, |
| 464 | |
| 465 | static PyObject * |
| 466 | _ssl__SSLContext_get_ciphers_impl(PySSLContext *self); |
| 467 | |
| 468 | static PyObject * |
| 469 | _ssl__SSLContext_get_ciphers(PySSLContext *self, PyObject *Py_UNUSED(ignored)) |
| 470 | { |
| 471 | return _ssl__SSLContext_get_ciphers_impl(self); |
| 472 | } |
| 473 | |
| 474 | #endif /* (OPENSSL_VERSION_NUMBER >= 0x10002000UL) */ |
| 475 | |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 476 | PyDoc_STRVAR(_ssl__SSLContext__set_npn_protocols__doc__, |
| 477 | "_set_npn_protocols($self, protos, /)\n" |
| 478 | "--\n" |
| 479 | "\n"); |
| 480 | |
| 481 | #define _SSL__SSLCONTEXT__SET_NPN_PROTOCOLS_METHODDEF \ |
| 482 | {"_set_npn_protocols", (PyCFunction)_ssl__SSLContext__set_npn_protocols, METH_O, _ssl__SSLContext__set_npn_protocols__doc__}, |
| 483 | |
| 484 | static PyObject * |
| 485 | _ssl__SSLContext__set_npn_protocols_impl(PySSLContext *self, |
| 486 | Py_buffer *protos); |
| 487 | |
| 488 | static PyObject * |
| 489 | _ssl__SSLContext__set_npn_protocols(PySSLContext *self, PyObject *arg) |
| 490 | { |
| 491 | PyObject *return_value = NULL; |
| 492 | Py_buffer protos = {NULL, NULL}; |
| 493 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 494 | if (PyObject_GetBuffer(arg, &protos, PyBUF_SIMPLE) != 0) { |
| 495 | goto exit; |
| 496 | } |
| 497 | if (!PyBuffer_IsContiguous(&protos, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 498 | _PyArg_BadArgument("_set_npn_protocols", "argument", "contiguous buffer", arg); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 499 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 500 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 501 | return_value = _ssl__SSLContext__set_npn_protocols_impl(self, &protos); |
| 502 | |
| 503 | exit: |
| 504 | /* Cleanup for protos */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 505 | if (protos.obj) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 506 | PyBuffer_Release(&protos); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 507 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 508 | |
| 509 | return return_value; |
| 510 | } |
| 511 | |
| 512 | PyDoc_STRVAR(_ssl__SSLContext__set_alpn_protocols__doc__, |
| 513 | "_set_alpn_protocols($self, protos, /)\n" |
| 514 | "--\n" |
| 515 | "\n"); |
| 516 | |
| 517 | #define _SSL__SSLCONTEXT__SET_ALPN_PROTOCOLS_METHODDEF \ |
| 518 | {"_set_alpn_protocols", (PyCFunction)_ssl__SSLContext__set_alpn_protocols, METH_O, _ssl__SSLContext__set_alpn_protocols__doc__}, |
| 519 | |
| 520 | static PyObject * |
| 521 | _ssl__SSLContext__set_alpn_protocols_impl(PySSLContext *self, |
| 522 | Py_buffer *protos); |
| 523 | |
| 524 | static PyObject * |
| 525 | _ssl__SSLContext__set_alpn_protocols(PySSLContext *self, PyObject *arg) |
| 526 | { |
| 527 | PyObject *return_value = NULL; |
| 528 | Py_buffer protos = {NULL, NULL}; |
| 529 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 530 | if (PyObject_GetBuffer(arg, &protos, PyBUF_SIMPLE) != 0) { |
| 531 | goto exit; |
| 532 | } |
| 533 | if (!PyBuffer_IsContiguous(&protos, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 534 | _PyArg_BadArgument("_set_alpn_protocols", "argument", "contiguous buffer", arg); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 535 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 536 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 537 | return_value = _ssl__SSLContext__set_alpn_protocols_impl(self, &protos); |
| 538 | |
| 539 | exit: |
| 540 | /* Cleanup for protos */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 541 | if (protos.obj) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 542 | PyBuffer_Release(&protos); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 543 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 544 | |
| 545 | return return_value; |
| 546 | } |
| 547 | |
| 548 | PyDoc_STRVAR(_ssl__SSLContext_load_cert_chain__doc__, |
| 549 | "load_cert_chain($self, /, certfile, keyfile=None, password=None)\n" |
| 550 | "--\n" |
| 551 | "\n"); |
| 552 | |
| 553 | #define _SSL__SSLCONTEXT_LOAD_CERT_CHAIN_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 554 | {"load_cert_chain", (PyCFunction)(void(*)(void))_ssl__SSLContext_load_cert_chain, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLContext_load_cert_chain__doc__}, |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 555 | |
| 556 | static PyObject * |
| 557 | _ssl__SSLContext_load_cert_chain_impl(PySSLContext *self, PyObject *certfile, |
| 558 | PyObject *keyfile, PyObject *password); |
| 559 | |
| 560 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 561 | _ssl__SSLContext_load_cert_chain(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 562 | { |
| 563 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 564 | static const char * const _keywords[] = {"certfile", "keyfile", "password", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 565 | static _PyArg_Parser _parser = {NULL, _keywords, "load_cert_chain", 0}; |
| 566 | PyObject *argsbuf[3]; |
| 567 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 568 | PyObject *certfile; |
Serhiy Storchaka | 279f446 | 2019-09-14 12:24:05 +0300 | [diff] [blame] | 569 | PyObject *keyfile = Py_None; |
| 570 | PyObject *password = Py_None; |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 571 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 572 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf); |
| 573 | if (!args) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 574 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 575 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 576 | certfile = args[0]; |
| 577 | if (!noptargs) { |
| 578 | goto skip_optional_pos; |
| 579 | } |
| 580 | if (args[1]) { |
| 581 | keyfile = args[1]; |
| 582 | if (!--noptargs) { |
| 583 | goto skip_optional_pos; |
| 584 | } |
| 585 | } |
| 586 | password = args[2]; |
| 587 | skip_optional_pos: |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 588 | return_value = _ssl__SSLContext_load_cert_chain_impl(self, certfile, keyfile, password); |
| 589 | |
| 590 | exit: |
| 591 | return return_value; |
| 592 | } |
| 593 | |
| 594 | PyDoc_STRVAR(_ssl__SSLContext_load_verify_locations__doc__, |
| 595 | "load_verify_locations($self, /, cafile=None, capath=None, cadata=None)\n" |
| 596 | "--\n" |
| 597 | "\n"); |
| 598 | |
| 599 | #define _SSL__SSLCONTEXT_LOAD_VERIFY_LOCATIONS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 600 | {"load_verify_locations", (PyCFunction)(void(*)(void))_ssl__SSLContext_load_verify_locations, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLContext_load_verify_locations__doc__}, |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 601 | |
| 602 | static PyObject * |
| 603 | _ssl__SSLContext_load_verify_locations_impl(PySSLContext *self, |
| 604 | PyObject *cafile, |
| 605 | PyObject *capath, |
| 606 | PyObject *cadata); |
| 607 | |
| 608 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 609 | _ssl__SSLContext_load_verify_locations(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 610 | { |
| 611 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 612 | static const char * const _keywords[] = {"cafile", "capath", "cadata", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 613 | static _PyArg_Parser _parser = {NULL, _keywords, "load_verify_locations", 0}; |
| 614 | PyObject *argsbuf[3]; |
| 615 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Serhiy Storchaka | 279f446 | 2019-09-14 12:24:05 +0300 | [diff] [blame] | 616 | PyObject *cafile = Py_None; |
| 617 | PyObject *capath = Py_None; |
| 618 | PyObject *cadata = Py_None; |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 619 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 620 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 3, 0, argsbuf); |
| 621 | if (!args) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 622 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 623 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 624 | if (!noptargs) { |
| 625 | goto skip_optional_pos; |
| 626 | } |
| 627 | if (args[0]) { |
| 628 | cafile = args[0]; |
| 629 | if (!--noptargs) { |
| 630 | goto skip_optional_pos; |
| 631 | } |
| 632 | } |
| 633 | if (args[1]) { |
| 634 | capath = args[1]; |
| 635 | if (!--noptargs) { |
| 636 | goto skip_optional_pos; |
| 637 | } |
| 638 | } |
| 639 | cadata = args[2]; |
| 640 | skip_optional_pos: |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 641 | return_value = _ssl__SSLContext_load_verify_locations_impl(self, cafile, capath, cadata); |
| 642 | |
| 643 | exit: |
| 644 | return return_value; |
| 645 | } |
| 646 | |
| 647 | PyDoc_STRVAR(_ssl__SSLContext_load_dh_params__doc__, |
| 648 | "load_dh_params($self, path, /)\n" |
| 649 | "--\n" |
| 650 | "\n"); |
| 651 | |
| 652 | #define _SSL__SSLCONTEXT_LOAD_DH_PARAMS_METHODDEF \ |
| 653 | {"load_dh_params", (PyCFunction)_ssl__SSLContext_load_dh_params, METH_O, _ssl__SSLContext_load_dh_params__doc__}, |
| 654 | |
| 655 | PyDoc_STRVAR(_ssl__SSLContext__wrap_socket__doc__, |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 656 | "_wrap_socket($self, /, sock, server_side, server_hostname=None, *,\n" |
| 657 | " owner=None, session=None)\n" |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 658 | "--\n" |
| 659 | "\n"); |
| 660 | |
| 661 | #define _SSL__SSLCONTEXT__WRAP_SOCKET_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 662 | {"_wrap_socket", (PyCFunction)(void(*)(void))_ssl__SSLContext__wrap_socket, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLContext__wrap_socket__doc__}, |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 663 | |
| 664 | static PyObject * |
| 665 | _ssl__SSLContext__wrap_socket_impl(PySSLContext *self, PyObject *sock, |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 666 | int server_side, PyObject *hostname_obj, |
| 667 | PyObject *owner, PyObject *session); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 668 | |
| 669 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 670 | _ssl__SSLContext__wrap_socket(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 671 | { |
| 672 | PyObject *return_value = NULL; |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 673 | static const char * const _keywords[] = {"sock", "server_side", "server_hostname", "owner", "session", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 674 | static _PyArg_Parser _parser = {NULL, _keywords, "_wrap_socket", 0}; |
| 675 | PyObject *argsbuf[5]; |
| 676 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 677 | PyObject *sock; |
| 678 | int server_side; |
| 679 | PyObject *hostname_obj = Py_None; |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 680 | PyObject *owner = Py_None; |
| 681 | PyObject *session = Py_None; |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 682 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 683 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); |
| 684 | if (!args) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 685 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 686 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 687 | if (!PyObject_TypeCheck(args[0], PySocketModule.Sock_Type)) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 688 | _PyArg_BadArgument("_wrap_socket", "argument 'sock'", (PySocketModule.Sock_Type)->tp_name, args[0]); |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 689 | goto exit; |
| 690 | } |
| 691 | sock = args[0]; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 692 | server_side = _PyLong_AsInt(args[1]); |
| 693 | if (server_side == -1 && PyErr_Occurred()) { |
| 694 | goto exit; |
| 695 | } |
| 696 | if (!noptargs) { |
| 697 | goto skip_optional_pos; |
| 698 | } |
| 699 | if (args[2]) { |
| 700 | hostname_obj = args[2]; |
| 701 | if (!--noptargs) { |
| 702 | goto skip_optional_pos; |
| 703 | } |
| 704 | } |
| 705 | skip_optional_pos: |
| 706 | if (!noptargs) { |
| 707 | goto skip_optional_kwonly; |
| 708 | } |
| 709 | if (args[3]) { |
| 710 | owner = args[3]; |
| 711 | if (!--noptargs) { |
| 712 | goto skip_optional_kwonly; |
| 713 | } |
| 714 | } |
| 715 | session = args[4]; |
| 716 | skip_optional_kwonly: |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 717 | return_value = _ssl__SSLContext__wrap_socket_impl(self, sock, server_side, hostname_obj, owner, session); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 718 | |
| 719 | exit: |
| 720 | return return_value; |
| 721 | } |
| 722 | |
| 723 | PyDoc_STRVAR(_ssl__SSLContext__wrap_bio__doc__, |
| 724 | "_wrap_bio($self, /, incoming, outgoing, server_side,\n" |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 725 | " server_hostname=None, *, owner=None, session=None)\n" |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 726 | "--\n" |
| 727 | "\n"); |
| 728 | |
| 729 | #define _SSL__SSLCONTEXT__WRAP_BIO_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 730 | {"_wrap_bio", (PyCFunction)(void(*)(void))_ssl__SSLContext__wrap_bio, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLContext__wrap_bio__doc__}, |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 731 | |
| 732 | static PyObject * |
| 733 | _ssl__SSLContext__wrap_bio_impl(PySSLContext *self, PySSLMemoryBIO *incoming, |
| 734 | PySSLMemoryBIO *outgoing, int server_side, |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 735 | PyObject *hostname_obj, PyObject *owner, |
| 736 | PyObject *session); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 737 | |
| 738 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 739 | _ssl__SSLContext__wrap_bio(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 740 | { |
| 741 | PyObject *return_value = NULL; |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 742 | static const char * const _keywords[] = {"incoming", "outgoing", "server_side", "server_hostname", "owner", "session", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 743 | static _PyArg_Parser _parser = {NULL, _keywords, "_wrap_bio", 0}; |
| 744 | PyObject *argsbuf[6]; |
| 745 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 746 | PySSLMemoryBIO *incoming; |
| 747 | PySSLMemoryBIO *outgoing; |
| 748 | int server_side; |
| 749 | PyObject *hostname_obj = Py_None; |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 750 | PyObject *owner = Py_None; |
| 751 | PyObject *session = Py_None; |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 752 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 753 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 4, 0, argsbuf); |
| 754 | if (!args) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 755 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 756 | } |
Christian Heimes | 5c36da7 | 2020-11-20 09:40:12 +0100 | [diff] [blame^] | 757 | if (!PyObject_TypeCheck(args[0], PySSLMemoryBIO_Type)) { |
| 758 | _PyArg_BadArgument("_wrap_bio", "argument 'incoming'", (PySSLMemoryBIO_Type)->tp_name, args[0]); |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 759 | goto exit; |
| 760 | } |
| 761 | incoming = (PySSLMemoryBIO *)args[0]; |
Christian Heimes | 5c36da7 | 2020-11-20 09:40:12 +0100 | [diff] [blame^] | 762 | if (!PyObject_TypeCheck(args[1], PySSLMemoryBIO_Type)) { |
| 763 | _PyArg_BadArgument("_wrap_bio", "argument 'outgoing'", (PySSLMemoryBIO_Type)->tp_name, args[1]); |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 764 | goto exit; |
| 765 | } |
| 766 | outgoing = (PySSLMemoryBIO *)args[1]; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 767 | server_side = _PyLong_AsInt(args[2]); |
| 768 | if (server_side == -1 && PyErr_Occurred()) { |
| 769 | goto exit; |
| 770 | } |
| 771 | if (!noptargs) { |
| 772 | goto skip_optional_pos; |
| 773 | } |
| 774 | if (args[3]) { |
| 775 | hostname_obj = args[3]; |
| 776 | if (!--noptargs) { |
| 777 | goto skip_optional_pos; |
| 778 | } |
| 779 | } |
| 780 | skip_optional_pos: |
| 781 | if (!noptargs) { |
| 782 | goto skip_optional_kwonly; |
| 783 | } |
| 784 | if (args[4]) { |
| 785 | owner = args[4]; |
| 786 | if (!--noptargs) { |
| 787 | goto skip_optional_kwonly; |
| 788 | } |
| 789 | } |
| 790 | session = args[5]; |
| 791 | skip_optional_kwonly: |
Christian Heimes | 141c5e8 | 2018-02-24 21:10:57 +0100 | [diff] [blame] | 792 | return_value = _ssl__SSLContext__wrap_bio_impl(self, incoming, outgoing, server_side, hostname_obj, owner, session); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 793 | |
| 794 | exit: |
| 795 | return return_value; |
| 796 | } |
| 797 | |
| 798 | PyDoc_STRVAR(_ssl__SSLContext_session_stats__doc__, |
| 799 | "session_stats($self, /)\n" |
| 800 | "--\n" |
| 801 | "\n"); |
| 802 | |
| 803 | #define _SSL__SSLCONTEXT_SESSION_STATS_METHODDEF \ |
| 804 | {"session_stats", (PyCFunction)_ssl__SSLContext_session_stats, METH_NOARGS, _ssl__SSLContext_session_stats__doc__}, |
| 805 | |
| 806 | static PyObject * |
| 807 | _ssl__SSLContext_session_stats_impl(PySSLContext *self); |
| 808 | |
| 809 | static PyObject * |
| 810 | _ssl__SSLContext_session_stats(PySSLContext *self, PyObject *Py_UNUSED(ignored)) |
| 811 | { |
| 812 | return _ssl__SSLContext_session_stats_impl(self); |
| 813 | } |
| 814 | |
| 815 | PyDoc_STRVAR(_ssl__SSLContext_set_default_verify_paths__doc__, |
| 816 | "set_default_verify_paths($self, /)\n" |
| 817 | "--\n" |
| 818 | "\n"); |
| 819 | |
| 820 | #define _SSL__SSLCONTEXT_SET_DEFAULT_VERIFY_PATHS_METHODDEF \ |
| 821 | {"set_default_verify_paths", (PyCFunction)_ssl__SSLContext_set_default_verify_paths, METH_NOARGS, _ssl__SSLContext_set_default_verify_paths__doc__}, |
| 822 | |
| 823 | static PyObject * |
| 824 | _ssl__SSLContext_set_default_verify_paths_impl(PySSLContext *self); |
| 825 | |
| 826 | static PyObject * |
| 827 | _ssl__SSLContext_set_default_verify_paths(PySSLContext *self, PyObject *Py_UNUSED(ignored)) |
| 828 | { |
| 829 | return _ssl__SSLContext_set_default_verify_paths_impl(self); |
| 830 | } |
| 831 | |
| 832 | #if !defined(OPENSSL_NO_ECDH) |
| 833 | |
| 834 | PyDoc_STRVAR(_ssl__SSLContext_set_ecdh_curve__doc__, |
| 835 | "set_ecdh_curve($self, name, /)\n" |
| 836 | "--\n" |
| 837 | "\n"); |
| 838 | |
| 839 | #define _SSL__SSLCONTEXT_SET_ECDH_CURVE_METHODDEF \ |
| 840 | {"set_ecdh_curve", (PyCFunction)_ssl__SSLContext_set_ecdh_curve, METH_O, _ssl__SSLContext_set_ecdh_curve__doc__}, |
| 841 | |
| 842 | #endif /* !defined(OPENSSL_NO_ECDH) */ |
| 843 | |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 844 | PyDoc_STRVAR(_ssl__SSLContext_cert_store_stats__doc__, |
| 845 | "cert_store_stats($self, /)\n" |
| 846 | "--\n" |
| 847 | "\n" |
| 848 | "Returns quantities of loaded X.509 certificates.\n" |
| 849 | "\n" |
| 850 | "X.509 certificates with a CA extension and certificate revocation lists\n" |
| 851 | "inside the context\'s cert store.\n" |
| 852 | "\n" |
| 853 | "NOTE: Certificates in a capath directory aren\'t loaded unless they have\n" |
| 854 | "been used at least once."); |
| 855 | |
| 856 | #define _SSL__SSLCONTEXT_CERT_STORE_STATS_METHODDEF \ |
| 857 | {"cert_store_stats", (PyCFunction)_ssl__SSLContext_cert_store_stats, METH_NOARGS, _ssl__SSLContext_cert_store_stats__doc__}, |
| 858 | |
| 859 | static PyObject * |
| 860 | _ssl__SSLContext_cert_store_stats_impl(PySSLContext *self); |
| 861 | |
| 862 | static PyObject * |
| 863 | _ssl__SSLContext_cert_store_stats(PySSLContext *self, PyObject *Py_UNUSED(ignored)) |
| 864 | { |
| 865 | return _ssl__SSLContext_cert_store_stats_impl(self); |
| 866 | } |
| 867 | |
| 868 | PyDoc_STRVAR(_ssl__SSLContext_get_ca_certs__doc__, |
| 869 | "get_ca_certs($self, /, binary_form=False)\n" |
| 870 | "--\n" |
| 871 | "\n" |
| 872 | "Returns a list of dicts with information of loaded CA certs.\n" |
| 873 | "\n" |
| 874 | "If the optional argument is True, returns a DER-encoded copy of the CA\n" |
| 875 | "certificate.\n" |
| 876 | "\n" |
| 877 | "NOTE: Certificates in a capath directory aren\'t loaded unless they have\n" |
| 878 | "been used at least once."); |
| 879 | |
| 880 | #define _SSL__SSLCONTEXT_GET_CA_CERTS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 881 | {"get_ca_certs", (PyCFunction)(void(*)(void))_ssl__SSLContext_get_ca_certs, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLContext_get_ca_certs__doc__}, |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 882 | |
| 883 | static PyObject * |
| 884 | _ssl__SSLContext_get_ca_certs_impl(PySSLContext *self, int binary_form); |
| 885 | |
| 886 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 887 | _ssl__SSLContext_get_ca_certs(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 888 | { |
| 889 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 890 | static const char * const _keywords[] = {"binary_form", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 891 | static _PyArg_Parser _parser = {NULL, _keywords, "get_ca_certs", 0}; |
| 892 | PyObject *argsbuf[1]; |
| 893 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 894 | int binary_form = 0; |
| 895 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 896 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); |
| 897 | if (!args) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 898 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 899 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 900 | if (!noptargs) { |
| 901 | goto skip_optional_pos; |
| 902 | } |
| 903 | binary_form = PyObject_IsTrue(args[0]); |
| 904 | if (binary_form < 0) { |
| 905 | goto exit; |
| 906 | } |
| 907 | skip_optional_pos: |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 908 | return_value = _ssl__SSLContext_get_ca_certs_impl(self, binary_form); |
| 909 | |
| 910 | exit: |
| 911 | return return_value; |
| 912 | } |
| 913 | |
| 914 | static PyObject * |
| 915 | _ssl_MemoryBIO_impl(PyTypeObject *type); |
| 916 | |
| 917 | static PyObject * |
| 918 | _ssl_MemoryBIO(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 919 | { |
| 920 | PyObject *return_value = NULL; |
| 921 | |
Christian Heimes | 5c36da7 | 2020-11-20 09:40:12 +0100 | [diff] [blame^] | 922 | if ((type == PySSLMemoryBIO_Type) && |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 923 | !_PyArg_NoPositional("MemoryBIO", args)) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 924 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 925 | } |
Christian Heimes | 5c36da7 | 2020-11-20 09:40:12 +0100 | [diff] [blame^] | 926 | if ((type == PySSLMemoryBIO_Type) && |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 927 | !_PyArg_NoKeywords("MemoryBIO", kwargs)) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 928 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 929 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 930 | return_value = _ssl_MemoryBIO_impl(type); |
| 931 | |
| 932 | exit: |
| 933 | return return_value; |
| 934 | } |
| 935 | |
| 936 | PyDoc_STRVAR(_ssl_MemoryBIO_read__doc__, |
| 937 | "read($self, size=-1, /)\n" |
| 938 | "--\n" |
| 939 | "\n" |
| 940 | "Read up to size bytes from the memory BIO.\n" |
| 941 | "\n" |
| 942 | "If size is not specified, read the entire buffer.\n" |
| 943 | "If the return value is an empty bytes instance, this means either\n" |
| 944 | "EOF or that no data is available. Use the \"eof\" property to\n" |
| 945 | "distinguish between the two."); |
| 946 | |
| 947 | #define _SSL_MEMORYBIO_READ_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 948 | {"read", (PyCFunction)(void(*)(void))_ssl_MemoryBIO_read, METH_FASTCALL, _ssl_MemoryBIO_read__doc__}, |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 949 | |
| 950 | static PyObject * |
| 951 | _ssl_MemoryBIO_read_impl(PySSLMemoryBIO *self, int len); |
| 952 | |
| 953 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 954 | _ssl_MemoryBIO_read(PySSLMemoryBIO *self, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 955 | { |
| 956 | PyObject *return_value = NULL; |
| 957 | int len = -1; |
| 958 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 959 | if (!_PyArg_CheckPositional("read", nargs, 0, 1)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 960 | goto exit; |
| 961 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 962 | if (nargs < 1) { |
| 963 | goto skip_optional; |
| 964 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 965 | len = _PyLong_AsInt(args[0]); |
| 966 | if (len == -1 && PyErr_Occurred()) { |
| 967 | goto exit; |
| 968 | } |
| 969 | skip_optional: |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 970 | return_value = _ssl_MemoryBIO_read_impl(self, len); |
| 971 | |
| 972 | exit: |
| 973 | return return_value; |
| 974 | } |
| 975 | |
| 976 | PyDoc_STRVAR(_ssl_MemoryBIO_write__doc__, |
| 977 | "write($self, b, /)\n" |
| 978 | "--\n" |
| 979 | "\n" |
| 980 | "Writes the bytes b into the memory BIO.\n" |
| 981 | "\n" |
| 982 | "Returns the number of bytes written."); |
| 983 | |
| 984 | #define _SSL_MEMORYBIO_WRITE_METHODDEF \ |
| 985 | {"write", (PyCFunction)_ssl_MemoryBIO_write, METH_O, _ssl_MemoryBIO_write__doc__}, |
| 986 | |
| 987 | static PyObject * |
| 988 | _ssl_MemoryBIO_write_impl(PySSLMemoryBIO *self, Py_buffer *b); |
| 989 | |
| 990 | static PyObject * |
| 991 | _ssl_MemoryBIO_write(PySSLMemoryBIO *self, PyObject *arg) |
| 992 | { |
| 993 | PyObject *return_value = NULL; |
| 994 | Py_buffer b = {NULL, NULL}; |
| 995 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 996 | if (PyObject_GetBuffer(arg, &b, PyBUF_SIMPLE) != 0) { |
| 997 | goto exit; |
| 998 | } |
| 999 | if (!PyBuffer_IsContiguous(&b, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 1000 | _PyArg_BadArgument("write", "argument", "contiguous buffer", arg); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1001 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1002 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1003 | return_value = _ssl_MemoryBIO_write_impl(self, &b); |
| 1004 | |
| 1005 | exit: |
| 1006 | /* Cleanup for b */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1007 | if (b.obj) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1008 | PyBuffer_Release(&b); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1009 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1010 | |
| 1011 | return return_value; |
| 1012 | } |
| 1013 | |
| 1014 | PyDoc_STRVAR(_ssl_MemoryBIO_write_eof__doc__, |
| 1015 | "write_eof($self, /)\n" |
| 1016 | "--\n" |
| 1017 | "\n" |
| 1018 | "Write an EOF marker to the memory BIO.\n" |
| 1019 | "\n" |
| 1020 | "When all data has been read, the \"eof\" property will be True."); |
| 1021 | |
| 1022 | #define _SSL_MEMORYBIO_WRITE_EOF_METHODDEF \ |
| 1023 | {"write_eof", (PyCFunction)_ssl_MemoryBIO_write_eof, METH_NOARGS, _ssl_MemoryBIO_write_eof__doc__}, |
| 1024 | |
| 1025 | static PyObject * |
| 1026 | _ssl_MemoryBIO_write_eof_impl(PySSLMemoryBIO *self); |
| 1027 | |
| 1028 | static PyObject * |
| 1029 | _ssl_MemoryBIO_write_eof(PySSLMemoryBIO *self, PyObject *Py_UNUSED(ignored)) |
| 1030 | { |
| 1031 | return _ssl_MemoryBIO_write_eof_impl(self); |
| 1032 | } |
| 1033 | |
| 1034 | PyDoc_STRVAR(_ssl_RAND_add__doc__, |
| 1035 | "RAND_add($module, string, entropy, /)\n" |
| 1036 | "--\n" |
| 1037 | "\n" |
| 1038 | "Mix string into the OpenSSL PRNG state.\n" |
| 1039 | "\n" |
| 1040 | "entropy (a float) is a lower bound on the entropy contained in\n" |
Chandan Kumar | 63c2c8a | 2017-06-09 15:13:58 +0530 | [diff] [blame] | 1041 | "string. See RFC 4086."); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1042 | |
| 1043 | #define _SSL_RAND_ADD_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1044 | {"RAND_add", (PyCFunction)(void(*)(void))_ssl_RAND_add, METH_FASTCALL, _ssl_RAND_add__doc__}, |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1045 | |
| 1046 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1047 | _ssl_RAND_add_impl(PyObject *module, Py_buffer *view, double entropy); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1048 | |
| 1049 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1050 | _ssl_RAND_add(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1051 | { |
| 1052 | PyObject *return_value = NULL; |
| 1053 | Py_buffer view = {NULL, NULL}; |
| 1054 | double entropy; |
| 1055 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1056 | if (!_PyArg_CheckPositional("RAND_add", nargs, 2, 2)) { |
| 1057 | goto exit; |
| 1058 | } |
| 1059 | if (PyUnicode_Check(args[0])) { |
| 1060 | Py_ssize_t len; |
| 1061 | const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len); |
| 1062 | if (ptr == NULL) { |
| 1063 | goto exit; |
| 1064 | } |
| 1065 | PyBuffer_FillInfo(&view, args[0], (void *)ptr, len, 1, 0); |
| 1066 | } |
| 1067 | else { /* any bytes-like object */ |
| 1068 | if (PyObject_GetBuffer(args[0], &view, PyBUF_SIMPLE) != 0) { |
| 1069 | goto exit; |
| 1070 | } |
| 1071 | if (!PyBuffer_IsContiguous(&view, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 1072 | _PyArg_BadArgument("RAND_add", "argument 1", "contiguous buffer", args[0]); |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 1073 | goto exit; |
| 1074 | } |
| 1075 | } |
Raymond Hettinger | aef9ad8 | 2019-08-24 19:10:39 -0700 | [diff] [blame] | 1076 | if (PyFloat_CheckExact(args[1])) { |
| 1077 | entropy = PyFloat_AS_DOUBLE(args[1]); |
| 1078 | } |
| 1079 | else |
| 1080 | { |
| 1081 | entropy = PyFloat_AsDouble(args[1]); |
| 1082 | if (entropy == -1.0 && PyErr_Occurred()) { |
| 1083 | goto exit; |
| 1084 | } |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 1085 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1086 | return_value = _ssl_RAND_add_impl(module, &view, entropy); |
| 1087 | |
| 1088 | exit: |
| 1089 | /* Cleanup for view */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1090 | if (view.obj) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1091 | PyBuffer_Release(&view); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1092 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1093 | |
| 1094 | return return_value; |
| 1095 | } |
| 1096 | |
| 1097 | PyDoc_STRVAR(_ssl_RAND_bytes__doc__, |
| 1098 | "RAND_bytes($module, n, /)\n" |
| 1099 | "--\n" |
| 1100 | "\n" |
| 1101 | "Generate n cryptographically strong pseudo-random bytes."); |
| 1102 | |
| 1103 | #define _SSL_RAND_BYTES_METHODDEF \ |
| 1104 | {"RAND_bytes", (PyCFunction)_ssl_RAND_bytes, METH_O, _ssl_RAND_bytes__doc__}, |
| 1105 | |
| 1106 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1107 | _ssl_RAND_bytes_impl(PyObject *module, int n); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1108 | |
| 1109 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1110 | _ssl_RAND_bytes(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1111 | { |
| 1112 | PyObject *return_value = NULL; |
| 1113 | int n; |
| 1114 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1115 | n = _PyLong_AsInt(arg); |
| 1116 | if (n == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1117 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1118 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1119 | return_value = _ssl_RAND_bytes_impl(module, n); |
| 1120 | |
| 1121 | exit: |
| 1122 | return return_value; |
| 1123 | } |
| 1124 | |
| 1125 | PyDoc_STRVAR(_ssl_RAND_pseudo_bytes__doc__, |
| 1126 | "RAND_pseudo_bytes($module, n, /)\n" |
| 1127 | "--\n" |
| 1128 | "\n" |
| 1129 | "Generate n pseudo-random bytes.\n" |
| 1130 | "\n" |
| 1131 | "Return a pair (bytes, is_cryptographic). is_cryptographic is True\n" |
| 1132 | "if the bytes generated are cryptographically strong."); |
| 1133 | |
| 1134 | #define _SSL_RAND_PSEUDO_BYTES_METHODDEF \ |
| 1135 | {"RAND_pseudo_bytes", (PyCFunction)_ssl_RAND_pseudo_bytes, METH_O, _ssl_RAND_pseudo_bytes__doc__}, |
| 1136 | |
| 1137 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1138 | _ssl_RAND_pseudo_bytes_impl(PyObject *module, int n); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1139 | |
| 1140 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1141 | _ssl_RAND_pseudo_bytes(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1142 | { |
| 1143 | PyObject *return_value = NULL; |
| 1144 | int n; |
| 1145 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1146 | n = _PyLong_AsInt(arg); |
| 1147 | if (n == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1148 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1149 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1150 | return_value = _ssl_RAND_pseudo_bytes_impl(module, n); |
| 1151 | |
| 1152 | exit: |
| 1153 | return return_value; |
| 1154 | } |
| 1155 | |
| 1156 | PyDoc_STRVAR(_ssl_RAND_status__doc__, |
| 1157 | "RAND_status($module, /)\n" |
| 1158 | "--\n" |
| 1159 | "\n" |
| 1160 | "Returns 1 if the OpenSSL PRNG has been seeded with enough data and 0 if not.\n" |
| 1161 | "\n" |
| 1162 | "It is necessary to seed the PRNG with RAND_add() on some platforms before\n" |
| 1163 | "using the ssl() function."); |
| 1164 | |
| 1165 | #define _SSL_RAND_STATUS_METHODDEF \ |
| 1166 | {"RAND_status", (PyCFunction)_ssl_RAND_status, METH_NOARGS, _ssl_RAND_status__doc__}, |
| 1167 | |
| 1168 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1169 | _ssl_RAND_status_impl(PyObject *module); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1170 | |
| 1171 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1172 | _ssl_RAND_status(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1173 | { |
| 1174 | return _ssl_RAND_status_impl(module); |
| 1175 | } |
| 1176 | |
Benjamin Peterson | b8a2f51 | 2016-07-06 23:55:15 -0700 | [diff] [blame] | 1177 | #if !defined(OPENSSL_NO_EGD) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1178 | |
| 1179 | PyDoc_STRVAR(_ssl_RAND_egd__doc__, |
| 1180 | "RAND_egd($module, path, /)\n" |
| 1181 | "--\n" |
| 1182 | "\n" |
| 1183 | "Queries the entropy gather daemon (EGD) on the socket named by \'path\'.\n" |
| 1184 | "\n" |
| 1185 | "Returns number of bytes read. Raises SSLError if connection to EGD\n" |
| 1186 | "fails or if it does not provide enough data to seed PRNG."); |
| 1187 | |
| 1188 | #define _SSL_RAND_EGD_METHODDEF \ |
| 1189 | {"RAND_egd", (PyCFunction)_ssl_RAND_egd, METH_O, _ssl_RAND_egd__doc__}, |
| 1190 | |
| 1191 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1192 | _ssl_RAND_egd_impl(PyObject *module, PyObject *path); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1193 | |
| 1194 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1195 | _ssl_RAND_egd(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1196 | { |
| 1197 | PyObject *return_value = NULL; |
| 1198 | PyObject *path; |
| 1199 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1200 | if (!PyUnicode_FSConverter(arg, &path)) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1201 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1202 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1203 | return_value = _ssl_RAND_egd_impl(module, path); |
| 1204 | |
| 1205 | exit: |
| 1206 | return return_value; |
| 1207 | } |
| 1208 | |
Benjamin Peterson | b8a2f51 | 2016-07-06 23:55:15 -0700 | [diff] [blame] | 1209 | #endif /* !defined(OPENSSL_NO_EGD) */ |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1210 | |
| 1211 | PyDoc_STRVAR(_ssl_get_default_verify_paths__doc__, |
| 1212 | "get_default_verify_paths($module, /)\n" |
| 1213 | "--\n" |
| 1214 | "\n" |
| 1215 | "Return search paths and environment vars that are used by SSLContext\'s set_default_verify_paths() to load default CAs.\n" |
| 1216 | "\n" |
| 1217 | "The values are \'cert_file_env\', \'cert_file\', \'cert_dir_env\', \'cert_dir\'."); |
| 1218 | |
| 1219 | #define _SSL_GET_DEFAULT_VERIFY_PATHS_METHODDEF \ |
| 1220 | {"get_default_verify_paths", (PyCFunction)_ssl_get_default_verify_paths, METH_NOARGS, _ssl_get_default_verify_paths__doc__}, |
| 1221 | |
| 1222 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1223 | _ssl_get_default_verify_paths_impl(PyObject *module); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1224 | |
| 1225 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1226 | _ssl_get_default_verify_paths(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1227 | { |
| 1228 | return _ssl_get_default_verify_paths_impl(module); |
| 1229 | } |
| 1230 | |
| 1231 | PyDoc_STRVAR(_ssl_txt2obj__doc__, |
| 1232 | "txt2obj($module, /, txt, name=False)\n" |
| 1233 | "--\n" |
| 1234 | "\n" |
| 1235 | "Lookup NID, short name, long name and OID of an ASN1_OBJECT.\n" |
| 1236 | "\n" |
| 1237 | "By default objects are looked up by OID. With name=True short and\n" |
| 1238 | "long name are also matched."); |
| 1239 | |
| 1240 | #define _SSL_TXT2OBJ_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1241 | {"txt2obj", (PyCFunction)(void(*)(void))_ssl_txt2obj, METH_FASTCALL|METH_KEYWORDS, _ssl_txt2obj__doc__}, |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1242 | |
| 1243 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1244 | _ssl_txt2obj_impl(PyObject *module, const char *txt, int name); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1245 | |
| 1246 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1247 | _ssl_txt2obj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1248 | { |
| 1249 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1250 | static const char * const _keywords[] = {"txt", "name", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1251 | static _PyArg_Parser _parser = {NULL, _keywords, "txt2obj", 0}; |
| 1252 | PyObject *argsbuf[2]; |
| 1253 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1254 | const char *txt; |
| 1255 | int name = 0; |
| 1256 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1257 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
| 1258 | if (!args) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1259 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1260 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1261 | if (!PyUnicode_Check(args[0])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 1262 | _PyArg_BadArgument("txt2obj", "argument 'txt'", "str", args[0]); |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1263 | goto exit; |
| 1264 | } |
| 1265 | Py_ssize_t txt_length; |
| 1266 | txt = PyUnicode_AsUTF8AndSize(args[0], &txt_length); |
| 1267 | if (txt == NULL) { |
| 1268 | goto exit; |
| 1269 | } |
| 1270 | if (strlen(txt) != (size_t)txt_length) { |
| 1271 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 1272 | goto exit; |
| 1273 | } |
| 1274 | if (!noptargs) { |
| 1275 | goto skip_optional_pos; |
| 1276 | } |
| 1277 | name = PyObject_IsTrue(args[1]); |
| 1278 | if (name < 0) { |
| 1279 | goto exit; |
| 1280 | } |
| 1281 | skip_optional_pos: |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1282 | return_value = _ssl_txt2obj_impl(module, txt, name); |
| 1283 | |
| 1284 | exit: |
| 1285 | return return_value; |
| 1286 | } |
| 1287 | |
| 1288 | PyDoc_STRVAR(_ssl_nid2obj__doc__, |
| 1289 | "nid2obj($module, nid, /)\n" |
| 1290 | "--\n" |
| 1291 | "\n" |
| 1292 | "Lookup NID, short name, long name and OID of an ASN1_OBJECT by NID."); |
| 1293 | |
| 1294 | #define _SSL_NID2OBJ_METHODDEF \ |
| 1295 | {"nid2obj", (PyCFunction)_ssl_nid2obj, METH_O, _ssl_nid2obj__doc__}, |
| 1296 | |
| 1297 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1298 | _ssl_nid2obj_impl(PyObject *module, int nid); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1299 | |
| 1300 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1301 | _ssl_nid2obj(PyObject *module, PyObject *arg) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1302 | { |
| 1303 | PyObject *return_value = NULL; |
| 1304 | int nid; |
| 1305 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1306 | nid = _PyLong_AsInt(arg); |
| 1307 | if (nid == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1308 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1309 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1310 | return_value = _ssl_nid2obj_impl(module, nid); |
| 1311 | |
| 1312 | exit: |
| 1313 | return return_value; |
| 1314 | } |
| 1315 | |
| 1316 | #if defined(_MSC_VER) |
| 1317 | |
| 1318 | PyDoc_STRVAR(_ssl_enum_certificates__doc__, |
| 1319 | "enum_certificates($module, /, store_name)\n" |
| 1320 | "--\n" |
| 1321 | "\n" |
| 1322 | "Retrieve certificates from Windows\' cert store.\n" |
| 1323 | "\n" |
| 1324 | "store_name may be one of \'CA\', \'ROOT\' or \'MY\'. The system may provide\n" |
| 1325 | "more cert storages, too. The function returns a list of (bytes,\n" |
| 1326 | "encoding_type, trust) tuples. The encoding_type flag can be interpreted\n" |
| 1327 | "with X509_ASN_ENCODING or PKCS_7_ASN_ENCODING. The trust setting is either\n" |
| 1328 | "a set of OIDs or the boolean True."); |
| 1329 | |
| 1330 | #define _SSL_ENUM_CERTIFICATES_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1331 | {"enum_certificates", (PyCFunction)(void(*)(void))_ssl_enum_certificates, METH_FASTCALL|METH_KEYWORDS, _ssl_enum_certificates__doc__}, |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1332 | |
| 1333 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1334 | _ssl_enum_certificates_impl(PyObject *module, const char *store_name); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1335 | |
| 1336 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1337 | _ssl_enum_certificates(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1338 | { |
| 1339 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1340 | static const char * const _keywords[] = {"store_name", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1341 | static _PyArg_Parser _parser = {NULL, _keywords, "enum_certificates", 0}; |
| 1342 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1343 | const char *store_name; |
| 1344 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1345 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 1346 | if (!args) { |
| 1347 | goto exit; |
| 1348 | } |
| 1349 | if (!PyUnicode_Check(args[0])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 1350 | _PyArg_BadArgument("enum_certificates", "argument 'store_name'", "str", args[0]); |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1351 | goto exit; |
| 1352 | } |
| 1353 | Py_ssize_t store_name_length; |
| 1354 | store_name = PyUnicode_AsUTF8AndSize(args[0], &store_name_length); |
| 1355 | if (store_name == NULL) { |
| 1356 | goto exit; |
| 1357 | } |
| 1358 | if (strlen(store_name) != (size_t)store_name_length) { |
| 1359 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1360 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1361 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1362 | return_value = _ssl_enum_certificates_impl(module, store_name); |
| 1363 | |
| 1364 | exit: |
| 1365 | return return_value; |
| 1366 | } |
| 1367 | |
| 1368 | #endif /* defined(_MSC_VER) */ |
| 1369 | |
| 1370 | #if defined(_MSC_VER) |
| 1371 | |
| 1372 | PyDoc_STRVAR(_ssl_enum_crls__doc__, |
| 1373 | "enum_crls($module, /, store_name)\n" |
| 1374 | "--\n" |
| 1375 | "\n" |
| 1376 | "Retrieve CRLs from Windows\' cert store.\n" |
| 1377 | "\n" |
| 1378 | "store_name may be one of \'CA\', \'ROOT\' or \'MY\'. The system may provide\n" |
| 1379 | "more cert storages, too. The function returns a list of (bytes,\n" |
| 1380 | "encoding_type) tuples. The encoding_type flag can be interpreted with\n" |
| 1381 | "X509_ASN_ENCODING or PKCS_7_ASN_ENCODING."); |
| 1382 | |
| 1383 | #define _SSL_ENUM_CRLS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 1384 | {"enum_crls", (PyCFunction)(void(*)(void))_ssl_enum_crls, METH_FASTCALL|METH_KEYWORDS, _ssl_enum_crls__doc__}, |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1385 | |
| 1386 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1387 | _ssl_enum_crls_impl(PyObject *module, const char *store_name); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1388 | |
| 1389 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1390 | _ssl_enum_crls(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1391 | { |
| 1392 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1393 | static const char * const _keywords[] = {"store_name", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1394 | static _PyArg_Parser _parser = {NULL, _keywords, "enum_crls", 0}; |
| 1395 | PyObject *argsbuf[1]; |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1396 | const char *store_name; |
| 1397 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1398 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 1399 | if (!args) { |
| 1400 | goto exit; |
| 1401 | } |
| 1402 | if (!PyUnicode_Check(args[0])) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 1403 | _PyArg_BadArgument("enum_crls", "argument 'store_name'", "str", args[0]); |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1404 | goto exit; |
| 1405 | } |
| 1406 | Py_ssize_t store_name_length; |
| 1407 | store_name = PyUnicode_AsUTF8AndSize(args[0], &store_name_length); |
| 1408 | if (store_name == NULL) { |
| 1409 | goto exit; |
| 1410 | } |
| 1411 | if (strlen(store_name) != (size_t)store_name_length) { |
| 1412 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1413 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1414 | } |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1415 | return_value = _ssl_enum_crls_impl(module, store_name); |
| 1416 | |
| 1417 | exit: |
| 1418 | return return_value; |
| 1419 | } |
| 1420 | |
| 1421 | #endif /* defined(_MSC_VER) */ |
| 1422 | |
| 1423 | #ifndef _SSL__SSLSOCKET_SELECTED_NPN_PROTOCOL_METHODDEF |
| 1424 | #define _SSL__SSLSOCKET_SELECTED_NPN_PROTOCOL_METHODDEF |
| 1425 | #endif /* !defined(_SSL__SSLSOCKET_SELECTED_NPN_PROTOCOL_METHODDEF) */ |
| 1426 | |
| 1427 | #ifndef _SSL__SSLSOCKET_SELECTED_ALPN_PROTOCOL_METHODDEF |
| 1428 | #define _SSL__SSLSOCKET_SELECTED_ALPN_PROTOCOL_METHODDEF |
| 1429 | #endif /* !defined(_SSL__SSLSOCKET_SELECTED_ALPN_PROTOCOL_METHODDEF) */ |
| 1430 | |
Christian Heimes | 25bfcd5 | 2016-09-06 00:04:45 +0200 | [diff] [blame] | 1431 | #ifndef _SSL__SSLCONTEXT_GET_CIPHERS_METHODDEF |
| 1432 | #define _SSL__SSLCONTEXT_GET_CIPHERS_METHODDEF |
| 1433 | #endif /* !defined(_SSL__SSLCONTEXT_GET_CIPHERS_METHODDEF) */ |
| 1434 | |
Serhiy Storchaka | 4b7b82f | 2015-05-03 16:14:08 +0300 | [diff] [blame] | 1435 | #ifndef _SSL__SSLCONTEXT_SET_ECDH_CURVE_METHODDEF |
| 1436 | #define _SSL__SSLCONTEXT_SET_ECDH_CURVE_METHODDEF |
| 1437 | #endif /* !defined(_SSL__SSLCONTEXT_SET_ECDH_CURVE_METHODDEF) */ |
| 1438 | |
| 1439 | #ifndef _SSL_RAND_EGD_METHODDEF |
| 1440 | #define _SSL_RAND_EGD_METHODDEF |
| 1441 | #endif /* !defined(_SSL_RAND_EGD_METHODDEF) */ |
| 1442 | |
| 1443 | #ifndef _SSL_ENUM_CERTIFICATES_METHODDEF |
| 1444 | #define _SSL_ENUM_CERTIFICATES_METHODDEF |
| 1445 | #endif /* !defined(_SSL_ENUM_CERTIFICATES_METHODDEF) */ |
| 1446 | |
| 1447 | #ifndef _SSL_ENUM_CRLS_METHODDEF |
| 1448 | #define _SSL_ENUM_CRLS_METHODDEF |
| 1449 | #endif /* !defined(_SSL_ENUM_CRLS_METHODDEF) */ |
Christian Heimes | 5c36da7 | 2020-11-20 09:40:12 +0100 | [diff] [blame^] | 1450 | /*[clinic end generated code: output=2bb53a80040c9b35 input=a9049054013a1b77]*/ |