MCPcopy Create free account
hub / github.com/Syncplay/syncplay / _allowTLSconnections

Method _allowTLSconnections

syncplay/server.py:251–290  ·  view source on GitHub ↗
(self, path)

Source from the content-addressed store, hash-verified

249 watcher.setPlaylistIndex(room.getName(), room.getPlaylistIndex())
250
251 def _allowTLSconnections(self, path):
252 try:
253 privKey = open(path+'/privkey.pem', 'rb').read()
254 certif = open(path+'/cert.pem', 'rb').read()
255 chain = open(path+'/chain.pem', 'rb').read()
256
257 self.lastEditCertTime = os.path.getmtime(path+'/cert.pem')
258
259 privKeyPySSL = crypto.load_privatekey(crypto.FILETYPE_PEM, privKey)
260 certifPySSL = crypto.load_certificate(crypto.FILETYPE_PEM, certif)
261
262 sentinel = b'-----BEGIN CERTIFICATE-----'
263 chainPySSL = [crypto.load_certificate(crypto.FILETYPE_PEM, sentinel + chain_cert) for chain_cert in
264 chain.split(sentinel)[1:]]
265
266 cipherListString = "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:"\
267 "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:"\
268 "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384"
269 accCiphers = ssl.AcceptableCiphers.fromOpenSSLCipherString(cipherListString)
270
271 try:
272 contextFactory = ssl.CertificateOptions(privateKey=privKeyPySSL, certificate=certifPySSL,
273 extraCertChain=chainPySSL, acceptableCiphers=accCiphers,
274 raiseMinimumTo=ssl.TLSVersion.TLSv1_2)
275 except AttributeError:
276 contextFactory = ssl.CertificateOptions(privateKey=privKeyPySSL, certificate=certifPySSL,
277 extraCertChain=chainPySSL, acceptableCiphers=accCiphers,
278 method=TLSv1_2_METHOD)
279
280 self.options = contextFactory
281 self.serverAcceptsTLS = True
282 self._TLSattempts = 0
283 print("TLS support is enabled.")
284 except Exception as e:
285 self.options = None
286 self.serverAcceptsTLS = False
287 self.lastEditCertTime = None
288 print("Error while loading the TLS certificates.")
289 print(e)
290 print("TLS support is not enabled.")
291
292 def checkLastEditCertTime(self):
293 try:

Callers 2

__init__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected