Skip to content

Commit f8321af

Browse files
committed
Initial commit.
0 parents  commit f8321af

File tree

8 files changed

+808
-0
lines changed

8 files changed

+808
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin

LICENSE

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
passff-host
2+
===========
3+
4+
[![Join the chat at https://gitter.im/jvenant/passff](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jvenant/passff?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5+
6+
Host app for the WebExtension **[PassFF](https://addons.mozilla.org/firefox/addon/passff)**
7+
8+
### Overview
9+
This piece of software wraps around the **[zx2c4 pass](http://www.zx2c4.com/projects/password-store/)** shell command. It has to be installed for the PassFF browser extension to work properly.
10+
11+
### Installation
12+
Download the `install_host_app.sh` script from [our releases page](https://github.com/passff/passff-host/releases) and execute it. You can do this in one line like so:
13+
14+
```
15+
$ curl -sSL https://github.com/passff/passff-host/releases/download/1.0/install_host_app.sh | bash -s -- [firefox|chrome|opera|chromium|vivaldi]
16+
```
17+
18+
This script will download the host application (a small python script) and the add-on's manifest file (a JSON config file) and put them in the right place.
19+
If you're concerned about executing a script that downloads files from the web, you can download the files yourself and run the script with the `--local` option instead or link the files yourself. Details below.
20+
21+
#### Windows
22+
Download the `install_host_app.bat` script from [our releases page](https://github.com/passff/passff-host/releases) and execute it from within a shell with a correct PATH.
23+
*The rule of thumb is: if you can execute pass and python from your shell, then your host application will be installed correctly.*
24+
25+
```
26+
> install_host_app.bat [firefox|chrome|opera|chromium|vivaldi]
27+
```
28+
29+
Note: Older Windows versions might require powershell to be installed manually as the install script uses powershell internally. Windows 10 users should be fine out of the box.
30+
31+
#### Latest from GitHub
32+
This is not recommended! Only for developers and for testing purposes!
33+
34+
Clone the repository. Then, from the project's `src/` directory, run `make` and execute the installation script in `bin/testing` for your desired browser (`firefox`, `chrome`, `opera`, `chromium`, or `vivaldi`):
35+
36+
```
37+
$ cd ./src
38+
$ make
39+
$ cd ../bin/testing
40+
$ ./install_host_app.sh --local [firefox|chrome|opera|chromium|vivaldi]
41+
```
42+
43+
This will copy the host application and manifest files to the right place for your browser. The `--local` option makes the script use the files on disk rather than downloading them from GitHub.
44+
45+
If this doesn't work, you can link the files yourself. First, change the `path` value in the `passff.json` file to be the absolute path to the project's `bin/testing/passff.py` file. Then symlink (or copy) the file `bin/testing/passff.json` to the appropriate location for your browser and OS:
46+
47+
- Firefox
48+
- Linux
49+
- Per-user: `~/.mozilla/native-messaging-hosts/passff.json`
50+
- System-wide: `/usr/{lib,lib64,share}/mozilla/native-messaging-hosts/passff.json`
51+
- OS X
52+
- `/Library/Application Support/Mozilla/NativeMessagingHosts/passff.json`
53+
- Windows
54+
- Per-user: `Path contained in registry key HKEY_CURRENT_USER\Software\Mozilla\NativeMessagingHosts\passff`
55+
- System-wide: `Path contained in registry key HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\NativeMessagingHosts\passff`
56+
- Chrome
57+
- Linux
58+
- Per-user: `~/.config/google-chrome/NativeMessagingHosts/passff.json`
59+
- System-wide: `/etc/opt/chrome/native-messaging-hosts/passff.json`
60+
- OS X
61+
- Per-user: `~/Library/Application Support/Google/Chrome/NativeMessagingHosts/passff.json`
62+
- System-wide: `/Library/Google/Chrome/NativeMessagingHosts/passff.json`
63+
- Windows
64+
- Per-user: `HKEY_CURRENT_USER\SOFTWARE\Google\Chrome\NativeMessagingHosts\passff`
65+
- System-wide: `HKEY_LOCAL_MACHINE\SOFTWARE\Google\Chrome\NativeMessagingHosts\passff`
66+
- Chromium
67+
- Linux
68+
- Per-user: `~/.config/chromium/NativeMessagingHosts/passff.json`
69+
- System-wide: `/etc/chromium/native-messaging-hosts/passff.json`
70+
- OS X
71+
- Per-user: `~/Library/Application Support/Chromium/NativeMessagingHosts/passff.json`
72+
- System-wide: `/Library/Application Support/Chromium/NativeMessagingHosts/passff.json`
73+
- Opera
74+
- Same as Chrome
75+
- Vivaldi
76+
- Linux
77+
- Per-user: `~/.config/vivaldi/NativeMessagingHosts/passff.json`
78+
- System-wide: `/etc/vivaldi/native-messaging-hosts/passff.json`
79+
- OS X
80+
- Per-user: `~/Library/Application Support/Vivaldi/NativeMessagingHosts/passff.json`
81+
- System-wide: `/Library/Application Support/Vivaldi/NativeMessagingHosts/passff.json`
82+
83+
### Preferences
84+
By modifying the `preferences section` in `passff.py` you will be able to set
85+
- the path to the `pass` script,
86+
- additional command line arguments that are passed to `pass`,
87+
- the shell `stdout` charset,
88+
- additional environment variables.

src/Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
VERSION := testing
3+
4+
SRC_DIR := .
5+
TARGET_DIR := ../bin/$(VERSION)
6+
7+
INSTALL_WIN_FILE := install_host_app.bat
8+
INSTALL_WIN_SRC := $(SRC_DIR)/$(INSTALL_WIN_FILE)
9+
INSTALL_WIN_TARGET := $(TARGET_DIR)/$(INSTALL_WIN_FILE)
10+
11+
INSTALL_UNIX_FILE := install_host_app.sh
12+
INSTALL_UNIX_SRC := $(SRC_DIR)/$(INSTALL_UNIX_FILE)
13+
INSTALL_UNIX_TARGET := $(TARGET_DIR)/$(INSTALL_UNIX_FILE)
14+
15+
HOST_APP_FILES := passff.py passff.json
16+
HOST_APP_SRC := $(addprefix $(SRC_DIR)/,$(HOST_APP_FILES))
17+
HOST_APP_TARGET := $(addprefix $(TARGET_DIR)/,$(HOST_APP_FILES))
18+
19+
HOST_TARGETS := $(INSTALL_WIN_TARGET) $(INSTALL_UNIX_TARGET) $(HOST_APP_TARGET)
20+
21+
all: $(HOST_TARGETS)
22+
23+
%/.d:
24+
mkdir -p $(@D)
25+
@touch $@
26+
27+
$(HOST_TARGETS): $(TARGET_DIR)/%: $(SRC_DIR)/% $(TARGET_DIR)/.d
28+
cp $(SRC_DIR)/$* $@
29+
sed -i "s/_VERSIONHOLDER_/$(VERSION)/g" $@
30+
31+
clean:
32+
rm -rf $(TARGET_DIR)
33+
34+
.PRECIOUS: %/.d

src/install_host_app.bat

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
@ECHO OFF
2+
SETLOCAL
3+
4+
SET "APP_NAME=passff"
5+
SET "VERSION=_VERSIONHOLDER_"
6+
SET "HOST_URL=https://github.com/passff/passff-host/releases/download/%VERSION%/passff.py"
7+
SET "MANIFEST_URL=https://github.com/passff/passff-host/releases/download/%VERSION%/passff.json"
8+
9+
SET "TARGET_DIR=%APPDATA%\%APP_NAME%"
10+
SET "HOST_MANIFEST=%APP_NAME%.json"
11+
SET "HOST_SCRIPT=%APP_NAME%.py"
12+
SET "HOST_BATCH=%APP_NAME%.bat"
13+
14+
SET "HOST_MANIFEST_FULL=%TARGET_DIR%\%HOST_MANIFEST%"
15+
SET "HOST_SCRIPT_FULL=%TARGET_DIR%\%HOST_SCRIPT%"
16+
SET "HOST_BATCH_FULL=%TARGET_DIR%\%HOST_BATCH%"
17+
18+
SET "USE_LOCAL_FILES="
19+
SET "TARGET_REG="
20+
21+
REM check prerequisites: is python installed & in path?
22+
python --version >NUL 2> NUL || (
23+
ECHO "python not found in PATH. Please execute this command in a shell where python is in PATH"
24+
EXIT /B
25+
)
26+
27+
:loop
28+
IF NOT "%1"=="" (
29+
IF "%1"=="--local" (
30+
SET "USE_LOCAL_FILES=true"
31+
SHIFT
32+
) ELSE IF "%1"=="--help" (
33+
GOTO :help
34+
) ELSE IF "%1"=="firefox" (
35+
SET "TARGET_REG=HKCU\SOFTWARE\Mozilla\NativeMessagingHosts\%APP_NAME%"
36+
SHIFT
37+
) ELSE IF "%1"=="chrome" (
38+
SET "TARGET_REG=HKCU\Software\Google\Chrome\NativeMessagingHosts\%APP_NAME%"
39+
SHIFT
40+
) ELSE IF "%1"=="chromium" (
41+
ECHO Chromium registry key location for Native Messaging Hosts is undocumented. Assuming key for Chrome. Please provide feedback if this worked: https://github.com/passff/passff/issues/202
42+
SET "TARGET_REG=HKCU\Software\Google\Chrome\NativeMessagingHosts\%APP_NAME%"
43+
SHIFT
44+
) ELSE IF "%1"=="opera" (
45+
ECHO Opera registry key location for Native Messaging Hosts is undocumented. Assuming key for Chrome. Please provide feedback if this worked: https://github.com/passff/passff/issues/202
46+
SET "TARGET_REG=HKCU\Software\Google\Chrome\NativeMessagingHosts\%APP_NAME%"
47+
SHIFT
48+
) ELSE IF "%1"=="vivaldi" (
49+
ECHO Vivaldi registry key location for Native Messaging Hosts is undocumented. Assuming key for Chrome. Please provide feedback if this worked: https://github.com/passff/passff/issues/202
50+
SET "TARGET_REG=HKCU\Software\Google\Chrome\NativeMessagingHosts\%APP_NAME%"
51+
SHIFT
52+
) ELSE (
53+
SHIFT
54+
)
55+
GOTO :loop
56+
)
57+
58+
IF "%TARGET_REG%"=="" (
59+
GOTO :help
60+
)
61+
62+
IF EXIST "%TARGET_DIR%" (
63+
dir /AD "%TARGET_DIR%" > nul || (
64+
ECHO "%TARGET_DIR%" is not a directory
65+
EXIT /B
66+
)
67+
) ELSE (
68+
MKDIR "%TARGET_DIR%" 2> nul
69+
)
70+
71+
IF "%USE_LOCAL_FILES%"=="true" (
72+
IF NOT EXIST "%~dp0%HOST_MANIFEST%" (
73+
ECHO local file "%~dp0%HOST_MANIFEST%" not found
74+
EXIT /B
75+
)
76+
IF NOT EXIST "%~dp0%HOST_SCRIPT%" (
77+
ECHO local file "%~dp0%HOST_SCRIPT%" not found
78+
EXIT /B
79+
)
80+
COPY /Y "%~dp0%HOST_MANIFEST%" "%HOST_MANIFEST_FULL%"
81+
COPY /Y "%~dp0%HOST_SCRIPT%" "%HOST_SCRIPT_FULL%"
82+
) ELSE (
83+
powershell -Command "(New-Object Net.WebClient).DownloadFile('%HOST_URL%', '%HOST_SCRIPT_FULL%')"
84+
powershell -Command "(New-Object Net.WebClient).DownloadFile('%MANIFEST_URL%', '%HOST_MANIFEST_FULL%')"
85+
)
86+
87+
powershell -Command "(Get-Content '%HOST_MANIFEST_FULL%') -replace 'PLACEHOLDER', '%HOST_BATCH_FULL:\=/%' | Set-Content '%HOST_MANIFEST_FULL%'"
88+
89+
(
90+
ECHO @ECHO OFF
91+
ECHO SET "PATH=%PATH%"
92+
ECHO SET "GNUPGHOME=%GNUPGHOME%"
93+
ECHO python "%HOST_SCRIPT_FULL%" %%*
94+
)>"%HOST_BATCH_FULL%"
95+
96+
REG ADD "%TARGET_REG%" /ve /d "%HOST_MANIFEST_FULL%" /f || (
97+
ECHO Adding key to registry failed - maybe you need Administrator rights for this. Please run
98+
ECHO REG ADD "%TARGET_REG%" /ve /d "%HOST_MANIFEST_FULL%" /f
99+
ECHO manually in an administrative shell.
100+
)
101+
EXIT /B
102+
103+
:help
104+
ECHO Usage: %0 [OPTION] [chrome^|chromium^|firefox^|opera^|vivaldi]
105+
ECHO
106+
ECHO Options:
107+
ECHO --local Install files from disk instead of downloading them
108+
ECHO --help Show this message"
109+
EXIT /B

src/install_host_app.sh

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/usr/bin/env bash
2+
3+
# This script is derived from `install.sh` in Danny van Kooten's "browserpass":
4+
# https://github.com/dannyvankooten/browserpass
5+
6+
set -e
7+
8+
APP_NAME="passff"
9+
VERSION="_VERSIONHOLDER_"
10+
HOST_URL="https://github.com/passff/passff-host/releases/download/$VERSION/passff.py"
11+
MANIFEST_URL="https://github.com/passff/passff-host/releases/download/$VERSION/passff.json"
12+
13+
# Find target dirs for various browsers & OS'es
14+
# https://developer.chrome.com/extensions/nativeMessaging#native-messaging-host-location
15+
# https://wiki.mozilla.org/WebExtensions/Native_Messaging
16+
if [ $(uname -s) == 'Darwin' ]; then
17+
if [ "$(whoami)" == "root" ]; then
18+
TARGET_DIR_CHROME="/Library/Google/Chrome/NativeMessagingHosts"
19+
TARGET_DIR_CHROMIUM="/Library/Application Support/Chromium/NativeMessagingHosts"
20+
TARGET_DIR_FIREFOX="/Library/Application Support/Mozilla/NativeMessagingHosts"
21+
TARGET_DIR_VIVALDI="/Library/Application Support/Vivaldi/NativeMessagingHosts"
22+
else
23+
TARGET_DIR_CHROME="$HOME/Library/Application Support/Google/Chrome/NativeMessagingHosts"
24+
TARGET_DIR_CHROMIUM="$HOME/Library/Application Support/Chromium/NativeMessagingHosts"
25+
TARGET_DIR_FIREFOX="$HOME/Library/Application Support/Mozilla/NativeMessagingHosts"
26+
TARGET_DIR_VIVALDI="$HOME/Library/Application Support/Vivaldi/NativeMessagingHosts"
27+
fi
28+
else
29+
if [ "$(whoami)" == "root" ]; then
30+
TARGET_DIR_CHROME="/etc/opt/chrome/native-messaging-hosts"
31+
TARGET_DIR_CHROMIUM="/etc/chromium/native-messaging-hosts"
32+
TARGET_DIR_FIREFOX="/usr/lib/mozilla/native-messaging-hosts"
33+
TARGET_DIR_VIVALDI="/etc/vivaldi/native-messaging-hosts"
34+
else
35+
TARGET_DIR_CHROME="$HOME/.config/google-chrome/NativeMessagingHosts"
36+
TARGET_DIR_CHROMIUM="$HOME/.config/chromium/NativeMessagingHosts"
37+
TARGET_DIR_FIREFOX="$HOME/.mozilla/native-messaging-hosts"
38+
TARGET_DIR_VIVALDI="$HOME/.config/vivaldi/NativeMessagingHosts"
39+
fi
40+
fi
41+
42+
function usage {
43+
echo "Usage: $0 [OPTION] [chrome|chromium|firefox|opera|vivaldi]
44+
45+
Options:
46+
-l, --local Install files from disk instead of downloading them
47+
-h, --help Show this message"
48+
}
49+
50+
while [[ $# -gt 0 ]]; do
51+
case $1 in
52+
chrome)
53+
BROWSER_NAME="Chrome"
54+
TARGET_DIR="$TARGET_DIR_CHROME"
55+
;;
56+
chromium)
57+
BROWSER_NAME="Chromium"
58+
TARGET_DIR="$TARGET_DIR_CHROMIUM"
59+
;;
60+
firefox)
61+
BROWSER_NAME="Firefox"
62+
TARGET_DIR="$TARGET_DIR_FIREFOX"
63+
;;
64+
opera)
65+
BROWSER_NAME="Opera"
66+
TARGET_DIR="$TARGET_DIR_VIVALDI"
67+
;;
68+
vivaldi)
69+
BROWSER_NAME="Vivaldi"
70+
TARGET_DIR="$TARGET_DIR_VIVALDI"
71+
;;
72+
-l|--local)
73+
USE_LOCAL_FILES=true
74+
;;
75+
-h|--help)
76+
usage
77+
exit 0
78+
;;
79+
*)
80+
usage
81+
exit 1
82+
;;
83+
esac
84+
shift
85+
done
86+
87+
PYTHON3_PATH="$(which python3)"
88+
if [ -x "$PYTHON3_PATH" ]; then
89+
echo "Python 3 executable located at $PYTHON3_PATH"
90+
else
91+
echo "Python 3 executable not found, but Python 3 is required for PassFF to work!"
92+
exit 1
93+
fi
94+
95+
if [ -z "$TARGET_DIR" ]; then
96+
usage
97+
exit 1
98+
fi
99+
100+
HOST_FILE_PATH="$TARGET_DIR/$APP_NAME.py"
101+
MANIFEST_FILE_PATH="$TARGET_DIR/$APP_NAME.json"
102+
ESCAPED_HOST_FILE_PATH="${HOST_FILE_PATH////\\/}"
103+
104+
echo "Installing $BROWSER_NAME host config"
105+
106+
# Create config dir if not existing
107+
mkdir -p "$TARGET_DIR"
108+
109+
if [ "$USE_LOCAL_FILES" = true ]; then
110+
DIR="$( cd "$( dirname "$0" )" && pwd )"
111+
cp "$DIR/passff.py" "$HOST_FILE_PATH"
112+
cp "$DIR/passff.json" "$MANIFEST_FILE_PATH"
113+
else
114+
# Download native host script and manifest
115+
curl -sSL "$HOST_URL" > "$HOST_FILE_PATH"
116+
curl -sSL "$MANIFEST_URL" > "$MANIFEST_FILE_PATH"
117+
fi
118+
119+
# Replace path to host
120+
sed -i -e "s/PLACEHOLDER/$ESCAPED_HOST_FILE_PATH/" "$MANIFEST_FILE_PATH"
121+
122+
# Replace path to python3 executable
123+
sed -i "1c#\!${PYTHON3_PATH}" "$HOST_FILE_PATH"
124+
125+
# Set permissions for the manifest so that all users can read it.
126+
chmod a+x "$HOST_FILE_PATH"
127+
chmod o+r "$MANIFEST_FILE_PATH"
128+
129+
echo "Native messaging host for $BROWSER_NAME has been installed to $TARGET_DIR."

src/passff.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "passff",
3+
"description": "Host for communicating with zx2c4 pass",
4+
"path": "PLACEHOLDER",
5+
"type": "stdio",
6+
"allowed_extensions": [ "[email protected]" ]
7+
}

0 commit comments

Comments
 (0)