summaryrefslogtreecommitdiff
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
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)
-rw-r--r--ChangeLog6
-rw-r--r--OpenSSL/ssl/context.c18
-rw-r--r--OpenSSL/ssl/ssl.c9
-rw-r--r--OpenSSL/test/test_ssl.py11
-rw-r--r--doc/pyOpenSSL.tex5
5 files changed, 49 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index dffd05d..e28720d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-08-29 Guillermo Gonzalez <guillermo.gonzalez@canonical.com>
+
+ * OpenSSL/ssl/context.c: Add Context.set_mode method.
+ * OpenSSL/ssl/ssl.c: Add MODE_RELEASE_BUFFERS and OP_NO_COMPRESSION
+ constants.
+
2011-06-12 Jean-Paul Calderone <exarkun@twistedmatrix.com>
* OpenSSL/crypto/pkey.c: Add the PKey.check method, mostly
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
diff --git a/doc/pyOpenSSL.tex b/doc/pyOpenSSL.tex
index 6a49748..92d3356 100644
--- a/doc/pyOpenSSL.tex
+++ b/doc/pyOpenSSL.tex
@@ -1055,6 +1055,11 @@ Add SSL options. Options you have set before are not cleared!
This method should be used with the \constant{OP_*} constants.
\end{methoddesc}
+\begin{methoddesc}[Context]{set_mode}{mode}
+Add SSL mode. Modes you have set before are not cleared!
+This method should be used with the \constant{MODE_*} constants.
+\end{methoddesc}
+
\begin{methoddesc}[Context]{set_passwd_cb}{callback\optional{, userdata}}
Set the passphrase callback to \var{callback}. This function will be called
when a private key with a passphrase is loaded. \var{callback} must accept