Skip to content

Commit

Permalink
progress in fixing the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
keks committed Jan 26, 2020
1 parent 11ce556 commit f64c52a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions secrethandshake/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,28 @@ func (s *State) verifyClientAuth(data []byte) bool {
secHasher.Write(s.aBob[:])
copy(s.secret2[:], secHasher.Sum(nil))

s.hello = make([]byte, 0, len(data)-16)
s.hello = make([]byte, len(data)-16)

var (
nonce [24]byte // always 0?
openOk bool
sig [ed25519.SignatureSize]byte
public [ed25519.PublicKeySize]byte
hello = make([]byte, 0, len(data)-16)
)

s.hello, openOk = box.OpenAfterPrecomputation(s.hello, data, &nonce, &s.secret2)
if !openOk && s.hello == nil {
hello, openOk = box.OpenAfterPrecomputation(hello, data, &nonce, &s.secret2)
if !openOk && hello == nil {
fmt.Println("warning: nil hello")
}

// subtle API requires an int containing 0 or 1, we only have bool.
// we can't branch because openOk is secret.
okInt := int(*((*byte)(unsafe.Pointer(&openOk))))

// this is not super secret data like keys, so we can copy it around
copy(s.hello, hello)

subtle.ConstantTimeCopy(okInt, sig[:], s.hello[:ed25519.SignatureSize])
subtle.ConstantTimeCopy(okInt, public[:], s.hello[ed25519.SignatureSize:ed25519.SignatureSize+ed25519.PublicKeySize])

Expand Down

0 comments on commit f64c52a

Please sign in to comment.