From c05b73f8ecd9e4661f2cb86c8a9681ce6ff3f6d3 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Sun, 8 Oct 2023 13:46:38 +0300 Subject: [PATCH 1/3] add CLI option to force cold init --- main.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 25d48bf..67d3919 100644 --- a/main.go +++ b/main.go @@ -62,6 +62,7 @@ type CLIArgs struct { password string tfacode string fakeSNI string + forceColdInit bool } func parse_args() CLIArgs { @@ -90,6 +91,7 @@ func parse_args() CLIArgs { flag.StringVar(&args.password, "password", "", "password for login") flag.StringVar(&args.tfacode, "2fa", "", "2FA code for login") flag.StringVar(&args.fakeSNI, "fake-sni", "com", "fake SNI to use to contact windscribe servers") + flag.BoolVar(&args.forceColdInit, "force-cold-init", false, "force cold init") flag.Parse() if args.listLocations && args.listProxies { arg_fail("list-locations and list-proxies flags are mutually exclusive") @@ -192,9 +194,14 @@ func run() int { wndc.Mux.Unlock() // Try ressurect state - state, err := loadState(args.stateFile) + state, err := maybeLoadState(args.forceColdInit, args.stateFile) if err != nil { - mainLogger.Warning("Failed to load client state: %v. It is OK for a first run. Performing cold init...", err) + switch err { + case errColdInitForced: + mainLogger.Info("Cold init forced.") + default: + mainLogger.Warning("Failed to load client state: %v. It is OK for a first run. Performing cold init...", err) + } err = coldInit(wndc, args.username, args.password, args.tfacode, args.timeout) if err != nil { mainLogger.Critical("Cold init failed: %v", err) @@ -345,6 +352,14 @@ func pickServer(serverList wndclient.ServerList, location string) string { return candidates[rnd.Intn(len(candidates))] } +var errColdInitForced = errors.New("cold init forced!") +func maybeLoadState(forceColdInit bool, filename string) (*wndclient.WndClientState, error) { + if forceColdInit { + return nil, errColdInitForced + } + return loadState(filename) +} + func loadState(filename string) (*wndclient.WndClientState, error) { file, err := os.Open(filename) if err != nil { From 8fc8de5519bd3fc7f8086f8dec94b46fed2b0edf Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Sun, 8 Oct 2023 13:49:30 +0300 Subject: [PATCH 2/3] doc: update CLI synopsis --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 20aef8c..3f77fca 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,8 @@ windscribe-proxy -list-proxies | auth-secret | String | client auth secret (default `952b4412f002315aa50751032fcaab03`) | | bind-address | String | HTTP proxy listen address (default `127.0.0.1:28080`) | | cafile | String | use custom CA certificate bundle file | +| fake-sni | String | fake SNI to use to contact windscribe servers (default "com") | +| force-cold-init | - | force cold init | | list-locations | - | list available locations and exit | | list-proxies | - | output proxy list and exit | | location | String | desired proxy location. Default: best location | From a664a9ded9daea76d46ceb7e2be29e3ea8e81cf9 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Sun, 8 Oct 2023 13:57:39 +0300 Subject: [PATCH 3/3] fix typo --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 67d3919..ab57307 100644 --- a/main.go +++ b/main.go @@ -193,7 +193,7 @@ func run() int { wndc.State.Settings.ClientAuthSecret = args.clientAuthSecret wndc.Mux.Unlock() - // Try ressurect state + // Try to resurrect state state, err := maybeLoadState(args.forceColdInit, args.stateFile) if err != nil { switch err {