How to disable SSL3 and weak ciphers with cherrypy builtin ssl module (python 3)

2024/9/20 11:54:05

I have configured Cherrypy 3.8.0 with Python 3 to use SSL/TLS. However, I want to disable SSL3 to avoid POODLE. I searched through the documentation but I am unsure on how to implement it.

I am using the cherrypy/python builtin ssl module, not pyOpenSSL which I am unable to use under Python 3.

Answer

To disable SSL3, you should set the ssl_context variable yourself rather than accepting the default. Here's an example using Python's built-in ssl module (in lieu of the built-in cherrypy ssl module).

import cherrypy
import sslctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ctx.options |= ssl.OP_NO_SSLv2 
ctx.options |= ssl.OP_NO_SSLv3cherrypy.config.update(server_config)

where in this case, SSL is from the OpenSSL module.

It's worth noting that beginning in Python 3.2.3, the ssl module disables certain weak ciphers by default.

Furthermore, you can specifically set all the ciphers you want with

ciphers = {'DHE-RSA-AE256-SHA',...'RC4-SHA'
}ctx.set_ciphers(':'.join(ciphers))

If you're using the CherryPyWSGIServer from the web.wsgiserver module, you would set the default ciphers with

CherryPyWSGIServer.ssl_adapter.context.set_cipher_list(':'.join(ciphers))

Here is part of the documentation detailing the above: http://docs.cherrypy.org/en/latest/pkg/cherrypy.wsgiserver.html#module-cherrypy.wsgiserver.ssl_builtin

Lastly, here are some sources (asking similar questions) that you may want to look at:

  • How to block SSL protocols in favor of TLS?
  • https://review.cloudera.org/r/4739/diff/
  • http://roadha.us/2014/10/disable-sslv3-avoid-poodle-attack-web-py/
  • http://blog.gosquadron.com/use-tls
  • http://www.experts-exchange.com/questions/28073251/Disable-weak-SSL-cipher-on-CherryPy-pyOpenSSL-Windows-2008-Server.html
https://en.xdnf.cn/q/72171.html

Related Q&A

cleaning big data using python

I have to clean a input data file in python. Due to typo error, the datafield may have strings instead of numbers. I would like to identify all fields which are a string and fill these with NaN using p…

Using the Python shell in Vi mode on Windows

I know that you can use the Python shell in Vi mode on Unix-like operating systems. For example, I have this line in my ~/.inputrc:set editing-mode viThis lets me use Vi-style editing inside the Python…

Calculate residual deviance from scikit-learn logistic regression model

Is there any way to calculate residual deviance of a scikit-learn logistic regression model? This is a standard output from R model summaries, but I couldnt find it any of sklearns documentation.

Use Python to create 2D coordinate

I am truly a novice in Python. Now, I am doing a project which involves creating a list of 2D coordinates. The coordinates should be uniformly placed, using a square grid (10*10), like(0,0)(0,1)(0,2)(0…

How to pass Unicode title to matplotlib?

Cant get the titles right in matplotlib: technologien in C gives: technologien in CPossible solutions already tried:utechnologien in C doesnt work neither does: # -*- coding: utf-8 -*- at the beginnin…

Cythonize but not compile .pyx files using setup.py

I have a Cython project containing several .pyx files. To distribute my project I would like to provide my generated .c files as recommended in the Cython documentation, to minimize problems with diffe…

How to clear matplotlib labels in legend?

Is there a way to clear matplotlib labels inside a graphs legend? This post explains how to remove the legend itself, but the labels themselves still remain, and appear again if you plot a new figure.…

Threading and Signals problem in PyQt

Im having some problems with communicating between Threads in PyQt. Im using signals to communicate between two threads, a Sender and a Listener. The sender sends messages, which are expected to be rec…

stopping a python thread using __del__

I have a threaded program in Python that works fine except that __del__ does not get called once the thread is running:class tt(threading.Thread):def __init__(self):threading.Thread.__init__(self)self.…

Python-docx: Is it possible to add a new run to paragraph in a specific place (not at the end)

I want to set a style to a corrected word in MS Word text. Since its not possible to change text style inside a run, I want to insert a new run with new style into the existing paragraph...for p in doc…