• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *
_ssl__SSLSocket_do_handshake(PySSLSocket * self,PyObject * Py_UNUSED (ignored))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 *
_ssl__test_decode_cert(PyObject * module,PyObject * arg)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 *
_ssl__SSLSocket_getpeercert(PySSLSocket * self,PyObject * const * args,Py_ssize_t nargs)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_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 *
_ssl__SSLSocket_shared_ciphers(PySSLSocket * self,PyObject * Py_UNUSED (ignored))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 *
_ssl__SSLSocket_cipher(PySSLSocket * self,PyObject * Py_UNUSED (ignored))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 *
_ssl__SSLSocket_version(PySSLSocket * self,PyObject * Py_UNUSED (ignored))137 _ssl__SSLSocket_version(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
138 {
139     return _ssl__SSLSocket_version_impl(self);
140 }
141 
142 #if (HAVE_NPN)
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 *
_ssl__SSLSocket_selected_npn_protocol(PySSLSocket * self,PyObject * Py_UNUSED (ignored))156 _ssl__SSLSocket_selected_npn_protocol(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
157 {
158     return _ssl__SSLSocket_selected_npn_protocol_impl(self);
159 }
160 
161 #endif /* (HAVE_NPN) */
162 
163 #if (HAVE_ALPN)
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 *
_ssl__SSLSocket_selected_alpn_protocol(PySSLSocket * self,PyObject * Py_UNUSED (ignored))177 _ssl__SSLSocket_selected_alpn_protocol(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
178 {
179     return _ssl__SSLSocket_selected_alpn_protocol_impl(self);
180 }
181 
182 #endif /* (HAVE_ALPN) */
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 *
_ssl__SSLSocket_compression(PySSLSocket * self,PyObject * Py_UNUSED (ignored))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 *
_ssl__SSLSocket_write(PySSLSocket * self,PyObject * arg)216 _ssl__SSLSocket_write(PySSLSocket *self, PyObject *arg)
217 {
218     PyObject *return_value = NULL;
219     Py_buffer b = {NULL, NULL};
220 
221     if (PyObject_GetBuffer(arg, &b, PyBUF_SIMPLE) != 0) {
222         goto exit;
223     }
224     if (!PyBuffer_IsContiguous(&b, 'C')) {
225         _PyArg_BadArgument("write", "argument", "contiguous buffer", arg);
226         goto exit;
227     }
228     return_value = _ssl__SSLSocket_write_impl(self, &b);
229 
230 exit:
231     /* Cleanup for b */
232     if (b.obj) {
233        PyBuffer_Release(&b);
234     }
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 *
_ssl__SSLSocket_pending(PySSLSocket * self,PyObject * Py_UNUSED (ignored))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 *
_ssl__SSLSocket_read(PySSLSocket * self,PyObject * args)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:
278             if (!PyArg_ParseTuple(args, "i:read", &len)) {
279                 goto exit;
280             }
281             break;
282         case 2:
283             if (!PyArg_ParseTuple(args, "iw*:read", &len, &buffer)) {
284                 goto exit;
285             }
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 */
296     if (buffer.obj) {
297        PyBuffer_Release(&buffer);
298     }
299 
300     return return_value;
301 }
302 
303 PyDoc_STRVAR(_ssl__SSLSocket_shutdown__doc__,
304 "shutdown($self, /)\n"
305 "--\n"
306 "\n"
307 "Does the SSL shutdown handshake with the remote end.");
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 *
_ssl__SSLSocket_shutdown(PySSLSocket * self,PyObject * Py_UNUSED (ignored))316 _ssl__SSLSocket_shutdown(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
317 {
318     return _ssl__SSLSocket_shutdown_impl(self);
319 }
320 
321 PyDoc_STRVAR(_ssl__SSLSocket_get_channel_binding__doc__,
322 "get_channel_binding($self, /, cb_type=\'tls-unique\')\n"
323 "--\n"
324 "\n"
325 "Get channel binding data for current connection.\n"
326 "\n"
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.");
330 
331 #define _SSL__SSLSOCKET_GET_CHANNEL_BINDING_METHODDEF    \
332     {"get_channel_binding", (PyCFunction)(void(*)(void))_ssl__SSLSocket_get_channel_binding, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLSocket_get_channel_binding__doc__},
333 
334 static PyObject *
335 _ssl__SSLSocket_get_channel_binding_impl(PySSLSocket *self,
336                                          const char *cb_type);
337 
338 static PyObject *
_ssl__SSLSocket_get_channel_binding(PySSLSocket * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)339 _ssl__SSLSocket_get_channel_binding(PySSLSocket *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
340 {
341     PyObject *return_value = NULL;
342     static const char * const _keywords[] = {"cb_type", NULL};
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;
346     const char *cb_type = "tls-unique";
347 
348     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
349     if (!args) {
350         goto exit;
351     }
352     if (!noptargs) {
353         goto skip_optional_pos;
354     }
355     if (!PyUnicode_Check(args[0])) {
356         _PyArg_BadArgument("get_channel_binding", "argument 'cb_type'", "str", args[0]);
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:
369     return_value = _ssl__SSLSocket_get_channel_binding_impl(self, cb_type);
370 
371 exit:
372     return return_value;
373 }
374 
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 *
_ssl__SSLSocket_verify_client_post_handshake(PySSLSocket * self,PyObject * Py_UNUSED (ignored))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 
393 static PyObject *
394 _ssl__SSLContext_impl(PyTypeObject *type, int proto_version);
395 
396 static PyObject *
_ssl__SSLContext(PyTypeObject * type,PyObject * args,PyObject * kwargs)397 _ssl__SSLContext(PyTypeObject *type, PyObject *args, PyObject *kwargs)
398 {
399     PyObject *return_value = NULL;
400     int proto_version;
401 
402     if ((type == &PySSLContext_Type) &&
403         !_PyArg_NoKeywords("_SSLContext", kwargs)) {
404         goto exit;
405     }
406     if (!_PyArg_CheckPositional("_SSLContext", PyTuple_GET_SIZE(args), 1, 1)) {
407         goto exit;
408     }
409     if (PyFloat_Check(PyTuple_GET_ITEM(args, 0))) {
410         PyErr_SetString(PyExc_TypeError,
411                         "integer argument expected, got float" );
412         goto exit;
413     }
414     proto_version = _PyLong_AsInt(PyTuple_GET_ITEM(args, 0));
415     if (proto_version == -1 && PyErr_Occurred()) {
416         goto exit;
417     }
418     return_value = _ssl__SSLContext_impl(type, proto_version);
419 
420 exit:
421     return return_value;
422 }
423 
424 PyDoc_STRVAR(_ssl__SSLContext_set_ciphers__doc__,
425 "set_ciphers($self, cipherlist, /)\n"
426 "--\n"
427 "\n");
428 
429 #define _SSL__SSLCONTEXT_SET_CIPHERS_METHODDEF    \
430     {"set_ciphers", (PyCFunction)_ssl__SSLContext_set_ciphers, METH_O, _ssl__SSLContext_set_ciphers__doc__},
431 
432 static PyObject *
433 _ssl__SSLContext_set_ciphers_impl(PySSLContext *self, const char *cipherlist);
434 
435 static PyObject *
_ssl__SSLContext_set_ciphers(PySSLContext * self,PyObject * arg)436 _ssl__SSLContext_set_ciphers(PySSLContext *self, PyObject *arg)
437 {
438     PyObject *return_value = NULL;
439     const char *cipherlist;
440 
441     if (!PyUnicode_Check(arg)) {
442         _PyArg_BadArgument("set_ciphers", "argument", "str", arg);
443         goto exit;
444     }
445     Py_ssize_t cipherlist_length;
446     cipherlist = PyUnicode_AsUTF8AndSize(arg, &cipherlist_length);
447     if (cipherlist == NULL) {
448         goto exit;
449     }
450     if (strlen(cipherlist) != (size_t)cipherlist_length) {
451         PyErr_SetString(PyExc_ValueError, "embedded null character");
452         goto exit;
453     }
454     return_value = _ssl__SSLContext_set_ciphers_impl(self, cipherlist);
455 
456 exit:
457     return return_value;
458 }
459 
460 #if (OPENSSL_VERSION_NUMBER >= 0x10002000UL)
461 
462 PyDoc_STRVAR(_ssl__SSLContext_get_ciphers__doc__,
463 "get_ciphers($self, /)\n"
464 "--\n"
465 "\n");
466 
467 #define _SSL__SSLCONTEXT_GET_CIPHERS_METHODDEF    \
468     {"get_ciphers", (PyCFunction)_ssl__SSLContext_get_ciphers, METH_NOARGS, _ssl__SSLContext_get_ciphers__doc__},
469 
470 static PyObject *
471 _ssl__SSLContext_get_ciphers_impl(PySSLContext *self);
472 
473 static PyObject *
_ssl__SSLContext_get_ciphers(PySSLContext * self,PyObject * Py_UNUSED (ignored))474 _ssl__SSLContext_get_ciphers(PySSLContext *self, PyObject *Py_UNUSED(ignored))
475 {
476     return _ssl__SSLContext_get_ciphers_impl(self);
477 }
478 
479 #endif /* (OPENSSL_VERSION_NUMBER >= 0x10002000UL) */
480 
481 PyDoc_STRVAR(_ssl__SSLContext__set_npn_protocols__doc__,
482 "_set_npn_protocols($self, protos, /)\n"
483 "--\n"
484 "\n");
485 
486 #define _SSL__SSLCONTEXT__SET_NPN_PROTOCOLS_METHODDEF    \
487     {"_set_npn_protocols", (PyCFunction)_ssl__SSLContext__set_npn_protocols, METH_O, _ssl__SSLContext__set_npn_protocols__doc__},
488 
489 static PyObject *
490 _ssl__SSLContext__set_npn_protocols_impl(PySSLContext *self,
491                                          Py_buffer *protos);
492 
493 static PyObject *
_ssl__SSLContext__set_npn_protocols(PySSLContext * self,PyObject * arg)494 _ssl__SSLContext__set_npn_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_npn_protocols", "argument", "contiguous buffer", arg);
504         goto exit;
505     }
506     return_value = _ssl__SSLContext__set_npn_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__set_alpn_protocols__doc__,
518 "_set_alpn_protocols($self, protos, /)\n"
519 "--\n"
520 "\n");
521 
522 #define _SSL__SSLCONTEXT__SET_ALPN_PROTOCOLS_METHODDEF    \
523     {"_set_alpn_protocols", (PyCFunction)_ssl__SSLContext__set_alpn_protocols, METH_O, _ssl__SSLContext__set_alpn_protocols__doc__},
524 
525 static PyObject *
526 _ssl__SSLContext__set_alpn_protocols_impl(PySSLContext *self,
527                                           Py_buffer *protos);
528 
529 static PyObject *
_ssl__SSLContext__set_alpn_protocols(PySSLContext * self,PyObject * arg)530 _ssl__SSLContext__set_alpn_protocols(PySSLContext *self, PyObject *arg)
531 {
532     PyObject *return_value = NULL;
533     Py_buffer protos = {NULL, NULL};
534 
535     if (PyObject_GetBuffer(arg, &protos, PyBUF_SIMPLE) != 0) {
536         goto exit;
537     }
538     if (!PyBuffer_IsContiguous(&protos, 'C')) {
539         _PyArg_BadArgument("_set_alpn_protocols", "argument", "contiguous buffer", arg);
540         goto exit;
541     }
542     return_value = _ssl__SSLContext__set_alpn_protocols_impl(self, &protos);
543 
544 exit:
545     /* Cleanup for protos */
546     if (protos.obj) {
547        PyBuffer_Release(&protos);
548     }
549 
550     return return_value;
551 }
552 
553 PyDoc_STRVAR(_ssl__SSLContext_load_cert_chain__doc__,
554 "load_cert_chain($self, /, certfile, keyfile=None, password=None)\n"
555 "--\n"
556 "\n");
557 
558 #define _SSL__SSLCONTEXT_LOAD_CERT_CHAIN_METHODDEF    \
559     {"load_cert_chain", (PyCFunction)(void(*)(void))_ssl__SSLContext_load_cert_chain, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLContext_load_cert_chain__doc__},
560 
561 static PyObject *
562 _ssl__SSLContext_load_cert_chain_impl(PySSLContext *self, PyObject *certfile,
563                                       PyObject *keyfile, PyObject *password);
564 
565 static PyObject *
_ssl__SSLContext_load_cert_chain(PySSLContext * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)566 _ssl__SSLContext_load_cert_chain(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
567 {
568     PyObject *return_value = NULL;
569     static const char * const _keywords[] = {"certfile", "keyfile", "password", NULL};
570     static _PyArg_Parser _parser = {NULL, _keywords, "load_cert_chain", 0};
571     PyObject *argsbuf[3];
572     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
573     PyObject *certfile;
574     PyObject *keyfile = Py_None;
575     PyObject *password = Py_None;
576 
577     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
578     if (!args) {
579         goto exit;
580     }
581     certfile = args[0];
582     if (!noptargs) {
583         goto skip_optional_pos;
584     }
585     if (args[1]) {
586         keyfile = args[1];
587         if (!--noptargs) {
588             goto skip_optional_pos;
589         }
590     }
591     password = args[2];
592 skip_optional_pos:
593     return_value = _ssl__SSLContext_load_cert_chain_impl(self, certfile, keyfile, password);
594 
595 exit:
596     return return_value;
597 }
598 
599 PyDoc_STRVAR(_ssl__SSLContext_load_verify_locations__doc__,
600 "load_verify_locations($self, /, cafile=None, capath=None, cadata=None)\n"
601 "--\n"
602 "\n");
603 
604 #define _SSL__SSLCONTEXT_LOAD_VERIFY_LOCATIONS_METHODDEF    \
605     {"load_verify_locations", (PyCFunction)(void(*)(void))_ssl__SSLContext_load_verify_locations, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLContext_load_verify_locations__doc__},
606 
607 static PyObject *
608 _ssl__SSLContext_load_verify_locations_impl(PySSLContext *self,
609                                             PyObject *cafile,
610                                             PyObject *capath,
611                                             PyObject *cadata);
612 
613 static PyObject *
_ssl__SSLContext_load_verify_locations(PySSLContext * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)614 _ssl__SSLContext_load_verify_locations(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
615 {
616     PyObject *return_value = NULL;
617     static const char * const _keywords[] = {"cafile", "capath", "cadata", NULL};
618     static _PyArg_Parser _parser = {NULL, _keywords, "load_verify_locations", 0};
619     PyObject *argsbuf[3];
620     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
621     PyObject *cafile = Py_None;
622     PyObject *capath = Py_None;
623     PyObject *cadata = Py_None;
624 
625     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 3, 0, argsbuf);
626     if (!args) {
627         goto exit;
628     }
629     if (!noptargs) {
630         goto skip_optional_pos;
631     }
632     if (args[0]) {
633         cafile = args[0];
634         if (!--noptargs) {
635             goto skip_optional_pos;
636         }
637     }
638     if (args[1]) {
639         capath = args[1];
640         if (!--noptargs) {
641             goto skip_optional_pos;
642         }
643     }
644     cadata = args[2];
645 skip_optional_pos:
646     return_value = _ssl__SSLContext_load_verify_locations_impl(self, cafile, capath, cadata);
647 
648 exit:
649     return return_value;
650 }
651 
652 PyDoc_STRVAR(_ssl__SSLContext_load_dh_params__doc__,
653 "load_dh_params($self, path, /)\n"
654 "--\n"
655 "\n");
656 
657 #define _SSL__SSLCONTEXT_LOAD_DH_PARAMS_METHODDEF    \
658     {"load_dh_params", (PyCFunction)_ssl__SSLContext_load_dh_params, METH_O, _ssl__SSLContext_load_dh_params__doc__},
659 
660 PyDoc_STRVAR(_ssl__SSLContext__wrap_socket__doc__,
661 "_wrap_socket($self, /, sock, server_side, server_hostname=None, *,\n"
662 "             owner=None, session=None)\n"
663 "--\n"
664 "\n");
665 
666 #define _SSL__SSLCONTEXT__WRAP_SOCKET_METHODDEF    \
667     {"_wrap_socket", (PyCFunction)(void(*)(void))_ssl__SSLContext__wrap_socket, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLContext__wrap_socket__doc__},
668 
669 static PyObject *
670 _ssl__SSLContext__wrap_socket_impl(PySSLContext *self, PyObject *sock,
671                                    int server_side, PyObject *hostname_obj,
672                                    PyObject *owner, PyObject *session);
673 
674 static PyObject *
_ssl__SSLContext__wrap_socket(PySSLContext * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)675 _ssl__SSLContext__wrap_socket(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
676 {
677     PyObject *return_value = NULL;
678     static const char * const _keywords[] = {"sock", "server_side", "server_hostname", "owner", "session", NULL};
679     static _PyArg_Parser _parser = {NULL, _keywords, "_wrap_socket", 0};
680     PyObject *argsbuf[5];
681     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
682     PyObject *sock;
683     int server_side;
684     PyObject *hostname_obj = Py_None;
685     PyObject *owner = Py_None;
686     PyObject *session = Py_None;
687 
688     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
689     if (!args) {
690         goto exit;
691     }
692     if (!PyObject_TypeCheck(args[0], PySocketModule.Sock_Type)) {
693         _PyArg_BadArgument("_wrap_socket", "argument 'sock'", (PySocketModule.Sock_Type)->tp_name, args[0]);
694         goto exit;
695     }
696     sock = args[0];
697     if (PyFloat_Check(args[1])) {
698         PyErr_SetString(PyExc_TypeError,
699                         "integer argument expected, got float" );
700         goto exit;
701     }
702     server_side = _PyLong_AsInt(args[1]);
703     if (server_side == -1 && PyErr_Occurred()) {
704         goto exit;
705     }
706     if (!noptargs) {
707         goto skip_optional_pos;
708     }
709     if (args[2]) {
710         hostname_obj = args[2];
711         if (!--noptargs) {
712             goto skip_optional_pos;
713         }
714     }
715 skip_optional_pos:
716     if (!noptargs) {
717         goto skip_optional_kwonly;
718     }
719     if (args[3]) {
720         owner = args[3];
721         if (!--noptargs) {
722             goto skip_optional_kwonly;
723         }
724     }
725     session = args[4];
726 skip_optional_kwonly:
727     return_value = _ssl__SSLContext__wrap_socket_impl(self, sock, server_side, hostname_obj, owner, session);
728 
729 exit:
730     return return_value;
731 }
732 
733 PyDoc_STRVAR(_ssl__SSLContext__wrap_bio__doc__,
734 "_wrap_bio($self, /, incoming, outgoing, server_side,\n"
735 "          server_hostname=None, *, owner=None, session=None)\n"
736 "--\n"
737 "\n");
738 
739 #define _SSL__SSLCONTEXT__WRAP_BIO_METHODDEF    \
740     {"_wrap_bio", (PyCFunction)(void(*)(void))_ssl__SSLContext__wrap_bio, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLContext__wrap_bio__doc__},
741 
742 static PyObject *
743 _ssl__SSLContext__wrap_bio_impl(PySSLContext *self, PySSLMemoryBIO *incoming,
744                                 PySSLMemoryBIO *outgoing, int server_side,
745                                 PyObject *hostname_obj, PyObject *owner,
746                                 PyObject *session);
747 
748 static PyObject *
_ssl__SSLContext__wrap_bio(PySSLContext * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)749 _ssl__SSLContext__wrap_bio(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
750 {
751     PyObject *return_value = NULL;
752     static const char * const _keywords[] = {"incoming", "outgoing", "server_side", "server_hostname", "owner", "session", NULL};
753     static _PyArg_Parser _parser = {NULL, _keywords, "_wrap_bio", 0};
754     PyObject *argsbuf[6];
755     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
756     PySSLMemoryBIO *incoming;
757     PySSLMemoryBIO *outgoing;
758     int server_side;
759     PyObject *hostname_obj = Py_None;
760     PyObject *owner = Py_None;
761     PyObject *session = Py_None;
762 
763     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 4, 0, argsbuf);
764     if (!args) {
765         goto exit;
766     }
767     if (!PyObject_TypeCheck(args[0], &PySSLMemoryBIO_Type)) {
768         _PyArg_BadArgument("_wrap_bio", "argument 'incoming'", (&PySSLMemoryBIO_Type)->tp_name, args[0]);
769         goto exit;
770     }
771     incoming = (PySSLMemoryBIO *)args[0];
772     if (!PyObject_TypeCheck(args[1], &PySSLMemoryBIO_Type)) {
773         _PyArg_BadArgument("_wrap_bio", "argument 'outgoing'", (&PySSLMemoryBIO_Type)->tp_name, args[1]);
774         goto exit;
775     }
776     outgoing = (PySSLMemoryBIO *)args[1];
777     if (PyFloat_Check(args[2])) {
778         PyErr_SetString(PyExc_TypeError,
779                         "integer argument expected, got float" );
780         goto exit;
781     }
782     server_side = _PyLong_AsInt(args[2]);
783     if (server_side == -1 && PyErr_Occurred()) {
784         goto exit;
785     }
786     if (!noptargs) {
787         goto skip_optional_pos;
788     }
789     if (args[3]) {
790         hostname_obj = args[3];
791         if (!--noptargs) {
792             goto skip_optional_pos;
793         }
794     }
795 skip_optional_pos:
796     if (!noptargs) {
797         goto skip_optional_kwonly;
798     }
799     if (args[4]) {
800         owner = args[4];
801         if (!--noptargs) {
802             goto skip_optional_kwonly;
803         }
804     }
805     session = args[5];
806 skip_optional_kwonly:
807     return_value = _ssl__SSLContext__wrap_bio_impl(self, incoming, outgoing, server_side, hostname_obj, owner, session);
808 
809 exit:
810     return return_value;
811 }
812 
813 PyDoc_STRVAR(_ssl__SSLContext_session_stats__doc__,
814 "session_stats($self, /)\n"
815 "--\n"
816 "\n");
817 
818 #define _SSL__SSLCONTEXT_SESSION_STATS_METHODDEF    \
819     {"session_stats", (PyCFunction)_ssl__SSLContext_session_stats, METH_NOARGS, _ssl__SSLContext_session_stats__doc__},
820 
821 static PyObject *
822 _ssl__SSLContext_session_stats_impl(PySSLContext *self);
823 
824 static PyObject *
_ssl__SSLContext_session_stats(PySSLContext * self,PyObject * Py_UNUSED (ignored))825 _ssl__SSLContext_session_stats(PySSLContext *self, PyObject *Py_UNUSED(ignored))
826 {
827     return _ssl__SSLContext_session_stats_impl(self);
828 }
829 
830 PyDoc_STRVAR(_ssl__SSLContext_set_default_verify_paths__doc__,
831 "set_default_verify_paths($self, /)\n"
832 "--\n"
833 "\n");
834 
835 #define _SSL__SSLCONTEXT_SET_DEFAULT_VERIFY_PATHS_METHODDEF    \
836     {"set_default_verify_paths", (PyCFunction)_ssl__SSLContext_set_default_verify_paths, METH_NOARGS, _ssl__SSLContext_set_default_verify_paths__doc__},
837 
838 static PyObject *
839 _ssl__SSLContext_set_default_verify_paths_impl(PySSLContext *self);
840 
841 static PyObject *
_ssl__SSLContext_set_default_verify_paths(PySSLContext * self,PyObject * Py_UNUSED (ignored))842 _ssl__SSLContext_set_default_verify_paths(PySSLContext *self, PyObject *Py_UNUSED(ignored))
843 {
844     return _ssl__SSLContext_set_default_verify_paths_impl(self);
845 }
846 
847 #if !defined(OPENSSL_NO_ECDH)
848 
849 PyDoc_STRVAR(_ssl__SSLContext_set_ecdh_curve__doc__,
850 "set_ecdh_curve($self, name, /)\n"
851 "--\n"
852 "\n");
853 
854 #define _SSL__SSLCONTEXT_SET_ECDH_CURVE_METHODDEF    \
855     {"set_ecdh_curve", (PyCFunction)_ssl__SSLContext_set_ecdh_curve, METH_O, _ssl__SSLContext_set_ecdh_curve__doc__},
856 
857 #endif /* !defined(OPENSSL_NO_ECDH) */
858 
859 PyDoc_STRVAR(_ssl__SSLContext_cert_store_stats__doc__,
860 "cert_store_stats($self, /)\n"
861 "--\n"
862 "\n"
863 "Returns quantities of loaded X.509 certificates.\n"
864 "\n"
865 "X.509 certificates with a CA extension and certificate revocation lists\n"
866 "inside the context\'s cert store.\n"
867 "\n"
868 "NOTE: Certificates in a capath directory aren\'t loaded unless they have\n"
869 "been used at least once.");
870 
871 #define _SSL__SSLCONTEXT_CERT_STORE_STATS_METHODDEF    \
872     {"cert_store_stats", (PyCFunction)_ssl__SSLContext_cert_store_stats, METH_NOARGS, _ssl__SSLContext_cert_store_stats__doc__},
873 
874 static PyObject *
875 _ssl__SSLContext_cert_store_stats_impl(PySSLContext *self);
876 
877 static PyObject *
_ssl__SSLContext_cert_store_stats(PySSLContext * self,PyObject * Py_UNUSED (ignored))878 _ssl__SSLContext_cert_store_stats(PySSLContext *self, PyObject *Py_UNUSED(ignored))
879 {
880     return _ssl__SSLContext_cert_store_stats_impl(self);
881 }
882 
883 PyDoc_STRVAR(_ssl__SSLContext_get_ca_certs__doc__,
884 "get_ca_certs($self, /, binary_form=False)\n"
885 "--\n"
886 "\n"
887 "Returns a list of dicts with information of loaded CA certs.\n"
888 "\n"
889 "If the optional argument is True, returns a DER-encoded copy of the CA\n"
890 "certificate.\n"
891 "\n"
892 "NOTE: Certificates in a capath directory aren\'t loaded unless they have\n"
893 "been used at least once.");
894 
895 #define _SSL__SSLCONTEXT_GET_CA_CERTS_METHODDEF    \
896     {"get_ca_certs", (PyCFunction)(void(*)(void))_ssl__SSLContext_get_ca_certs, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLContext_get_ca_certs__doc__},
897 
898 static PyObject *
899 _ssl__SSLContext_get_ca_certs_impl(PySSLContext *self, int binary_form);
900 
901 static PyObject *
_ssl__SSLContext_get_ca_certs(PySSLContext * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)902 _ssl__SSLContext_get_ca_certs(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
903 {
904     PyObject *return_value = NULL;
905     static const char * const _keywords[] = {"binary_form", NULL};
906     static _PyArg_Parser _parser = {NULL, _keywords, "get_ca_certs", 0};
907     PyObject *argsbuf[1];
908     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
909     int binary_form = 0;
910 
911     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
912     if (!args) {
913         goto exit;
914     }
915     if (!noptargs) {
916         goto skip_optional_pos;
917     }
918     binary_form = PyObject_IsTrue(args[0]);
919     if (binary_form < 0) {
920         goto exit;
921     }
922 skip_optional_pos:
923     return_value = _ssl__SSLContext_get_ca_certs_impl(self, binary_form);
924 
925 exit:
926     return return_value;
927 }
928 
929 static PyObject *
930 _ssl_MemoryBIO_impl(PyTypeObject *type);
931 
932 static PyObject *
_ssl_MemoryBIO(PyTypeObject * type,PyObject * args,PyObject * kwargs)933 _ssl_MemoryBIO(PyTypeObject *type, PyObject *args, PyObject *kwargs)
934 {
935     PyObject *return_value = NULL;
936 
937     if ((type == &PySSLMemoryBIO_Type) &&
938         !_PyArg_NoPositional("MemoryBIO", args)) {
939         goto exit;
940     }
941     if ((type == &PySSLMemoryBIO_Type) &&
942         !_PyArg_NoKeywords("MemoryBIO", kwargs)) {
943         goto exit;
944     }
945     return_value = _ssl_MemoryBIO_impl(type);
946 
947 exit:
948     return return_value;
949 }
950 
951 PyDoc_STRVAR(_ssl_MemoryBIO_read__doc__,
952 "read($self, size=-1, /)\n"
953 "--\n"
954 "\n"
955 "Read up to size bytes from the memory BIO.\n"
956 "\n"
957 "If size is not specified, read the entire buffer.\n"
958 "If the return value is an empty bytes instance, this means either\n"
959 "EOF or that no data is available. Use the \"eof\" property to\n"
960 "distinguish between the two.");
961 
962 #define _SSL_MEMORYBIO_READ_METHODDEF    \
963     {"read", (PyCFunction)(void(*)(void))_ssl_MemoryBIO_read, METH_FASTCALL, _ssl_MemoryBIO_read__doc__},
964 
965 static PyObject *
966 _ssl_MemoryBIO_read_impl(PySSLMemoryBIO *self, int len);
967 
968 static PyObject *
_ssl_MemoryBIO_read(PySSLMemoryBIO * self,PyObject * const * args,Py_ssize_t nargs)969 _ssl_MemoryBIO_read(PySSLMemoryBIO *self, PyObject *const *args, Py_ssize_t nargs)
970 {
971     PyObject *return_value = NULL;
972     int len = -1;
973 
974     if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
975         goto exit;
976     }
977     if (nargs < 1) {
978         goto skip_optional;
979     }
980     if (PyFloat_Check(args[0])) {
981         PyErr_SetString(PyExc_TypeError,
982                         "integer argument expected, got float" );
983         goto exit;
984     }
985     len = _PyLong_AsInt(args[0]);
986     if (len == -1 && PyErr_Occurred()) {
987         goto exit;
988     }
989 skip_optional:
990     return_value = _ssl_MemoryBIO_read_impl(self, len);
991 
992 exit:
993     return return_value;
994 }
995 
996 PyDoc_STRVAR(_ssl_MemoryBIO_write__doc__,
997 "write($self, b, /)\n"
998 "--\n"
999 "\n"
1000 "Writes the bytes b into the memory BIO.\n"
1001 "\n"
1002 "Returns the number of bytes written.");
1003 
1004 #define _SSL_MEMORYBIO_WRITE_METHODDEF    \
1005     {"write", (PyCFunction)_ssl_MemoryBIO_write, METH_O, _ssl_MemoryBIO_write__doc__},
1006 
1007 static PyObject *
1008 _ssl_MemoryBIO_write_impl(PySSLMemoryBIO *self, Py_buffer *b);
1009 
1010 static PyObject *
_ssl_MemoryBIO_write(PySSLMemoryBIO * self,PyObject * arg)1011 _ssl_MemoryBIO_write(PySSLMemoryBIO *self, PyObject *arg)
1012 {
1013     PyObject *return_value = NULL;
1014     Py_buffer b = {NULL, NULL};
1015 
1016     if (PyObject_GetBuffer(arg, &b, PyBUF_SIMPLE) != 0) {
1017         goto exit;
1018     }
1019     if (!PyBuffer_IsContiguous(&b, 'C')) {
1020         _PyArg_BadArgument("write", "argument", "contiguous buffer", arg);
1021         goto exit;
1022     }
1023     return_value = _ssl_MemoryBIO_write_impl(self, &b);
1024 
1025 exit:
1026     /* Cleanup for b */
1027     if (b.obj) {
1028        PyBuffer_Release(&b);
1029     }
1030 
1031     return return_value;
1032 }
1033 
1034 PyDoc_STRVAR(_ssl_MemoryBIO_write_eof__doc__,
1035 "write_eof($self, /)\n"
1036 "--\n"
1037 "\n"
1038 "Write an EOF marker to the memory BIO.\n"
1039 "\n"
1040 "When all data has been read, the \"eof\" property will be True.");
1041 
1042 #define _SSL_MEMORYBIO_WRITE_EOF_METHODDEF    \
1043     {"write_eof", (PyCFunction)_ssl_MemoryBIO_write_eof, METH_NOARGS, _ssl_MemoryBIO_write_eof__doc__},
1044 
1045 static PyObject *
1046 _ssl_MemoryBIO_write_eof_impl(PySSLMemoryBIO *self);
1047 
1048 static PyObject *
_ssl_MemoryBIO_write_eof(PySSLMemoryBIO * self,PyObject * Py_UNUSED (ignored))1049 _ssl_MemoryBIO_write_eof(PySSLMemoryBIO *self, PyObject *Py_UNUSED(ignored))
1050 {
1051     return _ssl_MemoryBIO_write_eof_impl(self);
1052 }
1053 
1054 PyDoc_STRVAR(_ssl_RAND_add__doc__,
1055 "RAND_add($module, string, entropy, /)\n"
1056 "--\n"
1057 "\n"
1058 "Mix string into the OpenSSL PRNG state.\n"
1059 "\n"
1060 "entropy (a float) is a lower bound on the entropy contained in\n"
1061 "string.  See RFC 4086.");
1062 
1063 #define _SSL_RAND_ADD_METHODDEF    \
1064     {"RAND_add", (PyCFunction)(void(*)(void))_ssl_RAND_add, METH_FASTCALL, _ssl_RAND_add__doc__},
1065 
1066 static PyObject *
1067 _ssl_RAND_add_impl(PyObject *module, Py_buffer *view, double entropy);
1068 
1069 static PyObject *
_ssl_RAND_add(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1070 _ssl_RAND_add(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1071 {
1072     PyObject *return_value = NULL;
1073     Py_buffer view = {NULL, NULL};
1074     double entropy;
1075 
1076     if (!_PyArg_CheckPositional("RAND_add", nargs, 2, 2)) {
1077         goto exit;
1078     }
1079     if (PyUnicode_Check(args[0])) {
1080         Py_ssize_t len;
1081         const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1082         if (ptr == NULL) {
1083             goto exit;
1084         }
1085         PyBuffer_FillInfo(&view, args[0], (void *)ptr, len, 1, 0);
1086     }
1087     else { /* any bytes-like object */
1088         if (PyObject_GetBuffer(args[0], &view, PyBUF_SIMPLE) != 0) {
1089             goto exit;
1090         }
1091         if (!PyBuffer_IsContiguous(&view, 'C')) {
1092             _PyArg_BadArgument("RAND_add", "argument 1", "contiguous buffer", args[0]);
1093             goto exit;
1094         }
1095     }
1096     if (PyFloat_CheckExact(args[1])) {
1097         entropy = PyFloat_AS_DOUBLE(args[1]);
1098     }
1099     else
1100     {
1101         entropy = PyFloat_AsDouble(args[1]);
1102         if (entropy == -1.0 && PyErr_Occurred()) {
1103             goto exit;
1104         }
1105     }
1106     return_value = _ssl_RAND_add_impl(module, &view, entropy);
1107 
1108 exit:
1109     /* Cleanup for view */
1110     if (view.obj) {
1111        PyBuffer_Release(&view);
1112     }
1113 
1114     return return_value;
1115 }
1116 
1117 PyDoc_STRVAR(_ssl_RAND_bytes__doc__,
1118 "RAND_bytes($module, n, /)\n"
1119 "--\n"
1120 "\n"
1121 "Generate n cryptographically strong pseudo-random bytes.");
1122 
1123 #define _SSL_RAND_BYTES_METHODDEF    \
1124     {"RAND_bytes", (PyCFunction)_ssl_RAND_bytes, METH_O, _ssl_RAND_bytes__doc__},
1125 
1126 static PyObject *
1127 _ssl_RAND_bytes_impl(PyObject *module, int n);
1128 
1129 static PyObject *
_ssl_RAND_bytes(PyObject * module,PyObject * arg)1130 _ssl_RAND_bytes(PyObject *module, PyObject *arg)
1131 {
1132     PyObject *return_value = NULL;
1133     int n;
1134 
1135     if (PyFloat_Check(arg)) {
1136         PyErr_SetString(PyExc_TypeError,
1137                         "integer argument expected, got float" );
1138         goto exit;
1139     }
1140     n = _PyLong_AsInt(arg);
1141     if (n == -1 && PyErr_Occurred()) {
1142         goto exit;
1143     }
1144     return_value = _ssl_RAND_bytes_impl(module, n);
1145 
1146 exit:
1147     return return_value;
1148 }
1149 
1150 PyDoc_STRVAR(_ssl_RAND_pseudo_bytes__doc__,
1151 "RAND_pseudo_bytes($module, n, /)\n"
1152 "--\n"
1153 "\n"
1154 "Generate n pseudo-random bytes.\n"
1155 "\n"
1156 "Return a pair (bytes, is_cryptographic).  is_cryptographic is True\n"
1157 "if the bytes generated are cryptographically strong.");
1158 
1159 #define _SSL_RAND_PSEUDO_BYTES_METHODDEF    \
1160     {"RAND_pseudo_bytes", (PyCFunction)_ssl_RAND_pseudo_bytes, METH_O, _ssl_RAND_pseudo_bytes__doc__},
1161 
1162 static PyObject *
1163 _ssl_RAND_pseudo_bytes_impl(PyObject *module, int n);
1164 
1165 static PyObject *
_ssl_RAND_pseudo_bytes(PyObject * module,PyObject * arg)1166 _ssl_RAND_pseudo_bytes(PyObject *module, PyObject *arg)
1167 {
1168     PyObject *return_value = NULL;
1169     int n;
1170 
1171     if (PyFloat_Check(arg)) {
1172         PyErr_SetString(PyExc_TypeError,
1173                         "integer argument expected, got float" );
1174         goto exit;
1175     }
1176     n = _PyLong_AsInt(arg);
1177     if (n == -1 && PyErr_Occurred()) {
1178         goto exit;
1179     }
1180     return_value = _ssl_RAND_pseudo_bytes_impl(module, n);
1181 
1182 exit:
1183     return return_value;
1184 }
1185 
1186 PyDoc_STRVAR(_ssl_RAND_status__doc__,
1187 "RAND_status($module, /)\n"
1188 "--\n"
1189 "\n"
1190 "Returns 1 if the OpenSSL PRNG has been seeded with enough data and 0 if not.\n"
1191 "\n"
1192 "It is necessary to seed the PRNG with RAND_add() on some platforms before\n"
1193 "using the ssl() function.");
1194 
1195 #define _SSL_RAND_STATUS_METHODDEF    \
1196     {"RAND_status", (PyCFunction)_ssl_RAND_status, METH_NOARGS, _ssl_RAND_status__doc__},
1197 
1198 static PyObject *
1199 _ssl_RAND_status_impl(PyObject *module);
1200 
1201 static PyObject *
_ssl_RAND_status(PyObject * module,PyObject * Py_UNUSED (ignored))1202 _ssl_RAND_status(PyObject *module, PyObject *Py_UNUSED(ignored))
1203 {
1204     return _ssl_RAND_status_impl(module);
1205 }
1206 
1207 #if !defined(OPENSSL_NO_EGD)
1208 
1209 PyDoc_STRVAR(_ssl_RAND_egd__doc__,
1210 "RAND_egd($module, path, /)\n"
1211 "--\n"
1212 "\n"
1213 "Queries the entropy gather daemon (EGD) on the socket named by \'path\'.\n"
1214 "\n"
1215 "Returns number of bytes read.  Raises SSLError if connection to EGD\n"
1216 "fails or if it does not provide enough data to seed PRNG.");
1217 
1218 #define _SSL_RAND_EGD_METHODDEF    \
1219     {"RAND_egd", (PyCFunction)_ssl_RAND_egd, METH_O, _ssl_RAND_egd__doc__},
1220 
1221 static PyObject *
1222 _ssl_RAND_egd_impl(PyObject *module, PyObject *path);
1223 
1224 static PyObject *
_ssl_RAND_egd(PyObject * module,PyObject * arg)1225 _ssl_RAND_egd(PyObject *module, PyObject *arg)
1226 {
1227     PyObject *return_value = NULL;
1228     PyObject *path;
1229 
1230     if (!PyUnicode_FSConverter(arg, &path)) {
1231         goto exit;
1232     }
1233     return_value = _ssl_RAND_egd_impl(module, path);
1234 
1235 exit:
1236     return return_value;
1237 }
1238 
1239 #endif /* !defined(OPENSSL_NO_EGD) */
1240 
1241 PyDoc_STRVAR(_ssl_get_default_verify_paths__doc__,
1242 "get_default_verify_paths($module, /)\n"
1243 "--\n"
1244 "\n"
1245 "Return search paths and environment vars that are used by SSLContext\'s set_default_verify_paths() to load default CAs.\n"
1246 "\n"
1247 "The values are \'cert_file_env\', \'cert_file\', \'cert_dir_env\', \'cert_dir\'.");
1248 
1249 #define _SSL_GET_DEFAULT_VERIFY_PATHS_METHODDEF    \
1250     {"get_default_verify_paths", (PyCFunction)_ssl_get_default_verify_paths, METH_NOARGS, _ssl_get_default_verify_paths__doc__},
1251 
1252 static PyObject *
1253 _ssl_get_default_verify_paths_impl(PyObject *module);
1254 
1255 static PyObject *
_ssl_get_default_verify_paths(PyObject * module,PyObject * Py_UNUSED (ignored))1256 _ssl_get_default_verify_paths(PyObject *module, PyObject *Py_UNUSED(ignored))
1257 {
1258     return _ssl_get_default_verify_paths_impl(module);
1259 }
1260 
1261 PyDoc_STRVAR(_ssl_txt2obj__doc__,
1262 "txt2obj($module, /, txt, name=False)\n"
1263 "--\n"
1264 "\n"
1265 "Lookup NID, short name, long name and OID of an ASN1_OBJECT.\n"
1266 "\n"
1267 "By default objects are looked up by OID. With name=True short and\n"
1268 "long name are also matched.");
1269 
1270 #define _SSL_TXT2OBJ_METHODDEF    \
1271     {"txt2obj", (PyCFunction)(void(*)(void))_ssl_txt2obj, METH_FASTCALL|METH_KEYWORDS, _ssl_txt2obj__doc__},
1272 
1273 static PyObject *
1274 _ssl_txt2obj_impl(PyObject *module, const char *txt, int name);
1275 
1276 static PyObject *
_ssl_txt2obj(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1277 _ssl_txt2obj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1278 {
1279     PyObject *return_value = NULL;
1280     static const char * const _keywords[] = {"txt", "name", NULL};
1281     static _PyArg_Parser _parser = {NULL, _keywords, "txt2obj", 0};
1282     PyObject *argsbuf[2];
1283     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1284     const char *txt;
1285     int name = 0;
1286 
1287     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
1288     if (!args) {
1289         goto exit;
1290     }
1291     if (!PyUnicode_Check(args[0])) {
1292         _PyArg_BadArgument("txt2obj", "argument 'txt'", "str", args[0]);
1293         goto exit;
1294     }
1295     Py_ssize_t txt_length;
1296     txt = PyUnicode_AsUTF8AndSize(args[0], &txt_length);
1297     if (txt == NULL) {
1298         goto exit;
1299     }
1300     if (strlen(txt) != (size_t)txt_length) {
1301         PyErr_SetString(PyExc_ValueError, "embedded null character");
1302         goto exit;
1303     }
1304     if (!noptargs) {
1305         goto skip_optional_pos;
1306     }
1307     name = PyObject_IsTrue(args[1]);
1308     if (name < 0) {
1309         goto exit;
1310     }
1311 skip_optional_pos:
1312     return_value = _ssl_txt2obj_impl(module, txt, name);
1313 
1314 exit:
1315     return return_value;
1316 }
1317 
1318 PyDoc_STRVAR(_ssl_nid2obj__doc__,
1319 "nid2obj($module, nid, /)\n"
1320 "--\n"
1321 "\n"
1322 "Lookup NID, short name, long name and OID of an ASN1_OBJECT by NID.");
1323 
1324 #define _SSL_NID2OBJ_METHODDEF    \
1325     {"nid2obj", (PyCFunction)_ssl_nid2obj, METH_O, _ssl_nid2obj__doc__},
1326 
1327 static PyObject *
1328 _ssl_nid2obj_impl(PyObject *module, int nid);
1329 
1330 static PyObject *
_ssl_nid2obj(PyObject * module,PyObject * arg)1331 _ssl_nid2obj(PyObject *module, PyObject *arg)
1332 {
1333     PyObject *return_value = NULL;
1334     int nid;
1335 
1336     if (PyFloat_Check(arg)) {
1337         PyErr_SetString(PyExc_TypeError,
1338                         "integer argument expected, got float" );
1339         goto exit;
1340     }
1341     nid = _PyLong_AsInt(arg);
1342     if (nid == -1 && PyErr_Occurred()) {
1343         goto exit;
1344     }
1345     return_value = _ssl_nid2obj_impl(module, nid);
1346 
1347 exit:
1348     return return_value;
1349 }
1350 
1351 #if defined(_MSC_VER)
1352 
1353 PyDoc_STRVAR(_ssl_enum_certificates__doc__,
1354 "enum_certificates($module, /, store_name)\n"
1355 "--\n"
1356 "\n"
1357 "Retrieve certificates from Windows\' cert store.\n"
1358 "\n"
1359 "store_name may be one of \'CA\', \'ROOT\' or \'MY\'.  The system may provide\n"
1360 "more cert storages, too.  The function returns a list of (bytes,\n"
1361 "encoding_type, trust) tuples.  The encoding_type flag can be interpreted\n"
1362 "with X509_ASN_ENCODING or PKCS_7_ASN_ENCODING. The trust setting is either\n"
1363 "a set of OIDs or the boolean True.");
1364 
1365 #define _SSL_ENUM_CERTIFICATES_METHODDEF    \
1366     {"enum_certificates", (PyCFunction)(void(*)(void))_ssl_enum_certificates, METH_FASTCALL|METH_KEYWORDS, _ssl_enum_certificates__doc__},
1367 
1368 static PyObject *
1369 _ssl_enum_certificates_impl(PyObject *module, const char *store_name);
1370 
1371 static PyObject *
_ssl_enum_certificates(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1372 _ssl_enum_certificates(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1373 {
1374     PyObject *return_value = NULL;
1375     static const char * const _keywords[] = {"store_name", NULL};
1376     static _PyArg_Parser _parser = {NULL, _keywords, "enum_certificates", 0};
1377     PyObject *argsbuf[1];
1378     const char *store_name;
1379 
1380     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1381     if (!args) {
1382         goto exit;
1383     }
1384     if (!PyUnicode_Check(args[0])) {
1385         _PyArg_BadArgument("enum_certificates", "argument 'store_name'", "str", args[0]);
1386         goto exit;
1387     }
1388     Py_ssize_t store_name_length;
1389     store_name = PyUnicode_AsUTF8AndSize(args[0], &store_name_length);
1390     if (store_name == NULL) {
1391         goto exit;
1392     }
1393     if (strlen(store_name) != (size_t)store_name_length) {
1394         PyErr_SetString(PyExc_ValueError, "embedded null character");
1395         goto exit;
1396     }
1397     return_value = _ssl_enum_certificates_impl(module, store_name);
1398 
1399 exit:
1400     return return_value;
1401 }
1402 
1403 #endif /* defined(_MSC_VER) */
1404 
1405 #if defined(_MSC_VER)
1406 
1407 PyDoc_STRVAR(_ssl_enum_crls__doc__,
1408 "enum_crls($module, /, store_name)\n"
1409 "--\n"
1410 "\n"
1411 "Retrieve CRLs from Windows\' cert store.\n"
1412 "\n"
1413 "store_name may be one of \'CA\', \'ROOT\' or \'MY\'.  The system may provide\n"
1414 "more cert storages, too.  The function returns a list of (bytes,\n"
1415 "encoding_type) tuples.  The encoding_type flag can be interpreted with\n"
1416 "X509_ASN_ENCODING or PKCS_7_ASN_ENCODING.");
1417 
1418 #define _SSL_ENUM_CRLS_METHODDEF    \
1419     {"enum_crls", (PyCFunction)(void(*)(void))_ssl_enum_crls, METH_FASTCALL|METH_KEYWORDS, _ssl_enum_crls__doc__},
1420 
1421 static PyObject *
1422 _ssl_enum_crls_impl(PyObject *module, const char *store_name);
1423 
1424 static PyObject *
_ssl_enum_crls(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1425 _ssl_enum_crls(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1426 {
1427     PyObject *return_value = NULL;
1428     static const char * const _keywords[] = {"store_name", NULL};
1429     static _PyArg_Parser _parser = {NULL, _keywords, "enum_crls", 0};
1430     PyObject *argsbuf[1];
1431     const char *store_name;
1432 
1433     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1434     if (!args) {
1435         goto exit;
1436     }
1437     if (!PyUnicode_Check(args[0])) {
1438         _PyArg_BadArgument("enum_crls", "argument 'store_name'", "str", args[0]);
1439         goto exit;
1440     }
1441     Py_ssize_t store_name_length;
1442     store_name = PyUnicode_AsUTF8AndSize(args[0], &store_name_length);
1443     if (store_name == NULL) {
1444         goto exit;
1445     }
1446     if (strlen(store_name) != (size_t)store_name_length) {
1447         PyErr_SetString(PyExc_ValueError, "embedded null character");
1448         goto exit;
1449     }
1450     return_value = _ssl_enum_crls_impl(module, store_name);
1451 
1452 exit:
1453     return return_value;
1454 }
1455 
1456 #endif /* defined(_MSC_VER) */
1457 
1458 #ifndef _SSL__SSLSOCKET_SELECTED_NPN_PROTOCOL_METHODDEF
1459     #define _SSL__SSLSOCKET_SELECTED_NPN_PROTOCOL_METHODDEF
1460 #endif /* !defined(_SSL__SSLSOCKET_SELECTED_NPN_PROTOCOL_METHODDEF) */
1461 
1462 #ifndef _SSL__SSLSOCKET_SELECTED_ALPN_PROTOCOL_METHODDEF
1463     #define _SSL__SSLSOCKET_SELECTED_ALPN_PROTOCOL_METHODDEF
1464 #endif /* !defined(_SSL__SSLSOCKET_SELECTED_ALPN_PROTOCOL_METHODDEF) */
1465 
1466 #ifndef _SSL__SSLCONTEXT_GET_CIPHERS_METHODDEF
1467     #define _SSL__SSLCONTEXT_GET_CIPHERS_METHODDEF
1468 #endif /* !defined(_SSL__SSLCONTEXT_GET_CIPHERS_METHODDEF) */
1469 
1470 #ifndef _SSL__SSLCONTEXT_SET_ECDH_CURVE_METHODDEF
1471     #define _SSL__SSLCONTEXT_SET_ECDH_CURVE_METHODDEF
1472 #endif /* !defined(_SSL__SSLCONTEXT_SET_ECDH_CURVE_METHODDEF) */
1473 
1474 #ifndef _SSL_RAND_EGD_METHODDEF
1475     #define _SSL_RAND_EGD_METHODDEF
1476 #endif /* !defined(_SSL_RAND_EGD_METHODDEF) */
1477 
1478 #ifndef _SSL_ENUM_CERTIFICATES_METHODDEF
1479     #define _SSL_ENUM_CERTIFICATES_METHODDEF
1480 #endif /* !defined(_SSL_ENUM_CERTIFICATES_METHODDEF) */
1481 
1482 #ifndef _SSL_ENUM_CRLS_METHODDEF
1483     #define _SSL_ENUM_CRLS_METHODDEF
1484 #endif /* !defined(_SSL_ENUM_CRLS_METHODDEF) */
1485 /*[clinic end generated code: output=a4aeb3f92a091c64 input=a9049054013a1b77]*/
1486