Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
9c3e8d7b
Commit
9c3e8d7b
authored
Sep 13, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #63 from jbenet/fix/identify-test_handshake-issue-61
fix(identify) Handshake
parents
5a41a2ac
24b7703f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
9 deletions
+29
-9
identify/identify.go
identify/identify.go
+27
-7
swarm/conn.go
swarm/conn.go
+2
-2
No files found.
identify/identify.go
View file @
9c3e8d7b
...
...
@@ -33,11 +33,14 @@ var ErrUnsupportedKeyType = errors.New("unsupported key type")
// Performs initial communication with this peer to share node ID's and
// initiate communication. (secureIn, secureOut, error)
func
Handshake
(
self
,
remote
*
peer
.
Peer
,
in
,
out
chan
[]
byte
)
(
chan
[]
byte
,
chan
[]
byte
,
error
)
{
func
Handshake
(
self
,
remote
*
peer
.
Peer
,
in
<-
chan
[]
byte
,
out
chan
<-
[]
byte
)
(
<-
chan
[]
byte
,
chan
<-
[]
byte
,
error
)
{
// Generate and send Hello packet.
// Hello = (rand, PublicKey, Supported)
nonce
:=
make
([]
byte
,
16
)
rand
.
Read
(
nonce
)
_
,
err
:=
rand
.
Read
(
nonce
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
hello
:=
new
(
Hello
)
...
...
@@ -95,6 +98,9 @@ func Handshake(self, remote *peer.Peer, in, out chan []byte) (chan []byte, chan
}
epubkey
,
done
,
err
:=
ci
.
GenerateEKeyPair
(
exchange
)
// Generate EphemeralPubKey
if
err
!=
nil
{
return
nil
,
nil
,
err
}
var
handshake
bytes
.
Buffer
// Gather corpus to sign.
handshake
.
Write
(
encoded
)
...
...
@@ -110,6 +116,9 @@ func Handshake(self, remote *peer.Peer, in, out chan []byte) (chan []byte, chan
}
exEncoded
,
err
:=
proto
.
Marshal
(
exPacket
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
out
<-
exEncoded
...
...
@@ -124,9 +133,18 @@ func Handshake(self, remote *peer.Peer, in, out chan []byte) (chan []byte, chan
}
var
theirHandshake
bytes
.
Buffer
theirHandshake
.
Write
(
resp
)
theirHandshake
.
Write
(
encoded
)
theirHandshake
.
Write
(
exchangeResp
.
GetEpubkey
())
_
,
err
=
theirHandshake
.
Write
(
resp
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
_
,
err
=
theirHandshake
.
Write
(
encoded
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
_
,
err
=
theirHandshake
.
Write
(
exchangeResp
.
GetEpubkey
())
if
err
!=
nil
{
return
nil
,
nil
,
err
}
ok
,
err
:=
remote
.
PubKey
.
Verify
(
theirHandshake
.
Bytes
(),
exchangeResp
.
GetSignature
())
if
err
!=
nil
{
...
...
@@ -176,7 +194,7 @@ func makeMac(hashType string, key []byte) (hash.Hash, int) {
}
}
func
secureInProxy
(
in
,
secureIn
chan
[]
byte
,
hashType
string
,
tIV
,
tCKey
,
tMKey
[]
byte
)
{
func
secureInProxy
(
in
<-
chan
[]
byte
,
secureIn
chan
<-
[]
byte
,
hashType
string
,
tIV
,
tCKey
,
tMKey
[]
byte
)
{
theirBlock
,
_
:=
aes
.
NewCipher
(
tCKey
)
theirCipher
:=
cipher
.
NewCTR
(
theirBlock
,
tIV
)
...
...
@@ -185,6 +203,7 @@ func secureInProxy(in, secureIn chan []byte, hashType string, tIV, tCKey, tMKey
for
{
data
,
ok
:=
<-
in
if
!
ok
{
close
(
secureIn
)
return
}
...
...
@@ -211,7 +230,7 @@ func secureInProxy(in, secureIn chan []byte, hashType string, tIV, tCKey, tMKey
}
}
func
secureOutProxy
(
out
,
secureOut
chan
[]
byte
,
hashType
string
,
mIV
,
mCKey
,
mMKey
[]
byte
)
{
func
secureOutProxy
(
out
chan
<-
[]
byte
,
secureOut
<-
chan
[]
byte
,
hashType
string
,
mIV
,
mCKey
,
mMKey
[]
byte
)
{
myBlock
,
_
:=
aes
.
NewCipher
(
mCKey
)
myCipher
:=
cipher
.
NewCTR
(
myBlock
,
mIV
)
...
...
@@ -220,6 +239,7 @@ func secureOutProxy(out, secureOut chan []byte, hashType string, mIV, mCKey, mMK
for
{
data
,
ok
:=
<-
secureOut
if
!
ok
{
close
(
out
)
return
}
...
...
swarm/conn.go
View file @
9c3e8d7b
...
...
@@ -25,8 +25,8 @@ type Conn struct {
Closed
chan
bool
Outgoing
*
msgio
.
Chan
Incoming
*
msgio
.
Chan
secIn
chan
[]
byte
secOut
chan
[]
byte
secIn
<-
chan
[]
byte
secOut
chan
<-
[]
byte
}
// ConnMap maps Keys (Peer.IDs) to Connections.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment