mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 09:30:28 +00:00
add public keys to multicast, public key pinning to multicast peering
This commit is contained in:
parent
ff751a5409
commit
414c100125
@ -2,6 +2,8 @@ package multicast
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/ed25519"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -303,7 +305,12 @@ func (m *Multicast) _announce() {
|
|||||||
if a, err := net.ResolveTCPAddr("tcp6", lladdr); err == nil {
|
if a, err := net.ResolveTCPAddr("tcp6", lladdr); err == nil {
|
||||||
a.Zone = ""
|
a.Zone = ""
|
||||||
destAddr.Zone = iface.Name
|
destAddr.Zone = iface.Name
|
||||||
msg := []byte(a.String())
|
key, err := hex.DecodeString(m.config.PublicKey)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
msg := append([]byte(nil), key...)
|
||||||
|
msg = append(msg, a.String()...)
|
||||||
_, _ = m.sock.WriteTo(msg, nil, destAddr)
|
_, _ = m.sock.WriteTo(msg, nil, destAddr)
|
||||||
}
|
}
|
||||||
if info.interval.Seconds() < 15 {
|
if info.interval.Seconds() < 15 {
|
||||||
@ -342,7 +349,12 @@ func (m *Multicast) listen() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
anAddr := string(bs[:nBytes])
|
if len(bs) < ed25519.PublicKeySize {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var key ed25519.PublicKey
|
||||||
|
key = append(key, bs[:ed25519.PublicKeySize]...)
|
||||||
|
anAddr := string(bs[ed25519.PublicKeySize:nBytes])
|
||||||
addr, err := net.ResolveTCPAddr("tcp6", anAddr)
|
addr, err := net.ResolveTCPAddr("tcp6", anAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
@ -357,7 +369,8 @@ func (m *Multicast) listen() {
|
|||||||
})
|
})
|
||||||
if _, ok := interfaces[from.Zone]; ok {
|
if _, ok := interfaces[from.Zone]; ok {
|
||||||
addr.Zone = ""
|
addr.Zone = ""
|
||||||
u, err := url.Parse("tcp://" + addr.String())
|
pin := fmt.Sprintf("/?ed25519=%s", hex.EncodeToString(key))
|
||||||
|
u, err := url.Parse("tcp://" + addr.String() + pin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.log.Debugln("Call from multicast failed, parse error:", addr.String(), err)
|
m.log.Debugln("Call from multicast failed, parse error:", addr.String(), err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user