mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
commit
23ce1face0
@ -502,7 +502,7 @@ class _Connection:
|
|||||||
# Cipher List
|
# Cipher List
|
||||||
if cipher_list:
|
if cipher_list:
|
||||||
try:
|
try:
|
||||||
context.set_cipher_list(cipher_list)
|
context.set_cipher_list(cipher_list.encode())
|
||||||
context.set_tmp_ecdh(OpenSSL.crypto.get_elliptic_curve('prime256v1'))
|
context.set_tmp_ecdh(OpenSSL.crypto.get_elliptic_curve('prime256v1'))
|
||||||
except SSL.Error as v:
|
except SSL.Error as v:
|
||||||
raise exceptions.TlsException("SSL cipher specification error: %s" % str(v))
|
raise exceptions.TlsException("SSL cipher specification error: %s" % str(v))
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
import os
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
import mmap
|
import mmap
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
DATATYPES = dict(
|
DATATYPES = dict(
|
||||||
@ -74,24 +74,20 @@ class RandomGenerator:
|
|||||||
|
|
||||||
|
|
||||||
class FileGenerator:
|
class FileGenerator:
|
||||||
|
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.path = path
|
self.path = path
|
||||||
self.fp = open(path, "rb")
|
|
||||||
self.map = mmap.mmap(self.fp.fileno(), 0, access=mmap.ACCESS_READ)
|
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.map)
|
return os.path.getsize(self.path)
|
||||||
|
|
||||||
def __getitem__(self, x):
|
def __getitem__(self, x):
|
||||||
if isinstance(x, slice):
|
with open(self.path, mode="rb") as f:
|
||||||
return self.map.__getitem__(x)
|
if isinstance(x, slice):
|
||||||
# A slice of length 1 returns a byte object (not an integer)
|
with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as mapped:
|
||||||
return self.map.__getitem__(slice(x, x + 1 or self.map.size()))
|
return mapped.__getitem__(x)
|
||||||
|
else:
|
||||||
|
f.seek(x)
|
||||||
|
return f.read(1)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s" % self.path
|
return "<%s" % self.path
|
||||||
|
|
||||||
def close(self):
|
|
||||||
self.map.close()
|
|
||||||
self.fp.close()
|
|
||||||
|
@ -216,7 +216,8 @@ def args_pathod(argv, stdout_=sys.stdout, stderr_=sys.stderr):
|
|||||||
anchors = []
|
anchors = []
|
||||||
for patt, spec in args.anchors:
|
for patt, spec in args.anchors:
|
||||||
if os.path.isfile(spec):
|
if os.path.isfile(spec):
|
||||||
data = open(spec).read()
|
with open(spec) as f:
|
||||||
|
data = f.read()
|
||||||
spec = data
|
spec = data
|
||||||
try:
|
try:
|
||||||
arex = re.compile(patt)
|
arex = re.compile(patt)
|
||||||
|
@ -391,7 +391,7 @@ class TestSNI(tservers.ServerTestBase):
|
|||||||
class TestServerCipherList(tservers.ServerTestBase):
|
class TestServerCipherList(tservers.ServerTestBase):
|
||||||
handler = ClientCipherListHandler
|
handler = ClientCipherListHandler
|
||||||
ssl = dict(
|
ssl = dict(
|
||||||
cipher_list=b'AES256-GCM-SHA384'
|
cipher_list='AES256-GCM-SHA384'
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_echo(self):
|
def test_echo(self):
|
||||||
|
@ -14,16 +14,14 @@ def test_randomgenerator():
|
|||||||
|
|
||||||
def test_filegenerator(tmpdir):
|
def test_filegenerator(tmpdir):
|
||||||
f = tmpdir.join("foo")
|
f = tmpdir.join("foo")
|
||||||
f.write(b"x" * 10000)
|
f.write(b"abcdefghijklmnopqrstuvwxyz" * 1000)
|
||||||
g = generators.FileGenerator(str(f))
|
g = generators.FileGenerator(str(f))
|
||||||
assert len(g) == 10000
|
assert len(g) == 26000
|
||||||
assert g[0] == b"x"
|
assert g[0] == b"a"
|
||||||
assert g[-1] == b"x"
|
assert g[2:7] == b"cdefg"
|
||||||
assert g[0:5] == b"xxxxx"
|
|
||||||
assert len(g[1:10]) == 9
|
assert len(g[1:10]) == 9
|
||||||
assert len(g[10000:10001]) == 0
|
assert len(g[26000:26001]) == 0
|
||||||
assert repr(g)
|
assert repr(g)
|
||||||
g.close()
|
|
||||||
|
|
||||||
|
|
||||||
def test_transform_generator():
|
def test_transform_generator():
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
import logging
|
import os
|
||||||
import requests
|
import requests
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pathod import test
|
from pathod import test
|
||||||
|
from pathod.pathod import SSLOptions, CA_CERT_NAME
|
||||||
from mitmproxy.test import tutils
|
|
||||||
|
|
||||||
import requests.packages.urllib3
|
|
||||||
|
|
||||||
requests.packages.urllib3.disable_warnings()
|
|
||||||
logging.disable(logging.CRITICAL)
|
|
||||||
|
|
||||||
|
|
||||||
class TestDaemonManual:
|
class TestDaemonManual:
|
||||||
@ -22,29 +16,17 @@ class TestDaemonManual:
|
|||||||
with pytest.raises(requests.ConnectionError):
|
with pytest.raises(requests.ConnectionError):
|
||||||
requests.get("http://localhost:%s/p/202:da" % d.port)
|
requests.get("http://localhost:%s/p/202:da" % d.port)
|
||||||
|
|
||||||
def test_startstop_ssl(self):
|
@pytest.mark.parametrize('not_after_connect', [True, False])
|
||||||
d = test.Daemon(ssl=True)
|
def test_startstop_ssl(self, not_after_connect):
|
||||||
rsp = requests.get(
|
ssloptions = SSLOptions(
|
||||||
"https://localhost:%s/p/202:da" %
|
cn=b'localhost',
|
||||||
d.port,
|
sans=[b'localhost', b'127.0.0.1'],
|
||||||
verify=False)
|
not_after_connect=not_after_connect,
|
||||||
assert rsp.ok
|
|
||||||
assert rsp.status_code == 202
|
|
||||||
d.shutdown()
|
|
||||||
with pytest.raises(requests.ConnectionError):
|
|
||||||
requests.get("http://localhost:%s/p/202:da" % d.port)
|
|
||||||
|
|
||||||
def test_startstop_ssl_explicit(self):
|
|
||||||
ssloptions = dict(
|
|
||||||
certfile=tutils.test_data.path("pathod/data/testkey.pem"),
|
|
||||||
cacert=tutils.test_data.path("pathod/data/testkey.pem"),
|
|
||||||
ssl_after_connect=False
|
|
||||||
)
|
)
|
||||||
d = test.Daemon(ssl=ssloptions)
|
d = test.Daemon(ssl=True, ssloptions=ssloptions)
|
||||||
rsp = requests.get(
|
rsp = requests.get(
|
||||||
"https://localhost:%s/p/202:da" %
|
"https://localhost:%s/p/202:da" % d.port,
|
||||||
d.port,
|
verify=os.path.expanduser(os.path.join(d.thread.server.ssloptions.confdir, CA_CERT_NAME)))
|
||||||
verify=False)
|
|
||||||
assert rsp.ok
|
assert rsp.ok
|
||||||
assert rsp.status_code == 202
|
assert rsp.status_code == 202
|
||||||
d.shutdown()
|
d.shutdown()
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
@ -13,6 +14,7 @@ from pathod import language
|
|||||||
from pathod import pathoc
|
from pathod import pathoc
|
||||||
from pathod import pathod
|
from pathod import pathod
|
||||||
from pathod import test
|
from pathod import test
|
||||||
|
from pathod.pathod import CA_CERT_NAME
|
||||||
|
|
||||||
|
|
||||||
def treader(bytes):
|
def treader(bytes):
|
||||||
@ -72,7 +74,7 @@ class DaemonTests:
|
|||||||
self.d.port,
|
self.d.port,
|
||||||
path
|
path
|
||||||
),
|
),
|
||||||
verify=False,
|
verify=os.path.join(self.d.thread.server.ssloptions.confdir, CA_CERT_NAME),
|
||||||
params=params
|
params=params
|
||||||
)
|
)
|
||||||
return resp
|
return resp
|
||||||
|
Loading…
Reference in New Issue
Block a user