Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

crypto and key-management api for DeepKey: Keystore & PassphraseManager #1104

Merged
merged 87 commits into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
64ed4b9
renaming device->indexed seeds for generalization and created SeedCon…
zippy Mar 9, 2019
d812b76
wip adding KeyStore implementation
zippy Mar 9, 2019
8302845
wip added crypo.rs for conductor
zippy Mar 10, 2019
ba84993
added sign function
zippy Mar 11, 2019
422a03c
fixed breaking test
zippy Mar 11, 2019
9fbb6ce
moved keystore into dpki crate
zippy Mar 11, 2019
a6fd424
rename hc_dpki crate dir to just dpki
zippy Mar 11, 2019
2413d7b
Merge branch 'develop' into crypto-conductor-1
zippy Mar 12, 2019
2907bc9
added keystore.verify function
zippy Mar 12, 2019
af2e66f
Small fix in keystore
sphinxc0re Mar 12, 2019
ffcb386
added verify trait for provenance
zippy Mar 12, 2019
4145827
wip: merge develop into crypto-conductor-1
zippy Mar 12, 2019
5fba5cb
refactored verify into trait and implemented on provenance
zippy Mar 12, 2019
f214328
rename add_dervied_seed to add_seed_from_seed
zippy Mar 12, 2019
b56054b
implemented sign_one_time
zippy Mar 12, 2019
ff4e2ad
fixes for CI test passing
zippy Mar 12, 2019
3869737
fixed file ownership changes
zippy Mar 13, 2019
e8ee071
modify inner implementation of SeedContext to 8 byte array
zippy Mar 13, 2019
54f47d5
cleaned up unused bindings
zippy Mar 13, 2019
64d629f
Merge branch 'develop' into crypto-conductor-1
zippy Mar 13, 2019
7150a2c
revert rename of Indexed->Device, plus bits of refactor
zippy Mar 13, 2019
0c488c1
mod revert
zippy Mar 13, 2019
912b56d
Merge branch 'develop' into crypto-conductor-1
zippy Mar 14, 2019
1132cb6
Merge branch 'develop' into crypto-conductor-1
zippy Mar 15, 2019
d661136
make secret in keystore be a keypair not a keybundle
zippy Mar 15, 2019
67bccef
add result to generate random keypairs funcs
zippy Mar 15, 2019
cd4eb22
moved low level crypto functions into dpki::utils so keystore does no…
zippy Mar 15, 2019
ca6ea3f
revert wierd mode change again!
zippy Mar 15, 2019
a28bddb
refactor passphrase encrypt/decrypt
zippy Mar 15, 2019
0467df6
added test cases
zippy Mar 15, 2019
38370d6
rename
zippy Mar 15, 2019
76ac309
refactor generate_random_buf
zippy Mar 15, 2019
e619b09
use refactored generate_random_buf
zippy Mar 15, 2019
dd99ded
added passphrase check to keystore
zippy Mar 18, 2019
7852ba9
fmt
zippy Mar 18, 2019
e636d5d
added change passphrase to keystore
zippy Mar 18, 2019
d124c18
added add to keystore
zippy Mar 18, 2019
ab1c163
added get to keystore
zippy Mar 18, 2019
3cd7da6
added encrypting key secret to keystore
zippy Mar 19, 2019
c5295bc
remove seed_type from keybundle
zippy Mar 19, 2019
bfd4220
added SigningKeyPair blobing
zippy Mar 19, 2019
64ec987
added EncryptingKeyPair blobing
zippy Mar 19, 2019
8fce5c9
Keystore: keys -> cache, +secrets
lucksus Mar 19, 2019
7a5d0e3
Merge remote-tracking branch 'origin/crypto-conductor-1' into crypto-…
lucksus Mar 19, 2019
a545a0b
Move Keystore to conductor_api
lucksus Mar 19, 2019
d058ca2
warnings--
lucksus Mar 19, 2019
eb7d348
rustfmt
lucksus Mar 19, 2019
7f1b788
Merge branch 'develop' into crypto-conductor-1
lucksus Mar 19, 2019
63f274f
Add PassphraseManager to Keystore
lucksus Mar 19, 2019
6d985b9
Keystore::secrets as encrypted normative storage
lucksus Mar 19, 2019
686cb6b
rustfmt
lucksus Mar 19, 2019
6c4c837
Keystore save/load
lucksus Mar 19, 2019
c70babe
allow(dead_code) on Keystore functions
lucksus Mar 19, 2019
8b2cbfb
added ability to add and get keybundles on the keystore
zippy Mar 19, 2019
5dc5e37
wip using keystore in conductor instead of keyfile
zippy Mar 20, 2019
f3a1cb6
updates to keyloader testing
zippy Mar 20, 2019
38d4fd4
wip kegen use of keystore
zippy Mar 20, 2019
296b1fc
kegen cli with keystore
zippy Mar 20, 2019
172ac33
fixed breaking test
zippy Mar 20, 2019
c8ceaf1
Merge branch 'develop' into crypto-conductor-1
zippy Mar 20, 2019
a2cf3a1
Merge branch 'develop' into crypto-conductor-1
zippy Mar 20, 2019
ef3c431
updated verify_signature to use provenance verify trait
zippy Mar 20, 2019
47fcb0a
removed unused use
zippy Mar 20, 2019
f80363b
changelog
zippy Mar 20, 2019
517bcc3
updated resource class for build test for circleci
zippy Mar 20, 2019
510f7c0
removed agent_name as identifier for keybundle in cli keygen
zippy Mar 20, 2019
f58a6bd
Adjust node-conductor to use Keystore instead of KeyBundle directly
lucksus Mar 20, 2019
b46013a
Merge remote-tracking branch 'origin/crypto-conductor-1' into crypto-…
lucksus Mar 20, 2019
bbfb859
Keystore: configurable hash config, set to relaxed values in tests
lucksus Mar 20, 2019
08f7e9f
rustfmt
lucksus Mar 20, 2019
e09d183
Set CircleCI resource_class back to "large" for hc-test
lucksus Mar 20, 2019
c3f19f8
Fix keygen to provide hash config for Keystore
lucksus Mar 20, 2019
6d91f60
rustfmt
lucksus Mar 20, 2019
c62b072
hc keygen info text update
lucksus Mar 20, 2019
1249844
merge develop into crypto-1
zippy Mar 21, 2019
4f55b73
Remove allow(dead_code)
lucksus Mar 21, 2019
392b036
Keystore comments
lucksus Mar 21, 2019
a80424b
remove unneeded allow dead code directives
zippy Mar 21, 2019
8b93acc
rustfmt
lucksus Mar 21, 2019
3175c5c
Merge remote-tracking branch 'origin/crypto-conductor-1' into crypto-…
lucksus Mar 21, 2019
d0a9d8d
Keystore comments
lucksus Mar 21, 2019
36bdbb4
remove unneeded derive step as per review request
zippy Mar 21, 2019
a8e372d
changed places where incorrect key_bundle id was being used
zippy Mar 21, 2019
5259a95
Fix remaining incorrect key_bundle id
lucksus Mar 21, 2019
6d5c07c
rustfmt
lucksus Mar 21, 2019
a61e3e4
Merge branch 'develop' into crypto-conductor-1
zippy Mar 21, 2019
cbd0692
rename key_file->keystore_file
zippy Mar 21, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Adds `nix-shell` support for Mac OS X [#1132](https://github.com/holochain/holochain-rust/pull/1132)
- Adds `hc-test-all` command to `nix-shell` [#1132](https://github.com/holochain/holochain-rust/pull/1132)
- Adds `./scripts/nix/pod.sh` script to isolate/debug `nix-shell` commands [#1139](https://github.com/holochain/holochain-rust/pull/1139)
- Adds keystore and passphrase management service [#1104](https://github.com/holochain/holochain-rust/pull/1104)
- Adds tooling to manage dependencies in Cargo.toml [#1140](https://github.com/holochain/holochain-rust/pull/1140)

### Changed

- `nix-shell` is now the recommended development approach on supported platforms [#1132](https://github.com/holochain/holochain-rust/pull/1132)
- Pins every dependant crate version with `=x.y.z` at the Cargo.toml level [#1140](https://github.com/holochain/holochain-rust/pull/1140)
- Breaking Change: `key_file` value now renamed to `keystore_file` in both config.toml files and the conductor's `admin/agent/add` interface [#1104](https://github.com/holochain/holochain-rust/pull/1104)

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ members = [
"net",
"nodejs_waiter",
"sodium",
"hc_dpki",
"dpki",
"test_bin",
]
exclude = [
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ holochain_core_types = { path = "../core_types" }
holochain_core = { path = "../core" }
holochain_common = { path = "../common" }
holochain_conductor_api = { path = "../conductor_api" }
holochain_dpki = { path = "../hc_dpki" }
holochain_dpki = { path = "../dpki" }
holochain_sodium = { path = "../sodium" }
holochain_wasm_utils = { path = "../wasm_utils" }
structopt = "=0.2.15"
Expand Down
69 changes: 26 additions & 43 deletions cli/src/cli/keygen.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
use error::DefaultResult;
use holochain_common::paths::keys_directory;
use holochain_dpki::{key_blob::Blobbable, key_bundle::KeyBundle, seed::SeedType, SEED_SIZE};
use holochain_sodium::secbuf::SecBuf;
use rpassword;
use std::{
fs::{create_dir_all, File},
io::prelude::*,
path::PathBuf,
use holochain_conductor_api::{
key_loaders::mock_passphrase_manager,
keystore::{Keystore, PRIMARY_KEYBUNDLE_ID},
};
use holochain_dpki::SEED_SIZE;
use rpassword;
use std::{fs::create_dir_all, path::PathBuf};

pub fn keygen(path: Option<PathBuf>, passphrase: Option<String>) -> DefaultResult<()> {
println!(
"This will create a new agent key bundle - that is all keys needed to represent one agent."
);
println!("This key bundle will be stored in a file, encrypted with a passphrase.");
println!("The passphrase is securing the keys and will be needed, together with the key file, in order to use the key.");
println!("Please enter a secret passphrase below, you will have to enter it again when unlocking this key to use within a Holochain conductor.");
println!("This will create a new agent keystore and populate it with an agent keybundle");
println!("(=all keys needed to represent an agent: public/private keys for signing/encryption");
println!("This keybundle will be stored encrypted by passphrase within the keystore file.");
println!("The passphrase is securing the keys and will be needed, together with the file, in order to use the key.");
println!("Please enter a secret passphrase below, you will have to enter it again when unlocking these keys to use within a Holochain conductor.");

let passphrase = passphrase.unwrap_or_else(|| {
let passphrase1 = rpassword::read_password_from_tty(Some("Passphrase: ")).unwrap();
Expand All @@ -27,49 +25,36 @@ pub fn keygen(path: Option<PathBuf>, passphrase: Option<String>) -> DefaultResul
passphrase1
});

let mut seed = SecBuf::with_secure(SEED_SIZE);
seed.randomize();

let mut keybundle = KeyBundle::new_from_seed_buf(&mut seed, SeedType::Mock)
.expect("Failed to generate keybundle");
let passphrase_bytes = passphrase.as_bytes();
let mut passphrase_buf = SecBuf::with_insecure(passphrase_bytes.len());
passphrase_buf
.write(0, passphrase_bytes)
.expect("SecBuf must be writeable");
let mut keystore = Keystore::new(mock_passphrase_manager(passphrase), None)?;
keystore.add_random_seed("root_seed", SEED_SIZE)?;

let blob = keybundle
.as_blob(&mut passphrase_buf, "hint".to_string(), None)
.expect("Failed to encrypt with passphrase.");
let (pub_key, _) = keystore.add_keybundle_from_seed("root_seed", PRIMARY_KEYBUNDLE_ID)?;

let path = if None == path {
let p = keys_directory();
create_dir_all(p.clone())?;
p.join(keybundle.get_id().clone())
p.join(pub_key.clone())
} else {
path.unwrap()
};

let mut file = File::create(path.clone())?;
file.write_all(serde_json::to_string(&blob).unwrap().as_bytes())?;
keystore.save(path.clone())?;

println!("");
println!("Succesfully created new agent keys.");
println!("Succesfully created new agent keystore.");
println!("");
println!("Public address: {}", keybundle.get_id());
println!("Public address: {}", pub_key);
println!("Bundle written to: {}.", path.to_str().unwrap());
println!("");
println!("You can set this file in a conductor config as key_file for an agent.");
println!("You can set this file in a conductor config as keystore_file for an agent.");
Ok(())
}

#[cfg(test)]
pub mod test {
use super::*;
use holochain_dpki::key_blob::KeyBlob;
use std::{
fs::{remove_file, File},
path::PathBuf,
};
use holochain_conductor_api::{key_loaders::mock_passphrase_manager, keystore::Keystore};
use std::{fs::remove_file, path::PathBuf};

#[test]
fn keygen_roundtrip() {
Expand All @@ -78,13 +63,11 @@ pub mod test {

keygen(Some(path.clone()), Some(passphrase.clone())).expect("Keygen should work");

let mut file = File::open(path.clone()).unwrap();
let mut contents = String::new();
file.read_to_string(&mut contents).unwrap();
let mut keystore =
Keystore::new_from_file(path.clone(), mock_passphrase_manager(passphrase), None)
.unwrap();

let blob: KeyBlob = serde_json::from_str(&contents).unwrap();
let mut passphrase = SecBuf::with_insecure_from_string(passphrase);
let keybundle = KeyBundle::from_blob(&blob, &mut passphrase, None);
let keybundle = keystore.get_keybundle(PRIMARY_KEYBUNDLE_ID);

assert!(keybundle.is_ok());

Expand Down
17 changes: 11 additions & 6 deletions cli/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use holochain_common::env_vars::EnvVar;
use holochain_conductor_api::{
conductor::{mount_conductor_from_config, CONDUCTOR},
config::*,
key_loaders::{test_keybundle, test_keybundle_loader},
key_loaders::{test_keystore, test_keystore_loader},
keystore::PRIMARY_KEYBUNDLE_ID,
logger::LogRules,
};
use holochain_core_types::agent::AgentId;
Expand All @@ -26,7 +27,7 @@ pub fn run(
mount_conductor_from_config(conductor_config);
let mut conductor_guard = CONDUCTOR.lock().unwrap();
let conductor = conductor_guard.as_mut().expect("Conductor must be mounted");
conductor.key_loader = test_keybundle_loader();
conductor.key_loader = test_keystore_loader();

conductor
.load_config()
Expand Down Expand Up @@ -97,13 +98,17 @@ fn agent_configuration() -> AgentConfiguration {
.value()
.ok()
.unwrap_or_else(|| String::from(AGENT_NAME_DEFAULT));
let keybundle = test_keybundle(&agent_name);
let agent_id = AgentId::new(&agent_name, keybundle.get_id());
let mut keystore = test_keystore(&agent_name);
let pub_key = keystore
.get_keybundle(PRIMARY_KEYBUNDLE_ID)
.expect("should be able to get keybundle")
.get_id();
let agent_id = AgentId::new(&agent_name, pub_key);
AgentConfiguration {
id: AGENT_CONFIG_ID.into(),
name: agent_id.nick,
public_address: agent_id.pub_sign_key,
key_file: agent_name,
keystore_file: agent_name,
holo_remote_key: None,
}
}
Expand Down Expand Up @@ -274,7 +279,7 @@ mod tests {
name: "testAgent".to_string(),
public_address: "HcScjN8wBwrn3tuyg89aab3a69xsIgdzmX5P9537BqQZ5A7TEZu7qCY4Xzzjhma"
.to_string(),
key_file: "testAgent".to_string(),
keystore_file: "testAgent".to_string(),
holo_remote_key: None,
},
);
Expand Down
4 changes: 2 additions & 2 deletions conductor/example-config/basic.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ bridges = []

[[agents]]
id = "test agent 1"
key_file = "holo_tester.key"
keystore_file = "holo_tester.key"
name = "Holo Tester 1"
public_address = "HoloTester1-----------------------------------------------------------------------AAACZp4xHB"

[[agents]]
id = "test agent 2"
key_file = "holo_tester.key"
keystore_file = "holo_tester.key"
name = "Holo Tester 2"
public_address = "HoloTester2-----------------------------------------------------------------------AAAGy4WW9e"

Expand Down
2 changes: 1 addition & 1 deletion conductor/example-config/empty-container.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
id = "test agent 1"
name = "Holo Tester 1"
public_address = "HoloTester1-----------------------------------------------------------------------AAACZp4xHB"
key_file = "holo_tester.key"
keystore_file = "holo_tester.key"

dnas = []

Expand Down
2 changes: 1 addition & 1 deletion conductor/example-config/holo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ signing_service_uri = "http://localhost:8888"

[[agents]]
id = "test agent 1"
key_file = "holo_tester.key"
keystore_file = "holo_tester.key"
name = "Holo Tester 1"
public_address = "HoloTester1-----------------------------------------------------------------------AAACZp4xHB"
holo_remote_key = true
Expand Down
2 changes: 1 addition & 1 deletion conductor/example-config/static-only.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
id = "test agent 1"
name = "Holo Tester 1"
public_address = "HoloTester1-----------------------------------------------------------------------AAACZp4xHB"
key_file = "holo_tester.key"
keystore_file = "holo_tester.key"

[[ui_bundles]]
id = "bundle1"
Expand Down
2 changes: 1 addition & 1 deletion conductor_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["Holochain Core Dev Team <[email protected]>"]
holochain_cas_implementations = { path = "../cas_implementations" }
holochain_core = { path = "../core" }
holochain_core_types = { path = "../core_types" }
holochain_dpki = { path = "../hc_dpki" }
holochain_dpki = { path = "../dpki" }
holochain_net = { path = "../net" }
holochain_sodium = { path = "../sodium" }
holochain_common = { path = "../common" }
Expand Down
8 changes: 4 additions & 4 deletions conductor_api/src/conductor/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ pub mod tests {
format!(
r#"[[agents]]
id = 'test-agent-1'
key_file = 'holo_tester1.key'
keystore_file = 'holo_tester1.key'
name = 'Holo Tester 1'
public_address = '{}'"#,
test_keybundle(1).get_id()
Expand All @@ -577,7 +577,7 @@ public_address = '{}'"#,
format!(
r#"[[agents]]
id = 'test-agent-2'
key_file = 'holo_tester2.key'
keystore_file = 'holo_tester2.key'
name = 'Holo Tester 2'
public_address = '{}'"#,
test_keybundle(2).get_id()
Expand Down Expand Up @@ -1379,7 +1379,7 @@ type = 'websocket'"#,
id: String::from("new-agent"),
name: String::from("Mr. New"),
public_address: AgentId::generate_fake("new").address().to_string(),
key_file: String::from("new-test-path"),
keystore_file: String::from("new-test-path"),
holo_remote_key: None,
};

Expand All @@ -1399,7 +1399,7 @@ type = 'websocket'"#,
String::from(
r#"[[agents]]
id = 'new-agent'
key_file = 'new-test-path'
keystore_file = 'new-test-path'
name = 'Mr. New'
public_address = 'HcScIkRaAaaaaaaaaaAaaaAAAAaaaaaaaaAaaaaAaaaaaaaaAaaAAAAatzu4aqa'"#,
),
Expand Down
Loading