Skip to content

Commit

Permalink
SyncplayClient: explicitly pass certifi as trustRoot for Twisted
Browse files Browse the repository at this point in the history
- py2app: include pem in the bundle
- requirements: add pem
- SyncplayClient.start: explicitly use certifi store as trustRoot
  • Loading branch information
albertosottile committed Nov 5, 2022
1 parent 2aa7312 commit af0d000
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion buildPy2app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
OPTIONS = {
'iconfile': 'syncplay/resources/icon.icns',
'extra_scripts': 'syncplayServer.py',
'includes': {'PySide2.QtCore', 'PySide2.QtUiTools', 'PySide2.QtGui', 'PySide2.QtWidgets', 'certifi', 'cffi'},
'includes': {'PySide2.QtCore', 'PySide2.QtUiTools', 'PySide2.QtGui', 'PySide2.QtWidgets', 'certifi', 'cffi', 'pem'},
'excludes': {'PySide', 'PySide.QtCore', 'PySide.QtUiTools', 'PySide.QtGui', 'tkinter'},
'qt_plugins': [
'platforms/libqcocoa.dylib',
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
certifi>=2018.11.29
pem>=21.2.0
twisted[tls]>=16.4.0
appnope>=0.1.0; sys_platform == 'darwin'
pypiwin32>=223; sys_platform == 'win32'
Expand Down
15 changes: 8 additions & 7 deletions syncplay/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
from twisted.internet import reactor, task, defer, threads

try:
SSL_CERT_FILE = None
import certifi
from twisted.internet.ssl import Certificate, optionsForClientTLS
import pem
from twisted.internet.ssl import Certificate, optionsForClientTLS, trustRootFromCertificates
certPath = certifi.where()
if os.path.exists(certPath):
os.environ['SSL_CERT_FILE'] = certPath
SSL_CERT_FILE = certPath
elif 'zip' in certPath:
import tempfile
import zipfile
Expand All @@ -32,7 +34,7 @@
archive = zipfile.ZipFile(zipPath, 'r')
tmpDir = tempfile.gettempdir()
extractedPath = archive.extract(memberPath, tmpDir)
os.environ['SSL_CERT_FILE'] = extractedPath
SSL_CERT_FILE = extractedPath
except:
pass

Expand Down Expand Up @@ -831,10 +833,9 @@ def start(self, host, port):
port = int(port)
self._endpoint = HostnameEndpoint(reactor, host, port)
try:
caCertFP = open(os.environ['SSL_CERT_FILE'])
caCertTwisted = Certificate.loadPEM(caCertFP.read().encode('utf-8'))
caCertFP.close()
self.protocolFactory.options = optionsForClientTLS(hostname=host)
certs = pem.parse_file(SSL_CERT_FILE)
trustRoot = trustRootFromCertificates([Certificate.loadPEM(str(cert)) for cert in certs])
self.protocolFactory.options = optionsForClientTLS(hostname=host, trustRoot=trustRoot)
self._clientSupportsTLS = True
except Exception as e:
self.ui.showDebugMessage(str(e))
Expand Down

0 comments on commit af0d000

Please sign in to comment.