summaryrefslogtreecommitdiff
path: root/OpenSSL
diff options
context:
space:
mode:
authorGuillermo Gonzalez <guillo.gonzo@gmail.com>2011-08-29 16:16:58 -0300
committerGuillermo Gonzalez <guillo.gonzo@gmail.com>2011-08-29 16:16:58 -0300
commit74a2c299e03525456dc0788e3c1a96f2b2f9d504 (patch)
tree5e48e35934523db879582bf48ae5f8e3fc80ef10 /OpenSSL
parent042b66d4834b493ff82c9f2dc16aca09f39c9d8a (diff)
downloadpyopenssl-74a2c299e03525456dc0788e3c1a96f2b2f9d504.tar.gz
- Add Context.set_mode method
- Add MODE_RELEASE_BUFFERS and OP_NO_COMPRESSION constants, only if are defined (openssl >= 1.0.0)
Diffstat (limited to 'OpenSSL')
-rw-r--r--OpenSSL/ssl/context.c18
-rw-r--r--OpenSSL/ssl/ssl.c9
-rw-r--r--OpenSSL/test/test_ssl.py11
3 files changed, 38 insertions, 0 deletions
diff --git a/OpenSSL/ssl/context.c b/OpenSSL/ssl/context.c
index c2bdcab..4ab024f 100644
--- a/OpenSSL/ssl/context.c
+++ b/OpenSSL/ssl/context.c
@@ -1108,6 +1108,23 @@ ssl_Context_set_options(ssl_ContextObj *self, PyObject *args)
return PyLong_FromLong(SSL_CTX_set_options(self->ctx, options));
}
+static char ssl_Context_set_mode_doc[] = "\n\
+Add modes via bitmask. Modes set before are not cleared!\n\
+\n\
+@param mode: The mode to add.\n\
+@return: The new mode bitmask.\n\
+";
+static PyObject *
+ssl_Context_set_mode(ssl_ContextObj *self, PyObject *args)
+{
+ long mode;
+
+ if (!PyArg_ParseTuple(args, "l:set_mode", &mode))
+ return NULL;
+
+ return PyLong_FromLong(SSL_CTX_set_mode(self->ctx, mode));
+}
+
static char ssl_Context_set_tlsext_servername_callback_doc[] = "\n\
Specify a callback function to be called when clients specify a server name.\n\
\n\
@@ -1174,6 +1191,7 @@ static PyMethodDef ssl_Context_methods[] = {
ADD_METHOD(set_app_data),
ADD_METHOD(get_cert_store),
ADD_METHOD(set_options),
+ ADD_METHOD(set_mode),
ADD_METHOD(set_tlsext_servername_callback),
{ NULL, NULL }
};
diff --git a/OpenSSL/ssl/ssl.c b/OpenSSL/ssl/ssl.c
index 0dd9871..ce84041 100644
--- a/OpenSSL/ssl/ssl.c
+++ b/OpenSSL/ssl/ssl.c
@@ -224,6 +224,10 @@ do { \
PyModule_AddIntConstant(module, "OP_NETSCAPE_CA_DN_BUG", SSL_OP_NETSCAPE_CA_DN_BUG);
PyModule_AddIntConstant(module, "OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG", SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG);
+#ifdef SSL_OP_NO_COMPRESSION
+ PyModule_AddIntConstant(module, "OP_NO_COMPRESSION", SSL_OP_NO_COMPRESSION);
+#endif
+
/* DTLS related options. The first two of these were introduced in
* 2005, the third in 2007. To accomodate systems which are still using
* older versions, make them optional. */
@@ -273,6 +277,11 @@ do { \
/* Straight up version number */
PyModule_AddIntConstant(module, "OPENSSL_VERSION_NUMBER", OPENSSL_VERSION_NUMBER);
+ /* SSL modes constants */
+#ifdef SSL_MODE_RELEASE_BUFFERS
+ PyModule_AddIntConstant(module, "MODE_RELEASE_BUFFERS", SSL_MODE_RELEASE_BUFFERS);
+#endif
+
if (!init_ssl_context(module))
goto error;
if (!init_ssl_connection(module))
diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py
index 2ab67fd..dfe804d 100644
--- a/OpenSSL/test/test_ssl.py
+++ b/OpenSSL/test/test_ssl.py
@@ -352,6 +352,17 @@ class ContextTests(TestCase, _LoopbackMixin):
self.assertRaises(TypeError, context.set_options, 1, None)
+ def test_set_mode_wrong_args(self):
+ """
+ L{Context.set_mode} raises L{TypeError} if called with the wrong
+ number of arguments or a non-C{int} argument.
+ """
+ context = Context(TLSv1_METHOD)
+ self.assertRaises(TypeError, context.set_mode)
+ self.assertRaises(TypeError, context.set_mode, None)
+ self.assertRaises(TypeError, context.set_mode, 1, None)
+
+
def test_set_timeout_wrong_args(self):
"""
L{Context.set_timeout} raises L{TypeError} if called with the wrong