Add session fingerprint to improve auto-discovery.

This commit is contained in:
NBTX 2019-12-19 21:21:12 +00:00
parent 114ea1919b
commit fa0c2d9774
3 changed files with 18 additions and 4 deletions

3
go.mod
View file

@ -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

2
go.sum
View file

@ -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=

View file

@ -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;