Expand description
The unlock pipeline and the encryption primitives, on bitwarden-crypto.
The shapes here are the ones the live spike proved against Vaultwarden
1.37.4: the wrapped user key and private key decrypt to bytes (the private
key is PKCS#8 DER, not PEM), the organization key and the RSA-wrapped
attachment keys unwrap with RSA-OAEP-SHA1, and an attachment is the
0x02 | IV | MAC | ciphertext buffer the official clients upload.
Re-exportsΒ§
use std::collections::HashMap;πuse std::num::NonZeroU32;πuse anyhow::Context;πuse anyhow::Result;πuse anyhow::anyhow;πuse anyhow::bail;πuse base64::Engine;πuse bitwarden_crypto::BitwardenLegacyKeyBytes;πuse bitwarden_crypto::EncString;πuse bitwarden_crypto::HashPurpose;πuse bitwarden_crypto::Kdf;πuse bitwarden_crypto::KeyDecryptable;πuse bitwarden_crypto::KeyEncryptable;πuse bitwarden_crypto::MasterKey;πuse bitwarden_crypto::OctetStreamBytes;πuse hmac::Hmac;πuse hmac::KeyInit;πuse hmac::Mac;πuse rsa::pkcs8::DecodePrivateKey;πuse sha2::Digest;πuse sha2::Sha256;πuse zeroize::Zeroizing;πuse crate::vault::VaultError;πuse crate::vault::models::Prelogin;πuse crate::vault::models::Profile;πuse crate::vault::models::TokenResponse;π
StructsΒ§
- Totp
- One computed TOTP code and the window it belongs to.
- Unlocked
- An unlocked accountβs keys: the user key every personal cipher inherits, the account private key, and any organization keys the profile carries.
EnumsΒ§
- Symmetric
Crypto Key - The key type an
Unlockedholds, re-exported so a caller building one for a test can name it. A symmetric encryption key. Used to encrypt and decryptEncString
FunctionsΒ§
- cipher_
key - A cipherβs own key, when the item carries one, else the user/org key it inherits.
- decode_
base32 π - decrypt_
attachment_ blob - Decrypt a downloaded attachment blob.
- decrypt_
bytes - decrypt_
str - derive_
master_ key - Derive the master key from the password and the configured email.
- enc_
string_ type - The EncString type byte of a string, without decoding it:
"2...."givesSome(2). - encrypt_
attachment_ blob - Encrypt an attachment into the uploaded wire form:
0x02 | IV | MAC | ciphertext, identical toEncString::to_buffer. - encrypt_
str - kdf_
from_ prelogin - The KDF a prelogin answer names. An unknown type is an error rather than a guess, because guessing the KDF derives the wrong key.
- kdf_
label - The KDF in one line, for a log line or a refusal message.
- make_
symmetric_ key - A fresh symmetric key for one attachment, in the algorithm the live server stores its blobs with.
- master_
password_ hash - The hash the token endpoint takes as
password. - org_
keys π - Unwrap every organization key the profile carries, naming the ones that failed. A failed org is not fatal to the unlock - the account is still usable - but its ciphers must not be touched with another key.
- parse_
private_ πkey - The account private key is stored as raw PKCS#8 DER by the Bitwarden clients; older exports and other clients may hold PEM or base64 DER, so every shape is tried.
- rsa_
oaep_ πunwrap - sha256_
hex - totp_
from_ uri - Compute a TOTP code from the stored
login.totpvalue: an otpauth URI, or a bare base32 secret (Bitwarden accepts both). The seed never leaves the process. - unlock
- Unwrap the user key, the account private key and the organization keys.
- unlock_
with_ user_ key - Unlock from a user key a client released through its platform authenticator, rather than one derived from the master password.
- unwrap_
attachment_ key - Unwrap an attachment key by its EncString type.
- unwrap_
org_ key - Unwrap an organization key: EncString type 4, RSA-2048-OAEP-SHA1 with the userβs private key. Type 6 is named rather than guessed at.
- unwrap_
symmetric_ key - verify_
type6_ πmac - wire_
from_ πenc_ string - with_
user_ πkey - The half of an unlock that starts from a known user key.
- wrap_
symmetric_ key - wrapped_
user_ πkey - The wrapped user key this unlock will report the fingerprint of. An empty string is a field a client left unset, not a wrapped key; it must not shadow the profileβs real one.