Skip to main content

flamberge_keys/
lib.rs

1//! Key acquisition for the DeDRM schemes.
2//!
3//! Two kinds of key source, mirroring the Python tools:
4//! * **Offline generators** (pure crypto, reproducible anywhere): PID encoders
5//!   (`pid`), B&N name+CC keygen (`ignoble`), eReader name+CC key (`ereader`),
6//!   Kobo device-key derivation (`kobo`). These are implemented.
7//! * **Platform extraction** (reads local DRM-app state — registry/DPAPI,
8//!   plists, SQLite): `kindle`, `adobe`. These are stubbed and are the parts
9//!   that require a specific host OS + user profile.
10//!
11//! Reference: `docs/DEDRM_SCHEMES.md` §2.5, §4, §6, §7.2, §8.2, §9.2.
12
13pub mod adobe;
14pub mod ereader;
15pub mod error;
16pub mod ignoble;
17pub mod kindle;
18pub mod kobo;
19pub mod pid;
20
21pub use error::KeyError;
22
23pub type Result<T> = std::result::Result<T, KeyError>;
24
25/// All candidate keys gathered for a decryption attempt. Schemes brute-force the
26/// relevant bucket against the book. Mirrors the plugin's prefs buckets.
27#[derive(Debug, Default, Clone)]
28pub struct KeyStore {
29    /// Explicit Mobipocket/Topaz/KFX PIDs (8- or 10-char).
30    pub pids: Vec<String>,
31    /// Kindle device serial numbers (eInk / android-derived).
32    pub serials: Vec<String>,
33    /// Adobe ADEPT user keys: DER-encoded RSA private keys.
34    pub adept_keys: Vec<Vec<u8>>,
35    /// Barnes & Noble user keys (28-char base64 `ccHash`).
36    pub bandn_keys: Vec<String>,
37    /// eReader user keys (8-byte DES keys, hex in the plugin prefs).
38    pub ereader_keys: Vec<[u8; 8]>,
39    /// Kobo candidate user keys (16-byte AES keys).
40    pub kobo_keys: Vec<[u8; 16]>,
41    /// Raw bytes of the Kobo library SQLite DB (`KoboReader.sqlite` /
42    /// `Kobo.sqlite`). Unlike other schemes, the Kobo per-file wrapped page keys
43    /// live outside the book, in this DB (§9.3); the scheme reads them from here.
44    pub kobo_db: Option<Vec<u8>>,
45    /// Which Kobo volume (book) the input corresponds to. When `None` and the DB
46    /// holds exactly one volume, that volume is used.
47    pub kobo_volumeid: Option<String>,
48    /// Decoded Kindle key databases (from `.k4i` / `.kinf`). Unlike bare
49    /// serials, a full DB carries the account DSN + token, so the Kindle schemes
50    /// derive extra candidate PIDs from it via [`pid::k4_pids`] (§6.2).
51    pub kindle_dbs: Vec<kindle::KindleDb>,
52}
53
54impl KeyStore {
55    pub fn new() -> Self {
56        Self::default()
57    }
58}