-
Notifications
You must be signed in to change notification settings - Fork 116
Connect to known nodes via Noise_XK #307
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
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
06968c4
Connect to known nodes via Noise_XK
Varunram e6ca9c3
Put global back in
Varunram 12e01b7
pass a single param to Dial instead of passing an empty slice
Varunram 36171eb
make tests work
Varunram daed60f
differentiate based on ln1 prefix
Varunram 23f4b0e
Merge branch 'master' into noisexk
delbonis 30e54f4
Merge upstream/master
gertjaap ca91390
Logging code change
gertjaap b3b3dc7
Merge branch 'master' into noisexk
Varunram File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |
| "bytes" | ||
| "fmt" | ||
| "io" | ||
| "log" | ||
| "math" | ||
| "net" | ||
| "time" | ||
|
|
@@ -29,15 +30,31 @@ type Conn struct { | |
|
|
||
| // A compile-time assertion to ensure that Conn meets the net.Conn interface. | ||
| var _ net.Conn = (*Conn)(nil) | ||
| var Noise_XK bool | ||
|
|
||
| // Dial attempts to establish an encrypted+authenticated connection with the | ||
| // remote peer located at address which has remotePub as its long-term static | ||
| // public key. In the case of a handshake failure, the connection is closed and | ||
| // a non-nil error is returned. | ||
| func Dial(localPriv *koblitz.PrivateKey, ipAddr string, remotePKH string, | ||
| func Dial(localPriv *btcec.PrivateKey, ipAddr string, remoteAddress string, | ||
| dialer func(string, string) (net.Conn, error)) (*Conn, error) { | ||
|
|
||
| var remotePKH string | ||
| var remotePK [33]byte | ||
| if remoteAddress[0:3] == "ln1" { // its a remote PKH | ||
| remotePKH = remoteAddress | ||
| } else if len(remoteAddress) == 33 { // remotePK | ||
| temp := []byte(remoteAddress) | ||
| copy(remotePK[:], temp) | ||
| } | ||
| var conn net.Conn | ||
| var err error | ||
| var empty [33]byte | ||
| if remotePK != empty { | ||
| log.Println("Connecting via Noise_XK since we know remotePK") | ||
| Noise_XK = true | ||
| SetConsts() | ||
| } | ||
| conn, err = dialer("tcp", ipAddr) | ||
| logging.Info("ipAddr is", ipAddr) | ||
| if err != nil { | ||
|
|
@@ -48,9 +65,8 @@ func Dial(localPriv *koblitz.PrivateKey, ipAddr string, remotePKH string, | |
| conn: conn, | ||
| noise: NewNoiseMachine(true, localPriv), | ||
| } | ||
|
|
||
| // Initiate the handshake by sending the first act to the receiver. | ||
| actOne, err := b.noise.GenActOne() | ||
| actOne, err := b.noise.GenActOne(remotePK) | ||
| if err != nil { | ||
| b.conn.Close() | ||
| return nil, err | ||
|
|
@@ -69,22 +85,30 @@ func Dial(localPriv *koblitz.PrivateKey, ipAddr string, remotePKH string, | |
| // remotePub), then read the second act after which we'll be able to | ||
| // send our static public key to the remote peer with strong forward | ||
| // secrecy. | ||
| var actTwo [ActTwoSize]byte | ||
| actTwo := make([]byte, ActTwoSize) | ||
| if _, err := io.ReadFull(conn, actTwo[:]); err != nil { | ||
| b.conn.Close() | ||
| return nil, err | ||
| } | ||
| s, err := b.noise.RecvActTwo(actTwo) | ||
| if err != nil { | ||
| b.conn.Close() | ||
| return nil, err | ||
| if !Noise_XK { | ||
| remotePK, err = b.noise.RecvActTwo(actTwo) | ||
| if err != nil { | ||
| b.conn.Close() | ||
| return nil, err | ||
| } | ||
| } else { | ||
| if _, err := b.noise.RecvActTwo(actTwo); err != nil { | ||
| b.conn.Close() | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| logging.Info("Received pubkey", s) | ||
| if lnutil.LitAdrFromPubkey(s) != remotePKH { | ||
| logging.Infoln("Received pubkey", remotePK) | ||
| if lnutil.LitAdrFromPubkey(remotePK) != remotePKH && !Noise_XK { | ||
| // for noise_XK dont check PKH and PK because we'd have already checked this | ||
| // the last time we connected to this guy | ||
| return nil, fmt.Errorf("Remote PKH doesn't match. Quitting!") | ||
| } | ||
| logging.Infof("Received PKH %s matches", lnutil.LitAdrFromPubkey(s)) | ||
| logging.Infof("Received PKH %s matches", lnutil.LitAdrFromPubkey(remotePK)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logging statement should be different when Noise_XK is true - you didn't check that it matches. Something like "Assuming PKH still matches" or just don't log it at all. |
||
|
|
||
| // Finally, complete the handshake by sending over our encrypted static | ||
| // key and execute the final ECDH operation. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to make sense to switch these clauses around, so that if Noise_XK is true it will not do the comparison.