Work on tools

This commit is contained in:
Kevin F 2023-01-21 18:55:58 -06:00
parent f089202286
commit 608d780db1
9 changed files with 103 additions and 65 deletions

View File

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

View File

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

View File

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

View File

@ -104,7 +104,6 @@ package auth
import(
"os"
"path/filepath"
"fmt"
"errors"
"encoding/base64"
"crypto/rand"

View File

@ -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")
}

29
tools/Cowsay.md Normal file
View File

@ -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 <text>")
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)
}
---
```

3
tools/Editor.md Normal file
View File

@ -0,0 +1,3 @@
# Input Method Editor
This tool uses your $EDITOR to buffer keystrokes.

15
tools/HelloWorld.md Normal file
View File

@ -0,0 +1,15 @@
# Hello World
Bare bones keyboard tool.
``` go
--- /tools/helloworld.go
@{tool header}
func doTool(){
fmt.Println("Hello World")
}
@{tool main}
---

48
tools/Tools.md Normal file
View File

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