aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-05-09 00:26:05 +0200
committerKatharina Fey <kookie@spacekookie.de>2018-05-09 00:26:05 +0200
commit659eaa9ff296ae3e03362593ee756cbe6d1f42ed (patch)
tree9489e5d205fb4fc0975cd21e41357ad3c2f80af1
parent2d95fbfce49cbb3decbe819aefb9bae1491d1469 (diff)
Bumping version on core and crypto
-rw-r--r--Cargo.lock35
-rw-r--r--lockchain-core/Cargo.toml2
-rw-r--r--lockchain-core/src/crypto.rs2
-rw-r--r--lockchain-core/src/crypto/data.rs15
-rw-r--r--lockchain-core/src/crypto/keys.rs13
-rw-r--r--lockchain-core/src/lib.rs2
-rw-r--r--lockchain-crypto/Cargo.toml4
-rw-r--r--lockchain-crypto/src/data.rs13
-rw-r--r--lockchain-crypto/src/engine.rs72
-rw-r--r--lockchain-crypto/src/lib.rs2
-rw-r--r--lockchain-files/Cargo.toml8
-rw-r--r--lockchain-files/src/fs.rs47
-rw-r--r--lockchain-files/src/lib.rs80
-rw-r--r--lockchain-files/src/vault.rs0
14 files changed, 233 insertions, 62 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 1f48669..7c6bc19 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -539,7 +539,22 @@ dependencies = [
[[package]]
name = "lockchain-core"
-version = "0.4.0"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "base64 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "bcrypt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "blake2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "chrono 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "lockchain-core"
+version = "0.5.0"
dependencies = [
"base64 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bcrypt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -553,9 +568,9 @@ dependencies = [
[[package]]
name = "lockchain-crypto"
-version = "0.1.0"
+version = "0.2.0"
dependencies = [
- "lockchain-core 0.4.0",
+ "lockchain-core 0.5.0",
"miscreant 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -564,16 +579,19 @@ dependencies = [
[[package]]
name = "lockchain-files"
version = "0.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "lockchain-core 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lockchain-core 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lockchain-files"
-version = "0.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
+version = "0.1.0"
dependencies = [
- "lockchain-core 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lockchain-core 0.5.0",
+ "serde 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -602,7 +620,7 @@ name = "lockchain-server"
version = "0.1.0"
dependencies = [
"clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "lockchain-core 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lockchain-core 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lockchain-files 0.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lockchain-http 0.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1424,6 +1442,7 @@ dependencies = [
"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b"
"checksum linked-hash-map 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "70fb39025bc7cdd76305867c4eccf2f2dcf6e9a57f5b21a93e1c2d86cd03ec9e"
"checksum lockchain-core 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8cc843193c0f63da17232b600423a6da3117a86ed43b91652ab81300d017f0c1"
+"checksum lockchain-core 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d8734dcfea6d8b3a58dfcb8acb68ad2beac6e3dc3c31b50d3b4352d1317c5052"
"checksum lockchain-files 0.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c6404bea015818d89ea81e86c6eb463cfc0e0599a04c67bfcfbb285f4ff4133"
"checksum lockchain-http 0.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cfef9fc7585ca94e9f5294854d208914fbff1bbd85a7f47a3e335665b08df302"
"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
diff --git a/lockchain-core/Cargo.toml b/lockchain-core/Cargo.toml
index a46e26c..3570625 100644
--- a/lockchain-core/Cargo.toml
+++ b/lockchain-core/Cargo.toml
@@ -5,7 +5,7 @@ documentation = "https://docs.rs/lockchain-core"
homepage = "https://github.com/spacekookie/lockchain/tree/master/lockchain-core"
readme = "README.md"
license = "MIT/X11 OR Apache-2.0"
-version = "0.4.1"
+version = "0.5.0"
authors = ["Katharina Fey <kookie@spacekookie.de>"]
[dependencies]
diff --git a/lockchain-core/src/crypto.rs b/lockchain-core/src/crypto.rs
index b00f79a..3bba5a2 100644
--- a/lockchain-core/src/crypto.rs
+++ b/lockchain-core/src/crypto.rs
@@ -5,6 +5,8 @@
mod keys;
mod utils;
+mod data;
pub use self::keys::{Key, KEY_LENGTH};
+pub use self::data::PackedData;
pub use self::utils::*; \ No newline at end of file
diff --git a/lockchain-core/src/crypto/data.rs b/lockchain-core/src/crypto/data.rs
new file mode 100644
index 0000000..b87f0dc
--- /dev/null
+++ b/lockchain-core/src/crypto/data.rs
@@ -0,0 +1,15 @@
+use traits::AutoEncoder;
+
+/// Represents some encrypted packed data
+///
+/// Includes nonce, vault iv and blob. This abstraction
+/// is important to be able to send encrypted records across
+/// a network.
+#[derive(Serialize, Deserialize)]
+pub struct PackedData {
+ pub nonce: Vec<u8>,
+ pub iv: Vec<u8>,
+ pub data: Vec<u8>,
+}
+
+impl AutoEncoder for PackedData {} \ No newline at end of file
diff --git a/lockchain-core/src/crypto/keys.rs b/lockchain-core/src/crypto/keys.rs
index f132075..6211851 100644
--- a/lockchain-core/src/crypto/keys.rs
+++ b/lockchain-core/src/crypto/keys.rs
@@ -1,5 +1,6 @@
//! A module that handles key generation and key loading
+use traits::AutoEncoder;
use super::utils::{hashing, random};
/// A shared key length parameter for all cryptographic operations
@@ -14,12 +15,14 @@ pub struct Key {
pub data: Vec<u8>,
}
+impl AutoEncoder for Key {}
+
impl Key {
/// Create a new key from scratch
pub fn generate() -> Key {
let data = random::bytes(KEY_LENGTH);
- return Key { data: data };
+ Key { data: data }
}
/// Use a password as a key
@@ -29,13 +32,17 @@ impl Key {
for b in &hashed {
vec.push(b.clone());
}
- return Key { data: vec };
+ Key { data: vec }
+ }
+
+ pub fn to_vec(&self) -> Vec<u8> {
+ self.data.clone()
}
/// Used to get the raw data from this key, as a slice copy
pub fn to_slice(&self) -> [u8; KEY_LENGTH] {
let mut slice: [u8; KEY_LENGTH] = [0; KEY_LENGTH];
slice.clone_from_slice(&self.data);
- return slice;
+ slice
}
}
diff --git a/lockchain-core/src/lib.rs b/lockchain-core/src/lib.rs
index 294f883..02e5a88 100644
--- a/lockchain-core/src/lib.rs
+++ b/lockchain-core/src/lib.rs
@@ -19,6 +19,6 @@ pub mod crypto;
mod users;
mod record;
-
+pub use self::crypto::PackedData;
pub use self::record::{Header, Payload, Record, EncryptedBody};
pub use self::users::User; \ No newline at end of file
diff --git a/lockchain-crypto/Cargo.toml b/lockchain-crypto/Cargo.toml
index 2e780e0..48a41d5 100644
--- a/lockchain-crypto/Cargo.toml
+++ b/lockchain-crypto/Cargo.toml
@@ -5,11 +5,11 @@ documentation = "https://docs.rs/lockchain-crypto"
homepage = "https://github.com/spacekookie/lockchain/tree/master/lockchain-crypto"
readme = "README.md"
license = "MIT/X11 OR Apache-2.0"
-version = "0.1.0"
+version = "0.2.0"
authors = ["Katharina Fey <kookie@spacekookie.de>"]
[dependencies]
-lockchain-core = { version = ">=0.4", path = "../lockchain-core" }
+lockchain-core = { path = "../lockchain-core", version = ">= 0.5.0-alpha" }
serde_derive = "1.0"
serde = "1.0"
diff --git a/lockchain-crypto/src/data.rs b/lockchain-crypto/src/data.rs
deleted file mode 100644
index 74698e4..0000000
--- a/lockchain-crypto/src/data.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-//! A simple data layout
-
-use lcc::traits::AutoEncoder;
-
-/// Represents some packed data – includes nonce and blob
-#[derive(Serialize, Deserialize)]
-pub struct PackedData {
- pub nonce: Vec<u8>,
- pub iv: Vec<u8>,
- pub data: Vec<u8>,
-}
-
-impl AutoEncoder for PackedData {} \ No newline at end of file
diff --git a/lockchain-crypto/src/engine.rs b/lockchain-crypto/src/engine.rs
index d9664bb..1af386c 100644
--- a/lockchain-crypto/src/engine.rs
+++ b/lockchain-crypto/src/engine.rs
@@ -1,22 +1,20 @@
//!
-use lcc::{traits::{AutoEncoder, Encryptable, EncryptionHandler},
- EncryptedBody};
+use lcc::traits::{AutoEncoder, Encryptable, EncryptionHandler};
+use lcc::{EncryptedBody, PackedData};
+
use miscreant::aead::{Aes256Siv, Algorithm};
-use super::data::PackedData;
use super::databody::DataBody;
-use lcc::crypto::{Key, keys::KEY_LENGTH};
-use lcc::crypto::utils::random;
-
-use std::collections::BTreeMap;
+use lcc::crypto::random;
+use lcc::crypto::{Key, KEY_LENGTH};
impl Encryptable for DataBody {}
pub struct AesEngine {
ctx: Aes256Siv,
- key: Key,
+ _key: Key,
iv: Vec<u8>,
}
@@ -26,45 +24,69 @@ impl AesEngine {
let key = Key::generate();
Self {
ctx: Aes256Siv::new(&key.to_slice()),
- key,
+ _key: key,
iv: random::bytes(KEY_LENGTH),
}
}
-
+ /// Generate an Aes context from password
pub fn from_pw(pw: &str, salt: &str) -> Self {
let key = Key::from_password(pw, salt);
Self {
ctx: Aes256Siv::new(&key.to_slice()),
- key,
+ _key: key,
iv: random::bytes(KEY_LENGTH),
}
}
-}
-impl EncryptionHandler<DataBody> for AesEngine {
- fn encrypt(&mut self, item: DataBody) -> EncryptedBody {
- let ser = item.encode();
+ /// Load a packed data object which contains an Aes context
+ pub fn load(packed: PackedData, pw: &str, salt: &str) -> Option<Self> {
+ let mut temp = Self::from_pw(pw, salt);
+ let k = Key::decode(&String::from_utf8(temp.decrypt_primitive(&packed)?).ok()?);
+
+ Some(Self {
+ ctx: Aes256Siv::new(&k.to_slice()),
+ _key: k,
+ iv: packed.iv
+ })
+ }
+
+ /// Serialise the current context to save it somewhere
+ pub fn save(&mut self) -> PackedData {
+ let k = self._key.to_vec();
+ self.encrypt_primitive(&k)
+ }
+
+ fn encrypt_primitive(&mut self, data: &Vec<u8>) -> PackedData {
let nonce = random::bytes(64);
let iv = &self.iv.as_slice();
- let data = &ser.as_bytes();
+ let encrypted = self.ctx.seal(nonce.as_slice(), iv, data.as_slice());
- let encrypted = self.ctx.seal(nonce.as_slice(), iv, data);
- let data = PackedData {
+ PackedData {
iv: self.iv.clone(),
data: encrypted,
nonce: nonce,
- }.encode();
+ }
+ }
+
+ fn decrypt_primitive(&mut self, packed: &PackedData) -> Option<Vec<u8>> {
+ let iv = &self.iv.as_slice();
+ Some(self.ctx
+ .open(packed.nonce.as_slice(), iv, packed.data.as_slice())
+ .ok()?)
+ }
+}
+impl EncryptionHandler<DataBody> for AesEngine {
+ fn encrypt(&mut self, item: DataBody) -> EncryptedBody {
+ let ser = item.encode();
+ let data = self.encrypt_primitive(&ser.as_bytes().to_vec()).encode();
EncryptedBody { data }
}
fn decrypt(&mut self, item: EncryptedBody) -> Option<DataBody> {
let packed = PackedData::decode(&item.data);
- let iv = &self.iv.as_slice();
- let decrypted = self.ctx
- .open(packed.nonce.as_slice(), iv, packed.data.as_slice())
- .ok()?;
-
- Some(DataBody::decode(&String::from_utf8(decrypted).ok()?))
+ Some(DataBody::decode(&String::from_utf8(
+ self.decrypt_primitive(&packed)?,
+ ).ok()?))
}
}
diff --git a/lockchain-crypto/src/lib.rs b/lockchain-crypto/src/lib.rs
index b10b2c5..a33e8bc 100644
--- a/lockchain-crypto/src/lib.rs
+++ b/lockchain-crypto/src/lib.rs
@@ -11,10 +11,8 @@ extern crate miscreant;
extern crate lockchain_core as lcc;
-
mod databody;
mod engine;
-mod data;
pub use databody::*;
pub use engine::AesEngine;
diff --git a/lockchain-files/Cargo.toml b/lockchain-files/Cargo.toml
index 8b6b828..9a5fd9f 100644
--- a/lockchain-files/Cargo.toml
+++ b/lockchain-files/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "lockchain-files"
description = "Filesystem storage backend for lockchain vaults"
-version = "0.0.0"
+version = "0.1.0"
authors = ["Katharina Fey <kookie@spacekookie.de>"]
documentation = "https://docs.rs/lockchain-files"
@@ -10,4 +10,8 @@ readme = "README.md"
license = "MIT/X11 OR Apache-2.0"
[dependencies]
-lockchain-core = ">=0.3.2"
+lockchain-core = { version = ">=0.5.0-alpha", path = "../lockchain-core" }
+
+serde = "1.0"
+serde_json = "1.0"
+serde_derive = "1.0" \ No newline at end of file
diff --git a/lockchain-files/src/fs.rs b/lockchain-files/src/fs.rs
new file mode 100644
index 0000000..52d7729
--- /dev/null
+++ b/lockchain-files/src/fs.rs
@@ -0,0 +1,47 @@
+//! Utility module which handles filesystem writes
+
+use std::path::PathBuf;
+use std::fs::{self, OpenOptions};
+use lcc::traits::AutoEncoder;
+
+use lcc::Record;
+
+pub struct Filesystem {
+ name: String,
+ path: String,
+ root: PathBuf,
+}
+
+pub enum FileType<T> {
+ Record(T),
+ Metadata(T),
+ Checksum(T)
+}
+
+impl Filesystem {
+ pub fn create(path: &str, name: &str) -> Filesystem {
+ let mut buffer = PathBuf::new();
+ buffer.push(path);
+ buffer.push(format!("{}.vault", name));
+
+ Filesystem {
+ name: name.to_owned(),
+ path: path.to_owned(),
+ root: buffer,
+ }
+ }
+
+ /// Create required directories
+ pub fn scaffold(&self) -> Option<()> {
+ fs::create_dir_all(&self.root).ok()?;
+ fs::create_dir(&self.root.join("records")).ok()?;
+ fs::create_dir(&self.root.join("metadata")).ok()?;
+ fs::create_dir(&self.root.join("checksums")).ok()?;
+ Some(())
+ }
+
+ /// Load all files of a certain type into a Vec<String>
+ pub fn fetch<T: AutoEncoder>(types: FileType<T>) -> Vec<T> {
+ unimplemented!()
+ }
+}
diff --git a/lockchain-files/src/lib.rs b/lockchain-files/src/lib.rs
index 31e1bb2..90109ac 100644
--- a/lockchain-files/src/lib.rs
+++ b/lockchain-files/src/lib.rs
@@ -1,7 +1,77 @@
-#[cfg(test)]
-mod tests {
- #[test]
- fn it_works() {
- assert_eq!(2 + 2, 4);
+//! A module that enables file management for vaults
+//!
+//!
+#![feature(non_modrs_mods)]
+
+extern crate serde;
+#[macro_use]
+extern crate serde_derive;
+extern crate serde_json;
+
+extern crate lockchain_core as lcc;
+
+use lcc::traits::{Body, Vault};
+use lcc::{Payload, Record};
+use std::collections::HashMap;
+
+mod fs;
+use fs::Filesystem;
+
+/// Represents a vault on disk
+pub struct DataVault<T: Body> {
+ records: HashMap<String, Record<T>>,
+ fs: Filesystem,
+}
+
+impl<T: Body> DataVault<T> {
+ /// Small utility function to setup file structure
+ fn initialize(self) -> Self {
+ self.fs.scaffold();
+ self
+ }
+}
+
+impl<T: Body> Vault<T> for DataVault<T> {
+ fn new(name: &str, location: &str) -> Self {
+ Self {
+ records: HashMap::new(),
+ fs: Filesystem::create(location, name),
+ }.initialize()
+ }
+
+ fn fetch(&mut self) {
+ unimplemented!()
+ }
+
+ fn pull(&mut self, name: &str) {
+ unimplemented!()
+ }
+
+ fn sync(&mut self) {
+ unimplemented!()
+ }
+
+ fn get_record(&self, name: &str) -> Option<&Record<T>> {
+ unimplemented!()
+ }
+
+ fn contains(&self, name: &str) -> bool {
+ unimplemented!()
+ }
+
+ fn add_record(&mut self, key: &str, category: &str, tags: Vec<&str>) {
+ unimplemented!()
+ }
+
+ fn delete_record(&mut self, record: &str) -> Option<Record<T>> {
+ unimplemented!()
+ }
+
+ fn add_data(&mut self, record: &str, key: &str, data: Payload) -> Option<()> {
+ unimplemented!()
+ }
+
+ fn get_data(&self, record: &str, key: &str) -> Option<&Payload> {
+ unimplemented!()
}
}
diff --git a/lockchain-files/src/vault.rs b/lockchain-files/src/vault.rs
deleted file mode 100644
index e69de29..0000000
--- a/lockchain-files/src/vault.rs
+++ /dev/null