From fa0c2d9774dce868515e1a360c8255057cd1901e Mon Sep 17 00:00:00 2001 From: NBTX Date: Thu, 19 Dec 2019 21:21:12 +0000 Subject: [PATCH] Add session fingerprint to improve auto-discovery. --- go.mod | 3 ++- go.sum | 2 ++ libproxy/proxy.go | 17 ++++++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 28bf123..4801453 100644 --- a/go.mod +++ b/go.mod @@ -7,12 +7,13 @@ require ( github.com/KnicKnic/go-powershell v0.0.8 // indirect github.com/akavel/rsrc v0.8.0 // indirect github.com/atotto/clipboard v0.1.2 - github.com/bhendo/go-powershell v0.0.0-20190719160123-219e7fb4e41e + github.com/bhendo/go-powershell v0.0.0-20190719160123-219e7fb4e41e // indirect github.com/cratonica/2goarray v0.0.0-20190331194516-514510793eaa // indirect github.com/deckarep/gosx-notifier v0.0.0-20180201035817-e127226297fb github.com/gen2brain/dlgs v0.0.0-20191023125645-8832682fb7f8 github.com/getlantern/systray v0.0.0-20191206015929-6658a36a3306 github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect + github.com/google/uuid v1.1.1 github.com/gopherjs/gopherjs v0.0.0-20191106031601-ce3c9ade29de // indirect github.com/juju/errors v0.0.0-20190930114154-d42613fe1ab9 // indirect github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8 // indirect diff --git a/go.sum b/go.sum index 833a3a1..bfa8db5 100644 --- a/go.sum +++ b/go.sum @@ -42,6 +42,8 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE= github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v0.0.0-20191106031601-ce3c9ade29de h1:F7WD09S8QB4LrkEpka0dFPLSotH11HRpCsLIbIcJ7sU= github.com/gopherjs/gopherjs v0.0.0-20191106031601-ce3c9ade29de/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/juju/errors v0.0.0-20190930114154-d42613fe1ab9 h1:hJix6idebFclqlfZCHE7EUX7uqLCyb70nHNHH1XKGBg= diff --git a/libproxy/proxy.go b/libproxy/proxy.go index 8783cb5..9a60185 100644 --- a/libproxy/proxy.go +++ b/libproxy/proxy.go @@ -7,11 +7,15 @@ import ( "log" "net/http" "net/url" + "strconv" "strings" + + "github.com/google/uuid" ); type statusChangeFunction func(status string, isListening bool); var accessToken string; +var sessionFingerprint string; type Request struct { AccessToken string; @@ -33,8 +37,15 @@ type Response struct { Headers map[string]string `json:"headers"`; } -func Initialize(initialAccessToken string, proxyURL string, onStatusChange statusChangeFunction, withSSL bool, finished chan bool) { +func Initialize( + initialAccessToken string, + proxyURL string, + onStatusChange statusChangeFunction, + withSSL bool, + finished chan bool, +) { accessToken = initialAccessToken; + sessionFingerprint = uuid.New().String() log.Println("Starting proxy server..."); http.HandleFunc("/", proxyHandler); @@ -93,7 +104,7 @@ func proxyHandler(response http.ResponseWriter, request *http.Request) { // Then, for anything other than an POST request, we'll return an empty JSON object. response.Header().Add("Content-Type", "application/json; charset=utf-8"); if request.Method != "POST" { - _, _ = fmt.Fprintln(response, "{}"); + _, _ = fmt.Fprintln(response, "{\"success\": true, \"data\":{\"sessionFingerprint\":\"" + sessionFingerprint + "\", \"isProtected\":" + strconv.FormatBool(len(accessToken) > 0) + "}}"); return; } @@ -108,7 +119,7 @@ func proxyHandler(response http.ResponseWriter, request *http.Request) { return; } - if(len(accessToken) > 0 && requestData.AccessToken != accessToken){ + if (len(accessToken) > 0 && requestData.AccessToken != accessToken) { log.Print("An unauthorized request was made."); _, _ = fmt.Fprintln(response, "{\"success\": false, \"data\":{\"message\":\"(Proxy Error) Unauthorized request; you may need to set your access token in Settings.\"}}"); return;