Compare commits
	
		
			5 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | d495ba9be7 | ||
|  | 5b194581b5 | ||
|  | 55f63043ee | ||
|  | 36172bf310 | ||
| 2549e1ae08 | 
| @@ -1,4 +1,4 @@ | |||||||
| # vppn: Virtual Pretty Private Network | # vppn: Virtual Potentially Private Network | ||||||
|  |  | ||||||
| ## TODO | ## TODO | ||||||
|  |  | ||||||
| @@ -30,7 +30,7 @@ AmbientCapabilities=CAP_NET_BIND_SERVICE | |||||||
| Type=simple | Type=simple | ||||||
| User=user | User=user | ||||||
| WorkingDirectory=/home/user/ | WorkingDirectory=/home/user/ | ||||||
| ExecStart=/home/user/hub -listen <addr>:https -secure=true -root-dir=/home/user | ExecStart=/home/user/hub -listen <addr>:https -root-dir=/home/user | ||||||
| Restart=always | Restart=always | ||||||
| RestartSec=8 | RestartSec=8 | ||||||
| TimeoutStopSec=24 | TimeoutStopSec=24 | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								go.mod
									
									
									
									
									
								
							| @@ -5,13 +5,12 @@ go 1.23.2 | |||||||
| require ( | require ( | ||||||
| 	git.crumpington.com/lib/go v0.8.1 | 	git.crumpington.com/lib/go v0.8.1 | ||||||
| 	git.crumpington.com/lib/webutil v0.0.7 | 	git.crumpington.com/lib/webutil v0.0.7 | ||||||
| 	github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 |  | ||||||
| 	golang.org/x/crypto v0.29.0 | 	golang.org/x/crypto v0.29.0 | ||||||
|  | 	golang.org/x/sys v0.27.0 | ||||||
| ) | ) | ||||||
|  |  | ||||||
| require ( | require ( | ||||||
| 	github.com/mattn/go-sqlite3 v1.14.24 // indirect | 	github.com/mattn/go-sqlite3 v1.14.24 // indirect | ||||||
| 	golang.org/x/net v0.31.0 // indirect | 	golang.org/x/net v0.31.0 // indirect | ||||||
| 	golang.org/x/sys v0.27.0 // indirect |  | ||||||
| 	golang.org/x/text v0.20.0 // indirect | 	golang.org/x/text v0.20.0 // indirect | ||||||
| ) | ) | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.sum
									
									
									
									
									
								
							| @@ -4,8 +4,6 @@ git.crumpington.com/lib/webutil v0.0.7 h1:1RG9CpuXYalT0NPj8fvxjOLV566LqL37APvAdA | |||||||
| git.crumpington.com/lib/webutil v0.0.7/go.mod h1:efIEiuK1uqFIhI/dlsWUHMsC5bXcEbJEjmdluRoFPPQ= | git.crumpington.com/lib/webutil v0.0.7/go.mod h1:efIEiuK1uqFIhI/dlsWUHMsC5bXcEbJEjmdluRoFPPQ= | ||||||
| github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM= | github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM= | ||||||
| github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= | github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= | ||||||
| github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 h1:TG/diQgUe0pntT/2D9tmUCz4VNwm9MfrtPr0SU2qSX8= |  | ||||||
| github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8/go.mod h1:P5HUIBuIWKbyjl083/loAegFkfbFNx5i2qEP4CNbm7E= |  | ||||||
| golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= | golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= | ||||||
| golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= | golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= | ||||||
| golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= | golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= | ||||||
|   | |||||||
							
								
								
									
										18
									
								
								hub/app.go
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								hub/app.go
									
									
									
									
									
								
							| @@ -19,14 +19,14 @@ var templateFS embed.FS | |||||||
| type Config struct { | type Config struct { | ||||||
| 	RootDir    string | 	RootDir    string | ||||||
| 	ListenAddr string | 	ListenAddr string | ||||||
| 	Secure     bool | 	Insecure   bool | ||||||
| } | } | ||||||
|  |  | ||||||
| type App struct { | type App struct { | ||||||
| 	api    *api.API | 	api      *api.API | ||||||
| 	mux    *http.ServeMux | 	mux      *http.ServeMux | ||||||
| 	tmpl   map[string]*template.Template | 	tmpl     map[string]*template.Template | ||||||
| 	secure bool | 	insecure bool | ||||||
| } | } | ||||||
|  |  | ||||||
| func NewApp(conf Config) (*App, error) { | func NewApp(conf Config) (*App, error) { | ||||||
| @@ -36,10 +36,10 @@ func NewApp(conf Config) (*App, error) { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	app := &App{ | 	app := &App{ | ||||||
| 		api:    api, | 		api:      api, | ||||||
| 		mux:    http.NewServeMux(), | 		mux:      http.NewServeMux(), | ||||||
| 		tmpl:   webutil.ParseTemplateSet(templateFuncs, templateFS), | 		tmpl:     webutil.ParseTemplateSet(templateFuncs, templateFS), | ||||||
| 		secure: conf.Secure, | 		insecure: conf.Insecure, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	app.registerRoutes() | 	app.registerRoutes() | ||||||
|   | |||||||
| @@ -17,8 +17,9 @@ func (a *App) setCookie(w http.ResponseWriter, name, value string) { | |||||||
| 		Name:     name, | 		Name:     name, | ||||||
| 		Value:    value, | 		Value:    value, | ||||||
| 		Path:     "/", | 		Path:     "/", | ||||||
| 		Secure:   a.secure, | 		Secure:   !a.insecure, | ||||||
| 		SameSite: http.SameSiteStrictMode, | 		SameSite: http.SameSiteStrictMode, | ||||||
|  | 		HttpOnly: true, | ||||||
| 		MaxAge:   86400 * 365 * 10, | 		MaxAge:   86400 * 365 * 10, | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ func Main() { | |||||||
| 	conf := Config{} | 	conf := Config{} | ||||||
| 	flag.StringVar(&conf.RootDir, "root-dir", "", "[REQUIRED] Root directory.") | 	flag.StringVar(&conf.RootDir, "root-dir", "", "[REQUIRED] Root directory.") | ||||||
| 	flag.StringVar(&conf.ListenAddr, "listen", "", "[REQUIRED] Listen address.") | 	flag.StringVar(&conf.ListenAddr, "listen", "", "[REQUIRED] Listen address.") | ||||||
| 	flag.BoolVar(&conf.Secure, "secure", false, "Use secure cookies.") | 	flag.BoolVar(&conf.Insecure, "insecure", false, "Don't use secure cookies.") | ||||||
|  |  | ||||||
| 	flag.Parse() | 	flag.Parse() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,7 +1,3 @@ | |||||||
| body { |  | ||||||
|     max-width: 1920px; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| .def-list tr td:first-child { | .def-list tr td:first-child { | ||||||
|     text-align:right; |     text-align:right; | ||||||
|     width:1%; |     width:1%; | ||||||
|   | |||||||
| @@ -3,7 +3,6 @@ | |||||||
|  |  | ||||||
| <p> | <p> | ||||||
|   <a href="/admin/peer/edit/?PeerIP={{.Peer.PeerIP}}">Edit</a> / |   <a href="/admin/peer/edit/?PeerIP={{.Peer.PeerIP}}">Edit</a> / | ||||||
|   <a href="/admin/peer/init/?PeerIP={{.Peer.PeerIP}}">Initialize</a> / |  | ||||||
|   <a href="/admin/peer/delete/?PeerIP={{.Peer.PeerIP}}">Delete</a> |   <a href="/admin/peer/delete/?PeerIP={{.Peer.PeerIP}}">Delete</a> | ||||||
| </p> | </p> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,23 +13,25 @@ const ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| type header struct { | type header struct { | ||||||
|  | 	Version  byte | ||||||
| 	StreamID byte | 	StreamID byte | ||||||
| 	Counter  uint64 // Init with time.Now().Unix << 30 to ensure monotonic. |  | ||||||
| 	SourceIP byte | 	SourceIP byte | ||||||
| 	DestIP   byte | 	DestIP   byte | ||||||
|  | 	Counter  uint64 // Init with time.Now().Unix << 30 to ensure monotonic. | ||||||
| } | } | ||||||
|  |  | ||||||
| func (h *header) Parse(b []byte) { | func (h *header) Parse(b []byte) { | ||||||
| 	h.StreamID = b[0] | 	h.Version = b[0] | ||||||
| 	h.Counter = *(*uint64)(unsafe.Pointer(&b[1])) | 	h.StreamID = b[1] | ||||||
| 	h.SourceIP = b[9] | 	h.SourceIP = b[2] | ||||||
| 	h.DestIP = b[10] | 	h.DestIP = b[3] | ||||||
|  | 	h.Counter = *(*uint64)(unsafe.Pointer(&b[4])) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (h *header) Marshal(buf []byte) { | func (h *header) Marshal(buf []byte) { | ||||||
| 	buf[0] = h.StreamID | 	buf[0] = h.Version | ||||||
| 	*(*uint64)(unsafe.Pointer(&buf[1])) = h.Counter | 	buf[1] = h.StreamID | ||||||
| 	buf[9] = h.SourceIP | 	buf[2] = h.SourceIP | ||||||
| 	buf[10] = h.DestIP | 	buf[3] = h.DestIP | ||||||
| 	buf[11] = 0 | 	*(*uint64)(unsafe.Pointer(&buf[4])) = h.Counter | ||||||
| } | } | ||||||
|   | |||||||
| @@ -107,14 +107,10 @@ type peerStateData struct { | |||||||
| // ---------------------------------------------------------------------------- | // ---------------------------------------------------------------------------- | ||||||
|  |  | ||||||
| func (s *peerStateData) sendControlPacket(pkt interface{ Marshal([]byte) []byte }) { | func (s *peerStateData) sendControlPacket(pkt interface{ Marshal([]byte) []byte }) { | ||||||
| 	s.limiter.Limit() | 	s._sendControlPacket(pkt, s.staged) | ||||||
| 	_sendControlPacket(pkt, s.staged, s.buf1, s.buf2) |  | ||||||
| } | } | ||||||
|  |  | ||||||
| func (s *peerStateData) sendControlPacketTo( | func (s *peerStateData) sendControlPacketTo(pkt interface{ Marshal([]byte) []byte }, addr netip.AddrPort) { | ||||||
| 	pkt interface{ Marshal([]byte) []byte }, |  | ||||||
| 	addr netip.AddrPort, |  | ||||||
| ) { |  | ||||||
| 	if !addr.IsValid() { | 	if !addr.IsValid() { | ||||||
| 		s.logf("ERROR: Attepted to send packet to invalid address: %v", addr) | 		s.logf("ERROR: Attepted to send packet to invalid address: %v", addr) | ||||||
| 		return | 		return | ||||||
| @@ -122,7 +118,14 @@ func (s *peerStateData) sendControlPacketTo( | |||||||
| 	route := s.staged | 	route := s.staged | ||||||
| 	route.Direct = true | 	route.Direct = true | ||||||
| 	route.RemoteAddr = addr | 	route.RemoteAddr = addr | ||||||
| 	s.limiter.Limit() | 	s._sendControlPacket(pkt, route) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func (s *peerStateData) _sendControlPacket(pkt interface{ Marshal([]byte) []byte }, route peerRoute) { | ||||||
|  | 	if err := s.limiter.Limit(); err != nil { | ||||||
|  | 		s.logf("Not sending control packet: rate limited.") // Shouldn't happen. | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
| 	_sendControlPacket(pkt, route, s.buf1, s.buf2) | 	_sendControlPacket(pkt, route, s.buf1, s.buf2) | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user