Skip to content

Concept: Commandline wallet with decent security

gaudenzkessler edited this page Jan 10, 2023 · 3 revisions

Goal

Currently the main purpose of the substrate-api-client is to use it as a library from within another software component. Specifically it assumes, that the storage of the keys (used for the transactions) is taken care of in the software using the api-client. For certain usecases this is insufficient, especially when the command-line-interface (CLI) is used to make transactions. We want to extend the current implementation by adding the possibility to use keys, that are stored with encryption, and in a second step also two-factor-authentication.

Current situation

The api client offers a keystore that stores the keypair into an object and to write that object to a file. The users have to handle the file themselves. The integritee worker for example (https://github.com/integritee-network/worker) makes use of it. However, other users should have the possibility to store their keypair in a more convenient way.

Currently the user has to set the private key which is stored in the application state and loaded from there for signing the extrinsic:

seq_current drawio

Password Protection

We want a wallet that stores the keys in a file and takes over the file handling and encryption.

In a first step we store a password protected private key in a file. The ssh private key works as an example.

seq_new drawio

Encryption with 2nd Factor

2FA

In a second step we enhance the password protection of the private key by a second factor from the Yubikey. There is a library for RUST: https://crates.io/crates/yubico.

There are 2 possibilities:

1. Use a symmetric key to encrypt and decrypt the private key with the Yubikey.

key storage

_sec_encrypt_stor drawio

key usage

sec_encrypt_usage drawio

2. Store the private key on the Yubikey. This means that we do not need the local storage anymore. 

key storage

sec_yubikey_store drawio

key usage

sec_yubikey_usage drawio

Miscellaneous

Private key encryption

For the encryption we use substrate's primitives in crypto.rs. The protected key will be stored in a file. The plan is to use the same encryption algorithm, as currently.

Private key in state 

If we keep the private key in the state of the software, it could be read from the RAM by a local attacker. To prevent this, we use the Rust library Secret to manage the key from within our software.