Skip to content

Commit 2d96c37

Browse files
Fix decryption on Ventura 13.6 for bare-metal M1 instances (#214)
* Update to fallback to regex key parsing * [pre-commit.ci lite] apply automatic fixes * Add exceptions * [pre-commit.ci lite] apply automatic fixes * Add ignore * [pre-commit.ci lite] apply automatic fixes * Move ignore * Update spacing * Update plist.py * Break out login into helper function in parser --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 32d0304 commit 2d96c37

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

findmy/plist.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import logging
1414
import plistlib
15+
import re
1516
import subprocess
1617
from pathlib import Path
1718
from typing import IO
@@ -26,15 +27,36 @@
2627
_DEFAULT_SEARCH_PATH = Path.home() / "Library" / "com.apple.icloud.searchpartyd"
2728

2829

30+
def _parse_beaconstore_key_from_string_output(output: str) -> bytes:
31+
if '"acct"<blob>="BeaconStoreKey"' not in output:
32+
raise ValueError
33+
m = re.search(r'"gena"<blob>=0x([0-9A-Fa-f]+)', output)
34+
if not m:
35+
raise ValueError
36+
return bytes.fromhex(m.group(1))
37+
38+
39+
def _parse_beaconstore_key_from_hex_output(output: str) -> bytes:
40+
if not output:
41+
msg = "Empty output from security -w"
42+
raise ValueError(msg)
43+
return bytes.fromhex(output)
44+
45+
2946
# consider switching to this library https://github.com/microsoft/keyper
3047
# once they publish a version of it that includes my MR with the changes to make it compatible
3148
# with keys that are non-utf-8 encoded (like the BeaconStore one)
3249
# if I contribute this, properly escape the label argument here...
3350
def _get_beaconstore_key() -> bytes:
34-
"""Get the decryption key for BeaconStore using the system password prompt window."""
35-
# This thing will pop up 2 Password Input windows...
36-
key_in_hex = subprocess.getoutput("/usr/bin/security find-generic-password -l 'BeaconStore' -w") # noqa: S605
37-
return bytes.fromhex(key_in_hex)
51+
try:
52+
# This thing will pop up 2 Password Input windows...
53+
key_in_hex = subprocess.getoutput( # noqa: S605
54+
"/usr/bin/security find-generic-password -l 'BeaconStore' -w"
55+
)
56+
return _parse_beaconstore_key_from_hex_output(key_in_hex)
57+
except (ValueError, subprocess.SubprocessError):
58+
output = subprocess.getoutput("/usr/bin/security find-generic-password -l 'BeaconStore'") # noqa: S605
59+
return _parse_beaconstore_key_from_string_output(output)
3860

3961

4062
def _get_accessory_name(

0 commit comments

Comments
 (0)