Skip to content

Feature: Asymmetric decryption using hsmd secret (encrypted using hsmd public key) #3118

Open
@ZmnSCPxj

Description

@ZmnSCPxj

Propose addition of new command:

decryptblob

decryptblob blob ephemeralPubkey

Decrypts a hex-encoded blob using an ephemeral public key and the node private key.

To encrypt:

  • Allocate some non-swappable memory.
  • Generate a new ephemeral private key in the non-swappable memory from a high-entropy random source.
  • Multiply the ephemeral private key by G and store the point in normal memory. This is the ephemeral public key and should be stored with the encrypted message.
  • Multiply the ephemeral private key by the node public key and store the point in non-swappable memory.
  • SHA256 the point (product of ephemeral privkey and node pubkey), put hash in non-swappable memory.
  • Create a Chacha20 state in non-swappable memory, copy the hash above as the key, set the nonce and counter to 0.
  • XOR the Chacha20 output with the message (in normal memory).
  • Clear all non-swappable memory to 0 and release.

To decrypt, hsmd will recover the key state by multiplying its node private key with the ephemeral public key, generating the same point which when hashed generates the same Chacha20 state.

(exact details subject to change, we just need some method of asymmetric encryption, which is easiest done using symmetric encryption and ECDH, and which is difficult to hack with known-plaintext attack.)


Use case is for db_write hooks that need to store the database queries in a server that is only trusted to store the data (but not trusted to leak it to everybody else). The db_write hook could encrypt on-the-fly before responding to the db_write hook.

On recovery, we only need:

  • The original hsm_secret
    • We could switch to generating this from standard words.
  • The encrypted database queries file, containing point-ciphertext pairs.

We replace the hsm_secret with the recovered hsm_secret, then restart lightningd with --offline, then decodeblob each point-ciphertext pair and extract each database query on a fresh database. Then stop the lightningd and replace its database.

We may need to have a better way to push binaries through the RPC though.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions