diff --git a/Client.md b/Client.md index 9ff1e2c..e5208dc 100644 --- a/Client.md +++ b/Client.md @@ -9,6 +9,16 @@ When GoSmartKeyboard is started in client mode, it does the following: 5. If the server responds with "authenticated", we start reading keys from stdin and sending them to the server until EOF. +--- handle client command + +if len(os.Args) > 1 && os.Args[1] == "connect" { + @{start client} + os.Exit(0) +} + +--- + + ## Connecting The base64 authentication token is loaded from the environment variable `KEYBOARD_AUTH`, if it does not exist we read it from stdin (base64 encoded), ended with a newline. @@ -44,7 +54,9 @@ _, authResponse, err := client.ReadMessage() if err != nil { log.Fatal("read:", err) } -if string(authResponse) != "authenticated" { +if string(authResponse) == "authenticated" { + fmt.Println("authenticated") +} else { log.Fatal("authentication failed") } diff --git a/ReadMe.md b/ReadMe.md index a1d0460..a7e3c04 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -63,13 +63,14 @@ Then we can start the web server and listen for websocket connections. func main(){ - if os.Args[1] == "connect" { - @{start client} - os.Exit(0) - } + @{handle client command} tokenBase64, _ := auth.ProvisionToken() - fmt.Println(tokenBase64) + if len(tokenBase64) > 0 { + fmt.Println("This is your authentication token, it will only be shown once: " + tokenBase64) + } + + server.StartServer() } diff --git a/Server.md b/Server.md index bb0fe5d..90ca758 100644 --- a/Server.md +++ b/Server.md @@ -19,6 +19,7 @@ if unixSocketPathExists { listener, _ = net.Listen("unix", unixSocketPath) } else{ if tcpBindAddressExists && tcpBindPortExists { + listener, _ = net.Listen("tcp", tcpBindAddress + ":" + tcpBindPort) } else { listener, _ = net.Listen("tcp", "127.0.0.1:8080") @@ -34,13 +35,13 @@ if unixSocketPathExists { - +``` go --- start http server func StartServer() { @{create listener} - + fmt.Println("Listening on", listener.Addr()) http.HandleFunc("/sendkeys", clientConnected) //http.HandleFunc("/activewindow", ) http.Serve(listener, nil) @@ -60,6 +61,7 @@ import( "time" "os" "net/http" + "fmt" "log" "keyboard.voidnet.tech/auth" @{gorilla/websocket import string} diff --git a/security/Authentication.md b/security/Authentication.md index 82df9b6..8793d46 100644 --- a/security/Authentication.md +++ b/security/Authentication.md @@ -16,10 +16,9 @@ KDF. authToken := [32]byte{} rand.Read(authToken[:]) -authTokenString := base64.StdEncoding.EncodeToString(authToken[:]) +authTokenString = base64.StdEncoding.EncodeToString(authToken[:]) hashedID := sha3.Sum256(authToken[:]) -fmt.Println("This is your authentication token, it will only be shown once: " + authTokenString) --- ``` @@ -71,7 +70,7 @@ func CheckAuthToken(token string) error { --- --- provision token function -func ProvisionToken() (base64Token string, failed error){ +func ProvisionToken() (authTokenString string, failed error){ @{define authentication token file} if _, err := os.Stat(authTokenFile); err == nil { @@ -88,7 +87,7 @@ func ProvisionToken() (base64Token string, failed error){ panic(err) } fo.Write(hashedID[:]) - return base64Token, nil + return authTokenString, nil } ---