{"record":{"id":"f55ed1b15d229b3f","repo":"tinyhumansai/openhuman","slug":"invalid-aes-key-e","errorCode":null,"errorMessage":"invalid AES key: {e}","messagePattern":"invalid AES key: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/api/rest.rs","lineNumber":1158,"sourceCode":"        anyhow::bail!(\"encrypted payload too short\");\n    }\n    let iv = &combined[0..16];\n    let tag = &combined[16..32];\n    let ciphertext = &combined[32..];\n\n    // aes-gcm expects ciphertext || tag\n    let mut ct_with_tag = Vec::with_capacity(ciphertext.len() + tag.len());\n    ct_with_tag.extend_from_slice(ciphertext);\n    ct_with_tag.extend_from_slice(tag);\n\n    use aes_gcm::aead::generic_array::typenum::U16;\n    use aes_gcm::aead::{Aead, KeyInit};\n    use aes_gcm::aes::Aes256;\n    use aes_gcm::AesGcm;\n    type Aes256Gcm16 = AesGcm<Aes256, U16>;\n\n    let cipher =\n        Aes256Gcm16::new_from_slice(&key).map_err(|e| anyhow::anyhow!(\"invalid AES key: {e}\"))?;\n    let nonce = aes_gcm::aead::generic_array::GenericArray::from_slice(iv);\n    let plain = cipher\n        .decrypt(nonce, ct_with_tag.as_ref())\n        .map_err(|e| anyhow::anyhow!(\"AES-GCM decrypt failed: {e}\"))?;\n\n    String::from_utf8(plain).context(\"handoff plaintext is not UTF-8\")\n}\n\n/// Decode the shared encryption key into 32 raw AES bytes.\n///\n/// Accepts, in order of preference:\n/// 1. base64url without padding — the current backend format (e.g.\n///    a 43-char alphanumeric string using `-` / `_`). This must be tried\n///    BEFORE standard base64 because `-`/`_` are invalid in the standard\n///    alphabet and would fail cleanly, whereas a standard-base64 string\n///    never contains `-`/`_` so base64url_no_pad will still decode it\n///    correctly as long as there's no padding.\n/// 2. base64url with padding.","sourceCodeStart":1140,"sourceCodeEnd":1176,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/749120085864ce16e0f273c7b86fac7740b39c5b/src/api/rest.rs#L1140-L1176","documentation":"Key-initialisation error in decrypt_handoff_blob (used by fetch_integration_tokens_handoff): constructing the AES-256-GCM cipher from the 32-byte key slice failed. aes-gcm only rejects on a wrong key length, so in practice the handoff key bytes are malformed — wrong length, wrong encoding, or a key from a mismatched device/session — before any ciphertext is touched.","triggerScenarios":"Thrown at src/api/rest.rs:1158 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the handoff key is exactly 32 raw bytes and correctly base64/hex-decoded before being passed","Confirm both sides derive the key from the same device-pairing secret","Re-pair the device if the key material simply does not correspond to this handoff blob"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"749120085864ce16e0f273c7b86fac7740b39c5b","analyzedAt":"2026-08-17T21:21:45.363Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}