mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-10 05:10:26 +00:00
Try to perform TCP-like key exchange
This commit is contained in:
parent
704e4a062f
commit
f556f3e2a8
@ -34,42 +34,42 @@ func (l *awdl) init(c *Core) error {
|
|||||||
return nil
|
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) {
|
||||||
/*
|
|
||||||
myLinkPub, myLinkPriv := crypto.NewBoxKeys()
|
|
||||||
meta := version_getBaseMetadata()
|
|
||||||
meta.box = l.core.boxPub
|
|
||||||
meta.sig = l.core.sigPub
|
|
||||||
meta.link = *myLinkPub
|
|
||||||
metaBytes := meta.encode()
|
|
||||||
l.core.log.Println("toAWDL <- metaBytes")
|
|
||||||
toAWDL <- metaBytes
|
|
||||||
l.core.log.Println("metaBytes = <-fromAWDL")
|
|
||||||
metaBytes = <-fromAWDL
|
|
||||||
l.core.log.Println("version_metadata{}")
|
|
||||||
meta = version_metadata{}
|
|
||||||
if !meta.decode(metaBytes) || !meta.check() {
|
|
||||||
return nil, errors.New("Metadata decode failure")
|
|
||||||
}
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
shared := crypto.GetSharedKey(myLinkPriv, &meta.link)
|
|
||||||
*/
|
|
||||||
shared := crypto.GetSharedKey(&l.core.boxPriv, boxPubKey)
|
|
||||||
intf := awdlInterface{
|
intf := awdlInterface{
|
||||||
awdl: l,
|
awdl: l,
|
||||||
fromAWDL: fromAWDL,
|
fromAWDL: fromAWDL,
|
||||||
toAWDL: toAWDL,
|
toAWDL: toAWDL,
|
||||||
shutdown: make(chan bool),
|
shutdown: make(chan bool),
|
||||||
peer: l.core.peers.newPeer(boxPubKey, sigPubKey, shared, name),
|
|
||||||
//peer: l.core.peers.newPeer(&meta.box, &meta.sig, shared, name),
|
|
||||||
}
|
}
|
||||||
|
l.mutex.Lock()
|
||||||
|
l.interfaces[name] = &intf
|
||||||
|
l.mutex.Unlock()
|
||||||
|
myLinkPub, myLinkPriv := crypto.NewBoxKeys()
|
||||||
|
meta := version_getBaseMetadata()
|
||||||
|
meta.box = l.core.boxPub
|
||||||
|
meta.sig = l.core.sigPub
|
||||||
|
meta.link = *myLinkPub
|
||||||
|
metaBytes := meta.encode()
|
||||||
|
l.core.log.Println("toAWDL <- metaBytes")
|
||||||
|
toAWDL <- metaBytes
|
||||||
|
l.core.log.Println("metaBytes = <-fromAWDL")
|
||||||
|
metaBytes = <-fromAWDL
|
||||||
|
l.core.log.Println("version_metadata{}")
|
||||||
|
meta = version_metadata{}
|
||||||
|
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)
|
||||||
|
l.core.log.Println("l.core.peers.newPeer")
|
||||||
|
intf.peer = l.core.peers.newPeer(&meta.box, &meta.sig, shared, name)
|
||||||
if intf.peer != nil {
|
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.linkOut = make(chan []byte, 1) // protocol traffic
|
||||||
intf.peer.out = func(msg []byte) {
|
intf.peer.out = func(msg []byte) {
|
||||||
defer func() { recover() }()
|
defer func() { recover() }()
|
||||||
@ -84,6 +84,7 @@ func (l *awdl) create(fromAWDL chan []byte, toAWDL chan []byte, boxPubKey *crypt
|
|||||||
go intf.peer.linkLoop()
|
go intf.peer.linkLoop()
|
||||||
return &intf, nil
|
return &intf, nil
|
||||||
}
|
}
|
||||||
|
delete(l.interfaces, name)
|
||||||
return nil, errors.New("l.core.peers.newPeer failed")
|
return nil, errors.New("l.core.peers.newPeer failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,11 +13,9 @@ void Log(const char *text) {
|
|||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
"errors"
|
"errors"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
|
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/util"
|
"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
|
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)
|
fromAWDL := make(chan []byte, 32)
|
||||||
toAWDL := make(chan []byte, 32)
|
toAWDL := make(chan []byte, 32)
|
||||||
|
|
||||||
var boxPub crypto.BoxPubKey
|
if intf, err := c.awdl.create(fromAWDL, toAWDL, name); err == nil {
|
||||||
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 != nil {
|
if intf != nil {
|
||||||
c.log.Println(err)
|
c.log.Println(err)
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user