Commit 1b442b8e authored by Ad Schellevis's avatar Ad Schellevis

(proxy, remote acl's) add option to disable cert validation, closes...

(proxy, remote acl's) add option to disable cert validation, closes https://github.com/opnsense/core/issues/1271
parent 9bc6342f
...@@ -38,6 +38,12 @@ ...@@ -38,6 +38,12 @@
<nbDropdownElements>300</nbDropdownElements> <nbDropdownElements>300</nbDropdownElements>
<help><![CDATA[select categories to use, leave empty for all. Categories are visible after initial download.]]></help> <help><![CDATA[select categories to use, leave empty for all. Categories are visible after initial download.]]></help>
</field> </field>
<field>
<id>blacklist.sslNoVerify</id>
<label>ssl ignore cert</label>
<type>checkbox</type>
<help>Ignore SSL certificate validation (for self-signed certificates)</help>
</field>
<field> <field>
<id>blacklist.description</id> <id>blacklist.description</id>
<label>Description</label> <label>Description</label>
......
...@@ -330,6 +330,10 @@ ...@@ -330,6 +330,10 @@
<SelectAll>Y</SelectAll> <SelectAll>Y</SelectAll>
<Multiple>Y</Multiple> <Multiple>Y</Multiple>
</filter> </filter>
<sslNoVerify type="BooleanField">
<default>0</default>
<Required>Y</Required>
</sslNoVerify>
<description type="TextField"> <description type="TextField">
<Required>Y</Required> <Required>Y</Required>
<mask>/^([\t\n\v\f\r 0-9a-zA-Z.,_\x{00A0}-\x{FFFF}]){1,255}$/u</mask> <mask>/^([\t\n\v\f\r 0-9a-zA-Z.,_\x{00A0}-\x{FFFF}]){1,255}$/u</mask>
......
...@@ -50,7 +50,7 @@ class Downloader(object): ...@@ -50,7 +50,7 @@ class Downloader(object):
""" Download helper """ Download helper
""" """
def __init__(self, url,username, password, timeout): def __init__(self, url,username, password, timeout, ssl_no_verify=False):
""" init new """ init new
:param url: source url :param url: source url
:param timeout: timeout in seconds :param timeout: timeout in seconds
...@@ -60,6 +60,7 @@ class Downloader(object): ...@@ -60,6 +60,7 @@ class Downloader(object):
self._source_handle = None self._source_handle = None
self._username = username self._username = username
self._password = password self._password = password
self._ssl_no_verify = ssl_no_verify
def fetch(self): def fetch(self):
""" fetch (raw) source data into tempfile using self._source_handle """ fetch (raw) source data into tempfile using self._source_handle
...@@ -67,11 +68,16 @@ class Downloader(object): ...@@ -67,11 +68,16 @@ class Downloader(object):
self._source_handle = None self._source_handle = None
if self._url.lower().startswith('http://') or self._url.lower().startswith('https://'): if self._url.lower().startswith('http://') or self._url.lower().startswith('https://'):
# HTTP(S) download # HTTP(S) download
req_opts = dict()
req_opts['url'] = self._url
req_opts['stream'] = True
req_opts['timeout'] = self._timeout
if self._ssl_no_verify:
req_opts['verify'] = False
if self._username is not None: if self._username is not None:
req = requests.get(url=self._url, stream=True, timeout=self._timeout, req_opts['auth'] = (self._username, self._password)
auth=(self._username, self._password))
else: req = requests.get(**req_opts)
req = requests.get(url=self._url, stream=True, timeout=self._timeout)
if req.status_code == 200: if req.status_code == 200:
self._source_handle = tempfile.NamedTemporaryFile() self._source_handle = tempfile.NamedTemporaryFile()
shutil.copyfileobj(req.raw, self._source_handle) shutil.copyfileobj(req.raw, self._source_handle)
...@@ -301,7 +307,11 @@ def main(): ...@@ -301,7 +307,11 @@ def main():
else: else:
download_username = None download_username = None
download_password = None download_password = None
acl = Downloader(download_url, download_username, download_password, acl_max_timeout) if cnf.has_option(section, 'sslNoVerify') and cnf.get(section, 'sslNoVerify') == '1':
sslNoVerify = True
else:
sslNoVerify = False
acl = Downloader(download_url, download_username, download_password, acl_max_timeout, sslNoVerify)
all_filenames = list() all_filenames = list()
for filename, basefilename, file_ext, line in acl.download(): for filename, basefilename, file_ext, line in acl.download():
if filename_in_ignorelist(basefilename, file_ext): if filename_in_ignorelist(basefilename, file_ext):
......
...@@ -11,5 +11,6 @@ filter:{{blacklist.filter|default('')}} ...@@ -11,5 +11,6 @@ filter:{{blacklist.filter|default('')}}
username={{blacklist.username}} username={{blacklist.username}}
password={{blacklist.password|default('')}} password={{blacklist.password|default('')}}
{% endif %} {% endif %}
sslNoVerify={{blacklist.sslNoVerify|default('0')}}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment