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-dms3
Commits
c85dd281
Commit
c85dd281
authored
Sep 01, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test for crypto handshake
parent
48865db1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
3 deletions
+57
-3
identify/identify.go
identify/identify.go
+4
-3
identify/identify_test.go
identify/identify_test.go
+53
-0
No files found.
identify/identify.go
View file @
c85dd281
...
...
@@ -54,6 +54,7 @@ func Handshake(self, remote *peer.Peer, in, out chan []byte) error {
out
<-
encrypted
challenge
:=
<-
in
// Decrypt challenge and send plaintext to partner
plain
,
err
:=
rsa
.
DecryptPKCS1v15
(
rand
.
Reader
,
self
.
PrivKey
.
(
*
rsa
.
PrivateKey
),
challenge
)
if
err
!=
nil
{
return
err
...
...
@@ -108,15 +109,15 @@ type KeyPair struct {
Priv
crypto
.
PrivateKey
}
func
GenKeypair
()
(
*
KeyPair
,
error
)
{
priv
,
err
:=
rsa
.
GenerateKey
(
rand
.
Reader
,
4096
)
func
GenKeypair
(
bits
int
)
(
*
KeyPair
,
error
)
{
priv
,
err
:=
rsa
.
GenerateKey
(
rand
.
Reader
,
bits
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
KeyPair
{
Priv
:
priv
,
Pub
:
priv
.
PublicKey
,
Pub
:
&
priv
.
PublicKey
,
},
nil
}
...
...
identify/identify_test.go
0 → 100644
View file @
c85dd281
package
identify
import
(
"testing"
"github.com/jbenet/go-ipfs/peer"
)
func
TestHandshake
(
t
*
testing
.
T
)
{
kpa
,
err
:=
GenKeypair
(
512
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
kpb
,
err
:=
GenKeypair
(
512
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
cha
:=
make
(
chan
[]
byte
,
5
)
chb
:=
make
(
chan
[]
byte
,
5
)
ida
,
err
:=
kpa
.
ID
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
pa
:=
&
peer
.
Peer
{
ID
:
ida
,
PubKey
:
kpa
.
Pub
,
PrivKey
:
kpa
.
Priv
,
}
idb
,
err
:=
kpb
.
ID
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
pb
:=
&
peer
.
Peer
{
ID
:
idb
,
PubKey
:
kpb
.
Pub
,
PrivKey
:
kpb
.
Priv
,
}
go
func
()
{
err
:=
Handshake
(
pa
,
pb
,
cha
,
chb
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}()
err
=
Handshake
(
pb
,
pa
,
chb
,
cha
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
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