AirPods 키

AirPods는 Bluetooth Low Energy(BLE)로 1초에 여러 번 상태를 브로드캐스트합니다. 각 브로드캐스트의 일부는 공개되어 있고 일부는 암호화되어 있습니다. 키가 없으면 CAPod은 공개 부분을 읽습니다: 10% 단위의 배터리, 충전 상태, 케이스 뚜껑, 착용 상태. 내 AirPods의 키 두 개가 있으면 더 많은 정보를 얻을 수 있습니다.

키는 AirPods가 어떤 휴대폰이나 컴퓨터와 페어링되어 있든 같습니다.

이 키는 내 AirPods에 속한 정보입니다. 공개 이슈, 채팅, 스크린샷에 올리지 마세요.

자동 가져오기

직접 연결을 지원하는 휴대폰에서는 CAPod이 연결할 때 AirPods에 두 키를 요청하고, 페어링 된 기기가 해당 AirPods인 프로필에 저장합니다. 따로 할 일은 없습니다. 프로필을 열면 두 키 모두 구성됨으로 표시됩니다.

휴대폰이 직접 연결을 지원하지 않거나 키가 계속 설정되지 않음으로 남아 있다면 키를 수동으로 추출하세요.

수동 추출

Android에는 키를 보여 주는 방법이 없으므로, 수동으로 추출하려면 AirPods와 페어링된 컴퓨터가 필요합니다.

macOS에서 스크립트 사용

이 스크립트는 페어링된 모든 AirPods 또는 Beats 기기의 키를 macOS 키체인에서 읽습니다. macOS는 접근을 허용하기 전에 암호를 묻습니다.

get_airpod_keys.sh
#!/usr/bin/env bash

set -u

SYSTEM_KEYCHAIN="/Library/Keychains/System.keychain"

usage() {
  cat <<'EOF'
Usage:
  ./get_airpod_keys.sh
  ./get_airpod_keys.sh --address AA:BB:CC:DD:EE:FF

Extracts AirPods / Beats MagicAcc keys from the macOS MobileBluetooth
Keychain item for CAPod:
  - MagicAccIRK     -> CAPod Identity key
  - MagicAccEncKey  -> CAPod Encryption key

macOS may show Keychain permission prompts. These keys are sensitive.
EOF
}

normalize_mac() {
  printf '%s\n' "$1" | tr '[:lower:]' '[:upper:]'
}

discover_bluetooth_addresses() {
  system_profiler SPBluetoothDataType -json 2>/dev/null \
    | awk -F '"' '/"device_address"[[:space:]]*:/ { print $4 }' \
    | sort -u
}

lookup_mobilebluetooth_item() {
  local address="$1"

  security find-generic-password \
    -a "$address" \
    -s MobileBluetooth \
    -g "$SYSTEM_KEYCHAIN" 2>&1
}

extract_plist_value() {
  local key="$1"

  # security(1) prints the password plist as an escaped one-line string, so
  # this intentionally parses the <key>...</key><string>...</string> pattern.
  sed -nE "s/.*<key>${key}<\\/key>[^<]*<string>([^<]+)<\\/string>.*/\\1/p"
}

print_keys_for_address() {
  local address="$1"
  local output
  local irk
  local enc_key
  local local_address

  output="$(lookup_mobilebluetooth_item "$address")"

  irk="$(printf '%s\n' "$output" | extract_plist_value "MagicAccIRK")"
  enc_key="$(printf '%s\n' "$output" | extract_plist_value "MagicAccEncKey")"
  local_address="$(printf '%s\n' "$output" | extract_plist_value "LocalAddress")"

  if [[ -z "$irk" || -z "$enc_key" ]]; then
    return 1
  fi

  printf 'Bluetooth address: %s\n' "$address"
  if [[ -n "$local_address" ]]; then
    printf 'Local Mac address: %s\n' "$local_address"
  fi
  printf 'CAPod Identity key / MagicAccIRK:\n%s\n\n' "$irk"
  printf 'CAPod Encryption key / MagicAccEncKey:\n%s\n' "$enc_key"
  printf '%s\n' '---'
  return 0
}

