aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: fd577941efc984035e163dfbfa9fd69541666b86 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
mod api;
mod error;
mod identity;
mod prelude;
mod secret;

fn main() {
    let client = api::Client::new_self_hosted("https://bitwarden.tozt.net");

    let email = rprompt::prompt_reply_stderr("Email: ").unwrap();
    let password = rpassword::prompt_password_stderr("Password: ").unwrap();

    let iterations = client.prelogin(&email).unwrap();
    let identity =
        identity::Identity::new(&email, &password, iterations).unwrap();

    let (access_token, _refresh_token, protected_key) = client
        .login(&identity.email, &identity.master_password_hash)
        .unwrap();

    let protected_key = secret::Secret::new(&protected_key).unwrap();
    let master_key = protected_key
        .decrypt(&identity.enc_key, &identity.mac_key)
        .unwrap();

    let enc_key = &master_key[0..32];
    let mac_key = &master_key[32..64];

    let ciphers = client.sync(&access_token).unwrap();
    for cipher in ciphers {
        let secret_name = secret::Secret::new(&cipher.name).unwrap();
        let name = secret_name.decrypt(enc_key, mac_key).unwrap();
        let secret_username =
            secret::Secret::new(&cipher.login.username).unwrap();
        let username = secret_username.decrypt(enc_key, mac_key).unwrap();
        let secret_password =
            secret::Secret::new(&cipher.login.password).unwrap();
        let password = secret_password.decrypt(enc_key, mac_key).unwrap();
        println!("{}:", String::from_utf8(name).unwrap());
        println!("  Username: {}", String::from_utf8(username).unwrap());
        println!("  Password: {}", String::from_utf8(password).unwrap());
    }
}