@cryptotaxi247 / kubo / commits / 1439a53b1

handshake: bugfix (secure -> insecure chan) + logs

Juan Batiz-Benet committed Sep 19, 2014 at 05:25 UTC 1439a53b150e7c9b811745f048198c045999e43a
1 file changed +9 -2
crypto/spipe/handshake.go
+9 -2
@@ -5,6 +5,7 @@ package spipe
5 import (
6 "bytes"
7 "errors"
8 + "fmt"
9 "strings"
10
11 "crypto/aes"
@@ -48,6 +49,7 @@ func (s *SecurePipe) handshake() error {
49 return err
50 }
51
52 + // u.DOut("handshake: %s <--> %s\n", s.local.ID.Pretty(), s.remote.ID.Pretty())
53 myPubKey, err := s.local.PubKey.Bytes()
54 if err != nil {
55 return err
@@ -65,6 +67,7 @@ func (s *SecurePipe) handshake() error {
67 return err
68 }
69
70 + // u.POut("sending encoded handshake\n")
71 s.insecure.Out <- encoded
72
73 // Parse their Propose packet and generate an Exchange packet.
@@ -73,9 +76,10 @@ func (s *SecurePipe) handshake() error {
76 select {
77 case <-s.ctx.Done():
78 return ErrClosed
76 - case resp = <-s.Duplex.In:
79 + case resp = <-s.insecure.In:
80 }
81
82 + // u.POut("received encoded handshake\n")
83 proposeResp := new(Propose)
84 err = proto.Unmarshal(resp, proposeResp)
85 if err != nil {
@@ -98,6 +102,7 @@ func (s *SecurePipe) handshake() error {
102 } else if s.remote.ID == nil {
103 s.remote.ID = remoteID
104 }
105 + // u.POut("Remote Peer Identified as %s\n", s.remote.ID.Pretty())
106
107 exchange, err := selectBest(SupportedExchanges, proposeResp.GetExchanges())
108 if err != nil {
@@ -114,6 +119,7 @@ func (s *SecurePipe) handshake() error {
119 return err
120 }
121
122 + // u.POut("Selected %s %s %s\n", exchange, cipherType, hashType)
123 epubkey, done, err := ci.GenerateEKeyPair(exchange) // Generate EphemeralPubKey
124
125 var handshake bytes.Buffer // Gather corpus to sign.
@@ -153,6 +159,7 @@ func (s *SecurePipe) handshake() error {
159 theirHandshake.Write(encoded)
160 theirHandshake.Write(exchangeResp.GetEpubkey())
161
162 + // u.POut("Remote Peer Identified as %s\n", s.remote.ID.Pretty())
163 ok, err := s.remote.PubKey.Verify(theirHandshake.Bytes(), exchangeResp.GetSignature())
164 if err != nil {
165 return err
@@ -180,7 +187,7 @@ func (s *SecurePipe) handshake() error {
187 select {
188 case <-s.ctx.Done():
189 return ErrClosed
183 - case resp2 = <-s.Duplex.In:
190 + case resp2 = <-s.In:
191 }
192
193 if bytes.Compare(resp2, finished) != 0 {