From 608d780db19f8b25ea66431358b69ec7004be358 Mon Sep 17 00:00:00 2001 From: Kevin F Date: Sat, 21 Jan 2023 18:55:58 -0600 Subject: [PATCH] Work on tools --- Client.md | 7 ++-- Makefile | 2 +- Streaming.md | 4 ++- security/Authentication.md | 1 - smartkeyboard/auth/auth_test.go | 59 --------------------------------- tools/Cowsay.md | 29 ++++++++++++++++ tools/Editor.md | 3 ++ tools/HelloWorld.md | 15 +++++++++ tools/Tools.md | 48 +++++++++++++++++++++++++++ 9 files changed, 103 insertions(+), 65 deletions(-) delete mode 100644 smartkeyboard/auth/auth_test.go create mode 100644 tools/Cowsay.md create mode 100644 tools/Editor.md create mode 100644 tools/HelloWorld.md create mode 100644 tools/Tools.md diff --git a/Client.md b/Client.md index 57284c7..f0ba5f1 100644 --- a/Client.md +++ b/Client.md @@ -8,7 +8,7 @@ When GoSmartKeyboard is started in client mode, it does the following: 4 Send the auth token to the server. 5. If the server responds with "authenticated", we start reading keys from stdin and sending them to the server until EOF. - +``` go --- handle client command if len(os.Args) > 1 && os.Args[1] == "connect" { @@ -17,6 +17,7 @@ if len(os.Args) > 1 && os.Args[1] == "connect" { } --- +``` ## Connecting @@ -88,10 +89,10 @@ We read keys from stdin and send them to the server until we get EOF --- start client += - +reader := bufio.NewReader(os.Stdin) for { var key string - reader := bufio.NewReader(os.Stdin) + rune, _, err := reader.ReadRune() //:= fmt.Scan(&key) key = string(rune) diff --git a/Makefile b/Makefile index d13d0fe..a680bcd 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ weave: srcweave --formatter srcweave-format --weave docs/ ReadMe.md security/Authentication.md EnvironmentVariables.md Dependencies.md Server.md Streaming.md ThreatModel.md Client.md util/removefencedcode.py tangle: - srcweave --formatter srcweave-format --tangle smartkeyboard/ ReadMe.md security/Authentication.md EnvironmentVariables.md Dependencies.md Server.md Streaming.md ThreatModel.md Client.md + srcweave --formatter srcweave-format --tangle smartkeyboard/ ReadMe.md security/Authentication.md EnvironmentVariables.md Dependencies.md Server.md Streaming.md ThreatModel.md Client.md tools/Tools.md tools/Cowsay.md tools/Editor.md tools/HelloWorld.md clean: rm -rf docs find smartkeyboard/ -type f -not -name "*_test.go" -delete diff --git a/Streaming.md b/Streaming.md index cdc98d0..80e3647 100644 --- a/Streaming.md +++ b/Streaming.md @@ -41,10 +41,12 @@ func clientConnected(w http.ResponseWriter, r *http.Request) { } log.Printf("recv: %s", message) message_string := string(message) + if message_string == "" { + message_string = "\n" + } err = keyboard.Type(message_string) if err != nil { log.Println("type:", err) - break } } } diff --git a/security/Authentication.md b/security/Authentication.md index 8793d46..7c26581 100644 --- a/security/Authentication.md +++ b/security/Authentication.md @@ -104,7 +104,6 @@ package auth import( "os" "path/filepath" - "fmt" "errors" "encoding/base64" "crypto/rand" diff --git a/smartkeyboard/auth/auth_test.go b/smartkeyboard/auth/auth_test.go deleted file mode 100644 index fbaf1d3..0000000 --- a/smartkeyboard/auth/auth_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package auth - -import ( - "encoding/base64" - "golang.org/x/crypto/sha3" - "os" - "testing" -) - -func TestAuthPasswordHashBad(t *testing.T) { - os.RemoveAll("test-auth-token") - os.Setenv("KEYBOARD_AUTH_TOKEN_FILE", "test-auth-token") - os.WriteFile("test-auth-token", []byte("junk"), 0644) - t.Log("TestAuthPasswordHash") - - password := "wrong password" - - result := CheckAuthToken(password) - if result == nil { - t.Errorf("Expected error, got nil") - } - os.RemoveAll("test-auth-token") -} - -func TestAuthPasswordEmpty(t *testing.T) { - os.RemoveAll("test-auth-token") - os.Setenv("KEYBOARD_AUTH_TOKEN_FILE", "test-auth-token") - os.WriteFile("test-auth-token", []byte("c0067d4af4e87f00dbac63b6156828237059172d1bbeac67427345d6a9fda484"), 0644) - t.Log("TestAuthPasswordHash") - - password := "" - - result := CheckAuthToken(password) - if result == nil { - t.Errorf("Expected error, got nil") - } - os.RemoveAll("test-auth-token") -} - -func TestAuthPasswordHashGood(t *testing.T) { - os.RemoveAll("test-auth-token") - os.Setenv("KEYBOARD_AUTH_TOKEN_FILE", "test-auth-token") - //os.WriteFile("test-auth-token", []byte("c0067d4af4e87f00dbac63b6156828237059172d1bbeac67427345d6a9fda484"), 0644) - expectedHash := sha3.Sum256([]byte("password")) - fo, err := os.Create("test-auth-token") - if err != nil { - panic(err) - } - fo.Write(expectedHash[:]) - t.Log("TestAuthPasswordHash") - - password := base64.StdEncoding.EncodeToString([]byte("password")) - - result := CheckAuthToken(password) - if result != nil { - t.Errorf("Expected nil, got error") - } - os.RemoveAll("test-auth-token") -} diff --git a/tools/Cowsay.md b/tools/Cowsay.md new file mode 100644 index 0000000..06414ad --- /dev/null +++ b/tools/Cowsay.md @@ -0,0 +1,29 @@ +# Cowsay + +This tool sends your text as cow speech to the server. It is a simple example of a tool that can be used to send text to the server. + +``` go + +--- /tools/cowsay.go +@{tool header} +@{tool main} + +func doTool(){ + if len(os.Args) < 2 { + fmt.Println("Usage: cowsay ") + os.Exit(1) + } + cmd := exec.Command("cowsay", os.Args[1:]) + //cmd.Stdin = strings.NewReader("some input") + var out bytes.Buffer + cmd.Stdout = &out + err := cmd.Run() + if err != nil { + log.Fatal(err) + } + fmt.Println(strings) +} + + +--- +``` \ No newline at end of file diff --git a/tools/Editor.md b/tools/Editor.md new file mode 100644 index 0000000..fc9f6dd --- /dev/null +++ b/tools/Editor.md @@ -0,0 +1,3 @@ +# Input Method Editor + +This tool uses your $EDITOR to buffer keystrokes. diff --git a/tools/HelloWorld.md b/tools/HelloWorld.md new file mode 100644 index 0000000..6f79497 --- /dev/null +++ b/tools/HelloWorld.md @@ -0,0 +1,15 @@ +# Hello World + +Bare bones keyboard tool. + +``` go +--- /tools/helloworld.go +@{tool header} + +func doTool(){ + fmt.Println("Hello World") + +} + +@{tool main} +--- \ No newline at end of file diff --git a/tools/Tools.md b/tools/Tools.md new file mode 100644 index 0000000..5a85047 --- /dev/null +++ b/tools/Tools.md @@ -0,0 +1,48 @@ +# Keyboarding Tools + +The actual keyboarding tools are completely seperate from the server and client code. +As far as features are concerned, they only need to write to stdout. + +All tools have the same initial structure: +``` go +--- tool header +package main +import ( + "fmt" + "os" + "log" + "time" +) +--- +--- tool main +func main(){ + @{get auth token} + @{start tool} +} + +--- + +--- start tool + +time.Sleep(1 * time.Second) + +fmt.Println(authTokenInput) + +doTool() + + +--- + +--- get auth token --- noWeave + +@{get authTokenInput from environment} + +if !authTokenInputExists { + //fmt.Print("Enter authentication token: ") + _, err := fmt.Scanln(&authTokenInput) + if err != nil { + log.Fatal(err) + } +} + +---