diff options
author | Mark Haines <mark.haines@matrix.org> | 2014-11-03 16:35:24 +0000 |
---|---|---|
committer | Mark Haines <mark.haines@matrix.org> | 2014-11-03 16:35:24 +0000 |
commit | af83bf6712629bd9121d1b28b18dda936f0c28f2 (patch) | |
tree | dc0f354131ac7575703a73f247c334843258a52f | |
parent | handle server names with embeded ports (diff) | |
download | synapse-af83bf6712629bd9121d1b28b18dda936f0c28f2.tar.xz |
Script for checking event hashes
-rw-r--r-- | scripts/check_event_hash.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/scripts/check_event_hash.py b/scripts/check_event_hash.py new file mode 100644 index 0000000000..9fa4452ee6 --- /dev/null +++ b/scripts/check_event_hash.py @@ -0,0 +1,43 @@ +from synapse.crypto.event_signing import * +from syutil.base64util import encode_base64 + +import argparse +import hashlib +import sys +import json + +class dictobj(dict): + def __init__(self, *args, **kargs): + dict.__init__(self, *args, **kargs) + self.__dict__ = self + + def get_dict(self): + return dict(self) + + +def main(): + parser = parser = argparse.ArgumentParser() + parser.add_argument("input_json", nargs="?", type=argparse.FileType('r'), + default=sys.stdin) + args = parser.parse_args() + logging.basicConfig() + + event_json = dictobj(json.load(args.input_json)) + + algorithms = { + "sha256": hashlib.sha256, + } + + for alg_name in event_json.hashes: + if check_event_pdu_content_hash(event_json, algorithms[alg_name]): + print "PASS content hash %s" % (alg_name,) + else: + print "FAIL content hash %s" % (alg_name,) + + for algorithm in algorithms.values(): + name, h_bytes = compute_pdu_event_reference_hash(event_json, algorithm) + print "Reference hash %s: %s" % (name, encode_base64(bytes)) + +if __name__=="__main__": + main() + |