{"record":{"id":"34afd45e53c6e031","repo":"commaai/openpilot","slug":"invalid-profilemetadata","errorCode":null,"errorMessage":"Invalid profileMetadata","messagePattern":"Invalid profileMetadata","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"openpilot/common/esim/lpa.py","lineNumber":601,"sourceCode":"\n  if result is None:\n    raise RuntimeError(\"Profile installation failed: no result from eUICC\")\n  if not result[\"success\"] and result[\"errorReason\"] is not None:\n    msg = BPP_ERROR_MESSAGES.get(result[\"errorReason\"])\n    if not msg:\n      cmd_name = BPP_COMMAND_NAMES.get(result[\"bppCommandId\"], f\"unknown({result['bppCommandId']})\")\n      err_name = BPP_ERROR_REASONS.get(result[\"errorReason\"], f\"unknown({result['errorReason']})\")\n      msg = f\"Profile installation failed at {cmd_name}: {err_name}\"\n    raise RuntimeError(msg)\n  if not result[\"success\"]:\n    raise RuntimeError(\"Profile installation failed: no result from eUICC\")\n  return result\n\n\ndef parse_metadata(b64_metadata: str) -> dict:\n  root = find_tag(b64d(b64_metadata), TAG_PROFILE_METADATA)\n  if root is None:\n    raise RuntimeError(\"Invalid profileMetadata\")\n  return decode_struct(root, PROFILE)\n\n\ndef cancel_session(client: AtClient, transaction_id: bytes, reason: int = 127) -> str:\n  content = encode_tlv(0x80, transaction_id) + encode_tlv(0x81, bytes([reason]))\n  response = es10x_command(client, encode_tlv(TAG_CANCEL_SESSION, content))\n  return b64e(response)\n\n\ndef parse_lpa_activation_code(activation_code: str) -> tuple[str, str]:\n  \"\"\"Parse 'LPA:1$smdp.example.com$MATCHING-ID' into (smdp_address, matching_id).\"\"\"\n  if not activation_code.startswith(\"LPA:\"):\n    raise ValueError(\"Invalid activation code format\")\n  parts = activation_code[4:].split(\"$\")\n  if len(parts) != 3:\n    raise ValueError(\"Invalid activation code format\")\n  return parts[1], parts[2]\n","sourceCodeStart":583,"sourceCodeEnd":619,"githubUrl":"https://github.com/commaai/openpilot/blob/516ec1e68203439a73f340f1d0b3b91eabc626ee/openpilot/common/esim/lpa.py#L583-L619","documentation":"parse_metadata() raises this when the base64-decoded profileMetadata payload does not contain the TAG_PROFILE_METADATA TLV tag. The function expects an ASN.1 DER structure with a profileMetadata root; its absence means the input is not a valid GSMA profileMetadata blob.","triggerScenarios":"Calling parse_metadata(b64_metadata) with a base64 string that decodes without a TAG_PROFILE_METADATA element — e.g. passing an arbitrary server response field or corrupted base64.","commonSituations":"Feeding the wrong field from an SM-DP+ response into parse_metadata; base64 padding/URL-safe alphabet mismatch; truncated metadata from a flaky transfer.","solutions":["Verify the input is the profileMetadata field of the ES9+ response, not another base64 blob","Decode the base64 manually and inspect the TLV tags to confirm structure","Check for base64 URL-safe vs standard alphabet or padding issues before parsing"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from openpilot.common.esim.lpa import find_tag, TAG_PROFILE_METADATA\nfrom base64 import b64decode\n\ndef is_valid_metadata(b64: str) -> bool:\n    try:\n        return find_tag(b64decode(b64), TAG_PROFILE_METADATA) is not None\n    except Exception:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    meta = parse_metadata(b64)\nexcept RuntimeError:\n    log.exception(\"bad profileMetadata from SM-DP+\")\n    raise","preventionTips":["Only pass the profileMetadata field from ES9+ responses","Validate base64 alphabet/padding before parsing"],"tags":["esim","lpa","asn1","parsing"],"backgroundTag":null,"analyzedSha":"516ec1e68203439a73f340f1d0b3b91eabc626ee","analyzedAt":"2026-08-15T00:17:37.461Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}