Better JSON output (subjects and certificate fp separated)

This commit is contained in:
Alexandre Dulaunoy 2015-08-17 09:48:58 +00:00
parent 976aa74d2d
commit 436afcc6ad

View file

@ -27,7 +27,7 @@ class SSLQueryHandler(tornado.web.RequestHandler):
def get(self, input): def get(self, input):
try: try:
#Redis structure Set of (FP) per IP #Redis structure Set of (FP) per IP
r = redis.StrictRedis(host='127.0.0.1', port=6381) r = redis.StrictRedis(host='127.0.0.1', port=8323)
except: except:
print "Unable to connect to the Redis server" print "Unable to connect to the Redis server"
sys.exit(255) sys.exit(255)
@ -57,14 +57,17 @@ class SSLQueryHandler(tornado.web.RequestHandler):
for ip in iplist: for ip in iplist:
s = r.smembers(ip) s = r.smembers(ip)
if s: if s:
out[str(ip)] = [] out[str(ip)] = {}
out[str(ip)]['certificates'] = []
out[str(ip)]['subjects'] = {}
for fingerprint in s: for fingerprint in s:
subjects = r.smembers(fingerprint) subjects = r.smembers(fingerprint)
out[str(ip)]['certificates'].append(fingerprint)
if subjects: if subjects:
out[str(ip)]['subjects'][fingerprint] = {}
out[str(ip)]['subjects'][fingerprint]['values'] = []
for subject in subjects: for subject in subjects:
out[str(ip)].append(subject) out[str(ip)]['subjects'][fingerprint]['values'].append(subject)
else:
out[str(ip)].append(fingerprint)
if not self._finished: if not self._finished:
self.set_header('Content-Type', 'application/json') self.set_header('Content-Type', 'application/json')