Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi: add deadline for first connection of new LNC conn #408

Merged
merged 3 commits into from
Aug 23, 2022

Conversation

ellemouton
Copy link
Member

@ellemouton ellemouton commented Aug 18, 2022

In this PR, we add a deadline for the initial connection of an LNC
connection. So with this, the user is forced to use their pairing phrase
within a certain time frame. After this initial connection, future
connections are made with the second handshake version meaning that the
pairing phrase is rendered useless. By adding a time limit to the time
in which a user can use their pairing phrase, we reduce the risk created
by the users pairing phrase being leaked. The default time limit is set
to 10 minutes but can be customsed with the new firstlncconndeadline
flag.

The first commit in this PR adds a new CreatedAt field to Session so that
we can have an absolute deadline.

Depends on lightninglabs/lightning-node-connect#53

Fixes #406

@ellemouton ellemouton force-pushed the timeLimitFirstLNCConn branch from 96dbc12 to 6ff563f Compare August 18, 2022 16:50
@ellemouton ellemouton requested review from guggero and jamaljsr August 18, 2022 16:55
jamaljsr
jamaljsr previously approved these changes Aug 18, 2022
Copy link
Member

@jamaljsr jamaljsr left a comment

Choose a reason for hiding this comment

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

tACK LGTM.. amazing turn around time 🥇

Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Nice, looks pretty good and should be a great security improvement!
I left a suggestion for making the logic a bit easier to understand.

session/tlv.go Show resolved Hide resolved

err = s.db.RevokeSession(pubKey)
if err != nil {
log.Debugf("error revoking session: "+"%v", err)
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for not returning the error here? Or was this intended to be a return fmt.Errorf()? Also, string concatenation artifacts.

Copy link
Member Author

Choose a reason for hiding this comment

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

erg yeah sorry 🙈 also, there should be a return after this 🙈

config.go Outdated
Loop: &loopDefaultConfig,
PoolMode: defaultPoolMode,
Pool: &poolDefaultConfig,
FirstLNCConnDeadline: 10 * time.Minute,
Copy link
Member

Choose a reason for hiding this comment

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

nit: extract into constant?

}

// Start the deadline timer.
firstConnectionDeadline = time.NewTimer(
Copy link
Member

Choose a reason for hiding this comment

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

I think we could use time.AfterFunc() here that closes the firstConnTimeout. Then in the onNewStatus callback we only stop that timer and we don't need a whole other goroutine (the debug comment could be moved into the onNewStatus callback).

Copy link
Member Author

Choose a reason for hiding this comment

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

omg yeeeesss!!! thank you :) updated!

Copy link
Member Author

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

thanks @guggero ! updated as per you suggestion 🚀 much neater the way you have suggested :)


err = s.db.RevokeSession(pubKey)
if err != nil {
log.Debugf("error revoking session: "+"%v", err)
Copy link
Member Author

Choose a reason for hiding this comment

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

erg yeah sorry 🙈 also, there should be a return after this 🙈

}

// Start the deadline timer.
firstConnectionDeadline = time.NewTimer(
Copy link
Member Author

Choose a reason for hiding this comment

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

omg yeeeesss!!! thank you :) updated!

@ellemouton
Copy link
Member Author

hmmm the itest keeps failing....i must have broken something on the latest update. looking into it

@ellemouton ellemouton force-pushed the timeLimitFirstLNCConn branch from 603f4c7 to 3ea0e5a Compare August 23, 2022 07:19
In this commit, we add a deadline for the initial connection of an LNC
connection. So with this, the user is forced to use their pairing phrase
within a certain time frame. After this initial connection, future
connections are made with the second handshake version meaning that the
pairing phrase is rendered useless. By adding a time limit to the time
in which a user can use their pairing phrase, we reduce the risk created
by the users pairing phrase being leaked. The default time limit is set
to 10 minutes but can be customsed with the new `firstlncconndeadline`
flag.
@ellemouton ellemouton force-pushed the timeLimitFirstLNCConn branch from 3ea0e5a to d5c2604 Compare August 23, 2022 07:31
@ellemouton
Copy link
Member Author

hahaha found the issue 🙈 when I extracted the timeout into a variable, I used seconds instead of minutes 🙈 should be g2g now! I also added another commit that adds LNC client logging to the itests just to make it easier to debug these things in future

@ellemouton ellemouton requested a review from guggero August 23, 2022 07:44
Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

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

utACK, LGTM 🎉

@ellemouton ellemouton requested a review from jamaljsr August 23, 2022 13:11
Copy link
Member

@jamaljsr jamaljsr left a comment

Choose a reason for hiding this comment

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

tACK 🔥

The deadline works as advertised. Thanks for this great update.

@ellemouton ellemouton merged commit 3d9bdfc into lightninglabs:master Aug 23, 2022
@ellemouton ellemouton deleted the timeLimitFirstLNCConn branch August 23, 2022 19:48
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.

add time limit on switch to second handshake
3 participants