| 323 | return status |
| 324 | |
| 325 | def process_results(data, level=None, do_json=False, do_nagios=False): |
| 326 | logging.debug('processing results on %s' % data) |
| 327 | exit_status = 0 |
| 328 | results = dict() |
| 329 | # initialize the failures struct |
| 330 | global failures |
| 331 | json_output = dict() |
| 332 | failures = dict() |
| 333 | failures['fubar'] = [] |
| 334 | failures['old'] = [] |
| 335 | failures['intermediate'] = [] |
| 336 | failures['modern'] = [] |
| 337 | if not level: |
| 338 | level='none' |
| 339 | try: |
| 340 | results = json.loads(data) |
| 341 | except ValueError as e: |
| 342 | print("invalid json data: " + str(e)) |
| 343 | try: |
| 344 | if results: |
| 345 | if do_json: |
| 346 | json_output['target'] = results['target'] |
| 347 | d = datetime.utcnow() |
| 348 | json_output['utctimestamp'] = d.isoformat("T") + "Z" |
| 349 | json_output['level'] = evaluate_all(results) |
| 350 | json_output['target_level'] = level |
| 351 | json_output['compliance'] = False |
| 352 | if json_output['target_level'] in json_output['level']: |
| 353 | json_output['compliance'] = True |
| 354 | if operator: |
| 355 | json_output['operator'] = operator |
| 356 | else: |
| 357 | measured_lvl = evaluate_all(results) |
| 358 | print(results['target'] + " has " + measured_lvl + " ssl/tls") |
| 359 | if level != 'none': |
| 360 | if level in measured_lvl: |
| 361 | print("and complies with the '" + level + "' level") |
| 362 | else: |
| 363 | print("and DOES NOT comply with the '" + level + "' level") |
| 364 | except TypeError as e: |
| 365 | print("Error processing data: " + str(e)) |
| 366 | return False |
| 367 | |
| 368 | if do_json: |
| 369 | json_output['failures'] = deepcopy(failures) |
| 370 | print(json.dumps(json_output)) |
| 371 | return True |
| 372 | |
| 373 | if len(failures['fubar']) > 0: |
| 374 | print("\nThings that are bad:") |
| 375 | for failure in failures['fubar']: |
| 376 | print("* " + failure) |
| 377 | if do_nagios: |
| 378 | exit_status = 2 |
| 379 | |
| 380 | # print failures |
| 381 | if level != 'none': |
| 382 | if len(failures[level]) > 0: |