كريم أحمد

Reverse-Engineer the Software You Depend On

2 ديسمبر 2026

Here’s a small experiment with a concrete payoff: take a piece of software I genuinely depend on, figure out exactly how it encrypts my data, and turn that knowledge into a backup I fully control. The target: Proton Pass, the password manager.

The result is a Python script that decrypts my entire vault offline, every login and 2FA secret, and re-encrypts it with my own key, every day, without ever touching Proton’s servers after the initial setup.

What follows isn’t the clean path, it’s the real one, dead ends included. Each section describes the wrong turns I took before the thing that actually worked, because that’s usually where the learning is.

Where the data lives

Proton Pass is a browser extension, so its local state sits in Firefox’s IndexedDB. On disk that’s a SQLite file inside the extension’s storage directory.

First dead end: the object-store keys looked like garbage, tubuf, tbmu, tobqtipu. It took a while to notice they’re just state, salt, and snapshot with every letter shifted forward by one (ROT-1). Trivial, but it stopped me cold for a bit.

state    -> tubuf
salt     -> tbmu
snapshot -> tobqtipu

The values are Firefox structured-clone blobs, Snappy-compressed on disk. Two entries matter: 0state (the vault cache) and 0salt (a 32-byte salt).

How the cache is actually encrypted

Second dead end: my first instinct was to feed my login password straight into a key-derivation function and try to decrypt the cache. It failed, and for a good reason, Proton doesn’t encrypt the cache with your raw password at all. There’s a key chain. First, a mailbox key is derived from your password with bcrypt:

keyPassword = bcrypt(loginPassword, KeySalt)

The KeySalt is a server-side value, which matters later. From the mailbox key, a cache key is derived with HKDF:

cacheKey = HKDF-SHA256(ikm=keyPassword, salt=0salt, info="pass-extension-cache-key")

And the cache blob itself is AES-256-GCM, with the AAD fixed to the string "cache":

0state    = AES-256-GCM(cacheKey, nonce=IV, AAD="cache")
0snapshot = AES-256-GCM(cacheKey, nonce=IV, AAD="cache")  // holds the vault key

Third dead end: I also spent a while chasing the “offline” derivation, an Argon2 key derived from my password and a salt stored in the session. That turned out to be a separate offline-verification path, not the cache key. It was a red herring for this goal.

So far, all standard primitives. The real wall is recovering keyPassword.

Recovering the mailbox key

keyPassword is derived from your password plus a server-side KeySalt, so the raw password alone is useless. And the key isn’t written to disk in plaintext.

Dead ends here, in order:

  1. Reading it from the extension’s storage API. I tried to pull the key from browser.storage.session in the debugger. Firefox’s MV3 synthetic background page exposes a storage property but it resolves to undefined, so that whole route was a dead end.
  2. Finding it on disk. The extension’s IndexedDB only held the encrypted cache and its salt, the key itself was never persisted, so there was nothing to read.
  3. The web app, take one. The web app (pass.proton.me) persists a session in localStorage under ps-<localId>, and its blob field is AES-256-GCM encrypted with a random 32-byte clientKey. I captured a key and tried to decrypt, and the GCM tag check failed. The reason: the session is per-UID, and I’d grabbed a key for a different session than the blob I held (three sessions were active).
  4. The moving target. On top of that, the ps-<id> entry vanished on logout and came back under a new local id, so I had to re-sync which blob I was actually decrypting.

What actually worked: the clientKey is generated client-side and pushed to the server during session setup, the key travels in the request body of a PUT, not a GET response:

PUT auth/v4/sessions/local/key   body: { "Key": "<base64>" }

Capture that request (its body), pair it with the matching session’s blob, and the decryption succeeds:

blob = AES-256-GCM(clientKey, 16-byte IV, no AAD)   // payloadVersion=1
// = { keyPassword, offlineKD, sessionLockToken, digest }

That unblocks everything downstream.

The XOR surprise

Once the cache is decrypted, each item’s data is already in plaintext. But the sensitive fields look like {v: "...", m: "..."}.

Dead end: I assumed this was another cipher layer with per-item keys, and went hunting for the item-key derivation. Reading Proton’s source set that straight: it’s plain XOR obfuscation.

plaintext = base64(v) XOR base64(m)

No per-item keys, no extra KDF, the {v,m} pair just keeps the secret out of memory in the clear. XOR it back and you have the password.

Reading Firefox’s on-disk format

Before any crypto, the raw blob has to be decoded. The layout is:

[ varint uncompressed_len ][ raw Snappy stream ]

Dead end: an off-the-shelf Snappy library threw Invalid Snappy bitstream, because Firefox uses the raw block format (no framing) with a varint length prefix, not the framed format the library expected. I ended up writing a ~40-line decoder by hand: a run of literal/copy tags.

After decompression you get a structured-clone value: a 16-byte header, then the payload. The string length (with a high-bit “Latin-1” flag) is the little-endian uint32 at bytes 8-12, and the payload starts at offset 16:

payload = decompressed[16 : 16 + (len & 0x7fffffff)]

One more dead end: my first snapshot decrypt failed because I’d treated the whole remainder as the ciphertext, there’s a trailing padding byte after the string, so the payload length is not simply “the rest of the buffer”. Trimming to the declared length fixed it.

Automating the whole thing

All of the above is wrapped in a single script with no external dependencies beyond Python’s cryptography library. The flow, in order:

  1. Snapshot the database. Dead end: opening the live IndexedDB directly threw database is locked, because Firefox holds it in WAL mode. The fix: copy .sqlite + -wal + -shm to a temp dir and read the copy.
  2. Decode the Snappy + structured-clone wrapper.
  3. Decrypt the cache: HKDF-SHA256 for the key, AES-256-GCM for the blob.
  4. Deobfuscate every {v,m} field by XOR.
  5. Pull 2FA. The Authenticator extension stores TOTP secrets in Firefox’s storage-sync-v2.sqlite, so those are read the same way (copy + parse).
  6. Re-encrypt the combined JSON with my own passphrase.

The export’s encryption is deliberately boring and verifiable:

key    = PBKDF2-HMAC-SHA256(passphrase, salt, iterations=600000, dklen=32)
output = AES-256-GCM(key, nonce=IV, AAD="protonpass-backup-v1")
file   = "PPBK" + salt + IV + (ciphertext + tag)

The file layout is documented so the backup can be decrypted by hand if the script is ever lost. Cron runs the script daily, and an rclone crypt remote syncs the encrypted export off-site. The script is non-fatal: if anything fails it logs and keeps the last good export rather than overwriting it.

Result

One run decrypts the entire vault, every login and every 2FA secret, and writes a single encrypted file. It works while Firefox is open, needs no network after the initial key recovery, and the backup is encrypted with a key that only exists on the local machine.

The broader point isn’t about Proton specifically, the encryption did its job, and this is just reading my own data with my own key. It’s that the tools we depend on are, with enough patience, readable. The key chain is the whole game: find where the data lives, trace where the key comes from, and follow it link by link, and expect to go down a few wrong paths on the way.

Sources

Almost everything here came from reading Proton’s open-source web client (ProtonMail/WebClients) and Firefox’s own source. The key files:

Firefox’s on-disk format:

And the primitives, for reference: HKDF (RFC 5869), PBKDF2 (RFC 8018), AES-GCM (NIST SP 800-38D).