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

Add support for psk2 handshakes #49

Merged
merged 1 commit into from
Dec 5, 2023
Merged

Add support for psk2 handshakes #49

merged 1 commit into from
Dec 5, 2023

Conversation

nsmith5
Copy link

@nsmith5 nsmith5 commented Nov 30, 2023

In psk2 handshakes, the responder doesn't know which preshared key to use until after they read the first message. To support this, allow setting preshared key for responder after the first ReadMessage with a new SetPresharedKey method.

Example usage:

// Initiator knows and sets psk initially
initiator, err := noise.NewHandshakeState(noise.Config{
    CipherSuite:           foo,
    Pattern:               HandshakeIX,
    PresharedKeyPlacement: 2,
    PresharedKey:          psk,
    Initiator:             true,
    StaticKeypair:         bar,
})

// Responder doesn't know which psk to set until it knows which peer its talking to
responder, err := noise.NewHandshakeState(noise.Config{
    CipherSuite:           foo,
    Pattern:               HandshakeIX,
    PresharedKeyPlacement: 2,
    StaticKeypair:         baz,
})

// -> e, s
msg, _, _, err = initiator.WriteMessage(nil, nil)
res, _, _, err = responder.ReadMessage(nil, msg)

// Go look up which psk to use based on the peer static public key
psk  := LookUpPSK(responder.PeerStatic())
err = responder.SetPresharedKey(psk)

// Finish up the handshake
// <- e, dhee, dhse, s, dhes, psk
msg, respEncrypt, respDecrypt, _ := responder.WriteMessage(nil, nil)
res, initEncrypt, initDecypt, _ := initiator.ReadMessage(nil, msg)

// transport I -> R
msg, err = initEncrypt.Encrypt(nil, nil, []byte("foo"))
res, err = respDecrypt.Decrypt(nil, nil, msg)

// transport R -> I
msg, err = respEncrypt.Encrypt(nil, nil, []byte("bar"))
res, err = respDecrypt.Decrypt(nil, nil, msg)

Resolves #45

In psk2, the responder doesn't know which preshared key to use until
after they read the first message. To support this, allow setting psk
for reponder after initialization with SetPresharedKey method.
@titanous titanous merged commit acf4844 into flynn:master Dec 5, 2023
2 checks passed
@nsmith5 nsmith5 deleted the support-psk2 branch December 5, 2023 23:33
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.

Psk2 handshakes
2 participants