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

Add tmkms yubihsm keys import command #107

Merged
merged 4 commits into from
Nov 20, 2018
Merged

Add tmkms yubihsm keys import command #107

merged 4 commits into from
Nov 20, 2018

Conversation

liamsi
Copy link
Contributor

@liamsi liamsi commented Nov 20, 2018

Can someone with a yubihsm test if this actually works?

@liamsi liamsi requested a review from tarcieri November 20, 2018 21:23
Cargo.toml Outdated
@@ -19,6 +19,7 @@ circle-ci = { repository = "tendermint/kms" }
abscissa = "0.0.6"
abscissa_derive = "0.0.2"
byteorder = "1.2"
base64 = "0.10.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use base64 from subtle_encoding, which is already a dependency (should be a drop-in replacement):

https://docs.rs/subtle-encoding/latest/subtle_encoding/base64/index.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh thanks. Should have asked directly. I spent half an hour or so searching for a light weight base64 crate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That crate is probably fine now, but had some issues in the past. Regardless, it'd probably be good to avoid adding additional dependencies.

Replacing it should be as easy as:

use subtle_encoding::base64

...and it should otherwise be (mostly) API-compatible.

Copy link
Contributor Author

@liamsi liamsi Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! And yes, agree about avoiding dependencies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, looks good!

Also: this is literally the use case subtle-encoding is designed for: decoding private keys in constant time.

yubihsm::AsymmetricAlg::Ed25519,
key,
) {
status_err!("couldn't generate key #{}: {}", self.key_id.unwrap(), e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be "couldn't import key" or thereabouts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. that parts was actually copy&pasted from the generate command (as they almost do the same thing).

process::exit(1);
});
let v: Value = serde_json::from_slice(&contents).unwrap();
let s = v["priv_key"]["value"].as_str().unwrap_or_else(|| {
Copy link
Contributor

@tony-iqlusion tony-iqlusion Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One alternative to consider for this sort of thing is using serde_derive to derive Deserialize for the structure of priv_validator.json.

I'm not sure it matters as this code is probably effectively "done" in that the priv_validator.json format is unlikely to change and this is literally the only use case which matters for tmkms, but I thought I'd at least throw it out there.

Copy link
Contributor Author

@liamsi liamsi Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I also thought about this. But I think we can keep this for now. If we ever need other fields, we can change to using serde_derive.

@tony-iqlusion
Copy link
Contributor

A couple nits, otherwise LGTM.

@liamsi liamsi merged commit 4b2a2ca into master Nov 20, 2018
@liamsi liamsi deleted the import_privval_key branch November 20, 2018 21:52
@tony-iqlusion tony-iqlusion mentioned this pull request Nov 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants