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