• Stars
    star
    113
  • Rank 309,170 (Top 7 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rust KeePass database file parser for KDB, KDBX3 and KDBX4, with experimental support for KDBX4 writing.

keepass-rs

Crates.io Documentation Build Status codecov dependency status License file

Rust KeePass database file parser for KDB, KDBX3 and KDBX4, with experimental support for KDBX4 writing.

Usage

Open a database

use keepass::{
    db::NodeRef,
    Database,
    DatabaseKey,
    error::DatabaseOpenError
};
use std::fs::File;

fn main() -> Result<(), DatabaseOpenError> {
    // Open KeePass database using a password (keyfile is also supported)
    let mut file = File::open("tests/resources/test_db_with_password.kdbx")?;
    let key = DatabaseKey::new().with_password("demopass");
    let db = Database::open(&mut file, key)?;

    // Iterate over all `Group`s and `Entry`s
    for node in &db.root {
        match node {
            NodeRef::Group(g) => {
                println!("Saw group '{0}'", g.name);
            },
            NodeRef::Entry(e) => {
                let title = e.get_title().unwrap_or("(no title)");
                let user = e.get_username().unwrap_or("(no username)");
                let pass = e.get_password().unwrap_or("(no password)");
                println!("Entry '{0}': '{1}' : '{2}'", title, user, pass);
            }
        }
    }

    Ok(())
}

Save a KDBX4 database (EXPERIMENTAL)

IMPORTANT: The inner XML data structure will be re-written from scratch from the internal object representation of this crate, so any field that is not parsed by the library will be lost in the written output file! Please make sure to back up your database before trying this feature.

You can enable the experimental support for saving KDBX4 databases using the save_kdbx4 feature.

use keepass::{
    db::{Database, Entry, Group, Node, NodeRef, Value},
    DatabaseKey,
};
use std::fs::File;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut db = Database::new(Default::default());

    db.meta.database_name = Some("Demo database".to_string());

    let mut group = Group::new("Demo group");

    let mut entry = Entry::new();
    entry.fields.insert("Title".to_string(), Value::Unprotected("Demo entry".to_string()));
    entry.fields.insert("UserName".to_string(), Value::Unprotected("jdoe".to_string()));
    entry.fields.insert("Password".to_string(), Value::Protected("hunter2".as_bytes().into()));

    group.add_child(entry);

    db.root.add_child(group);

    #[cfg(feature = "save_kdbx4")]
    db.save(
        &mut File::create("demo.kdbx")?,
        DatabaseKey::new().with_password("demopass"),
    )?;

    Ok(())
}

Use developer tools

This crate contains several command line tools that can be enabled with the utilities feature flag. See the [[bin]] sections in Cargo.toml for a complete list.

An example command line for running the kp-dump-xml command would be:

cargo run --release --features "utilities" --bin kp-dump-xml -- path/to/database.kdbx

Installation

Add the following to the dependencies section of your Cargo.toml:

[dependencies]
keepass = "*" # TODO replace with current version

Performance Notes

Please set the RUSTFLAGS environment variable when compiling to enable CPU-specific optimizations (this greatly affects the speed of the AES key derivation):

export RUSTFLAGS='-C target-cpu=native'

For best results, also compile in Release mode.

Alternatively, you can add a .cargo/config.toml like in this project to ensure that rustflags are always set.

For AArch64 / ARMv8:

The aes optimizations are not yet enabled on stable rust. If you want a big performance boost you can build using nightly and enabling the armv8 feature of the aes crate:

[dependencies.aes]
# Needs at least 0.7.5 for the feature
version = "0.7.5"
features = ["armv8"]

License

MIT

More Repositories

1

OCRmyPDF-web

A tiny frontend for OCRing PDF files via the web.
JavaScript
45
star
2

Py2D

Game utility library for vector-based games in Python
Python
36
star
3

pavolume

Simple command-line volume control for PulseAudio with libnotify messages
Python
33
star
4

qstat-pretty

Pretty GridEngine, Torque and Platform LSF status tables
Python
31
star
5

mixem

Pythonic Expectation-Maximization (EM) implementation for fitting mixtures of probability densities
Python
26
star
6

NEOW

Node.js Eve Online API Wrapper (with Promises)
CoffeeScript
20
star
7

svelte-colorpick

Color picker for Svelte
Svelte
15
star
8

TermPalette

Terminal ANSI color palette previewer
Python
13
star
9

docker-mini-php

A super-lightweight docker image for serving PHP apps over HTTP: Alpine Linux + runit + lighttpd + php-fpm
9
star
10

ThreeJS-Fractal

A pretty mandelbrot set in WebGL and GLSL using Three.js
JavaScript
9
star
11

SSHGrid

Poor-man's grid computing via SSH
Perl
6
star
12

docker-graphviz

Simple REST Microservice for rendering Graphviz graphs from DOT files
Python
6
star
13

docker-mini-piwik

A minimal Dockerfile for running Piwik (also in dokku)
5
star
14

hug_middleware_cors

DEPRECATED: this has been merged into the main hug project
Python
5
star
15

docker-tabula-java

A minimal docker image for running tabula-java for PDF table extraction
5
star
16

BioPython-A3MIO

A3M/A2M support for BioPython
Python
5
star
17

PyLBFGS

NumPy/Ctypes Python bindings for libLBFGS
Python
5
star
18

ParOpt

Generic command-line parameter optimization
Python
4
star
19

commonr

CommonJS Module/1.1 - style module management for R
R
4
star
20

PyMOL-RR

CASP RR file visualization for PyMOL
Python
3
star
21

PyHiero

Hiero Bitmap Font parser + renderer for Python (and optionally Pygame)
Python
3
star
22

LudumDare27-10Seconds

My entry for the 27th Ludum Dare compo
Python
2
star
23

ggez-specs

Gluing together ggez and specs
Rust
2
star
24

Zapply

Batch-run commands with zsh globbing and pattern matching
Shell
2
star
25

rust-musl-builder-mingw

rust-musl-builder + mingw -> cross-compile rust code for windows using the x86_64-pc-windows-gnu target
2
star
26

aoc2015

Advent of code 2015, in Rust
Rust
2
star
27

ParseOpt

Small and simple MIT-licensed command line parser in C
C
2
star
28

aoc

Advent of Code, in Rust
Rust
2
star
29

aoc2019

Advent of Code 2019, in Rust
Rust
2
star
30

RPSBot

A Rock-Paper-Scissors game that learns how you play
JavaScript
2
star
31

autodev.R

Automatic graphics device creation from a string identifier / filename
R
1
star
32

mini-helloworld-httpd

Competing for the smallest-possible 'Hello World' HTTP server
C
1
star
33

ffindex-python

ffindex support for Python
Python
1
star
34

LudumDare26-Minimalism

Code for my Ludum Dare 26 entry "The Migration"
Python
1
star
35

awesome-config

My configuration for the awesome window manager
Lua
1
star
36

dssp_packager

Script for generating DSSP Debian Packages
1
star
37

msacounts

A python module for fast, C-accelerated counting of residue frequencies and residue pair frequencies in multiple sequence alignments (MSAs)
C
1
star
38

actix-rust-s3-experiment

Minimal experiment to show interplay between actix-web and rust-s3
Rust
1
star
39

DarlingJS-Boilerplate

Boilerplate for making games with Darling.js
CoffeeScript
1
star
40

MPIBPC-Kantine

Automatically parsing and translating what's for lunch at the Max Planck Institute for Biophysical Chemistry
HTML
1
star
41

overseer

Monitor a docker socket and list tagged services in an API endpoint
Rust
1
star