Skip to content

Commit

Permalink
Simple mode (#12)
Browse files Browse the repository at this point in the history
* More details for configuration arguments  
* Implement simple mode, requires only one client interface but loses multihop features
  • Loading branch information
luker983 authored May 24, 2023
1 parent d712407 commit 2d0d7bc
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 96 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ On the client machine, run Wiretap in configure mode to build a config
./wiretap configure --port <port> --endpoint <socket> --routes <routes>
```

* `--port` sets the listening port of the Client's Relay interface. It's set to 51820 by default. Note that the E2EE listening port does not need to be accessible to the Server
* `--endpoint` tells the Server how to connect to the Client's Relay interface (the E2EE interfaces already know how to talk to each other if the Relay interfaces are working)
* `--routes` is the equivalent of WireGuard's AllowedIPs setting. This tells the Client to route traffic that matches these IP ranges through Wiretap

Following the example in the diagram:
```bash
./wiretap configure --port 1337 --endpoint 1.3.3.7:1337 --routes 10.0.0.0/24
Expand Down Expand Up @@ -99,7 +103,7 @@ Config File: ./wiretap serve -f wiretap_server.conf
```

> **Note**
> Wiretap uses 2 WireGuard interfaces per node in order to safely and scalably chain together servers. See the [How It Works](#how-it-works) section for details
> Wiretap uses 2 WireGuard interfaces per node in order to safely and scalably chain together servers. This means your client will bind to more than one port, but only the Relay Interface port needs to be accessible by the Server. See the [How It Works](#how-it-works) section for details. Use `--simple` if your setup requires a single interface on the client
Install the resulting config either by copying and pasting the output or by importing the new `wiretap_relay.conf` and `wiretap_e2ee.conf` files into WireGuard:

Expand Down
6 changes: 3 additions & 3 deletions src/cmd/add_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (c addServerCmdConfig) Run() {
// Copy to clipboard if requested.
var clipboardStatus string
if c.writeToClipboard {
err = clipboard.WriteAll(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, "POSIX"))
err = clipboard.WriteAll(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, peer.POSIX, false))
if err != nil {
clipboardStatus = fmt.Sprintf("%s %s", RedBold("clipboard:"), Red(fmt.Sprintf("error copying to clipboard: %v", err)))
} else {
Expand All @@ -347,8 +347,8 @@ func (c addServerCmdConfig) Run() {
fmt.Fprintln(color.Output)
fmt.Fprintln(color.Output, fileStatusServer)
fmt.Fprintln(color.Output)
fmt.Fprintln(color.Output, Cyan("POSIX Shell: "), Green(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, "POSIX")))
fmt.Fprintln(color.Output, Cyan(" PowerShell: "), Green(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, "POWERSHELL")))
fmt.Fprintln(color.Output, Cyan("POSIX Shell: "), Green(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, peer.POSIX, false)))
fmt.Fprintln(color.Output, Cyan(" PowerShell: "), Green(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, peer.PowerShell, false)))
fmt.Fprintln(color.Output, Cyan("Config File: "), Green("./wiretap serve -f "+c.configFileServer))
fmt.Fprintln(color.Output)
if c.writeToClipboard {
Expand Down
53 changes: 36 additions & 17 deletions src/cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type configureCmdConfig struct {
configFileE2EE string
configFileServer string
writeToClipboard bool
simple bool
clientAddr4Relay string
clientAddr6Relay string
clientAddr4E2EE string
Expand All @@ -44,6 +45,7 @@ var configureCmdArgs = configureCmdConfig{
configFileE2EE: ConfigE2EE,
configFileServer: ConfigServer,
writeToClipboard: false,
simple: false,
clientAddr4Relay: ClientRelaySubnet4.Addr().Next().String() + "/32",
clientAddr6Relay: ClientRelaySubnet6.Addr().Next().String() + "/128",
clientAddr4E2EE: ClientE2EESubnet4.Addr().Next().String() + "/32",
Expand Down Expand Up @@ -77,6 +79,7 @@ func init() {
configureCmd.Flags().StringVarP(&configureCmdArgs.configFileE2EE, "e2ee-output", "", configureCmdArgs.configFileE2EE, "wireguard E2EE config output filename")
configureCmd.Flags().StringVarP(&configureCmdArgs.configFileServer, "server-output", "s", configureCmdArgs.configFileServer, "wiretap server config output filename")
configureCmd.Flags().BoolVarP(&configureCmdArgs.writeToClipboard, "clipboard", "c", configureCmdArgs.writeToClipboard, "copy configuration args to clipboard")
configureCmd.Flags().BoolVarP(&configureCmdArgs.simple, "simple", "", configureCmdArgs.simple, "disable multihop and multiclient features for a simpler setup")

configureCmd.Flags().StringVarP(&configureCmdArgs.apiAddr, "api", "0", configureCmdArgs.apiAddr, "address of server API service")
configureCmd.Flags().StringVarP(&configureCmdArgs.clientAddr4Relay, "ipv4-relay", "", configureCmdArgs.clientAddr4Relay, "ipv4 relay address")
Expand Down Expand Up @@ -138,8 +141,14 @@ func (c configureCmdConfig) Run() {
ListenPort: c.port,
Peers: []peer.PeerConfigArgs{
{
PublicKey: serverConfigRelay.GetPublicKey(),
AllowedIPs: []string{relaySubnet4.String(), relaySubnet6.String()},
PublicKey: serverConfigRelay.GetPublicKey(),
AllowedIPs: func() []string {
if c.simple {
return c.allowedIPs
} else {
return []string{relaySubnet4.String(), relaySubnet6.String()}
}
}(),
Endpoint: func() string {
if c.outbound {
return c.endpoint
Expand Down Expand Up @@ -217,11 +226,13 @@ func (c configureCmdConfig) Run() {

// Write config file and get status string.
var fileStatusE2EE string
err = os.WriteFile(c.configFileE2EE, []byte(clientConfigE2EE.AsFile()), 0600)
if err != nil {
fileStatusE2EE = fmt.Sprintf("%s %s", RedBold("config:"), Red(fmt.Sprintf("error writing config file: %v", err)))
} else {
fileStatusE2EE = fmt.Sprintf("%s %s", GreenBold("config:"), Green(c.configFileE2EE))
if !c.simple {
err = os.WriteFile(c.configFileE2EE, []byte(clientConfigE2EE.AsFile()), 0600)
if err != nil {
fileStatusE2EE = fmt.Sprintf("%s %s", RedBold("config:"), Red(fmt.Sprintf("error writing config file: %v", err)))
} else {
fileStatusE2EE = fmt.Sprintf("%s %s", GreenBold("config:"), Green(c.configFileE2EE))
}
}

// Write server config file and get status string.
Expand All @@ -233,10 +244,16 @@ func (c configureCmdConfig) Run() {
fileStatusServer = fmt.Sprintf("%s %s", GreenBold("server config:"), Green(c.configFileServer))
}

// Make config file string
serverConfigFile := fmt.Sprintf("./wiretap serve -f %s", c.configFileServer)
if c.simple {
serverConfigFile = fmt.Sprintf("%s --simple", serverConfigFile)
}

// Copy to clipboard if requested.
var clipboardStatus string
if c.writeToClipboard {
err = clipboard.WriteAll(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, "POSIX"))
err = clipboard.WriteAll(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, peer.POSIX, c.simple))
if err != nil {
clipboardStatus = fmt.Sprintf("%s %s", RedBold("clipboard:"), Red(fmt.Sprintf("error copying to clipboard: %v", err)))
} else {
Expand All @@ -247,24 +264,26 @@ func (c configureCmdConfig) Run() {
// Write and format output.
fmt.Fprintln(color.Output)
fmt.Fprintln(color.Output, "Configurations successfully generated.")
fmt.Fprintln(color.Output, "Import the two configs into WireGuard locally and pass the arguments below to Wiretap on the remote machine.")
fmt.Fprintln(color.Output, "Import the config(s) into WireGuard locally and pass the arguments below to Wiretap on the remote machine.")
fmt.Fprintln(color.Output)
fmt.Fprintln(color.Output, fileStatusRelay)
fmt.Fprintln(color.Output, Green(strings.Repeat("─", 32)))
fmt.Fprint(color.Output, WhiteBold(clientConfigRelay.AsFile()))
fmt.Fprintln(color.Output, Green(strings.Repeat("─", 32)))
fmt.Fprintln(color.Output)
fmt.Fprintln(color.Output, fileStatusE2EE)
fmt.Fprintln(color.Output, Green(strings.Repeat("─", 32)))
fmt.Fprint(color.Output, WhiteBold(clientConfigE2EE.AsFile()))
fmt.Fprintln(color.Output, Green(strings.Repeat("─", 32)))
fmt.Fprintln(color.Output)
if !c.simple {
fmt.Fprintln(color.Output, fileStatusE2EE)
fmt.Fprintln(color.Output, Green(strings.Repeat("─", 32)))
fmt.Fprint(color.Output, WhiteBold(clientConfigE2EE.AsFile()))
fmt.Fprintln(color.Output, Green(strings.Repeat("─", 32)))
fmt.Fprintln(color.Output)
}
fmt.Fprintln(color.Output, fileStatusServer)
fmt.Fprintln(color.Output)
fmt.Fprintln(color.Output, GreenBold("server command:"))
fmt.Fprintln(color.Output, Cyan("POSIX Shell: "), Green(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, "POSIX")))
fmt.Fprintln(color.Output, Cyan(" PowerShell: "), Green(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, "POWERSHELL")))
fmt.Fprintln(color.Output, Cyan("Config File: "), Green("./wiretap serve -f "+c.configFileServer))
fmt.Fprintln(color.Output, Cyan("POSIX Shell: "), Green(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, peer.POSIX, c.simple)))
fmt.Fprintln(color.Output, Cyan(" PowerShell: "), Green(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, peer.PowerShell, c.simple)))
fmt.Fprintln(color.Output, Cyan("Config File: "), Green(serverConfigFile))
fmt.Fprintln(color.Output)
if c.writeToClipboard {
fmt.Fprintln(color.Output, clipboardStatus)
Expand Down
Loading

0 comments on commit 2d0d7bc

Please sign in to comment.