netlib.utils -> netlib.check
Now only contains is_valid_[host,port] Intermediate step - this will be in mitproxy.net soon.
This commit is contained in:
parent
e0f3cce14c
commit
9870844b38
|
@ -7,7 +7,7 @@ import netlib.exceptions
|
|||
from mitmproxy import exceptions
|
||||
from mitmproxy.contrib.tls import _constructs
|
||||
from mitmproxy.proxy.protocol import base
|
||||
from netlib import utils
|
||||
from netlib import check
|
||||
|
||||
|
||||
# taken from https://testssl.sh/openssl-rfc.mappping.html
|
||||
|
@ -265,7 +265,7 @@ class TlsClientHello:
|
|||
extension.type == 0x00 and
|
||||
len(extension.server_names) == 1 and
|
||||
extension.server_names[0].type == 0 and
|
||||
utils.is_valid_host(extension.server_names[0].name)
|
||||
check.is_valid_host(extension.server_names[0].name)
|
||||
)
|
||||
if is_valid_sni_extension:
|
||||
return extension.server_names[0].name.decode("idna")
|
||||
|
|
|
@ -6,7 +6,7 @@ from netlib.http import request
|
|||
from netlib.http import response
|
||||
from netlib.http import headers
|
||||
from netlib.http import url
|
||||
from netlib import utils
|
||||
from netlib import check
|
||||
from netlib import exceptions
|
||||
|
||||
|
||||
|
@ -274,7 +274,7 @@ def _parse_authority_form(hostport):
|
|||
try:
|
||||
host, port = hostport.split(b":")
|
||||
port = int(port)
|
||||
if not utils.is_valid_host(host) or not utils.is_valid_port(port):
|
||||
if not check.is_valid_host(host) or not check.is_valid_port(port):
|
||||
raise ValueError()
|
||||
except ValueError:
|
||||
raise exceptions.HttpSyntaxException("Invalid host specification: {}".format(hostport))
|
||||
|
|
|
@ -2,7 +2,7 @@ import urllib
|
|||
from typing import Sequence
|
||||
from typing import Tuple
|
||||
|
||||
from netlib import utils
|
||||
from netlib import check
|
||||
|
||||
|
||||
# PY2 workaround
|
||||
|
@ -62,9 +62,9 @@ def parse(url):
|
|||
if not full_path.startswith(b"/"):
|
||||
full_path = b"/" + full_path
|
||||
|
||||
if not utils.is_valid_host(host):
|
||||
if not check.is_valid_host(host):
|
||||
raise ValueError("Invalid Host")
|
||||
if not utils.is_valid_port(port):
|
||||
if not check.is_valid_port(port):
|
||||
raise ValueError("Invalid Port")
|
||||
|
||||
return parsed.scheme, host, port, full_path
|
||||
|
|
|
@ -2,7 +2,8 @@ import struct
|
|||
import array
|
||||
import ipaddress
|
||||
|
||||
from netlib import tcp, utils
|
||||
from netlib import tcp
|
||||
from netlib import check
|
||||
from mitmproxy.types import bidi
|
||||
|
||||
|
||||
|
@ -204,7 +205,7 @@ class Message:
|
|||
elif atyp == ATYP.DOMAINNAME:
|
||||
length, = struct.unpack("!B", f.safe_read(1))
|
||||
host = f.safe_read(length)
|
||||
if not utils.is_valid_host(host):
|
||||
if not check.is_valid_host(host):
|
||||
raise SocksError(REP.GENERAL_SOCKS_SERVER_FAILURE, "Invalid hostname: %s" % host)
|
||||
host = host.decode("idna")
|
||||
use_ipv6 = False
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import mock
|
||||
import io
|
||||
|
||||
import netlib.utils
|
||||
import netlib.tutils
|
||||
from netlib.http import Headers
|
||||
import mitmproxy.io
|
||||
from mitmproxy import flowfilter, options
|
||||
|
|
|
@ -9,7 +9,6 @@ from unittest.case import SkipTest
|
|||
|
||||
import io
|
||||
|
||||
import netlib.utils
|
||||
import netlib.tutils
|
||||
from mitmproxy import controller
|
||||
from mitmproxy import connections
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
# coding=utf-8
|
||||
|
||||
from netlib import check
|
||||
|
||||
|
||||
def test_is_valid_host():
|
||||
assert not check.is_valid_host(b"")
|
||||
assert check.is_valid_host(b"one.two")
|
||||
assert not check.is_valid_host(b"one" * 255)
|
||||
assert check.is_valid_host(b"one.two.")
|
|
@ -1,10 +0,0 @@
|
|||
# coding=utf-8
|
||||
|
||||
from netlib import utils
|
||||
|
||||
|
||||
def test_is_valid_host():
|
||||
assert not utils.is_valid_host(b"")
|
||||
assert utils.is_valid_host(b"one.two")
|
||||
assert not utils.is_valid_host(b"one" * 255)
|
||||
assert utils.is_valid_host(b"one.two.")
|
Loading…
Reference in New Issue