[Win32] Fix missing certs for HTTPS requests

The following error occured on Windows when switching to using HTTPS
url with Twisted Agent:
```
<class 'twisted.web._newclient.ResponseNeverReceived'>: [<twisted.python.failure.Failure OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]>
```

The fix is to install certifi and provide the path to the trust store as
env var for OpenSSL to pick up.

Also includes a simplication of the core test_listen_port code.
This commit is contained in:
Calum Lind 2018-06-29 10:22:30 +01:00
parent 3fab799dbf
commit e626f9fece
3 changed files with 11 additions and 11 deletions

View File

@ -32,6 +32,7 @@ install:
pip install
tox
pywin32
certifi
)
- if not defined TOXENV (
pip install
@ -44,6 +45,7 @@ install:
slimit
setproctitle
pywin32
certifi
pygame
bbfreeze
pefile

View File

@ -40,6 +40,12 @@ except ImportError:
from urlparse import urljoin # pylint: disable=ungrouped-imports
from urllib import pathname2url, unquote_plus # pylint: disable=ungrouped-imports
# Windows workaround for HTTPS requests requiring certificate authority bundle.
# see: https://twistedmatrix.com/trac/ticket/9209
if platform.system() in ('Windows', 'Microsoft'):
from certifi import where
os.environ['SSL_CERT_FILE'] = where()
DBUS_FILEMAN = None
# gi makes dbus available on Window but don't import it as unused.
if platform.system() not in ('Windows', 'Microsoft', 'Darwin'):

View File

@ -1121,23 +1121,15 @@ class Core(component.Component):
port = self.get_listen_port()
url = 'https://deluge-torrent.org/test_port.php?port=%s' % port
agent = Agent(reactor, connectTimeout=30)
d = agent.request(
b'GET',
url.encode('utf-8'),
)
d = agent.request(b'GET', url.encode())
def on_get_page(response):
d = readBody(response)
d.addCallback(on_read_body)
return d
def on_read_body(body):
def on_get_page(body):
return bool(int(body))
def on_error(failure):
log.warning('Error testing listen port: %s', failure)
d.addCallback(on_get_page)
d.addCallback(readBody).addCallback(on_get_page)
d.addErrback(on_error)
return d