Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
af83bf67
Commit
af83bf67
authored
10 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
Script for checking event hashes
parent
fe6832fa
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/check_event_hash.py
+43
-0
43 additions, 0 deletions
scripts/check_event_hash.py
with
43 additions
and
0 deletions
scripts/check_event_hash.py
0 → 100644
+
43
−
0
View file @
af83bf67
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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment