summaryrefslogtreecommitdiff
path: root/handshake_ntor.go
diff options
context:
space:
mode:
authorYawning Angel <yawning@schwanenlied.me>2014-06-01 05:22:07 +0000
committerYawning Angel <yawning@schwanenlied.me>2014-06-01 05:22:07 +0000
commit36228437c43bf3fa67a4d5b8da8ddf123645e530 (patch)
treeb4772fe6a9162c543a46961dc8af053be5b1405c /handshake_ntor.go
parent2001f0b698183b998dbf8e52f5d40a0d82aeef09 (diff)
Move the server keypair generation to right after Accept().
Instead of threading the code, move the keypair generation to right after Accept() is called. This should mask the timing differential due to the rejection sampling with the noise from the variablity in how long it takes for the server to get around to pulling a connection out of the backlog, and the time taken for the client to send it's portion of the handshake. The downside is that anyone connecting to the obfs4 port does force us to do a bunch of math, but the obfs4 math is relatively cheap compared to it's precursors. Fixes #9.
Diffstat (limited to 'handshake_ntor.go')
-rw-r--r--handshake_ntor.go15
1 files changed, 4 insertions, 11 deletions
diff --git a/handshake_ntor.go b/handshake_ntor.go
index 92f00dc..46e2a13 100644
--- a/handshake_ntor.go
+++ b/handshake_ntor.go
@@ -121,7 +121,7 @@ type clientHandshake struct {
serverMark []byte
}
-func newClientHandshake(nodeID *ntor.NodeID, serverIdentity *ntor.PublicKey, sessionKey *ntor.Keypair) (*clientHandshake, error) {
+func newClientHandshake(nodeID *ntor.NodeID, serverIdentity *ntor.PublicKey, sessionKey *ntor.Keypair) *clientHandshake {
hs := new(clientHandshake)
hs.keypair = sessionKey
hs.nodeID = nodeID
@@ -129,7 +129,7 @@ func newClientHandshake(nodeID *ntor.NodeID, serverIdentity *ntor.PublicKey, ses
hs.padLen = csrand.IntRange(clientMinPadLength, clientMaxPadLength)
hs.mac = hmac.New(sha256.New, append(hs.serverIdentity.Bytes()[:], hs.nodeID.Bytes()[:]...))
- return hs, nil
+ return hs
}
func (hs *clientHandshake) generateHandshake() ([]byte, error) {
@@ -236,8 +236,9 @@ type serverHandshake struct {
clientMark []byte
}
-func newServerHandshake(nodeID *ntor.NodeID, serverIdentity *ntor.Keypair) *serverHandshake {
+func newServerHandshake(nodeID *ntor.NodeID, serverIdentity *ntor.Keypair, sessionKey *ntor.Keypair) *serverHandshake {
hs := new(serverHandshake)
+ hs.keypair = sessionKey
hs.nodeID = nodeID
hs.serverIdentity = serverIdentity
hs.padLen = csrand.IntRange(serverMinPadLength, serverMaxPadLength)
@@ -312,14 +313,6 @@ func (hs *serverHandshake) parseClientHandshake(filter *replayFilter, resp []byt
return nil, ErrInvalidHandshake
}
- // At this point the client knows that we exist, so do the keypair
- // generation and complete our side of the handshake.
- var err error
- hs.keypair, err = ntor.NewKeypair(true)
- if err != nil {
- return nil, err
- }
-
clientPublic := hs.clientRepresentative.ToPublic()
ok, seed, auth := ntor.ServerHandshake(clientPublic, hs.keypair,
hs.serverIdentity, hs.nodeID)