Skip to content

Commit

Permalink
Check e and s in same message
Browse files Browse the repository at this point in the history
  • Loading branch information
emilbayes committed Sep 6, 2019
1 parent 9f107a0 commit e2f6409
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
12 changes: 10 additions & 2 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ var serverKeys = simpleHandshake.keygen()
// Make a client/server pair. These are also known as initiator/responder
var client = simpleHandshake(true, {
pattern: 'XX',
staticKeyPair: clientKeys
staticKeyPair: clientKeys,
onstatickey: (key, ondone) => {
console.log('static key', key)
ondone(null)
}
})

var server = simpleHandshake(false, {
pattern: 'XX',
staticKeyPair: serverKeys
staticKeyPair: serverKeys,
onstatickey: (key, ondone) => {
console.log('static key', key)
ondone(null)
}
})

// Use a simple Round trip function to do the back and forth.
Expand Down
19 changes: 14 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,24 @@ SimpleHandshake.prototype.recv = function recv (data, cb) {
var hasREAfter = self.state.re != null
var hasRSAfter = self.state.rs != null

// e and s may come in the same message, so we always have to check static
// after ephemeral. Assumption here (which holds for all official Noise handshakes)
// is that e always comes before s
if (hasREBefore === false && hasREAfter === true) {
return self.onephemeralkey(self.state.re, ondone)
return self.onephemeralkey(self.state.re, checkStatic)
}

if (hasRSBefore === false && hasRSAfter === true) {
return self.onstatickey(self.state.rs, ondone)
}
return checkStatic()

function checkStatic (err) {
if (err) return ondone(err)

return ondone()
if (hasRSBefore === false && hasRSAfter === true) {
return self.onstatickey(self.state.rs, ondone)
}

return ondone()
}

function ondone (err) {
if (err) return self._finish(err, null, cb)
Expand Down

0 comments on commit e2f6409

Please sign in to comment.