This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 267
Signing 2 - hc keygen #974
Merged
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0ecd7e1
Added command: hc keygen
8e7e8c2
rustfmt
b71a1c9
Changelog
b470fcd
Merge branch 'develop' into hc-keygen
25c2611
Merge branch 'develop' into hc-keygen
zippy dcb6c41
Merge branch 'develop' into hc-keygen
Connoropolous 2ccdacb
Merge branch 'develop' into hc-keygen
3bf977f
Add crate holochain_common with paths module and use it in cli::kegyen
d84ad41
XDG compliant paths
3f5f301
Output++
c25acb8
Test keygen
c5e4500
rustfmt
e7a5637
Update common/src/paths.rs
sphinxc0re debf294
style
3a192ba
warnings--
1b35b04
keygen -> cli README
515eed8
Update common/src/paths.rs
sphinxc0re 29073ed
[skip travis] [ci skip] wording tweaks
b4908c6
Update cli/src/main.rs
Connoropolous File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use error::DefaultResult; | ||
use holochain_dpki::{ | ||
bundle::KeyBundle, | ||
keypair::{Keypair, SEEDSIZE}, | ||
util::PwHashConfig, | ||
}; | ||
use holochain_sodium::{pwhash, random::random_secbuf, secbuf::SecBuf}; | ||
use rpassword; | ||
use std::{ | ||
fs::{create_dir_all, File}, | ||
io::prelude::*, | ||
path::PathBuf, | ||
}; | ||
|
||
pub fn keygen() -> DefaultResult<()> { | ||
let passphrase = rpassword::read_password_from_tty(Some("Passphrase: ")).unwrap(); | ||
|
||
let mut seed = SecBuf::with_secure(SEEDSIZE); | ||
random_secbuf(&mut seed); | ||
let mut keypair = Keypair::new_from_seed(&mut seed).unwrap(); | ||
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 bundle: KeyBundle = keypair | ||
.get_bundle( | ||
&mut passphrase_buf, | ||
"hint".to_string(), | ||
Some(PwHashConfig( | ||
pwhash::OPSLIMIT_INTERACTIVE, | ||
pwhash::MEMLIMIT_INTERACTIVE, | ||
pwhash::ALG_ARGON2ID13, | ||
)), | ||
) | ||
.unwrap(); | ||
|
||
let path = match directories::UserDirs::new() { | ||
Some(user_dirs) => user_dirs.home_dir().join(".holochain").join("keys"), | ||
None => PathBuf::new(), | ||
}; | ||
|
||
create_dir_all(path.clone())?; | ||
let path = path.join(keypair.pub_keys); | ||
let mut file = File::create(path.clone())?; | ||
file.write_all(serde_json::to_string(&bundle).unwrap().as_bytes())?; | ||
println!("Wrote {}.", path.to_str().unwrap()); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,11 @@ extern crate holochain_sodium; | |
#[macro_use] | ||
extern crate arrayref; | ||
extern crate base64; | ||
extern crate rustc_serialize; | ||
|
||
extern crate bip39; | ||
extern crate boolinator; | ||
extern crate rustc_serialize; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed again? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know. I've just moved this by two lines for alphanumeric sorting. |
||
#[macro_use] | ||
extern crate serde; | ||
|
||
pub mod bundle; | ||
pub mod error; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on what I added into the tree about directories, I propose that we create a new crate, or shareable file, that keeps track of and documents all the “magic strings” representing paths on devices. I find that they get scattered in the code and the act as high risk points of failure for our system I think. If we could start in that direction in this Pr that would be amazing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I'm in favor of creating these directories with the XDG_CONFIG convention in mind. The
directories
crate already does that for you, we just have to use it.