|
@@ -4,7 +4,6 @@
|
|
|
package e2e
|
|
|
|
|
|
import (
|
|
|
- "fmt"
|
|
|
"net/netip"
|
|
|
"slices"
|
|
|
"testing"
|
|
@@ -12,6 +11,7 @@ import (
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
"github.com/slackhq/nebula"
|
|
|
+ "github.com/slackhq/nebula/cert"
|
|
|
"github.com/slackhq/nebula/e2e/router"
|
|
|
"github.com/slackhq/nebula/header"
|
|
|
"github.com/slackhq/nebula/udp"
|
|
@@ -21,11 +21,11 @@ import (
|
|
|
|
|
|
func BenchmarkHotPath(b *testing.B) {
|
|
|
ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
|
|
|
- myControl, _, _, _ := newSimpleServer(ca, caKey, "me", "10.128.0.1/24", nil)
|
|
|
- theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them", "10.128.0.2/24", nil)
|
|
|
+ myControl, myVpnIpNet, _, _ := newSimpleServer(cert.Version1, ca, caKey, "me", "10.128.0.1/24", nil)
|
|
|
+ theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them", "10.128.0.2/24", nil)
|
|
|
|
|
|
// Put their info in our lighthouse
|
|
|
- myControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), theirUdpAddr)
|
|
|
+ myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
|
|
|
|
|
|
// Start the servers
|
|
|
myControl.Start()
|
|
@@ -35,7 +35,7 @@ func BenchmarkHotPath(b *testing.B) {
|
|
|
r.CancelFlowLogs()
|
|
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
- myControl.InjectTunUDPPacket(theirVpnIpNet.Addr(), 80, 80, []byte("Hi from me"))
|
|
|
+ myControl.InjectTunUDPPacket(theirVpnIpNet[0].Addr(), 80, myVpnIpNet[0].Addr(), 80, []byte("Hi from me"))
|
|
|
_ = r.RouteForAllUntilTxTun(theirControl)
|
|
|
}
|
|
|
|
|
@@ -45,18 +45,18 @@ func BenchmarkHotPath(b *testing.B) {
|
|
|
|
|
|
func TestGoodHandshake(t *testing.T) {
|
|
|
ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
|
|
|
- myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me", "10.128.0.1/24", nil)
|
|
|
- theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them", "10.128.0.2/24", nil)
|
|
|
+ myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "me", "10.128.0.1/24", nil)
|
|
|
+ theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them", "10.128.0.2/24", nil)
|
|
|
|
|
|
// Put their info in our lighthouse
|
|
|
- myControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), theirUdpAddr)
|
|
|
+ myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
|
|
|
|
|
|
// Start the servers
|
|
|
myControl.Start()
|
|
|
theirControl.Start()
|
|
|
|
|
|
t.Log("Send a udp packet through to begin standing up the tunnel, this should come out the other side")
|
|
|
- myControl.InjectTunUDPPacket(theirVpnIpNet.Addr(), 80, 80, []byte("Hi from me"))
|
|
|
+ myControl.InjectTunUDPPacket(theirVpnIpNet[0].Addr(), 80, myVpnIpNet[0].Addr(), 80, []byte("Hi from me"))
|
|
|
|
|
|
t.Log("Have them consume my stage 0 packet. They have a tunnel now")
|
|
|
theirControl.InjectUDPPacket(myControl.GetFromUDP(true))
|
|
@@ -77,16 +77,16 @@ func TestGoodHandshake(t *testing.T) {
|
|
|
myControl.WaitForType(1, 0, theirControl)
|
|
|
|
|
|
t.Log("Make sure our host infos are correct")
|
|
|
- assertHostInfoPair(t, myUdpAddr, theirUdpAddr, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl)
|
|
|
+ assertHostInfoPair(t, myUdpAddr, theirUdpAddr, myVpnIpNet, theirVpnIpNet, myControl, theirControl)
|
|
|
|
|
|
t.Log("Get that cached packet and make sure it looks right")
|
|
|
myCachedPacket := theirControl.GetFromTun(true)
|
|
|
- assertUdpPacket(t, []byte("Hi from me"), myCachedPacket, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), 80, 80)
|
|
|
+ assertUdpPacket(t, []byte("Hi from me"), myCachedPacket, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), 80, 80)
|
|
|
|
|
|
t.Log("Do a bidirectional tunnel test")
|
|
|
r := router.NewR(t, myControl, theirControl)
|
|
|
defer r.RenderFlow()
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
|
|
|
r.RenderHostmaps("Final hostmaps", myControl, theirControl)
|
|
|
myControl.Stop()
|
|
@@ -97,12 +97,12 @@ func TestGoodHandshake(t *testing.T) {
|
|
|
func TestWrongResponderHandshake(t *testing.T) {
|
|
|
ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
|
|
|
|
|
|
- myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me", "10.128.0.100/24", nil)
|
|
|
- theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them", "10.128.0.99/24", nil)
|
|
|
- evilControl, evilVpnIp, evilUdpAddr, _ := newSimpleServer(ca, caKey, "evil", "10.128.0.2/24", nil)
|
|
|
+ myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "me", "10.128.0.100/24", nil)
|
|
|
+ theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them", "10.128.0.99/24", nil)
|
|
|
+ evilControl, evilVpnIp, evilUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "evil", "10.128.0.2/24", nil)
|
|
|
|
|
|
// Put the evil udp addr in for their vpn Ip, this is a case of being lied to by the lighthouse.
|
|
|
- myControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), evilUdpAddr)
|
|
|
+ myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), evilUdpAddr)
|
|
|
|
|
|
// Build a router so we don't have to reason who gets which packet
|
|
|
r := router.NewR(t, myControl, theirControl, evilControl)
|
|
@@ -114,7 +114,7 @@ func TestWrongResponderHandshake(t *testing.T) {
|
|
|
evilControl.Start()
|
|
|
|
|
|
t.Log("Start the handshake process, we will route until we see the evil tunnel closed")
|
|
|
- myControl.InjectTunUDPPacket(theirVpnIpNet.Addr(), 80, 80, []byte("Hi from me"))
|
|
|
+ myControl.InjectTunUDPPacket(theirVpnIpNet[0].Addr(), 80, myVpnIpNet[0].Addr(), 80, []byte("Hi from me"))
|
|
|
|
|
|
h := &header.H{}
|
|
|
r.RouteForAllExitFunc(func(p *udp.Packet, c *nebula.Control) router.ExitType {
|
|
@@ -131,8 +131,8 @@ func TestWrongResponderHandshake(t *testing.T) {
|
|
|
})
|
|
|
|
|
|
t.Log("Evil tunnel is closed, inject the correct udp addr for them")
|
|
|
- myControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), theirUdpAddr)
|
|
|
- pendingHi := myControl.GetHostInfoByVpnIp(theirVpnIpNet.Addr(), true)
|
|
|
+ myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
|
|
|
+ pendingHi := myControl.GetHostInfoByVpnAddr(theirVpnIpNet[0].Addr(), true)
|
|
|
assert.NotContains(t, pendingHi.RemoteAddrs, evilUdpAddr)
|
|
|
|
|
|
t.Log("Route until we see the cached packet")
|
|
@@ -153,18 +153,18 @@ func TestWrongResponderHandshake(t *testing.T) {
|
|
|
|
|
|
t.Log("My cached packet should be received by them")
|
|
|
myCachedPacket := theirControl.GetFromTun(true)
|
|
|
- assertUdpPacket(t, []byte("Hi from me"), myCachedPacket, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), 80, 80)
|
|
|
+ assertUdpPacket(t, []byte("Hi from me"), myCachedPacket, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), 80, 80)
|
|
|
|
|
|
t.Log("Test the tunnel with them")
|
|
|
- assertHostInfoPair(t, myUdpAddr, theirUdpAddr, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl)
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
+ assertHostInfoPair(t, myUdpAddr, theirUdpAddr, myVpnIpNet, theirVpnIpNet, myControl, theirControl)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
|
|
|
t.Log("Flush all packets from all controllers")
|
|
|
r.FlushAll()
|
|
|
|
|
|
t.Log("Ensure ensure I don't have any hostinfo artifacts from evil")
|
|
|
- assert.Nil(t, myControl.GetHostInfoByVpnIp(evilVpnIp.Addr(), true), "My pending hostmap should not contain evil")
|
|
|
- assert.Nil(t, myControl.GetHostInfoByVpnIp(evilVpnIp.Addr(), false), "My main hostmap should not contain evil")
|
|
|
+ assert.Nil(t, myControl.GetHostInfoByVpnAddr(evilVpnIp[0].Addr(), true), "My pending hostmap should not contain evil")
|
|
|
+ assert.Nil(t, myControl.GetHostInfoByVpnAddr(evilVpnIp[0].Addr(), false), "My main hostmap should not contain evil")
|
|
|
|
|
|
//TODO: assert hostmaps for everyone
|
|
|
r.RenderHostmaps("Final hostmaps", myControl, theirControl, evilControl)
|
|
@@ -176,17 +176,17 @@ func TestWrongResponderHandshake(t *testing.T) {
|
|
|
func TestWrongResponderHandshakeStaticHostMap(t *testing.T) {
|
|
|
ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
|
|
|
|
|
|
- theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them", "10.128.0.99/24", nil)
|
|
|
- evilControl, evilVpnIp, evilUdpAddr, _ := newSimpleServer(ca, caKey, "evil", "10.128.0.2/24", nil)
|
|
|
+ theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them", "10.128.0.99/24", nil)
|
|
|
+ evilControl, evilVpnIp, evilUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "evil", "10.128.0.2/24", nil)
|
|
|
o := m{
|
|
|
"static_host_map": m{
|
|
|
- theirVpnIpNet.Addr().String(): []string{evilUdpAddr.String()},
|
|
|
+ theirVpnIpNet[0].Addr().String(): []string{evilUdpAddr.String()},
|
|
|
},
|
|
|
}
|
|
|
- myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me", "10.128.0.100/24", o)
|
|
|
+ myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "me", "10.128.0.100/24", o)
|
|
|
|
|
|
// Put the evil udp addr in for their vpn addr, this is a case of a remote at a static entry changing its vpn addr.
|
|
|
- myControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), evilUdpAddr)
|
|
|
+ myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), evilUdpAddr)
|
|
|
|
|
|
// Build a router so we don't have to reason who gets which packet
|
|
|
r := router.NewR(t, myControl, theirControl, evilControl)
|
|
@@ -198,7 +198,7 @@ func TestWrongResponderHandshakeStaticHostMap(t *testing.T) {
|
|
|
evilControl.Start()
|
|
|
|
|
|
t.Log("Start the handshake process, we will route until we see the evil tunnel closed")
|
|
|
- myControl.InjectTunUDPPacket(theirVpnIpNet.Addr(), 80, 80, []byte("Hi from me"))
|
|
|
+ myControl.InjectTunUDPPacket(theirVpnIpNet[0].Addr(), 80, myVpnIpNet[0].Addr(), 80, []byte("Hi from me"))
|
|
|
|
|
|
h := &header.H{}
|
|
|
r.RouteForAllExitFunc(func(p *udp.Packet, c *nebula.Control) router.ExitType {
|
|
@@ -215,8 +215,8 @@ func TestWrongResponderHandshakeStaticHostMap(t *testing.T) {
|
|
|
})
|
|
|
|
|
|
t.Log("Evil tunnel is closed, inject the correct udp addr for them")
|
|
|
- myControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), theirUdpAddr)
|
|
|
- pendingHi := myControl.GetHostInfoByVpnIp(theirVpnIpNet.Addr(), true)
|
|
|
+ myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
|
|
|
+ pendingHi := myControl.GetHostInfoByVpnAddr(theirVpnIpNet[0].Addr(), true)
|
|
|
assert.NotContains(t, pendingHi.RemoteAddrs, evilUdpAddr)
|
|
|
|
|
|
t.Log("Route until we see the cached packet")
|
|
@@ -237,18 +237,19 @@ func TestWrongResponderHandshakeStaticHostMap(t *testing.T) {
|
|
|
|
|
|
t.Log("My cached packet should be received by them")
|
|
|
myCachedPacket := theirControl.GetFromTun(true)
|
|
|
- assertUdpPacket(t, []byte("Hi from me"), myCachedPacket, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), 80, 80)
|
|
|
+ assertUdpPacket(t, []byte("Hi from me"), myCachedPacket, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), 80, 80)
|
|
|
|
|
|
t.Log("Test the tunnel with them")
|
|
|
- assertHostInfoPair(t, myUdpAddr, theirUdpAddr, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl)
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
+ assertHostInfoPair(t, myUdpAddr, theirUdpAddr, myVpnIpNet, theirVpnIpNet, myControl, theirControl)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
|
|
|
t.Log("Flush all packets from all controllers")
|
|
|
r.FlushAll()
|
|
|
|
|
|
t.Log("Ensure ensure I don't have any hostinfo artifacts from evil")
|
|
|
- assert.Nil(t, myControl.GetHostInfoByVpnIp(evilVpnIp.Addr(), true), "My pending hostmap should not contain evil")
|
|
|
- assert.Nil(t, myControl.GetHostInfoByVpnIp(evilVpnIp.Addr(), false), "My main hostmap should not contain evil")
|
|
|
+ assert.Nil(t, myControl.GetHostInfoByVpnAddr(evilVpnIp[0].Addr(), true), "My pending hostmap should not contain evil")
|
|
|
+ assert.Nil(t, myControl.GetHostInfoByVpnAddr(evilVpnIp[0].Addr(), false), "My main hostmap should not contain evil")
|
|
|
+ //NOTE: if evil lost the handshake race it may still have a tunnel since me would reject the handshake since the tunnel is complete
|
|
|
|
|
|
//TODO: assert hostmaps for everyone
|
|
|
r.RenderHostmaps("Final hostmaps", myControl, theirControl, evilControl)
|
|
@@ -262,12 +263,12 @@ func TestStage1Race(t *testing.T) {
|
|
|
// But will eventually collapse down to a single tunnel
|
|
|
|
|
|
ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
|
|
|
- myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me ", "10.128.0.1/24", nil)
|
|
|
- theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them", "10.128.0.2/24", nil)
|
|
|
+ myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "me ", "10.128.0.1/24", nil)
|
|
|
+ theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them", "10.128.0.2/24", nil)
|
|
|
|
|
|
// Put their info in our lighthouse and vice versa
|
|
|
- myControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), theirUdpAddr)
|
|
|
- theirControl.InjectLightHouseAddr(myVpnIpNet.Addr(), myUdpAddr)
|
|
|
+ myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
|
|
|
+ theirControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr)
|
|
|
|
|
|
// Build a router so we don't have to reason who gets which packet
|
|
|
r := router.NewR(t, myControl, theirControl)
|
|
@@ -278,8 +279,8 @@ func TestStage1Race(t *testing.T) {
|
|
|
theirControl.Start()
|
|
|
|
|
|
t.Log("Trigger a handshake to start on both me and them")
|
|
|
- myControl.InjectTunUDPPacket(theirVpnIpNet.Addr(), 80, 80, []byte("Hi from me"))
|
|
|
- theirControl.InjectTunUDPPacket(myVpnIpNet.Addr(), 80, 80, []byte("Hi from them"))
|
|
|
+ myControl.InjectTunUDPPacket(theirVpnIpNet[0].Addr(), 80, myVpnIpNet[0].Addr(), 80, []byte("Hi from me"))
|
|
|
+ theirControl.InjectTunUDPPacket(myVpnIpNet[0].Addr(), 80, theirVpnIpNet[0].Addr(), 80, []byte("Hi from them"))
|
|
|
|
|
|
t.Log("Get both stage 1 handshake packets")
|
|
|
myHsForThem := myControl.GetFromUDP(true)
|
|
@@ -291,14 +292,14 @@ func TestStage1Race(t *testing.T) {
|
|
|
|
|
|
r.Log("Route until they receive a message packet")
|
|
|
myCachedPacket := r.RouteForAllUntilTxTun(theirControl)
|
|
|
- assertUdpPacket(t, []byte("Hi from me"), myCachedPacket, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), 80, 80)
|
|
|
+ assertUdpPacket(t, []byte("Hi from me"), myCachedPacket, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), 80, 80)
|
|
|
|
|
|
r.Log("Their cached packet should be received by me")
|
|
|
theirCachedPacket := r.RouteForAllUntilTxTun(myControl)
|
|
|
- assertUdpPacket(t, []byte("Hi from them"), theirCachedPacket, theirVpnIpNet.Addr(), myVpnIpNet.Addr(), 80, 80)
|
|
|
+ assertUdpPacket(t, []byte("Hi from them"), theirCachedPacket, theirVpnIpNet[0].Addr(), myVpnIpNet[0].Addr(), 80, 80)
|
|
|
|
|
|
r.Log("Do a bidirectional tunnel test")
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
|
|
|
myHostmapHosts := myControl.ListHostmapHosts(false)
|
|
|
myHostmapIndexes := myControl.ListHostmapIndexes(false)
|
|
@@ -316,7 +317,7 @@ func TestStage1Race(t *testing.T) {
|
|
|
r.Log("Spin until connection manager tears down a tunnel")
|
|
|
|
|
|
for len(myControl.GetHostmap().Indexes)+len(theirControl.GetHostmap().Indexes) > 2 {
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
t.Log("Connection manager hasn't ticked yet")
|
|
|
time.Sleep(time.Second)
|
|
|
}
|
|
@@ -339,12 +340,12 @@ func TestStage1Race(t *testing.T) {
|
|
|
|
|
|
func TestUncleanShutdownRaceLoser(t *testing.T) {
|
|
|
ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
|
|
|
- myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me ", "10.128.0.1/24", nil)
|
|
|
- theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them", "10.128.0.2/24", nil)
|
|
|
+ myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "me ", "10.128.0.1/24", nil)
|
|
|
+ theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them", "10.128.0.2/24", nil)
|
|
|
|
|
|
// Teach my how to get to the relay and that their can be reached via the relay
|
|
|
- myControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), theirUdpAddr)
|
|
|
- theirControl.InjectLightHouseAddr(myVpnIpNet.Addr(), myUdpAddr)
|
|
|
+ myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
|
|
|
+ theirControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr)
|
|
|
|
|
|
// Build a router so we don't have to reason who gets which packet
|
|
|
r := router.NewR(t, myControl, theirControl)
|
|
@@ -355,10 +356,10 @@ func TestUncleanShutdownRaceLoser(t *testing.T) {
|
|
|
theirControl.Start()
|
|
|
|
|
|
r.Log("Trigger a handshake from me to them")
|
|
|
- myControl.InjectTunUDPPacket(theirVpnIpNet.Addr(), 80, 80, []byte("Hi from me"))
|
|
|
+ myControl.InjectTunUDPPacket(theirVpnIpNet[0].Addr(), 80, myVpnIpNet[0].Addr(), 80, []byte("Hi from me"))
|
|
|
|
|
|
p := r.RouteForAllUntilTxTun(theirControl)
|
|
|
- assertUdpPacket(t, []byte("Hi from me"), p, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), 80, 80)
|
|
|
+ assertUdpPacket(t, []byte("Hi from me"), p, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), 80, 80)
|
|
|
|
|
|
r.Log("Nuke my hostmap")
|
|
|
myHostmap := myControl.GetHostmap()
|
|
@@ -366,17 +367,17 @@ func TestUncleanShutdownRaceLoser(t *testing.T) {
|
|
|
myHostmap.Indexes = map[uint32]*nebula.HostInfo{}
|
|
|
myHostmap.RemoteIndexes = map[uint32]*nebula.HostInfo{}
|
|
|
|
|
|
- myControl.InjectTunUDPPacket(theirVpnIpNet.Addr(), 80, 80, []byte("Hi from me again"))
|
|
|
+ myControl.InjectTunUDPPacket(theirVpnIpNet[0].Addr(), 80, myVpnIpNet[0].Addr(), 80, []byte("Hi from me again"))
|
|
|
p = r.RouteForAllUntilTxTun(theirControl)
|
|
|
- assertUdpPacket(t, []byte("Hi from me again"), p, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), 80, 80)
|
|
|
+ assertUdpPacket(t, []byte("Hi from me again"), p, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), 80, 80)
|
|
|
|
|
|
r.Log("Assert the tunnel works")
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
|
|
|
r.Log("Wait for the dead index to go away")
|
|
|
start := len(theirControl.GetHostmap().Indexes)
|
|
|
for {
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
if len(theirControl.GetHostmap().Indexes) < start {
|
|
|
break
|
|
|
}
|
|
@@ -388,12 +389,12 @@ func TestUncleanShutdownRaceLoser(t *testing.T) {
|
|
|
|
|
|
func TestUncleanShutdownRaceWinner(t *testing.T) {
|
|
|
ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
|
|
|
- myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me ", "10.128.0.1/24", nil)
|
|
|
- theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them", "10.128.0.2/24", nil)
|
|
|
+ myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "me ", "10.128.0.1/24", nil)
|
|
|
+ theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them", "10.128.0.2/24", nil)
|
|
|
|
|
|
// Teach my how to get to the relay and that their can be reached via the relay
|
|
|
- myControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), theirUdpAddr)
|
|
|
- theirControl.InjectLightHouseAddr(myVpnIpNet.Addr(), myUdpAddr)
|
|
|
+ myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
|
|
|
+ theirControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr)
|
|
|
|
|
|
// Build a router so we don't have to reason who gets which packet
|
|
|
r := router.NewR(t, myControl, theirControl)
|
|
@@ -404,10 +405,10 @@ func TestUncleanShutdownRaceWinner(t *testing.T) {
|
|
|
theirControl.Start()
|
|
|
|
|
|
r.Log("Trigger a handshake from me to them")
|
|
|
- myControl.InjectTunUDPPacket(theirVpnIpNet.Addr(), 80, 80, []byte("Hi from me"))
|
|
|
+ myControl.InjectTunUDPPacket(theirVpnIpNet[0].Addr(), 80, myVpnIpNet[0].Addr(), 80, []byte("Hi from me"))
|
|
|
|
|
|
p := r.RouteForAllUntilTxTun(theirControl)
|
|
|
- assertUdpPacket(t, []byte("Hi from me"), p, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), 80, 80)
|
|
|
+ assertUdpPacket(t, []byte("Hi from me"), p, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), 80, 80)
|
|
|
r.RenderHostmaps("Final hostmaps", myControl, theirControl)
|
|
|
|
|
|
r.Log("Nuke my hostmap")
|
|
@@ -416,18 +417,18 @@ func TestUncleanShutdownRaceWinner(t *testing.T) {
|
|
|
theirHostmap.Indexes = map[uint32]*nebula.HostInfo{}
|
|
|
theirHostmap.RemoteIndexes = map[uint32]*nebula.HostInfo{}
|
|
|
|
|
|
- theirControl.InjectTunUDPPacket(myVpnIpNet.Addr(), 80, 80, []byte("Hi from them again"))
|
|
|
+ theirControl.InjectTunUDPPacket(myVpnIpNet[0].Addr(), 80, theirVpnIpNet[0].Addr(), 80, []byte("Hi from them again"))
|
|
|
p = r.RouteForAllUntilTxTun(myControl)
|
|
|
- assertUdpPacket(t, []byte("Hi from them again"), p, theirVpnIpNet.Addr(), myVpnIpNet.Addr(), 80, 80)
|
|
|
+ assertUdpPacket(t, []byte("Hi from them again"), p, theirVpnIpNet[0].Addr(), myVpnIpNet[0].Addr(), 80, 80)
|
|
|
r.RenderHostmaps("Derp hostmaps", myControl, theirControl)
|
|
|
|
|
|
r.Log("Assert the tunnel works")
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
|
|
|
r.Log("Wait for the dead index to go away")
|
|
|
start := len(myControl.GetHostmap().Indexes)
|
|
|
for {
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
if len(myControl.GetHostmap().Indexes) < start {
|
|
|
break
|
|
|
}
|
|
@@ -439,14 +440,14 @@ func TestUncleanShutdownRaceWinner(t *testing.T) {
|
|
|
|
|
|
func TestRelays(t *testing.T) {
|
|
|
ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
|
|
|
- myControl, myVpnIpNet, _, _ := newSimpleServer(ca, caKey, "me ", "10.128.0.1/24", m{"relay": m{"use_relays": true}})
|
|
|
- relayControl, relayVpnIpNet, relayUdpAddr, _ := newSimpleServer(ca, caKey, "relay ", "10.128.0.128/24", m{"relay": m{"am_relay": true}})
|
|
|
- theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them ", "10.128.0.2/24", m{"relay": m{"use_relays": true}})
|
|
|
+ myControl, myVpnIpNet, _, _ := newSimpleServer(cert.Version1, ca, caKey, "me ", "10.128.0.1/24", m{"relay": m{"use_relays": true}})
|
|
|
+ relayControl, relayVpnIpNet, relayUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "relay ", "10.128.0.128/24", m{"relay": m{"am_relay": true}})
|
|
|
+ theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them ", "10.128.0.2/24", m{"relay": m{"use_relays": true}})
|
|
|
|
|
|
// Teach my how to get to the relay and that their can be reached via the relay
|
|
|
- myControl.InjectLightHouseAddr(relayVpnIpNet.Addr(), relayUdpAddr)
|
|
|
- myControl.InjectRelays(theirVpnIpNet.Addr(), []netip.Addr{relayVpnIpNet.Addr()})
|
|
|
- relayControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), theirUdpAddr)
|
|
|
+ myControl.InjectLightHouseAddr(relayVpnIpNet[0].Addr(), relayUdpAddr)
|
|
|
+ myControl.InjectRelays(theirVpnIpNet[0].Addr(), []netip.Addr{relayVpnIpNet[0].Addr()})
|
|
|
+ relayControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
|
|
|
|
|
|
// Build a router so we don't have to reason who gets which packet
|
|
|
r := router.NewR(t, myControl, relayControl, theirControl)
|
|
@@ -458,11 +459,11 @@ func TestRelays(t *testing.T) {
|
|
|
theirControl.Start()
|
|
|
|
|
|
t.Log("Trigger a handshake from me to them via the relay")
|
|
|
- myControl.InjectTunUDPPacket(theirVpnIpNet.Addr(), 80, 80, []byte("Hi from me"))
|
|
|
+ myControl.InjectTunUDPPacket(theirVpnIpNet[0].Addr(), 80, myVpnIpNet[0].Addr(), 80, []byte("Hi from me"))
|
|
|
|
|
|
p := r.RouteForAllUntilTxTun(theirControl)
|
|
|
r.Log("Assert the tunnel works")
|
|
|
- assertUdpPacket(t, []byte("Hi from me"), p, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), 80, 80)
|
|
|
+ assertUdpPacket(t, []byte("Hi from me"), p, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), 80, 80)
|
|
|
r.RenderHostmaps("Final hostmaps", myControl, relayControl, theirControl)
|
|
|
//TODO: assert we actually used the relay even though it should be impossible for a tunnel to have occurred without it
|
|
|
}
|
|
@@ -470,19 +471,19 @@ func TestRelays(t *testing.T) {
|
|
|
func TestStage1RaceRelays(t *testing.T) {
|
|
|
//NOTE: this is a race between me and relay resulting in a full tunnel from me to them via relay
|
|
|
ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
|
|
|
- myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me ", "10.128.0.1/24", m{"relay": m{"use_relays": true}})
|
|
|
- relayControl, relayVpnIpNet, relayUdpAddr, _ := newSimpleServer(ca, caKey, "relay ", "10.128.0.128/24", m{"relay": m{"am_relay": true}})
|
|
|
- theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them ", "10.128.0.2/24", m{"relay": m{"use_relays": true}})
|
|
|
+ myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "me ", "10.128.0.1/24", m{"relay": m{"use_relays": true}})
|
|
|
+ relayControl, relayVpnIpNet, relayUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "relay ", "10.128.0.128/24", m{"relay": m{"am_relay": true}})
|
|
|
+ theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them ", "10.128.0.2/24", m{"relay": m{"use_relays": true}})
|
|
|
|
|
|
// Teach my how to get to the relay and that their can be reached via the relay
|
|
|
- myControl.InjectLightHouseAddr(relayVpnIpNet.Addr(), relayUdpAddr)
|
|
|
- theirControl.InjectLightHouseAddr(relayVpnIpNet.Addr(), relayUdpAddr)
|
|
|
+ myControl.InjectLightHouseAddr(relayVpnIpNet[0].Addr(), relayUdpAddr)
|
|
|
+ theirControl.InjectLightHouseAddr(relayVpnIpNet[0].Addr(), relayUdpAddr)
|
|
|
|
|
|
- myControl.InjectRelays(theirVpnIpNet.Addr(), []netip.Addr{relayVpnIpNet.Addr()})
|
|
|
- theirControl.InjectRelays(myVpnIpNet.Addr(), []netip.Addr{relayVpnIpNet.Addr()})
|
|
|
+ myControl.InjectRelays(theirVpnIpNet[0].Addr(), []netip.Addr{relayVpnIpNet[0].Addr()})
|
|
|
+ theirControl.InjectRelays(myVpnIpNet[0].Addr(), []netip.Addr{relayVpnIpNet[0].Addr()})
|
|
|
|
|
|
- relayControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), theirUdpAddr)
|
|
|
- relayControl.InjectLightHouseAddr(myVpnIpNet.Addr(), myUdpAddr)
|
|
|
+ relayControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
|
|
|
+ relayControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr)
|
|
|
|
|
|
// Build a router so we don't have to reason who gets which packet
|
|
|
r := router.NewR(t, myControl, relayControl, theirControl)
|
|
@@ -494,14 +495,14 @@ func TestStage1RaceRelays(t *testing.T) {
|
|
|
theirControl.Start()
|
|
|
|
|
|
r.Log("Get a tunnel between me and relay")
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), relayVpnIpNet.Addr(), myControl, relayControl, r)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), relayVpnIpNet[0].Addr(), myControl, relayControl, r)
|
|
|
|
|
|
r.Log("Get a tunnel between them and relay")
|
|
|
- assertTunnel(t, theirVpnIpNet.Addr(), relayVpnIpNet.Addr(), theirControl, relayControl, r)
|
|
|
+ assertTunnel(t, theirVpnIpNet[0].Addr(), relayVpnIpNet[0].Addr(), theirControl, relayControl, r)
|
|
|
|
|
|
r.Log("Trigger a handshake from both them and me via relay to them and me")
|
|
|
- myControl.InjectTunUDPPacket(theirVpnIpNet.Addr(), 80, 80, []byte("Hi from me"))
|
|
|
- theirControl.InjectTunUDPPacket(myVpnIpNet.Addr(), 80, 80, []byte("Hi from them"))
|
|
|
+ myControl.InjectTunUDPPacket(theirVpnIpNet[0].Addr(), 80, myVpnIpNet[0].Addr(), 80, []byte("Hi from me"))
|
|
|
+ theirControl.InjectTunUDPPacket(myVpnIpNet[0].Addr(), 80, theirVpnIpNet[0].Addr(), 80, []byte("Hi from them"))
|
|
|
|
|
|
r.Log("Wait for a packet from them to me")
|
|
|
p := r.RouteForAllUntilTxTun(myControl)
|
|
@@ -519,20 +520,20 @@ func TestStage1RaceRelays(t *testing.T) {
|
|
|
func TestStage1RaceRelays2(t *testing.T) {
|
|
|
//NOTE: this is a race between me and relay resulting in a full tunnel from me to them via relay
|
|
|
ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
|
|
|
- myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me ", "10.128.0.1/24", m{"relay": m{"use_relays": true}})
|
|
|
- relayControl, relayVpnIpNet, relayUdpAddr, _ := newSimpleServer(ca, caKey, "relay ", "10.128.0.128/24", m{"relay": m{"am_relay": true}})
|
|
|
- theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them ", "10.128.0.2/24", m{"relay": m{"use_relays": true}})
|
|
|
+ myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "me ", "10.128.0.1/24", m{"relay": m{"use_relays": true}})
|
|
|
+ relayControl, relayVpnIpNet, relayUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "relay ", "10.128.0.128/24", m{"relay": m{"am_relay": true}})
|
|
|
+ theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them ", "10.128.0.2/24", m{"relay": m{"use_relays": true}})
|
|
|
l := NewTestLogger()
|
|
|
|
|
|
// Teach my how to get to the relay and that their can be reached via the relay
|
|
|
- myControl.InjectLightHouseAddr(relayVpnIpNet.Addr(), relayUdpAddr)
|
|
|
- theirControl.InjectLightHouseAddr(relayVpnIpNet.Addr(), relayUdpAddr)
|
|
|
+ myControl.InjectLightHouseAddr(relayVpnIpNet[0].Addr(), relayUdpAddr)
|
|
|
+ theirControl.InjectLightHouseAddr(relayVpnIpNet[0].Addr(), relayUdpAddr)
|
|
|
|
|
|
- myControl.InjectRelays(theirVpnIpNet.Addr(), []netip.Addr{relayVpnIpNet.Addr()})
|
|
|
- theirControl.InjectRelays(myVpnIpNet.Addr(), []netip.Addr{relayVpnIpNet.Addr()})
|
|
|
+ myControl.InjectRelays(theirVpnIpNet[0].Addr(), []netip.Addr{relayVpnIpNet[0].Addr()})
|
|
|
+ theirControl.InjectRelays(myVpnIpNet[0].Addr(), []netip.Addr{relayVpnIpNet[0].Addr()})
|
|
|
|
|
|
- relayControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), theirUdpAddr)
|
|
|
- relayControl.InjectLightHouseAddr(myVpnIpNet.Addr(), myUdpAddr)
|
|
|
+ relayControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
|
|
|
+ relayControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr)
|
|
|
|
|
|
// Build a router so we don't have to reason who gets which packet
|
|
|
r := router.NewR(t, myControl, relayControl, theirControl)
|
|
@@ -545,16 +546,16 @@ func TestStage1RaceRelays2(t *testing.T) {
|
|
|
|
|
|
r.Log("Get a tunnel between me and relay")
|
|
|
l.Info("Get a tunnel between me and relay")
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), relayVpnIpNet.Addr(), myControl, relayControl, r)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), relayVpnIpNet[0].Addr(), myControl, relayControl, r)
|
|
|
|
|
|
r.Log("Get a tunnel between them and relay")
|
|
|
l.Info("Get a tunnel between them and relay")
|
|
|
- assertTunnel(t, theirVpnIpNet.Addr(), relayVpnIpNet.Addr(), theirControl, relayControl, r)
|
|
|
+ assertTunnel(t, theirVpnIpNet[0].Addr(), relayVpnIpNet[0].Addr(), theirControl, relayControl, r)
|
|
|
|
|
|
r.Log("Trigger a handshake from both them and me via relay to them and me")
|
|
|
l.Info("Trigger a handshake from both them and me via relay to them and me")
|
|
|
- myControl.InjectTunUDPPacket(theirVpnIpNet.Addr(), 80, 80, []byte("Hi from me"))
|
|
|
- theirControl.InjectTunUDPPacket(myVpnIpNet.Addr(), 80, 80, []byte("Hi from them"))
|
|
|
+ myControl.InjectTunUDPPacket(theirVpnIpNet[0].Addr(), 80, myVpnIpNet[0].Addr(), 80, []byte("Hi from me"))
|
|
|
+ theirControl.InjectTunUDPPacket(myVpnIpNet[0].Addr(), 80, theirVpnIpNet[0].Addr(), 80, []byte("Hi from them"))
|
|
|
|
|
|
//r.RouteUntilAfterMsgType(myControl, header.Control, header.MessageNone)
|
|
|
//r.RouteUntilAfterMsgType(theirControl, header.Control, header.MessageNone)
|
|
@@ -567,7 +568,7 @@ func TestStage1RaceRelays2(t *testing.T) {
|
|
|
|
|
|
r.Log("Assert the tunnel works")
|
|
|
l.Info("Assert the tunnel works")
|
|
|
- assertTunnel(t, theirVpnIpNet.Addr(), myVpnIpNet.Addr(), theirControl, myControl, r)
|
|
|
+ assertTunnel(t, theirVpnIpNet[0].Addr(), myVpnIpNet[0].Addr(), theirControl, myControl, r)
|
|
|
|
|
|
t.Log("Wait until we remove extra tunnels")
|
|
|
l.Info("Wait until we remove extra tunnels")
|
|
@@ -587,7 +588,7 @@ func TestStage1RaceRelays2(t *testing.T) {
|
|
|
"theirControl": len(theirControl.GetHostmap().Indexes),
|
|
|
"relayControl": len(relayControl.GetHostmap().Indexes),
|
|
|
}).Info("Waiting for hostinfos to be removed...")
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
t.Log("Connection manager hasn't ticked yet")
|
|
|
time.Sleep(time.Second)
|
|
|
retries--
|
|
@@ -595,7 +596,7 @@ func TestStage1RaceRelays2(t *testing.T) {
|
|
|
|
|
|
r.Log("Assert the tunnel works")
|
|
|
l.Info("Assert the tunnel works")
|
|
|
- assertTunnel(t, theirVpnIpNet.Addr(), myVpnIpNet.Addr(), theirControl, myControl, r)
|
|
|
+ assertTunnel(t, theirVpnIpNet[0].Addr(), myVpnIpNet[0].Addr(), theirControl, myControl, r)
|
|
|
|
|
|
myControl.Stop()
|
|
|
theirControl.Stop()
|
|
@@ -607,14 +608,14 @@ func TestStage1RaceRelays2(t *testing.T) {
|
|
|
|
|
|
func TestRehandshakingRelays(t *testing.T) {
|
|
|
ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
|
|
|
- myControl, myVpnIpNet, _, _ := newSimpleServer(ca, caKey, "me ", "10.128.0.1/24", m{"relay": m{"use_relays": true}})
|
|
|
- relayControl, relayVpnIpNet, relayUdpAddr, relayConfig := newSimpleServer(ca, caKey, "relay ", "10.128.0.128/24", m{"relay": m{"am_relay": true}})
|
|
|
- theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them ", "10.128.0.2/24", m{"relay": m{"use_relays": true}})
|
|
|
+ myControl, myVpnIpNet, _, _ := newSimpleServer(cert.Version1, ca, caKey, "me ", "10.128.0.1/24", m{"relay": m{"use_relays": true}})
|
|
|
+ relayControl, relayVpnIpNet, relayUdpAddr, relayConfig := newSimpleServer(cert.Version1, ca, caKey, "relay ", "10.128.0.128/24", m{"relay": m{"am_relay": true}})
|
|
|
+ theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them ", "10.128.0.2/24", m{"relay": m{"use_relays": true}})
|
|
|
|
|
|
// Teach my how to get to the relay and that their can be reached via the relay
|
|
|
- myControl.InjectLightHouseAddr(relayVpnIpNet.Addr(), relayUdpAddr)
|
|
|
- myControl.InjectRelays(theirVpnIpNet.Addr(), []netip.Addr{relayVpnIpNet.Addr()})
|
|
|
- relayControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), theirUdpAddr)
|
|
|
+ myControl.InjectLightHouseAddr(relayVpnIpNet[0].Addr(), relayUdpAddr)
|
|
|
+ myControl.InjectRelays(theirVpnIpNet[0].Addr(), []netip.Addr{relayVpnIpNet[0].Addr()})
|
|
|
+ relayControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
|
|
|
|
|
|
// Build a router so we don't have to reason who gets which packet
|
|
|
r := router.NewR(t, myControl, relayControl, theirControl)
|
|
@@ -626,17 +627,17 @@ func TestRehandshakingRelays(t *testing.T) {
|
|
|
theirControl.Start()
|
|
|
|
|
|
t.Log("Trigger a handshake from me to them via the relay")
|
|
|
- myControl.InjectTunUDPPacket(theirVpnIpNet.Addr(), 80, 80, []byte("Hi from me"))
|
|
|
+ myControl.InjectTunUDPPacket(theirVpnIpNet[0].Addr(), 80, myVpnIpNet[0].Addr(), 80, []byte("Hi from me"))
|
|
|
|
|
|
p := r.RouteForAllUntilTxTun(theirControl)
|
|
|
r.Log("Assert the tunnel works")
|
|
|
- assertUdpPacket(t, []byte("Hi from me"), p, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), 80, 80)
|
|
|
+ assertUdpPacket(t, []byte("Hi from me"), p, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), 80, 80)
|
|
|
r.RenderHostmaps("working hostmaps", myControl, relayControl, theirControl)
|
|
|
|
|
|
// When I update the certificate for the relay, both me and them will have 2 host infos for the relay,
|
|
|
// and the main host infos will not have any relay state to handle the me<->relay<->them tunnel.
|
|
|
r.Log("Renew relay certificate and spin until me and them sees it")
|
|
|
- _, _, myNextPrivKey, myNextPEM := NewTestCert(ca, caKey, "relay", time.Now(), time.Now().Add(5*time.Minute), []netip.Prefix{relayVpnIpNet}, nil, []string{"new group"})
|
|
|
+ _, _, myNextPrivKey, myNextPEM := NewTestCert(cert.Version1, ca, caKey, "relay", time.Now(), time.Now().Add(5*time.Minute), relayVpnIpNet, nil, []string{"new group"})
|
|
|
|
|
|
caB, err := ca.MarshalPEM()
|
|
|
if err != nil {
|
|
@@ -654,8 +655,8 @@ func TestRehandshakingRelays(t *testing.T) {
|
|
|
|
|
|
for {
|
|
|
r.Log("Assert the tunnel works between myVpnIpNet and relayVpnIpNet")
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), relayVpnIpNet.Addr(), myControl, relayControl, r)
|
|
|
- c := myControl.GetHostInfoByVpnIp(relayVpnIpNet.Addr(), false)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), relayVpnIpNet[0].Addr(), myControl, relayControl, r)
|
|
|
+ c := myControl.GetHostInfoByVpnAddr(relayVpnIpNet[0].Addr(), false)
|
|
|
if len(c.Cert.Groups()) != 0 {
|
|
|
// We have a new certificate now
|
|
|
r.Log("Certificate between my and relay is updated!")
|
|
@@ -667,8 +668,8 @@ func TestRehandshakingRelays(t *testing.T) {
|
|
|
|
|
|
for {
|
|
|
r.Log("Assert the tunnel works between theirVpnIpNet and relayVpnIpNet")
|
|
|
- assertTunnel(t, theirVpnIpNet.Addr(), relayVpnIpNet.Addr(), theirControl, relayControl, r)
|
|
|
- c := theirControl.GetHostInfoByVpnIp(relayVpnIpNet.Addr(), false)
|
|
|
+ assertTunnel(t, theirVpnIpNet[0].Addr(), relayVpnIpNet[0].Addr(), theirControl, relayControl, r)
|
|
|
+ c := theirControl.GetHostInfoByVpnAddr(relayVpnIpNet[0].Addr(), false)
|
|
|
if len(c.Cert.Groups()) != 0 {
|
|
|
// We have a new certificate now
|
|
|
r.Log("Certificate between their and relay is updated!")
|
|
@@ -679,13 +680,13 @@ func TestRehandshakingRelays(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r.Log("Assert the relay tunnel still works")
|
|
|
- assertTunnel(t, theirVpnIpNet.Addr(), myVpnIpNet.Addr(), theirControl, myControl, r)
|
|
|
+ assertTunnel(t, theirVpnIpNet[0].Addr(), myVpnIpNet[0].Addr(), theirControl, myControl, r)
|
|
|
r.RenderHostmaps("working hostmaps", myControl, relayControl, theirControl)
|
|
|
// We should have two hostinfos on all sides
|
|
|
for len(myControl.GetHostmap().Indexes) != 2 {
|
|
|
t.Logf("Waiting for myControl hostinfos (%v != 2) to get cleaned up from lack of use...", len(myControl.GetHostmap().Indexes))
|
|
|
r.Log("Assert the relay tunnel still works")
|
|
|
- assertTunnel(t, theirVpnIpNet.Addr(), myVpnIpNet.Addr(), theirControl, myControl, r)
|
|
|
+ assertTunnel(t, theirVpnIpNet[0].Addr(), myVpnIpNet[0].Addr(), theirControl, myControl, r)
|
|
|
r.Log("yupitdoes")
|
|
|
time.Sleep(time.Second)
|
|
|
}
|
|
@@ -693,7 +694,7 @@ func TestRehandshakingRelays(t *testing.T) {
|
|
|
for len(theirControl.GetHostmap().Indexes) != 2 {
|
|
|
t.Logf("Waiting for theirControl hostinfos (%v != 2) to get cleaned up from lack of use...", len(theirControl.GetHostmap().Indexes))
|
|
|
r.Log("Assert the relay tunnel still works")
|
|
|
- assertTunnel(t, theirVpnIpNet.Addr(), myVpnIpNet.Addr(), theirControl, myControl, r)
|
|
|
+ assertTunnel(t, theirVpnIpNet[0].Addr(), myVpnIpNet[0].Addr(), theirControl, myControl, r)
|
|
|
r.Log("yupitdoes")
|
|
|
time.Sleep(time.Second)
|
|
|
}
|
|
@@ -701,7 +702,7 @@ func TestRehandshakingRelays(t *testing.T) {
|
|
|
for len(relayControl.GetHostmap().Indexes) != 2 {
|
|
|
t.Logf("Waiting for relayControl hostinfos (%v != 2) to get cleaned up from lack of use...", len(relayControl.GetHostmap().Indexes))
|
|
|
r.Log("Assert the relay tunnel still works")
|
|
|
- assertTunnel(t, theirVpnIpNet.Addr(), myVpnIpNet.Addr(), theirControl, myControl, r)
|
|
|
+ assertTunnel(t, theirVpnIpNet[0].Addr(), myVpnIpNet[0].Addr(), theirControl, myControl, r)
|
|
|
r.Log("yupitdoes")
|
|
|
time.Sleep(time.Second)
|
|
|
}
|
|
@@ -711,14 +712,14 @@ func TestRehandshakingRelays(t *testing.T) {
|
|
|
func TestRehandshakingRelaysPrimary(t *testing.T) {
|
|
|
// This test is the same as TestRehandshakingRelays but one of the terminal types is a primary swap winner
|
|
|
ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
|
|
|
- myControl, myVpnIpNet, _, _ := newSimpleServer(ca, caKey, "me ", "10.128.0.128/24", m{"relay": m{"use_relays": true}})
|
|
|
- relayControl, relayVpnIpNet, relayUdpAddr, relayConfig := newSimpleServer(ca, caKey, "relay ", "10.128.0.1/24", m{"relay": m{"am_relay": true}})
|
|
|
- theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them ", "10.128.0.2/24", m{"relay": m{"use_relays": true}})
|
|
|
+ myControl, myVpnIpNet, _, _ := newSimpleServer(cert.Version1, ca, caKey, "me ", "10.128.0.128/24", m{"relay": m{"use_relays": true}})
|
|
|
+ relayControl, relayVpnIpNet, relayUdpAddr, relayConfig := newSimpleServer(cert.Version1, ca, caKey, "relay ", "10.128.0.1/24", m{"relay": m{"am_relay": true}})
|
|
|
+ theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them ", "10.128.0.2/24", m{"relay": m{"use_relays": true}})
|
|
|
|
|
|
// Teach my how to get to the relay and that their can be reached via the relay
|
|
|
- myControl.InjectLightHouseAddr(relayVpnIpNet.Addr(), relayUdpAddr)
|
|
|
- myControl.InjectRelays(theirVpnIpNet.Addr(), []netip.Addr{relayVpnIpNet.Addr()})
|
|
|
- relayControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), theirUdpAddr)
|
|
|
+ myControl.InjectLightHouseAddr(relayVpnIpNet[0].Addr(), relayUdpAddr)
|
|
|
+ myControl.InjectRelays(theirVpnIpNet[0].Addr(), []netip.Addr{relayVpnIpNet[0].Addr()})
|
|
|
+ relayControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
|
|
|
|
|
|
// Build a router so we don't have to reason who gets which packet
|
|
|
r := router.NewR(t, myControl, relayControl, theirControl)
|
|
@@ -730,17 +731,17 @@ func TestRehandshakingRelaysPrimary(t *testing.T) {
|
|
|
theirControl.Start()
|
|
|
|
|
|
t.Log("Trigger a handshake from me to them via the relay")
|
|
|
- myControl.InjectTunUDPPacket(theirVpnIpNet.Addr(), 80, 80, []byte("Hi from me"))
|
|
|
+ myControl.InjectTunUDPPacket(theirVpnIpNet[0].Addr(), 80, myVpnIpNet[0].Addr(), 80, []byte("Hi from me"))
|
|
|
|
|
|
p := r.RouteForAllUntilTxTun(theirControl)
|
|
|
r.Log("Assert the tunnel works")
|
|
|
- assertUdpPacket(t, []byte("Hi from me"), p, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), 80, 80)
|
|
|
+ assertUdpPacket(t, []byte("Hi from me"), p, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), 80, 80)
|
|
|
r.RenderHostmaps("working hostmaps", myControl, relayControl, theirControl)
|
|
|
|
|
|
// When I update the certificate for the relay, both me and them will have 2 host infos for the relay,
|
|
|
// and the main host infos will not have any relay state to handle the me<->relay<->them tunnel.
|
|
|
r.Log("Renew relay certificate and spin until me and them sees it")
|
|
|
- _, _, myNextPrivKey, myNextPEM := NewTestCert(ca, caKey, "relay", time.Now(), time.Now().Add(5*time.Minute), []netip.Prefix{relayVpnIpNet}, nil, []string{"new group"})
|
|
|
+ _, _, myNextPrivKey, myNextPEM := NewTestCert(cert.Version1, ca, caKey, "relay", time.Now(), time.Now().Add(5*time.Minute), relayVpnIpNet, nil, []string{"new group"})
|
|
|
|
|
|
caB, err := ca.MarshalPEM()
|
|
|
if err != nil {
|
|
@@ -758,8 +759,8 @@ func TestRehandshakingRelaysPrimary(t *testing.T) {
|
|
|
|
|
|
for {
|
|
|
r.Log("Assert the tunnel works between myVpnIpNet and relayVpnIpNet")
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), relayVpnIpNet.Addr(), myControl, relayControl, r)
|
|
|
- c := myControl.GetHostInfoByVpnIp(relayVpnIpNet.Addr(), false)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), relayVpnIpNet[0].Addr(), myControl, relayControl, r)
|
|
|
+ c := myControl.GetHostInfoByVpnAddr(relayVpnIpNet[0].Addr(), false)
|
|
|
if len(c.Cert.Groups()) != 0 {
|
|
|
// We have a new certificate now
|
|
|
r.Log("Certificate between my and relay is updated!")
|
|
@@ -771,8 +772,8 @@ func TestRehandshakingRelaysPrimary(t *testing.T) {
|
|
|
|
|
|
for {
|
|
|
r.Log("Assert the tunnel works between theirVpnIpNet and relayVpnIpNet")
|
|
|
- assertTunnel(t, theirVpnIpNet.Addr(), relayVpnIpNet.Addr(), theirControl, relayControl, r)
|
|
|
- c := theirControl.GetHostInfoByVpnIp(relayVpnIpNet.Addr(), false)
|
|
|
+ assertTunnel(t, theirVpnIpNet[0].Addr(), relayVpnIpNet[0].Addr(), theirControl, relayControl, r)
|
|
|
+ c := theirControl.GetHostInfoByVpnAddr(relayVpnIpNet[0].Addr(), false)
|
|
|
if len(c.Cert.Groups()) != 0 {
|
|
|
// We have a new certificate now
|
|
|
r.Log("Certificate between their and relay is updated!")
|
|
@@ -783,13 +784,13 @@ func TestRehandshakingRelaysPrimary(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r.Log("Assert the relay tunnel still works")
|
|
|
- assertTunnel(t, theirVpnIpNet.Addr(), myVpnIpNet.Addr(), theirControl, myControl, r)
|
|
|
+ assertTunnel(t, theirVpnIpNet[0].Addr(), myVpnIpNet[0].Addr(), theirControl, myControl, r)
|
|
|
r.RenderHostmaps("working hostmaps", myControl, relayControl, theirControl)
|
|
|
// We should have two hostinfos on all sides
|
|
|
for len(myControl.GetHostmap().Indexes) != 2 {
|
|
|
t.Logf("Waiting for myControl hostinfos (%v != 2) to get cleaned up from lack of use...", len(myControl.GetHostmap().Indexes))
|
|
|
r.Log("Assert the relay tunnel still works")
|
|
|
- assertTunnel(t, theirVpnIpNet.Addr(), myVpnIpNet.Addr(), theirControl, myControl, r)
|
|
|
+ assertTunnel(t, theirVpnIpNet[0].Addr(), myVpnIpNet[0].Addr(), theirControl, myControl, r)
|
|
|
r.Log("yupitdoes")
|
|
|
time.Sleep(time.Second)
|
|
|
}
|
|
@@ -797,7 +798,7 @@ func TestRehandshakingRelaysPrimary(t *testing.T) {
|
|
|
for len(theirControl.GetHostmap().Indexes) != 2 {
|
|
|
t.Logf("Waiting for theirControl hostinfos (%v != 2) to get cleaned up from lack of use...", len(theirControl.GetHostmap().Indexes))
|
|
|
r.Log("Assert the relay tunnel still works")
|
|
|
- assertTunnel(t, theirVpnIpNet.Addr(), myVpnIpNet.Addr(), theirControl, myControl, r)
|
|
|
+ assertTunnel(t, theirVpnIpNet[0].Addr(), myVpnIpNet[0].Addr(), theirControl, myControl, r)
|
|
|
r.Log("yupitdoes")
|
|
|
time.Sleep(time.Second)
|
|
|
}
|
|
@@ -805,7 +806,7 @@ func TestRehandshakingRelaysPrimary(t *testing.T) {
|
|
|
for len(relayControl.GetHostmap().Indexes) != 2 {
|
|
|
t.Logf("Waiting for relayControl hostinfos (%v != 2) to get cleaned up from lack of use...", len(relayControl.GetHostmap().Indexes))
|
|
|
r.Log("Assert the relay tunnel still works")
|
|
|
- assertTunnel(t, theirVpnIpNet.Addr(), myVpnIpNet.Addr(), theirControl, myControl, r)
|
|
|
+ assertTunnel(t, theirVpnIpNet[0].Addr(), myVpnIpNet[0].Addr(), theirControl, myControl, r)
|
|
|
r.Log("yupitdoes")
|
|
|
time.Sleep(time.Second)
|
|
|
}
|
|
@@ -814,12 +815,12 @@ func TestRehandshakingRelaysPrimary(t *testing.T) {
|
|
|
|
|
|
func TestRehandshaking(t *testing.T) {
|
|
|
ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
|
|
|
- myControl, myVpnIpNet, myUdpAddr, myConfig := newSimpleServer(ca, caKey, "me ", "10.128.0.2/24", nil)
|
|
|
- theirControl, theirVpnIpNet, theirUdpAddr, theirConfig := newSimpleServer(ca, caKey, "them", "10.128.0.1/24", nil)
|
|
|
+ myControl, myVpnIpNet, myUdpAddr, myConfig := newSimpleServer(cert.Version1, ca, caKey, "me ", "10.128.0.2/24", nil)
|
|
|
+ theirControl, theirVpnIpNet, theirUdpAddr, theirConfig := newSimpleServer(cert.Version1, ca, caKey, "them", "10.128.0.1/24", nil)
|
|
|
|
|
|
// Put their info in our lighthouse and vice versa
|
|
|
- myControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), theirUdpAddr)
|
|
|
- theirControl.InjectLightHouseAddr(myVpnIpNet.Addr(), myUdpAddr)
|
|
|
+ myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
|
|
|
+ theirControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr)
|
|
|
|
|
|
// Build a router so we don't have to reason who gets which packet
|
|
|
r := router.NewR(t, myControl, theirControl)
|
|
@@ -830,12 +831,12 @@ func TestRehandshaking(t *testing.T) {
|
|
|
theirControl.Start()
|
|
|
|
|
|
t.Log("Stand up a tunnel between me and them")
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
|
|
|
r.RenderHostmaps("Starting hostmaps", myControl, theirControl)
|
|
|
|
|
|
r.Log("Renew my certificate and spin until their sees it")
|
|
|
- _, _, myNextPrivKey, myNextPEM := NewTestCert(ca, caKey, "me", time.Now(), time.Now().Add(5*time.Minute), []netip.Prefix{myVpnIpNet}, nil, []string{"new group"})
|
|
|
+ _, _, myNextPrivKey, myNextPEM := NewTestCert(cert.Version1, ca, caKey, "me", time.Now(), time.Now().Add(5*time.Minute), myVpnIpNet, nil, []string{"new group"})
|
|
|
|
|
|
caB, err := ca.MarshalPEM()
|
|
|
if err != nil {
|
|
@@ -852,8 +853,8 @@ func TestRehandshaking(t *testing.T) {
|
|
|
myConfig.ReloadConfigString(string(rc))
|
|
|
|
|
|
for {
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
- c := theirControl.GetHostInfoByVpnIp(myVpnIpNet.Addr(), false)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
+ c := theirControl.GetHostInfoByVpnAddr(myVpnIpNet[0].Addr(), false)
|
|
|
if len(c.Cert.Groups()) != 0 {
|
|
|
// We have a new certificate now
|
|
|
break
|
|
@@ -880,19 +881,19 @@ func TestRehandshaking(t *testing.T) {
|
|
|
|
|
|
r.Log("Spin until there is only 1 tunnel")
|
|
|
for len(myControl.GetHostmap().Indexes)+len(theirControl.GetHostmap().Indexes) > 2 {
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
t.Log("Connection manager hasn't ticked yet")
|
|
|
time.Sleep(time.Second)
|
|
|
}
|
|
|
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
myFinalHostmapHosts := myControl.ListHostmapHosts(false)
|
|
|
myFinalHostmapIndexes := myControl.ListHostmapIndexes(false)
|
|
|
theirFinalHostmapHosts := theirControl.ListHostmapHosts(false)
|
|
|
theirFinalHostmapIndexes := theirControl.ListHostmapIndexes(false)
|
|
|
|
|
|
// Make sure the correct tunnel won
|
|
|
- c := theirControl.GetHostInfoByVpnIp(myVpnIpNet.Addr(), false)
|
|
|
+ c := theirControl.GetHostInfoByVpnAddr(myVpnIpNet[0].Addr(), false)
|
|
|
assert.Contains(t, c.Cert.Groups(), "new group")
|
|
|
|
|
|
// We should only have a single tunnel now on both sides
|
|
@@ -911,12 +912,12 @@ func TestRehandshakingLoser(t *testing.T) {
|
|
|
// The purpose of this test is that the race loser renews their certificate and rehandshakes. The final tunnel
|
|
|
// Should be the one with the new certificate
|
|
|
ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
|
|
|
- myControl, myVpnIpNet, myUdpAddr, myConfig := newSimpleServer(ca, caKey, "me ", "10.128.0.2/24", nil)
|
|
|
- theirControl, theirVpnIpNet, theirUdpAddr, theirConfig := newSimpleServer(ca, caKey, "them", "10.128.0.1/24", nil)
|
|
|
+ myControl, myVpnIpNet, myUdpAddr, myConfig := newSimpleServer(cert.Version1, ca, caKey, "me ", "10.128.0.2/24", nil)
|
|
|
+ theirControl, theirVpnIpNet, theirUdpAddr, theirConfig := newSimpleServer(cert.Version1, ca, caKey, "them", "10.128.0.1/24", nil)
|
|
|
|
|
|
// Put their info in our lighthouse and vice versa
|
|
|
- myControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), theirUdpAddr)
|
|
|
- theirControl.InjectLightHouseAddr(myVpnIpNet.Addr(), myUdpAddr)
|
|
|
+ myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
|
|
|
+ theirControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr)
|
|
|
|
|
|
// Build a router so we don't have to reason who gets which packet
|
|
|
r := router.NewR(t, myControl, theirControl)
|
|
@@ -927,16 +928,12 @@ func TestRehandshakingLoser(t *testing.T) {
|
|
|
theirControl.Start()
|
|
|
|
|
|
t.Log("Stand up a tunnel between me and them")
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
-
|
|
|
- tt1 := myControl.GetHostInfoByVpnIp(theirVpnIpNet.Addr(), false)
|
|
|
- tt2 := theirControl.GetHostInfoByVpnIp(myVpnIpNet.Addr(), false)
|
|
|
- fmt.Println(tt1.LocalIndex, tt2.LocalIndex)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
|
|
|
r.RenderHostmaps("Starting hostmaps", myControl, theirControl)
|
|
|
|
|
|
r.Log("Renew their certificate and spin until mine sees it")
|
|
|
- _, _, theirNextPrivKey, theirNextPEM := NewTestCert(ca, caKey, "them", time.Now(), time.Now().Add(5*time.Minute), []netip.Prefix{theirVpnIpNet}, nil, []string{"their new group"})
|
|
|
+ _, _, theirNextPrivKey, theirNextPEM := NewTestCert(cert.Version1, ca, caKey, "them", time.Now(), time.Now().Add(5*time.Minute), theirVpnIpNet, nil, []string{"their new group"})
|
|
|
|
|
|
caB, err := ca.MarshalPEM()
|
|
|
if err != nil {
|
|
@@ -953,8 +950,8 @@ func TestRehandshakingLoser(t *testing.T) {
|
|
|
theirConfig.ReloadConfigString(string(rc))
|
|
|
|
|
|
for {
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
- theirCertInMe := myControl.GetHostInfoByVpnIp(theirVpnIpNet.Addr(), false)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
+ theirCertInMe := myControl.GetHostInfoByVpnAddr(theirVpnIpNet[0].Addr(), false)
|
|
|
|
|
|
if slices.Contains(theirCertInMe.Cert.Groups(), "their new group") {
|
|
|
break
|
|
@@ -980,19 +977,19 @@ func TestRehandshakingLoser(t *testing.T) {
|
|
|
|
|
|
r.Log("Spin until there is only 1 tunnel")
|
|
|
for len(myControl.GetHostmap().Indexes)+len(theirControl.GetHostmap().Indexes) > 2 {
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
t.Log("Connection manager hasn't ticked yet")
|
|
|
time.Sleep(time.Second)
|
|
|
}
|
|
|
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
myFinalHostmapHosts := myControl.ListHostmapHosts(false)
|
|
|
myFinalHostmapIndexes := myControl.ListHostmapIndexes(false)
|
|
|
theirFinalHostmapHosts := theirControl.ListHostmapHosts(false)
|
|
|
theirFinalHostmapIndexes := theirControl.ListHostmapIndexes(false)
|
|
|
|
|
|
// Make sure the correct tunnel won
|
|
|
- theirCertInMe := myControl.GetHostInfoByVpnIp(theirVpnIpNet.Addr(), false)
|
|
|
+ theirCertInMe := myControl.GetHostInfoByVpnAddr(theirVpnIpNet[0].Addr(), false)
|
|
|
assert.Contains(t, theirCertInMe.Cert.Groups(), "their new group")
|
|
|
|
|
|
// We should only have a single tunnel now on both sides
|
|
@@ -1011,12 +1008,12 @@ func TestRaceRegression(t *testing.T) {
|
|
|
// We had a bug where we were not finding the duplicate handshake and responding to the final stage 1 which
|
|
|
// caused a cross-linked hostinfo
|
|
|
ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
|
|
|
- myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me", "10.128.0.1/24", nil)
|
|
|
- theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them", "10.128.0.2/24", nil)
|
|
|
+ myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "me", "10.128.0.1/24", nil)
|
|
|
+ theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them", "10.128.0.2/24", nil)
|
|
|
|
|
|
// Put their info in our lighthouse
|
|
|
- myControl.InjectLightHouseAddr(theirVpnIpNet.Addr(), theirUdpAddr)
|
|
|
- theirControl.InjectLightHouseAddr(myVpnIpNet.Addr(), myUdpAddr)
|
|
|
+ myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
|
|
|
+ theirControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr)
|
|
|
|
|
|
// Start the servers
|
|
|
myControl.Start()
|
|
@@ -1030,8 +1027,8 @@ func TestRaceRegression(t *testing.T) {
|
|
|
//them rx stage:2 initiatorIndex=120607833 responderIndex=4209862089
|
|
|
|
|
|
t.Log("Start both handshakes")
|
|
|
- myControl.InjectTunUDPPacket(theirVpnIpNet.Addr(), 80, 80, []byte("Hi from me"))
|
|
|
- theirControl.InjectTunUDPPacket(myVpnIpNet.Addr(), 80, 80, []byte("Hi from them"))
|
|
|
+ myControl.InjectTunUDPPacket(theirVpnIpNet[0].Addr(), 80, myVpnIpNet[0].Addr(), 80, []byte("Hi from me"))
|
|
|
+ theirControl.InjectTunUDPPacket(myVpnIpNet[0].Addr(), 80, theirVpnIpNet[0].Addr(), 80, []byte("Hi from them"))
|
|
|
|
|
|
t.Log("Get both stage 1")
|
|
|
myStage1ForThem := myControl.GetFromUDP(true)
|
|
@@ -1061,8 +1058,48 @@ func TestRaceRegression(t *testing.T) {
|
|
|
r.RenderHostmaps("Starting hostmaps", myControl, theirControl)
|
|
|
|
|
|
t.Log("Make sure the tunnel still works")
|
|
|
- assertTunnel(t, myVpnIpNet.Addr(), theirVpnIpNet.Addr(), myControl, theirControl, r)
|
|
|
+ assertTunnel(t, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
|
|
|
+
|
|
|
+ myControl.Stop()
|
|
|
+ theirControl.Stop()
|
|
|
+}
|
|
|
+
|
|
|
+func TestV2NonPrimaryWithLighthouse(t *testing.T) {
|
|
|
+ ca, _, caKey, _ := NewTestCaCert(time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
|
|
|
+ lhControl, lhVpnIpNet, lhUdpAddr, _ := newSimpleServer(cert.Version2, ca, caKey, "lh ", "10.128.0.1/24, ff::1/64", m{"lighthouse": m{"am_lighthouse": true}})
|
|
|
+
|
|
|
+ o := m{
|
|
|
+ "static_host_map": m{
|
|
|
+ lhVpnIpNet[1].Addr().String(): []string{lhUdpAddr.String()},
|
|
|
+ },
|
|
|
+ "lighthouse": m{
|
|
|
+ "hosts": []string{lhVpnIpNet[1].Addr().String()},
|
|
|
+ "local_allow_list": m{
|
|
|
+ // Try and block our lighthouse updates from using the actual addresses assigned to this computer
|
|
|
+ // If we start discovering addresses the test router doesn't know about then test traffic cant flow
|
|
|
+ "10.0.0.0/24": true,
|
|
|
+ "::/0": false,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ myControl, myVpnIpNet, _, _ := newSimpleServer(cert.Version2, ca, caKey, "me ", "10.128.0.2/24, ff::2/64", o)
|
|
|
+ theirControl, theirVpnIpNet, _, _ := newSimpleServer(cert.Version2, ca, caKey, "them", "10.128.0.3/24, ff::3/64", o)
|
|
|
+
|
|
|
+ // Build a router so we don't have to reason who gets which packet
|
|
|
+ r := router.NewR(t, lhControl, myControl, theirControl)
|
|
|
+ defer r.RenderFlow()
|
|
|
+
|
|
|
+ // Start the servers
|
|
|
+ lhControl.Start()
|
|
|
+ myControl.Start()
|
|
|
+ theirControl.Start()
|
|
|
+
|
|
|
+ t.Log("Stand up an ipv6 tunnel between me and them")
|
|
|
+ assert.True(t, myVpnIpNet[1].Addr().Is6())
|
|
|
+ assert.True(t, theirVpnIpNet[1].Addr().Is6())
|
|
|
+ assertTunnel(t, myVpnIpNet[1].Addr(), theirVpnIpNet[1].Addr(), myControl, theirControl, r)
|
|
|
|
|
|
+ lhControl.Stop()
|
|
|
myControl.Stop()
|
|
|
theirControl.Stop()
|
|
|
}
|