diff --git a/pymisp/api.py b/pymisp/api.py index f12b668..f10485f 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -368,6 +368,19 @@ class PyMISP(object): return self._check_response(response) + def _valid_uuid(self,uuid): + """ + Test valid uuid générate by CakePhp + + CakeText::uuid follow RFC 4122 + - the third group must start with a 4, + - the fourth group must start with 8, 9, a or b. + + :param uuid: A UUID to validate + """ + regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I) + match = regex.match(uuid) + return bool(match) # ##### File attributes ##### def _send_attributes(self, event, attributes, proposal=False): @@ -732,7 +745,7 @@ class PyMISP(object): def search(self, values=None, not_values=None, type_attribute=None, category=None, org=None, tags=None, not_tags=None, date_from=None, - date_to=None, last=None): + date_to=None, last=None, uuid=None): """ Search via the Rest API @@ -746,6 +759,7 @@ class PyMISP(object): :param date_from: First date :param date_to: Last date :param last: Last updated events (for example 5d or 12h or 30m) + :param uuid: A uuid valideted """ val = self.__prepare_rest_search(values, not_values).replace('/', '|') @@ -773,6 +787,11 @@ class PyMISP(object): query['to'] = date_to if last is not None: query['last'] = last + if uuid is not None: + if self._valid_uuid(uuid): + query['uuid'] = uuid + else: + return {'error': 'You must enter a valid uuid.'} session = self.__prepare_session('json') return self.__query(session, 'restSearch/download', query)