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

yubihsm: Support for exporting/importing wrapped (encrypted) keys #197

Merged
merged 2 commits into from
Mar 6, 2019

Conversation

tarcieri
Copy link
Contributor

@tarcieri tarcieri commented Mar 5, 2019

Adds support directly to the KMS to make encrypted backups of keys which have been generated inside of the YubiHSM (retroactively, as there exists a similar feature as part of key generation).

Also adds a corresponding command to import the encrypted backups. There was already a tmkms yubihsm keys import command so this overloads the command to handle both importing existing
priv_validator.json files (the previous functionality) and importing encrypted backups, with the former ideally going away with time.

@tarcieri tarcieri requested a review from liamsi March 5, 2019 06:22
@tarcieri
Copy link
Contributor Author

tarcieri commented Mar 5, 2019

Tested manually locally:

$ cargo run --features=yubihsm yubihsm keys generate 1
     Running `target/debug/tmkms yubihsm keys generate 1`
   Generated key #1: cosmosvalconspub1zcjduepql4usvw6hsg3xkrw6ngkxsju962ddngj8v94tzz7pmmjwcer5gf7s0kgpve
$ cargo run --features=yubihsm yubihsm keys export --id=1 ../exported.enc
     Running `target/debug/tmkms yubihsm keys export --id=1 ../exported.enc`
    Exported key 0x0001 (encrypted under wrap key 0x0001) to ../exported.enc
$ cargo run --features=yubihsm yubihsm keys import ../exported.enc
     Running `target/debug/tmkms yubihsm keys import ../exported.enc`
    Imported key 0x0001: cosmosvalconspub1zcjduepql4usvw6hsg3xkrw6ngkxsju962ddngj8v94tzz7pmmjwcer5gf7s0kgpve

This could use some better CI testing, but it's a bit tricky because the MockHSM is not set up to persist state between commands (perhaps it could use some sort of state file), which is needed to test generating and exporting a key as two separate steps.

Adds support directly to the KMS to make encrypted backups of keys which
have been generated inside of the YubiHSM (retroactively, as there
exists a similar feature as part of key generation).

Also adds a corresponding command to import the encrypted backups.
There was already a `tmkms yubihsm keys import` command so this
overloads the command to handle both importing existing
`priv_validator.json` files (the previous functionality) and importing
encrypted backups, with the former ideally going away with time.
@tarcieri tarcieri force-pushed the export-import-wrapped branch from 41e0ab8 to ece16ae Compare March 5, 2019 06:24
@tarcieri
Copy link
Contributor Author

tarcieri commented Mar 5, 2019

This is the last thing (aside from documentation) I'd like to do before cutting a v0.4.0 release of tmkms.

We should also probably cut a proper v0.3.0 release of the tendermint crate (I released a beta last week).

@@ -119,6 +119,7 @@ impl Callable for GenerateCommand {
impl_command!(GenerateCommand);

/// Create an encrypted backup of this key under the given wrap key ID
// TODO(tarcieri): unify this with the similar code in export?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would definitely be nice to do this before landing this PR as it's otherwise code duplication.

process::exit(1);
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some weird magic/guesswork/detection for what type of key to import if it isn't explicitly specified.

I think this should work right most of the time (and if it guesses wrong, it will only result in an error), however it'd be nice to eventually deprecate and remove the overloaded priv_validator.json import functionality, at least at such a time as people are no longer importing priv_validator.json keys in practice.

@@ -42,7 +42,7 @@ signatory-ledger-tm = { version = "0.11", optional = true }
subtle-encoding = { version = "0.3", features = ["bech32-preview"] }
tendermint = { version = "0.3.0-beta1", path = "tendermint-rs" }
tiny-bip39 = "0.6"
yubihsm = { version = "0.22.0-alpha2", features = ["setup", "usb"], optional = true }
yubihsm = { version = "0.22", features = ["setup", "usb"], optional = true }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bumped this to the final release (no changes from v0.22.0-alpha2 other than the version bump):

tendermint/yubihsm-rs#194

@tarcieri
Copy link
Contributor Author

tarcieri commented Mar 6, 2019

I'm tacking the YubiHSM documentation onto this commit (in 2ae8002), with the hope I can address UX concerns encountered actually trying to run these commands at the same time.

I'd appreciate any early feedback.

@tarcieri tarcieri force-pushed the export-import-wrapped branch from 2ae8002 to 8aaa1bd Compare March 6, 2019 03:31
@tarcieri tarcieri merged commit b19123d into master Mar 6, 2019
@tarcieri tarcieri deleted the export-import-wrapped branch March 6, 2019 03:35
@tarcieri
Copy link
Contributor Author

tarcieri commented Mar 6, 2019

:shipit:

@tarcieri tarcieri mentioned this pull request Mar 6, 2019
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