Commit acb3f280 by lwilms

applied recommendations

parent 980bf603
......@@ -13,8 +13,6 @@ PDF_NAME = Path(MAIN_TEMPLATE).with_suffix('.pdf').name
def execute_latex(tmp_dir):
current_dir = os.getcwd()
os.chdir(tmp_dir)
print(current_dir)
print(tmp_dir)
execute_shell_command('env buf_size=1000000 pdflatex {}'.format(MAIN_TEMPLATE))
os.chdir(current_dir)
......
......@@ -104,7 +104,7 @@
\begin{tikzpicture}
\foreach [count=\i] \x/\y in {#1}{
\draw[fill=maingray,maingray] (0,\i) rectangle (6,\i+0.4);
\draw[fill=white,mainblue](0,\i) rectangle (\y,\i+0.4);
\draw[fill=white,mainblue](0,\i) rectangle (\y*6,\i+0.4);
\node [above right] at (0,\i+0.4) {\x};
}
\end{tikzpicture}
......
......@@ -13,6 +13,27 @@ META_TEMPLATE = 'meta.tex'
CUSTOM_TEMPLATE_CLASS = 'twentysecondcv.cls'
LOGO_FILE = 'fact.png'
LATEX_CHARACTER_ESCAPES = OrderedDict([
('\\', ''),
('\'', ''),
('$', '\\$'),
('(', '$($'),
(')', '$)$'),
('[', '$[$'),
(']', '$]$'),
('#', '\\#'),
('%', '\\%'),
('&', '\\&'),
('_', '\\_'),
('{', '\\{'),
('}', '\\}'),
('^', '\\textasciicircum{}'),
('~', '\\textasciitilde{}'),
('>', '\\textgreater{}'),
('<', '\\textless{}'),
('\n', '\\newline ')
])
def render_number_as_size(number, verbose=True):
if not isinstance(number, (int, float)):
......@@ -29,27 +50,7 @@ def render_unix_time(unix_time_stamp):
def replace_special_characters(data):
latex_character_escapes = OrderedDict()
latex_character_escapes['\\'] = ''
latex_character_escapes['\''] = ''
latex_character_escapes['$'] = '\\$'
latex_character_escapes['('] = '$($'
latex_character_escapes[')'] = '$)$'
latex_character_escapes['['] = '$[$'
latex_character_escapes[']'] = '$]$'
latex_character_escapes['#'] = '\\#'
latex_character_escapes['%'] = '\\%'
latex_character_escapes['&'] = '\\&'
latex_character_escapes['_'] = '\\_'
latex_character_escapes['{'] = '\\{'
latex_character_escapes['}'] = '\\}'
latex_character_escapes['^'] = '\\textasciicircum{}'
latex_character_escapes['~'] = '\\textasciitilde{}'
latex_character_escapes['>'] = '\\textgreater{}'
latex_character_escapes['<'] = '\\textless{}'
latex_character_escapes['\n'] = '\\newline '
for character, replacement in latex_character_escapes.items():
for character, replacement in LATEX_CHARACTER_ESCAPES.items():
if character in data:
data = data.replace(character, replacement)
return data
......@@ -95,23 +96,22 @@ def get_five_longest_entries(summary, top=5):
def exploit_mitigation(summary):
summary = summary['exploit_mitigations']['summary']
max_count = count_mitigations(summary) # bar is maxed at 6
pie_num, canary_num, relro_num, nx_num, fortify_num = 0, 0, 0, 0, 0
for selected_summary in summary:
if 'PIE' in selected_summary and 'present' in selected_summary:
pie_num += len(summary[selected_summary])
if 'RELRO' in selected_summary and 'enabled' in selected_summary:
relro_num += len(summary[selected_summary])
if 'Canary' in selected_summary and 'enabled' in selected_summary:
canary_num += len(summary[selected_summary])
if 'NX' in selected_summary and 'enabled' in selected_summary:
nx_num += len(summary[selected_summary])
if 'FORTIFY' in selected_summary and 'enabled' in selected_summary:
fortify_num += len(summary[selected_summary])
return '{0}{2}/{3}{1},{0}{4}/{5}{1},' \
'{0}{6}/{7}{1},{0}{8}/{9}{1},' \
'{0}{10}/{11}{1}'.format('{', '}', 'CANARY', canary_num * 6 / max_count, 'PIE', pie_num * 6 / max_count,
'RELRO', relro_num * 6 / max_count, 'NX', nx_num * 6 / max_count,
'FORTIFY\_SOURCE', fortify_num * 6 / max_count)
numbers = dict()
for key in ['PIE', 'RELRO', 'Canary', 'NX', 'FORTIFY']:
numbers[key] = count_occurrences(key, summary)
return (
f'{{CANARY/{numbers["Canary"] / max_count}}},{{PIE/{numbers["PIE"] / max_count}}},'
f'{{RELRO/{numbers["RELRO"] / max_count}}},{{NX/{numbers["NX"] / max_count}}},'
f'{{FORTIFY\\_SOURCE/{numbers["FORTIFY"] / max_count}}}'
)
def count_occurrences(key, summary):
return sum(
len(summary[entry])
for entry in summary
if key in entry and ('present' in entry or 'enabled' in entry)
)
def count_mitigations(summary):
......@@ -134,20 +134,31 @@ def software_components(software_string):
software = software_string
ver_number = ''
if ' ' in software_string:
if len(software_string.split(' ')) > 2:
software = ''.join(software_string.split(' ')[:-1])
ver_number = software_string.split(' ')[-1]
try:
int(ver_number[0])
except ValueError:
ver_number, software = software, ver_number
elif isinstance(software_string.split(' '), list) and len(software_string.split(' ')[1]) > 0:
software, ver_number = software_string.split(' ')
try:
int(ver_number[0])
except ValueError:
ver_number, software = software, ver_number
return '{}{}{}{}'.format(ver_number, '}', '{', software)
splitted_software_string = software_string.split(' ')
if len(splitted_software_string) > 2:
software, ver_number = larger_two_components(splitted_software_string)
elif len(splitted_software_string[1]) > 0:
software, ver_number = less_three_components(splitted_software_string)
return f'{ver_number}}}{{{software}'
def less_three_components(software_string):
software, ver_number = software_string
try:
int(ver_number[0])
except ValueError:
return ver_number, software
return software, ver_number
def larger_two_components(software_string):
software = ''.join(software_string[:-1])
ver_number = software_string[-1]
try:
int(ver_number[0])
except ValueError:
return ver_number, software
return software, ver_number
def get_triples(analysis):
......@@ -162,8 +173,7 @@ def get_desired_triple(seleced_summary, which_desired):
chosen_one = 'x x' * 60
while len(chosen_one) > 50:
chosen_one = choice(desired_list)
return '{2}{1}{0}{3}{4}$\>$ (incl. {5})'.format('{', '}', len(desired_list), which_desired, '\quad',
replace_special_characters(chosen_one))
return f'{len(desired_list)}}}{{{which_desired}\\quad$\\>$ (incl. {replace_special_characters(chosen_one)})'
def ip_or_uri(summary, which_select):
......@@ -190,8 +200,7 @@ def _validate_ip(ip, address_format):
def get_x_entries(summary, how_many=10):
if len(summary) <= how_many:
return summary
else:
return summary[:how_many]
return summary[:how_many]
def _add_filters_to_jinja(environment):
......
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