Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Dev

Controlling the cipher list for SSL connections

 

 

Python dev RSS feed   Index | Next | Previous | View Threaded


frantzcj at gmail

Sep 7, 2009, 9:09 AM

Post #1 of 8 (860 views)
Permalink
Controlling the cipher list for SSL connections

Greetings,

I would like to be able to set the cipher list when creating an SSL
connection.  It appears that the current SSL module doesn't provide
this functionality.

The attached patch (against trunk) adds this ability to SSLSocket.

Thank you,
--Chris

PS: Please reply directly to me, as I'm not subscribed to this list.

Index: Python-2.7/Lib/ssl.py
===================================================================
--- Python-2.7/Lib/ssl.py    (revision 74703)
+++ Python-2.7/Lib/ssl.py    (working copy)
@@ -88,7 +88,7 @@
                  server_side=False, cert_reqs=CERT_NONE,
                  ssl_version=PROTOCOL_SSLv23, ca_certs=None,
                  do_handshake_on_connect=True,
-                 suppress_ragged_eofs=True):
+                 suppress_ragged_eofs=True, cipher_list=None):
         socket.__init__(self, _sock=sock._sock)
         # the initializer for socket trashes the methods (tsk, tsk), so...
         self.send = lambda data, flags=0: SSLSocket.send(self, data, flags)
@@ -110,7 +110,8 @@
             # yes, create the SSL object
             self._sslobj = _ssl.sslwrap(self._sock, server_side,
                                         keyfile, certfile,
-                                        cert_reqs, ssl_version, ca_certs)
+                                        cert_reqs, ssl_version,
+                                        ca_certs, cipher_list)
             if do_handshake_on_connect:
                 timeout = self.gettimeout()
                 try:
Index: Python-2.7/Modules/_ssl.c
===================================================================
--- Python-2.7/Modules/_ssl.c    (revision 74703)
+++ Python-2.7/Modules/_ssl.c    (working copy)
@@ -261,7 +261,8 @@
            enum py_ssl_server_or_client socket_type,
            enum py_ssl_cert_requirements certreq,
            enum py_ssl_version proto_version,
