tinyhumansai/openhuman · error · anyhow::Error

invalid AES key

Error message

invalid AES key: {e}

What it means

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.

Solutions

  1. Verify the handoff key is exactly 32 raw bytes and correctly base64/hex-decoded before being passed
  2. Confirm both sides derive the key from the same device-pairing secret
  3. Re-pair the device if the key material simply does not correspond to this handoff blob
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/api/rest.rs:1158 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tinyhumansai/openhuman@7491200858 (2026-08-17). Data as JSON: /api/errors/f55ed1b15d229b3f. Report an issue: GitHub.

Appendix: source

Thrown at src/api/rest.rs:1158

        anyhow::bail!("encrypted payload too short");
    }
    let iv = &combined[0..16];
    let tag = &combined[16..32];
    let ciphertext = &combined[32..];

    // aes-gcm expects ciphertext || tag
    let mut ct_with_tag = Vec::with_capacity(ciphertext.len() + tag.len());
    ct_with_tag.extend_from_slice(ciphertext);
    ct_with_tag.extend_from_slice(tag);

    use aes_gcm::aead::generic_array::typenum::U16;
    use aes_gcm::aead::{Aead, KeyInit};
    use aes_gcm::aes::Aes256;
    use aes_gcm::AesGcm;
    type Aes256Gcm16 = AesGcm<Aes256, U16>;

    let cipher =
        Aes256Gcm16::new_from_slice(&key).map_err(|e| anyhow::anyhow!("invalid AES key: {e}"))?;
    let nonce = aes_gcm::aead::generic_array::GenericArray::from_slice(iv);
    let plain = cipher
        .decrypt(nonce, ct_with_tag.as_ref())
        .map_err(|e| anyhow::anyhow!("AES-GCM decrypt failed: {e}"))?;

    String::from_utf8(plain).context("handoff plaintext is not UTF-8")
}

/// Decode the shared encryption key into 32 raw AES bytes.
///
/// Accepts, in order of preference:
/// 1. base64url without padding — the current backend format (e.g.
///    a 43-char alphanumeric string using `-` / `_`). This must be tried
///    BEFORE standard base64 because `-`/`_` are invalid in the standard
///    alphabet and would fail cleanly, whereas a standard-base64 string
///    never contains `-`/`_` so base64url_no_pad will still decode it
///    correctly as long as there's no padding.
/// 2. base64url with padding.

View on GitHub (pinned to 7491200858)