Don't pass password around as a pointer to a slice
A slice can be nil, so there is no reason for extra indirection to represent the lack of a password.
This commit is contained in:
1 parent
cda6b8d582
commit
619ebc20a8
3 files changed
+9
-8
No files matched your search
+2
-2
@@ -19,11 +19,11 @@ func GenerateKeyPair() (publicKey, privateKey *[32]byte, err error) {
|
|||||||
return box.GenerateKey(rand.Reader)
|
return box.GenerateKey(rand.Reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FormSessionKey(remotePublicKey, localPrivateKey *[32]byte, secretKey *[]byte) *[32]byte {
|
func FormSessionKey(remotePublicKey, localPrivateKey *[32]byte, secretKey []byte) *[32]byte {
|
||||||
var sharedKey [32]byte
|
var sharedKey [32]byte
|
||||||
box.Precompute(&sharedKey, remotePublicKey, localPrivateKey)
|
box.Precompute(&sharedKey, remotePublicKey, localPrivateKey)
|
||||||
sharedKeySlice := sharedKey[:]
|
sharedKeySlice := sharedKey[:]
|
||||||
sharedKeySlice = append(sharedKeySlice, *secretKey...)
|
sharedKeySlice = append(sharedKeySlice, secretKey...)
|
||||||
sessionKey := sha256.Sum256(sharedKeySlice)
|
sessionKey := sha256.Sum256(sharedKeySlice)
|
||||||
return &sessionKey
|
return &sessionKey
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-4
@@ -27,7 +27,7 @@ type Router struct {
|
|||||||
GossipChannels map[uint32]*GossipChannel
|
GossipChannels map[uint32]*GossipChannel
|
||||||
TopologyGossip Gossip
|
TopologyGossip Gossip
|
||||||
UDPListener *net.UDPConn
|
UDPListener *net.UDPConn
|
||||||
Password *[]byte
|
Password []byte
|
||||||
ConnLimit int
|
ConnLimit int
|
||||||
BufSz int
|
BufSz int
|
||||||
LogFrame func(string, []byte, *layers.Ethernet)
|
LogFrame func(string, []byte, *layers.Ethernet)
|
||||||
@@ -50,12 +50,10 @@ func NewRouter(iface *net.Interface, name PeerName, nickName string, password []
|
|||||||
router := &Router{
|
router := &Router{
|
||||||
Iface: iface,
|
Iface: iface,
|
||||||
GossipChannels: make(map[uint32]*GossipChannel),
|
GossipChannels: make(map[uint32]*GossipChannel),
|
||||||
|
Password: password,
|
||||||
ConnLimit: connLimit,
|
ConnLimit: connLimit,
|
||||||
BufSz: bufSz,
|
BufSz: bufSz,
|
||||||
LogFrame: logFrame}
|
LogFrame: logFrame}
|
||||||
if len(password) > 0 {
|
|
||||||
router.Password = &password
|
|
||||||
}
|
|
||||||
onMacExpiry := func(mac net.HardwareAddr, peer *Peer) {
|
onMacExpiry := func(mac net.HardwareAddr, peer *Peer) {
|
||||||
log.Println("Expired MAC", mac, "at", peer.Name)
|
log.Println("Expired MAC", mac, "at", peer.Name)
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -104,9 +104,12 @@ func main() {
|
|||||||
if password == "" {
|
if password == "" {
|
||||||
password = os.Getenv("WEAVE_PASSWORD")
|
password = os.Getenv("WEAVE_PASSWORD")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pwSlice []byte
|
||||||
if password == "" {
|
if password == "" {
|
||||||
log.Println("Communication between peers is unencrypted.")
|
log.Println("Communication between peers is unencrypted.")
|
||||||
} else {
|
} else {
|
||||||
|
pwSlice = []byte(password)
|
||||||
log.Println("Communication between peers is encrypted.")
|
log.Println("Communication between peers is encrypted.")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +133,7 @@ func main() {
|
|||||||
defer profile.Start(&p).Stop()
|
defer profile.Start(&p).Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
router := weave.NewRouter(iface, ourName, nickName, []byte(password), connLimit, bufSz*1024*1024, logFrame)
|
router := weave.NewRouter(iface, ourName, nickName, pwSlice, connLimit, bufSz*1024*1024, logFrame)
|
||||||
log.Println("Our name is", router.Ourself.Name, "("+router.Ourself.NickName+")")
|
log.Println("Our name is", router.Ourself.Name, "("+router.Ourself.NickName+")")
|
||||||
router.Start()
|
router.Start()
|
||||||
for _, peer := range peers {
|
for _, peer := range peers {
|
||||||
@@ -146,7 +149,7 @@ func main() {
|
|||||||
|
|
||||||
func handleHttp(router *weave.Router) {
|
func handleHttp(router *weave.Router) {
|
||||||
encryption := "off"
|
encryption := "off"
|
||||||
if router.Password != nil && len(*router.Password) > 0 {
|
if router.Password != nil {
|
||||||
encryption = "on"
|
encryption = "on"
|
||||||
}
|
}
|
||||||
http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Reference in new issue
Block a user