diff --git a/pymisp/tools/reportlab_generator.py b/pymisp/tools/reportlab_generator.py index dd4e0d8..b84f3ac 100644 --- a/pymisp/tools/reportlab_generator.py +++ b/pymisp/tools/reportlab_generator.py @@ -6,8 +6,15 @@ import base64 import logging import pprint from io import BytesIO -import pymisp -from html import escape +from functools import partial + +import sys + +if sys.version_info.major >= 3: + from html import escape +else: + print( + "ExportPDF running with Python < 3 : stability and output not guaranteed. Please run exportPDF with at least Python3") logger = logging.getLogger('pymisp') @@ -31,9 +38,20 @@ except ImportError: ######################################################################## +def create_flowable_tag(misp_tag): + ''' + Returns a Flowable tag linked to one tag. + :param misp_tag: A misp tag of a misp event or a misp event's attribute + :return: one flowable representing a tag (with style) + ''' + col1_style, col2_style = get_table_styles() + + return [Flowable_Tag(text=misp_tag.name, color=misp_tag.colour, custom_style=col1_style)] + + class Flowable_Tag(Flowable): """ - Custom flowable to handle tags + Custom flowable to handle tags. Draw one Tag with the webview formatting Modified from : http://two.pairlist.net/pipermail/reportlab-users/2005-February/003695.html and : http://www.blog.pythonlibrary.org/2014/03/10/reportlab-how-to-create-custom-flowables/ """ @@ -74,16 +92,18 @@ class Flowable_Tag(Flowable): brightness = r * 299 + g * 587 + b * 114 / 1000 if brightness < 500: # Standard treeshold for human vision : 123 instead of 500 - return "#ffffff" # Black + text_color = "#ffffff" # Black else: - return "#000000" # White + text_color = "#000000" # White + + return text_color # ---------------------------------------------------------------------- def draw(self): - """ + ''' Draw the shape, text, etc to show a Tag Honestely, constant are totally ad-hoc. Feels free to change it, but be sure to test the visual result of it. - """ + ''' RADIUS = 1 * mm LEFT_INTERNAL_PADDING = 2 ELONGATION = LEFT_INTERNAL_PADDING * 2 @@ -102,6 +122,9 @@ class Flowable_Tag(Flowable): p.drawOn(self.canv, *self.coord(self.x, self.y + 0.5 * LEFT_INTERNAL_PADDING, mm)) +# Copy of pdfexport.py moduleconfig +moduleconfig = ["MISP_base_url_for_dynamic_link", "MISP_name_for_metadata"] + # == Row colors of the table (alternating) == EVEN_COLOR = colors.whitesmoke ODD_COLOR = colors.lightgrey @@ -132,15 +155,20 @@ PAGESIZE = (140 * mm, 216 * mm) # width, height BASE_MARGIN = 5 * mm # Create a list here to specify each row separately # == Parameters for error handling for content too long to fit on a page == -FRAME_MAX_HEIGHT = 500 # 650 # Ad hoc value for a A4 page +FRAME_MAX_HEIGHT = 500 # 650 # Ad hoc value for a A4 page FRAME_MAX_WIDTH = 356 STR_TOO_LONG_WARNING = "
[Too long to fit on a single page. Cropped]" +# == Parameters for links management == +LINK_TYPE = "link" # Name of the type that define 'good' links +URL_TYPE = "url" # Name of the type that define 'bad' links +WARNING_MESSAGE_URL = "'https://Please_consider_that_this_may_be_a_harmful_link'" +GOOD_LINK_COLOR = 'blue' +BAD_LINK_COLOR = 'red' -''' -"UTILITIES" METHODS. Not meant to be used except for development purposes -''' +######################################################################## +# "UTILITIES" METHODS. Not meant to be used except for development purposes def get_sample_fonts(): ''' @@ -168,10 +196,7 @@ def get_sample_styles(): sample_style_sheet.list() -''' -"INTERNAL" METHODS. Not meant to be used outside of this class. -''' - +# "INTERNAL" METHODS. Not meant to be used outside of this class. def alternate_colors_style_generator(data): ''' @@ -234,348 +259,6 @@ def general_style_generator(): return lines_list -def get_published_value(misp_event, item, col2_style): - ''' - Returns a flowable paragraph to add to the pdf given the misp_event published/published_time - More information on how to play with paragraph into reportlab cells : - https://stackoverflow.com/questions/11810008/reportlab-add-two-paragraphs-into-one-table-cell - :param misp_event: A misp event with or without "published"/"publish_timestamp" attributes - :param item: a list of name, in order : - ["Name to be print in the pdf", "json property access name", - " Name to be display if no values found in the misp_event", json property access name (for timestamp")] - e.g. item = ["Published", 'published', "None", "publish_timestamp"] - :param col2_style: style to be applied on the returned paragraph - :return: a Paragraph to add in the pdf, regarding the values of "published"/"publish_timestamp" - ''' - - RED_COLOR = '#ff0000' - GREEN_COLOR = '#008000' - YES_ANSWER = " Yes (" - NO_ANSWER = "No" - - # Formatting similar to MISP Event web view - if hasattr(misp_event, item[1]): - if getattr(misp_event, item[1]): # == True - if hasattr(misp_event, item[3]): - # Published and have published date - return Paragraph(YES_ANSWER + getattr(misp_event, item[3]).strftime(EXPORT_DATE_FORMAT) + ")", - col2_style) - else: - # Published without published date - return YES_ANSWER + "no date)" - else: - # Not published - return NO_ANSWER - else: - # Does not have a published attribute - return item[2] - - -def get_timestamp_value(misp_event, item, col2_style): - ''' - Returns a flowable paragraph to add to the pdf given the misp_event timestamp - :param misp_event: A misp event with or without "timestamp" attributes - :param item: a list of name, in order : - ["Name to be print in the pdf", "json property access name", - " Name to be display if no values found in the misp_event"] - :param col2_style: style to be applied on the returned paragraph - :return: a Paragraph to add in the pdf, regarding the values of "timestamp" - ''' - if hasattr(misp_event, item[1]): - return Paragraph(str(getattr(misp_event, item[1]).strftime(EXPORT_DATE_FORMAT)), col2_style) - else: - return Paragraph(item[2], col2_style) - - -def get_creator_organisation_value(misp_event, item, col2_style): - ''' - Returns a flowable paragraph to add to the pdf given the misp_event creator organisation - :param misp_event: A misp event with or without "timestamp" attributes - :param item: a list of name, in order : - ["Name to be print in the pdf", "json property access name", - " Name to be display if no values found in the misp_event", "json property access name (second level)"] - :param col2_style: style to be applied on the returned paragraph - :return: a Paragraph to add in the pdf, regarding the values of "creator organisation" - ''' - if hasattr(misp_event, item[1]): - return Paragraph(escape(str(getattr(getattr(misp_event, item[1]), item[3]))), col2_style) - else: - return Paragraph(item[2], col2_style) - - -def get_attributes_number_value(misp_event, item, col2_style): - ''' - Returns a flowable paragraph to add to the pdf given the misp_event attributes - :param misp_event: A misp event with or without "attributes" attributes - :param item: a list of name, in order : - ["Name to be print in the pdf", "json property access name", - " Name to be display if no values found in the misp_event"] - :param col2_style: style to be applied on the returned paragraph - :return: a Paragraph to add in the pdf, regarding the values of "attributes" - ''' - if hasattr(misp_event, item[1]): - return Paragraph(str(len(getattr(misp_event, item[1]))), col2_style) - else: - return Paragraph(item[2], col2_style) - - -def get_tag_value(misp_event, item, col2_style): - ''' - Returns a flowable paragraph to add to the pdf given the misp_event tags - :param misp_event: A misp event with or without "tags" attributes - :param item: a list of name, in order : - ["Name to be print in the pdf", "json property access name", - " Name to be display if no values found in the misp_event"] - :param col2_style: style to be applied on the returned paragraph - :return: a Paragraph to add in the pdf, regarding the values of "tags" - ''' - if hasattr(misp_event, item[1]): - table_event_tags = create_flowable_table_from_tags(misp_event) - return table_event_tags - else: - return Paragraph(item[2], col2_style) - -def get_unoverflowable_paragraph(dirty_string, curr_style) : - ''' - Create a paragraph that can fit on a cell of one page. Mostly hardcoded values. - This method can be improved (get the exact size of the current frame, and limit the paragraph to this size.) - This might be worst look at KeepInFrame (which hasn't went well so far) - :param dirty_string: - :param curr_style: - :return: - ''' - sanitized_str = str(escape(dirty_string)) - - # Get the space that the paragraph needs to be printed - w, h = Paragraph(sanitized_str, curr_style).wrap(FRAME_MAX_WIDTH, FRAME_MAX_HEIGHT) - - # If there is enough space, directly send back the sanitized paragraph - if w <= FRAME_MAX_WIDTH and h <= FRAME_MAX_HEIGHT : - return Paragraph(sanitized_str, curr_style) - else : - # Otherwise, cut the content to fit the paragraph (Dichotomy) - max_carac_amount = int((FRAME_MAX_HEIGHT/(h*1.0))*len(sanitized_str)) - - i = 0 - MAX_ITERATION = 10 - limited_string = "" - while (w > FRAME_MAX_WIDTH or h > FRAME_MAX_HEIGHT) and i" + safe_string(getattr(misp_event, item[1])) + "" + + if color: + # They want fancy colors + html_url = "" + html_url + "" + + # Construct final paragraph + answer = get_unoverflowable_paragraph(html_url, col2_style, False) + + else: + # We can't build links + answer = get_unoverflowable_paragraph(getattr(misp_event, item[1]), col2_style) + + else: + # No it doesn't, so we directly give the default answer + answer = Paragraph(item[2], col2_style) + + return answer + + +def get_timestamp_value(misp_event, item, col2_style): + ''' + Returns a flowable paragraph to add to the pdf given the misp_event timestamp + :param misp_event: A misp event with or without "timestamp" attributes + :param item: a list of name, in order : + ["Name to be print in the pdf", "json property access name", + " Name to be display if no values found in the misp_event"] + :param col2_style: style to be applied on the returned paragraph + :return: a Paragraph to add in the pdf, regarding the values of "timestamp" + ''' + if hasattr(misp_event, item[1]): + return Paragraph(str(getattr(misp_event, item[1]).strftime(EXPORT_DATE_FORMAT)), col2_style) + return Paragraph(item[2], col2_style) + + +def get_creator_organisation_value(misp_event, item, col2_style): + ''' + Returns a flowable paragraph to add to the pdf given the misp_event creator organisation + :param misp_event: A misp event with or without "timestamp" attributes + :param item: a list of name, in order : + ["Name to be print in the pdf", "json property access name", + " Name to be display if no values found in the misp_event", "json property access name (second level)"] + :param col2_style: style to be applied on the returned paragraph + :return: a Paragraph to add in the pdf, regarding the values of "creator organisation" + ''' + if hasattr(misp_event, item[1]): + return Paragraph(safe_string(getattr(getattr(misp_event, item[1]), item[3])), col2_style) + return Paragraph(item[2], col2_style) + + +def get_attributes_number_value(misp_event, item, col2_style): + ''' + Returns a flowable paragraph to add to the pdf given the misp_event attributes + :param misp_event: A misp event with or without "attributes" attributes + :param item: a list of name, in order : + ["Name to be print in the pdf", "json property access name", + " Name to be display if no values found in the misp_event"] + :param col2_style: style to be applied on the returned paragraph + :return: a Paragraph to add in the pdf, regarding the values of "attributes" + ''' + if hasattr(misp_event, item[1]): + return Paragraph(str(len(getattr(misp_event, item[1]))), col2_style) + return Paragraph(item[2], col2_style) + + +def get_tag_value(misp_event, item, col2_style): + ''' + Returns a flowable paragraph to add to the pdf given the misp_event tags + :param misp_event: A misp event with or without "tags" attributes + :param item: a list of name, in order : + ["Name to be print in the pdf", "json property access name", + " Name to be display if no values found in the misp_event"] + :param col2_style: style to be applied on the returned paragraph + :return: a Paragraph to add in the pdf, regarding the values of "tags" + ''' + if hasattr(misp_event, item[1]): + table_event_tags = create_flowable_table_from_tags(misp_event) + return table_event_tags + return Paragraph(item[2], col2_style) + + +def get_published_value(misp_event, item, col2_style): + ''' + Returns a flowable paragraph to add to the pdf given the misp_event published/published_time + More information on how to play with paragraph into reportlab cells : + https://stackoverflow.com/questions/11810008/reportlab-add-two-paragraphs-into-one-table-cell + :param misp_event: A misp event with or without "published"/"publish_timestamp" attributes + :param item: a list of name, in order : + ["Name to be print in the pdf", "json property access name", + " Name to be display if no values found in the misp_event", json property access name (for timestamp")] + e.g. item = ["Published", 'published', "None", "publish_timestamp"] + :param col2_style: style to be applied on the returned paragraph + :return: a Paragraph to add in the pdf, regarding the values of "published"/"publish_timestamp" + ''' + + RED_COLOR = '#ff0000' + GREEN_COLOR = '#008000' + YES_ANSWER = " Yes (" + NO_ANSWER = "No" + + answer = "" + + # Formatting similar to MISP Event web view + if hasattr(misp_event, item[1]): + if getattr(misp_event, item[1]): # == True + if hasattr(misp_event, item[3]): + # Published and have published date + answer = Paragraph(YES_ANSWER + getattr(misp_event, item[3]).strftime(EXPORT_DATE_FORMAT) + ")", + col2_style) + else: + # Published without published date + answer = YES_ANSWER + "no date)" + else: + # Not published + answer = NO_ANSWER + else: + # Does not have a published attribute + answer = item[2] + + return answer + + +def is_safe_attribute(curr_object, attribute_name): + return hasattr(curr_object, attribute_name) and getattr(curr_object, attribute_name) is not None and getattr( + curr_object, attribute_name) != "" + + +def create_flowable_table_from_one_attribute(misp_attribute): + ''' + Returns a table (flowalbe) representing the attribute + :param misp_attribute: A misp attribute + :return: a table representing this misp's attribute's attributes, to add to the pdf as a flowable + ''' + data = [] + col1_style, col2_style = get_table_styles() + + # To reduce code size, and automate it a bit, triplet (Displayed Name, object_attribute_name, + # to_display_if_not_present) are store in the following list + list_attr_automated = [["UUID", 'uuid', "None"], + ["Category", 'category', "None"], + ["Comment", 'comment', "None"], + ["Type", 'type', "None"], + ["Value", 'value', "None"]] + + # Handle the special case of links + STANDARD_TYPE = True + if hasattr(misp_attribute, 'type') and ( + getattr(misp_attribute, 'type') == LINK_TYPE or getattr(misp_attribute, 'type') == URL_TYPE): + # Special case for links + STANDARD_TYPE = False + + # Automated adding of standard (python) attributes of the misp event + for item in list_attr_automated: + if is_safe_attribute(misp_attribute, item[1]) and (STANDARD_TYPE or item[1] != 'value'): + # The attribute exists, we fetch it and create the row + data.append([Paragraph(item[0], col1_style), + get_unoverflowable_paragraph(getattr(misp_attribute, item[1]), col2_style)]) + + # The attribute does not exist, you may want to print a default text on the row. Then use as a else case : + # data.append([Paragraph(item[0], col1_style), Paragraph(item[2], col2_style)]) + + # Handle Special case for links (Value) + if not STANDARD_TYPE: + item = ["Value", 'value', "None"] + + if is_safe_attribute(misp_attribute, item[1]): + if getattr(misp_attribute, 'type') == LINK_TYPE: + data.append([Paragraph(item[0], col1_style), get_unoverflowable_paragraph( + "" + getattr( + misp_attribute, item[1]) + "", col2_style, False)]) + elif getattr(misp_attribute, 'type') == URL_TYPE: + data.append([Paragraph(item[0], col1_style), get_unoverflowable_paragraph( + "" + getattr(misp_attribute, + item[ + 1]) + "", + col2_style, False)]) + + # Tags + item = ["Tags", 'Tag', "None"] + if hasattr(misp_attribute, item[1]): + data.append([Paragraph(item[0], col1_style), get_tag_value(misp_attribute, item, col2_style)]) + + return create_flowable_table_from_data(data) + + +def create_tags_table_from_data(data): + ''' + Given a list of flowables tags (2D/list of list), creates a Table with styles adapted to tags. + :param data: list of list of tags (flowables) + :return: a Table - with styles - to add to another table + ''' + + # Create the table + curr_table = Table(data, COL_WIDTHS, rowHeights=ROW_HEIGHT_FOR_TAGS) + + # Create styles and set parameters + general_style = general_style_generator() + + # Make the table nicer + curr_table.setStyle(TableStyle(general_style)) + + return curr_table + + +######################################################################## +# General attribut formater + +def safe_string(bad_str): + return escape(str(bad_str)) + + +def get_unoverflowable_paragraph(dirty_string, curr_style, do_escape_string=True): + ''' + Create a paragraph that can fit on a cell of one page. Mostly hardcoded values. + This method can be improved (get the exact size of the current frame, and limit the paragraph to this size.) + This might be worst look at KeepInFrame (which hasn't went well so far) + :param do_escape_string: Activate the escaping (may be useful to add inline HTML, e.g. hyperlinks) + :param dirty_string: String to transform + :param curr_style: Style to apply to the returned paragraph + :return: + ''' + if do_escape_string: + sanitized_str = str(escape(str(dirty_string))) + else: + sanitized_str = dirty_string + + # Get the space that the paragraph needs to be printed + w, h = Paragraph(sanitized_str, curr_style).wrap(FRAME_MAX_WIDTH, FRAME_MAX_HEIGHT) + + # If there is enough space, directly send back the sanitized paragraph + if w <= FRAME_MAX_WIDTH and h <= FRAME_MAX_HEIGHT: + answer_paragraph = Paragraph(sanitized_str, curr_style) + else: + # Otherwise, cut the content to fit the paragraph (Dichotomy) + max_carac_amount = int((FRAME_MAX_HEIGHT / (h * 1.0)) * len(sanitized_str)) + + i = 0 + MAX_ITERATION = 10 + limited_string = "" + while (w > FRAME_MAX_WIDTH or h > FRAME_MAX_HEIGHT) and i < MAX_ITERATION: + i += 1 + limited_string = sanitized_str[:max_carac_amount] # .replace("\n", "").replace("\r", "") + w, h = Paragraph(limited_string + STR_TOO_LONG_WARNING, curr_style).wrap(FRAME_MAX_WIDTH, FRAME_MAX_HEIGHT) + max_carac_amount = int(max_carac_amount / 2) + + if w <= FRAME_MAX_WIDTH and h <= FRAME_MAX_HEIGHT: + answer_paragraph = Paragraph(limited_string + STR_TOO_LONG_WARNING, curr_style) + else: + # We may still end with a not short enough string + answer_paragraph = Paragraph(STR_TOO_LONG_WARNING, curr_style) + + return answer_paragraph + + +######################################################################## +# General Event's Attributes formater tools + +def uuid_to_url(baseurl, uuid): + ''' + Return an url constructed from the MISP baseurl and the uuid of the event, to go to this event on this MISP + :param baseurl: the baseurl of the MISP instnce e.g. http://localhost:8080 or http://localhost:8080/ + :param uuid: the uuid of the event that we want to have a link to + :return: the complete URL to go to this event on this MISP instance + ''' + if baseurl[len(baseurl) - 1] != "/": + baseurl += "/" + return baseurl + "events/view/" + uuid + + +def create_flowable_table_from_data(data): + ''' + Given a list of flowables items (2D/list of list), creates a Table with styles. + :param data: list of list of items (flowables is better) + :return: a Table - with styles - to add to the pdf + ''' + # Create the table + curr_table = Table(data, COL_WIDTHS) + + # Aside notes : + # colWidths='*' does a 100% and share the space automatically + # rowHeights=ROW_HEIGHT if you want a fixed height. /!\ Problems with paragraphs that are spreading everywhere + + # Create styles and set parameters + alternate_colors_style = alternate_colors_style_generator(data) + lines_style = lines_style_generator(data) + general_style = general_style_generator() + + # Make the table nicer + curr_table.setStyle(TableStyle(general_style + alternate_colors_style + lines_style)) + + return curr_table + + +######################################################################## +# General Event's Attributes formater + +def create_flowable_table_from_event(misp_event, config=None): + ''' + Returns Table presenting a MISP event + :param misp_event: A misp event (complete or not) + :return: a table that can be added to a pdf + ''' + + # To reduce code size, and automate it a bit, triplet (Displayed Name, object_attribute_name, + # to_display_if_not_present) are store in the following list + list_attr_automated = [ + # ["Event ID", 'id', "None"], + ["Date", 'date', "None"], + ["Owner org", 'owner', "None"], + ["Threat level", 'threat_level_id', "None"], # TODO : improve design + ["Analysis", 'analysis', "None"], # TODO : improve design + Ask where the enum is ! + # TODO : Not present ["Email", 'email', "None"], + # TODO : ["Distribution", 'distribution', "None"], + # TODO : ["First recorded change", 'TODO', "None"], + # TODO : ["Last change", 'TODO', "None"], + # TODO : ["Modification map", 'TODO', "None"], + # TODO : ["Sightings", 'TODO', "None"] + ] + + data = [] + col1_style, col2_style = get_table_styles() + + # Manual addition + # UUID + item = ["UUID", 'uuid', "None"] + data.append([Paragraph(item[0], col1_style), get_value_link_to_event(misp_event, item, col2_style, config)]) + + # Automated adding of standard (python) attributes of the misp event + # Note that PEP 0363 may change the syntax in future release : https://www.python.org/dev/peps/pep-0363/ + for item in list_attr_automated: + if hasattr(misp_event, item[1]): + # The attribute exist, we fetch it and create the row + data.append( + [Paragraph(item[0], col1_style), + get_unoverflowable_paragraph(getattr(misp_event, item[1]), col2_style)]) + else: + # The attribute does not exist ,we print a default text on the row + data.append([Paragraph(item[0], col1_style), Paragraph(item[2], col2_style)]) + + # Manual addition + # Info + item = ["Info", 'info', "None"] + data.append([Paragraph(item[0], col1_style), get_value_link_to_event(misp_event, item, col2_style, config)]) + + # Timestamp + item = ["Event date", 'timestamp', "None"] + data.append([Paragraph(item[0], col1_style), get_timestamp_value(misp_event, item, col2_style)]) + + # Published + item = ["Published", 'published', "None", "publish_timestamp"] + data.append([Paragraph(item[0], col1_style), get_published_value(misp_event, item, col2_style)]) + + # Creator organisation + item = ["Creator Org", 'Orgc', "None", "name"] + data.append([Paragraph(item[0], col1_style), get_creator_organisation_value(misp_event, item, col2_style)]) + + # Number of Attributes + item = ["# Attributes", 'Attribute', "None"] + data.append([Paragraph(item[0], col1_style), get_attributes_number_value(misp_event, item, col2_style)]) + + # Tags + item = ["Tags", 'Tag', "None"] + data.append([Paragraph(item[0], col1_style), get_tag_value(misp_event, item, col2_style)]) + + return create_flowable_table_from_data(data) + + +def create_flowable_table_from_attributes(misp_event): + ''' + Returns a list of flowables representing the list of attributes of a misp event. + The list is composed alternatively of headers and tables, to add to the pdf + :param misp_event: A misp event + :return: a table of flowables + ''' + + flowable_table = [] sample_style_sheet = getSampleStyleSheet() + i = 0 - set_metadata(misp_event) + if hasattr(misp_event, "Attribute"): + # There is some attributes for this object + for item in getattr(misp_event, "Attribute"): + # you can use a spacer instead of title to separate paragraph: flowable_table.append(Spacer(1, 5 * mm)) + flowable_table.append(Paragraph("Attribute #" + str(i), sample_style_sheet['Heading3'])) + flowable_table.append(create_flowable_table_from_one_attribute(item)) + i += 1 + else: + # No attributes for this object + flowable_table.append(Paragraph("No attributes", sample_style_sheet['Heading2'])) - # Create stuff - title = Paragraph(misp_event.info, sample_style_sheet['Heading1']) - subtitle = Paragraph("General information", sample_style_sheet['Heading2']) - attributes = Paragraph("Attributes", sample_style_sheet['Heading2']) - - table_event_general = create_flowable_table_from_event(misp_event) - table_event_attribute = create_flowable_table_from_attributes(misp_event) - - # If you want to output the full json, just add next line - # paragraph_2 = Paragraph(str(misp_event.to_json()), sample_style_sheet['Code']) - - # Add all parts to final PDF - flowables.append(title) - flowables.append(subtitle) - flowables.append(table_event_general) - - flowables.append(PageBreak()) - - flowables.append(attributes) - flowables += table_event_attribute - - return flowables + return flowable_table -def set_template(canvas, doc): +def create_flowable_table_from_tags(misp_event): + ''' + Returns a Table (flowable) to add to a pdf, representing the list of tags of an event or a misp event + :param misp_event: A misp event + :return: a table of flowable to add to the pdf + ''' + + flowable_table = [] + col1_style, col2_style = get_table_styles() + i = 0 + + if hasattr(misp_event, "Tag") and len(getattr(misp_event, "Tag")) > 1: # 'Tag' can exist and be empty + # There is some tags for this object + for item in getattr(misp_event, "Tag"): + flowable_table.append(create_flowable_tag(item)) + i += 1 + answer_tags = create_tags_table_from_data(flowable_table) + else: + # No tags for this object + answer_tags = [Paragraph("No tags", col2_style)] + + return answer_tags + + +######################################################################## +# Handling static parts drawn on the upper layer + +def set_template(canvas, doc, misp_event, config=None): add_page_number(canvas, doc) - add_metadata(canvas, doc) + add_metadata(canvas, doc, misp_event, config) + # TODO : add_header() + # TODO : add_footer() + + +def add_metadata(canvas, doc, misp_event, config=None): + ''' + Allow to add metadata to the pdf. Would need deeper digging to change other metadata. + :param canvas: / Automatically filled during pdf compilation + :param doc: / Automatically filled during pdf compilation + :param misp_event: To send trough "partial", to get information to complete metadaa + :return: / Automatically filled during pdf compilation + ''' -METADATA = {} -def set_metadata(misp_event: pymisp.MISPEvent): if hasattr(misp_event, 'info'): - METADATA["title"] = getattr(misp_event, 'info') + canvas.setTitle(getattr(misp_event, 'info')) + if hasattr(misp_event, 'info'): - METADATA["subject"] = getattr(misp_event, 'info') + canvas.setSubject(getattr(misp_event, 'info')) + if hasattr(misp_event, 'Orgc'): if hasattr(getattr(misp_event, 'Orgc'), 'name'): - METADATA["author"] = getattr(getattr(misp_event, 'Orgc'), 'name') - METADATA["creator"] = getattr(getattr(misp_event, 'Orgc'), 'name') - if hasattr(misp_event, 'uuid'): - METADATA["keywords"] = getattr(misp_event, 'uuid') + canvas.setAuthor(getattr(getattr(misp_event, 'Orgc'), 'name')) + + if config is not None and moduleconfig[1] in config: + canvas.setCreator(config[moduleconfig[1]]) + else: + canvas.setCreator(getattr(getattr(misp_event, 'Orgc'), 'name')) + + if hasattr(misp_event, 'uuid'): + canvas.setKeywords(getattr(misp_event, 'uuid')) -def add_metadata(canvas, doc): - # There should be a nicer way to do it : - # From : https://stackoverflow.com/questions/52358853/reportlab-metadata-creationdate-and-modificationdate - keys = METADATA.keys() - if 'title' in keys: - canvas.setTitle(METADATA["title"]) - if 'subject' in keys: - canvas.setSubject(METADATA["subject"]) - if 'author' in keys: - canvas.setAuthor(METADATA["author"]) - if 'creator' in keys: - canvas.setCreator(METADATA["creator"]) - if 'keywords' in keys: - canvas.setKeywords(METADATA["keywords"]) def add_page_number(canvas, doc): ''' - Add footer to each page, drawing the page number + Draw the page number on each page :param canvas: / Automatically filled during pdf compilation :param doc: / Automatically filled during pdf compilation :return: / Automatically filled during pdf compilation @@ -693,7 +787,45 @@ def add_page_number(canvas, doc): canvas.restoreState() -def export_flowables_to_pdf(document, pdf_buffer, flowables): +######################################################################## +# Main part of the script, handling the global formatting of the pdf + +def collect_parts(misp_event, config=None): + ''' + Main part of the PDF creation, it creates a ready-to-compile-as-pdf list of flowables from a MISP Event, calling subfunctions to handle the printing of each element + :param misp_event: a misp event + :return: a list of flowables to compile as pdf + ''' + # List of elements/content we want to add + flowables = [] + # Get the list of available styles + sample_style_sheet = getSampleStyleSheet() + + # Create stuff + title = get_value_link_to_event(misp_event, ["Info", 'info', "None"], sample_style_sheet['Heading1'], config, False) + subtitle = Paragraph("General information", sample_style_sheet['Heading2']) + attributes = Paragraph("Attributes", sample_style_sheet['Heading2']) + + table_event_general = create_flowable_table_from_event(misp_event, config) + table_event_attribute = create_flowable_table_from_attributes(misp_event) + + # If you want to output the full json (as debug), just add next line + # paragraph_2 = Paragraph(str(misp_event.to_json()), sample_style_sheet['Code']) + + # Add all parts to final PDF + flowables.append(title) + flowables.append(subtitle) + flowables.append(table_event_general) + + flowables.append(PageBreak()) + + flowables.append(attributes) + flowables += table_event_attribute + + return flowables + + +def export_flowables_to_pdf(document, misp_event, flowables, config=None): ''' Export function : creates a pdf from a list of flowables, adding page numbers, etc. :param document: A document template @@ -704,15 +836,16 @@ def export_flowables_to_pdf(document, pdf_buffer, flowables): document.build( flowables, - onFirstPage=set_template, # Pagination for first page - onLaterPages=set_template, # Pagination for all other page + # Partial used to set the metadata + onFirstPage=partial(set_template, misp_event=misp_event, config=config), # Pagination for first page + onLaterPages=partial(set_template, misp_event=misp_event, config=config), # Pagination for all other page ) -''' -"EXTERNAL" exposed METHODS. Meant to be used outside of this class. -''' -def convert_event_in_pdf_buffer(misp_event: pymisp.MISPEvent): +######################################################################## +# "EXTERNAL" exposed METHODS. Meant to be used outside of this class. + +def convert_event_in_pdf_buffer(misp_event, config=None): ''' Externally callable function that create a full pdf from a Misp Event :param misp_event: a misp event @@ -730,13 +863,13 @@ def convert_event_in_pdf_buffer(misp_event: pymisp.MISPEvent): bottomMargin=BASE_MARGIN) # Collect already accessible event's parts to be shown - flowables = collect_parts(misp_event) + flowables = collect_parts(misp_event, config) # Export - export_flowables_to_pdf(curr_document, pdf_buffer, flowables) + export_flowables_to_pdf(curr_document, misp_event, flowables, config) pdf_value = pdf_buffer.getvalue() - # TODO : Not sure what to give back ? Buffer ? Buffer.value() ? Base64(buffer.value()) ? ... + # Not sure what to give back ? Buffer ? Buffer.value() ? Base64(buffer.value()) ? ... So far only buffer.value() pdf_buffer.close() return pdf_value @@ -745,12 +878,15 @@ def convert_event_in_pdf_buffer(misp_event: pymisp.MISPEvent): def get_values_from_buffer(pdf_buffer): return pdf_buffer.value() + def get_base64_from_buffer(pdf_buffer): return base64.b64encode(pdf_buffer.value()) + def get_base64_from_value(pdf_value): return base64.b64encode(pdf_value) + def register_to_file(pdf_buffer, file_name): # Used for testing purposes only pdf_buffer.seek(0) @@ -758,6 +894,7 @@ def register_to_file(pdf_buffer, file_name): with open(file_name, 'wb') as f: f.write(pdf_buffer.read()) + def register_value_to_file(pdf_value, file_name): with open(file_name, 'wb') as f: f.write(pdf_value) diff --git a/tests/reportlab_testoutputs/basic_event.pdf b/tests/reportlab_testoutputs/basic_event.pdf deleted file mode 100644 index 18ec6ae..0000000 --- a/tests/reportlab_testoutputs/basic_event.pdf +++ /dev/null @@ -1,391 +0,0 @@ -%PDF-1.4 -%“Œ‹ž ReportLab Generated PDF document http://www.reportlab.com -1 0 obj -<< -/F1 2 0 R /F2 3 0 R /F3 4 0 R /F4 6 0 R ->> -endobj -2 0 obj -<< -/BaseFont /Helvetica /Encoding /WinAnsiEncoding /Name /F1 /Subtype /Type1 /Type /Font ->> -endobj -3 0 obj -<< -/BaseFont /Times-Roman /Encoding /WinAnsiEncoding /Name /F2 /Subtype /Type1 /Type /Font ->> -endobj -4 0 obj -<< -/BaseFont /Helvetica-Bold /Encoding /WinAnsiEncoding /Name /F3 /Subtype /Type1 /Type /Font ->> -endobj -5 0 obj -<< -/Contents 26 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -6 0 obj -<< -/BaseFont /Helvetica-BoldOblique /Encoding /WinAnsiEncoding /Name /F4 /Subtype /Type1 /Type /Font ->> -endobj -7 0 obj -<< -/Contents 27 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -8 0 obj -<< -/Contents 28 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -9 0 obj -<< -/Contents 29 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -10 0 obj -<< -/Contents 30 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -11 0 obj -<< -/Contents 31 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -12 0 obj -<< -/Contents 32 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -13 0 obj -<< -/Contents 33 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -14 0 obj -<< -/Contents 34 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -15 0 obj -<< -/Contents 35 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -16 0 obj -<< -/Contents 36 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -17 0 obj -<< -/Contents 37 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -18 0 obj -<< -/Contents 38 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -19 0 obj -<< -/Contents 39 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -20 0 obj -<< -/Contents 40 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -21 0 obj -<< -/Contents 41 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -22 0 obj -<< -/Contents 42 0 R /MediaBox [ 0 0 396.8504 612.2835 ] /Parent 25 0 R /Resources << -/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] ->> /Rotate 0 /Trans << - ->> - /Type /Page ->> -endobj -23 0 obj -<< -/PageMode /UseNone /Pages 25 0 R /Type /Catalog ->> -endobj -24 0 obj -<< -/Author (\(anonymous\)) /CreationDate (D:20190222095950-01'00') /Creator (\(unspecified\)) /Keywords () /ModDate (D:20190222095950-01'00') /Producer (ReportLab PDF Library - www.reportlab.com) - /Subject (\(unspecified\)) /Title (\(anonymous\)) /Trapped /False ->> -endobj -25 0 obj -<< -/Count 17 /Kids [ 5 0 R 7 0 R 8 0 R 9 0 R 10 0 R 11 0 R 12 0 R 13 0 R 14 0 R 15 0 R - 16 0 R 17 0 R 18 0 R 19 0 R 20 0 R 21 0 R 22 0 R ] /Type /Pages ->> -endobj -26 0 obj -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#?$q97XPN"j$hCBRYWq'-nskX8`HFlH9?DBLi[_@i6I,JNpqt"0X?3OZA5?XS?&grn*ZgqGUCrB%^JOiuKH?g9>h?<\SYSujFGlmHqlhMaRo^qEqg"de#e.>jYj3ED*CD#<7=d)0/R\G6__5rooL<-Q5M8MdCf?$FEIU:)XOq!QWg*CtApL22[ZSdfNiYiA,YdF2-p5g,mO^4)>)\P8`0>&5rg[$gEk-MOamJ*bjm'\ZVcW*=,jWu]O.-Je>@Sg?2-6)@eU-?r0:Xbr3J'7I[7jkj:hrtGpt%C>@pJDP\(eBi=raB;27Y1recQjSI8Ol0WK]NUfp##eGs^lC4OZI>!NqT5hM/6&4SOmg[feK]s!K44G%"'0,k,DoNK/jqKr5ML1*apf6W*YOSukBR#,JZdh`r-4/RoW__B`\46XsDUaG2cFKUS.Jd:ULZg9Q(@8)kERUJ1g;4RS`q:0UKLGTtlDeFKZTK7T9hpa@hMYgaA"rc$)O5Ll=n2endstream -endobj -xref -0 43 -0000000000 65535 f -0000000073 00000 n -0000000134 00000 n -0000000241 00000 n -0000000350 00000 n -0000000462 00000 n -0000000667 00000 n -0000000786 00000 n -0000000991 00000 n -0000001196 00000 n -0000001401 00000 n -0000001607 00000 n -0000001813 00000 n -0000002019 00000 n -0000002225 00000 n -0000002431 00000 n -0000002637 00000 n -0000002843 00000 n -0000003049 00000 n -0000003255 00000 n -0000003461 00000 n -0000003667 00000 n -0000003873 00000 n -0000004079 00000 n -0000004149 00000 n -0000004433 00000 n -0000004606 00000 n -0000006289 00000 n -0000008501 00000 n -0000009864 00000 n -0000011100 00000 n -0000012458 00000 n -0000013785 00000 n -0000015063 00000 n -0000016495 00000 n -0000018034 00000 n -0000019565 00000 n -0000021123 00000 n -0000022589 00000 n -0000024150 00000 n -0000025632 00000 n -0000027123 00000 n -0000028652 00000 n -trailer -<< -/ID -[<0f16994cff7b04926980333b4fec6185><0f16994cff7b04926980333b4fec6185>] -% ReportLab generated PDF document -- digest (http://www.reportlab.com) - -/Info 24 0 R -/Root 23 0 R -/Size 43 ->> -startxref -29793 -%%EOF diff --git a/tests/test_reportlab.py b/tests/test_reportlab.py index 74925e4..1d9c8bc 100644 --- a/tests/test_reportlab.py +++ b/tests/test_reportlab.py @@ -6,17 +6,24 @@ from pymisp import MISPEvent from pymisp.tools import reportlab_generator -import os import sys +import os +import time + +manual_testing = True class TestMISPEvent(unittest.TestCase): def setUp(self): self.maxDiff = None self.mispevent = MISPEvent() - self.test_folder = "tests/reportlab_testfiles/" #tests/ - self.test_batch_folder = "tests/OSINT_output/" - self.storage_folder = "tests/reportlab_testoutputs/" + if not manual_testing : + self.root = "tests/" + else : + self.root = "" + self.test_folder = self.root + "reportlab_testfiles/" + self.test_batch_folder = self.root + "OSINT_output/" + self.storage_folder = self.root + "reportlab_testoutputs/" def init_event(self): self.mispevent.info = 'This is a test' @@ -28,39 +35,120 @@ class TestMISPEvent(unittest.TestCase): def check_python_2(self): if sys.version_info.major < 3: # we want Python2 test to pass - assert(True) + return True def test_basic_event(self): - self.check_python_2() - self.init_event() - reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent), self.storage_folder + "basic_event.pdf") + if self.check_python_2(): + self.assertTrue(True) + else: + self.init_event() + reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent), + self.storage_folder + "basic_event.pdf") def test_event(self): - self.check_python_2() - self.init_event() - self.mispevent.load_file(self.test_folder + 'to_delete1.json') - reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent), - self.storage_folder + "basic_event.pdf") + if self.check_python_2(): + self.assertTrue(True) + else: + self.init_event() + self.mispevent.load_file(self.test_folder + 'to_delete1.json') + reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent), + self.storage_folder + "basic_event.pdf") def test_HTML_json(self): - self.check_python_2() - self.init_event() - self.mispevent.load_file(self.test_folder + '56e12e66-f01c-41be-afea-4d9a950d210f.json') - reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent), - self.storage_folder + "HTML.pdf") + if self.check_python_2(): + self.assertTrue(True) + else: + self.init_event() + self.mispevent.load_file(self.test_folder + '56e12e66-f01c-41be-afea-4d9a950d210f.json') + reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent), + self.storage_folder + "HTML.pdf") def test_long_json(self): - self.check_python_2() - self.init_event() - self.mispevent.load_file(self.test_folder + '57153590-f73c-49fa-be4b-4737950d210f.json') - reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent), - self.storage_folder + "Very_long.pdf") - # Issue report : "We are not smart enough" : https://pairlist2.pair.net/pipermail/reportlab-users/2010-May/009529.html - # Not nice but working solution exposed ther e: https://pairlist2.pair.net/pipermail/reportlab-users/2016-March/011525.html + if self.check_python_2(): + self.assertTrue(True) + else: + self.init_event() + self.mispevent.load_file(self.test_folder + '57153590-f73c-49fa-be4b-4737950d210f.json') + reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent), + self.storage_folder + "long.pdf") + # Issue report : "We are not smart enough" : https://pairlist2.pair.net/pipermail/reportlab-users/2010-May/009529.html + # Not nice but working solution exposed ther e: https://pairlist2.pair.net/pipermail/reportlab-users/2016-March/011525.html def test_very_long_json(self): - self.check_python_2() - self.init_event() - self.mispevent.load_file(self.test_folder + '5abf6421-c1b8-477b-a9d2-9c0902de0b81.json') - reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent), - self.storage_folder + "super_long.pdf") + if self.check_python_2(): + self.assertTrue(True) + else: + self.init_event() + self.mispevent.load_file(self.test_folder + '5abf6421-c1b8-477b-a9d2-9c0902de0b81.json') + reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent), + self.storage_folder + "very_long.pdf") + + def test_full_config_json(self): + if self.check_python_2(): + self.assertTrue(True) + else: + + config = {} + moduleconfig = ["MISP_base_url_for_dynamic_link", "MISP_name_for_metadata"] + config[moduleconfig[0]] = "http://localhost:8080" + config[moduleconfig[1]] = "My Wonderful CERT" + + self.init_event() + self.mispevent.load_file(self.test_folder + '5abf6421-c1b8-477b-a9d2-9c0902de0b81.json') + reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config), + self.storage_folder + "config_complete.pdf") + + def test_partial_0_config_json(self): + if self.check_python_2(): + self.assertTrue(True) + else: + + config = {} + moduleconfig = ["MISP_base_url_for_dynamic_link", "MISP_name_for_metadata"] + config[moduleconfig[0]] = "http://localhost:8080" + + self.init_event() + self.mispevent.load_file(self.test_folder + '5abf6421-c1b8-477b-a9d2-9c0902de0b81.json') + reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config), + self.storage_folder + "config_partial_0.pdf") + + def test_partial_1_config_json(self): + if self.check_python_2(): + self.assertTrue(True) + else: + + config = {} + moduleconfig = ["MISP_base_url_for_dynamic_link", "MISP_name_for_metadata"] + config[moduleconfig[1]] = "My Wonderful CERT" + + self.init_event() + self.mispevent.load_file(self.test_folder + '5abf6421-c1b8-477b-a9d2-9c0902de0b81.json') + reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config), + self.storage_folder + "config_partial_1.pdf") + + def test_batch_OSINT_events(self): + # Test case ONLY for manual testing. Needs to download a full list of OSINT events ! + + if self.check_python_2(): + self.assertTrue(True) + elif not manual_testing : + self.assertTrue(True) + else: + self.init_event() + + file_nb = str(len(os.listdir(self.test_batch_folder))) + i = 0 + t = time.time() + for curr_file in os.listdir(self.test_batch_folder): + self.mispevent = MISPEvent() + file_path = self.test_batch_folder + curr_file + + print("Current file : " + file_path + " " + str(i) + " over " + file_nb) + i += 1 + + self.mispevent.load_file(file_path) + + reportlab_generator.register_value_to_file( + reportlab_generator.convert_event_in_pdf_buffer(self.mispevent), + self.storage_folder + curr_file + ".pdf") + print("Elapsed time : " + str(time.time() - t))