Skip to content

Commit

Permalink
make scripts python 3 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
tomato42 committed May 30, 2015
1 parent 3bc8dc5 commit a53a916
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
25 changes: 16 additions & 9 deletions analyze.py
Expand Up @@ -5,6 +5,8 @@
#
# Contributor: Julien Vehent jvehent@mozilla.com [:ulfr]

from __future__ import print_function

import sys, os, json, subprocess, logging, argparse, platform
from collections import namedtuple
from datetime import datetime
Expand Down Expand Up @@ -319,8 +321,8 @@ def process_results(data, level=None, do_json=False, do_nagios=False):
level='none'
try:
results = json.loads(data)
except ValueError, e:
print("invalid json data")
except ValueError as e:
print("invalid json data: " + str(e))
try:
if results:
if do_json:
Expand All @@ -342,12 +344,13 @@ def process_results(data, level=None, do_json=False, do_nagios=False):
print("and complies with the '" + level + "' level")
else:
print("and DOES NOT comply with the '" + level + "' level")
except TypeError, e:
except TypeError as e:
print("Error processing data: " + str(e))
return False

if do_json:
json_output['failures'] = deepcopy(failures)
print json.dumps(json_output)
print(json.dumps(json_output))
return True

if len(failures['fubar']) > 0:
Expand Down Expand Up @@ -419,16 +422,20 @@ def build_ciphers_lists(opensslbin):

logging.debug('Loading all ciphers: ' + allC)
all_ciphers = subprocess.Popen([opensslbin, 'ciphers', allC],
stderr=blackhole, stdout=subprocess.PIPE).communicate()[0].rstrip().split(':')
stderr=blackhole, stdout=subprocess.PIPE).communicate()[0].rstrip()
all_ciphers = str(all_ciphers).split(":")
logging.debug('Loading old ciphers: ' + oldC)
old_ciphers = subprocess.Popen([opensslbin, 'ciphers', oldC],
stderr=blackhole, stdout=subprocess.PIPE).communicate()[0].rstrip().split(':')
stderr=blackhole, stdout=subprocess.PIPE).communicate()[0].rstrip()
old_ciphers = str(old_ciphers).split(':')
logging.debug('Loading intermediate ciphers: ' + intC)
intermediate_ciphers = subprocess.Popen([opensslbin, 'ciphers', intC],
stderr=blackhole, stdout=subprocess.PIPE).communicate()[0].rstrip().split(':')
stderr=blackhole, stdout=subprocess.PIPE).communicate()[0].rstrip()
intermediate_ciphers = str(intermediate_ciphers).split(':')
logging.debug('Loading modern ciphers: ' + modernC)
modern_ciphers = subprocess.Popen([opensslbin, 'ciphers', modernC],
stderr=blackhole, stdout=subprocess.PIPE).communicate()[0].rstrip().split(':')
stderr=blackhole, stdout=subprocess.PIPE).communicate()[0].rstrip()
modern_ciphers = str(modern_ciphers).split(':')
blackhole.close()

def main():
Expand Down Expand Up @@ -481,7 +488,7 @@ def main():
data = subprocess.check_output([mypath + '/cipherscan', '-o', args.openssl, '-j', args.target])
else:
data = subprocess.check_output([mypath + '/cipherscan', '-j', args.target])
exit_status=process_results(data, args.level, args.json, args.nagios)
exit_status=process_results(str(data), args.level, args.json, args.nagios)
else:
if os.fstat(args.infile.fileno()).st_size < 2:
logging.error("invalid input file")
Expand Down
16 changes: 8 additions & 8 deletions top1m/parse_CAs.py
Expand Up @@ -5,7 +5,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Author: Hubert Kario - 2014

from __future__ import division
from __future__ import division, print_function

path = "./results/"
ca_certs_path = "./ca_files"
Expand Down Expand Up @@ -61,7 +61,7 @@ def get_path_for_hash(cert_hash):
if not os.path.exists(f_name):
f_name = ca_certs_path + '/' + cert_hash + '.pem'
if not os.path.exists(f_name):
#print "File with hash " + c_hash + " is missing!"
#print("File with hash " + c_hash + " is missing!")
return None
return f_name

Expand Down Expand Up @@ -201,7 +201,7 @@ def collect_key_sizes(file_names):
try:
res = json.loads(line)
except ValueError as e:
print "can't process line: " + line
print("can't process line: " + line)
continue

f=res
Expand Down Expand Up @@ -248,13 +248,13 @@ def collect_key_sizes(file_names):
if server_chain_trusted:
if server_chain_complete:
chains["complete"] += 1
print "complete: " + f['host']
print("complete: " + f['host'])
else:
chains["incomplete"] += 1
print "incomplete: " + f['host']
print("incomplete: " + f['host'])
else:
chains["untrusted"] += 1
print "untrusted: " + f['host']
print("untrusted: " + f['host'])

if valid:
hosts += 1
Expand All @@ -276,9 +276,9 @@ def collect_key_sizes(file_names):
continue

""" Display stats """
#print "openssl invocations: " + str(invocations["openssl"])
#print("openssl invocations: " + str(invocations["openssl"]))

print "Statistics from " + str(total) + " chains provided by " + str(hosts) + " hosts"
print("Statistics from " + str(total) + " chains provided by " + str(hosts) + " hosts")

print("\nServer provided chains Count Percent")
print("-------------------------+---------+-------")
Expand Down
2 changes: 1 addition & 1 deletion top1m/parse_results.py
Expand Up @@ -6,7 +6,7 @@
# Author: Julien Vehent [:ulfr] - 2013
# Contributors: Hubert Kario - 2014

from __future__ import division
from __future__ import division, print_function

path = "./results/"

Expand Down

0 comments on commit a53a916

Please sign in to comment.