diff --git a/.gitignore b/.gitignore index 5be7bc2..26e70a9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /browserpass /browserpass-* vendor/ +dist/ diff --git a/Makefile b/Makefile index 5ea3c94..10ba04c 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,11 @@ +PKG_NAME ?= browserpass + +APP_ID = com.github.browserpass.native +OS = $(shell uname -s) + +####################### +# For local development + .PHONY: all all: deps browserpass test @@ -11,9 +19,6 @@ browserpass: *.go **/*.go browserpass-linux64: *.go **/*.go env GOOS=linux GOARCH=amd64 go build -o $@ -browserpass-windows64: *.go **/*.go - env GOOS=windows GOARCH=amd64 go build -o $@.exe - browserpass-darwinx64: *.go **/*.go env GOOS=darwin GOARCH=amd64 go build -o $@ @@ -23,6 +28,176 @@ browserpass-openbsd64: *.go **/*.go browserpass-freebsd64: *.go **/*.go env GOOS=freebsd GOARCH=amd64 go build -o $@ +browserpass-windows64: *.go **/*.go + env GOOS=windows GOARCH=amd64 go build -o $@.exe + .PHONY: test test: go test ./... + +####################### +# For official releases + +.PHONY: clean +clean: + rm -f browserpass browserpass-* + rm -rf dist vendor + +.PHONY: tarball +tarball: clean deps + $(eval TMPDIR := $(shell mktemp -d)) + mkdir -p $(TMPDIR)/browserpass-native + cp -r * $(TMPDIR)/browserpass-native + + rm -rf $(TMPDIR)/browserpass-native/.git + (cd $(TMPDIR) && tar -czf $(TMPDIR)/browserpass-native-src.tar.gz browserpass-native) + + mkdir -p dist + cp $(TMPDIR)/browserpass-native-src.tar.gz dist/ + rm -rf $(TMPDIR) + +.PHONY: dist +dist: clean deps tarball browserpass-linux64 browserpass-darwinx64 browserpass-openbsd64 browserpass-freebsd64 browserpass-windows64 + mkdir -p dist + zip -FS dist/browserpass-linux64 browserpass-linux64 browser-files/* Makefile README.md LICENSE + zip -FS dist/browserpass-darwinx64 browserpass-darwinx64 browser-files/* Makefile README.md LICENSE + zip -FS dist/browserpass-openbsd64 browserpass-openbsd64 browser-files/* Makefile README.md LICENSE + zip -FS dist/browserpass-freebsd64 browserpass-freebsd64 browser-files/* Makefile README.md LICENSE + zip -FS dist/browserpass-windows64 browserpass-windows64.exe browser-files/* Makefile README.md LICENSE + + for file in dist/*; do \ + gpg --detach-sign "$$file"; \ + done + +####################### +# For user installation + +.PHONY: install +install: + install -Dm755 -t "$(DESTDIR)/usr/bin/" $(PKG_NAME) + install -Dm644 -t "$(DESTDIR)/usr/lib/browserpass/" Makefile + install -Dm644 -t "$(DESTDIR)/usr/share/licenses/browserpass/" LICENSE + install -Dm644 -t "$(DESTDIR)/usr/share/doc/browserpass/" README.md + + install -Dm644 browser-files/chromium-host.json "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" + install -Dm644 browser-files/chromium-policy.json "$(DESTDIR)/usr/lib/browserpass/policies/chromium/$(APP_ID).json" + install -Dm644 browser-files/firefox-host.json "$(DESTDIR)/usr/lib/browserpass/hosts/firefox/$(APP_ID).json" + + sed -i "s|%%replace%%|$(DESTDIR)/usr/bin/$(PKG_NAME)|" "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" + sed -i "s|%%replace%%|$(DESTDIR)/usr/bin/$(PKG_NAME)|" "$(DESTDIR)/usr/lib/browserpass/hosts/firefox/$(APP_ID).json" + +# Browser-specific hosts targets + +.PHONY: hosts-chromium +hosts-chromium: + @case $(OS) in \ + Linux) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "/etc/chromium/native-messaging-hosts/" ;; \ + Darwin) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "/Library/Application Support/Chromium/NativeMessagingHosts/" ;; \ + *) echo "The operating system $(OS) is not supported"; exit 1 ;; \ + esac + +.PHONY: hosts-chromium-user +hosts-chromium-user: + @case $(OS) in \ + Linux|OpenBSD|FreeBSD) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "${HOME}/.config/chromium/NativeMessagingHosts/" ;; \ + Darwin) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "${HOME}/Library/Application Support/Chromium/NativeMessagingHosts/" ;; \ + *) echo "The operating system $(OS) is not supported"; exit 1 ;; \ + esac + +.PHONY: hosts-chrome +hosts-chrome: + @case $(OS) in \ + Linux) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "/etc/opt/chrome/native-messaging-hosts/" ;; \ + Darwin) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "/Library/Google/Chrome/NativeMessagingHosts/" ;; \ + *) echo "The operating system $(OS) is not supported"; exit 1 ;; \ + esac + +.PHONY: hosts-chrome-user +hosts-chrome-user: + @case $(OS) in \ + Linux|OpenBSD|FreeBSD) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "${HOME}/.config/google-chrome/NativeMessagingHosts/" ;; \ + Darwin) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "${HOME}/Library/Application Support/Google/Chrome/NativeMessagingHosts/" ;; \ + *) echo "The operating system $(OS) is not supported"; exit 1 ;; \ + esac + +.PHONY: hosts-vivaldi +hosts-vivaldi: + @case $(OS) in \ + Linux) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "/etc/opt/vivaldi/native-messaging-hosts/" ;; \ + Darwin) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "/Library/Application Support/Vivaldi/NativeMessagingHosts/" ;; \ + *) echo "The operating system $(OS) is not supported"; exit 1 ;; \ + esac + +.PHONY: hosts-vivaldi-user +hosts-vivaldi-user: + @case $(OS) in \ + Linux|OpenBSD|FreeBSD) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "${HOME}/.config/vivaldi/NativeMessagingHosts/" ;; \ + Darwin) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "${HOME}/Library/Application Support/Vivaldi/NativeMessagingHosts/" ;; \ + *) echo "The operating system $(OS) is not supported"; exit 1 ;; \ + esac + +.PHONY: hosts-firefox +hosts-firefox: + @case $(OS) in \ + Linux) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/firefox/$(APP_ID).json" "/usr/lib/mozilla/native-messaging-hosts/" ;; \ + Darwin) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/firefox/$(APP_ID).json" "/Library/Application Support/Mozilla/NativeMessagingHosts/" ;; \ + *) echo "The operating system $(OS) is not supported"; exit 1 ;; \ + esac + +.PHONY: hosts-firefox-user +hosts-firefox-user: + @case $(OS) in \ + Linux|OpenBSD|FreeBSD) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/firefox/$(APP_ID).json" "${HOME}/.mozilla/native-messaging-hosts/" ;; \ + Darwin) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/firefox/$(APP_ID).json" "${HOME}/Library/Application Support/Mozilla/NativeMessagingHosts/" ;; \ + *) echo "The operating system $(OS) is not supported"; exit 1 ;; \ + esac + +# Browser-specific policies targets + +.PHONY: policies-chromium +policies-chromium: + @case $(OS) in \ + Linux) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "/etc/chromium/policies/managed/" ;; \ + Darwin) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "/Library/Application Support/Chromium/policies/managed/" ;; \ + *) echo "The operating system $(OS) is not supported"; exit 1 ;; \ + esac + +.PHONY: policies-chromium-user +policies-chromium-user: + @case $(OS) in \ + Linux|OpenBSD|FreeBSD) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "${HOME}/.config/chromium/policies/managed/" ;; \ + Darwin) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "${HOME}/Library/Application Support/Chromium/policies/managed/" ;; \ + *) echo "The operating system $(OS) is not supported"; exit 1 ;; \ + esac + +.PHONY: policies-chrome +policies-chrome: + @case $(OS) in \ + Linux) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "/etc/opt/chrome/policies/managed/" ;; \ + Darwin) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "/Library/Google/Chrome/policies/managed/" ;; \ + *) echo "The operating system $(OS) is not supported"; exit 1 ;; \ + esac + +.PHONY: policies-chrome-user +policies-chrome-user: + @case $(OS) in \ + Linux|OpenBSD|FreeBSD) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "${HOME}/.config/google-chrome/policies/managed/" ;; \ + Darwin) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "${HOME}/Library/Application Support/Google/Chrome/policies/managed/" ;; \ + *) echo "The operating system $(OS) is not supported"; exit 1 ;; \ + esac + +.PHONY: policies-vivaldi +policies-vivaldi: + @case $(OS) in \ + Linux) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "/etc/opt/vivaldi/policies/managed/" ;; \ + Darwin) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "/Library/Application Support/Vivaldi/policies/managed/" ;; \ + *) echo "The operating system $(OS) is not supported"; exit 1 ;; \ + esac + +.PHONY: policies-vivaldi-user +policies-vivaldi-user: + @case $(OS) in \ + Linux|OpenBSD|FreeBSD) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "${HOME}/.config/vivaldi/policies/managed/" ;; \ + Darwin) ln -sf "$(DESTDIR)/usr/lib/browserpass/hosts/chromium/$(APP_ID).json" "${HOME}/Library/Application Support/Vivaldi/policies/managed/" ;; \ + *) echo "The operating system $(OS) is not supported"; exit 1 ;; \ + esac diff --git a/browser-files/chromium-host.json b/browser-files/chromium-host.json new file mode 100644 index 0000000..8faa3d7 --- /dev/null +++ b/browser-files/chromium-host.json @@ -0,0 +1,10 @@ +{ + "name": "com.github.browserpass.native", + "description": "Browserpass native component for the Chromium extension", + "path": "%%replace%%", + "type": "stdio", + "allowed_origins": [ + "chrome-extension://naepdomgkenhinolocfifgehidddafch/", + "chrome-extension://klfoddkbhleoaabpmiigbmpbjfljimgb/" + ] +} diff --git a/browser-files/chromium-policy.json b/browser-files/chromium-policy.json new file mode 100644 index 0000000..d95634a --- /dev/null +++ b/browser-files/chromium-policy.json @@ -0,0 +1,5 @@ +{ + "ExtensionInstallForcelist": [ + "naepdomgkenhinolocfifgehidddafch;https://clients2.google.com/service/update2/crx" + ] +} diff --git a/browser-files/firefox-host.json b/browser-files/firefox-host.json new file mode 100644 index 0000000..571344a --- /dev/null +++ b/browser-files/firefox-host.json @@ -0,0 +1,7 @@ +{ + "name": "com.github.browserpass.native", + "description": "Browserpass native component for the Firefox extension", + "path": "%%replace%%", + "type": "stdio", + "allowed_extensions": ["browserpass@maximbaz.com"] +} diff --git a/openbsd/openbsd.go b/openbsd/openbsd.go index d41d6be..77c1f9e 100644 --- a/openbsd/openbsd.go +++ b/openbsd/openbsd.go @@ -6,5 +6,5 @@ import "golang.org/x/sys/unix" // Pledge allowed system calls func Pledge(promises string) { - unix.Pledge(promises, nil) + unix.Pledge(promises, "") }