0

I am trying to connect to my MariaDB with SSL enabled. On my old installation (Kubuntu 19.10) this worked. With the new installation (also new PC: Xubuntu 20.04) I get this error message:

ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1108)

Here are my installation details:
Old installation: python 3.7.5, pymysql 0.9.3, ssl.OPENSSL_VERSION = 1.1.1c 28 May 2019
New installation: python 3.8.2, pymysql 0.9.3, ssl.OPENSSL_VERSION = 1.1.1f 31 Mar 2020

I have compiled python 3.7.5 on my new PC -> I still get the error message.
I have compiled python with a different SSL version:
this works: python 3.7.5, ssl.OPENSSL_VERSION = OpenSSL 1.1.0m-dev xx XXX xxxx
this works: python 3.7.5, ssl.OPENSSL_VERSION = OpenSSL 1.1.1h-dev xx XXX xxxx
this works: python 3.8.2, ssl.OPENSSL_VERSION = OpenSSL 1.1.1h-dev xx XXX xxxx

This is my test script:

import os
import pymysql

#pymysql.connections.DEBUG = True
#pymysql._auth.DEBUG = True

host = "127.0.0.1"
port = 3306

ca = os.path.expanduser("~/ca-cert.pem")
ssl = {'ca': ca, 'check_hostname': False}

user = 'user'
passwd = 'passwd'


def test_ssl():
    con = pymysql.connect(user=user, password=passwd, host=host, port=port, ssl=ssl)
    con.close()

test_ssl()

The ca-cert I have created like this:

openssl genrsa 2048 > ca-key.pem
openssl req -new -x509 -nodes -days 3600 -key ca-key.pem -out ca-cert.pem

It seems, like the one specific version of openSSL does not work together with PyMySQL. It could be an error with the Xubuntu compilation. Or it could be the specific version (1.1.1f). But I do not know, how to compile this version myself.

1 Answer 1

0

I had the same issue but I found a solution.

I was creating a docker container based on ubuntu 20.04 and Python3.8.2. It installed openssl by default. The version from 2020-Mar-31 12:41:55 openssl-1.1.1f.tar.gz was giving me this error: ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1108). After looking for solutions, I found this link: https://cloudwafer.com/blog/installing-openssl-on-ubuntu-16-04-18-04/. In that link, you can find how to install openssl from the source. It shows you how to install the version from 2019-May-28 13:26:28 openssl-1.1.1c.tar.gz. First I built my container as originally and logged in and I followed the steps in the link. It solved my problem. The latest version from March 2020 was causing the issue.

I added the lines of code below when building the docker container to automate the steps. See:

RUN apt install build-essential checkinstall zlib1g-dev -y
WORKDIR /usr/local/src/
RUN wget https://www.openssl.org/source/openssl-1.1.1c.tar.gz && tar -xf openssl-1.1.1c.tar.gz
WORKDIR openssl-1.1.1c
RUN ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib && make && make install
COPY ./openssl-1.1.1c.conf /etc/ld.so.conf.d/
RUN ldconfig -v && mv /usr/bin/c_rehash /usr/bin/c_rehash.backup && mv /usr/bin/openssl /usr/bin/openssl.backup
ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/ssl/bin"
  • Note that I created the openssl-1.1.1c.conf file before building the container. The file is copied from the same directory where the dockerfile is saved. Create the file with that name and paste this inside: /usr/local/ssl/lib

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.