mitmproxy/netlib/version_check.py

45 lines
1.4 KiB
Python
Raw Normal View History

2015-08-03 16:06:31 +00:00
"""
Having installed a wrong version of pyOpenSSL or netlib is unfortunately a
very common source of error. Check before every start that both versions
are somewhat okay.
"""
2015-09-10 10:32:38 +00:00
from __future__ import division, absolute_import, print_function
import sys
import inspect
import os.path
2015-09-10 10:32:38 +00:00
import OpenSSL
PYOPENSSL_MIN_VERSION = (0, 15)
2015-08-03 16:06:31 +00:00
def check_pyopenssl_version(min_version=PYOPENSSL_MIN_VERSION, fp=sys.stderr):
min_version_str = u".".join(str(x) for x in min_version)
2015-09-10 10:32:38 +00:00
try:
v = tuple(int(x) for x in OpenSSL.__version__.split(".")[:2])
except ValueError:
print(
2015-09-15 17:12:15 +00:00
u"Cannot parse pyOpenSSL version: {}"
u"mitmproxy requires pyOpenSSL {} or greater.".format(
2015-09-10 10:32:38 +00:00
OpenSSL.__version__, min_version_str
),
file=fp
)
return
2015-08-03 16:06:31 +00:00
if v < min_version:
print(
2015-09-15 17:12:15 +00:00
u"You are using an outdated version of pyOpenSSL: "
u"mitmproxy requires pyOpenSSL {} or greater.".format(min_version_str),
file=fp
)
# Some users apparently have multiple versions of pyOpenSSL installed.
# Report which one we got.
pyopenssl_path = os.path.dirname(inspect.getfile(OpenSSL))
print(
2015-09-15 17:12:15 +00:00
u"Your pyOpenSSL {} installation is located at {}".format(
OpenSSL.__version__, pyopenssl_path
),
file=fp
)
sys.exit(1)