()
| 416 | modern = conf["configurations"]["modern"] |
| 417 | |
| 418 | def main(): |
| 419 | parser = argparse.ArgumentParser( |
| 420 | description='Analyze cipherscan results and provides guidelines to improve configuration.', |
| 421 | usage='\n* Analyze a single target, invokes cipherscan: $ ./analyze.py -t [target]' \ |
| 422 | '\n* Evaluate json results passed through stdin: $ python analyze.py target_results.json' \ |
| 423 | '\nexample: ./analyze.py -t mozilla.org', |
| 424 | epilog='Julien Vehent [:ulfr] - 2014') |
| 425 | parser.add_argument('-d', dest='debug', action='store_true', |
| 426 | help='debug output') |
| 427 | parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), |
| 428 | default=sys.stdin, help='cipherscan json results') |
| 429 | parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'), |
| 430 | default=sys.stdout, help='json formatted analysis') |
| 431 | parser.add_argument('-l', dest='level', |
| 432 | help='target configuration level [old, intermediate, modern]') |
| 433 | parser.add_argument('-t', dest='target', |
| 434 | help='analyze a <target>, invokes cipherscan') |
| 435 | parser.add_argument('-o', dest='openssl', |
| 436 | help='path to openssl binary, if you don\'t like the default') |
| 437 | parser.add_argument('-j', dest='json', action='store_true', |
| 438 | help='output results in json format') |
| 439 | parser.add_argument('--ops', dest='operator', |
| 440 | help='optional name of the operator\'s team added into the JSON output (for database insertion)') |
| 441 | parser.add_argument('--nagios', dest='nagios', action='store_true', |
| 442 | help='use nagios-conformant exit codes') |
| 443 | args = parser.parse_args() |
| 444 | |
| 445 | global mypath |
| 446 | mypath = os.path.dirname(os.path.realpath(sys.argv[0])) |
| 447 | |
| 448 | if args.debug: |
| 449 | logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) |
| 450 | else: |
| 451 | logging.basicConfig(stream=sys.stderr, level=logging.INFO) |
| 452 | |
| 453 | global operator |
| 454 | operator='' |
| 455 | if args.operator: |
| 456 | operator=args.operator |
| 457 | |
| 458 | build_ciphers_lists() |
| 459 | |
| 460 | if args.target: |
| 461 | # evaluate target specified as argument |
| 462 | logging.debug('Invoking cipherscan with target: ' + args.target) |
| 463 | data='' |
| 464 | if args.openssl: |
| 465 | data = subprocess.check_output([mypath + '/cipherscan', '-o', args.openssl, '-j', args.target]) |
| 466 | else: |
| 467 | data = subprocess.check_output([mypath + '/cipherscan', '-j', args.target]) |
| 468 | data = str_compat(data) |
| 469 | exit_status=process_results(str(data), args.level, args.json, args.nagios) |
| 470 | else: |
| 471 | if os.fstat(args.infile.fileno()).st_size < 2: |
| 472 | logging.error("invalid input file") |
| 473 | parser.print_help() |
| 474 | if args.nagios: |
| 475 | sys.exit(3) |
no test coverage detected