-           char *cacerts_file)
+           char *cacerts_file,
+           char *cipher_list)
 {
     PySSLObject *self;
     char *errstr = NULL;
@@ -366,6 +367,9 @@
     SSL_CTX_set_verify(self->ctx, verification_mode,
                NULL); /* set verify lvl */

+    if (cipher_list)
+        SSL_CTX_set_cipher_list(self->ctx, cipher_list);
+
     PySSL_BEGIN_ALLOW_THREADS
     self->ssl = SSL_new(self->ctx); /* New ssl struct */
     PySSL_END_ALLOW_THREADS
@@ -407,14 +411,17 @@
     char *key_file = NULL;
     char *cert_file = NULL;
     char *cacerts_file = NULL;
+    char *cipher_list = NULL;

-    if (!PyArg_ParseTuple(args, "O!i|zziiz:sslwrap",
+
+    if (!PyArg_ParseTuple(args, "O!i|zziizz:sslwrap",
                   PySocketModule.Sock_Type,
                   &Sock,
                   &server_side,
                   &key_file, &cert_file,
                   &verification_mode, &protocol,
-                  &cacerts_file))
+                  &cacerts_file,
+                  &cipher_list))
         return NULL;

     /*
@@ -427,12 +434,12 @@

     return (PyObject *) newPySSLObject(Sock, key_file, cert_file,
                        server_side, verification_mode,
-                       protocol, cacerts_file);
+                       protocol, cacerts_file, cipher_list);
 }

 PyDoc_STRVAR(ssl_doc,
 "sslwrap(socket, server_side, [keyfile, certfile, certs_mode, protocol,\n"
-"                              cacertsfile]) -> sslobject");
+"                              cacertsfile, cipherlist]) -> sslobject");

 /* SSL object methods */
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


fuzzyman at voidspace

Sep 7, 2009, 9:15 AM

Post #2 of 8 (821 views)
Permalink
Re: Controlling the cipher list for SSL connections [In reply to]

Hello Chris,

Can you post your patch to the Python bug tracker please -
http://bugs.python.org

Patches posted to this list tend to get lost...

Thanks

Michael

Chris Frantz wrote:
> Greetings,
>
> I would like to be able to set the cipher list when creating an SSL
> connection. It appears that the current SSL module doesn't provide
> this functionality.
>
> The attached patch (against trunk) adds this ability to SSLSocket.
>
> Thank you,
> --Chris
>
> PS: Please reply directly to me, as I'm not subscribed to this list.
>
> Index: Python-2.7/Lib/ssl.py
> ===================================================================
> --- Python-2.7/Lib/ssl.py (revision 74703)
> +++ Python-2.7/Lib/ssl.py (working copy)
> @@ -88,7 +88,7 @@
> server_side=False, cert_reqs=CERT_NONE,
> ssl_version=PROTOCOL_SSLv23, ca_certs=None,
> do_handshake_on_connect=True,
> - suppress_ragged_eofs=True):
> + suppress_ragged_eofs=True, cipher_list=None):
> socket.__init__(self, _sock=sock._sock)
> # the initializer for socket trashes the methods (tsk, tsk), so...
> self.send = lambda data, flags=0: SSLSocket.send(self, data, flags)
> @@ -110,7 +110,8 @@
> # yes, create the SSL object
> self._sslobj = _ssl.sslwrap(self._sock, server_side,
> keyfile, certfile,
> - cert_reqs, ssl_version, ca_certs)
> + cert_reqs, ssl_version,
> + ca_certs, cipher_list)
> if do_handshake_on_connect:
> timeout = self.gettimeout()
> try:
> Index: Python-2.7/Modules/_ssl.c
> ===================================================================
> --- Python-2.7/Modules/_ssl.c (revision 74703)
> +++ Python-2.7/Modules/_ssl.c (working copy)
> @@ -261,7 +261,8 @@
> enum py_ssl_server_or_client socket_type,
> enum py_ssl_cert_requirements certreq,
> enum py_ssl_version proto_version,
> - char *cacerts_file)
> + char *cacerts_file,
> + char *cipher_list)
> {
> PySSLObject *self;
> char *errstr = NULL;
> @@ -366,6 +367,9 @@
> SSL_CTX_set_verify(self->ctx, verification_mode,
> NULL); /* set verify lvl */
>
> + if (cipher_list)
> + SSL_CTX_set_cipher_list(self->ctx, cipher_list);
> +
> PySSL_BEGIN_ALLOW_THREADS
> self->ssl = SSL_new(self->ctx); /* New ssl struct */
> PySSL_END_ALLOW_THREADS
> @@ -407,14 +411,17 @@
> char *key_file = NULL;
> char *cert_file = NULL;
> char *cacerts_file = NULL;
> + char *cipher_list = NULL;
>
> - if (!PyArg_ParseTuple(args, "O!i|zziiz:sslwrap",
> +
> + if (!PyArg_ParseTuple(args, "O!i|zziizz:sslwrap",
> PySocketModule.Sock_Type,
> &Sock,
> &server_side,
> &key_file, &cert_file,
> &verification_mode, &protocol,
> - &cacerts_file))
> + &cacerts_file,
> + &cipher_list))
> return NULL;
>
> /*
> @@ -427,12 +434,12 @@
>
> return (PyObject *) newPySSLObject(Sock, key_file, cert_file,
> server_side, verification_mode,
> - protocol, cacerts_file);
> + protocol, cacerts_file, cipher_list);
> }
>
> PyDoc_STRVAR(ssl_doc,
> "sslwrap(socket, server_side, [keyfile, certfile, certs_mode, protocol,\n"
> -" cacertsfile]) -> sslobject");
> +" cacertsfile, cipherlist]) -> sslobject");
>
> /* SSL object methods */
> _______________________________________________
> Python-Dev mailing list
> Python-Dev [at] python
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk
>


--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog


_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


frantzcj at gmail

Sep 7, 2009, 9:32 AM

Post #3 of 8 (825 views)
Permalink
Re: Controlling the cipher list for SSL connections [In reply to]

Done.

Attached to Issue 3597, which is a similar request to mine.

Best Regards,
--Chris
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


janssen at parc

Sep 10, 2009, 10:09 AM

Post #4 of 8 (797 views)
Permalink
Re: Controlling the cipher list for SSL connections [In reply to]

Thanks, Chris. Can you explain why you want to set the cipher list
explicitly? IMO, it's usually better to select a security scheme (TLS1,
or SSLv3, etc.), and let the implementation pick the cipher list.

Bill

Chris Frantz <frantzcj [at] gmail> wrote:

> Done.
>
> Attached to Issue 3597, which is a similar request to mine.
>
> Best Regards,
> --Chris
> _______________________________________________
> Python-Dev mailing list
> Python-Dev [at] python
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/janssen%40parc.com
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


frantzcj at gmail

Sep 10, 2009, 11:04 AM

Post #5 of 8 (792 views)
Permalink
Re: Controlling the cipher list for SSL connections [In reply to]

Bill,

I agree that it's usually better to let the SSL implementation pick
the ciphers.

I have a certain device that I'd like to talk to that is running on an
underpowered embedded CPU. When I let OpenSSL pick the ciphers, it
chooses something like EDH-RSA-AES-SHA and takes about 3.5 seconds to
finish the handshake. If I can restrict the cipher list to
RSA-RC4-SHA I can reduce the handshake time to less than a second and
improve the throughput of any bulk data transfer over the connection.

--Chris



On Thu, Sep 10, 2009 at 12:09 PM, Bill Janssen<janssen [at] parc> wrote:
> Thanks, Chris.  Can you explain why you want to set the cipher list
> explicitly?  IMO, it's usually better to select a security scheme (TLS1,
> or SSLv3, etc.), and let the implementation pick the cipher list.
>
> Bill
>
> Chris Frantz <frantzcj [at] gmail> wrote:
>
>> Done.
>>
>> Attached to Issue 3597, which is a similar request to mine.
>>
>> Best Regards,
>> --Chris
>> _______________________________________________
>> Python-Dev mailing list
>> Python-Dev [at] python
>> http://mail.python.org/mailman/listinfo/python-dev
>> Unsubscribe: http://mail.python.org/mailman/options/python-dev/janssen%40parc.com
>
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


janssen at parc

Sep 10, 2009, 11:14 AM

Post #6 of 8 (790 views)
Permalink
Re: Controlling the cipher list for SSL connections [In reply to]

Chris,

OK, seems reasonable. Thanks. In the near term, can you do this with
M2Crypto or PyOpenSSL?

When I started this update in 2007, we were trying to keep the API
simple to avoid confusing people and avoid competition with the two
full-fledged toolkits out there. But I don't see any real reason not to
extend the API a bit.

Bill

Chris Frantz <frantzcj [at] gmail> wrote:

> Bill,
>
> I agree that it's usually better to let the SSL implementation pick
> the ciphers.
>
> I have a certain device that I'd like to talk to that is running on an
> underpowered embedded CPU. When I let OpenSSL pick the ciphers, it
> chooses something like EDH-RSA-AES-SHA and takes about 3.5 seconds to
> finish the handshake. If I can restrict the cipher list to
> RSA-RC4-SHA I can reduce the handshake time to less than a second and
> improve the throughput of any bulk data transfer over the connection.
>
> --Chris
>
>
>
> On Thu, Sep 10, 2009 at 12:09 PM, Bill Janssen<janssen [at] parc> wrote:
> > Thanks, Chris.  Can you explain why you want to set the cipher list
> > explicitly?  IMO, it's usually better to select a security scheme (TLS1,
> > or SSLv3, etc.), and let the implementation pick the cipher list.
> >
> > Bill
> >
> > Chris Frantz <frantzcj [at] gmail> wrote:
> >
> >> Done.
> >>
> >> Attached to Issue 3597, which is a similar request to mine.
> >>
> >> Best Regards,
> >> --Chris
> >> _______________________________________________
> >> Python-Dev mailing list
> >> Python-Dev [at] python
> >> http://mail.python.org/mailman/listinfo/python-dev
> >> Unsubscribe: http://mail.python.org/mailman/options/python-dev/janssen%40parc.com
> >
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


