Skip to content

Commit

Permalink
kbnm: Fix chat messages, dev install script, whitelist published exte…
Browse files Browse the repository at this point in the history
…nsion (keybase#6390)

* kbnm: Whitelist the internally published extension id

* kbnm: Fix install_host

mkdir was not calling with a variable, and realpath does not exist on vanilla osx

* kbnm: install_host, look for kbnm binary in GOPATH

* kbnm: Send chat body over stdin

* kbnm: Convert stdin goroutine to inline start/wait
  • Loading branch information
shazow authored Mar 28, 2017
1 parent a79deed commit bf110bb
Showing 3 changed files with 46 additions and 8 deletions.
23 changes: 20 additions & 3 deletions go/kbnm/handler.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package main

import (
"errors"
"io"
"os/exec"
)

@@ -24,8 +25,24 @@ func handleChat(req *Request) error {
}

// FIXME: Get the absolute path without a filled PATH var somehow?
cmd := exec.Command("/usr/local/bin/keybase", "chat", "send", "--private", req.To, req.Body)
cmd := exec.Command("/usr/local/bin/keybase", "chat", "send", "--private", req.To)

// TODO: Check/convert status code more precisely?
return cmd.Run()
// Write message body over STDIN to avoid running up against bugs with
// super long messages.
stdin, err := cmd.StdinPipe()
if err != nil {
return err
}

if err := cmd.Start(); err != nil {
stdin.Close()
return err
}

io.WriteString(stdin, req.Body)
stdin.Close()

// TODO: Check/convert status code more precisely? Maybe return stdout as
// part of the error if there is one?
return cmd.Wait()
}
3 changes: 2 additions & 1 deletion go/kbnm/host_json.template
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
"path": "@@HOST_PATH@@",
"type": "stdio",
"allowed_origins": [
"chrome-extension://kockbbfoibcdfibclaojljblnhpnjndg/"
"chrome-extension://kockbbfoibcdfibclaojljblnhpnjndg/",
"chrome-extension://gnjkbjlgkpiaehpibpdefaieklbfljjm/"
]
}
28 changes: 24 additions & 4 deletions go/kbnm/install_host
Original file line number Diff line number Diff line change
@@ -8,6 +8,14 @@
#
# It can be run multiple times. The whitelist will be overwritten each time.

realpath() {
if [[ $1 = /* ]]; then
echo "$1"
else
echo "$PWD/${1#./}"
fi
}

detect() {
# Find where the NativeMessagingHosts whitelist lives for this platform.
whoami="$(whoami)"
@@ -32,13 +40,23 @@ install() {
# Install the whitelist.
declare target="$1"

local target_dir="$(dirname target)"
local target_dir="$(dirname "$target")"
if [[ ! -d "$target_dir" ]]; then
mkdir -p "target_dir"
mkdir -p "$target_dir"
fi

local here="$(dirname $(realpath "$BASH_SOURCE"))"
local host_path="$(which kbnm || echo "$here/kbnm")"
local host_path="$(which "kbnm" || echo "$here/kbnm")"

if [[ ! -x "$host_path" ]]; then
# Is it in GOPATH, but not PATH?
host_path="$GOPATH/bin/kbnm"
fi

if [[ ! -x "$host_path" ]]; then
echo "failed to find kbnm executable, make sure it's in your \$PATH."
exit 2
fi

echo "Writing: $target"
cat "$here/host_json.template" \
@@ -47,7 +65,9 @@ install() {

chmod +r "$target"

echo "Success: Installed Chrome NativeMessaging whitelist: "$host_path" for $host_name"
cat "$target"

echo "Success."
}

uninstall() {

0 comments on commit bf110bb

Please sign in to comment.