Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Refactor handshakes and generated code #44

Closed
wants to merge 16 commits into from
Closed

Conversation

yusefnapora
Copy link
Contributor

@yusefnapora yusefnapora commented Feb 10, 2020

This is a largish refactor that (AFAICT) doesn't change anything semantically, but removes a lot of duplicate code and tricky control flow, and generally makes the code easier to follow and reason about.

The main changes are:

  • consolidated the generated code from the xx and ik packages into a core package
  • moved types & functions common to both handshake patterns to core/common.go
  • moved read/write methods to rw.go
  • combined readLength + insecure.Read into readMsgInsecure (same for writeMsgInsecure)
  • defined Encrypt / Decrypt methods on the NoiseSession type, and removed crypto.go
  • defined HandshakeCodec interface to bundle up the various Encode/Decode functions and the methods that alter NoiseSession state when preparing / accepting handshake messages.
    • This lets us parameterize the NoiseSession with a codec when we initialize it, and moves the encoding / decoding logic from the handshake runners to the NoiseSession
  • refactored the various runHanshake methods
    • split into separate functions for initiator / responder flows
    • split XXfallback path into separate functions from XX path

There are still a few things I'd like to clean up, but I think this is a good start.

closes #42

@raulk raulk self-requested a review February 10, 2020 15:35
@raulk
Copy link
Member

raulk commented Feb 10, 2020

@yusefnapora – would be amazing to have Go benchmarks for the handshake and the cypher. Then we can measure the impact of these changes very quickly in terms of memory, CPU and allocs.

@raulk
Copy link
Member

raulk commented Feb 10, 2020

You can use net.Pipe to mount the secure channel on both ends without touching the actual network (in memory pipe): https://golang.org/pkg/net/#Pipe.

@yusefnapora
Copy link
Contributor Author

closing, since much of this is irrelevant in light of #53

@yusefnapora yusefnapora closed this Mar 2, 2020
@yusefnapora yusefnapora deleted the refactor/handshake branch March 2, 2020 20:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor handshake runners
2 participants