summaryrefslogtreecommitdiff
path: root/monitor/josef_monitor.py
diff options
context:
space:
mode:
Diffstat (limited to 'monitor/josef_monitor.py')
-rwxr-xr-xmonitor/josef_monitor.py57
1 files changed, 30 insertions, 27 deletions
diff --git a/monitor/josef_monitor.py b/monitor/josef_monitor.py
index 3a71987..14a280a 100755
--- a/monitor/josef_monitor.py
+++ b/monitor/josef_monitor.py
@@ -26,7 +26,10 @@ else:
if not os.path.exists(OUTPUT_DIR):
os.makedirs(OUTPUT_DIR)
-DB = None
+if not os.path.exists(DB_PATH):
+ os.makedirs(DB_PATH)
+
+# DB = None
parser = argparse.ArgumentParser(description="")
@@ -51,7 +54,7 @@ class ctlog:
start_size = self.entries
while self.entries < self.sth["tree_size"]:
tmp_size = self.entries
- self.subtree, self.entries = fetch_and_increment_subtree(self.entries, self.sth["tree_size"] -1, self.url, self.subtree)
+ self.subtree, self.entries = self.fetch_and_increment_subtree(self.entries, self.sth["tree_size"] -1, self.url, self.subtree)
if tmp_size != self.entries:
self.log("Got entries " + str(tmp_size) + " to " \
+ str(self.entries -1 ) + " of " + str(self.sth["tree_size"]-1))
@@ -66,6 +69,29 @@ class ctlog:
# self.log("No new entries.")
+ def fetch_and_increment_subtree(self, first, last, url, subtree =[[]]):
+ # global DB
+ # try:
+ new_leafs = []
+ if first <= last:
+ entries = get_entries(url, first, last)["entries"]
+ tmp_cert_data = []
+ for item in entries:
+ tmp_data = check_domain(item, url)
+ if tmp_data:
+ tmp_cert_data.append(tmp_data)
+ new_leafs.append(get_leaf_hash(base64.b64decode(item["leaf_input"])))
+ if DB_PATH:
+ self.log("Adding to database...")
+ db_add_certs(DB_PATH, tmp_cert_data)
+ self.log("done adding to DB.")
+ if DEFAULT_CERT_FILE:
+ append_file(DEFAULT_CERT_FILE, tmp_cert_data)
+ subtree = reduce_tree(new_leafs, subtree)
+ # except:
+ # print "Failed to build subtree :("
+ return subtree, len(new_leafs) + first
+
def to_dict(self):
d = {}
@@ -215,28 +241,6 @@ def check_domain(raw_entry, log=None):
except IndexError:
return None
-def fetch_and_increment_subtree(first, last, url, subtree =[[]]):
- global DB
- # try:
- new_leafs = []
- if first <= last:
- entries = get_entries(url, first, last)["entries"]
- tmp_cert_data = []
- for item in entries:
- tmp_data = check_domain(item, url)
- if tmp_data:
- tmp_cert_data.append(tmp_data)
- new_leafs.append(get_leaf_hash(base64.b64decode(item["leaf_input"])))
- if DEFAULT_CERT_FILE:
- if DB is None:
- append_file(DEFAULT_CERT_FILE, tmp_cert_data)
- else:
- db_add_certs(DB, tmp_cert_data)
- subtree = reduce_tree(new_leafs, subtree)
- # except:
- # print "Failed to build subtree :("
- return subtree, len(new_leafs) + first
-
def verify_subtree(sth, subtree, base_url):
try:
tmp = deepcopy(subtree)
@@ -318,13 +322,12 @@ def get_all_roots(base_url):
root_cert = base64.decodestring(accepted_cert)
print get_cert_info(root_cert)["subject"]
-
def main(args):
global DB
# Create logs
logs = []
- if DB_PATH:
- DB = db_open(DB_PATH)
+ # if DB_PATH:
+ # DB = db_open(DB_PATH)
try:
for item in ctlogs:
logs.append(ctlog(item, ctlogs[item][0], ctlogs[item][1]))