blob: 43469d3c358242712c7f80f1f65e6cc04a9f3f25 [file] [log] [blame]
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_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
13static PyObject *
14_ssl__SSLSocket_do_handshake_impl(PySSLSocket *self);
15
16static PyObject *
17_ssl__SSLSocket_do_handshake(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
18{
19 return _ssl__SSLSocket_do_handshake_impl(self);
20}
21
22PyDoc_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
30static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030031_ssl__test_decode_cert_impl(PyObject *module, PyObject *path);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +030032
33static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030034_ssl__test_decode_cert(PyObject *module, PyObject *arg)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +030035{
36 PyObject *return_value = NULL;
37 PyObject *path;
38
Serhiy Storchaka32d96a22018-12-25 13:23:47 +020039 if (!PyUnicode_FSConverter(arg, &path)) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +030040 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030041 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +030042 return_value = _ssl__test_decode_cert_impl(module, path);
43
44exit:
45 return return_value;
46}
47
Christian Heimes141c5e82018-02-24 21:10:57 +010048PyDoc_STRVAR(_ssl__SSLSocket_getpeercert__doc__,
49"getpeercert($self, der=False, /)\n"
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +030050"--\n"
51"\n"
52"Returns the certificate for the peer.\n"
53"\n"
54"If no certificate was provided, returns None. If a certificate was\n"
55"provided, but not validated, returns an empty dictionary. Otherwise\n"
56"returns a dict containing information about the peer certificate.\n"
57"\n"
58"If the optional argument is True, returns a DER-encoded copy of the\n"
59"peer certificate, or None if no certificate was provided. This will\n"
60"return the certificate even if it wasn\'t validated.");
61
Christian Heimes141c5e82018-02-24 21:10:57 +010062#define _SSL__SSLSOCKET_GETPEERCERT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020063 {"getpeercert", (PyCFunction)(void(*)(void))_ssl__SSLSocket_getpeercert, METH_FASTCALL, _ssl__SSLSocket_getpeercert__doc__},
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +030064
65static PyObject *
Christian Heimes141c5e82018-02-24 21:10:57 +010066_ssl__SSLSocket_getpeercert_impl(PySSLSocket *self, int binary_mode);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +030067
68static PyObject *
Christian Heimes141c5e82018-02-24 21:10:57 +010069_ssl__SSLSocket_getpeercert(PySSLSocket *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +030070{
71 PyObject *return_value = NULL;
72 int binary_mode = 0;
73
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020074 if (!_PyArg_CheckPositional("getpeercert", nargs, 0, 1)) {
Victor Stinner259f0e42017-01-17 01:35:17 +010075 goto exit;
76 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020077 if (nargs < 1) {
78 goto skip_optional;
79 }
80 binary_mode = PyObject_IsTrue(args[0]);
81 if (binary_mode < 0) {
82 goto exit;
83 }
84skip_optional:
Christian Heimes141c5e82018-02-24 21:10:57 +010085 return_value = _ssl__SSLSocket_getpeercert_impl(self, binary_mode);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +030086
87exit:
88 return return_value;
89}
90
91PyDoc_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
99static PyObject *
100_ssl__SSLSocket_shared_ciphers_impl(PySSLSocket *self);
101
102static PyObject *
103_ssl__SSLSocket_shared_ciphers(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
104{
105 return _ssl__SSLSocket_shared_ciphers_impl(self);
106}
107
108PyDoc_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
116static PyObject *
117_ssl__SSLSocket_cipher_impl(PySSLSocket *self);
118
119static PyObject *
120_ssl__SSLSocket_cipher(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
121{
122 return _ssl__SSLSocket_cipher_impl(self);
123}
124
125PyDoc_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
133static PyObject *
134_ssl__SSLSocket_version_impl(PySSLSocket *self);
135
136static PyObject *
137_ssl__SSLSocket_version(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
138{
139 return _ssl__SSLSocket_version_impl(self);
140}
141
Christian Heimes29eab552018-02-25 12:31:33 +0100142#if (HAVE_NPN)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300143
144PyDoc_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
152static PyObject *
153_ssl__SSLSocket_selected_npn_protocol_impl(PySSLSocket *self);
154
155static PyObject *
156_ssl__SSLSocket_selected_npn_protocol(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
157{
158 return _ssl__SSLSocket_selected_npn_protocol_impl(self);
159}
160
Christian Heimes29eab552018-02-25 12:31:33 +0100161#endif /* (HAVE_NPN) */
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300162
Christian Heimes29eab552018-02-25 12:31:33 +0100163#if (HAVE_ALPN)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300164
165PyDoc_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
173static PyObject *
174_ssl__SSLSocket_selected_alpn_protocol_impl(PySSLSocket *self);
175
176static PyObject *
177_ssl__SSLSocket_selected_alpn_protocol(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
178{
179 return _ssl__SSLSocket_selected_alpn_protocol_impl(self);
180}
181
Christian Heimes29eab552018-02-25 12:31:33 +0100182#endif /* (HAVE_ALPN) */
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300183
184PyDoc_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
192static PyObject *
193_ssl__SSLSocket_compression_impl(PySSLSocket *self);
194
195static PyObject *
196_ssl__SSLSocket_compression(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
197{
198 return _ssl__SSLSocket_compression_impl(self);
199}
200
201PyDoc_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
212static PyObject *
213_ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b);
214
215static PyObject *
216_ssl__SSLSocket_write(PySSLSocket *self, PyObject *arg)
217{
218 PyObject *return_value = NULL;
219 Py_buffer b = {NULL, NULL};
220
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200221 if (PyObject_GetBuffer(arg, &b, PyBUF_SIMPLE) != 0) {
222 goto exit;
223 }
224 if (!PyBuffer_IsContiguous(&b, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200225 _PyArg_BadArgument("write", "argument", "contiguous buffer", arg);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300226 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300227 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300228 return_value = _ssl__SSLSocket_write_impl(self, &b);
229
230exit:
231 /* Cleanup for b */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300232 if (b.obj) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300233 PyBuffer_Release(&b);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300234 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300235
236 return return_value;
237}
238
239PyDoc_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
248static PyObject *
249_ssl__SSLSocket_pending_impl(PySSLSocket *self);
250
251static PyObject *
252_ssl__SSLSocket_pending(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
253{
254 return _ssl__SSLSocket_pending_impl(self);
255}
256
257PyDoc_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
264static PyObject *
265_ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
266 Py_buffer *buffer);
267
268static PyObject *
269_ssl__SSLSocket_read(PySSLSocket *self, PyObject *args)
270{
271 PyObject *return_value = NULL;
272 int len;
273 int group_right_1 = 0;
274 Py_buffer buffer = {NULL, NULL};
275
276 switch (PyTuple_GET_SIZE(args)) {
277 case 1:
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300278 if (!PyArg_ParseTuple(args, "i:read", &len)) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300279 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300280 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300281 break;
282 case 2:
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300283 if (!PyArg_ParseTuple(args, "iw*:read", &len, &buffer)) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300284 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300285 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300286 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
294exit:
295 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300296 if (buffer.obj) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300297 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300298 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300299
300 return return_value;
301}
302
303PyDoc_STRVAR(_ssl__SSLSocket_shutdown__doc__,
304"shutdown($self, /)\n"
305"--\n"
306"\n"
Christian Heimes141c5e82018-02-24 21:10:57 +0100307"Does the SSL shutdown handshake with the remote end.");
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300308
309#define _SSL__SSLSOCKET_SHUTDOWN_METHODDEF \
310 {"shutdown", (PyCFunction)_ssl__SSLSocket_shutdown, METH_NOARGS, _ssl__SSLSocket_shutdown__doc__},
311
312static PyObject *
313_ssl__SSLSocket_shutdown_impl(PySSLSocket *self);
314
315static PyObject *
316_ssl__SSLSocket_shutdown(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
317{
318 return _ssl__SSLSocket_shutdown_impl(self);
319}
320
Christian Heimes141c5e82018-02-24 21:10:57 +0100321PyDoc_STRVAR(_ssl__SSLSocket_get_channel_binding__doc__,
322"get_channel_binding($self, /, cb_type=\'tls-unique\')\n"
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300323"--\n"
324"\n"
Christian Heimes141c5e82018-02-24 21:10:57 +0100325"Get channel binding data for current connection.\n"
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300326"\n"
Christian Heimes141c5e82018-02-24 21:10:57 +0100327"Raise ValueError if the requested `cb_type` is not supported. Return bytes\n"
328"of the data or None if the data is not available (e.g. before the handshake).\n"
329"Only \'tls-unique\' channel binding data from RFC 5929 is supported.");
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300330
Christian Heimes141c5e82018-02-24 21:10:57 +0100331#define _SSL__SSLSOCKET_GET_CHANNEL_BINDING_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200332 {"get_channel_binding", (PyCFunction)(void(*)(void))_ssl__SSLSocket_get_channel_binding, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLSocket_get_channel_binding__doc__},
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300333
334static PyObject *
Christian Heimes141c5e82018-02-24 21:10:57 +0100335_ssl__SSLSocket_get_channel_binding_impl(PySSLSocket *self,
336 const char *cb_type);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300337
338static PyObject *
Christian Heimes141c5e82018-02-24 21:10:57 +0100339_ssl__SSLSocket_get_channel_binding(PySSLSocket *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300340{
Christian Heimes141c5e82018-02-24 21:10:57 +0100341 PyObject *return_value = NULL;
342 static const char * const _keywords[] = {"cb_type", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200343 static _PyArg_Parser _parser = {NULL, _keywords, "get_channel_binding", 0};
344 PyObject *argsbuf[1];
345 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
Christian Heimes141c5e82018-02-24 21:10:57 +0100346 const char *cb_type = "tls-unique";
347
Serhiy Storchaka31913912019-03-14 10:32:22 +0200348 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
349 if (!args) {
Christian Heimes141c5e82018-02-24 21:10:57 +0100350 goto exit;
351 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200352 if (!noptargs) {
353 goto skip_optional_pos;
354 }
355 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200356 _PyArg_BadArgument("get_channel_binding", "argument 'cb_type'", "str", args[0]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200357 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 }
368skip_optional_pos:
Christian Heimes141c5e82018-02-24 21:10:57 +0100369 return_value = _ssl__SSLSocket_get_channel_binding_impl(self, cb_type);
370
371exit:
372 return return_value;
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300373}
374
Christian Heimes9fb051f2018-09-23 08:32:31 +0200375PyDoc_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
384static PyObject *
385_ssl__SSLSocket_verify_client_post_handshake_impl(PySSLSocket *self);
386
387static PyObject *
388_ssl__SSLSocket_verify_client_post_handshake(PySSLSocket *self, PyObject *Py_UNUSED(ignored))
389{
390 return _ssl__SSLSocket_verify_client_post_handshake_impl(self);
391}
392
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300393static PyObject *
394_ssl__SSLContext_impl(PyTypeObject *type, int proto_version);
395
396static PyObject *
397_ssl__SSLContext(PyTypeObject *type, PyObject *args, PyObject *kwargs)
398{
399 PyObject *return_value = NULL;
400 int proto_version;
401
Christian Heimes5c36da72020-11-20 09:40:12 +0100402 if ((type == PySSLContext_Type) &&
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300403 !_PyArg_NoKeywords("_SSLContext", kwargs)) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300404 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300405 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200406 if (!_PyArg_CheckPositional("_SSLContext", PyTuple_GET_SIZE(args), 1, 1)) {
407 goto exit;
408 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200409 proto_version = _PyLong_AsInt(PyTuple_GET_ITEM(args, 0));
410 if (proto_version == -1 && PyErr_Occurred()) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300411 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300412 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300413 return_value = _ssl__SSLContext_impl(type, proto_version);
414
415exit:
416 return return_value;
417}
418
419PyDoc_STRVAR(_ssl__SSLContext_set_ciphers__doc__,
420"set_ciphers($self, cipherlist, /)\n"
421"--\n"
422"\n");
423
424#define _SSL__SSLCONTEXT_SET_CIPHERS_METHODDEF \
425 {"set_ciphers", (PyCFunction)_ssl__SSLContext_set_ciphers, METH_O, _ssl__SSLContext_set_ciphers__doc__},
426
427static PyObject *
428_ssl__SSLContext_set_ciphers_impl(PySSLContext *self, const char *cipherlist);
429
430static PyObject *
431_ssl__SSLContext_set_ciphers(PySSLContext *self, PyObject *arg)
432{
433 PyObject *return_value = NULL;
434 const char *cipherlist;
435
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200436 if (!PyUnicode_Check(arg)) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200437 _PyArg_BadArgument("set_ciphers", "argument", "str", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200438 goto exit;
439 }
440 Py_ssize_t cipherlist_length;
441 cipherlist = PyUnicode_AsUTF8AndSize(arg, &cipherlist_length);
442 if (cipherlist == NULL) {
443 goto exit;
444 }
445 if (strlen(cipherlist) != (size_t)cipherlist_length) {
446 PyErr_SetString(PyExc_ValueError, "embedded null character");
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300447 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300448 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300449 return_value = _ssl__SSLContext_set_ciphers_impl(self, cipherlist);
450
451exit:
452 return return_value;
453}
454
Christian Heimes25bfcd52016-09-06 00:04:45 +0200455#if (OPENSSL_VERSION_NUMBER >= 0x10002000UL)
456
457PyDoc_STRVAR(_ssl__SSLContext_get_ciphers__doc__,
458"get_ciphers($self, /)\n"
459"--\n"
460"\n");
461
462#define _SSL__SSLCONTEXT_GET_CIPHERS_METHODDEF \
463 {"get_ciphers", (PyCFunction)_ssl__SSLContext_get_ciphers, METH_NOARGS, _ssl__SSLContext_get_ciphers__doc__},
464
465static PyObject *
466_ssl__SSLContext_get_ciphers_impl(PySSLContext *self);
467
468static PyObject *
469_ssl__SSLContext_get_ciphers(PySSLContext *self, PyObject *Py_UNUSED(ignored))
470{
471 return _ssl__SSLContext_get_ciphers_impl(self);
472}
473
474#endif /* (OPENSSL_VERSION_NUMBER >= 0x10002000UL) */
475
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300476PyDoc_STRVAR(_ssl__SSLContext__set_npn_protocols__doc__,
477"_set_npn_protocols($self, protos, /)\n"
478"--\n"
479"\n");
480
481#define _SSL__SSLCONTEXT__SET_NPN_PROTOCOLS_METHODDEF \
482 {"_set_npn_protocols", (PyCFunction)_ssl__SSLContext__set_npn_protocols, METH_O, _ssl__SSLContext__set_npn_protocols__doc__},
483
484static PyObject *
485_ssl__SSLContext__set_npn_protocols_impl(PySSLContext *self,
486 Py_buffer *protos);
487
488static PyObject *
489_ssl__SSLContext__set_npn_protocols(PySSLContext *self, PyObject *arg)
490{
491 PyObject *return_value = NULL;
492 Py_buffer protos = {NULL, NULL};
493
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200494 if (PyObject_GetBuffer(arg, &protos, PyBUF_SIMPLE) != 0) {
495 goto exit;
496 }
497 if (!PyBuffer_IsContiguous(&protos, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200498 _PyArg_BadArgument("_set_npn_protocols", "argument", "contiguous buffer", arg);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300499 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300500 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300501 return_value = _ssl__SSLContext__set_npn_protocols_impl(self, &protos);
502
503exit:
504 /* Cleanup for protos */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300505 if (protos.obj) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300506 PyBuffer_Release(&protos);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300507 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300508
509 return return_value;
510}
511
512PyDoc_STRVAR(_ssl__SSLContext__set_alpn_protocols__doc__,
513"_set_alpn_protocols($self, protos, /)\n"
514"--\n"
515"\n");
516
517#define _SSL__SSLCONTEXT__SET_ALPN_PROTOCOLS_METHODDEF \
518 {"_set_alpn_protocols", (PyCFunction)_ssl__SSLContext__set_alpn_protocols, METH_O, _ssl__SSLContext__set_alpn_protocols__doc__},
519
520static PyObject *
521_ssl__SSLContext__set_alpn_protocols_impl(PySSLContext *self,
522 Py_buffer *protos);
523
524static PyObject *
525_ssl__SSLContext__set_alpn_protocols(PySSLContext *self, PyObject *arg)
526{
527 PyObject *return_value = NULL;
528 Py_buffer protos = {NULL, NULL};
529
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200530 if (PyObject_GetBuffer(arg, &protos, PyBUF_SIMPLE) != 0) {
531 goto exit;
532 }
533 if (!PyBuffer_IsContiguous(&protos, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200534 _PyArg_BadArgument("_set_alpn_protocols", "argument", "contiguous buffer", arg);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300535 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300536 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300537 return_value = _ssl__SSLContext__set_alpn_protocols_impl(self, &protos);
538
539exit:
540 /* Cleanup for protos */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300541 if (protos.obj) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300542 PyBuffer_Release(&protos);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300543 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300544
545 return return_value;
546}
547
548PyDoc_STRVAR(_ssl__SSLContext_load_cert_chain__doc__,
549"load_cert_chain($self, /, certfile, keyfile=None, password=None)\n"
550"--\n"
551"\n");
552
553#define _SSL__SSLCONTEXT_LOAD_CERT_CHAIN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200554 {"load_cert_chain", (PyCFunction)(void(*)(void))_ssl__SSLContext_load_cert_chain, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLContext_load_cert_chain__doc__},
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300555
556static PyObject *
557_ssl__SSLContext_load_cert_chain_impl(PySSLContext *self, PyObject *certfile,
558 PyObject *keyfile, PyObject *password);
559
560static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200561_ssl__SSLContext_load_cert_chain(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300562{
563 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300564 static const char * const _keywords[] = {"certfile", "keyfile", "password", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200565 static _PyArg_Parser _parser = {NULL, _keywords, "load_cert_chain", 0};
566 PyObject *argsbuf[3];
567 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300568 PyObject *certfile;
Serhiy Storchaka279f4462019-09-14 12:24:05 +0300569 PyObject *keyfile = Py_None;
570 PyObject *password = Py_None;
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300571
Serhiy Storchaka31913912019-03-14 10:32:22 +0200572 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
573 if (!args) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300574 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300575 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200576 certfile = args[0];
577 if (!noptargs) {
578 goto skip_optional_pos;
579 }
580 if (args[1]) {
581 keyfile = args[1];
582 if (!--noptargs) {
583 goto skip_optional_pos;
584 }
585 }
586 password = args[2];
587skip_optional_pos:
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300588 return_value = _ssl__SSLContext_load_cert_chain_impl(self, certfile, keyfile, password);
589
590exit:
591 return return_value;
592}
593
594PyDoc_STRVAR(_ssl__SSLContext_load_verify_locations__doc__,
595"load_verify_locations($self, /, cafile=None, capath=None, cadata=None)\n"
596"--\n"
597"\n");
598
599#define _SSL__SSLCONTEXT_LOAD_VERIFY_LOCATIONS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200600 {"load_verify_locations", (PyCFunction)(void(*)(void))_ssl__SSLContext_load_verify_locations, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLContext_load_verify_locations__doc__},
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300601
602static PyObject *
603_ssl__SSLContext_load_verify_locations_impl(PySSLContext *self,
604 PyObject *cafile,
605 PyObject *capath,
606 PyObject *cadata);
607
608static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200609_ssl__SSLContext_load_verify_locations(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300610{
611 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300612 static const char * const _keywords[] = {"cafile", "capath", "cadata", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200613 static _PyArg_Parser _parser = {NULL, _keywords, "load_verify_locations", 0};
614 PyObject *argsbuf[3];
615 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
Serhiy Storchaka279f4462019-09-14 12:24:05 +0300616 PyObject *cafile = Py_None;
617 PyObject *capath = Py_None;
618 PyObject *cadata = Py_None;
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300619
Serhiy Storchaka31913912019-03-14 10:32:22 +0200620 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 3, 0, argsbuf);
621 if (!args) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300622 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300623 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200624 if (!noptargs) {
625 goto skip_optional_pos;
626 }
627 if (args[0]) {
628 cafile = args[0];
629 if (!--noptargs) {
630 goto skip_optional_pos;
631 }
632 }
633 if (args[1]) {
634 capath = args[1];
635 if (!--noptargs) {
636 goto skip_optional_pos;
637 }
638 }
639 cadata = args[2];
640skip_optional_pos:
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300641 return_value = _ssl__SSLContext_load_verify_locations_impl(self, cafile, capath, cadata);
642
643exit:
644 return return_value;
645}
646
647PyDoc_STRVAR(_ssl__SSLContext_load_dh_params__doc__,
648"load_dh_params($self, path, /)\n"
649"--\n"
650"\n");
651
652#define _SSL__SSLCONTEXT_LOAD_DH_PARAMS_METHODDEF \
653 {"load_dh_params", (PyCFunction)_ssl__SSLContext_load_dh_params, METH_O, _ssl__SSLContext_load_dh_params__doc__},
654
655PyDoc_STRVAR(_ssl__SSLContext__wrap_socket__doc__,
Christian Heimes141c5e82018-02-24 21:10:57 +0100656"_wrap_socket($self, /, sock, server_side, server_hostname=None, *,\n"
657" owner=None, session=None)\n"
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300658"--\n"
659"\n");
660
661#define _SSL__SSLCONTEXT__WRAP_SOCKET_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200662 {"_wrap_socket", (PyCFunction)(void(*)(void))_ssl__SSLContext__wrap_socket, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLContext__wrap_socket__doc__},
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300663
664static PyObject *
665_ssl__SSLContext__wrap_socket_impl(PySSLContext *self, PyObject *sock,
Christian Heimes141c5e82018-02-24 21:10:57 +0100666 int server_side, PyObject *hostname_obj,
667 PyObject *owner, PyObject *session);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300668
669static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200670_ssl__SSLContext__wrap_socket(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300671{
672 PyObject *return_value = NULL;
Christian Heimes141c5e82018-02-24 21:10:57 +0100673 static const char * const _keywords[] = {"sock", "server_side", "server_hostname", "owner", "session", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200674 static _PyArg_Parser _parser = {NULL, _keywords, "_wrap_socket", 0};
675 PyObject *argsbuf[5];
676 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300677 PyObject *sock;
678 int server_side;
679 PyObject *hostname_obj = Py_None;
Christian Heimes141c5e82018-02-24 21:10:57 +0100680 PyObject *owner = Py_None;
681 PyObject *session = Py_None;
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300682
Serhiy Storchaka31913912019-03-14 10:32:22 +0200683 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
684 if (!args) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300685 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300686 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200687 if (!PyObject_TypeCheck(args[0], PySocketModule.Sock_Type)) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200688 _PyArg_BadArgument("_wrap_socket", "argument 'sock'", (PySocketModule.Sock_Type)->tp_name, args[0]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200689 goto exit;
690 }
691 sock = args[0];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200692 server_side = _PyLong_AsInt(args[1]);
693 if (server_side == -1 && PyErr_Occurred()) {
694 goto exit;
695 }
696 if (!noptargs) {
697 goto skip_optional_pos;
698 }
699 if (args[2]) {
700 hostname_obj = args[2];
701 if (!--noptargs) {
702 goto skip_optional_pos;
703 }
704 }
705skip_optional_pos:
706 if (!noptargs) {
707 goto skip_optional_kwonly;
708 }
709 if (args[3]) {
710 owner = args[3];
711 if (!--noptargs) {
712 goto skip_optional_kwonly;
713 }
714 }
715 session = args[4];
716skip_optional_kwonly:
Christian Heimes141c5e82018-02-24 21:10:57 +0100717 return_value = _ssl__SSLContext__wrap_socket_impl(self, sock, server_side, hostname_obj, owner, session);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300718
719exit:
720 return return_value;
721}
722
723PyDoc_STRVAR(_ssl__SSLContext__wrap_bio__doc__,
724"_wrap_bio($self, /, incoming, outgoing, server_side,\n"
Christian Heimes141c5e82018-02-24 21:10:57 +0100725" server_hostname=None, *, owner=None, session=None)\n"
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300726"--\n"
727"\n");
728
729#define _SSL__SSLCONTEXT__WRAP_BIO_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200730 {"_wrap_bio", (PyCFunction)(void(*)(void))_ssl__SSLContext__wrap_bio, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLContext__wrap_bio__doc__},
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300731
732static PyObject *
733_ssl__SSLContext__wrap_bio_impl(PySSLContext *self, PySSLMemoryBIO *incoming,
734 PySSLMemoryBIO *outgoing, int server_side,
Christian Heimes141c5e82018-02-24 21:10:57 +0100735 PyObject *hostname_obj, PyObject *owner,
736 PyObject *session);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300737
738static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200739_ssl__SSLContext__wrap_bio(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300740{
741 PyObject *return_value = NULL;
Christian Heimes141c5e82018-02-24 21:10:57 +0100742 static const char * const _keywords[] = {"incoming", "outgoing", "server_side", "server_hostname", "owner", "session", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200743 static _PyArg_Parser _parser = {NULL, _keywords, "_wrap_bio", 0};
744 PyObject *argsbuf[6];
745 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300746 PySSLMemoryBIO *incoming;
747 PySSLMemoryBIO *outgoing;
748 int server_side;
749 PyObject *hostname_obj = Py_None;
Christian Heimes141c5e82018-02-24 21:10:57 +0100750 PyObject *owner = Py_None;
751 PyObject *session = Py_None;
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300752
Serhiy Storchaka31913912019-03-14 10:32:22 +0200753 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 4, 0, argsbuf);
754 if (!args) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300755 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300756 }
Christian Heimes5c36da72020-11-20 09:40:12 +0100757 if (!PyObject_TypeCheck(args[0], PySSLMemoryBIO_Type)) {
758 _PyArg_BadArgument("_wrap_bio", "argument 'incoming'", (PySSLMemoryBIO_Type)->tp_name, args[0]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200759 goto exit;
760 }
761 incoming = (PySSLMemoryBIO *)args[0];
Christian Heimes5c36da72020-11-20 09:40:12 +0100762 if (!PyObject_TypeCheck(args[1], PySSLMemoryBIO_Type)) {
763 _PyArg_BadArgument("_wrap_bio", "argument 'outgoing'", (PySSLMemoryBIO_Type)->tp_name, args[1]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200764 goto exit;
765 }
766 outgoing = (PySSLMemoryBIO *)args[1];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200767 server_side = _PyLong_AsInt(args[2]);
768 if (server_side == -1 && PyErr_Occurred()) {
769 goto exit;
770 }
771 if (!noptargs) {
772 goto skip_optional_pos;
773 }
774 if (args[3]) {
775 hostname_obj = args[3];
776 if (!--noptargs) {
777 goto skip_optional_pos;
778 }
779 }
780skip_optional_pos:
781 if (!noptargs) {
782 goto skip_optional_kwonly;
783 }
784 if (args[4]) {
785 owner = args[4];
786 if (!--noptargs) {
787 goto skip_optional_kwonly;
788 }
789 }
790 session = args[5];
791skip_optional_kwonly:
Christian Heimes141c5e82018-02-24 21:10:57 +0100792 return_value = _ssl__SSLContext__wrap_bio_impl(self, incoming, outgoing, server_side, hostname_obj, owner, session);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300793
794exit:
795 return return_value;
796}
797
798PyDoc_STRVAR(_ssl__SSLContext_session_stats__doc__,
799"session_stats($self, /)\n"
800"--\n"
801"\n");
802
803#define _SSL__SSLCONTEXT_SESSION_STATS_METHODDEF \
804 {"session_stats", (PyCFunction)_ssl__SSLContext_session_stats, METH_NOARGS, _ssl__SSLContext_session_stats__doc__},
805
806static PyObject *
807_ssl__SSLContext_session_stats_impl(PySSLContext *self);
808
809static PyObject *
810_ssl__SSLContext_session_stats(PySSLContext *self, PyObject *Py_UNUSED(ignored))
811{
812 return _ssl__SSLContext_session_stats_impl(self);
813}
814
815PyDoc_STRVAR(_ssl__SSLContext_set_default_verify_paths__doc__,
816"set_default_verify_paths($self, /)\n"
817"--\n"
818"\n");
819
820#define _SSL__SSLCONTEXT_SET_DEFAULT_VERIFY_PATHS_METHODDEF \
821 {"set_default_verify_paths", (PyCFunction)_ssl__SSLContext_set_default_verify_paths, METH_NOARGS, _ssl__SSLContext_set_default_verify_paths__doc__},
822
823static PyObject *
824_ssl__SSLContext_set_default_verify_paths_impl(PySSLContext *self);
825
826static PyObject *
827_ssl__SSLContext_set_default_verify_paths(PySSLContext *self, PyObject *Py_UNUSED(ignored))
828{
829 return _ssl__SSLContext_set_default_verify_paths_impl(self);
830}
831
832#if !defined(OPENSSL_NO_ECDH)
833
834PyDoc_STRVAR(_ssl__SSLContext_set_ecdh_curve__doc__,
835"set_ecdh_curve($self, name, /)\n"
836"--\n"
837"\n");
838
839#define _SSL__SSLCONTEXT_SET_ECDH_CURVE_METHODDEF \
840 {"set_ecdh_curve", (PyCFunction)_ssl__SSLContext_set_ecdh_curve, METH_O, _ssl__SSLContext_set_ecdh_curve__doc__},
841
842#endif /* !defined(OPENSSL_NO_ECDH) */
843
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300844PyDoc_STRVAR(_ssl__SSLContext_cert_store_stats__doc__,
845"cert_store_stats($self, /)\n"
846"--\n"
847"\n"
848"Returns quantities of loaded X.509 certificates.\n"
849"\n"
850"X.509 certificates with a CA extension and certificate revocation lists\n"
851"inside the context\'s cert store.\n"
852"\n"
853"NOTE: Certificates in a capath directory aren\'t loaded unless they have\n"
854"been used at least once.");
855
856#define _SSL__SSLCONTEXT_CERT_STORE_STATS_METHODDEF \
857 {"cert_store_stats", (PyCFunction)_ssl__SSLContext_cert_store_stats, METH_NOARGS, _ssl__SSLContext_cert_store_stats__doc__},
858
859static PyObject *
860_ssl__SSLContext_cert_store_stats_impl(PySSLContext *self);
861
862static PyObject *
863_ssl__SSLContext_cert_store_stats(PySSLContext *self, PyObject *Py_UNUSED(ignored))
864{
865 return _ssl__SSLContext_cert_store_stats_impl(self);
866}
867
868PyDoc_STRVAR(_ssl__SSLContext_get_ca_certs__doc__,
869"get_ca_certs($self, /, binary_form=False)\n"
870"--\n"
871"\n"
872"Returns a list of dicts with information of loaded CA certs.\n"
873"\n"
874"If the optional argument is True, returns a DER-encoded copy of the CA\n"
875"certificate.\n"
876"\n"
877"NOTE: Certificates in a capath directory aren\'t loaded unless they have\n"
878"been used at least once.");
879
880#define _SSL__SSLCONTEXT_GET_CA_CERTS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200881 {"get_ca_certs", (PyCFunction)(void(*)(void))_ssl__SSLContext_get_ca_certs, METH_FASTCALL|METH_KEYWORDS, _ssl__SSLContext_get_ca_certs__doc__},
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300882
883static PyObject *
884_ssl__SSLContext_get_ca_certs_impl(PySSLContext *self, int binary_form);
885
886static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200887_ssl__SSLContext_get_ca_certs(PySSLContext *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300888{
889 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300890 static const char * const _keywords[] = {"binary_form", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200891 static _PyArg_Parser _parser = {NULL, _keywords, "get_ca_certs", 0};
892 PyObject *argsbuf[1];
893 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300894 int binary_form = 0;
895
Serhiy Storchaka31913912019-03-14 10:32:22 +0200896 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
897 if (!args) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300898 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300899 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200900 if (!noptargs) {
901 goto skip_optional_pos;
902 }
903 binary_form = PyObject_IsTrue(args[0]);
904 if (binary_form < 0) {
905 goto exit;
906 }
907skip_optional_pos:
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300908 return_value = _ssl__SSLContext_get_ca_certs_impl(self, binary_form);
909
910exit:
911 return return_value;
912}
913
914static PyObject *
915_ssl_MemoryBIO_impl(PyTypeObject *type);
916
917static PyObject *
918_ssl_MemoryBIO(PyTypeObject *type, PyObject *args, PyObject *kwargs)
919{
920 PyObject *return_value = NULL;
921
Christian Heimes5c36da72020-11-20 09:40:12 +0100922 if ((type == PySSLMemoryBIO_Type) &&
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300923 !_PyArg_NoPositional("MemoryBIO", args)) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300924 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300925 }
Christian Heimes5c36da72020-11-20 09:40:12 +0100926 if ((type == PySSLMemoryBIO_Type) &&
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300927 !_PyArg_NoKeywords("MemoryBIO", kwargs)) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300928 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300929 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300930 return_value = _ssl_MemoryBIO_impl(type);
931
932exit:
933 return return_value;
934}
935
936PyDoc_STRVAR(_ssl_MemoryBIO_read__doc__,
937"read($self, size=-1, /)\n"
938"--\n"
939"\n"
940"Read up to size bytes from the memory BIO.\n"
941"\n"
942"If size is not specified, read the entire buffer.\n"
943"If the return value is an empty bytes instance, this means either\n"
944"EOF or that no data is available. Use the \"eof\" property to\n"
945"distinguish between the two.");
946
947#define _SSL_MEMORYBIO_READ_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200948 {"read", (PyCFunction)(void(*)(void))_ssl_MemoryBIO_read, METH_FASTCALL, _ssl_MemoryBIO_read__doc__},
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300949
950static PyObject *
951_ssl_MemoryBIO_read_impl(PySSLMemoryBIO *self, int len);
952
953static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200954_ssl_MemoryBIO_read(PySSLMemoryBIO *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300955{
956 PyObject *return_value = NULL;
957 int len = -1;
958
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200959 if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100960 goto exit;
961 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200962 if (nargs < 1) {
963 goto skip_optional;
964 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200965 len = _PyLong_AsInt(args[0]);
966 if (len == -1 && PyErr_Occurred()) {
967 goto exit;
968 }
969skip_optional:
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +0300970 return_value = _ssl_MemoryBIO_read_impl(self, len);
971
972exit:
973 return return_value;
974}
975
976PyDoc_STRVAR(_ssl_MemoryBIO_write__doc__,
977"write($self, b, /)\n"
978"--\n"
979"\n"
980"Writes the bytes b into the memory BIO.\n"
981"\n"
982"Returns the number of bytes written.");
983
984#define _SSL_MEMORYBIO_WRITE_METHODDEF \
985 {"write", (PyCFunction)_ssl_MemoryBIO_write, METH_O, _ssl_MemoryBIO_write__doc__},
986
987static PyObject *
988_ssl_MemoryBIO_write_impl(PySSLMemoryBIO *self, Py_buffer *b);
989
990static PyObject *
991_ssl_MemoryBIO_write(PySSLMemoryBIO *self, PyObject *arg)
992{
993 PyObject *return_value = NULL;
994 Py_buffer b = {NULL, NULL};
995
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200996 if (PyObject_GetBuffer(arg, &b, PyBUF_SIMPLE) != 0) {
997 goto exit;
998 }
999 if (!PyBuffer_IsContiguous(&b, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001000 _PyArg_BadArgument("write", "argument", "contiguous buffer", arg);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001001 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001002 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001003 return_value = _ssl_MemoryBIO_write_impl(self, &b);
1004
1005exit:
1006 /* Cleanup for b */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001007 if (b.obj) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001008 PyBuffer_Release(&b);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001009 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001010
1011 return return_value;
1012}
1013
1014PyDoc_STRVAR(_ssl_MemoryBIO_write_eof__doc__,
1015"write_eof($self, /)\n"
1016"--\n"
1017"\n"
1018"Write an EOF marker to the memory BIO.\n"
1019"\n"
1020"When all data has been read, the \"eof\" property will be True.");
1021
1022#define _SSL_MEMORYBIO_WRITE_EOF_METHODDEF \
1023 {"write_eof", (PyCFunction)_ssl_MemoryBIO_write_eof, METH_NOARGS, _ssl_MemoryBIO_write_eof__doc__},
1024
1025static PyObject *
1026_ssl_MemoryBIO_write_eof_impl(PySSLMemoryBIO *self);
1027
1028static PyObject *
1029_ssl_MemoryBIO_write_eof(PySSLMemoryBIO *self, PyObject *Py_UNUSED(ignored))
1030{
1031 return _ssl_MemoryBIO_write_eof_impl(self);
1032}
1033
1034PyDoc_STRVAR(_ssl_RAND_add__doc__,
1035"RAND_add($module, string, entropy, /)\n"
1036"--\n"
1037"\n"
1038"Mix string into the OpenSSL PRNG state.\n"
1039"\n"
1040"entropy (a float) is a lower bound on the entropy contained in\n"
Chandan Kumar63c2c8a2017-06-09 15:13:58 +05301041"string. See RFC 4086.");
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001042
1043#define _SSL_RAND_ADD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001044 {"RAND_add", (PyCFunction)(void(*)(void))_ssl_RAND_add, METH_FASTCALL, _ssl_RAND_add__doc__},
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001045
1046static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001047_ssl_RAND_add_impl(PyObject *module, Py_buffer *view, double entropy);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001048
1049static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001050_ssl_RAND_add(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001051{
1052 PyObject *return_value = NULL;
1053 Py_buffer view = {NULL, NULL};
1054 double entropy;
1055
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001056 if (!_PyArg_CheckPositional("RAND_add", nargs, 2, 2)) {
1057 goto exit;
1058 }
1059 if (PyUnicode_Check(args[0])) {
1060 Py_ssize_t len;
1061 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1062 if (ptr == NULL) {
1063 goto exit;
1064 }
1065 PyBuffer_FillInfo(&view, args[0], (void *)ptr, len, 1, 0);
1066 }
1067 else { /* any bytes-like object */
1068 if (PyObject_GetBuffer(args[0], &view, PyBUF_SIMPLE) != 0) {
1069 goto exit;
1070 }
1071 if (!PyBuffer_IsContiguous(&view, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001072 _PyArg_BadArgument("RAND_add", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001073 goto exit;
1074 }
1075 }
Raymond Hettingeraef9ad82019-08-24 19:10:39 -07001076 if (PyFloat_CheckExact(args[1])) {
1077 entropy = PyFloat_AS_DOUBLE(args[1]);
1078 }
1079 else
1080 {
1081 entropy = PyFloat_AsDouble(args[1]);
1082 if (entropy == -1.0 && PyErr_Occurred()) {
1083 goto exit;
1084 }
Victor Stinner259f0e42017-01-17 01:35:17 +01001085 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001086 return_value = _ssl_RAND_add_impl(module, &view, entropy);
1087
1088exit:
1089 /* Cleanup for view */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001090 if (view.obj) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001091 PyBuffer_Release(&view);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001092 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001093
1094 return return_value;
1095}
1096
1097PyDoc_STRVAR(_ssl_RAND_bytes__doc__,
1098"RAND_bytes($module, n, /)\n"
1099"--\n"
1100"\n"
1101"Generate n cryptographically strong pseudo-random bytes.");
1102
1103#define _SSL_RAND_BYTES_METHODDEF \
1104 {"RAND_bytes", (PyCFunction)_ssl_RAND_bytes, METH_O, _ssl_RAND_bytes__doc__},
1105
1106static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001107_ssl_RAND_bytes_impl(PyObject *module, int n);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001108
1109static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001110_ssl_RAND_bytes(PyObject *module, PyObject *arg)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001111{
1112 PyObject *return_value = NULL;
1113 int n;
1114
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001115 n = _PyLong_AsInt(arg);
1116 if (n == -1 && PyErr_Occurred()) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001117 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001118 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001119 return_value = _ssl_RAND_bytes_impl(module, n);
1120
1121exit:
1122 return return_value;
1123}
1124
1125PyDoc_STRVAR(_ssl_RAND_pseudo_bytes__doc__,
1126"RAND_pseudo_bytes($module, n, /)\n"
1127"--\n"
1128"\n"
1129"Generate n pseudo-random bytes.\n"
1130"\n"
1131"Return a pair (bytes, is_cryptographic). is_cryptographic is True\n"
1132"if the bytes generated are cryptographically strong.");
1133
1134#define _SSL_RAND_PSEUDO_BYTES_METHODDEF \
1135 {"RAND_pseudo_bytes", (PyCFunction)_ssl_RAND_pseudo_bytes, METH_O, _ssl_RAND_pseudo_bytes__doc__},
1136
1137static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001138_ssl_RAND_pseudo_bytes_impl(PyObject *module, int n);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001139
1140static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001141_ssl_RAND_pseudo_bytes(PyObject *module, PyObject *arg)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001142{
1143 PyObject *return_value = NULL;
1144 int n;
1145
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001146 n = _PyLong_AsInt(arg);
1147 if (n == -1 && PyErr_Occurred()) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001148 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001149 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001150 return_value = _ssl_RAND_pseudo_bytes_impl(module, n);
1151
1152exit:
1153 return return_value;
1154}
1155
1156PyDoc_STRVAR(_ssl_RAND_status__doc__,
1157"RAND_status($module, /)\n"
1158"--\n"
1159"\n"
1160"Returns 1 if the OpenSSL PRNG has been seeded with enough data and 0 if not.\n"
1161"\n"
1162"It is necessary to seed the PRNG with RAND_add() on some platforms before\n"
1163"using the ssl() function.");
1164
1165#define _SSL_RAND_STATUS_METHODDEF \
1166 {"RAND_status", (PyCFunction)_ssl_RAND_status, METH_NOARGS, _ssl_RAND_status__doc__},
1167
1168static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001169_ssl_RAND_status_impl(PyObject *module);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001170
1171static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001172_ssl_RAND_status(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001173{
1174 return _ssl_RAND_status_impl(module);
1175}
1176
Benjamin Petersonb8a2f512016-07-06 23:55:15 -07001177#if !defined(OPENSSL_NO_EGD)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001178
1179PyDoc_STRVAR(_ssl_RAND_egd__doc__,
1180"RAND_egd($module, path, /)\n"
1181"--\n"
1182"\n"
1183"Queries the entropy gather daemon (EGD) on the socket named by \'path\'.\n"
1184"\n"
1185"Returns number of bytes read. Raises SSLError if connection to EGD\n"
1186"fails or if it does not provide enough data to seed PRNG.");
1187
1188#define _SSL_RAND_EGD_METHODDEF \
1189 {"RAND_egd", (PyCFunction)_ssl_RAND_egd, METH_O, _ssl_RAND_egd__doc__},
1190
1191static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001192_ssl_RAND_egd_impl(PyObject *module, PyObject *path);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001193
1194static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001195_ssl_RAND_egd(PyObject *module, PyObject *arg)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001196{
1197 PyObject *return_value = NULL;
1198 PyObject *path;
1199
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001200 if (!PyUnicode_FSConverter(arg, &path)) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001201 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001202 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001203 return_value = _ssl_RAND_egd_impl(module, path);
1204
1205exit:
1206 return return_value;
1207}
1208
Benjamin Petersonb8a2f512016-07-06 23:55:15 -07001209#endif /* !defined(OPENSSL_NO_EGD) */
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001210
1211PyDoc_STRVAR(_ssl_get_default_verify_paths__doc__,
1212"get_default_verify_paths($module, /)\n"
1213"--\n"
1214"\n"
1215"Return search paths and environment vars that are used by SSLContext\'s set_default_verify_paths() to load default CAs.\n"
1216"\n"
1217"The values are \'cert_file_env\', \'cert_file\', \'cert_dir_env\', \'cert_dir\'.");
1218
1219#define _SSL_GET_DEFAULT_VERIFY_PATHS_METHODDEF \
1220 {"get_default_verify_paths", (PyCFunction)_ssl_get_default_verify_paths, METH_NOARGS, _ssl_get_default_verify_paths__doc__},
1221
1222static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001223_ssl_get_default_verify_paths_impl(PyObject *module);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001224
1225static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001226_ssl_get_default_verify_paths(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001227{
1228 return _ssl_get_default_verify_paths_impl(module);
1229}
1230
1231PyDoc_STRVAR(_ssl_txt2obj__doc__,
1232"txt2obj($module, /, txt, name=False)\n"
1233"--\n"
1234"\n"
1235"Lookup NID, short name, long name and OID of an ASN1_OBJECT.\n"
1236"\n"
1237"By default objects are looked up by OID. With name=True short and\n"
1238"long name are also matched.");
1239
1240#define _SSL_TXT2OBJ_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001241 {"txt2obj", (PyCFunction)(void(*)(void))_ssl_txt2obj, METH_FASTCALL|METH_KEYWORDS, _ssl_txt2obj__doc__},
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001242
1243static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001244_ssl_txt2obj_impl(PyObject *module, const char *txt, int name);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001245
1246static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001247_ssl_txt2obj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001248{
1249 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001250 static const char * const _keywords[] = {"txt", "name", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001251 static _PyArg_Parser _parser = {NULL, _keywords, "txt2obj", 0};
1252 PyObject *argsbuf[2];
1253 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001254 const char *txt;
1255 int name = 0;
1256
Serhiy Storchaka31913912019-03-14 10:32:22 +02001257 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
1258 if (!args) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001259 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001260 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02001261 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001262 _PyArg_BadArgument("txt2obj", "argument 'txt'", "str", args[0]);
Serhiy Storchaka31913912019-03-14 10:32:22 +02001263 goto exit;
1264 }
1265 Py_ssize_t txt_length;
1266 txt = PyUnicode_AsUTF8AndSize(args[0], &txt_length);
1267 if (txt == NULL) {
1268 goto exit;
1269 }
1270 if (strlen(txt) != (size_t)txt_length) {
1271 PyErr_SetString(PyExc_ValueError, "embedded null character");
1272 goto exit;
1273 }
1274 if (!noptargs) {
1275 goto skip_optional_pos;
1276 }
1277 name = PyObject_IsTrue(args[1]);
1278 if (name < 0) {
1279 goto exit;
1280 }
1281skip_optional_pos:
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001282 return_value = _ssl_txt2obj_impl(module, txt, name);
1283
1284exit:
1285 return return_value;
1286}
1287
1288PyDoc_STRVAR(_ssl_nid2obj__doc__,
1289"nid2obj($module, nid, /)\n"
1290"--\n"
1291"\n"
1292"Lookup NID, short name, long name and OID of an ASN1_OBJECT by NID.");
1293
1294#define _SSL_NID2OBJ_METHODDEF \
1295 {"nid2obj", (PyCFunction)_ssl_nid2obj, METH_O, _ssl_nid2obj__doc__},
1296
1297static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001298_ssl_nid2obj_impl(PyObject *module, int nid);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001299
1300static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001301_ssl_nid2obj(PyObject *module, PyObject *arg)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001302{
1303 PyObject *return_value = NULL;
1304 int nid;
1305
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001306 nid = _PyLong_AsInt(arg);
1307 if (nid == -1 && PyErr_Occurred()) {
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001308 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001309 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001310 return_value = _ssl_nid2obj_impl(module, nid);
1311
1312exit:
1313 return return_value;
1314}
1315
1316#if defined(_MSC_VER)
1317
1318PyDoc_STRVAR(_ssl_enum_certificates__doc__,
1319"enum_certificates($module, /, store_name)\n"
1320"--\n"
1321"\n"
1322"Retrieve certificates from Windows\' cert store.\n"
1323"\n"
1324"store_name may be one of \'CA\', \'ROOT\' or \'MY\'. The system may provide\n"
1325"more cert storages, too. The function returns a list of (bytes,\n"
1326"encoding_type, trust) tuples. The encoding_type flag can be interpreted\n"
1327"with X509_ASN_ENCODING or PKCS_7_ASN_ENCODING. The trust setting is either\n"
1328"a set of OIDs or the boolean True.");
1329
1330#define _SSL_ENUM_CERTIFICATES_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001331 {"enum_certificates", (PyCFunction)(void(*)(void))_ssl_enum_certificates, METH_FASTCALL|METH_KEYWORDS, _ssl_enum_certificates__doc__},
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001332
1333static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001334_ssl_enum_certificates_impl(PyObject *module, const char *store_name);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001335
1336static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001337_ssl_enum_certificates(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001338{
1339 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001340 static const char * const _keywords[] = {"store_name", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001341 static _PyArg_Parser _parser = {NULL, _keywords, "enum_certificates", 0};
1342 PyObject *argsbuf[1];
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001343 const char *store_name;
1344
Serhiy Storchaka31913912019-03-14 10:32:22 +02001345 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1346 if (!args) {
1347 goto exit;
1348 }
1349 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001350 _PyArg_BadArgument("enum_certificates", "argument 'store_name'", "str", args[0]);
Serhiy Storchaka31913912019-03-14 10:32:22 +02001351 goto exit;
1352 }
1353 Py_ssize_t store_name_length;
1354 store_name = PyUnicode_AsUTF8AndSize(args[0], &store_name_length);
1355 if (store_name == NULL) {
1356 goto exit;
1357 }
1358 if (strlen(store_name) != (size_t)store_name_length) {
1359 PyErr_SetString(PyExc_ValueError, "embedded null character");
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001360 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001361 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001362 return_value = _ssl_enum_certificates_impl(module, store_name);
1363
1364exit:
1365 return return_value;
1366}
1367
1368#endif /* defined(_MSC_VER) */
1369
1370#if defined(_MSC_VER)
1371
1372PyDoc_STRVAR(_ssl_enum_crls__doc__,
1373"enum_crls($module, /, store_name)\n"
1374"--\n"
1375"\n"
1376"Retrieve CRLs from Windows\' cert store.\n"
1377"\n"
1378"store_name may be one of \'CA\', \'ROOT\' or \'MY\'. The system may provide\n"
1379"more cert storages, too. The function returns a list of (bytes,\n"
1380"encoding_type) tuples. The encoding_type flag can be interpreted with\n"
1381"X509_ASN_ENCODING or PKCS_7_ASN_ENCODING.");
1382
1383#define _SSL_ENUM_CRLS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001384 {"enum_crls", (PyCFunction)(void(*)(void))_ssl_enum_crls, METH_FASTCALL|METH_KEYWORDS, _ssl_enum_crls__doc__},
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001385
1386static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001387_ssl_enum_crls_impl(PyObject *module, const char *store_name);
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001388
1389static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001390_ssl_enum_crls(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001391{
1392 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001393 static const char * const _keywords[] = {"store_name", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001394 static _PyArg_Parser _parser = {NULL, _keywords, "enum_crls", 0};
1395 PyObject *argsbuf[1];
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001396 const char *store_name;
1397
Serhiy Storchaka31913912019-03-14 10:32:22 +02001398 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1399 if (!args) {
1400 goto exit;
1401 }
1402 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001403 _PyArg_BadArgument("enum_crls", "argument 'store_name'", "str", args[0]);
Serhiy Storchaka31913912019-03-14 10:32:22 +02001404 goto exit;
1405 }
1406 Py_ssize_t store_name_length;
1407 store_name = PyUnicode_AsUTF8AndSize(args[0], &store_name_length);
1408 if (store_name == NULL) {
1409 goto exit;
1410 }
1411 if (strlen(store_name) != (size_t)store_name_length) {
1412 PyErr_SetString(PyExc_ValueError, "embedded null character");
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001413 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001414 }
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001415 return_value = _ssl_enum_crls_impl(module, store_name);
1416
1417exit:
1418 return return_value;
1419}
1420
1421#endif /* defined(_MSC_VER) */
1422
1423#ifndef _SSL__SSLSOCKET_SELECTED_NPN_PROTOCOL_METHODDEF
1424 #define _SSL__SSLSOCKET_SELECTED_NPN_PROTOCOL_METHODDEF
1425#endif /* !defined(_SSL__SSLSOCKET_SELECTED_NPN_PROTOCOL_METHODDEF) */
1426
1427#ifndef _SSL__SSLSOCKET_SELECTED_ALPN_PROTOCOL_METHODDEF
1428 #define _SSL__SSLSOCKET_SELECTED_ALPN_PROTOCOL_METHODDEF
1429#endif /* !defined(_SSL__SSLSOCKET_SELECTED_ALPN_PROTOCOL_METHODDEF) */
1430
Christian Heimes25bfcd52016-09-06 00:04:45 +02001431#ifndef _SSL__SSLCONTEXT_GET_CIPHERS_METHODDEF
1432 #define _SSL__SSLCONTEXT_GET_CIPHERS_METHODDEF
1433#endif /* !defined(_SSL__SSLCONTEXT_GET_CIPHERS_METHODDEF) */
1434
Serhiy Storchaka4b7b82f2015-05-03 16:14:08 +03001435#ifndef _SSL__SSLCONTEXT_SET_ECDH_CURVE_METHODDEF
1436 #define _SSL__SSLCONTEXT_SET_ECDH_CURVE_METHODDEF
1437#endif /* !defined(_SSL__SSLCONTEXT_SET_ECDH_CURVE_METHODDEF) */
1438
1439#ifndef _SSL_RAND_EGD_METHODDEF
1440 #define _SSL_RAND_EGD_METHODDEF
1441#endif /* !defined(_SSL_RAND_EGD_METHODDEF) */
1442
1443#ifndef _SSL_ENUM_CERTIFICATES_METHODDEF
1444 #define _SSL_ENUM_CERTIFICATES_METHODDEF
1445#endif /* !defined(_SSL_ENUM_CERTIFICATES_METHODDEF) */
1446
1447#ifndef _SSL_ENUM_CRLS_METHODDEF
1448 #define _SSL_ENUM_CRLS_METHODDEF
1449#endif /* !defined(_SSL_ENUM_CRLS_METHODDEF) */
Christian Heimes5c36da72020-11-20 09:40:12 +01001450/*[clinic end generated code: output=2bb53a80040c9b35 input=a9049054013a1b77]*/