mirror of
https://github.com/smittix/intercept.git
synced 2026-07-07 00:58:12 -07:00
style: apply ruff-format to entire codebase
First-time run of ruff-format via pre-commit hook normalises quote style, trailing commas, and whitespace across 188 Python files. No logic changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,7 +11,7 @@ import platform
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
logger = logging.getLogger('intercept.bt.irk_extractor')
|
||||
logger = logging.getLogger("intercept.bt.irk_extractor")
|
||||
|
||||
# Cache paired IRKs for 30 seconds to avoid repeated disk reads
|
||||
_cache: list[dict] | None = None
|
||||
@@ -38,9 +38,9 @@ def get_paired_irks() -> list[dict]:
|
||||
|
||||
system = platform.system()
|
||||
try:
|
||||
if system == 'Darwin':
|
||||
if system == "Darwin":
|
||||
results = _extract_macos()
|
||||
elif system == 'Linux':
|
||||
elif system == "Linux":
|
||||
results = _extract_linux()
|
||||
else:
|
||||
logger.debug(f"IRK extraction not supported on {system}")
|
||||
@@ -58,24 +58,24 @@ def _extract_macos() -> list[dict]:
|
||||
"""Extract IRKs from macOS Bluetooth plist."""
|
||||
import plistlib
|
||||
|
||||
plist_path = Path('/Library/Preferences/com.apple.Bluetooth.plist')
|
||||
plist_path = Path("/Library/Preferences/com.apple.Bluetooth.plist")
|
||||
if not plist_path.exists():
|
||||
logger.debug("macOS Bluetooth plist not found")
|
||||
return []
|
||||
|
||||
with open(plist_path, 'rb') as f:
|
||||
with open(plist_path, "rb") as f:
|
||||
plist = plistlib.load(f)
|
||||
|
||||
devices = []
|
||||
|
||||
cache_data = plist.get('CoreBluetoothCache', {})
|
||||
cache_data = plist.get("CoreBluetoothCache", {})
|
||||
|
||||
# CoreBluetoothCache contains BLE device info including IRKs
|
||||
for device_uuid, device_info in cache_data.items():
|
||||
if not isinstance(device_info, dict):
|
||||
continue
|
||||
|
||||
irk = device_info.get('IRK')
|
||||
irk = device_info.get("IRK")
|
||||
if irk is None:
|
||||
continue
|
||||
|
||||
@@ -83,57 +83,61 @@ def _extract_macos() -> list[dict]:
|
||||
if isinstance(irk, bytes) and len(irk) == 16:
|
||||
irk_hex = irk.hex()
|
||||
elif isinstance(irk, str):
|
||||
irk_hex = irk.replace('-', '').replace(' ', '')
|
||||
irk_hex = irk.replace("-", "").replace(" ", "")
|
||||
if len(irk_hex) != 32:
|
||||
continue
|
||||
else:
|
||||
continue
|
||||
|
||||
name = device_info.get('Name') or device_info.get('DeviceName')
|
||||
address = device_info.get('DeviceAddress', device_uuid)
|
||||
addr_type = 'random' if device_info.get('AddressType', 1) == 1 else 'public'
|
||||
name = device_info.get("Name") or device_info.get("DeviceName")
|
||||
address = device_info.get("DeviceAddress", device_uuid)
|
||||
addr_type = "random" if device_info.get("AddressType", 1) == 1 else "public"
|
||||
|
||||
devices.append({
|
||||
'name': name,
|
||||
'address': str(address),
|
||||
'irk_hex': irk_hex,
|
||||
'address_type': addr_type,
|
||||
})
|
||||
devices.append(
|
||||
{
|
||||
"name": name,
|
||||
"address": str(address),
|
||||
"irk_hex": irk_hex,
|
||||
"address_type": addr_type,
|
||||
}
|
||||
)
|
||||
|
||||
# Also check LEPairedDevices / PairedDevices structures
|
||||
for section_key in ('LEPairedDevices', 'PairedDevices'):
|
||||
for section_key in ("LEPairedDevices", "PairedDevices"):
|
||||
section = plist.get(section_key, {})
|
||||
if not isinstance(section, dict):
|
||||
continue
|
||||
for addr, dev_info in section.items():
|
||||
if not isinstance(dev_info, dict):
|
||||
continue
|
||||
irk = dev_info.get('IRK') or dev_info.get('IdentityResolvingKey')
|
||||
irk = dev_info.get("IRK") or dev_info.get("IdentityResolvingKey")
|
||||
if irk is None:
|
||||
continue
|
||||
|
||||
if isinstance(irk, bytes) and len(irk) == 16:
|
||||
irk_hex = irk.hex()
|
||||
elif isinstance(irk, str):
|
||||
irk_hex = irk.replace('-', '').replace(' ', '')
|
||||
irk_hex = irk.replace("-", "").replace(" ", "")
|
||||
if len(irk_hex) != 32:
|
||||
continue
|
||||
else:
|
||||
continue
|
||||
|
||||
# Skip if we already have this IRK
|
||||
if any(d['irk_hex'] == irk_hex for d in devices):
|
||||
if any(d["irk_hex"] == irk_hex for d in devices):
|
||||
continue
|
||||
|
||||
name = dev_info.get('Name') or dev_info.get('DeviceName')
|
||||
addr_type = 'random' if dev_info.get('AddressType', 1) == 1 else 'public'
|
||||
name = dev_info.get("Name") or dev_info.get("DeviceName")
|
||||
addr_type = "random" if dev_info.get("AddressType", 1) == 1 else "public"
|
||||
|
||||
devices.append({
|
||||
'name': name,
|
||||
'address': str(addr),
|
||||
'irk_hex': irk_hex,
|
||||
'address_type': addr_type,
|
||||
})
|
||||
devices.append(
|
||||
{
|
||||
"name": name,
|
||||
"address": str(addr),
|
||||
"irk_hex": irk_hex,
|
||||
"address_type": addr_type,
|
||||
}
|
||||
)
|
||||
|
||||
logger.info(f"Extracted {len(devices)} IRK(s) from macOS paired devices")
|
||||
return devices
|
||||
@@ -147,7 +151,7 @@ def _extract_linux() -> list[dict]:
|
||||
"""
|
||||
import configparser
|
||||
|
||||
bt_root = Path('/var/lib/bluetooth')
|
||||
bt_root = Path("/var/lib/bluetooth")
|
||||
if not bt_root.exists():
|
||||
logger.debug("BlueZ bluetooth directory not found")
|
||||
return []
|
||||
@@ -161,7 +165,7 @@ def _extract_linux() -> list[dict]:
|
||||
if not device_dir.is_dir():
|
||||
continue
|
||||
|
||||
info_file = device_dir / 'info'
|
||||
info_file = device_dir / "info"
|
||||
if not info_file.exists():
|
||||
continue
|
||||
|
||||
@@ -171,28 +175,30 @@ def _extract_linux() -> list[dict]:
|
||||
except (configparser.Error, OSError):
|
||||
continue
|
||||
|
||||
if not config.has_section('IdentityResolvingKey'):
|
||||
if not config.has_section("IdentityResolvingKey"):
|
||||
continue
|
||||
|
||||
irk_hex = config.get('IdentityResolvingKey', 'Key', fallback=None)
|
||||
irk_hex = config.get("IdentityResolvingKey", "Key", fallback=None)
|
||||
if not irk_hex:
|
||||
continue
|
||||
|
||||
# BlueZ stores as hex string, may or may not have separators
|
||||
irk_hex = irk_hex.replace(' ', '').replace('-', '')
|
||||
irk_hex = irk_hex.replace(" ", "").replace("-", "")
|
||||
if len(irk_hex) != 32:
|
||||
continue
|
||||
|
||||
name = config.get('General', 'Name', fallback=None)
|
||||
name = config.get("General", "Name", fallback=None)
|
||||
address = device_dir.name # Directory name is the MAC address
|
||||
addr_type = config.get('General', 'AddressType', fallback=None)
|
||||
addr_type = config.get("General", "AddressType", fallback=None)
|
||||
|
||||
devices.append({
|
||||
'name': name,
|
||||
'address': address,
|
||||
'irk_hex': irk_hex,
|
||||
'address_type': addr_type,
|
||||
})
|
||||
devices.append(
|
||||
{
|
||||
"name": name,
|
||||
"address": address,
|
||||
"irk_hex": irk_hex,
|
||||
"address_type": addr_type,
|
||||
}
|
||||
)
|
||||
|
||||
logger.info(f"Extracted {len(devices)} IRK(s) from BlueZ paired devices")
|
||||
return devices
|
||||
|
||||
Reference in New Issue
Block a user