Skip to content

Can't use TLS in client on Fedora 31 #292

@Phidica

Description

@Phidica

Fedora 31, using current Git master of Syncplay (23ca271).

Despite having all of the required dependencies for TLS in the client, I was still seeing "This client does not support TLS" at startup. Running in debug mode, I saw the following:

$ ./syncplayClient.py --debug
UnicodeEncodeError: 'ascii' codec can't encode character '\u0151' in position 126065: ordinal not in range(128)
[...]

After digging through the source code and testing commands related to TLS, I found that the error arises from the following block in syncplay/client.py

try:
    caCertFP = open(os.environ['SSL_CERT_FILE'])
    caCertTwisted = Certificate.loadPEM(caCertFP.read())
    caCertFP.close()
    self.protocolFactory.options = optionsForClientTLS(hostname=host)
    self._clientSupportsTLS = True
except Exception as e:
    self.ui.showDebugMessage(str(e))

What's happening is that my system CA bundle (ca-certificates-2020.2.40-1.1.fc31.noarch) contains Unicode in one of the comments between certs. Specifically on the line

# NetLock Arany (Class Gold) Főtanúsítvány

Then Certificate.loadPEM(caCertFP.read()) raises an exception with the following trace (reproduced in an interactive Python session, running the commands myself):

Traceback (most recent call last):
  File "/usr/lib64/python3.7/site-packages/twisted/internet/_sslverify.py", line 500, in loadPEM
    return Class.load(data, crypto.FILETYPE_PEM)
  File "/usr/lib64/python3.7/site-packages/twisted/internet/_sslverify.py", line 477, in load
    return Class(crypto.load_certificate(format, requestData), *args)
  File "/usr/lib/python3.7/site-packages/OpenSSL/crypto.py", line 1824, in load_certificate
    buffer = buffer.encode("ascii")
UnicodeEncodeError: 'ascii' codec can't encode character '\u0151' in position 126065: ordinal not in range(128)

Here's the thing though: caCertTwisted is never even used for anything. It looks like we attempt to load the system CA bundle just as a test that it...exists, or something? But if I remove the line

    caCertTwisted = Certificate.loadPEM(caCertFP.read())

and then launch the client, TLS works! So, the UnicodeEncodeError raised by PyOpenSSL is actually irrelevant when it comes to actually starting the client with TLS, and I am able to successfully connect to the public server over TLSv1.3 after applying this change.

So, I think that this test done to determine whether the client can launch with TLS needs to be reviewed.

(Alternatively, this could be considered a bug upstream in Twisted or PyOpenSSL, however it kind of looks like these methods are only intended to be loading one certificate, not a bundle containing comments between certificates... So I'm not sure they would accept it as a bug?)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions