5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 20:00:27 +00:00

Try to perform TCP-like key exchange

This commit is contained in:
Neil Alexander 2019-01-13 22:57:37 +00:00
parent 704e4a062f
commit f556f3e2a8
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
2 changed files with 32 additions and 48 deletions

View File

@ -34,8 +34,16 @@ func (l *awdl) init(c *Core) error {
return nil
}
func (l *awdl) create(fromAWDL chan []byte, toAWDL chan []byte, boxPubKey *crypto.BoxPubKey, sigPubKey *crypto.SigPubKey, name string) (*awdlInterface, error) {
/*
func (l *awdl) create(fromAWDL chan []byte, toAWDL chan []byte /*boxPubKey *crypto.BoxPubKey, sigPubKey *crypto.SigPubKey*/, name string) (*awdlInterface, error) {
intf := awdlInterface{
awdl: l,
fromAWDL: fromAWDL,
toAWDL: toAWDL,
shutdown: make(chan bool),
}
l.mutex.Lock()
l.interfaces[name] = &intf
l.mutex.Unlock()
myLinkPub, myLinkPriv := crypto.NewBoxKeys()
meta := version_getBaseMetadata()
meta.box = l.core.boxPub
@ -51,25 +59,17 @@ func (l *awdl) create(fromAWDL chan []byte, toAWDL chan []byte, boxPubKey *crypt
if !meta.decode(metaBytes) || !meta.check() {
return nil, errors.New("Metadata decode failure")
}
l.core.log.Println("version_getBaseMetadata{}")
base := version_getBaseMetadata()
if meta.ver > base.ver || meta.ver == base.ver && meta.minorVer > base.minorVer {
return nil, errors.New("Failed to connect to node: " + name + " version: " + fmt.Sprintf("%d.%d", meta.ver, meta.minorVer))
}
l.core.log.Println("crypto.GetSharedKey")
shared := crypto.GetSharedKey(myLinkPriv, &meta.link)
*/
shared := crypto.GetSharedKey(&l.core.boxPriv, boxPubKey)
intf := awdlInterface{
awdl: l,
fromAWDL: fromAWDL,
toAWDL: toAWDL,
shutdown: make(chan bool),
peer: l.core.peers.newPeer(boxPubKey, sigPubKey, shared, name),
//peer: l.core.peers.newPeer(&meta.box, &meta.sig, shared, name),
}
//shared := crypto.GetSharedKey(&l.core.boxPriv, boxPubKey)
l.core.log.Println("l.core.peers.newPeer")
intf.peer = l.core.peers.newPeer(&meta.box, &meta.sig, shared, name)
if intf.peer != nil {
l.mutex.Lock()
l.interfaces[name] = &intf
l.mutex.Unlock()
intf.peer.linkOut = make(chan []byte, 1) // protocol traffic
intf.peer.out = func(msg []byte) {
defer func() { recover() }()
@ -84,6 +84,7 @@ func (l *awdl) create(fromAWDL chan []byte, toAWDL chan []byte, boxPubKey *crypt
go intf.peer.linkLoop()
return &intf, nil
}
delete(l.interfaces, name)
return nil, errors.New("l.core.peers.newPeer failed")
}

View File

@ -13,11 +13,9 @@ void Log(const char *text) {
*/
import "C"
import (
"encoding/hex"
"errors"
"unsafe"
"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
"github.com/yggdrasil-network/yggdrasil-go/src/util"
)
@ -31,26 +29,11 @@ func (nsl MobileLogger) Write(p []byte) (n int, err error) {
return len(p), nil
}
func (c *Core) AWDLCreateInterface(boxPubKey string, sigPubKey string, name string) error {
func (c *Core) AWDLCreateInterface(name string) error {
fromAWDL := make(chan []byte, 32)
toAWDL := make(chan []byte, 32)
var boxPub crypto.BoxPubKey
var sigPub crypto.SigPubKey
boxPubHex, err := hex.DecodeString(boxPubKey)
if err != nil {
c.log.Println(err)
return err
}
sigPubHex, err := hex.DecodeString(sigPubKey)
if err != nil {
c.log.Println(err)
return err
}
copy(boxPub[:], boxPubHex)
copy(sigPub[:], sigPubHex)
if intf, err := c.awdl.create(fromAWDL, toAWDL, &boxPub, &sigPub, name); err == nil {
if intf, err := c.awdl.create(fromAWDL, toAWDL, name); err == nil {
if intf != nil {
c.log.Println(err)
return err