Skip to content

Conversation

@guggero
Copy link
Contributor

@guggero guggero commented Apr 23, 2020

As part of the preparatory work for lightningnetwork/lnd#3929, we remove the node's private key from the NewRouter method and replace it with an interface that abstracts away the ECDH operation.

This is only necessary for the long-term node key. All other private keys are just temporary session keys.

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Straight forward change, gives us a ton of options in the future w.r.t how we handle onion blobs, etc. I think we'll want a similar change in the area of the switch/router where we need to at times re-derive the shared secret upon restart.

@Roasbeef
Copy link
Member

cc @joostjager (reviewers thing is messed up on this repo, can't assign ppl easily)

@guggero
Copy link
Contributor Author

guggero commented Apr 28, 2020

I'm working on a PR that does all this in lnd as well (brontide, htlcswitch, netann and watchtower). You mean that, right @Roasbeef? Or are there further changes that should be done in this repo?

Do you think the naming is OK? I'm going to use the same SingleKeyECDH thing in lnd too.

// SingleKeyECDH is an abstraction interface that hides the implementation of an
// ECDH operation against a specific private key. We use this abstraction for
// the long term keys which we eventually want to be able to keep in a hardware
// wallet or HSM.
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, which hardware wallets currently support ECDH?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have no idea, to be honest. HW wallets are my blind spot. But I imagine implementing that is pretty easy as it's not much different from signing a message.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Roasbeef do they exist?

Copy link
Member

Choose a reason for hiding this comment

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

Ledger and trezor have support in their APIs which can be leveraged by custom applications. With this though, I think we're more so targeting remote/restricted signers which can emulate these calls by using the existing lnd gRPC interface and sub-servers, or something else entirely.

crypto.go Outdated
// the long term keys which we eventually want to be able to keep in a hardware
// wallet or HSM.
type SingleKeyECDH interface {
// PubKey returns the public key of the wrapped, "local" private key.
Copy link
Contributor

Choose a reason for hiding this comment

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

Meaning of 'wrapped' and 'local' not immediately clear. This interface could also be implemented by structs that are not wrapping and/or local?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, adjusted the comment(s).

guggero added 3 commits April 28, 2020 15:02
With this commit we create a new interface that abstracts away the
ECDH implementation. We also create one implementation that satisfies
the interface that can be used if the private key is known directly.
Later we will change the generateSharedSecret function to use this
interface instead of doing the ECDH operation directly.
This is a preparatory commit that adds an error return value to the
generateSharedSecret and generateSharedSecrets method. This is needed
because the interface we want to abstract the onion key behind has
an error return value too.
To be able to eventually extract the private keys out of the node
itself into a hardware wallet or HSM, we need to abstract the ECDH
operation against the long-term key behind an interface.
@guggero guggero requested a review from Roasbeef April 28, 2020 13:08
// the output of a SHA256 hash.
type Hash256 [sha256.Size]byte

// SingleKeyECDH is an abstraction interface that hides the implementation of an
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering still if SingleKeyECDH is the right name. It also suggests some fancy algorithm in which you exchange keys with yourself. Thinking about alternatives. Maybe ExternalECDH or just Signer (even though it isn't really signing)

@Roasbeef
Copy link
Member

Roasbeef commented May 1, 2020

You mean that, right @Roasbeef? Or are there further changes that should be done in this repo?

Yeah, to propagate these changes into the lnd sphere.

No strong feelings w.r.t naming on my end.

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🥊

@Roasbeef Roasbeef merged commit 3c8c8d0 into lightningnetwork:master May 1, 2020
@guggero guggero deleted the sign-abstraction branch May 1, 2020 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants