summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjosef <josef.gson@gmail.com>2015-12-08 10:50:52 +0100
committerjosef <josef.gson@gmail.com>2015-12-08 10:50:52 +0100
commita932cff9da3cf794d84fcc884b2fac189f1bd96d (patch)
treeb3b02b633cedd68cfe95a6f669e9491cb40d5bf8
parent53fc45dfe6befeb85ba1f400e89d1d950321729b (diff)
reworking logging, testing failure
-rwxr-xr-xmonitor/gaol/gaol_auditor.py51
-rw-r--r--monitor/gaol/gaol_conf.py6
-rwxr-xr-xmonitor/gaol/gaol_test.py8
-rwxr-xr-xmonitor/josef_experimental.py5
4 files changed, 39 insertions, 31 deletions
diff --git a/monitor/gaol/gaol_auditor.py b/monitor/gaol/gaol_auditor.py
index d2da59b..4e2aca5 100755
--- a/monitor/gaol/gaol_auditor.py
+++ b/monitor/gaol/gaol_auditor.py
@@ -85,24 +85,34 @@ class ctlog:
raise e
- def log(self, string):
- s = time_str() + " " + string
+ def log(self, string, t="INFO"):
+ # s = time_str() + " " + string
+ if t == "ERROR":
+ s = time_str() + " " + ERROR_STR + string
+ email(s)
+ elif t == "WARNING":
+ s = time_str() + " " + WARNING_STR + string
+ elif t == "INFO":
+ s = time_str() + " " + string
+ else:
+ print "UNKNOWN LOGGING TYPE: " + t
+
with open(self.logfile, 'a') as f:
f.write(s + "\n")
f.close()
- email(s)
+ # email(s)
def update_sth(self):
try:
new_sth = get_sth(self.url)
except Exception, e:
- self.log(ERROR_STR + "Failed to fetch STH. " +str(e))
+ self.log("Failed to fetch STH. " +str(e), "ERROR")
return
try:
check_sth_signature(self.url, new_sth, base64.b64decode(self.key))
except:
- self.log(ERROR_STR + "Could not verify STH signature " + str(new_sth))
+ self.log("Could not verify STH signature " + str(new_sth), "ERROR")
if self.sth:
sth_time = time_str(new_sth["timestamp"])
@@ -119,28 +129,27 @@ class ctlog:
try:
if new["tree_size"] == old["tree_size"]:
if old["sha256_root_hash"] != new["sha256_root_hash"]:
- self.log(ERROR_STR + "New root hash for same tree size! Old:" + str(old) + " New:" + str(new))
+ self.log("New root hash for same tree size! Old:" + str(old) + " New:" + str(new), "ERROR")
elif new["tree_size"] < old["tree_size"]:
- self.log(ERROR_STR + "New tree is smaller than old tree! Old:" + str(old) + " New:" + str(new))
+ self.log("New tree is smaller than old tree! Old:" + str(old) + " New:" + str(new), "ERROR")
if new["timestamp"] < old["timestamp"]:
- self.log(ERROR_STR + "Regression in timestamps! Old:" + str(old) + " New:" + str(new))
+ self.log("Regression in timestamps! Old:" + str(old) + " New:" + str(new), "ERROR")
else:
age = time.time() - new["timestamp"]/1000
sth_time = time_str(new["timestamp"])
roothash = new['sha256_root_hash']
if age > 24 * 3600:
- s = ERROR_STR + "STH is older than 24h: %s UTC" % (sth_time)
- self.log(s + str(new))
- print s
+ self.log("STH is older than 24h: %s UTC" % (sth_time) + str(new), "ERROR")
+ # print s
elif age > 12 * 3600:
- s = "WARNING: STH is older than 12h: %s UTC" % (sth_time)
- self.log(s)
+ s = "STH is older than 12h: %s UTC" % (sth_time)
+ self.log(s, "WARNING")
elif age > 6 * 3600:
- s = "WARNING: STH is older than 6h: %s UTC" % (sth_time)
- self.log(s)
+ s = "STH is older than 6h: %s UTC" % (sth_time)
+ self.log(s, "WARNING")
except Exception, e:
- self.log(ERROR_STR + "Failed to verify progress! Old:" + str(old) + " New:" + str(new) + " Exception: " + str(e))
+ self.log("Failed to verify progress! Old:" + str(old) + " New:" + str(new) + " Exception: " + str(e), "ERROR")
def verify_consistency(self, old):
new = self.sth
@@ -153,15 +162,15 @@ class ctlog:
res = verify_consistency_proof(decoded_consistency_proof, old["tree_size"], new["tree_size"], base64.b64decode(old["sha256_root_hash"]))
if old["sha256_root_hash"] != str(base64.b64encode(res[0])):
- self.log(ERROR_STR + "Verification of consistency for old hash failed! Old:" \
+ self.log("Verification of consistency for old hash failed! Old:" \
+ str(old) + " New:" + str(new) + " Calculated:" + str(base64.b64encode(res[0]))\
- + " Proof:" + str(consistency_proof))
+ + " Proof:" + str(consistency_proof), "ERROR")
elif new["sha256_root_hash"] != str(base64.b64encode(res[1])):
- self.log(ERROR_STR + "Verification of consistency for new hash failed! Old:" \
- + str(old) + " New:" + str(new) + " Proof:" + str(consistency_proof))
+ self.log("Verification of consistency for new hash failed! Old:" \
+ + str(old) + " New:" + str(new) + " Proof:" + str(consistency_proof), "ERROR")
except Exception, e:
- self.log(ERROR_STR + "Could not verify consistency! " + " Old:" + str(old) + " New:" + str(new) + " Error:" + str(e))
+ self.log("Could not verify consistency! " + " Old:" + str(old) + " New:" + str(new) + " Error:" + str(e), "ERROR")
diff --git a/monitor/gaol/gaol_conf.py b/monitor/gaol/gaol_conf.py
index 7019989..af9f5ea 100644
--- a/monitor/gaol/gaol_conf.py
+++ b/monitor/gaol/gaol_conf.py
@@ -8,7 +8,8 @@ OUTPUT_DIR = "output/"
# Some strings
ERROR_STR = "ERROR: "
-EMAIL_SUBJECT = "GAOL"
+WARNING_STR = "WARNING: "
+EMAIL_SUBJECT = "GAOL Notification"
# Email addresses for error messages
EMAIL_ADDR = [
@@ -18,7 +19,8 @@ EMAIL_ADDR = [
# CT logs and associated keys
CTLOGS = [
{"name" : "gaol",
- "url" : "https://gaol.ct.nordu.net/open/",
+ # "url" : "https://gaol.ct.nordu.net/open/",
+ "url" : "https://gaol.fake.nordu.net/open/",
"key" : "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEE0E7UyZA2XkTJC2Rlcx0DbXkI1Y0+2OgoJQ0O+pwtVRCiVGHdU08i4m8MKx2r8FWbpHVgt6V0rLS8rYBErfSVA==",
"id" : "5WUP4zAPa2LwNM1oepj+x7cM8LlqB4fstdOMzzj4MzM=",
"build" : False},
diff --git a/monitor/gaol/gaol_test.py b/monitor/gaol/gaol_test.py
index dbcadc4..94eb63e 100755
--- a/monitor/gaol/gaol_test.py
+++ b/monitor/gaol/gaol_test.py
@@ -23,11 +23,11 @@ def test_consistency_proof(url, idx1, idx2):
if __name__ == '__main__':
url = CTLOGS[0]["url"]
- test_get_entry(url,1)
- test_get_entry(url,2)
- test_get_entry(url,3)
- test_get_entry(url,4)
test_get_entry(url,5)
+ test_get_entry(url,6)
+ test_get_entry(url,7)
+ # test_get_entry(url,4)
+ # test_get_entry(url,5)
# test_get_entry(url,6)
# test_submission(url, "Progress (n.): The process through which the Internet has evolved from smart people in front of dumb terminals to dumb people in front of smart terminals.")
# test_consistency_proof(url, 2, 3) \ No newline at end of file
diff --git a/monitor/josef_experimental.py b/monitor/josef_experimental.py
index b3acf1c..b40219f 100755
--- a/monitor/josef_experimental.py
+++ b/monitor/josef_experimental.py
@@ -172,20 +172,17 @@ def parse_entry(e, idx, log):
import subprocess
def email(s):
for addr in EMAIL_ADDR:
- # command = 'echo "' + s + '" | mail -s "' + EMAIL_SUBJECT + '" ' + addr
- # os.system("bash -c '" + command + "'")
p = subprocess.Popen(
["mail", "-s", EMAIL_SUBJECT, addr],
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
p.communicate(s)
- # print parsed
if __name__ == '__main__':
# Test email
- if True:
+ if False:
email("this is an automated test...")