summaryrefslogtreecommitdiff
path: root/monitor/josef_reader.py
diff options
context:
space:
mode:
Diffstat (limited to 'monitor/josef_reader.py')
-rwxr-xr-xmonitor/josef_reader.py67
1 files changed, 50 insertions, 17 deletions
diff --git a/monitor/josef_reader.py b/monitor/josef_reader.py
index bf415f7..c2653c1 100755
--- a/monitor/josef_reader.py
+++ b/monitor/josef_reader.py
@@ -2,13 +2,15 @@
# -*- coding: utf-8 -*-
import sys
-from certtools import *
+from josef_lib import *
import argparse
+from datetime import datetime as dt
parser = argparse.ArgumentParser(description="")
parser.add_argument('--domain', default=None, help="RTFM")
+parser.add_argument('--log', default=None, help="RTFM")
parser.add_argument('--exclude-expired', action='store_true', help="RTFM")
args = parser.parse_args()
@@ -23,12 +25,16 @@ monitored_domains = [
-# data = []
-f = open("plausible_cert_data.json")
+cur_time = dt.now()
+count_valid = 0
+count_all = 0
+f = open("output/cert_data.json")
for line in f:
tmp = json.loads(line)
try:
success = True
+ not_after_time = dt.strptime(tmp["not_after"], "%b %d %H:%M:%S %Y GMT")
+ not_before_time = dt.strptime(tmp["not_before"], "%b %d %H:%M:%S %Y GMT")
if args.domain:
if args.domain in tmp["subject"].split("CN=")[1] or \
@@ -36,25 +42,52 @@ for line in f:
pass
else:
success = False
+ else:
+ print "No domain selected!"
+ sys.exit()
- if args.exclude_expired:
- print "EXCLUDE EXPIRED NOT IMPLEMENTED YET"
+ if args.log:
+ if args.log in tmp["log"]:
+ pass
+ else:
+ success = False
+ if cur_time > not_after_time:
+ expired = True
+ elif cur_time < not_before_time:
+ expired = True
+ else:
+ expired = False
+
+ # Exclude expired
+ if args.exclude_expired and expired:
+ success = False
+
+
+ # Set count matches
+ if success:
+ count_all += 1
+ if not expired:
+ count_valid += 1
+ # Print matching
if success:
- print tmp["subject"].split("CN=")[1] + " certified by " + tmp["issuer"].split("CN=")[1]
+ s = tmp["subject"].split("CN=")[1] + \
+ " certified by " + tmp["issuer"].split("CN=")[1] + \
+ " (" + tmp["log"] + ") "
+ if expired:
+ print "(NOT VALID) " + s
+ else:
+ print "(VALID) " + s
+
+
+
except:
pass
f.close()
-
-# for item in data[10000:]:
-# try:
-# s = item["subject"].split("CN=")[1]
-# print "\n" + s
-# print item["SAN"]
-# except:
-# pass
-
-# print "\nTotal entries: " + str(len(data))
-
+print str(count_all) + " matches found."
+# if count_valid == 0:
+# print "No matching certificates found."
+# else:
+# print str(count_valid) + " of " + str(count_all) + " certs valid. (" + str(int(float(count_valid)/float(count_all)*100)) + "%)"