routes.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package daemon
  2. import (
  3. wg "git.aetherial.dev/aeth/yosai/pkg/wireguard/centos"
  4. )
  5. // Client for building internal Daemon route requests
  6. /*
  7. Route handler for all of the exposed functions that the daemon allows for
  8. :param msg: a SockMessage containing all of the request information
  9. */
  10. func (c *Context) DaemonRouter(msg SockMessage) SockMessage {
  11. switch msg.Method {
  12. case "render-config":
  13. serverKeypair, err := c.keyring.GetKey(c.Keytags.WgServerKeypairKeyname())
  14. if err != nil {
  15. return *NewSockMessage(MsgResponse, REQUEST_FAILED, []byte(err.Error()))
  16. }
  17. clientKeypair, err := c.keyring.GetKey(c.Keytags.WgClientKeypairKeyname())
  18. if err != nil {
  19. return *NewSockMessage(MsgResponse, REQUEST_FAILED, []byte(err.Error()))
  20. }
  21. seed := wg.WireguardTemplateSeed{
  22. VpnClientPrivateKey: clientKeypair.GetSecret(),
  23. VpnClientAddress: c.Config.VpnClientIpAddr(),
  24. Peers: []wg.WireguardTemplatePeer{
  25. wg.WireguardTemplatePeer{
  26. Pubkey: serverKeypair.GetPublic(),
  27. Address: c.Config.VpnServer(),
  28. Port: c.Config.VpnServerPort(),
  29. },
  30. }}
  31. cfg, err := wg.RenderClientConfiguration(seed)
  32. if err != nil {
  33. return *NewSockMessage(MsgResponse, REQUEST_FAILED, []byte(err.Error()))
  34. }
  35. return *NewSockMessage(MsgResponse, REQUEST_OK, cfg)
  36. default:
  37. return *NewSockMessage(MsgResponse, REQUEST_UNRESOLVED, []byte("Unresolved Method"))
  38. }
  39. }