handshakes_test.go 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. //go:build e2e_testing
  2. // +build e2e_testing
  3. package e2e
  4. import (
  5. "fmt"
  6. "net"
  7. "testing"
  8. "time"
  9. "github.com/sirupsen/logrus"
  10. "github.com/slackhq/nebula"
  11. "github.com/slackhq/nebula/e2e/router"
  12. "github.com/slackhq/nebula/header"
  13. "github.com/slackhq/nebula/iputil"
  14. "github.com/slackhq/nebula/udp"
  15. "github.com/stretchr/testify/assert"
  16. "gopkg.in/yaml.v2"
  17. )
  18. func BenchmarkHotPath(b *testing.B) {
  19. ca, _, caKey, _ := newTestCaCert(time.Now(), time.Now().Add(10*time.Minute), []*net.IPNet{}, []*net.IPNet{}, []string{})
  20. myControl, _, _, _ := newSimpleServer(ca, caKey, "me", net.IP{10, 0, 0, 1}, nil)
  21. theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them", net.IP{10, 0, 0, 2}, nil)
  22. // Put their info in our lighthouse
  23. myControl.InjectLightHouseAddr(theirVpnIpNet.IP, theirUdpAddr)
  24. // Start the servers
  25. myControl.Start()
  26. theirControl.Start()
  27. r := router.NewR(b, myControl, theirControl)
  28. r.CancelFlowLogs()
  29. for n := 0; n < b.N; n++ {
  30. myControl.InjectTunUDPPacket(theirVpnIpNet.IP, 80, 80, []byte("Hi from me"))
  31. _ = r.RouteForAllUntilTxTun(theirControl)
  32. }
  33. myControl.Stop()
  34. theirControl.Stop()
  35. }
  36. func TestGoodHandshake(t *testing.T) {
  37. ca, _, caKey, _ := newTestCaCert(time.Now(), time.Now().Add(10*time.Minute), []*net.IPNet{}, []*net.IPNet{}, []string{})
  38. myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me", net.IP{10, 0, 0, 1}, nil)
  39. theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them", net.IP{10, 0, 0, 2}, nil)
  40. // Put their info in our lighthouse
  41. myControl.InjectLightHouseAddr(theirVpnIpNet.IP, theirUdpAddr)
  42. // Start the servers
  43. myControl.Start()
  44. theirControl.Start()
  45. t.Log("Send a udp packet through to begin standing up the tunnel, this should come out the other side")
  46. myControl.InjectTunUDPPacket(theirVpnIpNet.IP, 80, 80, []byte("Hi from me"))
  47. t.Log("Have them consume my stage 0 packet. They have a tunnel now")
  48. theirControl.InjectUDPPacket(myControl.GetFromUDP(true))
  49. t.Log("Get their stage 1 packet so that we can play with it")
  50. stage1Packet := theirControl.GetFromUDP(true)
  51. t.Log("I consume a garbage packet with a proper nebula header for our tunnel")
  52. // this should log a statement and get ignored, allowing the real handshake packet to complete the tunnel
  53. badPacket := stage1Packet.Copy()
  54. badPacket.Data = badPacket.Data[:len(badPacket.Data)-header.Len]
  55. myControl.InjectUDPPacket(badPacket)
  56. t.Log("Have me consume their real stage 1 packet. I have a tunnel now")
  57. myControl.InjectUDPPacket(stage1Packet)
  58. t.Log("Wait until we see my cached packet come through")
  59. myControl.WaitForType(1, 0, theirControl)
  60. t.Log("Make sure our host infos are correct")
  61. assertHostInfoPair(t, myUdpAddr, theirUdpAddr, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl)
  62. t.Log("Get that cached packet and make sure it looks right")
  63. myCachedPacket := theirControl.GetFromTun(true)
  64. assertUdpPacket(t, []byte("Hi from me"), myCachedPacket, myVpnIpNet.IP, theirVpnIpNet.IP, 80, 80)
  65. t.Log("Do a bidirectional tunnel test")
  66. r := router.NewR(t, myControl, theirControl)
  67. defer r.RenderFlow()
  68. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  69. r.RenderHostmaps("Final hostmaps", myControl, theirControl)
  70. myControl.Stop()
  71. theirControl.Stop()
  72. //TODO: assert hostmaps
  73. }
  74. func TestWrongResponderHandshake(t *testing.T) {
  75. ca, _, caKey, _ := newTestCaCert(time.Now(), time.Now().Add(10*time.Minute), []*net.IPNet{}, []*net.IPNet{}, []string{})
  76. // The IPs here are chosen on purpose:
  77. // The current remote handling will sort by preference, public, and then lexically.
  78. // So we need them to have a higher address than evil (we could apply a preference though)
  79. myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me", net.IP{10, 0, 0, 100}, nil)
  80. theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them", net.IP{10, 0, 0, 99}, nil)
  81. evilControl, evilVpnIp, evilUdpAddr, _ := newSimpleServer(ca, caKey, "evil", net.IP{10, 0, 0, 2}, nil)
  82. // Add their real udp addr, which should be tried after evil.
  83. myControl.InjectLightHouseAddr(theirVpnIpNet.IP, theirUdpAddr)
  84. // Put the evil udp addr in for their vpn Ip, this is a case of being lied to by the lighthouse.
  85. myControl.InjectLightHouseAddr(theirVpnIpNet.IP, evilUdpAddr)
  86. // Build a router so we don't have to reason who gets which packet
  87. r := router.NewR(t, myControl, theirControl, evilControl)
  88. defer r.RenderFlow()
  89. // Start the servers
  90. myControl.Start()
  91. theirControl.Start()
  92. evilControl.Start()
  93. t.Log("Start the handshake process, we will route until we see our cached packet get sent to them")
  94. myControl.InjectTunUDPPacket(theirVpnIpNet.IP, 80, 80, []byte("Hi from me"))
  95. r.RouteForAllExitFunc(func(p *udp.Packet, c *nebula.Control) router.ExitType {
  96. h := &header.H{}
  97. err := h.Parse(p.Data)
  98. if err != nil {
  99. panic(err)
  100. }
  101. if p.ToIp.Equal(theirUdpAddr.IP) && p.ToPort == uint16(theirUdpAddr.Port) && h.Type == 1 {
  102. return router.RouteAndExit
  103. }
  104. return router.KeepRouting
  105. })
  106. //TODO: Assert pending hostmap - I should have a correct hostinfo for them now
  107. t.Log("My cached packet should be received by them")
  108. myCachedPacket := theirControl.GetFromTun(true)
  109. assertUdpPacket(t, []byte("Hi from me"), myCachedPacket, myVpnIpNet.IP, theirVpnIpNet.IP, 80, 80)
  110. t.Log("Test the tunnel with them")
  111. assertHostInfoPair(t, myUdpAddr, theirUdpAddr, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl)
  112. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  113. t.Log("Flush all packets from all controllers")
  114. r.FlushAll()
  115. t.Log("Ensure ensure I don't have any hostinfo artifacts from evil")
  116. assert.Nil(t, myControl.GetHostInfoByVpnIp(iputil.Ip2VpnIp(evilVpnIp.IP), true), "My pending hostmap should not contain evil")
  117. assert.Nil(t, myControl.GetHostInfoByVpnIp(iputil.Ip2VpnIp(evilVpnIp.IP), false), "My main hostmap should not contain evil")
  118. //NOTE: if evil lost the handshake race it may still have a tunnel since me would reject the handshake since the tunnel is complete
  119. //TODO: assert hostmaps for everyone
  120. r.RenderHostmaps("Final hostmaps", myControl, theirControl, evilControl)
  121. t.Log("Success!")
  122. myControl.Stop()
  123. theirControl.Stop()
  124. }
  125. func TestStage1Race(t *testing.T) {
  126. // This tests ensures that two hosts handshaking with each other at the same time will allow traffic to flow
  127. // But will eventually collapse down to a single tunnel
  128. ca, _, caKey, _ := newTestCaCert(time.Now(), time.Now().Add(10*time.Minute), []*net.IPNet{}, []*net.IPNet{}, []string{})
  129. myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me ", net.IP{10, 0, 0, 1}, nil)
  130. theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them", net.IP{10, 0, 0, 2}, nil)
  131. // Put their info in our lighthouse and vice versa
  132. myControl.InjectLightHouseAddr(theirVpnIpNet.IP, theirUdpAddr)
  133. theirControl.InjectLightHouseAddr(myVpnIpNet.IP, myUdpAddr)
  134. // Build a router so we don't have to reason who gets which packet
  135. r := router.NewR(t, myControl, theirControl)
  136. defer r.RenderFlow()
  137. // Start the servers
  138. myControl.Start()
  139. theirControl.Start()
  140. t.Log("Trigger a handshake to start on both me and them")
  141. myControl.InjectTunUDPPacket(theirVpnIpNet.IP, 80, 80, []byte("Hi from me"))
  142. theirControl.InjectTunUDPPacket(myVpnIpNet.IP, 80, 80, []byte("Hi from them"))
  143. t.Log("Get both stage 1 handshake packets")
  144. myHsForThem := myControl.GetFromUDP(true)
  145. theirHsForMe := theirControl.GetFromUDP(true)
  146. r.Log("Now inject both stage 1 handshake packets")
  147. r.InjectUDPPacket(theirControl, myControl, theirHsForMe)
  148. r.InjectUDPPacket(myControl, theirControl, myHsForThem)
  149. r.Log("Route until they receive a message packet")
  150. myCachedPacket := r.RouteForAllUntilTxTun(theirControl)
  151. assertUdpPacket(t, []byte("Hi from me"), myCachedPacket, myVpnIpNet.IP, theirVpnIpNet.IP, 80, 80)
  152. r.Log("Their cached packet should be received by me")
  153. theirCachedPacket := r.RouteForAllUntilTxTun(myControl)
  154. assertUdpPacket(t, []byte("Hi from them"), theirCachedPacket, theirVpnIpNet.IP, myVpnIpNet.IP, 80, 80)
  155. r.Log("Do a bidirectional tunnel test")
  156. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  157. myHostmapHosts := myControl.ListHostmapHosts(false)
  158. myHostmapIndexes := myControl.ListHostmapIndexes(false)
  159. theirHostmapHosts := theirControl.ListHostmapHosts(false)
  160. theirHostmapIndexes := theirControl.ListHostmapIndexes(false)
  161. // We should have two tunnels on both sides
  162. assert.Len(t, myHostmapHosts, 1)
  163. assert.Len(t, theirHostmapHosts, 1)
  164. assert.Len(t, myHostmapIndexes, 2)
  165. assert.Len(t, theirHostmapIndexes, 2)
  166. r.RenderHostmaps("Starting hostmaps", myControl, theirControl)
  167. r.Log("Spin until connection manager tears down a tunnel")
  168. for len(myControl.GetHostmap().Indexes)+len(theirControl.GetHostmap().Indexes) > 2 {
  169. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  170. t.Log("Connection manager hasn't ticked yet")
  171. time.Sleep(time.Second)
  172. }
  173. myFinalHostmapHosts := myControl.ListHostmapHosts(false)
  174. myFinalHostmapIndexes := myControl.ListHostmapIndexes(false)
  175. theirFinalHostmapHosts := theirControl.ListHostmapHosts(false)
  176. theirFinalHostmapIndexes := theirControl.ListHostmapIndexes(false)
  177. // We should only have a single tunnel now on both sides
  178. assert.Len(t, myFinalHostmapHosts, 1)
  179. assert.Len(t, theirFinalHostmapHosts, 1)
  180. assert.Len(t, myFinalHostmapIndexes, 1)
  181. assert.Len(t, theirFinalHostmapIndexes, 1)
  182. r.RenderHostmaps("Final hostmaps", myControl, theirControl)
  183. myControl.Stop()
  184. theirControl.Stop()
  185. }
  186. func TestUncleanShutdownRaceLoser(t *testing.T) {
  187. ca, _, caKey, _ := newTestCaCert(time.Now(), time.Now().Add(10*time.Minute), []*net.IPNet{}, []*net.IPNet{}, []string{})
  188. myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me ", net.IP{10, 0, 0, 1}, nil)
  189. theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them", net.IP{10, 0, 0, 2}, nil)
  190. // Teach my how to get to the relay and that their can be reached via the relay
  191. myControl.InjectLightHouseAddr(theirVpnIpNet.IP, theirUdpAddr)
  192. theirControl.InjectLightHouseAddr(myVpnIpNet.IP, myUdpAddr)
  193. // Build a router so we don't have to reason who gets which packet
  194. r := router.NewR(t, myControl, theirControl)
  195. defer r.RenderFlow()
  196. // Start the servers
  197. myControl.Start()
  198. theirControl.Start()
  199. r.Log("Trigger a handshake from me to them")
  200. myControl.InjectTunUDPPacket(theirVpnIpNet.IP, 80, 80, []byte("Hi from me"))
  201. p := r.RouteForAllUntilTxTun(theirControl)
  202. assertUdpPacket(t, []byte("Hi from me"), p, myVpnIpNet.IP, theirVpnIpNet.IP, 80, 80)
  203. r.Log("Nuke my hostmap")
  204. myHostmap := myControl.GetHostmap()
  205. myHostmap.Hosts = map[iputil.VpnIp]*nebula.HostInfo{}
  206. myHostmap.Indexes = map[uint32]*nebula.HostInfo{}
  207. myHostmap.RemoteIndexes = map[uint32]*nebula.HostInfo{}
  208. myControl.InjectTunUDPPacket(theirVpnIpNet.IP, 80, 80, []byte("Hi from me again"))
  209. p = r.RouteForAllUntilTxTun(theirControl)
  210. assertUdpPacket(t, []byte("Hi from me again"), p, myVpnIpNet.IP, theirVpnIpNet.IP, 80, 80)
  211. r.Log("Assert the tunnel works")
  212. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  213. r.Log("Wait for the dead index to go away")
  214. start := len(theirControl.GetHostmap().Indexes)
  215. for {
  216. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  217. if len(theirControl.GetHostmap().Indexes) < start {
  218. break
  219. }
  220. time.Sleep(time.Second)
  221. }
  222. r.RenderHostmaps("Final hostmaps", myControl, theirControl)
  223. }
  224. func TestUncleanShutdownRaceWinner(t *testing.T) {
  225. ca, _, caKey, _ := newTestCaCert(time.Now(), time.Now().Add(10*time.Minute), []*net.IPNet{}, []*net.IPNet{}, []string{})
  226. myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me ", net.IP{10, 0, 0, 1}, nil)
  227. theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them", net.IP{10, 0, 0, 2}, nil)
  228. // Teach my how to get to the relay and that their can be reached via the relay
  229. myControl.InjectLightHouseAddr(theirVpnIpNet.IP, theirUdpAddr)
  230. theirControl.InjectLightHouseAddr(myVpnIpNet.IP, myUdpAddr)
  231. // Build a router so we don't have to reason who gets which packet
  232. r := router.NewR(t, myControl, theirControl)
  233. defer r.RenderFlow()
  234. // Start the servers
  235. myControl.Start()
  236. theirControl.Start()
  237. r.Log("Trigger a handshake from me to them")
  238. myControl.InjectTunUDPPacket(theirVpnIpNet.IP, 80, 80, []byte("Hi from me"))
  239. p := r.RouteForAllUntilTxTun(theirControl)
  240. assertUdpPacket(t, []byte("Hi from me"), p, myVpnIpNet.IP, theirVpnIpNet.IP, 80, 80)
  241. r.RenderHostmaps("Final hostmaps", myControl, theirControl)
  242. r.Log("Nuke my hostmap")
  243. theirHostmap := theirControl.GetHostmap()
  244. theirHostmap.Hosts = map[iputil.VpnIp]*nebula.HostInfo{}
  245. theirHostmap.Indexes = map[uint32]*nebula.HostInfo{}
  246. theirHostmap.RemoteIndexes = map[uint32]*nebula.HostInfo{}
  247. theirControl.InjectTunUDPPacket(myVpnIpNet.IP, 80, 80, []byte("Hi from them again"))
  248. p = r.RouteForAllUntilTxTun(myControl)
  249. assertUdpPacket(t, []byte("Hi from them again"), p, theirVpnIpNet.IP, myVpnIpNet.IP, 80, 80)
  250. r.RenderHostmaps("Derp hostmaps", myControl, theirControl)
  251. r.Log("Assert the tunnel works")
  252. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  253. r.Log("Wait for the dead index to go away")
  254. start := len(myControl.GetHostmap().Indexes)
  255. for {
  256. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  257. if len(myControl.GetHostmap().Indexes) < start {
  258. break
  259. }
  260. time.Sleep(time.Second)
  261. }
  262. r.RenderHostmaps("Final hostmaps", myControl, theirControl)
  263. }
  264. func TestRelays(t *testing.T) {
  265. ca, _, caKey, _ := newTestCaCert(time.Now(), time.Now().Add(10*time.Minute), []*net.IPNet{}, []*net.IPNet{}, []string{})
  266. myControl, myVpnIpNet, _, _ := newSimpleServer(ca, caKey, "me ", net.IP{10, 0, 0, 1}, m{"relay": m{"use_relays": true}})
  267. relayControl, relayVpnIpNet, relayUdpAddr, _ := newSimpleServer(ca, caKey, "relay ", net.IP{10, 0, 0, 128}, m{"relay": m{"am_relay": true}})
  268. theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them ", net.IP{10, 0, 0, 2}, m{"relay": m{"use_relays": true}})
  269. // Teach my how to get to the relay and that their can be reached via the relay
  270. myControl.InjectLightHouseAddr(relayVpnIpNet.IP, relayUdpAddr)
  271. myControl.InjectRelays(theirVpnIpNet.IP, []net.IP{relayVpnIpNet.IP})
  272. relayControl.InjectLightHouseAddr(theirVpnIpNet.IP, theirUdpAddr)
  273. // Build a router so we don't have to reason who gets which packet
  274. r := router.NewR(t, myControl, relayControl, theirControl)
  275. defer r.RenderFlow()
  276. // Start the servers
  277. myControl.Start()
  278. relayControl.Start()
  279. theirControl.Start()
  280. t.Log("Trigger a handshake from me to them via the relay")
  281. myControl.InjectTunUDPPacket(theirVpnIpNet.IP, 80, 80, []byte("Hi from me"))
  282. p := r.RouteForAllUntilTxTun(theirControl)
  283. r.Log("Assert the tunnel works")
  284. assertUdpPacket(t, []byte("Hi from me"), p, myVpnIpNet.IP, theirVpnIpNet.IP, 80, 80)
  285. r.RenderHostmaps("Final hostmaps", myControl, relayControl, theirControl)
  286. //TODO: assert we actually used the relay even though it should be impossible for a tunnel to have occurred without it
  287. }
  288. func TestStage1RaceRelays(t *testing.T) {
  289. //NOTE: this is a race between me and relay resulting in a full tunnel from me to them via relay
  290. ca, _, caKey, _ := newTestCaCert(time.Now(), time.Now().Add(10*time.Minute), []*net.IPNet{}, []*net.IPNet{}, []string{})
  291. myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me ", net.IP{10, 0, 0, 1}, m{"relay": m{"use_relays": true}})
  292. relayControl, relayVpnIpNet, relayUdpAddr, _ := newSimpleServer(ca, caKey, "relay ", net.IP{10, 0, 0, 128}, m{"relay": m{"am_relay": true}})
  293. theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them ", net.IP{10, 0, 0, 2}, m{"relay": m{"use_relays": true}})
  294. // Teach my how to get to the relay and that their can be reached via the relay
  295. myControl.InjectLightHouseAddr(relayVpnIpNet.IP, relayUdpAddr)
  296. theirControl.InjectLightHouseAddr(relayVpnIpNet.IP, relayUdpAddr)
  297. myControl.InjectRelays(theirVpnIpNet.IP, []net.IP{relayVpnIpNet.IP})
  298. theirControl.InjectRelays(myVpnIpNet.IP, []net.IP{relayVpnIpNet.IP})
  299. relayControl.InjectLightHouseAddr(theirVpnIpNet.IP, theirUdpAddr)
  300. relayControl.InjectLightHouseAddr(myVpnIpNet.IP, myUdpAddr)
  301. // Build a router so we don't have to reason who gets which packet
  302. r := router.NewR(t, myControl, relayControl, theirControl)
  303. defer r.RenderFlow()
  304. // Start the servers
  305. myControl.Start()
  306. relayControl.Start()
  307. theirControl.Start()
  308. r.Log("Get a tunnel between me and relay")
  309. assertTunnel(t, myVpnIpNet.IP, relayVpnIpNet.IP, myControl, relayControl, r)
  310. r.Log("Get a tunnel between them and relay")
  311. assertTunnel(t, theirVpnIpNet.IP, relayVpnIpNet.IP, theirControl, relayControl, r)
  312. r.Log("Trigger a handshake from both them and me via relay to them and me")
  313. myControl.InjectTunUDPPacket(theirVpnIpNet.IP, 80, 80, []byte("Hi from me"))
  314. theirControl.InjectTunUDPPacket(myVpnIpNet.IP, 80, 80, []byte("Hi from them"))
  315. r.Log("Wait for a packet from them to me")
  316. p := r.RouteForAllUntilTxTun(myControl)
  317. _ = p
  318. myControl.Stop()
  319. theirControl.Stop()
  320. relayControl.Stop()
  321. //
  322. ////TODO: assert hostmaps
  323. }
  324. func TestStage1RaceRelays2(t *testing.T) {
  325. //NOTE: this is a race between me and relay resulting in a full tunnel from me to them via relay
  326. ca, _, caKey, _ := newTestCaCert(time.Now(), time.Now().Add(10*time.Minute), []*net.IPNet{}, []*net.IPNet{}, []string{})
  327. myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me ", net.IP{10, 0, 0, 1}, m{"relay": m{"use_relays": true}})
  328. relayControl, relayVpnIpNet, relayUdpAddr, _ := newSimpleServer(ca, caKey, "relay ", net.IP{10, 0, 0, 128}, m{"relay": m{"am_relay": true}})
  329. theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them ", net.IP{10, 0, 0, 2}, m{"relay": m{"use_relays": true}})
  330. l := NewTestLogger()
  331. // Teach my how to get to the relay and that their can be reached via the relay
  332. myControl.InjectLightHouseAddr(relayVpnIpNet.IP, relayUdpAddr)
  333. theirControl.InjectLightHouseAddr(relayVpnIpNet.IP, relayUdpAddr)
  334. myControl.InjectRelays(theirVpnIpNet.IP, []net.IP{relayVpnIpNet.IP})
  335. theirControl.InjectRelays(myVpnIpNet.IP, []net.IP{relayVpnIpNet.IP})
  336. relayControl.InjectLightHouseAddr(theirVpnIpNet.IP, theirUdpAddr)
  337. relayControl.InjectLightHouseAddr(myVpnIpNet.IP, myUdpAddr)
  338. // Build a router so we don't have to reason who gets which packet
  339. r := router.NewR(t, myControl, relayControl, theirControl)
  340. defer r.RenderFlow()
  341. // Start the servers
  342. myControl.Start()
  343. relayControl.Start()
  344. theirControl.Start()
  345. r.Log("Get a tunnel between me and relay")
  346. l.Info("Get a tunnel between me and relay")
  347. assertTunnel(t, myVpnIpNet.IP, relayVpnIpNet.IP, myControl, relayControl, r)
  348. r.Log("Get a tunnel between them and relay")
  349. l.Info("Get a tunnel between them and relay")
  350. assertTunnel(t, theirVpnIpNet.IP, relayVpnIpNet.IP, theirControl, relayControl, r)
  351. r.Log("Trigger a handshake from both them and me via relay to them and me")
  352. l.Info("Trigger a handshake from both them and me via relay to them and me")
  353. myControl.InjectTunUDPPacket(theirVpnIpNet.IP, 80, 80, []byte("Hi from me"))
  354. theirControl.InjectTunUDPPacket(myVpnIpNet.IP, 80, 80, []byte("Hi from them"))
  355. //r.RouteUntilAfterMsgType(myControl, header.Control, header.MessageNone)
  356. //r.RouteUntilAfterMsgType(theirControl, header.Control, header.MessageNone)
  357. r.Log("Wait for a packet from them to me")
  358. l.Info("Wait for a packet from them to me; myControl")
  359. r.RouteForAllUntilTxTun(myControl)
  360. l.Info("Wait for a packet from them to me; theirControl")
  361. r.RouteForAllUntilTxTun(theirControl)
  362. r.Log("Assert the tunnel works")
  363. l.Info("Assert the tunnel works")
  364. assertTunnel(t, theirVpnIpNet.IP, myVpnIpNet.IP, theirControl, myControl, r)
  365. t.Log("Wait until we remove extra tunnels")
  366. l.Info("Wait until we remove extra tunnels")
  367. l.WithFields(
  368. logrus.Fields{
  369. "myControl": len(myControl.GetHostmap().Indexes),
  370. "theirControl": len(theirControl.GetHostmap().Indexes),
  371. "relayControl": len(relayControl.GetHostmap().Indexes),
  372. }).Info("Waiting for hostinfos to be removed...")
  373. hostInfos := len(myControl.GetHostmap().Indexes) + len(theirControl.GetHostmap().Indexes) + len(relayControl.GetHostmap().Indexes)
  374. retries := 60
  375. for hostInfos > 6 && retries > 0 {
  376. hostInfos = len(myControl.GetHostmap().Indexes) + len(theirControl.GetHostmap().Indexes) + len(relayControl.GetHostmap().Indexes)
  377. l.WithFields(
  378. logrus.Fields{
  379. "myControl": len(myControl.GetHostmap().Indexes),
  380. "theirControl": len(theirControl.GetHostmap().Indexes),
  381. "relayControl": len(relayControl.GetHostmap().Indexes),
  382. }).Info("Waiting for hostinfos to be removed...")
  383. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  384. t.Log("Connection manager hasn't ticked yet")
  385. time.Sleep(time.Second)
  386. retries--
  387. }
  388. r.Log("Assert the tunnel works")
  389. l.Info("Assert the tunnel works")
  390. assertTunnel(t, theirVpnIpNet.IP, myVpnIpNet.IP, theirControl, myControl, r)
  391. myControl.Stop()
  392. theirControl.Stop()
  393. relayControl.Stop()
  394. //
  395. ////TODO: assert hostmaps
  396. }
  397. func TestRehandshakingRelays(t *testing.T) {
  398. ca, _, caKey, _ := newTestCaCert(time.Now(), time.Now().Add(10*time.Minute), []*net.IPNet{}, []*net.IPNet{}, []string{})
  399. myControl, myVpnIpNet, _, _ := newSimpleServer(ca, caKey, "me ", net.IP{10, 0, 0, 1}, m{"relay": m{"use_relays": true}})
  400. relayControl, relayVpnIpNet, relayUdpAddr, relayConfig := newSimpleServer(ca, caKey, "relay ", net.IP{10, 0, 0, 128}, m{"relay": m{"am_relay": true}})
  401. theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them ", net.IP{10, 0, 0, 2}, m{"relay": m{"use_relays": true}})
  402. // Teach my how to get to the relay and that their can be reached via the relay
  403. myControl.InjectLightHouseAddr(relayVpnIpNet.IP, relayUdpAddr)
  404. myControl.InjectRelays(theirVpnIpNet.IP, []net.IP{relayVpnIpNet.IP})
  405. relayControl.InjectLightHouseAddr(theirVpnIpNet.IP, theirUdpAddr)
  406. // Build a router so we don't have to reason who gets which packet
  407. r := router.NewR(t, myControl, relayControl, theirControl)
  408. defer r.RenderFlow()
  409. // Start the servers
  410. myControl.Start()
  411. relayControl.Start()
  412. theirControl.Start()
  413. t.Log("Trigger a handshake from me to them via the relay")
  414. myControl.InjectTunUDPPacket(theirVpnIpNet.IP, 80, 80, []byte("Hi from me"))
  415. p := r.RouteForAllUntilTxTun(theirControl)
  416. r.Log("Assert the tunnel works")
  417. assertUdpPacket(t, []byte("Hi from me"), p, myVpnIpNet.IP, theirVpnIpNet.IP, 80, 80)
  418. r.RenderHostmaps("working hostmaps", myControl, relayControl, theirControl)
  419. // When I update the certificate for the relay, both me and them will have 2 host infos for the relay,
  420. // and the main host infos will not have any relay state to handle the me<->relay<->them tunnel.
  421. r.Log("Renew relay certificate and spin until me and them sees it")
  422. _, _, myNextPrivKey, myNextPEM := newTestCert(ca, caKey, "relay", time.Now(), time.Now().Add(5*time.Minute), relayVpnIpNet, nil, []string{"new group"})
  423. caB, err := ca.MarshalToPEM()
  424. if err != nil {
  425. panic(err)
  426. }
  427. relayConfig.Settings["pki"] = m{
  428. "ca": string(caB),
  429. "cert": string(myNextPEM),
  430. "key": string(myNextPrivKey),
  431. }
  432. rc, err := yaml.Marshal(relayConfig.Settings)
  433. assert.NoError(t, err)
  434. relayConfig.ReloadConfigString(string(rc))
  435. for {
  436. r.Log("Assert the tunnel works between myVpnIpNet and relayVpnIpNet")
  437. assertTunnel(t, myVpnIpNet.IP, relayVpnIpNet.IP, myControl, relayControl, r)
  438. c := myControl.GetHostInfoByVpnIp(iputil.Ip2VpnIp(relayVpnIpNet.IP), false)
  439. if len(c.Cert.Details.Groups) != 0 {
  440. // We have a new certificate now
  441. r.Log("Certificate between my and relay is updated!")
  442. break
  443. }
  444. time.Sleep(time.Second)
  445. }
  446. for {
  447. r.Log("Assert the tunnel works between theirVpnIpNet and relayVpnIpNet")
  448. assertTunnel(t, theirVpnIpNet.IP, relayVpnIpNet.IP, theirControl, relayControl, r)
  449. c := theirControl.GetHostInfoByVpnIp(iputil.Ip2VpnIp(relayVpnIpNet.IP), false)
  450. if len(c.Cert.Details.Groups) != 0 {
  451. // We have a new certificate now
  452. r.Log("Certificate between their and relay is updated!")
  453. break
  454. }
  455. time.Sleep(time.Second)
  456. }
  457. r.Log("Assert the relay tunnel still works")
  458. assertTunnel(t, theirVpnIpNet.IP, myVpnIpNet.IP, theirControl, myControl, r)
  459. r.RenderHostmaps("working hostmaps", myControl, relayControl, theirControl)
  460. // We should have two hostinfos on all sides
  461. for len(myControl.GetHostmap().Indexes) != 2 {
  462. t.Logf("Waiting for myControl hostinfos (%v != 2) to get cleaned up from lack of use...", len(myControl.GetHostmap().Indexes))
  463. r.Log("Assert the relay tunnel still works")
  464. assertTunnel(t, theirVpnIpNet.IP, myVpnIpNet.IP, theirControl, myControl, r)
  465. r.Log("yupitdoes")
  466. time.Sleep(time.Second)
  467. }
  468. t.Logf("myControl hostinfos got cleaned up!")
  469. for len(theirControl.GetHostmap().Indexes) != 2 {
  470. t.Logf("Waiting for theirControl hostinfos (%v != 2) to get cleaned up from lack of use...", len(theirControl.GetHostmap().Indexes))
  471. r.Log("Assert the relay tunnel still works")
  472. assertTunnel(t, theirVpnIpNet.IP, myVpnIpNet.IP, theirControl, myControl, r)
  473. r.Log("yupitdoes")
  474. time.Sleep(time.Second)
  475. }
  476. t.Logf("theirControl hostinfos got cleaned up!")
  477. for len(relayControl.GetHostmap().Indexes) != 2 {
  478. t.Logf("Waiting for relayControl hostinfos (%v != 2) to get cleaned up from lack of use...", len(relayControl.GetHostmap().Indexes))
  479. r.Log("Assert the relay tunnel still works")
  480. assertTunnel(t, theirVpnIpNet.IP, myVpnIpNet.IP, theirControl, myControl, r)
  481. r.Log("yupitdoes")
  482. time.Sleep(time.Second)
  483. }
  484. t.Logf("relayControl hostinfos got cleaned up!")
  485. }
  486. func TestRehandshaking(t *testing.T) {
  487. ca, _, caKey, _ := newTestCaCert(time.Now(), time.Now().Add(10*time.Minute), []*net.IPNet{}, []*net.IPNet{}, []string{})
  488. myControl, myVpnIpNet, myUdpAddr, myConfig := newSimpleServer(ca, caKey, "me ", net.IP{10, 0, 0, 2}, nil)
  489. theirControl, theirVpnIpNet, theirUdpAddr, theirConfig := newSimpleServer(ca, caKey, "them", net.IP{10, 0, 0, 1}, nil)
  490. // Put their info in our lighthouse and vice versa
  491. myControl.InjectLightHouseAddr(theirVpnIpNet.IP, theirUdpAddr)
  492. theirControl.InjectLightHouseAddr(myVpnIpNet.IP, myUdpAddr)
  493. // Build a router so we don't have to reason who gets which packet
  494. r := router.NewR(t, myControl, theirControl)
  495. defer r.RenderFlow()
  496. // Start the servers
  497. myControl.Start()
  498. theirControl.Start()
  499. t.Log("Stand up a tunnel between me and them")
  500. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  501. r.RenderHostmaps("Starting hostmaps", myControl, theirControl)
  502. r.Log("Renew my certificate and spin until their sees it")
  503. _, _, myNextPrivKey, myNextPEM := newTestCert(ca, caKey, "me", time.Now(), time.Now().Add(5*time.Minute), myVpnIpNet, nil, []string{"new group"})
  504. caB, err := ca.MarshalToPEM()
  505. if err != nil {
  506. panic(err)
  507. }
  508. myConfig.Settings["pki"] = m{
  509. "ca": string(caB),
  510. "cert": string(myNextPEM),
  511. "key": string(myNextPrivKey),
  512. }
  513. rc, err := yaml.Marshal(myConfig.Settings)
  514. assert.NoError(t, err)
  515. myConfig.ReloadConfigString(string(rc))
  516. for {
  517. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  518. c := theirControl.GetHostInfoByVpnIp(iputil.Ip2VpnIp(myVpnIpNet.IP), false)
  519. if len(c.Cert.Details.Groups) != 0 {
  520. // We have a new certificate now
  521. break
  522. }
  523. time.Sleep(time.Second)
  524. }
  525. // Flip their firewall to only allowing the new group to catch the tunnels reverting incorrectly
  526. rc, err = yaml.Marshal(theirConfig.Settings)
  527. assert.NoError(t, err)
  528. var theirNewConfig m
  529. assert.NoError(t, yaml.Unmarshal(rc, &theirNewConfig))
  530. theirFirewall := theirNewConfig["firewall"].(map[interface{}]interface{})
  531. theirFirewall["inbound"] = []m{{
  532. "proto": "any",
  533. "port": "any",
  534. "group": "new group",
  535. }}
  536. rc, err = yaml.Marshal(theirNewConfig)
  537. assert.NoError(t, err)
  538. theirConfig.ReloadConfigString(string(rc))
  539. r.Log("Spin until there is only 1 tunnel")
  540. for len(myControl.GetHostmap().Indexes)+len(theirControl.GetHostmap().Indexes) > 2 {
  541. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  542. t.Log("Connection manager hasn't ticked yet")
  543. time.Sleep(time.Second)
  544. }
  545. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  546. myFinalHostmapHosts := myControl.ListHostmapHosts(false)
  547. myFinalHostmapIndexes := myControl.ListHostmapIndexes(false)
  548. theirFinalHostmapHosts := theirControl.ListHostmapHosts(false)
  549. theirFinalHostmapIndexes := theirControl.ListHostmapIndexes(false)
  550. // Make sure the correct tunnel won
  551. c := theirControl.GetHostInfoByVpnIp(iputil.Ip2VpnIp(myVpnIpNet.IP), false)
  552. assert.Contains(t, c.Cert.Details.Groups, "new group")
  553. // We should only have a single tunnel now on both sides
  554. assert.Len(t, myFinalHostmapHosts, 1)
  555. assert.Len(t, theirFinalHostmapHosts, 1)
  556. assert.Len(t, myFinalHostmapIndexes, 1)
  557. assert.Len(t, theirFinalHostmapIndexes, 1)
  558. r.RenderHostmaps("Final hostmaps", myControl, theirControl)
  559. myControl.Stop()
  560. theirControl.Stop()
  561. }
  562. func TestRehandshakingLoser(t *testing.T) {
  563. // The purpose of this test is that the race loser renews their certificate and rehandshakes. The final tunnel
  564. // Should be the one with the new certificate
  565. ca, _, caKey, _ := newTestCaCert(time.Now(), time.Now().Add(10*time.Minute), []*net.IPNet{}, []*net.IPNet{}, []string{})
  566. myControl, myVpnIpNet, myUdpAddr, myConfig := newSimpleServer(ca, caKey, "me ", net.IP{10, 0, 0, 2}, nil)
  567. theirControl, theirVpnIpNet, theirUdpAddr, theirConfig := newSimpleServer(ca, caKey, "them", net.IP{10, 0, 0, 1}, nil)
  568. // Put their info in our lighthouse and vice versa
  569. myControl.InjectLightHouseAddr(theirVpnIpNet.IP, theirUdpAddr)
  570. theirControl.InjectLightHouseAddr(myVpnIpNet.IP, myUdpAddr)
  571. // Build a router so we don't have to reason who gets which packet
  572. r := router.NewR(t, myControl, theirControl)
  573. defer r.RenderFlow()
  574. // Start the servers
  575. myControl.Start()
  576. theirControl.Start()
  577. t.Log("Stand up a tunnel between me and them")
  578. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  579. tt1 := myControl.GetHostInfoByVpnIp(iputil.Ip2VpnIp(theirVpnIpNet.IP), false)
  580. tt2 := theirControl.GetHostInfoByVpnIp(iputil.Ip2VpnIp(myVpnIpNet.IP), false)
  581. fmt.Println(tt1.LocalIndex, tt2.LocalIndex)
  582. r.RenderHostmaps("Starting hostmaps", myControl, theirControl)
  583. r.Log("Renew their certificate and spin until mine sees it")
  584. _, _, theirNextPrivKey, theirNextPEM := newTestCert(ca, caKey, "them", time.Now(), time.Now().Add(5*time.Minute), theirVpnIpNet, nil, []string{"their new group"})
  585. caB, err := ca.MarshalToPEM()
  586. if err != nil {
  587. panic(err)
  588. }
  589. theirConfig.Settings["pki"] = m{
  590. "ca": string(caB),
  591. "cert": string(theirNextPEM),
  592. "key": string(theirNextPrivKey),
  593. }
  594. rc, err := yaml.Marshal(theirConfig.Settings)
  595. assert.NoError(t, err)
  596. theirConfig.ReloadConfigString(string(rc))
  597. for {
  598. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  599. theirCertInMe := myControl.GetHostInfoByVpnIp(iputil.Ip2VpnIp(theirVpnIpNet.IP), false)
  600. _, theirNewGroup := theirCertInMe.Cert.Details.InvertedGroups["their new group"]
  601. if theirNewGroup {
  602. break
  603. }
  604. time.Sleep(time.Second)
  605. }
  606. // Flip my firewall to only allowing the new group to catch the tunnels reverting incorrectly
  607. rc, err = yaml.Marshal(myConfig.Settings)
  608. assert.NoError(t, err)
  609. var myNewConfig m
  610. assert.NoError(t, yaml.Unmarshal(rc, &myNewConfig))
  611. theirFirewall := myNewConfig["firewall"].(map[interface{}]interface{})
  612. theirFirewall["inbound"] = []m{{
  613. "proto": "any",
  614. "port": "any",
  615. "group": "their new group",
  616. }}
  617. rc, err = yaml.Marshal(myNewConfig)
  618. assert.NoError(t, err)
  619. myConfig.ReloadConfigString(string(rc))
  620. r.Log("Spin until there is only 1 tunnel")
  621. for len(myControl.GetHostmap().Indexes)+len(theirControl.GetHostmap().Indexes) > 2 {
  622. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  623. t.Log("Connection manager hasn't ticked yet")
  624. time.Sleep(time.Second)
  625. }
  626. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  627. myFinalHostmapHosts := myControl.ListHostmapHosts(false)
  628. myFinalHostmapIndexes := myControl.ListHostmapIndexes(false)
  629. theirFinalHostmapHosts := theirControl.ListHostmapHosts(false)
  630. theirFinalHostmapIndexes := theirControl.ListHostmapIndexes(false)
  631. // Make sure the correct tunnel won
  632. theirCertInMe := myControl.GetHostInfoByVpnIp(iputil.Ip2VpnIp(theirVpnIpNet.IP), false)
  633. assert.Contains(t, theirCertInMe.Cert.Details.Groups, "their new group")
  634. // We should only have a single tunnel now on both sides
  635. assert.Len(t, myFinalHostmapHosts, 1)
  636. assert.Len(t, theirFinalHostmapHosts, 1)
  637. assert.Len(t, myFinalHostmapIndexes, 1)
  638. assert.Len(t, theirFinalHostmapIndexes, 1)
  639. r.RenderHostmaps("Final hostmaps", myControl, theirControl)
  640. myControl.Stop()
  641. theirControl.Stop()
  642. }
  643. func TestRaceRegression(t *testing.T) {
  644. // This test forces stage 1, stage 2, stage 1 to be received by me from them
  645. // We had a bug where we were not finding the duplicate handshake and responding to the final stage 1 which
  646. // caused a cross-linked hostinfo
  647. ca, _, caKey, _ := newTestCaCert(time.Now(), time.Now().Add(10*time.Minute), []*net.IPNet{}, []*net.IPNet{}, []string{})
  648. myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(ca, caKey, "me", net.IP{10, 0, 0, 1}, nil)
  649. theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(ca, caKey, "them", net.IP{10, 0, 0, 2}, nil)
  650. // Put their info in our lighthouse
  651. myControl.InjectLightHouseAddr(theirVpnIpNet.IP, theirUdpAddr)
  652. theirControl.InjectLightHouseAddr(myVpnIpNet.IP, myUdpAddr)
  653. // Start the servers
  654. myControl.Start()
  655. theirControl.Start()
  656. //them rx stage:1 initiatorIndex=642843150 responderIndex=0
  657. //me rx stage:1 initiatorIndex=120607833 responderIndex=0
  658. //them rx stage:1 initiatorIndex=642843150 responderIndex=0
  659. //me rx stage:2 initiatorIndex=642843150 responderIndex=3701775874
  660. //me rx stage:1 initiatorIndex=120607833 responderIndex=0
  661. //them rx stage:2 initiatorIndex=120607833 responderIndex=4209862089
  662. t.Log("Start both handshakes")
  663. myControl.InjectTunUDPPacket(theirVpnIpNet.IP, 80, 80, []byte("Hi from me"))
  664. theirControl.InjectTunUDPPacket(myVpnIpNet.IP, 80, 80, []byte("Hi from them"))
  665. t.Log("Get both stage 1")
  666. myStage1ForThem := myControl.GetFromUDP(true)
  667. theirStage1ForMe := theirControl.GetFromUDP(true)
  668. t.Log("Inject them in a special way")
  669. theirControl.InjectUDPPacket(myStage1ForThem)
  670. myControl.InjectUDPPacket(theirStage1ForMe)
  671. theirControl.InjectUDPPacket(myStage1ForThem)
  672. //TODO: ensure stage 2
  673. t.Log("Get both stage 2")
  674. myStage2ForThem := myControl.GetFromUDP(true)
  675. theirStage2ForMe := theirControl.GetFromUDP(true)
  676. t.Log("Inject them in a special way again")
  677. myControl.InjectUDPPacket(theirStage2ForMe)
  678. myControl.InjectUDPPacket(theirStage1ForMe)
  679. theirControl.InjectUDPPacket(myStage2ForThem)
  680. r := router.NewR(t, myControl, theirControl)
  681. defer r.RenderFlow()
  682. t.Log("Flush the packets")
  683. r.RouteForAllUntilTxTun(myControl)
  684. r.RouteForAllUntilTxTun(theirControl)
  685. r.RenderHostmaps("Starting hostmaps", myControl, theirControl)
  686. t.Log("Make sure the tunnel still works")
  687. assertTunnel(t, myVpnIpNet.IP, theirVpnIpNet.IP, myControl, theirControl, r)
  688. myControl.Stop()
  689. theirControl.Stop()
  690. }
  691. //TODO: test
  692. // Race winner renews and handshakes
  693. // Race loser renews and handshakes
  694. // Does race winner repin the cert to old?
  695. //TODO: add a test with many lies