Skip to content

Commit

Permalink
Pretty print fields
Browse files Browse the repository at this point in the history
  • Loading branch information
dhinakg committed Aug 18, 2024
1 parent 36b3fdf commit f9f303a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions get_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

# Requirements: pip3 install requests pyhpke

import argparse
import base64
import json
from pathlib import Path
import argparse
import sys
from pathlib import Path
from pprint import pprint

import requests
from pyhpke import AEADId, CipherSuite, KDFId, KEMId, KEMKey
Expand Down Expand Up @@ -54,18 +55,20 @@ def main(aea_path: Path, verbose: bool = False):
field_size = int.from_bytes(auth_data_blob[:4], "little")
field_blob = auth_data_blob[:field_size]

key_end = field_blob.index(b"\x00", 4)
key = field_blob[4:key_end].decode()
value = field_blob[key_end + 1 :].decode()
key, value = field_blob[4:].split(b"\x00", 1)

fields[key] = value

auth_data_blob = auth_data_blob[field_size:]

if verbose:
print(fields, "\n", file=sys.stderr)
pprint(fields, stream=sys.stderr)

if "com.apple.wkms.fcs-response" not in fields:
error("No fcs-response field found, is this from an OTA?")
error("No fcs-response field found!")

if "com.apple.wkms.fcs-key-url" not in fields:
error("No fcs-key-url field found!")

fcs_response = json.loads(fields["com.apple.wkms.fcs-response"])
enc_request = base64.b64decode(fcs_response["enc-request"])
Expand Down

0 comments on commit f9f303a

Please sign in to comment.