main() {
  local addresses=()
  local found=0

  while [[ $# -gt 0 ]]; do
    case "$1" in
      --address|-a)
        if [[ $# -lt 2 ]]; then
          usage >&2
          exit 2
        fi
        addresses+=("$(normalize_mac "$2")")
        shift 2
        ;;
      --help|-h)
        usage
        exit 0
        ;;
      *)
        printf 'Unknown argument: %s\n\n' "$1" >&2
        usage >&2
        exit 2
        ;;
    esac
  done

  if [[ ${#addresses[@]} -eq 0 ]]; then
    while IFS= read -r address; do
      [[ -n "$address" ]] && addresses+=("$(normalize_mac "$address")")
    done < <(discover_bluetooth_addresses)
  fi

  if [[ ${#addresses[@]} -eq 0 ]]; then
    printf 'No Bluetooth device addresses found. Try --address AA:BB:CC:DD:EE:FF\n' >&2
    exit 1
  fi

  for address in "${addresses[@]}"; do
    if print_keys_for_address "$address"; then
      found=1
    fi
  done

  if [[ "$found" -eq 0 ]]; then
    printf 'No MobileBluetooth entries with MagicAccIRK/MagicAccEncKey were found.\n' >&2
    printf 'Make sure the AirPods are paired with this Mac, then try again.\n' >&2
    exit 1
  fi
}

main "$@"

@akshaynexus가 #597에서 기여했습니다.

macOS에서 더 짧은 스크립트 사용

이 더 짧은 대안은 일반 sh로 실행되며 python3가 필요합니다. 연결된 AirPods 또는 Beats 기기 중 첫 번째 기기의 키를 읽으므로, 먼저 Mac에 연결하세요. sh airpod_key_retrieval_posix.sh로 실행하세요. 키 필드가 비어 있다면 macOS가 키체인 접근을 거부했거나 AirPods가 이 Mac과 페어링되어 있지 않은 것입니다.

airpod_key_retrieval_posix.sh
ADDR="$(
  system_profiler SPBluetoothDataType -json 2>/dev/null |
  python3 -c '
import json, sys, re

data = json.load(sys.stdin)

for controller in data.get("SPBluetoothDataType", []):
    for item in controller.get("device_connected", []):
        for name, info in item.items():
            if re.search(r"AirPods|Beats", name, re.I):
                print(info.get("device_address", ""))
                raise SystemExit
'
)"

if [ -z "$ADDR" ]; then
  echo "No connected AirPods or Beats device found."
  exit 1
fi

OUT="$(security find-generic-password \
  -a "$ADDR" \
  -s MobileBluetooth \
  -g /Library/Keychains/System.keychain 2>&1)"

IRK="$(printf '%s\n' "$OUT" |
  sed -nE 's/.*<key>MagicAccIRK<\/key>[^<]*<string>([^<]+)<\/string>.*/\1/p')"

ENC="$(printf '%s\n' "$OUT" |
  sed -nE 's/.*<key>MagicAccEncKey<\/key>[^<]*<string>([^<]+)<\/string>.*/\1/p')"

LOCAL="$(printf '%s\n' "$OUT" |
  sed -nE 's/.*<key>LocalAddress<\/key>[^<]*<string>([^<]+)<\/string>.*/\1/p')"

printf '\nAirPods Keys\n'
printf '%s\n' '--------------------------------------------'
printf 'AirPods Address : %s\n' "$ADDR"
printf 'Mac Address     : %s\n' "$LOCAL"
printf 'Identity Key    : %s\n' "$IRK"
printf 'Encryption Key  : %s\n' "$ENC"
printf '%s\n' '--------------------------------------------'

@ikcv가 #597에서 기여했습니다.

macOS에서 키체인 접근 사용

스크립트 없이도 되지만, 모든 macOS 버전에서 되는 것은 아닙니다.

  1. AirPods를 Mac과 페어링하세요.
  2. Option 키를 누른 채 메뉴 막대의 블루투스 아이콘을 클릭하세요. AirPods의 주소를 적어 두세요(예: 9C:FC:…).
  3. 키체인 접근을 열고 MobileBluetooth를 검색하세요. 항목이 여러 개 있을 수 있습니다. 계정이 2단계의 주소인 항목을 여세요.
  4. 암호 보기를 체크하고 요청되면 암호를 입력하세요. macOS가 여러 번 물을 수 있습니다.
  5. 암호 필드의 텍스트를 복사하세요. 짧은 XML 문서입니다. MagicAccIRK가 ID 키이고 MagicAccEncKey가 암호화 키입니다.
<key>MagicAccEncKey</key>
<string>3A-9C-81-57-E6-44-7F-F2-FB-8E-07-63-6C-99-E1-29</string>
<key>MagicAccIRK</key>
<string>71-44-65-1E-E2-CA-D1-26-F2-4E-20-EE-3E-CC-DE-77</string>

Linux

이 Python 스크립트는 페어링된 AirPods에 연결해 키를 요청합니다. AirPods의 블루투스 주소를 인수로 전달하세요.

airpod_key_retrieval.py
import sys
import socket

PROXIMITY_KEY_TYPES = {
    0x01: "IRK",
    0x04: "ENC_KEY",
}

def parse_proximity_keys_response(data):
    if len(data) < 7 or data[4] != 0x31:
        return None
    key_count = data[6]
    keys = []
    offset = 7
    for _ in range(key_count):
        if offset + 3 >= len(data):
            break
        key_type = data[offset]
        key_length = data[offset + 2]
        offset += 4
        if offset + key_length > len(data):
            break
        key_bytes = data[offset:offset + key_length]
        keys.append((PROXIMITY_KEY_TYPES.get(key_type, f"TYPE_{key_type:02X}"), key_bytes))
        offset += key_length
    return keys

def hexdump(data):
    return " ".join(f"{b:02X}" for b in data)

def main():
    if len(sys.argv) != 2:
        print(f"Usage: {sys.argv[0]} <MAC>")
        sys.exit(1)

    bdaddr = sys.argv[1]
    PSM = 0x1001

    handshake = bytes.fromhex("00 00 04 00 01 00 02 00 00 00 00 00 00 00 00 00")
    key_req = bytes.fromhex("04 00 04 00 30 00 05 00")

    sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_SEQPACKET, socket.BTPROTO_L2CAP)
    sock.connect((bdaddr, PSM))
    sock.send(handshake)
    sock.send(key_req)

    try:
        while True:
            pkt = sock.recv(1024)
            keys = parse_proximity_keys_response(pkt)
            if keys is not None:
                print("Proximity Keys:")
                for name, key_bytes in keys:
                    print(f"  {name}: {hexdump(key_bytes)}")
                break
    finally:
        sock.close()

if __name__ == "__main__":
    main()

@kavishdevar가 #290에서 기여했습니다.

Windows

AirPods에서 작동하는지는 아직 확인되지 않았습니다. Home Assistant Private BLE Device 가이드에서 Windows 레지스트리로부터 기기의 ID 키를 읽는 방법을 설명합니다.

#757에서 보고되었습니다.

가상 머신이 있는 모든 컴퓨터

@2Elvin의 가이드는 가상 머신에서 macOS를 실행해 어떤 플랫폼에서든 키를 추출합니다.

CAPod에 키 입력

  1. 설정, 장치를 열고 프로필을 누르세요.
  2. ID 키를 누르고 ID 키(MagicAccIRK, 또는 Linux 스크립트의 IRK)를 붙여 넣으세요.
  3. 암호화 키를 누르고 암호화 키(MagicAccEncKey, 또는 ENC_KEY)를 붙여 넣으세요.
  4. 프로필을 저장하세요.

CAPod은 대시, 공백이 있거나 없는 키를 모두 받습니다(예: 71-44-65-1E-…). 두 키가 모두 작동하면 대시보드에 AirPods의 정확한 배터리 퍼센트가 표시됩니다.