ik->kkfallback complete
This commit is contained in:
parent
7c6510e7ce
commit
f3c6167915
|
@ -91,7 +91,6 @@ func NewKeypair(pub [32]byte, priv [32]byte) Keypair {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func (kp Keypair) PubKey() [32]byte {
|
||||
return kp.public_key
|
||||
}
|
||||
|
|
|
@ -84,6 +84,19 @@ func (s *secureSession) NoisePrivateKey() [32]byte {
|
|||
return s.noisePrivateKey
|
||||
}
|
||||
|
||||
func (s *secureSession) ReadLength() (int, error) {
|
||||
buf := make([]byte, 2)
|
||||
_, err := s.insecure.Read(buf)
|
||||
return int(binary.BigEndian.Uint16(buf)), err
|
||||
}
|
||||
|
||||
func (s *secureSession) WriteLength(length int) error {
|
||||
buf := make([]byte, 2)
|
||||
binary.BigEndian.PutUint16(buf, uint16(length))
|
||||
_, err := s.insecure.Write(buf)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *secureSession) setRemotePeerInfo(key []byte) (err error) {
|
||||
s.remote.libp2pKey, err = crypto.UnmarshalPublicKey(key)
|
||||
return err
|
||||
|
@ -98,6 +111,8 @@ func (s *secureSession) verifyPayload(payload *pb.NoiseHandshakePayload, noiseKe
|
|||
sig := payload.GetNoiseStaticKeySignature()
|
||||
msg := append([]byte(payload_string), noiseKey[:]...)
|
||||
|
||||
log.Debug("verifyPayload", "msg", msg)
|
||||
|
||||
ok, err := s.RemotePublicKey().Verify(msg, sig)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -108,19 +123,6 @@ func (s *secureSession) verifyPayload(payload *pb.NoiseHandshakePayload, noiseKe
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *secureSession) ReadLength() (int, error) {
|
||||
buf := make([]byte, 2)
|
||||
_, err := s.insecure.Read(buf)
|
||||
return int(binary.BigEndian.Uint16(buf)), err
|
||||
}
|
||||
|
||||
func (s *secureSession) WriteLength(length int) error {
|
||||
buf := make([]byte, 2)
|
||||
binary.BigEndian.PutUint16(buf, uint16(length))
|
||||
_, err := s.insecure.Write(buf)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *secureSession) runHandshake(ctx context.Context) error {
|
||||
|
||||
log.Debug("runHandshake", "cache", s.noiseStaticKeyCache)
|
||||
|
|
|
@ -442,7 +442,7 @@ func writeMessageA(hs *handshakestate, payload []byte, e *Keypair) (*handshakest
|
|||
ne, ns, ciphertext := emptyKey, []byte{}, []byte{}
|
||||
|
||||
if e == nil {
|
||||
hs.e = GenerateKeypair()
|
||||
hs.e = GenerateKeypair()
|
||||
} else {
|
||||
hs.e = *e
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ func doHandshake(t *testing.T) (*NoiseSession, *NoiseSession) {
|
|||
var msgbuf MessageBuffer
|
||||
msg := []byte{}
|
||||
msg = append(msg, payload_init_enc[:]...)
|
||||
ns_init, msgbuf = SendMessage(ns_init, msg)
|
||||
ns_init, msgbuf = SendMessage(ns_init, msg, nil)
|
||||
|
||||
t.Logf("stage 0 msgbuf: %v", msgbuf)
|
||||
t.Logf("stage 0 msgbuf ne len: %d", len(msgbuf.NE()))
|
||||
|
@ -111,7 +111,7 @@ func doHandshake(t *testing.T) (*NoiseSession, *NoiseSession) {
|
|||
t.Fatalf("proto marshal payload fail: %s", err)
|
||||
}
|
||||
msg = append(msg, payload_resp_enc[:]...)
|
||||
ns_resp, msgbuf = SendMessage(ns_resp, msg)
|
||||
ns_resp, msgbuf = SendMessage(ns_resp, msg, nil)
|
||||
|
||||
t.Logf("stage 1 msgbuf: %v", msgbuf)
|
||||
t.Logf("stage 1 msgbuf ne len: %d", len(msgbuf.NE()))
|
||||
|
@ -128,7 +128,7 @@ func doHandshake(t *testing.T) (*NoiseSession, *NoiseSession) {
|
|||
// stage 2: initiator
|
||||
// send message
|
||||
//msg = append(msg, payload_init_enc[:]...)
|
||||
ns_init, msgbuf = SendMessage(ns_init, nil)
|
||||
ns_init, msgbuf = SendMessage(ns_init, nil, nil)
|
||||
|
||||
t.Logf("stage 2 msgbuf: %v", msgbuf)
|
||||
t.Logf("stage 2 msgbuf ne len: %d", len(msgbuf.NE()))
|
||||
|
|
|
@ -140,7 +140,7 @@ func (s *secureSession) runHandshake_xx(ctx context.Context, fallback bool, init
|
|||
}
|
||||
} else {
|
||||
e_ik := s.ik_ns.Ephemeral()
|
||||
log.Debug("xxfallback stage 0 initiator", "ephemeral keys from ik", e_ik )
|
||||
log.Debug("xxfallback stage 0 initiator", "ephemeral keys from ik", e_ik)
|
||||
e_xx := xx.NewKeypair(e_ik.PubKey(), e_ik.PrivKey())
|
||||
|
||||
// initialize state as if we sent the first message
|
||||
|
@ -339,6 +339,8 @@ func (s *secureSession) runHandshake_xx(ctx context.Context, fallback bool, init
|
|||
}
|
||||
}
|
||||
|
||||
s.remote.noiseKey = s.xx_ns.RemoteKey()
|
||||
|
||||
// verify payload is signed by libp2p key
|
||||
err = s.verifyPayload(nhp, s.remote.noiseKey)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue