Compare commits

...

2 commits

Author SHA1 Message Date
746d8380cb
allow multiple rooms 2025-01-24 17:00:07 -03:00
c077b09717
file can't be empty 2025-01-24 16:55:31 -03:00
2 changed files with 8 additions and 6 deletions

View file

@ -25,11 +25,10 @@ options:
-p, --plain Returns the plain unencrypted content
```
Using the above example, let's say we want to only get session keys of the room
`!foo:matrix.org`. You can do this fairly easily with:
You can do this fairly easily with:
```bash
$ ./megolm_filter.py element-keys.txt '!foo:matrix.org'
$ ./megolm_filter.py element-keys.txt '!room1:matrix.org' '!room2:matrix.org' ...
```
You need to have PyCryptodome installed in order for this script to work.

View file

@ -145,7 +145,7 @@ def dec_session_data(passphrase, session_data):
def main():
parser = argparse.ArgumentParser(description="Operate on megolm session backups.")
parser.add_argument("file", nargs='?', help="megolm session data")
parser.add_argument("room_id", nargs='?', help="Room id to filter (optional)")
parser.add_argument("room_ids", nargs='*', help="Room id to filter (optional)")
parser.add_argument("-o", "--output", help="Output to file")
parser.add_argument("-p", "--plain", dest="mode", const="plain", action="store_const",
help="Returns the plain unencrypted content")
@ -154,6 +154,9 @@ def main():
if not args.mode:
args.mode = "encrypted"
if not args.file:
bail("You must specify a file")
with open(args.file, "rb") as f:
data = f.read()
@ -163,9 +166,9 @@ def main():
passphrase = getpass.getpass(f"Backup passphrase [mode={args.mode}]: ")
decrypted_data = dec_session_data(passphrase, data)
if args.room_id:
if args.room_ids:
json_data = json.loads(decrypted_data)
filtered_data = [ key for key in json_data if key['room_id'] == args.room_id ]
filtered_data = [ key for key in json_data if key['room_id'] in args.room_ids ]
if not filtered_data:
bail(f"No keys found for room {args.room_id}")