Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
obfs4-deprecated
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leap
obfs4-deprecated
Commits
2001f0b6
Commit
2001f0b6
authored
10 years ago
by
Yawning Angel
Browse files
Options
Downloads
Patches
Plain Diff
Generate client keypairs before connecting, instead of after.
Part of issue #9.
parent
697b51b4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
handshake_ntor.go
+2
-7
2 additions, 7 deletions
handshake_ntor.go
handshake_ntor_test.go
+18
-6
18 additions, 6 deletions
handshake_ntor_test.go
obfs4.go
+13
-1
13 additions, 1 deletion
obfs4.go
with
33 additions
and
14 deletions
handshake_ntor.go
+
2
−
7
View file @
2001f0b6
...
...
@@ -121,14 +121,9 @@ type clientHandshake struct {
serverMark
[]
byte
}
func
newClientHandshake
(
nodeID
*
ntor
.
NodeID
,
serverIdentity
*
ntor
.
PublicKey
)
(
*
clientHandshake
,
error
)
{
var
err
error
func
newClientHandshake
(
nodeID
*
ntor
.
NodeID
,
serverIdentity
*
ntor
.
PublicKey
,
sessionKey
*
ntor
.
Keypair
)
(
*
clientHandshake
,
error
)
{
hs
:=
new
(
clientHandshake
)
hs
.
keypair
,
err
=
ntor
.
NewKeypair
(
true
)
if
err
!=
nil
{
return
nil
,
err
}
hs
.
keypair
=
sessionKey
hs
.
nodeID
=
nodeID
hs
.
serverIdentity
=
serverIdentity
hs
.
padLen
=
csrand
.
IntRange
(
clientMinPadLength
,
clientMaxPadLength
)
...
...
This diff is collapsed.
Click to expand it.
handshake_ntor_test.go
+
18
−
6
View file @
2001f0b6
...
...
@@ -43,9 +43,13 @@ func TestHandshakeNtor(t *testing.T) {
// Test client handshake padding.
for
l
:=
clientMinPadLength
;
l
<=
clientMaxPadLength
;
l
++
{
// Generate the client state and override the pad length.
client
Hs
,
err
:=
n
ewClientHandshake
(
nodeID
,
idKeypair
.
Public
()
)
client
Keypair
,
err
:=
n
tor
.
NewKeypair
(
true
)
if
err
!=
nil
{
t
.
Fatalf
(
"[%d:0] newClientHandshake failed:"
,
l
,
err
)
t
.
Fatalf
(
"[%d:0] ntor.NewKeypair failed: %s"
,
l
,
err
)
}
clientHs
,
err
:=
newClientHandshake
(
nodeID
,
idKeypair
.
Public
(),
clientKeypair
)
if
err
!=
nil
{
t
.
Fatalf
(
"[%d:0] newClientHandshake failed: %s"
,
l
,
err
)
}
clientHs
.
padLen
=
l
...
...
@@ -99,9 +103,13 @@ func TestHandshakeNtor(t *testing.T) {
// Test server handshake padding.
for
l
:=
serverMinPadLength
;
l
<=
serverMaxPadLength
+
inlineSeedFrameLength
;
l
++
{
// Generate the client state and override the pad length.
clientHs
,
err
:=
newClientHandshake
(
nodeID
,
idKeypair
.
Public
())
clientKeypair
,
err
:=
ntor
.
NewKeypair
(
true
)
if
err
!=
nil
{
t
.
Fatalf
(
"[%d:0] ntor.NewKeypair failed: %s"
,
l
,
err
)
}
clientHs
,
err
:=
newClientHandshake
(
nodeID
,
idKeypair
.
Public
(),
clientKeypair
)
if
err
!=
nil
{
t
.
Fatalf
(
"[%d:0] newClientHandshake failed:"
,
l
,
err
)
t
.
Fatalf
(
"[%d:0] newClientHandshake failed:
%s
"
,
l
,
err
)
}
clientHs
.
padLen
=
clientMinPadLength
...
...
@@ -146,9 +154,13 @@ func TestHandshakeNtor(t *testing.T) {
}
// Test oversized client padding.
clientHs
,
err
:=
newClientHandshake
(
nodeID
,
idKeypair
.
Public
())
clientKeypair
,
err
:=
ntor
.
NewKeypair
(
true
)
if
err
!=
nil
{
t
.
Fatalf
(
"ntor.NewKeypair failed: %s"
,
err
)
}
clientHs
,
err
:=
newClientHandshake
(
nodeID
,
idKeypair
.
Public
(),
clientKeypair
)
if
err
!=
nil
{
t
.
Fatalf
(
"newClientHandshake failed:"
,
err
)
t
.
Fatalf
(
"newClientHandshake failed:
%s
"
,
err
)
}
clientHs
.
padLen
=
clientMaxPadLength
+
1
...
...
This diff is collapsed.
Click to expand it.
obfs4.go
+
13
−
1
View file @
2001f0b6
...
...
@@ -69,6 +69,8 @@ const (
type
Obfs4Conn
struct
{
conn
net
.
Conn
sessionKey
*
ntor
.
Keypair
lenProbDist
*
wDist
iatProbDist
*
wDist
...
...
@@ -157,6 +159,8 @@ func (c *Obfs4Conn) clientHandshake(nodeID *ntor.NodeID, publicKey *ntor.PublicK
}
defer
func
()
{
// The session key is not needed past returning from this routine.
c
.
sessionKey
=
nil
if
err
!=
nil
{
c
.
setBroken
()
}
...
...
@@ -165,7 +169,7 @@ func (c *Obfs4Conn) clientHandshake(nodeID *ntor.NodeID, publicKey *ntor.PublicK
// Generate/send the client handshake.
var
hs
*
clientHandshake
var
blob
[]
byte
hs
,
err
=
newClientHandshake
(
nodeID
,
publicKey
)
hs
,
err
=
newClientHandshake
(
nodeID
,
publicKey
,
c
.
sessionKey
)
if
err
!=
nil
{
return
}
...
...
@@ -576,6 +580,14 @@ func DialObfs4DialFn(dialFn DialFn, network, address, nodeID, publicKey string,
}
c
.
iatProbDist
=
newWDist
(
iatSeed
,
0
,
maxIatDelay
)
}
// Generate the session keypair *before* connecting to the remote peer.
c
.
sessionKey
,
err
=
ntor
.
NewKeypair
(
true
)
if
err
!=
nil
{
return
nil
,
err
}
// Connect to the remote peer.
c
.
conn
,
err
=
dialFn
(
network
,
address
)
if
err
!=
nil
{
return
nil
,
err
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment