Skip to content

Commit 2d0d7bc

Browse files
authored
Simple mode (#12)
* More details for configuration arguments * Implement simple mode, requires only one client interface but loses multihop features
1 parent d712407 commit 2d0d7bc

File tree

5 files changed

+183
-96
lines changed

5 files changed

+183
-96
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ On the client machine, run Wiretap in configure mode to build a config
5454
./wiretap configure --port <port> --endpoint <socket> --routes <routes>
5555
```
5656

57+
* `--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
58+
* `--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)
59+
* `--routes` is the equivalent of WireGuard's AllowedIPs setting. This tells the Client to route traffic that matches these IP ranges through Wiretap
60+
5761
Following the example in the diagram:
5862
```bash
5963
./wiretap configure --port 1337 --endpoint 1.3.3.7:1337 --routes 10.0.0.0/24
@@ -99,7 +103,7 @@ Config File: ./wiretap serve -f wiretap_server.conf
99103
```
100104

101105
> **Note**
102-
> 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
106+
> 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
103107
104108
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:
105109

src/cmd/add_server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func (c addServerCmdConfig) Run() {
320320
// Copy to clipboard if requested.
321321
var clipboardStatus string
322322
if c.writeToClipboard {
323-
err = clipboard.WriteAll(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, "POSIX"))
323+
err = clipboard.WriteAll(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, peer.POSIX, false))
324324
if err != nil {
325325
clipboardStatus = fmt.Sprintf("%s %s", RedBold("clipboard:"), Red(fmt.Sprintf("error copying to clipboard: %v", err)))
326326
} else {
@@ -347,8 +347,8 @@ func (c addServerCmdConfig) Run() {
347347
fmt.Fprintln(color.Output)
348348
fmt.Fprintln(color.Output, fileStatusServer)
349349
fmt.Fprintln(color.Output)
350-
fmt.Fprintln(color.Output, Cyan("POSIX Shell: "), Green(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, "POSIX")))
351-
fmt.Fprintln(color.Output, Cyan(" PowerShell: "), Green(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, "POWERSHELL")))
350+
fmt.Fprintln(color.Output, Cyan("POSIX Shell: "), Green(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, peer.POSIX, false)))
351+
fmt.Fprintln(color.Output, Cyan(" PowerShell: "), Green(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, peer.PowerShell, false)))
352352
fmt.Fprintln(color.Output, Cyan("Config File: "), Green("./wiretap serve -f "+c.configFileServer))
353353
fmt.Fprintln(color.Output)
354354
if c.writeToClipboard {

src/cmd/configure.go

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type configureCmdConfig struct {
2222
configFileE2EE string
2323
configFileServer string
2424
writeToClipboard bool
25+
simple bool
2526
clientAddr4Relay string
2627
clientAddr6Relay string
2728
clientAddr4E2EE string
@@ -44,6 +45,7 @@ var configureCmdArgs = configureCmdConfig{
4445
configFileE2EE: ConfigE2EE,
4546
configFileServer: ConfigServer,
4647
writeToClipboard: false,
48+
simple: false,
4749
clientAddr4Relay: ClientRelaySubnet4.Addr().Next().String() + "/32",
4850
clientAddr6Relay: ClientRelaySubnet6.Addr().Next().String() + "/128",
4951
clientAddr4E2EE: ClientE2EESubnet4.Addr().Next().String() + "/32",
@@ -77,6 +79,7 @@ func init() {
7779
configureCmd.Flags().StringVarP(&configureCmdArgs.configFileE2EE, "e2ee-output", "", configureCmdArgs.configFileE2EE, "wireguard E2EE config output filename")
7880
configureCmd.Flags().StringVarP(&configureCmdArgs.configFileServer, "server-output", "s", configureCmdArgs.configFileServer, "wiretap server config output filename")
7981
configureCmd.Flags().BoolVarP(&configureCmdArgs.writeToClipboard, "clipboard", "c", configureCmdArgs.writeToClipboard, "copy configuration args to clipboard")
82+
configureCmd.Flags().BoolVarP(&configureCmdArgs.simple, "simple", "", configureCmdArgs.simple, "disable multihop and multiclient features for a simpler setup")
8083

8184
configureCmd.Flags().StringVarP(&configureCmdArgs.apiAddr, "api", "0", configureCmdArgs.apiAddr, "address of server API service")
8285
configureCmd.Flags().StringVarP(&configureCmdArgs.clientAddr4Relay, "ipv4-relay", "", configureCmdArgs.clientAddr4Relay, "ipv4 relay address")
@@ -138,8 +141,14 @@ func (c configureCmdConfig) Run() {
138141
ListenPort: c.port,
139142
Peers: []peer.PeerConfigArgs{
140143
{
141-
PublicKey: serverConfigRelay.GetPublicKey(),
142-
AllowedIPs: []string{relaySubnet4.String(), relaySubnet6.String()},
144+
PublicKey: serverConfigRelay.GetPublicKey(),
145+
AllowedIPs: func() []string {
146+
if c.simple {
147+
return c.allowedIPs
148+
} else {
149+
return []string{relaySubnet4.String(), relaySubnet6.String()}
150+
}
151+
}(),
143152
Endpoint: func() string {
144153
if c.outbound {
145154
return c.endpoint
@@ -217,11 +226,13 @@ func (c configureCmdConfig) Run() {
217226

218227
// Write config file and get status string.
219228
var fileStatusE2EE string
220-
err = os.WriteFile(c.configFileE2EE, []byte(clientConfigE2EE.AsFile()), 0600)
221-
if err != nil {
222-
fileStatusE2EE = fmt.Sprintf("%s %s", RedBold("config:"), Red(fmt.Sprintf("error writing config file: %v", err)))
223-
} else {
224-
fileStatusE2EE = fmt.Sprintf("%s %s", GreenBold("config:"), Green(c.configFileE2EE))
229+
if !c.simple {
230+
err = os.WriteFile(c.configFileE2EE, []byte(clientConfigE2EE.AsFile()), 0600)
231+
if err != nil {
232+
fileStatusE2EE = fmt.Sprintf("%s %s", RedBold("config:"), Red(fmt.Sprintf("error writing config file: %v", err)))
233+
} else {
234+
fileStatusE2EE = fmt.Sprintf("%s %s", GreenBold("config:"), Green(c.configFileE2EE))
235+
}
225236
}
226237

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

247+
// Make config file string
248+
serverConfigFile := fmt.Sprintf("./wiretap serve -f %s", c.configFileServer)
249+
if c.simple {
250+
serverConfigFile = fmt.Sprintf("%s --simple", serverConfigFile)
251+
}
252+
236253
// Copy to clipboard if requested.
237254
var clipboardStatus string
238255
if c.writeToClipboard {
239-
err = clipboard.WriteAll(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, "POSIX"))
256+
err = clipboard.WriteAll(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, peer.POSIX, c.simple))
240257
if err != nil {
241258
clipboardStatus = fmt.Sprintf("%s %s", RedBold("clipboard:"), Red(fmt.Sprintf("error copying to clipboard: %v", err)))
242259
} else {
@@ -247,24 +264,26 @@ func (c configureCmdConfig) Run() {
247264
// Write and format output.
248265
fmt.Fprintln(color.Output)
249266
fmt.Fprintln(color.Output, "Configurations successfully generated.")
250-
fmt.Fprintln(color.Output, "Import the two configs into WireGuard locally and pass the arguments below to Wiretap on the remote machine.")
267+
fmt.Fprintln(color.Output, "Import the config(s) into WireGuard locally and pass the arguments below to Wiretap on the remote machine.")
251268
fmt.Fprintln(color.Output)
252269
fmt.Fprintln(color.Output, fileStatusRelay)
253270
fmt.Fprintln(color.Output, Green(strings.Repeat("─", 32)))
254271
fmt.Fprint(color.Output, WhiteBold(clientConfigRelay.AsFile()))
255272
fmt.Fprintln(color.Output, Green(strings.Repeat("─", 32)))
256273
fmt.Fprintln(color.Output)
257-
fmt.Fprintln(color.Output, fileStatusE2EE)
258-
fmt.Fprintln(color.Output, Green(strings.Repeat("─", 32)))
259-
fmt.Fprint(color.Output, WhiteBold(clientConfigE2EE.AsFile()))
260-
fmt.Fprintln(color.Output, Green(strings.Repeat("─", 32)))
261-
fmt.Fprintln(color.Output)
274+
if !c.simple {
275+
fmt.Fprintln(color.Output, fileStatusE2EE)
276+
fmt.Fprintln(color.Output, Green(strings.Repeat("─", 32)))
277+
fmt.Fprint(color.Output, WhiteBold(clientConfigE2EE.AsFile()))
278+
fmt.Fprintln(color.Output, Green(strings.Repeat("─", 32)))
279+
fmt.Fprintln(color.Output)
280+
}
262281
fmt.Fprintln(color.Output, fileStatusServer)
263282
fmt.Fprintln(color.Output)
264283
fmt.Fprintln(color.Output, GreenBold("server command:"))
265-
fmt.Fprintln(color.Output, Cyan("POSIX Shell: "), Green(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, "POSIX")))
266-
fmt.Fprintln(color.Output, Cyan(" PowerShell: "), Green(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, "POWERSHELL")))
267-
fmt.Fprintln(color.Output, Cyan("Config File: "), Green("./wiretap serve -f "+c.configFileServer))
284+
fmt.Fprintln(color.Output, Cyan("POSIX Shell: "), Green(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, peer.POSIX, c.simple)))
285+
fmt.Fprintln(color.Output, Cyan(" PowerShell: "), Green(peer.CreateServerCommand(serverConfigRelay, serverConfigE2EE, peer.PowerShell, c.simple)))
286+
fmt.Fprintln(color.Output, Cyan("Config File: "), Green(serverConfigFile))
268287
fmt.Fprintln(color.Output)
269288
if c.writeToClipboard {
270289
fmt.Fprintln(color.Output, clipboardStatus)

0 commit comments

Comments
 (0)