startTLS: making TLS support (and dependencies) optional

This commit is contained in:
Alberto Sottile 2019-02-05 16:28:48 +01:00
parent 7dfe9d2bdb
commit 18e39b4aae
3 changed files with 15 additions and 7 deletions

View File

@ -1,6 +1,5 @@
import ast import ast
import certifi
import collections import collections
import hashlib import hashlib
import os import os
@ -15,10 +14,16 @@ from functools import wraps
from twisted.internet.endpoints import HostnameEndpoint, wrapClientTLS from twisted.internet.endpoints import HostnameEndpoint, wrapClientTLS
from twisted.internet.protocol import ClientFactory from twisted.internet.protocol import ClientFactory
from twisted.internet.ssl import Certificate, optionsForClientTLS
from twisted.internet import reactor, task, defer, threads from twisted.internet import reactor, task, defer, threads
from twisted.application.internet import ClientService from twisted.application.internet import ClientService
try:
import certifi
from twisted.internet.ssl import optionsForClientTLS
os.environ['SSL_CERT_FILE'] = certifi.where()
except:
pass
from syncplay import utils, constants, version from syncplay import utils, constants, version
from syncplay.constants import PRIVACY_SENDHASHED_MODE, PRIVACY_DONTSEND_MODE, \ from syncplay.constants import PRIVACY_SENDHASHED_MODE, PRIVACY_DONTSEND_MODE, \
PRIVACY_HIDDENFILENAME PRIVACY_HIDDENFILENAME
@ -26,8 +31,6 @@ from syncplay.messages import getMissingStrings, getMessage
from syncplay.protocols import SyncClientProtocol from syncplay.protocols import SyncClientProtocol
from syncplay.utils import isMacOS from syncplay.utils import isMacOS
os.environ['SSL_CERT_FILE'] = certifi.where()
class SyncClientFactory(ClientFactory): class SyncClientFactory(ClientFactory):
def __init__(self, client, retry=constants.RECONNECT_RETRIES): def __init__(self, client, retry=constants.RECONNECT_RETRIES):

View File

@ -78,7 +78,7 @@ class SyncClientProtocol(JSONCommandProtocol):
self.sendTLS({"startTLS": "send"}) self.sendTLS({"startTLS": "send"})
self._client.ui.showMessage("Attempting secure connection") self._client.ui.showMessage("Attempting secure connection")
else: else:
self._client.ui.showErrorMessage("This server does not support TLS") self._client.ui.showErrorMessage("TLS is not supported")
self.sendHello() self.sendHello()
def connectionLost(self, reason): def connectionLost(self, reason):

View File

@ -5,12 +5,17 @@ import os
import random import random
import time import time
from string import Template from string import Template
from OpenSSL import crypto
from twisted.enterprise import adbapi from twisted.enterprise import adbapi
from twisted.internet import task, reactor, ssl from twisted.internet import task, reactor, ssl
from twisted.internet.protocol import Factory from twisted.internet.protocol import Factory
try:
from OpenSSL import crypto
from twisted.internet import ssl
except:
pass
import syncplay import syncplay
from syncplay import constants from syncplay import constants
from syncplay.messages import getMessage from syncplay.messages import getMessage
@ -212,7 +217,7 @@ class SyncFactory(Factory):
self.options = contextFactory self.options = contextFactory
except Exception as e: except Exception as e:
print(e) print(e)
print("Cannot import certificates. TLS support not enabled.") print("TLS support is not enabled.")
class StatsRecorder(object): class StatsRecorder(object):