forked from shaba/openuds
Fixed Client on non standard ports
This commit is contained in:
parent
55c4574021
commit
c9488329b9
@ -178,18 +178,24 @@ class RestApi:
|
|||||||
def _open(
|
def _open(
|
||||||
url: str, certErrorCallback: typing.Optional[CertCallbackType] = None
|
url: str, certErrorCallback: typing.Optional[CertCallbackType] = None
|
||||||
) -> typing.Any:
|
) -> typing.Any:
|
||||||
|
print('Open')
|
||||||
ctx = ssl.create_default_context()
|
ctx = ssl.create_default_context()
|
||||||
ctx.check_hostname = False
|
ctx.check_hostname = False
|
||||||
ctx.verify_mode = ssl.CERT_NONE
|
ctx.verify_mode = ssl.CERT_NONE
|
||||||
ctx.load_verify_locations(certifi.where())
|
ctx.load_verify_locations(tools.getCaCertsFile())
|
||||||
hostname = urllib.parse.urlparse(url)[1]
|
hostname = urllib.parse.urlparse(url)[1]
|
||||||
serial = ''
|
serial = ''
|
||||||
|
|
||||||
|
port = ''
|
||||||
|
if ':' in hostname:
|
||||||
|
hostname, port = hostname.split(':')
|
||||||
|
|
||||||
if url.startswith('https'):
|
if url.startswith('https'):
|
||||||
|
port = port or '443'
|
||||||
with ctx.wrap_socket(
|
with ctx.wrap_socket(
|
||||||
socket.socket(socket.AF_INET, socket.SOCK_STREAM), server_hostname=hostname
|
socket.socket(socket.AF_INET, socket.SOCK_STREAM), server_hostname=hostname
|
||||||
) as s:
|
) as s:
|
||||||
s.connect((hostname, 443))
|
s.connect((hostname, int(port)))
|
||||||
# Get binary certificate
|
# Get binary certificate
|
||||||
binCert = s.getpeercert(True)
|
binCert = s.getpeercert(True)
|
||||||
if binCert:
|
if binCert:
|
||||||
@ -231,6 +237,7 @@ class RestApi:
|
|||||||
def getUrl(
|
def getUrl(
|
||||||
url: str, certErrorCallback: typing.Optional[CertCallbackType] = None
|
url: str, certErrorCallback: typing.Optional[CertCallbackType] = None
|
||||||
) -> bytes:
|
) -> bytes:
|
||||||
|
print(url)
|
||||||
with RestApi._open(url, certErrorCallback) as response:
|
with RestApi._open(url, certErrorCallback) as response:
|
||||||
resp = response.read()
|
resp = response.read()
|
||||||
|
|
||||||
|
@ -33,12 +33,14 @@ import tempfile
|
|||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
import os
|
import os
|
||||||
|
import os.path
|
||||||
import socket
|
import socket
|
||||||
import stat
|
import stat
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import base64
|
import base64
|
||||||
import typing
|
import typing
|
||||||
|
import certifi
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import psutil
|
import psutil
|
||||||
@ -226,3 +228,20 @@ def verifySignature(script: bytes, signature: bytes) -> bool:
|
|||||||
|
|
||||||
# If no exception, the script was fine...
|
# If no exception, the script was fine...
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def getCaCertsFile() -> str:
|
||||||
|
logger.debug('Certifi: %s', certifi.where())
|
||||||
|
logger.debug('File: %s', __file__)
|
||||||
|
try:
|
||||||
|
if os.path.exists(certifi.where()):
|
||||||
|
logger.debug('Certifi file exists: %s', certifi.where())
|
||||||
|
return certifi.where()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if 'darwin' in sys.platform:
|
||||||
|
path = __file__
|
||||||
|
logger.debug('Certifi file: %s', path)
|
||||||
|
return path
|
||||||
|
|
||||||
|
return ''
|
||||||
|
@ -39,7 +39,7 @@ import select
|
|||||||
import typing
|
import typing
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import certifi
|
from . import tools
|
||||||
|
|
||||||
HANDSHAKE_V1 = b'\x5AMGB\xA5\x01\x00'
|
HANDSHAKE_V1 = b'\x5AMGB\xA5\x01\x00'
|
||||||
BUFFER_SIZE = 1024 * 16 # Max buffer length
|
BUFFER_SIZE = 1024 * 16 # Max buffer length
|
||||||
@ -51,7 +51,6 @@ TUNNEL_LISTENING, TUNNEL_OPENING, TUNNEL_PROCESSING, TUNNEL_ERROR = 0, 1, 2, 3
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ForwardServer(socketserver.ThreadingTCPServer):
|
class ForwardServer(socketserver.ThreadingTCPServer):
|
||||||
daemon_threads = True
|
daemon_threads = True
|
||||||
allow_reuse_address = True
|
allow_reuse_address = True
|
||||||
@ -118,7 +117,7 @@ class ForwardServer(socketserver.ThreadingTCPServer):
|
|||||||
|
|
||||||
# Do not "recompress" data, use only "base protocol" compression
|
# Do not "recompress" data, use only "base protocol" compression
|
||||||
context.options |= ssl.OP_NO_COMPRESSION
|
context.options |= ssl.OP_NO_COMPRESSION
|
||||||
context.load_verify_locations(certifi.where()) # Load certifi certificates
|
context.load_verify_locations(tools.getCaCertsFile()) # Load certifi certificates
|
||||||
|
|
||||||
# If ignore remote certificate
|
# If ignore remote certificate
|
||||||
if self.check_certificate is False:
|
if self.check_certificate is False:
|
||||||
|
Loading…
Reference in New Issue
Block a user