frantzcj at gmail

Sep 10, 2009, 11:26 AM

Post #7 of 8 (791 views)
Permalink
Re: Controlling the cipher list for SSL connections [In reply to]

Bill,

For now, using pyOpenSSL is acceptable. I just discovered that the
web.py framework wants pyOpenSSL. Since my project is also using
web.py, I'll need pyOpenSSL anyway.

Thank you,
--Chris


On Thu, Sep 10, 2009 at 1:14 PM, Bill Janssen<janssen [at] parc> wrote:
> Chris,
>
> OK, seems reasonable.  Thanks.  In the near term, can you do this with
> M2Crypto or PyOpenSSL?
>
> When I started this update in 2007, we were trying to keep the API
> simple to avoid confusing people and avoid competition with the two
> full-fledged toolkits out there.  But I don't see any real reason not to
> extend the API a bit.
>
> Bill
>
> Chris Frantz <frantzcj [at] gmail> wrote:
>
>> Bill,
>>
>> I agree that it's usually better to let the SSL implementation pick
>> the ciphers.
>>
>> I have a certain device that I'd like to talk to that is running on an
>> underpowered embedded CPU.   When I let OpenSSL pick the ciphers, it
>> chooses something like EDH-RSA-AES-SHA and takes about 3.5 seconds to
>> finish  the handshake.  If I can restrict the cipher list to
>> RSA-RC4-SHA I can reduce the handshake time to less than a second and
>> improve the throughput of any bulk data transfer over the connection.
>>
>> --Chris
>>
>>
>>
>> On Thu, Sep 10, 2009 at 12:09 PM, Bill Janssen<janssen [at] parc> wrote:
>> > Thanks, Chris.  Can you explain why you want to set the cipher list
>> > explicitly?  IMO, it's usually better to select a security scheme (TLS1,
>> > or SSLv3, etc.), and let the implementation pick the cipher list.
>> >
>> > Bill
>> >
>> > Chris Frantz <frantzcj [at] gmail> wrote:
>> >
>> >> Done.
>> >>
>> >> Attached to Issue 3597, which is a similar request to mine.
>> >>
>> >> Best Regards,
>> >> --Chris
>> >> _______________________________________________
>> >> Python-Dev mailing list
>> >> Python-Dev [at] python
>> >> http://mail.python.org/mailman/listinfo/python-dev
>> >> Unsubscribe: http://mail.python.org/mailman/options/python-dev/janssen%40parc.com
>> >
>
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


htoivonen at spikesource

Sep 10, 2009, 11:32 AM

Post #8 of 8 (792 views)
Permalink
Re: Controlling the cipher list for SSL connections [In reply to]

Bill Janssen wrote:
> OK, seems reasonable. Thanks. In the near term, can you do this with
> M2Crypto or PyOpenSSL?
>
> When I started this update in 2007, we were trying to keep the API
> simple to avoid confusing people and avoid competition with the two
> full-fledged toolkits out there. But I don't see any real reason not to
> extend the API a bit.

Speaking as the M2Crypto maintainer, I don't mind the stdlib competing
with M2Crypto/getting better at SSL. In fact, I would actually like to
see the stdlib SSL implementation getting good enough so that people
would not need M2Crypto for SSL (except maybe in special circumstances).
There is much M2Crypto does besides SSL so this wouldn't even obsolete it.

One of the main things IMO missing from stdlib SSL implementation is
hostname checking by default (with override option), but I know you and
I have different opinions on this. I would be happy to provide patches
against the stdlib SSL implementation for some things M2Crypto does that
the stdlib SSL module is missing if we could agree on the
features/design first. Simple is good, but I'd like the defaults to be
secure and commonly overridden things to be overrideable.

--
Heikki Toivonen
Attachments: signature.asc (0.25 KB)

Python dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.