summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosef Gustafsson <josef.gson@gmail.com>2015-09-10 13:37:17 +0200
committerJosef Gustafsson <josef.gson@gmail.com>2015-09-10 13:37:17 +0200
commit1df8593e526d76449dc0be54b6aae755a4405e57 (patch)
tree5ba046a2567463777d7d19feffcf9aca90779178
parentdbee1f90fc8e49c008bb9032c94eb8be6612c1de (diff)
creating output dir if missing
-rwxr-xr-xmonitor/josef_experimental.py84
-rwxr-xr-xmonitor/josef_leveldb.py57
-rwxr-xr-xmonitor/josef_monitor.py10
3 files changed, 95 insertions, 56 deletions
diff --git a/monitor/josef_experimental.py b/monitor/josef_experimental.py
index 10d48bb..14b8e99 100755
--- a/monitor/josef_experimental.py
+++ b/monitor/josef_experimental.py
@@ -4,15 +4,89 @@
import sys
from josef_lib import *
import leveldb
+import argparse
+import json
from josef_leveldb import *
+from datetime import datetime as dt
-SEP = ";"
-db = db_open()
-res = db_lookup_domain(db, "*.google.com")
-print res
-print "Found " + str(len(res)) + " results"
+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()
+
+monitored_domains = [
+ "google.com",
+ "preishelden.de",
+ "liu.se",
+ "nordu.net",
+ "symantec.com",
+]
+
+
+
+if args.domain:
+ db = db_open()
+ raw = db_lookup_domain(db, args.domain)
+else:
+ print "No domain selected!"
+ sys.exit()
+
+cur_time = dt.now()
+count_valid = 0
+count_all = 0
+for item in raw:
+ # print item + '}', type(item)
+ entry = json.loads((item + '}').replace("'", '"'))
+ # print entry, type(entry)
+ success = True
+ not_after_time = dt.strptime(entry["not_after"], "%b %d %H:%M:%S %Y GMT")
+ not_before_time = dt.strptime(entry["not_before"], "%b %d %H:%M:%S %Y GMT")
+
+
+ if args.log:
+ if args.log in entry["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:
+ s = entry["subject"].split("CN=")[1] + \
+ " certified by " + entry["issuer"].split("CN=")[1] + \
+ " (" + entry["log"] + ") "
+ if expired:
+ print "(NOT VALID) " + s
+ else:
+ print "(VALID) " + s
+
+
+print str(count_all) + " matches found."
+
+
+# print res
+# print "Found " + str(len(res)) + " results"
# print db.Get("wush.net")
# print db.Get("wush.net")
diff --git a/monitor/josef_leveldb.py b/monitor/josef_leveldb.py
index e985e8d..cee0035 100755
--- a/monitor/josef_leveldb.py
+++ b/monitor/josef_leveldb.py
@@ -73,18 +73,19 @@ def db_add_certs(db, data):
print "ERROR: NO DATABASE SET!"
return
# print data, type(data)
+ # batch = leveldb.WriteBatch()
for cert in data:
try:
db_add_domain(db, cert["subject"].split("CN=")[1], str(cert))
- except:
- # print "Failed adding Subject in " + str(cert)
+ except IndexError:
pass
- try:
+ # try:
for line in cert["SAN"].split("DNS:")[1:]:
db_add_domain(db, line, str(cert))
- except:
- # print "Failed adding SAN in " + str(cert)
- pass
+ # except:
+ # # print "Failed adding SAN in " + str(cert)
+ # pass
+ # db.Write(batch, sync = True)
@@ -125,50 +126,6 @@ def db_lookup_domain(db, domain):
return res
-# db_open()
-# # print db_lookup_domain("*.cox.com")
-# print db.Get("wush.net")
-
-# f = open("output/cert_data.json")
-# max_count = 1
-# for line in f:
-# # print max_count
-# # try:
-# tmp = json.loads(line)
-# # print tmp
-# # d = tmp["subject"].split("CN=")[1]
-# db_add_cert(tmp)
-# # print d
-
-# max_count -= 1
-# if max_count == 0:
-# break
- # except:
- # pass
-
- # tmp_res = ""
- # # print domain_list
- # # print tmp_res[:-1]
- # last = False
-
- # for i in range(3):
- # try:
- # except:
- # last = True
- # new_res_list = []
- # print len(tmp_res_list)
- # print tmp_res
- # for item in tmp_res_list:
- # if not last:
- # if match_domain(tmp_res, item):
- # new_res_list.append(item)
- # else:
- # res.append(item)
- # # print item
- # tmp_res_list = new_res_list
- # return res
-
-
diff --git a/monitor/josef_monitor.py b/monitor/josef_monitor.py
index 2812c37..4f03c73 100755
--- a/monitor/josef_monitor.py
+++ b/monitor/josef_monitor.py
@@ -1,5 +1,10 @@
#!/usr/bin/python
-# -*- coding: utf-8 -*-
+# -*- coding: utf-8 -*-
+
+# Selected dependencies
+# python-dev (apt)
+# pycrypto (pip)
+# leveldb (pip)
import time
import datetime
@@ -18,6 +23,9 @@ else:
print "Config file not found!"
sys.exit()
+if not os.path.exists(OUTPUT_DIR):
+ os.makedirs(OUTPUT_DIR)
+
DB = None
parser = argparse.ArgumentParser(description="")