Make all calls honor VERIFY_SSL_CERT setting (#1541)

* Make PmsConnect honor VERIFY_SSL_CERT setting

* Make all websockets and WebUI tests honor VERIFY_SSL_CERT setting

Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com>
This commit is contained in:
Niccolò Maggioni 2021-11-14 06:03:12 +01:00 committed by GitHub
parent 93cb067454
commit 90f3e9ac85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 5 deletions

View file

@ -94,9 +94,12 @@ class PmsConnect(object):
else: else:
self.token = plexpy.CONFIG.PMS_TOKEN self.token = plexpy.CONFIG.PMS_TOKEN
self.ssl_verify = plexpy.CONFIG.VERIFY_SSL_CERT
self.request_handler = http_handler.HTTPHandler(urls=self.url, self.request_handler = http_handler.HTTPHandler(urls=self.url,
token=self.token, token=self.token,
timeout=self.timeout) timeout=self.timeout,
ssl_verify=self.ssl_verify)
def get_sessions(self, output_format=''): def get_sessions(self, output_format=''):
""" """

View file

@ -222,7 +222,7 @@ def run():
logger.warn("Tautulli WebSocket :: Reconnection attempt %s." % str(reconnects)) logger.warn("Tautulli WebSocket :: Reconnection attempt %s." % str(reconnects))
try: try:
plexpy.WEBSOCKET = create_connection(uri, header=header) plexpy.WEBSOCKET = create_connection(uri, header=header, sslopt=sslopt)
logger.info("Tautulli WebSocket :: Ready") logger.info("Tautulli WebSocket :: Ready")
plexpy.WS_CONNECTED = True plexpy.WS_CONNECTED = True
except (websocket.WebSocketException, IOError, Exception) as e: except (websocket.WebSocketException, IOError, Exception) as e:

View file

@ -24,6 +24,7 @@ from backports import csv
from io import open, BytesIO from io import open, BytesIO
import base64 import base64
import json import json
import ssl as _ssl
import linecache import linecache
import os import os
import shutil import shutil
@ -41,6 +42,7 @@ from mako.lookup import TemplateLookup
import mako.template import mako.template
import mako.exceptions import mako.exceptions
import certifi
import websocket import websocket
if sys.version_info >= (3, 6): if sys.version_info >= (3, 6):
@ -4121,6 +4123,8 @@ class WebInterface(object):
{'identifier': '08u2phnlkdshf890bhdlksghnljsahgleikjfg9t'} {'identifier': '08u2phnlkdshf890bhdlksghnljsahgleikjfg9t'}
``` ```
""" """
ssl = helpers.bool_true(ssl)
# Attempt to get the pms_identifier from plex.tv if the server is published # Attempt to get the pms_identifier from plex.tv if the server is published
# Works for all PMS SSL settings # Works for all PMS SSL settings
if not identifier and hostname and port: if not identifier and hostname and port:
@ -4136,7 +4140,7 @@ class WebInterface(object):
# Fallback to checking /identity endpoint if the server is unpublished # Fallback to checking /identity endpoint if the server is unpublished
# Cannot set SSL settings on the PMS if unpublished so 'http' is okay # Cannot set SSL settings on the PMS if unpublished so 'http' is okay
if not identifier: if not identifier:
scheme = 'https' if helpers.cast_to_int(ssl) else 'http' scheme = 'https' if ssl else 'http'
url = '{scheme}://{hostname}:{port}'.format(scheme=scheme, hostname=hostname, port=port) url = '{scheme}://{hostname}:{port}'.format(scheme=scheme, hostname=hostname, port=port)
uri = '/identity' uri = '/identity'
@ -4166,10 +4170,20 @@ class WebInterface(object):
# Quick test websocket connection # Quick test websocket connection
ws_url = result['url'].replace('http', 'ws', 1) + '/:/websockets/notifications' ws_url = result['url'].replace('http', 'ws', 1) + '/:/websockets/notifications'
header = ['X-Plex-Token: %s' % plexpy.CONFIG.PMS_TOKEN] header = ['X-Plex-Token: %s' % plexpy.CONFIG.PMS_TOKEN]
# Enforce SSL as needed
if ssl:
secure = 'secure '
if plexpy.CONFIG.VERIFY_SSL_CERT:
sslopt = {'ca_certs': certifi.where()}
else:
sslopt = {'cert_reqs': _ssl.CERT_NONE}
else:
secure = ''
sslopt = None
logger.debug("Testing websocket connection...") logger.debug("Testing %swebsocket connection..." % secure)
try: try:
test_ws = websocket.create_connection(ws_url, header=header) test_ws = websocket.create_connection(ws_url, header=header, sslopt=sslopt)
test_ws.close() test_ws.close()
logger.debug("Websocket connection test successful.") logger.debug("Websocket connection test successful.")
result['ws'] = True result['ws'] = True