Skip to content

Commit

Permalink
Fixes #164: added check for string before os.path.isfile()
Browse files Browse the repository at this point in the history
  • Loading branch information
3c7 committed Jan 9, 2018
1 parent 1cda7ea commit 2be3a87
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
25 changes: 23 additions & 2 deletions analyzers/MISP/mispclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
import os


class EmptySearchtermError(Exception):
class MISPClientError(Exception):
"""Basic Error class"""
pass


class EmptySearchtermError(MISPClientError):
"""Exception raised, when no search terms are given."""
pass


class CertificateNotFoundError(MISPClientError):
"""Raised if certificate file could not be found"""
pass


class MISPClient:
"""The MISPClient class just hides the "complexity" of the queries. All params can be lists to query more than one
MISP instance.
Expand All @@ -27,14 +37,25 @@ def __init__(self, url, key, ssl=True, name='Unnamed'):
if type(url) is list:
for idx, server in enumerate(url):
verify = True

# Given ssl parameter is a list
if isinstance(ssl, list):
if os.path.isfile(ssl[idx]):
if isinstance(ssl[idx], str) and os.path.isfile(ssl[idx]):
verify = ssl[idx]
elif isinstance(ssl[idx], str) and not os.path.isfile(ssl[idx]):
raise CertificateNotFoundError('Certificate not found under {}.'.format(ssl[idx]))
elif isinstance(ssl[idx], bool):
verify = ssl[idx]
else:
raise TypeError('SSL parameter is a not expected type.')
# Do the same checks again, for the non-list type
elif isinstance(ssl, str):
if os.path.isfile(ssl):
verify = ssl
elif isinstance(ssl, bool):
verify = ssl
else:
raise TypeError('SSL parameter is a not expected type.')
self.misp_connections.append(pymisp.PyMISP(url=server,
key=key[idx],
ssl=verify))
Expand Down
1 change: 1 addition & 0 deletions analyzers/MISP/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cortexutils
pymisp
future; python_version <= '2.7'

3 comments on commit 2be3a87

@dafal
Copy link
Contributor

@dafal dafal commented on 2be3a87 Jan 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit generates an issus when running
pip install $(sort -u */requirements.txt)

Invalid requirement: '<=' Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 82, in __init__ req = Requirement(req) File "/usr/share/python-wheels/packaging-16.8-py2.py3-none-any.whl/packaging/requirements.py", line 94, in __init__ requirement_string[e.loc:e.loc + 8])) InvalidRequirement: Invalid requirement, parse error at "'<='"

@3c7
Copy link
Contributor Author

@3c7 3c7 commented on 2be3a87 Jan 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use

for requirement in $(ls -1 analyzers/*/requirements.txt); do
  pip install -r ${requirement}
done

as python version dependend requirements can only be used with the requirements-file parameter (pip install -r). Will update the docs.

@3c7
Copy link
Contributor Author

@3c7 3c7 commented on 2be3a87 Feb 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a mistake formatting the requirements file. @jeromeleonard pushed a hotfix, the installation should now work as documented. Sorry for that. :)

Please sign in to comment.