Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f9d721f179 | ||
|
|
7bb859f7df | ||
|
|
87df40db11 | ||
|
|
c0026b0b5f | ||
|
|
8c3e89368c | ||
|
|
36e08df09e | ||
|
|
d930387758 | ||
|
|
42bfe570e1 | ||
|
|
e877f8d27d | ||
|
|
6d1a5ca1a5 | ||
|
|
5d92e65a92 | ||
|
|
befbecb131 | ||
|
|
3d27747a91 | ||
|
|
b4d6a374d3 | ||
|
|
42eb428c4c | ||
|
|
7a1ab6a48c | ||
|
|
044024b549 | ||
|
|
7b9de10d80 | ||
|
|
e527f83dd4 | ||
|
|
1cffcde52d | ||
|
|
06cd3a53ac | ||
|
|
45817b10e3 | ||
|
|
8220b3619d | ||
|
|
1e28b7e273 | ||
|
|
8db4e1b414 | ||
|
|
cafa4f9054 | ||
|
|
71ace783e2 | ||
|
|
d80b8e16f9 | ||
|
|
027b359ed7 | ||
|
|
36e811bf74 | ||
|
|
41bb63baa7 | ||
|
|
423762d82f | ||
|
|
9f4f12f68a | ||
|
|
1497ecee17 | ||
|
|
3f4b8e43d5 | ||
|
|
a68e9fa3ee | ||
|
|
f70ade6adc | ||
|
|
e636813590 | ||
|
|
92ee741298 | ||
|
|
5c60cf8226 | ||
|
|
8f4121d921 | ||
|
|
b0c7b2079a | ||
|
|
055d130bc3 | ||
|
|
57d52c6658 | ||
|
|
8a601d6366 | ||
|
|
cc77006502 | ||
|
|
cb82a38b6a | ||
|
|
d19d6edf7d | ||
|
|
f2eaed3c86 | ||
|
|
b6cdc32d52 | ||
|
|
5047ce86b0 | ||
|
|
45f3f8dbc0 | ||
|
|
a52a4b6462 | ||
|
|
b8bed150d0 | ||
|
|
56be19e3a9 | ||
|
|
b256e9b9fd | ||
|
|
b4be99002d | ||
|
|
9447c3a75c | ||
|
|
3deda78d54 | ||
|
|
c76f76ffb7 |
No files matched your search
@@ -19,22 +19,13 @@ jobs:
|
||||
name: Submodule URLs are public HTTPS
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# Plain checkout on purpose: the guard must not depend on fetching
|
||||
# the submodules it validates (an SSH URL would break that fetch).
|
||||
# Plain checkout on purpose: the guard validates URLs before allowing
|
||||
# recursive submodule checkout to continue.
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Reject non-HTTPS submodule URLs
|
||||
run: |
|
||||
set -eu
|
||||
if [ ! -f .gitmodules ]; then echo "no submodules - ok"; exit 0; fi
|
||||
bad=$(grep -nE '^[[:space:]]*url[[:space:]]*=' .gitmodules \
|
||||
| grep -vE '^[0-9]+:[[:space:]]*url[[:space:]]*=[[:space:]]*https://' || true)
|
||||
if [ -n "$bad" ]; then
|
||||
echo "::error::Non-HTTPS submodule URL(s) break fresh clones and CI:$bad"
|
||||
exit 1
|
||||
fi
|
||||
echo "all submodule URLs HTTPS - ok"
|
||||
run: scripts/check_submodule_urls.sh
|
||||
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -43,24 +34,49 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.25.x
|
||||
cache: false
|
||||
- name: Test CLI and generator
|
||||
run: go test ./...
|
||||
- name: Install Emscripten
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git clone --depth 1 https://github.com/emscripten-core/emsdk.git "$HOME/emsdk"
|
||||
"$HOME/emsdk/emsdk" install latest
|
||||
"$HOME/emsdk/emsdk" activate latest
|
||||
echo "EM_CONFIG=$HOME/emsdk/.emscripten" >> "$GITHUB_ENV"
|
||||
echo "$HOME/emsdk/upstream/emscripten" >> "$GITHUB_PATH"
|
||||
- name: Test C CLI, core, and Kry generator
|
||||
run: make test
|
||||
- name: Build browser app
|
||||
run: make site
|
||||
- name: Verify generated site
|
||||
run: |
|
||||
test -s build/site/index.html
|
||||
test -s build/site/app/index.html
|
||||
test -s build/site/app/pass.wasm
|
||||
- name: Check formatting
|
||||
run: test -z "$(find . -path ./vendor -prune -o -name '*.go' -type f -print | xargs gofmt -l)"
|
||||
test -s build/site/app/index.wasm
|
||||
- name: Check fastlane metadata
|
||||
run: |
|
||||
set -eu
|
||||
meta=fastlane/metadata/android/en-US
|
||||
limit() {
|
||||
n=$(wc -m < "$1")
|
||||
if [ "$n" -gt "$2" ]; then
|
||||
echo "::error::$1 is $n characters (max $2)"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
limit "$meta/title.txt" 30
|
||||
limit "$meta/short_description.txt" 80
|
||||
limit "$meta/full_description.txt" 4000
|
||||
for f in "$meta"/changelogs/*.txt; do
|
||||
limit "$f" 500
|
||||
done
|
||||
code=$(sed -n 's/^[[:space:]]*versionCode \([0-9][0-9]*\)$/\1/p' droid/app/build.gradle | head -n 1)
|
||||
test -n "$code"
|
||||
test -s "$meta/changelogs/$code.txt"
|
||||
test -s "$meta/images/icon.png"
|
||||
echo "fastlane metadata ok (versionCode $code)"
|
||||
|
||||
build-gui:
|
||||
name: GUI (${{ matrix.arch }})
|
||||
needs: guard-submodule-urls
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
@@ -73,10 +89,6 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.25.x
|
||||
cache: false
|
||||
- name: Install native dependencies
|
||||
run: |
|
||||
mapfile -t packages < .github/apt/gui-packages.txt
|
||||
@@ -84,8 +96,6 @@ jobs:
|
||||
sudo apt-get install -y "${packages[@]}"
|
||||
- name: Build GUI
|
||||
run: make gui
|
||||
- name: Test GUI logic
|
||||
run: cd gui && go test ./...
|
||||
- name: Build Debian package
|
||||
run: make package-deb
|
||||
- uses: actions/upload-artifact@v4
|
||||
@@ -125,7 +135,7 @@ jobs:
|
||||
path: |
|
||||
droid/app/.cxx
|
||||
droid/app/build/intermediates/cxx
|
||||
key: android-native-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('droid/app/src/main/cpp/CMakeLists.txt', 'droid/app/build.gradle', 'native/*.c', 'droid/app/src/main/cpp/*.c', 'vendor/kryon/src/**/*.c', 'vendor/kryon/include/**/*.h', 'vendor/kryon/vendor/raylib/src/**') }}
|
||||
key: android-native-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('app/*.kry', 'droid/app/src/main/cpp/CMakeLists.txt', 'droid/app/build.gradle', 'native/*.c', 'droid/app/src/main/cpp/*.c', 'vendor/kryon/src/**/*.c', 'vendor/kryon/include/**/*.h', 'vendor/kryon/vendor/raylib/src/**') }}
|
||||
restore-keys: |
|
||||
android-native-${{ runner.os }}-${{ runner.arch }}-
|
||||
- name: Install Android SDK components
|
||||
@@ -139,3 +149,41 @@ jobs:
|
||||
set -euo pipefail
|
||||
chmod +x droid/gradlew
|
||||
make android-debug
|
||||
|
||||
android-input-test:
|
||||
name: Android input instrumentation
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
needs: guard-submodule-urls
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: '21'
|
||||
- uses: gradle/actions/setup-gradle@v3
|
||||
- name: Install Android SDK components
|
||||
run: |
|
||||
set -euo pipefail
|
||||
SDKMANAGER="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager"
|
||||
yes | "$SDKMANAGER" --licenses >/dev/null || true
|
||||
"$SDKMANAGER" "platforms;android-36" "build-tools;34.0.0" "ndk;28.2.13676358" "cmake;3.22.1"
|
||||
- name: Run Android input tests
|
||||
uses: reactivecircus/android-emulator-runner@v2
|
||||
with:
|
||||
api-level: 30
|
||||
arch: x86_64
|
||||
target: default
|
||||
emulator-boot-timeout: 900
|
||||
emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -no-metrics
|
||||
script: make android-input-test
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: failure()
|
||||
with:
|
||||
name: android-input-test-reports
|
||||
path: |
|
||||
droid/app/build/reports/androidTests/
|
||||
droid/app/build/outputs/androidTest-results/
|
||||
if-no-files-found: ignore
|
||||
@@ -13,44 +13,46 @@ concurrency:
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
cli:
|
||||
name: CLI (${{ matrix.os }}-${{ matrix.arch }})
|
||||
guard-submodule-urls:
|
||||
name: Submodule URLs are public HTTPS
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Reject non-HTTPS submodule URLs
|
||||
run: scripts/check_submodule_urls.sh
|
||||
|
||||
cli:
|
||||
name: CLI (${{ matrix.arch }})
|
||||
needs: guard-submodule-urls
|
||||
strategy:
|
||||
matrix:
|
||||
os: [linux, darwin, windows, freebsd]
|
||||
arch: [amd64, arm64]
|
||||
include:
|
||||
- runner: ubuntu-22.04
|
||||
arch: amd64
|
||||
- runner: ubuntu-24.04-arm
|
||||
arch: arm64
|
||||
runs-on: ${{ matrix.runner }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.24.x
|
||||
cache: false
|
||||
- name: Build archive
|
||||
env:
|
||||
TARGET_OS: ${{ matrix.os }}
|
||||
TARGET_ARCH: ${{ matrix.arch }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
name="pass-cli-${TARGET_OS}-${TARGET_ARCH}"
|
||||
make cli
|
||||
name="pass-cli-linux-${{ matrix.arch }}"
|
||||
mkdir -p "build/release/$name"
|
||||
suffix=""
|
||||
[ "$TARGET_OS" = windows ] && suffix=".exe"
|
||||
CGO_ENABLED=0 GOOS="$TARGET_OS" GOARCH="$TARGET_ARCH" go build -trimpath -ldflags='-s -w' -o "build/release/$name/pass$suffix" ./cmd/pass
|
||||
cp LICENSE README.md "build/release/$name/"
|
||||
if [ "$TARGET_OS" = windows ]; then
|
||||
(cd build/release && zip -qr "$name.zip" "$name")
|
||||
else
|
||||
tar -C build/release -czf "build/release/$name.tar.gz" "$name"
|
||||
fi
|
||||
cp pass LICENSE README.md "build/release/$name/"
|
||||
tar -C build/release -czf "build/release/$name.tar.gz" "$name"
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: cli-${{ matrix.os }}-${{ matrix.arch }}
|
||||
path: build/release/pass-cli-${{ matrix.os }}-${{ matrix.arch }}.*
|
||||
name: cli-linux-${{ matrix.arch }}
|
||||
path: build/release/pass-cli-linux-${{ matrix.arch }}.tar.gz
|
||||
if-no-files-found: error
|
||||
|
||||
gui:
|
||||
name: GUI (${{ matrix.arch }})
|
||||
needs: guard-submodule-urls
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
@@ -63,10 +65,6 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.25.x
|
||||
cache: false
|
||||
- name: Install native dependencies
|
||||
run: |
|
||||
mapfile -t packages < .github/apt/gui-packages.txt
|
||||
@@ -103,6 +101,7 @@ jobs:
|
||||
name: Android
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
needs: guard-submodule-urls
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
@@ -146,7 +145,7 @@ jobs:
|
||||
test -n "$KEYSTORE_BASE64" || { echo "::error::KEYSTORE_BASE64 secret is empty or missing"; exit 1; }
|
||||
mkdir -p "$HOME/.android"
|
||||
printf '%s' "$KEYSTORE_BASE64" | base64 -d > "$HOME/.android/pass-release.keystore"
|
||||
- name: Build release APK
|
||||
- name: Build release APKs
|
||||
env:
|
||||
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
||||
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
||||
@@ -155,34 +154,95 @@ jobs:
|
||||
test -n "$KEYSTORE_PASSWORD" || { echo "::error::KEYSTORE_PASSWORD secret is empty or missing"; exit 1; }
|
||||
test -n "$KEY_ALIAS" || { echo "::error::KEY_ALIAS secret is empty or missing"; exit 1; }
|
||||
chmod +x droid/gradlew
|
||||
make kry-c
|
||||
./droid/gradlew -p droid assembleRelease \
|
||||
-PsplitApks=true \
|
||||
-Pkeystore.path="$HOME/.android/pass-release.keystore" \
|
||||
-Pkeystore.alias="$KEY_ALIAS" \
|
||||
-Pkeystore.password="$KEYSTORE_PASSWORD" \
|
||||
--stacktrace
|
||||
VERSION=$(sed -n '1p' VERSION)
|
||||
mkdir -p build/release
|
||||
cp droid/app/build/outputs/apk/release/app-release.apk build/release/pass-android.apk
|
||||
cp droid/app/build/outputs/apk/release/app-universal-release.apk build/release/pass-android.apk
|
||||
cp droid/app/build/outputs/apk/release/app-arm64-v8a-release.apk build/release/pass-android-arm64-v8a.apk
|
||||
cp droid/app/build/outputs/apk/release/app-armeabi-v7a-release.apk build/release/pass-android-armeabi-v7a.apk
|
||||
cp droid/app/build/outputs/apk/release/app-universal-release.apk "build/release/pass-$VERSION.apk"
|
||||
cp droid/app/build/outputs/apk/release/app-arm64-v8a-release.apk "build/release/pass-$VERSION-arm64-v8a.apk"
|
||||
cp droid/app/build/outputs/apk/release/app-armeabi-v7a-release.apk "build/release/pass-$VERSION-armeabi-v7a.apk"
|
||||
test -s build/release/pass-android.apk
|
||||
test -s build/release/pass-android-arm64-v8a.apk
|
||||
test -s build/release/pass-android-armeabi-v7a.apk
|
||||
test -s "build/release/pass-$VERSION.apk"
|
||||
test -s "build/release/pass-$VERSION-arm64-v8a.apk"
|
||||
test -s "build/release/pass-$VERSION-armeabi-v7a.apk"
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: android
|
||||
path: build/release/pass-android.apk
|
||||
path: build/release/*.apk
|
||||
if-no-files-found: error
|
||||
|
||||
web:
|
||||
runs-on: ubuntu-latest
|
||||
needs: guard-submodule-urls
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.24.x
|
||||
cache: false
|
||||
submodules: recursive
|
||||
- name: Install Emscripten
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git clone --depth 1 https://github.com/emscripten-core/emsdk.git "$HOME/emsdk"
|
||||
"$HOME/emsdk/emsdk" install latest
|
||||
"$HOME/emsdk/emsdk" activate latest
|
||||
echo "EM_CONFIG=$HOME/emsdk/.emscripten" >> "$GITHUB_ENV"
|
||||
echo "$HOME/emsdk/upstream/emscripten" >> "$GITHUB_PATH"
|
||||
- run: make site
|
||||
- run: cd build/site && zip -qr ../pass-web.zip .
|
||||
- name: Package web site and HTML5 app
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cd build/site
|
||||
zip -qr ../pass-web.zip .
|
||||
|
||||
mkdir -p ../pass-html5
|
||||
cp app/index.html ../pass-html5/
|
||||
cp app/app.js ../pass-html5/
|
||||
cp app/index.js ../pass-html5/
|
||||
cp app/index.wasm ../pass-html5/
|
||||
cp app/sw.js ../pass-html5/
|
||||
cp manifest.webmanifest ../pass-html5/
|
||||
cp -R icons ../pass-html5/icons
|
||||
sed -i \
|
||||
-e 's#href="/manifest.webmanifest"#href="manifest.webmanifest"#g' \
|
||||
-e 's#href="/icons/#href="icons/#g' \
|
||||
-e 's#src="/icons/#src="icons/#g' \
|
||||
../pass-html5/index.html
|
||||
python3 - <<'PY'
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
root = Path("../pass-html5")
|
||||
manifest = json.loads((root / "manifest.webmanifest").read_text())
|
||||
manifest["start_url"] = "."
|
||||
manifest["scope"] = "."
|
||||
for icon in manifest.get("icons", []):
|
||||
icon["src"] = icon.get("src", "").lstrip("/")
|
||||
(root / "manifest.webmanifest").write_text(json.dumps(manifest, indent=2) + "\n")
|
||||
|
||||
sw = (root / "sw.js").read_text()
|
||||
sw = sw.replace(
|
||||
"const appFiles = ['/app/', '/app/app.js', '/app/index.js', '/app/index.wasm', '/manifest.webmanifest', '/icons/icon-192.png', '/icons/icon-512.png'];",
|
||||
"const appFiles = ['.', 'app.js', 'index.js', 'index.wasm', 'manifest.webmanifest', 'icons/icon-192.png', 'icons/icon-512.png'];",
|
||||
)
|
||||
(root / "sw.js").write_text(sw)
|
||||
PY
|
||||
cd ../pass-html5
|
||||
zip -qr ../pass-html5.zip .
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: web
|
||||
path: build/pass-web.zip
|
||||
path: |
|
||||
build/pass-web.zip
|
||||
build/pass-html5.zip
|
||||
if-no-files-found: error
|
||||
|
||||
publish:
|
||||
@@ -203,7 +263,7 @@ jobs:
|
||||
name: Resolve release version
|
||||
run: |
|
||||
set -euo pipefail
|
||||
version=$(sed -n 's/^const Version = "\([^"]*\)"/\1/p' version.go)
|
||||
version=$(sed -n '1p' VERSION)
|
||||
test -n "$version"
|
||||
tag="v$version"
|
||||
echo "tag=$tag" >> "$GITHUB_OUTPUT"
|
||||
@@ -212,18 +272,11 @@ jobs:
|
||||
else
|
||||
echo "released=true" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
- name: Create release tag
|
||||
if: steps.version.outputs.released == 'true'
|
||||
run: |
|
||||
git config user.name github-actions[bot]
|
||||
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
||||
git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}"
|
||||
git push origin "${{ steps.version.outputs.tag }}"
|
||||
- name: Generate Update Appcast
|
||||
if: steps.version.outputs.released == 'true'
|
||||
run: |
|
||||
set -euo pipefail
|
||||
VERSION=$(sed -n 's/^const Version = "\([^"]*\)"/\1/p' version.go)
|
||||
VERSION=$(sed -n '1p' VERSION)
|
||||
TAG="v$VERSION"
|
||||
BASE="https://github.com/waozixyz/pass/releases/download/$TAG"
|
||||
# appcast channel names use dpkg arch naming (amd64/arm64);
|
||||
@@ -256,6 +309,20 @@ jobs:
|
||||
--changelog CHANGELOG.md \
|
||||
--out build/artifacts/appcast.json \
|
||||
"${channels[@]}"
|
||||
- name: Publish checksums
|
||||
if: steps.version.outputs.released == 'true'
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cd build/artifacts
|
||||
# The glob expands before the redirect creates SHA256SUMS itself.
|
||||
sha256sum -- * > SHA256SUMS
|
||||
- name: Create release tag
|
||||
if: steps.version.outputs.released == 'true'
|
||||
run: |
|
||||
git config user.name github-actions[bot]
|
||||
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
||||
git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}"
|
||||
git push origin "${{ steps.version.outputs.tag }}"
|
||||
- name: Publish GitHub release
|
||||
if: steps.version.outputs.released == 'true'
|
||||
uses: softprops/action-gh-release@v2
|
||||
@@ -263,3 +330,89 @@ jobs:
|
||||
tag_name: ${{ steps.version.outputs.tag }}
|
||||
generate_release_notes: true
|
||||
files: build/artifacts/*
|
||||
|
||||
publish-itch:
|
||||
name: Publish itch.io
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 45
|
||||
continue-on-error: true
|
||||
needs:
|
||||
- web
|
||||
- android
|
||||
- gui
|
||||
- publish
|
||||
if: needs.publish.outputs.released == 'true'
|
||||
env:
|
||||
BUTLER_API_KEY: ${{ secrets.ITCH_API_KEY }}
|
||||
|
||||
steps:
|
||||
- name: Check itch.io Secret
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ -z "${BUTLER_API_KEY:-}" ]; then
|
||||
echo "ITCH_API_KEY secret is required to publish itch.io"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Download Release Artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: build/artifacts
|
||||
merge-multiple: true
|
||||
|
||||
- name: Install Butler
|
||||
timeout-minutes: 15
|
||||
run: |
|
||||
set -euo pipefail
|
||||
curl -fsSL \
|
||||
https://broth.itch.zone/butler/linux-amd64/LATEST/archive/default \
|
||||
-o "$RUNNER_TEMP/butler.zip"
|
||||
mkdir -p "$RUNNER_TEMP/butler"
|
||||
unzip -q "$RUNNER_TEMP/butler.zip" -d "$RUNNER_TEMP/butler"
|
||||
chmod +x "$RUNNER_TEMP/butler/butler"
|
||||
echo "$RUNNER_TEMP/butler" >> "$GITHUB_PATH"
|
||||
|
||||
- name: Publish Release Builds to itch.io
|
||||
run: |
|
||||
set -euo pipefail
|
||||
VERSION="$(sed -n '1p' VERSION)"
|
||||
|
||||
html5_zip="build/artifacts/pass-html5.zip"
|
||||
android_apk="build/artifacts/pass-android.apk"
|
||||
linux_appimage="build/artifacts/pass-$VERSION-x86_64.AppImage"
|
||||
|
||||
test -f "$html5_zip"
|
||||
test -f "$android_apk"
|
||||
test -f "$linux_appimage"
|
||||
|
||||
butler_push() {
|
||||
target="$1"
|
||||
channel="$2"
|
||||
attempt=1
|
||||
log_file="$(mktemp)"
|
||||
|
||||
while [ "$attempt" -le 6 ]; do
|
||||
if butler push "$target" "waozi/pass:$channel" --userversion "$VERSION" 2>&1 | tee "$log_file"; then
|
||||
rm -f "$log_file"
|
||||
return 0
|
||||
fi
|
||||
if ! grep -q "latest build is still processing" "$log_file"; then
|
||||
rm -f "$log_file"
|
||||
return 1
|
||||
fi
|
||||
echo "itch.io channel $channel is still processing; retrying in 60s ($attempt/6)"
|
||||
sleep 60
|
||||
attempt=$((attempt + 1))
|
||||
done
|
||||
|
||||
rm -f "$log_file"
|
||||
echo "itch.io channel $channel was still processing after retries"
|
||||
return 1
|
||||
}
|
||||
|
||||
butler_push "$html5_zip" html5
|
||||
butler_push "$android_apk" android
|
||||
butler_push "$linux_appimage" linux
|
||||
@@ -1,4 +1,4 @@
|
||||
name: Netlify
|
||||
name: Cloudflare Pages
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -10,25 +10,42 @@ permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: netlify-${{ github.ref }}
|
||||
group: pages-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
guard-submodule-urls:
|
||||
name: Submodule URLs are public HTTPS
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Reject non-HTTPS submodule URLs
|
||||
run: scripts/check_submodule_urls.sh
|
||||
|
||||
build:
|
||||
needs: guard-submodule-urls
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.24.x
|
||||
cache: false
|
||||
submodules: recursive
|
||||
- name: Install Emscripten
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git clone --depth 1 https://github.com/emscripten-core/emsdk.git "$HOME/emsdk"
|
||||
"$HOME/emsdk/emsdk" install latest
|
||||
"$HOME/emsdk/emsdk" activate latest
|
||||
echo "EM_CONFIG=$HOME/emsdk/.emscripten" >> "$GITHUB_ENV"
|
||||
echo "$HOME/emsdk/upstream/emscripten" >> "$GITHUB_PATH"
|
||||
- name: Build Site
|
||||
run: |
|
||||
set -euo pipefail
|
||||
make site
|
||||
test -s build/site/index.html
|
||||
test -s build/site/app/index.html
|
||||
test -s build/site/app/pass.wasm
|
||||
test -s build/site/app/index.wasm
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: pass-site
|
||||
@@ -45,23 +62,12 @@ jobs:
|
||||
with:
|
||||
name: pass-site
|
||||
path: build/site
|
||||
- name: Install Netlify CLI
|
||||
run: npm install --global netlify-cli
|
||||
- name: Deploy Preview To Netlify
|
||||
run: |
|
||||
set -euo pipefail
|
||||
auth_token="$(printf '%s' "$NETLIFY_AUTH_TOKEN" | tr -d '\r\n')"
|
||||
site_id="$(printf '%s' "$NETLIFY_SITE_ID" | tr -d '\r\n')"
|
||||
netlify deploy \
|
||||
--dir build/site \
|
||||
--no-build \
|
||||
--alias "pr-${{ github.event.pull_request.number }}" \
|
||||
--message "Preview ${{ github.event.pull_request.number }}" \
|
||||
--auth "$auth_token" \
|
||||
--site "$site_id"
|
||||
env:
|
||||
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
||||
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
|
||||
- name: Deploy Preview To Cloudflare Pages
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: pages deploy build/site --project-name=pass --branch=${{ github.head_ref || github.ref_name }}
|
||||
|
||||
deploy-production:
|
||||
name: Deploy Production
|
||||
@@ -73,29 +79,9 @@ jobs:
|
||||
with:
|
||||
name: pass-site
|
||||
path: build/site
|
||||
- name: Package Site
|
||||
run: |
|
||||
set -euo pipefail
|
||||
test -s build/site/index.html
|
||||
cd build/site
|
||||
zip -qr ../pass-site.zip .
|
||||
test -s ../pass-site.zip
|
||||
- name: Deploy Production To Netlify
|
||||
run: |
|
||||
set -euo pipefail
|
||||
auth_token="$(printf '%s' "$NETLIFY_AUTH_TOKEN" | tr -d '\r\n')"
|
||||
site_id="$(printf '%s' "$NETLIFY_SITE_ID" | tr -d '\r\n')"
|
||||
test -n "$auth_token" || { echo "::error::NETLIFY_AUTH_TOKEN is empty or missing"; exit 1; }
|
||||
test -n "$site_id" || { echo "::error::NETLIFY_SITE_ID is empty or missing"; exit 1; }
|
||||
|
||||
response="$(curl --fail-with-body --silent --show-error \
|
||||
-X POST \
|
||||
-H "Authorization: Bearer $auth_token" \
|
||||
-H "Content-Type: application/zip" \
|
||||
--data-binary "@build/pass-site.zip" \
|
||||
"https://api.netlify.com/api/v1/sites/$site_id/deploys")"
|
||||
|
||||
python3 -c 'import json, sys; deploy = json.loads(sys.argv[1]); state = deploy.get("state", ""); url = deploy.get("ssl_url") or deploy.get("url") or deploy.get("deploy_ssl_url") or deploy.get("deploy_url") or deploy.get("id"); print(f"Netlify deploy {state}: {url}"); raise SystemExit(1 if state in ("error", "failed") else 0)' "$response"
|
||||
env:
|
||||
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
||||
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
|
||||
- name: Deploy Production To Cloudflare Pages
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: pages deploy build/site --project-name=pass --branch=master
|
||||
@@ -1,3 +1,2 @@
|
||||
/build/
|
||||
/pass
|
||||
/gui/pass-gui
|
||||
@@ -1,5 +1,65 @@
|
||||
# Changelog
|
||||
|
||||
## [0.2.9] - 2026-09-05
|
||||
|
||||
- Keep bottom navigation, password controls, and dialog icons readable with
|
||||
dark tints in light mode and light tints in dark mode.
|
||||
- Prevent taps in Theme Settings from reaching fields underneath or opening
|
||||
the keyboard when saving the theme.
|
||||
|
||||
## [0.2.8] - 2026-08-26
|
||||
|
||||
- Match LessPass clients for the same site, login, master password, counter,
|
||||
character classes, and length settings.
|
||||
- Limit password length to LessPass's 5 to 35 character range.
|
||||
- Require Android fingerprint unlock for saved master passwords and store them
|
||||
with an authenticated Android Keystore key.
|
||||
- Use the Sweet Material palette by default, with Sweet-Dark matched colors in
|
||||
dark mode, and show generated passwords in a dedicated output field.
|
||||
- Keep settings controls fully scrollable above the bottom navigation and use
|
||||
the available form width while scrolling.
|
||||
- Keep theme dropdowns from opening the Android soft keyboard.
|
||||
|
||||
## [0.2.7] - 2026-08-24
|
||||
|
||||
- Fix Android source builds in stricter environments such as F-Droid builders
|
||||
while keeping Kry app source generation automatic.
|
||||
|
||||
## [0.2.6] - 2026-08-24
|
||||
|
||||
- Keep Android source builds self-contained so F-Droid and other source builds
|
||||
generate the Kry app sources automatically.
|
||||
|
||||
## [0.2.5] - 2026-08-24
|
||||
|
||||
- Add Android appearance settings for following device colors, choosing
|
||||
light or dark mode, selecting a color palette, and switching widget style.
|
||||
- Use Android system Material colors for the app theme, with a stable Material
|
||||
fallback instead of the bright pink accent some devices report.
|
||||
- Recalculate the Android layout cleanly when rotating between portrait and
|
||||
landscape, keeping controls clear of system bars and navigation insets.
|
||||
|
||||
## [0.2.4] - 2026-08-22
|
||||
|
||||
- Save and reuse Android master-password defaults, with fingerprint unlock
|
||||
available from the generator and settings screens.
|
||||
- Clear unlocked master-password text and generated passwords from the Android
|
||||
screen after a short timeout.
|
||||
- Autosave Android generator defaults when length, counter, character classes,
|
||||
excluded characters, or biometric display settings change.
|
||||
- Keep Android form fields visible while the keyboard is open, with better
|
||||
spacing around settings and excluded-character controls.
|
||||
- Run the real Pass app at pass.waozi.xyz/app through the Kryon canvas UI,
|
||||
replacing the standalone browser form.
|
||||
- Publish Android releases as a universal APK plus per-ABI APKs.
|
||||
|
||||
## [0.2.3] - 2026-08-21
|
||||
|
||||
- Verify every download: releases now ship a SHA256SUMS file covering the
|
||||
command-line, desktop, Android, and browser downloads.
|
||||
- The Android app now builds entirely from source with no developer signing
|
||||
key, clearing the way for F-Droid distribution.
|
||||
|
||||
## [0.2.2] - 2026-08-20
|
||||
|
||||
- Install pass on Android: a signed APK is now downloadable from
|
||||
|
||||
@@ -1,22 +1,91 @@
|
||||
.PHONY: all cli gui native run test native-test web site install install-cli uninstall-cli install-gui uninstall-gui package-deb package-appimage android-debug
|
||||
.PHONY: all cli kry-c kry-c-plan9 gui native run test coverage native-test cli-test runtime-test lesspass-compat-test check-submodule-urls kry-smoke web web-canvas site web-smoke android-debug android-smoke android-input-test e2e install install-cli uninstall-cli install-gui uninstall-gui package-deb package-appimage
|
||||
|
||||
BIN_DIR ?= $(HOME)/bin
|
||||
DATA_DIR ?= $(if $(XDG_DATA_HOME),$(XDG_DATA_HOME),$(HOME)/.local/share)
|
||||
CC ?= cc
|
||||
|
||||
KRYON_ARCH ?= $(shell uname -m)
|
||||
KRYON_BUILD_DIR := vendor/kryon/build/linux-$(KRYON_ARCH)
|
||||
KRYON_RUNTIME_SOURCES := $(shell find vendor/kryon/src vendor/kryon/include -type f)
|
||||
K2C_SOURCES := $(shell find vendor/kryon/cmd/k2c vendor/kryon/cmd/kir -type f)
|
||||
KRY_APP_SRCS := $(shell find app -type f -name '*.kry' | LC_ALL=C sort)
|
||||
KRY_C_GENERATED_DIR := build/krygen/c
|
||||
KRY_C_STAMP := $(KRY_C_GENERATED_DIR)/.stamp
|
||||
KRY_C_APP_SRCS := $(KRY_C_GENERATED_DIR)/app/nav.c $(KRY_C_GENERATED_DIR)/app/pass.c $(KRY_C_GENERATED_DIR)/app/profiles.c $(KRY_C_GENERATED_DIR)/app/settings.c
|
||||
K2C := $(KRYON_BUILD_DIR)/bin/k2c
|
||||
PASS_VERSION := $(shell sed -n '1p' VERSION)
|
||||
WEB_EMSDK_BIN ?= $(HOME)/emsdk/upstream/emscripten
|
||||
WEB_CC ?= $(if $(wildcard $(WEB_EMSDK_BIN)/emcc),$(WEB_EMSDK_BIN)/emcc,emcc)
|
||||
ifneq ($(wildcard $(WEB_EMSDK_BIN)/emcc),)
|
||||
export PATH := $(WEB_EMSDK_BIN):$(PATH)
|
||||
endif
|
||||
WEB_APP_BUILD_DIR := build/web-app
|
||||
WEB_APP_TARGET := $(WEB_APP_BUILD_DIR)/index.html
|
||||
WEB_APP_EMBEDDED_ASSETS_C := build/web/pass_embedded_assets.c
|
||||
WEB_APP_ASSETS := vendor/kryon/fonts/noto/NotoSans-Regular.ttf assets/fonts/emoji.ttf
|
||||
KRYON_ICON_ASSETS_C := vendor/kryon/src/ui/ui_icon_assets.c
|
||||
KRYON_WEB_SRCS_ALL := $(filter-out $(KRYON_ICON_ASSETS_C),$(shell find vendor/kryon/src -type f -name '*.c' | LC_ALL=C sort)) $(KRYON_ICON_ASSETS_C)
|
||||
KRYON_WEB_SRCS := $(filter-out vendor/kryon/src/backend/dom_% vendor/kryon/src/backend/libdraw_% vendor/kryon/src/backend/termi_% vendor/kryon/src/file_dialog/file_dialog.c vendor/kryon/src/ksync/% vendor/kryon/src/runtime_assets/% vendor/kryon/src/notification/% vendor/kryon/src/platform/plan9/% vendor/kryon/src/scene/physics_world.c vendor/kryon/src/scene/node_body2d.c vendor/kryon/src/scene/node_area2d.c vendor/kryon/src/scene/node_collision_shape2d.c,$(KRYON_WEB_SRCS_ALL))
|
||||
PASS_WEB_SRCS := droid/app/src/main/cpp/main.c native/pass_core.c native/pass_runtime.c $(KRY_C_APP_SRCS) $(WEB_APP_EMBEDDED_ASSETS_C)
|
||||
WEB_CFLAGS := -Wall -Wextra -std=gnu99 -Os -DPLATFORM_WEB -DGRAPHICS_API_OPENGL_ES2 -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DUI_EMBEDDED_ONLY=1 -DKRYON_WITH_PHYSICS=0 -Ivendor/kryon/include -Ivendor/kryon/src -I$(KRY_C_GENERATED_DIR) -Inative -Idroid/app/src/main/cpp
|
||||
WEB_LDFLAGS := -sASYNCIFY -sASYNCIFY_STACK_SIZE=1048576 -sFORCE_FILESYSTEM=1 -sFETCH=1 -sALLOW_MEMORY_GROWTH=1 -sINITIAL_MEMORY=134217728 -sSTACK_SIZE=16777216 -lidbfs.js -lm
|
||||
GUI_CFLAGS := -Wall -Wextra -std=gnu99 -O2 -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DUI_EMBEDDED_ONLY=1 -DKRYON_WITH_PHYSICS=0 -Ivendor/kryon/include -Ivendor/kryon/src -I$(KRY_C_GENERATED_DIR) -Inative -Idroid/app/src/main/cpp $(shell pkg-config --cflags sdl2 gtk+-3.0 2>/dev/null)
|
||||
GUI_LDLIBS := $(shell pkg-config --libs sdl2 2>/dev/null) $(shell pkg-config --libs libdrm gbm egl glesv2 2>/dev/null) $(shell pkg-config --libs gtk+-3.0 gio-2.0 glib-2.0 2>/dev/null) -ldl -lpthread -lm
|
||||
KRYON_STATIC_LIBS := $(KRYON_BUILD_DIR)/libkryon.a $(KRYON_BUILD_DIR)/raylib/libraylib.a
|
||||
|
||||
all: cli gui
|
||||
|
||||
cli:
|
||||
go build -o pass ./cmd/pass
|
||||
cli: build/pass
|
||||
cp build/pass pass
|
||||
|
||||
build/pass: native/pass_cli.c native/pass_core.c native/pass_core.h | build
|
||||
$(CC) -Wall -Wextra -O2 -std=gnu99 -Inative -DPASS_VERSION=\"$(PASS_VERSION)\" native/pass_cli.c native/pass_core.c -o $@
|
||||
|
||||
build build/gui:
|
||||
mkdir -p $@
|
||||
|
||||
$(KRYON_BUILD_DIR)/libkryon.a: $(KRYON_RUNTIME_SOURCES) vendor/kryon/Makefile
|
||||
$(MAKE) -C vendor/kryon -f Makefile all
|
||||
|
||||
gui: $(KRYON_BUILD_DIR)/libkryon.a
|
||||
cd gui && go build -o ../build/pass-gui .
|
||||
$(K2C): $(K2C_SOURCES) vendor/kryon/Makefile
|
||||
$(MAKE) -C vendor/kryon -f Makefile k2c
|
||||
|
||||
kry-c: $(KRY_C_STAMP)
|
||||
|
||||
$(KRY_C_STAMP): $(K2C) $(KRY_APP_SRCS) | build
|
||||
rm -rf $(KRY_C_GENERATED_DIR)
|
||||
mkdir -p $(KRY_C_GENERATED_DIR)
|
||||
$(K2C) --no-main --root . -o $(KRY_C_GENERATED_DIR) $(KRY_APP_SRCS)
|
||||
touch $@
|
||||
|
||||
PLAN9_DIR := build/plan9
|
||||
PLAN9_GENERATED := $(PLAN9_DIR)/generated
|
||||
PLAN9_FILE_LIST := $(PLAN9_DIR)/generated-c-files.txt
|
||||
PLAN9_EMBEDDED_ASSETS_C := $(PLAN9_DIR)/pass_embedded_assets.c
|
||||
PLAN9_ASSETS := vendor/kryon/fonts/noto/NotoSans-Regular.ttf assets/fonts/emoji.ttf
|
||||
|
||||
# Native Plan 9 build inputs: k2c emits 8c-safe C directly, the embedded
|
||||
# table carries the two fonts, and the file list feeds the mkfile.
|
||||
kry-c-plan9: kry-c
|
||||
rm -rf $(PLAN9_GENERATED)
|
||||
$(K2C) --no-main --plan9 --root . \
|
||||
--include-dir vendor/kryon/include --include-dir native \
|
||||
--include-dir droid/app/src/main/cpp \
|
||||
-o $(PLAN9_GENERATED) $(KRY_APP_SRCS)
|
||||
find $(PLAN9_GENERATED) -type f -name '*.c' | LC_ALL=C sort > $(PLAN9_FILE_LIST)
|
||||
sh vendor/kryon/scripts/embed-assets.sh $(PLAN9_EMBEDDED_ASSETS_C) $(PLAN9_ASSETS)
|
||||
|
||||
gui: build/pass-gui
|
||||
|
||||
build/pass-gui: $(KRYON_BUILD_DIR)/libkryon.a $(KRY_C_STAMP) droid/app/src/main/cpp/main.c native/pass_core.c native/pass_runtime.c native/pass_runtime.h | build
|
||||
$(CC) $(GUI_CFLAGS) -o $@ \
|
||||
droid/app/src/main/cpp/main.c \
|
||||
native/pass_core.c \
|
||||
native/pass_runtime.c \
|
||||
$(KRY_C_APP_SRCS) \
|
||||
-Wl,-export-dynamic \
|
||||
$(KRYON_STATIC_LIBS) \
|
||||
$(GUI_LDLIBS)
|
||||
|
||||
native: all
|
||||
|
||||
@@ -42,29 +111,96 @@ uninstall-gui:
|
||||
rm -f $(BIN_DIR)/pass-gui $(DATA_DIR)/applications/xyz.waozi.pass.desktop $(DATA_DIR)/icons/hicolor/512x512/apps/pass.png
|
||||
|
||||
test:
|
||||
go test ./...
|
||||
cd gui && go test ./...
|
||||
$(MAKE) native-test cli-test runtime-test lesspass-compat-test kry-smoke
|
||||
|
||||
# Checks the C generator (used by the Android app) against the same fixed
|
||||
# vectors as the Go tests.
|
||||
coverage:
|
||||
mkdir -p build/coverage
|
||||
rm -f build/coverage/*.gcda build/coverage/*.gcno build/coverage/*.gcov *.gcov
|
||||
$(CC) --coverage -O0 -g -Wall -Wextra -std=gnu99 -Inative -c native/pass_core.c -o build/coverage/pass_core.o
|
||||
$(CC) --coverage -O0 -g -Wall -Wextra -std=gnu99 -Inative -c native/pass_core_test.c -o build/coverage/pass_core_test.o
|
||||
$(CC) --coverage build/coverage/pass_core.o build/coverage/pass_core_test.o -o build/coverage/pass_core_test
|
||||
./build/coverage/pass_core_test
|
||||
$(CC) --coverage -O0 -g -Wall -Wextra -std=gnu99 -Inative -DPASS_VERSION=\"$(PASS_VERSION)\" -c native/pass_cli.c -o build/coverage/pass_cli.o
|
||||
$(CC) --coverage build/coverage/pass_cli.o build/coverage/pass_core.o -o build/coverage/pass_cli
|
||||
sh scripts/cli_test.sh build/coverage/pass_cli
|
||||
$(CC) --coverage -O0 -g -Wall -Wextra -std=gnu99 -Inative -Idroid/app/src/main/cpp -Ivendor/kryon/include -c native/pass_runtime.c -o build/coverage/pass_runtime.o
|
||||
$(CC) --coverage -O0 -g -Wall -Wextra -std=gnu99 -Ivendor/kryon/include -c vendor/kryon/src/core/app_storage.c -o build/coverage/app_storage.o
|
||||
$(CC) --coverage -O0 -g -Wall -Wextra -std=gnu99 -Ivendor/kryon/include -c vendor/kryon/src/kry_std/kry_filesystem.c -o build/coverage/kry_filesystem.o
|
||||
$(CC) --coverage -O0 -g -Wall -Wextra -std=gnu99 -Inative -Idroid/app/src/main/cpp -Ivendor/kryon/include -c native/pass_runtime_test.c -o build/coverage/pass_runtime_test.o
|
||||
$(CC) --coverage build/coverage/pass_runtime.o build/coverage/pass_runtime_test.o build/coverage/pass_core.o build/coverage/app_storage.o build/coverage/kry_filesystem.o -o build/coverage/pass_runtime_test
|
||||
./build/coverage/pass_runtime_test
|
||||
for data in build/coverage/*.gcda; do gcov -b -c "$$data"; done
|
||||
mv *.gcov build/coverage/
|
||||
|
||||
# Checks the C generator used by the CLI and every Kry app target.
|
||||
native-test:
|
||||
mkdir -p build
|
||||
cc -Wall -Wextra -O2 -Inative native/pass_core.c native/pass_core_test.c -o build/pass_core_test
|
||||
./build/pass_core_test
|
||||
|
||||
cli-test: cli
|
||||
test "$$(./pass lesspass.com [email protected] password)" = '\g-A1-.OHEwrXjT#'
|
||||
test "$$(./pass --length 20 --counter 2 service.test [email protected] master)" = 'j:x_Lo5b1XL_j0we%z`e'
|
||||
sh scripts/cli_test.sh ./pass
|
||||
|
||||
runtime-test:
|
||||
mkdir -p build
|
||||
$(CC) -Wall -Wextra -O2 -std=gnu99 -Inative -Idroid/app/src/main/cpp -Ivendor/kryon/include native/pass_runtime.c native/pass_core.c vendor/kryon/src/core/app_storage.c vendor/kryon/src/kry_std/kry_filesystem.c native/pass_runtime_test.c -o build/pass_runtime_test
|
||||
./build/pass_runtime_test
|
||||
|
||||
lesspass-compat-test: cli
|
||||
python3 scripts/lesspass_compat_test.py --cli ./pass
|
||||
|
||||
check-submodule-urls:
|
||||
bash scripts/check_submodule_urls.sh
|
||||
|
||||
kry-smoke:
|
||||
sh scripts/kry_smoke.sh
|
||||
|
||||
ANDROID_DIR := droid
|
||||
ANDROID_ABIS ?= armeabi-v7a,arm64-v8a
|
||||
|
||||
android-debug:
|
||||
cd $(ANDROID_DIR) && ./gradlew assembleDebug -Pabi=$(ANDROID_ABIS)
|
||||
android-debug: kry-c
|
||||
cd $(ANDROID_DIR) && ./gradlew assembleDebug -Pabi=$(ANDROID_ABIS) -PsplitApks=true
|
||||
mkdir -p build
|
||||
cp $(ANDROID_DIR)/app/build/outputs/apk/debug/app-debug.apk build/pass-android-debug.apk
|
||||
cp $(ANDROID_DIR)/app/build/outputs/apk/debug/app-universal-debug.apk build/pass-android-debug.apk
|
||||
cp $(ANDROID_DIR)/app/build/outputs/apk/debug/app-arm64-v8a-debug.apk build/pass-android-arm64-v8a-debug.apk
|
||||
cp $(ANDROID_DIR)/app/build/outputs/apk/debug/app-armeabi-v7a-debug.apk build/pass-android-armeabi-v7a-debug.apk
|
||||
|
||||
android-smoke: android-debug
|
||||
bash scripts/android_smoke.sh
|
||||
|
||||
android-input-test: kry-c
|
||||
cd $(ANDROID_DIR) && ./gradlew connectedDebugAndroidTest -Pabi=x86_64 -PsplitApks=false
|
||||
|
||||
web:
|
||||
./web/build.sh
|
||||
|
||||
web-canvas: $(WEB_APP_TARGET)
|
||||
|
||||
$(WEB_APP_BUILD_DIR) build/web:
|
||||
mkdir -p $@
|
||||
|
||||
$(WEB_APP_EMBEDDED_ASSETS_C): $(WEB_APP_ASSETS) vendor/kryon/scripts/embed-assets.sh | build/web
|
||||
sh vendor/kryon/scripts/embed-assets.sh $@ $(WEB_APP_ASSETS)
|
||||
|
||||
$(WEB_APP_TARGET): Makefile $(KRY_C_STAMP) $(PASS_WEB_SRCS) $(KRYON_WEB_SRCS) web/site/app/index.html web/site/app/app.js | $(WEB_APP_BUILD_DIR)
|
||||
$(WEB_CC) $(WEB_CFLAGS) \
|
||||
-o $(WEB_APP_BUILD_DIR)/index.js \
|
||||
$(PASS_WEB_SRCS) \
|
||||
$(KRYON_WEB_SRCS) \
|
||||
$(WEB_LDFLAGS)
|
||||
cp web/site/app/index.html $(WEB_APP_TARGET)
|
||||
cp web/site/app/app.js $(WEB_APP_BUILD_DIR)/app.js
|
||||
|
||||
site: web
|
||||
test -f build/site/index.html
|
||||
test -f build/site/app/pass.wasm
|
||||
test -f build/site/app/index.wasm
|
||||
|
||||
web-smoke: site
|
||||
bash scripts/web_smoke.sh
|
||||
|
||||
e2e: check-submodule-urls test native-test gui web-canvas site web-smoke android-debug android-smoke
|
||||
|
||||
package-deb: gui
|
||||
./scripts/package-deb.sh
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
# pass
|
||||
<p align="center">
|
||||
<img src="assets/app/readme-banner.png" alt="Pass" width="100%">
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://f-droid.org/packages/xyz.waozi.pass/">
|
||||
<img src="assets/app/badge-f-droid.png" alt="Get it on F-Droid" height="56">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
# Pass
|
||||
|
||||
Website and browser app: [pass.waozi.xyz](https://pass.waozi.xyz/)
|
||||
|
||||
`pass` is a stateless password generator: the same site, login, master
|
||||
Pass is a stateless password generator: the same site, login, master
|
||||
password, and settings produce the same result without a password database.
|
||||
It is a new, independently written implementation of the LessPass generation
|
||||
algorithm. Compatibility does not imply endorsement by or affiliation with the
|
||||
@@ -11,18 +21,11 @@ LessPass project.
|
||||
## Install
|
||||
|
||||
Prebuilt CLI and desktop downloads are available from
|
||||
[pass.waozi.xyz](https://pass.waozi.xyz/#downloads).
|
||||
|
||||
With Go 1.24 or newer:
|
||||
[pass.waozi.xyz](https://pass.waozi.xyz/#downloads). To build from a checkout:
|
||||
|
||||
```sh
|
||||
go install github.com/waozixyz/pass/cmd/pass@latest
|
||||
```
|
||||
|
||||
Or build the command from a checkout:
|
||||
|
||||
```sh
|
||||
go build ./cmd/pass
|
||||
git submodule update --init --recursive
|
||||
make cli
|
||||
```
|
||||
|
||||
## Use
|
||||
@@ -32,13 +35,13 @@ pass [OPTIONS] SITE LOGIN [MASTER_PASSWORD]
|
||||
```
|
||||
|
||||
The default password has 16 characters and includes lowercase letters,
|
||||
uppercase letters, digits, and symbols. The default counter is 1.
|
||||
uppercase letters, digits, and symbols. Length must be between 5 and 35,
|
||||
matching LessPass clients. The default counter is 1.
|
||||
|
||||
Passing a master password as an argument can expose it to process inspection
|
||||
and shell history. Omitting it is safer: `pass` first checks
|
||||
`LESSPASS_MASTER_PASSWORD`, then reads from the controlling terminal or console
|
||||
with echo disabled. Use `--prompt` to bypass the environment and always ask. For
|
||||
example:
|
||||
`LESSPASS_MASTER_PASSWORD`, then reads one line from standard input. Use
|
||||
`--prompt` to bypass the environment and read from standard input. For example:
|
||||
|
||||
```sh
|
||||
pass --prompt example.com alice
|
||||
@@ -46,62 +49,18 @@ pass --length 24 --counter 2 example.com alice
|
||||
pass --no-symbols --exclude '0O1Il' example.com alice
|
||||
```
|
||||
|
||||
`--copy` sends the result to the clipboard without printing it. On Linux a
|
||||
built-in pure-Go X11 clipboard is used when an X server (X.Org, Xlibre, or
|
||||
XWayland) is reachable, so no external tool is needed; otherwise `pass`
|
||||
falls back to `wl-copy`, `xclip`, `xsel`, `pbcopy`, or `clip.exe` and reports
|
||||
an error if none can be used. The copied password is served by a small
|
||||
detached process and disappears when another application takes the clipboard;
|
||||
`--clear-after 90s` releases it automatically after a delay (built-in X11
|
||||
clipboard only), and `--read-clipboard` prints the current contents.
|
||||
|
||||
## Profiles
|
||||
|
||||
An optional configuration file at `$XDG_CONFIG_HOME/pass/profiles.json`
|
||||
(usually `~/.config/pass/profiles.json`) can store named profiles — a login
|
||||
plus default settings — so daily invocations shrink to one flag:
|
||||
|
||||
```sh
|
||||
pass --profile work example.com
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"vault": "~/.vault",
|
||||
"copy": true,
|
||||
"clear_after": "90s",
|
||||
"profiles": {
|
||||
"work": {"login": "alice", "counter": 9, "length": 23, "symbols": false}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Profiles hold no secrets. Command-line flags always win over profile values,
|
||||
and without a configuration file pass behaves exactly as before.
|
||||
|
||||
## Master password from a vault
|
||||
|
||||
`--vault PATH` reads the master password from a file encrypted with OpenSSL:
|
||||
|
||||
```sh
|
||||
printf 'master password' | openssl enc -aes-256-cbc -md sha512 -a \
|
||||
-pbkdf2 -iter 100000 -salt -pass pass:... > ~/.vault
|
||||
pass --vault ~/.vault example.com alice
|
||||
```
|
||||
|
||||
The vault passphrase is requested on the terminal with echo disabled, or read
|
||||
from piped standard input, and the decrypted contents are used as the master
|
||||
password — the master itself never appears in argv or the environment. The
|
||||
vault path can also be set once in the profiles file.
|
||||
Clipboard copying, profile storage, settings, and Android fingerprint unlock
|
||||
live in the Kry app runtime. The C CLI stays stateless and prints the generated
|
||||
password.
|
||||
|
||||
Run `pass --help` for all flags.
|
||||
|
||||
## Desktop app
|
||||
|
||||
The optional desktop app is written in Go with Kryon and calls the same
|
||||
generator package directly. It keeps the master password in process memory,
|
||||
masks the master-password field, and clears copied passwords after 20 seconds
|
||||
unless the clipboard has since been replaced.
|
||||
The desktop, Android, and browser apps are written in Kry and compiled with
|
||||
Kryon's `k2c` compiler to C. They share `native/pass_core.c` for password
|
||||
generation and `native/pass_runtime.c` for app storage, clipboard, and platform
|
||||
hooks.
|
||||
|
||||
```sh
|
||||
git submodule update --init --recursive
|
||||
@@ -109,18 +68,26 @@ make gui
|
||||
./build/pass-gui
|
||||
```
|
||||
|
||||
## Library
|
||||
## Android
|
||||
|
||||
```go
|
||||
settings := pass.DefaultOptions()
|
||||
result, err := pass.Generate("example.com", "alice", master, settings)
|
||||
The Android app runs on Android 5.0 (API 21) and newer. Install the signed
|
||||
APK (`pass-android.apk`) from [pass.waozi.xyz](https://pass.waozi.xyz/#downloads)
|
||||
or the [releases page](https://github.com/waozixyz/pass/releases/latest). It
|
||||
uses the same generation algorithm as the desktop app, computes everything
|
||||
locally, and declares no Internet permission at all. The only permissions it
|
||||
requests are for the optional fingerprint unlock.
|
||||
|
||||
## Source Layout
|
||||
|
||||
The app has one UI implementation:
|
||||
|
||||
```text
|
||||
app/*.kry -> k2c -> generated C -> desktop / Android / web
|
||||
native/pass_core.c -> password derivation
|
||||
native/pass_runtime.c -> app-facing runtime externs
|
||||
native/pass_cli.c -> command-line frontend
|
||||
```
|
||||
|
||||
All inputs are interpreted as UTF-8 strings. Excluded characters are removed
|
||||
from every enabled character class; generation fails if a class becomes empty,
|
||||
all classes are disabled, or the requested length cannot include one character
|
||||
from each class.
|
||||
|
||||
## License
|
||||
|
||||
Copyright © 2026 Waozi. Distributed under the BSD 3-Clause License. See
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
#import "kryon.h"
|
||||
|
||||
state {
|
||||
nav_icons_loaded: int = 0
|
||||
nav_generate_icon: Texture2D
|
||||
nav_profiles_icon: Texture2D
|
||||
nav_settings_icon: Texture2D
|
||||
}
|
||||
|
||||
nav_load_icons :: () #private {
|
||||
if nav_icons_loaded == 1 {
|
||||
return
|
||||
}
|
||||
|
||||
nav_generate_icon = LoadUIIconTexture(UI_ICON_TYPE_HOME)
|
||||
nav_profiles_icon = LoadUIIconTexture(UI_ICON_TYPE_PROFILE)
|
||||
nav_settings_icon = LoadUIIconTexture(UI_ICON_TYPE_GEAR)
|
||||
nav_icons_loaded = 1
|
||||
}
|
||||
|
||||
nav_draw :: (x: int, y: int, width: int, height: int, view: int*) {
|
||||
nav_load_icons()
|
||||
|
||||
generate_active: int = 0
|
||||
profiles_active: int = 0
|
||||
settings_active: int = 0
|
||||
if *view == 0 {
|
||||
generate_active = 1
|
||||
}
|
||||
if *view == 1 {
|
||||
profiles_active = 1
|
||||
}
|
||||
if *view == 2 {
|
||||
settings_active = 1
|
||||
}
|
||||
|
||||
items: [3] BottomNavItem = {
|
||||
{0, "Generate", nav_generate_icon, generate_active, 0},
|
||||
{1, "Profiles", nav_profiles_icon, profiles_active, 0},
|
||||
{2, "Settings", nav_settings_icon, settings_active, 0}
|
||||
}
|
||||
|
||||
result := BottomNav((BottomNavProps){
|
||||
.view_width = GetFrameWidth(),
|
||||
.view_height = GetFrameHeight(),
|
||||
.count = 3,
|
||||
.items = items,
|
||||
.height = height,
|
||||
.icon_size = ScaleUIPx(22),
|
||||
.icon_padding = ScaleUIPx(8),
|
||||
.side_margin = x,
|
||||
.bottom_margin = GetFrameHeight() - y - height,
|
||||
.max_button_width = width / 3,
|
||||
.icon_color = GetThemeText()
|
||||
})
|
||||
|
||||
if result.clicked_route >= 0 {
|
||||
*view = result.clicked_route
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,404 @@
|
||||
#import "kryon.h"
|
||||
#import "android_host.h"
|
||||
#import "app/nav"
|
||||
#import "app/profiles"
|
||||
#import "app/settings"
|
||||
|
||||
pass_generate :: (site: const char*, login: const char*, master: const char*, length: int, counter: int, lower: int, upper: int, digits: int, symbols: int, exclude: const char*) -> int #extern "pass_generate"
|
||||
pass_generated :: () -> char* #extern "pass_generated"
|
||||
pass_status :: () -> char* #extern "pass_status"
|
||||
pass_copy :: () -> int #extern "pass_copy"
|
||||
pass_master_emoji :: (master: const char*) -> char* #extern "pass_master_emoji"
|
||||
pass_save_profile :: (name: const char*, site: const char*, login: const char*, length: int, counter: int, lower: int, upper: int, digits: int, symbols: int, exclude: const char*) -> int #extern "pass_save_profile"
|
||||
pass_take_unlocked_master :: (out: char*) -> int #extern "pass_take_unlocked_master"
|
||||
pass_unlock_master :: () -> int #extern "pass_unlock_master"
|
||||
pass_load_settings :: (auto_copy: int*, clear_seconds: int*, show_fingerprint: int*, length: int*, counter: int*, lower: int*, upper: int*, digits: int*, symbols: int*, exclude: char*, exclude_size: int, theme_source: int*, theme_mode: int*, theme_id: int*, theme_style: int*) -> int #extern "pass_load_settings"
|
||||
AndroidHostLeftReserved :: () -> int #extern "AndroidHostLeftReserved"
|
||||
AndroidHostTopReserved :: () -> int #extern "AndroidHostTopReserved"
|
||||
AndroidHostRightReserved :: () -> int #extern "AndroidHostRightReserved"
|
||||
AndroidHostBottomReserved :: () -> int #extern "AndroidHostBottomReserved"
|
||||
AndroidSecureStoreBiometricAvailable :: () -> int #extern "AndroidSecureStoreBiometricAvailable"
|
||||
AndroidSecureStoreHasSecret :: (key: const char*) -> int #extern "AndroidSecureStoreHasSecret"
|
||||
AndroidSecureStoreSecretUsesBiometric :: (key: const char*) -> int #extern "AndroidSecureStoreSecretUsesBiometric"
|
||||
|
||||
ViewMode :: enum {
|
||||
VIEW_GENERATE = 0,
|
||||
VIEW_PROFILES,
|
||||
VIEW_SETTINGS
|
||||
}
|
||||
|
||||
state {
|
||||
view: int = VIEW_GENERATE
|
||||
|
||||
site: [256] char = ""
|
||||
site_cursor: int = 0
|
||||
login: [256] char = ""
|
||||
login_cursor: int = 0
|
||||
master: [1024] char = ""
|
||||
master_cursor: int = 0
|
||||
exclude: [128] char = ""
|
||||
exclude_cursor: int = 0
|
||||
profile_name: [64] char = ""
|
||||
profile_name_cursor: int = 0
|
||||
|
||||
length: int = 16
|
||||
counter: int = 1
|
||||
lower: int = 1
|
||||
upper: int = 1
|
||||
digits: int = 1
|
||||
symbols: int = 1
|
||||
reveal_master: int = 0
|
||||
|
||||
auto_copy: int = 0
|
||||
clear_seconds: int = 20
|
||||
show_fingerprint: int = 1
|
||||
theme_source: int = THEME_SOURCE_APP
|
||||
theme_mode: int = THEME_MODE_SYSTEM
|
||||
theme_id: int = THEME_SWEET
|
||||
theme_style: int = THEME_STYLE_MATERIAL
|
||||
theme_menu_state: UIThemeSettingsState
|
||||
|
||||
pass_icons_loaded: int = 0
|
||||
pass_settings_loaded: int = 0
|
||||
pass_fingerprint_icon: Texture2D
|
||||
pass_eye_icon: Texture2D
|
||||
pass_eye_off_icon: Texture2D
|
||||
generate_scroll: int = 0
|
||||
profiles_scroll: int = 0
|
||||
settings_scroll: int = 0
|
||||
pass_focused_rect_valid: int = 0
|
||||
pass_focused_rect: Rectangle
|
||||
pass_visible_focus_id: int = 0
|
||||
pass_scroll_to_generated: int = 0
|
||||
}
|
||||
|
||||
app "Pass" {
|
||||
size 390 740
|
||||
fps 60
|
||||
}
|
||||
|
||||
pass_apply_theme :: () #private {
|
||||
if theme_source < THEME_SOURCE_APP {
|
||||
theme_source = THEME_SOURCE_APP
|
||||
}
|
||||
if theme_source > THEME_SOURCE_SYSTEM {
|
||||
theme_source = THEME_SOURCE_SYSTEM
|
||||
}
|
||||
if theme_mode < THEME_MODE_SYSTEM {
|
||||
theme_mode = THEME_MODE_SYSTEM
|
||||
}
|
||||
if theme_mode > THEME_MODE_DARK {
|
||||
theme_mode = THEME_MODE_DARK
|
||||
}
|
||||
if theme_style < THEME_STYLE_SYSTEM {
|
||||
theme_style = THEME_STYLE_SYSTEM
|
||||
}
|
||||
if theme_style > THEME_STYLE_MATERIAL {
|
||||
theme_style = THEME_STYLE_MATERIAL
|
||||
}
|
||||
if theme_id < 0 {
|
||||
theme_id = 0
|
||||
}
|
||||
if theme_id >= THEME_COUNT {
|
||||
theme_id = THEME_COUNT - 1
|
||||
}
|
||||
|
||||
dark: int = 0
|
||||
if theme_mode == THEME_MODE_DARK {
|
||||
dark = 1
|
||||
} else if theme_mode == THEME_MODE_SYSTEM {
|
||||
if SystemThemePrefersDark() {
|
||||
dark = 1
|
||||
}
|
||||
}
|
||||
|
||||
SetThemeSource((ThemeSource)theme_source)
|
||||
SetThemeMode((ThemeMode)theme_mode)
|
||||
SetThemeStyle((ThemeStyle)theme_style)
|
||||
SetCurrentTheme(theme_id, dark)
|
||||
}
|
||||
|
||||
pass_can_unlock_master :: () -> int #private {
|
||||
return AndroidSecureStoreHasSecret("default") &&
|
||||
AndroidSecureStoreSecretUsesBiometric("default") &&
|
||||
AndroidSecureStoreBiometricAvailable()
|
||||
}
|
||||
|
||||
pass_load_icons :: () #private {
|
||||
if pass_icons_loaded == 1 {
|
||||
return
|
||||
}
|
||||
|
||||
pass_fingerprint_icon = LoadUIIconTexture(UI_ICON_TYPE_FINGERPRINT)
|
||||
pass_eye_icon = LoadUIIconTexture(UI_ICON_TYPE_EYE)
|
||||
pass_eye_off_icon = LoadUIIconTexture(UI_ICON_TYPE_EYE_OFF)
|
||||
pass_icons_loaded = 1
|
||||
}
|
||||
|
||||
pass_load_saved_settings :: () #private {
|
||||
if pass_settings_loaded == 1 {
|
||||
return
|
||||
}
|
||||
|
||||
pass_load_settings(&auto_copy, &clear_seconds, &show_fingerprint, &length, &counter, &lower, &upper, &digits, &symbols, exclude, sizeof(exclude), &theme_source, &theme_mode, &theme_id, &theme_style)
|
||||
pass_settings_loaded = 1
|
||||
}
|
||||
|
||||
pass_generate_content_height :: () -> int #private {
|
||||
return ScaleUIPx(820)
|
||||
}
|
||||
|
||||
pass_draw_master_emoji :: (x: int, y: int, master_text: [1024] char, enabled: int) -> int #private {
|
||||
if enabled == 0 {
|
||||
return 0
|
||||
}
|
||||
if master_text[0] == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
font_token: int = PushUIFont("pass-emoji")
|
||||
Text(pass_master_emoji(master_text), x, y, Text20, GetThemeIcon())
|
||||
PopUIFont(font_token)
|
||||
return ScaleUIPx(32)
|
||||
}
|
||||
|
||||
pass_draw_generated_output :: (x: int, y: int, width: int) #private {
|
||||
bounds := (Rectangle){x, y, width, ScaleUIPx(54)}
|
||||
inner := (Rectangle){x + ScaleUIPx(14), y + ScaleUIPx(9), width - ScaleUIPx(28), ScaleUIPx(36)}
|
||||
output: char* = pass_generated()
|
||||
border: Color = Fade(GetThemeIcon(), 0.30f)
|
||||
fill: Color = GetThemeSurface()
|
||||
|
||||
DrawRectangleRounded(bounds, 0.12f, 10, fill)
|
||||
DrawRectangleRoundedLinesEx(bounds, 0.12f, 10, ScaleUIPx(1), border)
|
||||
if output[0] == 0 {
|
||||
TextInRect("Password will appear here", inner, Text16, Fade(GetThemeText(), 0.54f))
|
||||
} else {
|
||||
TextInRect(output, inner, Text16, GetThemeText())
|
||||
}
|
||||
}
|
||||
|
||||
pass_request_focused_input_visible :: (focus_id: int, bounds: Rectangle) #private {
|
||||
if IsUIFocusActive(focus_id) == 0 {
|
||||
if pass_visible_focus_id == focus_id {
|
||||
pass_visible_focus_id = 0
|
||||
}
|
||||
return
|
||||
}
|
||||
if pass_visible_focus_id == focus_id {
|
||||
return
|
||||
}
|
||||
|
||||
pass_visible_focus_id = focus_id
|
||||
pass_request_rect_visible(bounds)
|
||||
}
|
||||
|
||||
pass_request_rect_visible :: (bounds: Rectangle) #private {
|
||||
pass_focused_rect = bounds
|
||||
pass_focused_rect_valid = 1
|
||||
}
|
||||
|
||||
pass_ensure_focused_input_visible :: (area: UIScrollArea) #private {
|
||||
if pass_focused_rect_valid == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
EnsureUIScrollRectVisible(area, pass_focused_rect, ScaleUIPx(24))
|
||||
pass_focused_rect_valid = 0
|
||||
}
|
||||
|
||||
pass_draw_generate :: (pad: int, y: int, content_w: int) -> int #private {
|
||||
Text("Site", pad, y, Text14, GetThemeText())
|
||||
TextField((TextFieldProps){.bounds = {pad, y + ScaleUIPx(22), content_w, ScaleUIPx(38)}, .text = site, .text_size = sizeof(site), .cursor_position = &site_cursor, .max_codepoints = 255, .font = Text16, .focus_id = 101})
|
||||
pass_request_focused_input_visible(101, (Rectangle){pad, y, content_w, ScaleUIPx(62)})
|
||||
y += ScaleUIPx(72)
|
||||
|
||||
Text("Login", pad, y, Text14, GetThemeText())
|
||||
TextField((TextFieldProps){.bounds = {pad, y + ScaleUIPx(22), content_w, ScaleUIPx(38)}, .text = login, .text_size = sizeof(login), .cursor_position = &login_cursor, .max_codepoints = 255, .font = Text16, .focus_id = 102})
|
||||
pass_request_focused_input_visible(102, (Rectangle){pad, y, content_w, ScaleUIPx(62)})
|
||||
y += ScaleUIPx(72)
|
||||
|
||||
Text("Master password", pad, y, Text14, GetThemeText())
|
||||
show_unlock: int = 0
|
||||
if show_fingerprint == 1 && pass_can_unlock_master() == 1 {
|
||||
show_unlock = 1
|
||||
}
|
||||
action_size: int = ScaleUIPx(42)
|
||||
action_gap: int = ScaleUIPx(8)
|
||||
reveal_x: int = pad + content_w - action_size
|
||||
unlock_x: int = reveal_x - action_gap - action_size
|
||||
master_field_w: int = content_w - action_size - action_gap
|
||||
if show_unlock == 1 {
|
||||
master_field_w = content_w - action_size * 2 - action_gap * 2
|
||||
}
|
||||
if master_field_w < ScaleUIPx(120) {
|
||||
master_field_w = ScaleUIPx(120)
|
||||
}
|
||||
if reveal_master == 0 {
|
||||
TextField((TextFieldProps){.bounds = {pad, y + ScaleUIPx(22), master_field_w, ScaleUIPx(38)}, .text = master, .text_size = sizeof(master), .cursor_position = &master_cursor, .max_codepoints = 1023, .font = Text16, .focus_id = 103, .secure = 1})
|
||||
} else {
|
||||
TextField((TextFieldProps){.bounds = {pad, y + ScaleUIPx(22), master_field_w, ScaleUIPx(38)}, .text = master, .text_size = sizeof(master), .cursor_position = &master_cursor, .max_codepoints = 1023, .font = Text16, .focus_id = 103, .secure = 0})
|
||||
}
|
||||
pass_request_focused_input_visible(103, (Rectangle){pad, y, content_w, ScaleUIPx(62)})
|
||||
if show_unlock == 1 {
|
||||
if IconButton((IconButtonProps){.bounds = {unlock_x, y + ScaleUIPx(22), action_size, ScaleUIPx(38)}, .icon = pass_fingerprint_icon, .icon_size = ScaleUIPx(22), .icon_padding = ScaleUIPx(8), .focus_id = 14, .background = GetThemeButton(), .hover_background = GetThemeButtonHover(), .icon_color = GetThemeText(), .border = Fade(GetThemeIcon(), 0.35f), .radius = 0.10f}) {
|
||||
ClearUIFocus()
|
||||
SetUIFocusTextInputActive(0)
|
||||
pass_unlock_master()
|
||||
}
|
||||
}
|
||||
reveal_icon: Texture2D = pass_eye_icon
|
||||
if reveal_master == 1 {
|
||||
reveal_icon = pass_eye_off_icon
|
||||
}
|
||||
if IconButton((IconButtonProps){.bounds = {reveal_x, y + ScaleUIPx(22), action_size, ScaleUIPx(38)}, .icon = reveal_icon, .icon_size = ScaleUIPx(22), .icon_padding = ScaleUIPx(8), .focus_id = 13, .background = GetThemeButton(), .hover_background = GetThemeButtonHover(), .icon_color = GetThemeText(), .border = Fade(GetThemeIcon(), 0.35f), .radius = 0.10f}) {
|
||||
reveal_master = 1 - reveal_master
|
||||
}
|
||||
y += ScaleUIPx(64)
|
||||
y += pass_draw_master_emoji(pad, y, master, show_fingerprint)
|
||||
y += ScaleUIPx(12)
|
||||
|
||||
Text("Length", pad, y + ScaleUIPx(10), Text16, GetThemeText())
|
||||
Spinbox((SpinboxProps){.bounds = {pad + content_w - ScaleUIPx(156), y, ScaleUIPx(156), ScaleUIPx(40)}, .id = 20, .min = 5, .max = 35, .step = 1, .value = &length, .disabled = 0, .wrap = 0})
|
||||
y += ScaleUIPx(54)
|
||||
|
||||
Text("Counter", pad, y + ScaleUIPx(10), Text16, GetThemeText())
|
||||
Spinbox((SpinboxProps){.bounds = {pad + content_w - ScaleUIPx(156), y, ScaleUIPx(156), ScaleUIPx(40)}, .id = 21, .min = 1, .max = 999999, .step = 1, .value = &counter, .disabled = 0, .wrap = 0})
|
||||
y += ScaleUIPx(58)
|
||||
|
||||
Checkbox(31, pad, y, "a-z", &lower)
|
||||
Checkbox(32, pad + content_w / 4, y, "A-Z", &upper)
|
||||
Checkbox(33, pad + content_w / 2, y, "0-9", &digits)
|
||||
Checkbox(34, pad + (content_w / 4) * 3, y, "#", &symbols)
|
||||
y += ScaleUIPx(72)
|
||||
|
||||
Text("Exclude", pad, y, Text14, GetThemeText())
|
||||
TextField((TextFieldProps){.bounds = {pad, y + ScaleUIPx(22), content_w, ScaleUIPx(38)}, .text = exclude, .text_size = sizeof(exclude), .cursor_position = &exclude_cursor, .max_codepoints = 127, .font = Text16, .focus_id = 104})
|
||||
pass_request_focused_input_visible(104, (Rectangle){pad, y, content_w, ScaleUIPx(62)})
|
||||
y += ScaleUIPx(76)
|
||||
|
||||
if Button((ButtonProps){.bounds = {pad, y, content_w, ScaleUIPx(44)}, .label = "Generate", .style = ButtonStylePrimary, .font = Text16, .id = 40}) {
|
||||
pass_generate(site, login, master, length, counter, lower, upper, digits, symbols, exclude)
|
||||
pass_scroll_to_generated = 1
|
||||
if auto_copy == 1 {
|
||||
pass_copy()
|
||||
}
|
||||
}
|
||||
y += ScaleUIPx(60)
|
||||
|
||||
Text("Generated password", pad, y, Text14, GetThemeText())
|
||||
pass_draw_generated_output(pad, y + ScaleUIPx(22), content_w)
|
||||
if pass_scroll_to_generated == 1 {
|
||||
pass_request_rect_visible((Rectangle){pad, y, content_w, ScaleUIPx(82)})
|
||||
pass_scroll_to_generated = 0
|
||||
}
|
||||
y += ScaleUIPx(88)
|
||||
|
||||
if Button((ButtonProps){.bounds = {pad, y, content_w, ScaleUIPx(40)}, .label = "Copy", .style = ButtonStyleSecondary, .font = Text16, .id = 41}) {
|
||||
pass_copy()
|
||||
}
|
||||
|
||||
return y + ScaleUIPx(54)
|
||||
}
|
||||
|
||||
pass_draw_profiles :: (pad: int, y: int, content_w: int) -> int #private {
|
||||
Text("Profile name", pad, y, Text14, GetThemeText())
|
||||
TextField((TextFieldProps){.bounds = {pad, y + ScaleUIPx(22), content_w, ScaleUIPx(38)}, .text = profile_name, .text_size = sizeof(profile_name), .cursor_position = &profile_name_cursor, .max_codepoints = 63, .font = Text16, .focus_id = 201})
|
||||
pass_request_focused_input_visible(201, (Rectangle){pad, y, content_w, ScaleUIPx(62)})
|
||||
y += ScaleUIPx(76)
|
||||
|
||||
if Button((ButtonProps){.bounds = {pad, y, content_w, ScaleUIPx(42)}, .label = "Save Current Profile", .style = ButtonStylePrimary, .font = Text16, .id = 210}) {
|
||||
pass_save_profile(profile_name, site, login, length, counter, lower, upper, digits, symbols, exclude)
|
||||
}
|
||||
y += ScaleUIPx(58)
|
||||
|
||||
return profiles_draw_list(pad, y, content_w, master)
|
||||
}
|
||||
|
||||
pass_frame :: () #ui {
|
||||
if pass_take_unlocked_master(master) == 1 {
|
||||
master_cursor = 0
|
||||
}
|
||||
pass_load_saved_settings()
|
||||
pass_apply_theme()
|
||||
pass_load_icons()
|
||||
Background(GetThemeBackground())
|
||||
|
||||
screen_w: int = GetFrameWidth()
|
||||
screen_h: int = GetFrameHeight()
|
||||
pad: int = ScaleUIPx(18)
|
||||
top: int = ScaleUIPx(16) + ScaleUIPx(AndroidHostTopReserved())
|
||||
left: int = pad + ScaleUIPx(AndroidHostLeftReserved())
|
||||
right: int = pad + ScaleUIPx(AndroidHostRightReserved())
|
||||
bottom: int = ScaleUIPx(AndroidHostBottomReserved())
|
||||
content_w: int = screen_w - left - right
|
||||
if content_w < ScaleUIPx(160) {
|
||||
content_w = screen_w - left - right
|
||||
}
|
||||
if content_w < ScaleUIPx(96) {
|
||||
left = ScaleUIPx(8) + ScaleUIPx(AndroidHostLeftReserved())
|
||||
right = ScaleUIPx(8) + ScaleUIPx(AndroidHostRightReserved())
|
||||
content_w = screen_w - left - right
|
||||
}
|
||||
if content_w < 1 {
|
||||
content_w = 1
|
||||
}
|
||||
|
||||
settings_capture_theme_input()
|
||||
|
||||
nav_h: int = ScaleUIPx(66)
|
||||
nav_y: int = screen_h - bottom - nav_h
|
||||
scrollbar_x: int = screen_w - ScaleUIPx(AndroidHostRightReserved()) - ScaleUIPx(8)
|
||||
y: int = top
|
||||
view_h: int = nav_y - y
|
||||
if view_h < ScaleUIPx(180) {
|
||||
view_h = ScaleUIPx(180)
|
||||
}
|
||||
pass_focused_rect_valid = 0
|
||||
|
||||
if view == VIEW_GENERATE {
|
||||
area := (UIScrollArea){
|
||||
.bounds = {left, y, content_w, view_h},
|
||||
.content_height = pass_generate_content_height(),
|
||||
.scroll_offset = &generate_scroll,
|
||||
.content_width = content_w,
|
||||
.scrollbar_x = scrollbar_x
|
||||
}
|
||||
scroll := BeginUIScrollContainer(area)
|
||||
pass_draw_generate(scroll.content_x, scroll.content_y, scroll.content_w)
|
||||
pass_ensure_focused_input_visible(area)
|
||||
EndUIScrollContainer(area, scroll)
|
||||
} else if view == VIEW_PROFILES {
|
||||
area := (UIScrollArea){
|
||||
.bounds = {left, y, content_w, view_h},
|
||||
.content_height = profiles_content_height(),
|
||||
.scroll_offset = &profiles_scroll,
|
||||
.content_width = content_w,
|
||||
.scrollbar_x = scrollbar_x
|
||||
}
|
||||
scroll := BeginUIScrollContainer(area)
|
||||
pass_draw_profiles(scroll.content_x, scroll.content_y, scroll.content_w)
|
||||
pass_ensure_focused_input_visible(area)
|
||||
EndUIScrollContainer(area, scroll)
|
||||
} else {
|
||||
area := (UIScrollArea){
|
||||
.bounds = {left, y, content_w, view_h},
|
||||
.content_height = settings_content_height(master),
|
||||
.scroll_offset = &settings_scroll,
|
||||
.content_width = content_w,
|
||||
.scrollbar_x = scrollbar_x
|
||||
}
|
||||
scroll := BeginUIScrollContainer(area)
|
||||
settings_draw(scroll.content_x, scroll.content_y, scroll.content_w, master, &master_cursor, &reveal_master, &auto_copy, &clear_seconds, &show_fingerprint, &length, &counter, &lower, &upper, &digits, &symbols, exclude, &exclude_cursor, &theme_source, &theme_mode, &theme_id, &theme_style)
|
||||
pass_request_focused_input_visible(512, (Rectangle){scroll.content_x, scroll.content_y + ScaleUIPx(364), scroll.content_w, ScaleUIPx(62)})
|
||||
pass_request_focused_input_visible(530, (Rectangle){scroll.content_x, scroll.content_y + ScaleUIPx(534), scroll.content_w, ScaleUIPx(62)})
|
||||
pass_ensure_focused_input_visible(area)
|
||||
EndUIScrollContainer(area, scroll)
|
||||
}
|
||||
DrawRectangleRec((Rectangle){0, nav_y, screen_w, screen_h - nav_y}, GetThemeSurface())
|
||||
Line(0, nav_y, screen_w, nav_y, Fade(GetThemeIcon(), 0.24f))
|
||||
nav_draw(left, nav_y, content_w, nav_h, &view)
|
||||
if view == VIEW_SETTINGS {
|
||||
settings_draw_theme_modal(&auto_copy, &clear_seconds, &show_fingerprint, &length, &counter, &lower, &upper, &digits, &symbols, exclude, &theme_source, &theme_mode, &theme_id, &theme_style, &theme_menu_state)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#import "kryon.h"
|
||||
|
||||
pass_profile_count :: () -> int #extern "pass_profile_count"
|
||||
pass_profile_label :: (index: int) -> char* #extern "pass_profile_label"
|
||||
pass_generate_profile :: (index: int, master: const char*) -> int #extern "pass_generate_profile"
|
||||
pass_delete_profile :: (index: int) -> int #extern "pass_delete_profile"
|
||||
|
||||
profiles_draw_list :: (x: int, y: int, width: int, master: [1024] char) -> int {
|
||||
count: int = pass_profile_count()
|
||||
|
||||
if count == 0 {
|
||||
Text("No saved profiles", x, y, Text16, GetThemeIcon())
|
||||
return y + ScaleUIPx(48)
|
||||
}
|
||||
|
||||
for int i = 0; i < count; i++ {
|
||||
row_y: int = y + i * ScaleUIPx(48)
|
||||
|
||||
Text(pass_profile_label(i), x, row_y + ScaleUIPx(10), Text16, GetThemeText())
|
||||
if Button((ButtonProps){.bounds = {x + width - ScaleUIPx(170), row_y, ScaleUIPx(88), ScaleUIPx(36)}, .label = "Generate", .style = ButtonStyleSecondary, .font = Text14, .id = 300 + i}) {
|
||||
pass_generate_profile(i, master)
|
||||
}
|
||||
if Button((ButtonProps){.bounds = {x + width - ScaleUIPx(74), row_y, ScaleUIPx(74), ScaleUIPx(36)}, .label = "Delete", .style = ButtonStyleSecondary, .font = Text14, .id = 400 + i}) {
|
||||
pass_delete_profile(i)
|
||||
}
|
||||
}
|
||||
|
||||
return y + count * ScaleUIPx(48)
|
||||
}
|
||||
|
||||
profiles_content_height :: () -> int {
|
||||
count: int = pass_profile_count()
|
||||
list_h: int = ScaleUIPx(48)
|
||||
if count > 0 {
|
||||
list_h = count * ScaleUIPx(48)
|
||||
}
|
||||
return ScaleUIPx(76) + ScaleUIPx(58) + list_h + ScaleUIPx(110)
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
#import "kryon.h"
|
||||
#import "android_host.h"
|
||||
|
||||
pass_save_settings :: (auto_copy: int, clear_seconds: int, show_fingerprint: int, length: int, counter: int, lower: int, upper: int, digits: int, symbols: int, exclude: const char*, theme_source: int, theme_mode: int, theme_id: int, theme_style: int) -> int #extern "pass_save_settings"
|
||||
pass_save_master :: (master: const char*, require_biometric: int) -> int #extern "pass_save_master"
|
||||
pass_clear_master :: () -> int #extern "pass_clear_master"
|
||||
pass_fingerprint_status :: () -> char* #extern "pass_fingerprint_status"
|
||||
pass_master_emoji :: (master: const char*) -> char* #extern "pass_master_emoji"
|
||||
AndroidSecureStoreBiometricAvailable :: () -> int #extern "AndroidSecureStoreBiometricAvailable"
|
||||
AndroidSecureStoreHasSecret :: (key: const char*) -> int #extern "AndroidSecureStoreHasSecret"
|
||||
|
||||
state {
|
||||
settings_theme_modal_open: int = 0
|
||||
settings_icons_loaded: int = 0
|
||||
settings_close_icon: Texture2D
|
||||
settings_eye_icon: Texture2D
|
||||
settings_eye_off_icon: Texture2D
|
||||
}
|
||||
|
||||
settings_load_icons :: () #private {
|
||||
if settings_icons_loaded == 1 {
|
||||
return
|
||||
}
|
||||
|
||||
settings_close_icon = LoadUIIconTexture(UI_ICON_TYPE_X)
|
||||
settings_eye_icon = LoadUIIconTexture(UI_ICON_TYPE_EYE)
|
||||
settings_eye_off_icon = LoadUIIconTexture(UI_ICON_TYPE_EYE_OFF)
|
||||
settings_icons_loaded = 1
|
||||
}
|
||||
|
||||
settings_draw_master_emoji :: (x: int, y: int, master_text: [1024] char) -> int #private {
|
||||
if master_text[0] == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
font_token: int = PushUIFont("pass-emoji")
|
||||
Text(pass_master_emoji(master_text), x, y, Text20, GetThemeIcon())
|
||||
PopUIFont(font_token)
|
||||
return ScaleUIPx(32)
|
||||
}
|
||||
|
||||
settings_draw :: (
|
||||
x: int,
|
||||
y: int,
|
||||
width: int,
|
||||
master: [1024] char,
|
||||
master_cursor: int*,
|
||||
reveal_master: int*,
|
||||
auto_copy: int*,
|
||||
clear_seconds: int*,
|
||||
show_fingerprint: int*,
|
||||
length: int*,
|
||||
counter: int*,
|
||||
lower: int*,
|
||||
upper: int*,
|
||||
digits: int*,
|
||||
symbols: int*,
|
||||
exclude: [128] char,
|
||||
exclude_cursor: int*,
|
||||
theme_source: int*,
|
||||
theme_mode: int*,
|
||||
theme_id: int*,
|
||||
theme_style: int*
|
||||
) -> int {
|
||||
settings_load_icons()
|
||||
|
||||
Checkbox(501, x, y, "Auto-copy after Generate", auto_copy)
|
||||
y += ScaleUIPx(42)
|
||||
Slider(502, x, y, width, "Clipboard seconds", 0, 3600, clear_seconds, "", nil)
|
||||
y += ScaleUIPx(52)
|
||||
Checkbox(503, x, y, "Show master fingerprint", show_fingerprint)
|
||||
y += ScaleUIPx(52)
|
||||
|
||||
Text("Generation defaults", x, y, Text16, GetThemeText())
|
||||
y += ScaleUIPx(34)
|
||||
|
||||
Text("Length", x, y + ScaleUIPx(10), Text16, GetThemeText())
|
||||
Spinbox((SpinboxProps){.bounds = {x + width - ScaleUIPx(156), y, ScaleUIPx(156), ScaleUIPx(40)}, .id = 504, .min = 5, .max = 35, .step = 1, .value = length, .disabled = 0, .wrap = 0})
|
||||
y += ScaleUIPx(54)
|
||||
|
||||
Text("Counter", x, y + ScaleUIPx(10), Text16, GetThemeText())
|
||||
Spinbox((SpinboxProps){.bounds = {x + width - ScaleUIPx(156), y, ScaleUIPx(156), ScaleUIPx(40)}, .id = 505, .min = 1, .max = 999999, .step = 1, .value = counter, .disabled = 0, .wrap = 0})
|
||||
y += ScaleUIPx(58)
|
||||
|
||||
Checkbox(506, x, y, "a-z", lower)
|
||||
Checkbox(507, x + width / 4, y, "A-Z", upper)
|
||||
Checkbox(508, x + width / 2, y, "0-9", digits)
|
||||
Checkbox(509, x + (width / 4) * 3, y, "#", symbols)
|
||||
y += ScaleUIPx(72)
|
||||
|
||||
Text("Exclude", x, y, Text14, GetThemeText())
|
||||
TextField((TextFieldProps){.bounds = {x, y + ScaleUIPx(22), width, ScaleUIPx(38)}, .text = exclude, .text_size = 128, .cursor_position = exclude_cursor, .max_codepoints = 127, .font = Text16, .focus_id = 512})
|
||||
y += ScaleUIPx(76)
|
||||
|
||||
if Button((ButtonProps){.bounds = {x, y, width, ScaleUIPx(42)}, .label = "Save Settings", .style = ButtonStylePrimary, .font = Text16, .id = 510}) {
|
||||
pass_save_settings(*auto_copy, *clear_seconds, *show_fingerprint, *length, *counter, *lower, *upper, *digits, *symbols, exclude, *theme_source, *theme_mode, *theme_id, *theme_style)
|
||||
}
|
||||
y += ScaleUIPx(60)
|
||||
|
||||
Text("Secure master password", x, y, Text16, GetThemeText())
|
||||
y += ScaleUIPx(34)
|
||||
Text("Master password", x, y, Text14, GetThemeText())
|
||||
action_size: int = ScaleUIPx(42)
|
||||
action_gap: int = ScaleUIPx(8)
|
||||
field_w: int = width - action_size - action_gap
|
||||
if field_w < ScaleUIPx(120) {
|
||||
field_w = ScaleUIPx(120)
|
||||
}
|
||||
if *reveal_master == 0 {
|
||||
TextField((TextFieldProps){.bounds = {x, y + ScaleUIPx(22), field_w, ScaleUIPx(38)}, .text = master, .text_size = 1024, .cursor_position = master_cursor, .max_codepoints = 1023, .font = Text16, .focus_id = 530, .secure = 1})
|
||||
} else {
|
||||
TextField((TextFieldProps){.bounds = {x, y + ScaleUIPx(22), field_w, ScaleUIPx(38)}, .text = master, .text_size = 1024, .cursor_position = master_cursor, .max_codepoints = 1023, .font = Text16, .focus_id = 530, .secure = 0})
|
||||
}
|
||||
reveal_icon: Texture2D = settings_eye_icon
|
||||
if *reveal_master == 1 {
|
||||
reveal_icon = settings_eye_off_icon
|
||||
}
|
||||
if IconButton((IconButtonProps){.bounds = {x + width - action_size, y + ScaleUIPx(22), action_size, ScaleUIPx(38)}, .icon = reveal_icon, .icon_size = ScaleUIPx(22), .icon_padding = ScaleUIPx(8), .focus_id = 531, .background = GetThemeButton(), .hover_background = GetThemeButtonHover(), .icon_color = GetThemeText(), .border = Fade(GetThemeIcon(), 0.35f), .radius = 0.10f}) {
|
||||
*reveal_master = 1 - *reveal_master
|
||||
}
|
||||
y += ScaleUIPx(64)
|
||||
y += settings_draw_master_emoji(x, y, master)
|
||||
y += ScaleUIPx(12)
|
||||
|
||||
Text(pass_fingerprint_status(), x, y, Text12, GetThemeIcon())
|
||||
y += ScaleUIPx(30)
|
||||
|
||||
if Button((ButtonProps){.bounds = {x, y, width / 2 - ScaleUIPx(6), ScaleUIPx(42)}, .label = "Save", .style = ButtonStylePrimary, .font = Text16, .id = 520, .disabled = AndroidSecureStoreBiometricAvailable() == 0}) {
|
||||
pass_save_master(master, 1)
|
||||
}
|
||||
if Button((ButtonProps){.bounds = {x + width / 2 + ScaleUIPx(6), y, width / 2 - ScaleUIPx(6), ScaleUIPx(42)}, .label = "Forget", .style = ButtonStyleSecondary, .font = Text16, .id = 522, .disabled = AndroidSecureStoreHasSecret("default") == 0}) {
|
||||
pass_clear_master()
|
||||
}
|
||||
y += ScaleUIPx(60)
|
||||
|
||||
if Button((ButtonProps){.bounds = {x, y, width, ScaleUIPx(42)}, .label = "Theme Settings", .style = ButtonStyleSecondary, .font = Text16, .id = 500}) {
|
||||
ClearUIFocus()
|
||||
SetUIFocusTextInputActive(0)
|
||||
UIConsumeRelease()
|
||||
settings_theme_modal_open = 1
|
||||
}
|
||||
|
||||
return y + ScaleUIPx(52)
|
||||
}
|
||||
|
||||
settings_theme_modal_is_open :: () -> int {
|
||||
return settings_theme_modal_open
|
||||
}
|
||||
|
||||
settings_content_height :: (master: [1024] char) -> int {
|
||||
height: int = 0
|
||||
|
||||
height += ScaleUIPx(42)
|
||||
height += ScaleUIPx(52)
|
||||
height += ScaleUIPx(52)
|
||||
height += ScaleUIPx(34)
|
||||
height += ScaleUIPx(54)
|
||||
height += ScaleUIPx(58)
|
||||
height += ScaleUIPx(72)
|
||||
height += ScaleUIPx(76)
|
||||
height += ScaleUIPx(60)
|
||||
height += ScaleUIPx(34)
|
||||
height += ScaleUIPx(64)
|
||||
if master[0] != 0 {
|
||||
height += ScaleUIPx(32)
|
||||
}
|
||||
height += ScaleUIPx(12)
|
||||
height += ScaleUIPx(30)
|
||||
height += ScaleUIPx(60)
|
||||
height += ScaleUIPx(52)
|
||||
|
||||
return height
|
||||
}
|
||||
|
||||
settings_draw_theme_modal :: (
|
||||
auto_copy: int*,
|
||||
clear_seconds: int*,
|
||||
show_fingerprint: int*,
|
||||
length: int*,
|
||||
counter: int*,
|
||||
lower: int*,
|
||||
upper: int*,
|
||||
digits: int*,
|
||||
symbols: int*,
|
||||
exclude: [128] char,
|
||||
theme_source: int*,
|
||||
theme_mode: int*,
|
||||
theme_id: int*,
|
||||
theme_style: int*,
|
||||
theme_menu_state: UIThemeSettingsState*
|
||||
) {
|
||||
if settings_theme_modal_open == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
settings_load_icons()
|
||||
|
||||
empty_icon: Texture2D = {0}
|
||||
modal_w: int = GetScreenWidth() - ScaleUIPx(32)
|
||||
modal_h: int = ScaleUIPx(380)
|
||||
frame := ModalFrame(modal_w, modal_h, "Theme Settings", empty_icon, settings_close_icon)
|
||||
if frame.right_clicked == 1 {
|
||||
ClearUIFocus()
|
||||
SetUIFocusTextInputActive(0)
|
||||
UIConsumeRelease()
|
||||
settings_theme_modal_open = 0
|
||||
}
|
||||
|
||||
settings := (ThemeSettingsProps){
|
||||
.id_base = 600,
|
||||
.x = frame.content_x,
|
||||
.y = frame.content_y,
|
||||
.w = frame.content_w,
|
||||
.theme_source = theme_source,
|
||||
.theme_mode = theme_mode,
|
||||
.theme_id = theme_id,
|
||||
.theme_style = theme_style,
|
||||
.allow_system_source = 1,
|
||||
.allow_system_mode = 1,
|
||||
.palette_label = "Color palette",
|
||||
.source_system_label = "System colors",
|
||||
.style_label = "Widget style",
|
||||
.style_system_label = "System style"
|
||||
}
|
||||
ThemeSettings(settings, theme_menu_state, nil)
|
||||
|
||||
save_y: int = frame.content_y + frame.content_h - ScaleUIPx(44)
|
||||
if Button((ButtonProps){.bounds = {frame.content_x, save_y, frame.content_w, ScaleUIPx(40)}, .label = "Save Theme", .style = ButtonStylePrimary, .font = Text16, .id = 511}) {
|
||||
pass_save_settings(*auto_copy, *clear_seconds, *show_fingerprint, *length, *counter, *lower, *upper, *digits, *symbols, exclude, *theme_source, *theme_mode, *theme_id, *theme_style)
|
||||
ClearUIFocus()
|
||||
SetUIFocusTextInputActive(0)
|
||||
UIConsumeRelease()
|
||||
settings_theme_modal_open = 0
|
||||
}
|
||||
}
|
||||
|
||||
// Block the underlying form before drawing the modal's interactive controls.
|
||||
settings_capture_theme_input :: () {
|
||||
if settings_theme_modal_open == 1 {
|
||||
PushUIInputCapture((Rectangle){0, 0, GetFrameWidth(), GetFrameHeight()}, 0)
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 125 KiB After Width: | Height: | Size: 1.7 KiB |
@@ -0,0 +1,39 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="512" height="512" shape-rendering="crispEdges">
|
||||
<rect width="64" height="64" fill="none"/>
|
||||
|
||||
<rect x="10" y="8" width="44" height="48" fill="#1b3942"/>
|
||||
<rect x="8" y="10" width="48" height="44" fill="#1b3942"/>
|
||||
<rect x="12" y="12" width="40" height="40" fill="#8fcfc8"/>
|
||||
<rect x="12" y="12" width="40" height="8" fill="#b9e5dc"/>
|
||||
<rect x="12" y="44" width="40" height="8" fill="#5aa59f"/>
|
||||
<rect x="16" y="16" width="32" height="32" fill="#6ebdb6"/>
|
||||
|
||||
<rect x="22" y="24" width="20" height="22" fill="#14262d"/>
|
||||
<rect x="20" y="26" width="24" height="18" fill="#14262d"/>
|
||||
<rect x="24" y="26" width="18" height="16" fill="#f3e7c0"/>
|
||||
<rect x="22" y="28" width="20" height="16" fill="#d6c48d"/>
|
||||
<rect x="24" y="28" width="16" height="12" fill="#f7edcf"/>
|
||||
<rect x="28" y="32" width="8" height="4" fill="#17303a"/>
|
||||
<rect x="30" y="36" width="4" height="6" fill="#17303a"/>
|
||||
|
||||
<rect x="24" y="16" width="16" height="4" fill="#14262d"/>
|
||||
<rect x="22" y="20" width="4" height="8" fill="#14262d"/>
|
||||
<rect x="38" y="20" width="4" height="8" fill="#14262d"/>
|
||||
<rect x="26" y="18" width="12" height="4" fill="#e9f2ed"/>
|
||||
<rect x="24" y="22" width="4" height="6" fill="#e9f2ed"/>
|
||||
<rect x="36" y="22" width="4" height="6" fill="#b8c5bf"/>
|
||||
|
||||
<rect x="38" y="38" width="16" height="4" fill="#14262d"/>
|
||||
<rect x="50" y="34" width="6" height="6" fill="#14262d"/>
|
||||
<rect x="52" y="32" width="4" height="4" fill="#14262d"/>
|
||||
<rect x="40" y="40" width="14" height="4" fill="#f0bd52"/>
|
||||
<rect x="52" y="36" width="4" height="4" fill="#f0bd52"/>
|
||||
<rect x="44" y="44" width="4" height="4" fill="#f0bd52"/>
|
||||
<rect x="48" y="44" width="4" height="4" fill="#f0bd52"/>
|
||||
<rect x="42" y="38" width="10" height="2" fill="#ffe28a"/>
|
||||
<rect x="54" y="34" width="2" height="2" fill="#ffe28a"/>
|
||||
|
||||
<rect x="14" y="14" width="6" height="4" fill="#e4f2e9"/>
|
||||
<rect x="14" y="46" width="10" height="2" fill="#407f7b"/>
|
||||
<rect x="44" y="18" width="4" height="4" fill="#4a918c"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 485 KiB |
|
After Width: | Height: | Size: 283 KiB |
@@ -1,63 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type clipboardCommand struct {
|
||||
program string
|
||||
args []string
|
||||
}
|
||||
|
||||
func copyToClipboard(value string, clearAfter time.Duration) error {
|
||||
// The built-in pure-Go X11 clipboard doubles as the only backend that can
|
||||
// auto-clear: it owns the selection from a daemon and releases it on time.
|
||||
if handled, err := copyViaX11(value, clearAfter); handled {
|
||||
return err
|
||||
}
|
||||
if clearAfter > 0 {
|
||||
fmt.Fprintln(os.Stderr, "warning: --clear-after needs the built-in X11 clipboard; copying without auto-clear")
|
||||
}
|
||||
commands := clipboardCommands()
|
||||
var failures []error
|
||||
for _, candidate := range commands {
|
||||
path, err := exec.LookPath(candidate.program)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
command := exec.Command(path, candidate.args...)
|
||||
command.Stdin = strings.NewReader(value)
|
||||
if output, err := command.CombinedOutput(); err == nil {
|
||||
return nil
|
||||
} else if len(output) > 0 {
|
||||
failures = append(failures, fmt.Errorf("%s: %w: %s", candidate.program, err, output))
|
||||
} else {
|
||||
failures = append(failures, fmt.Errorf("%s: %w", candidate.program, err))
|
||||
}
|
||||
}
|
||||
if len(failures) > 0 {
|
||||
return fmt.Errorf("clipboard command failed: %w", errors.Join(failures...))
|
||||
}
|
||||
return errors.New("clipboard unavailable: install wl-copy, xclip, xsel, pbcopy, or clip.exe")
|
||||
}
|
||||
|
||||
func clipboardCommands() []clipboardCommand {
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
return []clipboardCommand{{program: "pbcopy"}}
|
||||
case "windows":
|
||||
return []clipboardCommand{{program: "clip.exe"}}
|
||||
default:
|
||||
return []clipboardCommand{
|
||||
{program: "wl-copy"},
|
||||
{program: "xclip", args: []string{"-selection", "clipboard", "-in"}},
|
||||
{program: "xsel", args: []string{"--clipboard", "--input"}},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
//go:build !linux
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// The built-in X11 clipboard is Linux-only; other platforms always fall back
|
||||
// to external clipboard tools.
|
||||
|
||||
func copyViaX11(text string, clearAfter time.Duration) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func runClipboardDaemon(timeout time.Duration) error {
|
||||
return errors.New("the built-in clipboard daemon is Linux-only")
|
||||
}
|
||||
|
||||
func readClipboardSelection() (string, error) {
|
||||
return "", errors.New("reading the clipboard is Linux-only")
|
||||
}
|
||||
@@ -1,318 +0,0 @@
|
||||
//go:build linux
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/BurntSushi/xgb"
|
||||
"github.com/BurntSushi/xgb/xproto"
|
||||
)
|
||||
|
||||
// Pure-Go X11 clipboard. Xlibre is protocol-compatible with X.Org, so the
|
||||
// regular CLIPBOARD selection works there too. No xclip/xsel/wl-copy needed.
|
||||
|
||||
const (
|
||||
selClipboard = "CLIPBOARD"
|
||||
atomUTF8 = "UTF8_STRING"
|
||||
atomString = "STRING"
|
||||
atomText = "TEXT"
|
||||
atomTextPlain = "text/plain"
|
||||
atomPlainUTF8 = "text/plain;charset=utf-8"
|
||||
atomTargets = "TARGETS"
|
||||
atomMultiple = "MULTIPLE"
|
||||
propName = "PASS_SELECTION"
|
||||
)
|
||||
|
||||
type xAtoms map[string]xproto.Atom
|
||||
|
||||
func allAtomNames() []string {
|
||||
return []string{selClipboard, atomUTF8, atomString, atomText, atomTextPlain,
|
||||
atomPlainUTF8, atomTargets, atomMultiple, propName}
|
||||
}
|
||||
|
||||
func internAtoms(c *xgb.Conn, names ...string) (xAtoms, error) {
|
||||
m := make(xAtoms, len(names))
|
||||
for _, n := range names {
|
||||
rep, err := xproto.InternAtom(c, false, uint16(len(n)), n).Reply()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m[n] = rep.Atom
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// serveClipboard takes ownership of the X11 CLIPBOARD selection and answers
|
||||
// paste requests until another client takes ownership or timeout elapses
|
||||
// (timeout <= 0 means "until replaced"). If ready is non-nil it is closed once
|
||||
// ownership has been confirmed.
|
||||
func serveClipboard(text string, timeout time.Duration, ready chan<- struct{}) error {
|
||||
c, err := xgb.NewConn()
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot connect to X server: %v", err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
atoms, err := internAtoms(c, allAtomNames()...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
screen := xproto.Setup(c).DefaultScreen(c)
|
||||
wid, err := c.NewId()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = xproto.CreateWindowChecked(c, 0, xproto.Window(wid), screen.Root,
|
||||
-1, -1, 1, 1, 0, 0, 0, 0, nil).Check()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
xproto.SetSelectionOwner(c, xproto.Window(wid), atoms[selClipboard], xproto.TimeCurrentTime)
|
||||
|
||||
rep, err := xproto.GetSelectionOwner(c, atoms[selClipboard]).Reply()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if rep.Owner != xproto.Window(wid) {
|
||||
return errors.New("failed to acquire CLIPBOARD ownership")
|
||||
}
|
||||
if ready != nil {
|
||||
close(ready)
|
||||
}
|
||||
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- selectionEventLoop(c, text, atoms) }()
|
||||
|
||||
sig := make(chan os.Signal, 1)
|
||||
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
|
||||
defer signal.Stop(sig)
|
||||
|
||||
if timeout > 0 {
|
||||
timer := time.NewTimer(timeout)
|
||||
defer timer.Stop()
|
||||
select {
|
||||
case err := <-done:
|
||||
return err
|
||||
case <-timer.C:
|
||||
return nil
|
||||
case <-sig:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
select {
|
||||
case err := <-done:
|
||||
return err
|
||||
case <-sig:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func selectionEventLoop(c *xgb.Conn, text string, atoms xAtoms) error {
|
||||
for {
|
||||
ev, err := c.WaitForEvent()
|
||||
if err != nil { // connection closed or protocol error
|
||||
return err
|
||||
}
|
||||
switch e := ev.(type) {
|
||||
case xproto.SelectionClearEvent:
|
||||
return nil // another client owns the clipboard now
|
||||
case xproto.DestroyNotifyEvent:
|
||||
return nil
|
||||
case xproto.SelectionRequestEvent:
|
||||
handleSelectionRequest(c, e, text, atoms)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func handleSelectionRequest(c *xgb.Conn, e xproto.SelectionRequestEvent, text string, atoms xAtoms) {
|
||||
prop := e.Property
|
||||
if prop == xproto.AtomNone {
|
||||
prop = e.Target
|
||||
}
|
||||
|
||||
ok := false
|
||||
switch e.Target {
|
||||
case atoms[atomTargets]:
|
||||
targets := []xproto.Atom{
|
||||
atoms[atomTargets], atoms[atomMultiple],
|
||||
atoms[atomUTF8], atoms[atomPlainUTF8],
|
||||
atoms[atomText], atoms[atomTextPlain], atoms[atomString],
|
||||
}
|
||||
buf := make([]byte, 4*len(targets))
|
||||
for i, t := range targets {
|
||||
binary.LittleEndian.PutUint32(buf[i*4:], uint32(t))
|
||||
}
|
||||
ok = changeProperty(c, e.Requestor, prop, xproto.AtomAtom, 32, buf)
|
||||
case atoms[atomUTF8], atoms[atomPlainUTF8], atoms[atomText], atoms[atomTextPlain], atoms[atomString]:
|
||||
// Generated passwords are plain ASCII, so serving the same bytes for
|
||||
// STRING (Latin-1) and TEXT targets is safe.
|
||||
ok = changeProperty(c, e.Requestor, prop, e.Target, 8, []byte(text))
|
||||
}
|
||||
if !ok {
|
||||
prop = xproto.AtomNone // refuse this target
|
||||
}
|
||||
|
||||
// Reply with a SelectionNotify event (event code 31).
|
||||
b := make([]byte, 32)
|
||||
b[0] = 31
|
||||
binary.LittleEndian.PutUint32(b[4:], uint32(e.Time))
|
||||
binary.LittleEndian.PutUint32(b[8:], uint32(e.Requestor))
|
||||
binary.LittleEndian.PutUint32(b[12:], uint32(e.Selection))
|
||||
binary.LittleEndian.PutUint32(b[16:], uint32(e.Target))
|
||||
binary.LittleEndian.PutUint32(b[20:], uint32(prop))
|
||||
xproto.SendEvent(c, false, e.Requestor, 0, string(b))
|
||||
}
|
||||
|
||||
func changeProperty(c *xgb.Conn, win xproto.Window, prop, typ xproto.Atom, format byte, data []byte) bool {
|
||||
units := uint32(len(data))
|
||||
if format == 32 {
|
||||
units /= 4
|
||||
}
|
||||
return xproto.ChangePropertyChecked(c, xproto.PropModeReplace, win, prop,
|
||||
typ, format, units, data).Check() == nil
|
||||
}
|
||||
|
||||
// copyViaX11 copies through the built-in clipboard server. It reports false
|
||||
// when no X server is reachable, so the caller can fall back to external
|
||||
// clipboard tools.
|
||||
func copyViaX11(text string, clearAfter time.Duration) (bool, error) {
|
||||
if os.Getenv("DISPLAY") == "" {
|
||||
return false, nil
|
||||
}
|
||||
probe, err := xgb.NewConn()
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
probe.Close()
|
||||
return true, spawnClipboardDaemon(text, clearAfter)
|
||||
}
|
||||
|
||||
// spawnClipboardDaemon re-executes this binary detached (new session) so the
|
||||
// clipboard keeps working after the terminal is closed. The password travels
|
||||
// over a pipe; it is never in argv or the environment.
|
||||
func spawnClipboardDaemon(text string, timeout time.Duration) error {
|
||||
r, w, err := os.Pipe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd := exec.Command(selfPath(), "--serve-clipboard", "--clear-after="+timeout.String())
|
||||
cmd.ExtraFiles = []*os.File{r}
|
||||
cmd.Env = os.Environ() // keep DISPLAY for the child
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
r.Close()
|
||||
w.Close()
|
||||
return err
|
||||
}
|
||||
if _, err := io.WriteString(w, text); err != nil {
|
||||
return err
|
||||
}
|
||||
w.Close()
|
||||
r.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
// selfPath returns the absolute path of this running executable, so the
|
||||
// detached clipboard daemon can re-exec itself reliably.
|
||||
func selfPath() string {
|
||||
if p, err := os.Executable(); err == nil {
|
||||
return p
|
||||
}
|
||||
return os.Args[0]
|
||||
}
|
||||
|
||||
// runClipboardDaemon is the detached child process: it receives the password
|
||||
// over the pipe passed as fd 3 and serves the X11 clipboard until it is
|
||||
// replaced or the timeout elapses.
|
||||
func runClipboardDaemon(timeout time.Duration) error {
|
||||
f := os.NewFile(uintptr(3), "pipe")
|
||||
if f == nil {
|
||||
return errors.New("no pipe on fd 3")
|
||||
}
|
||||
data := make([]byte, 0, 64)
|
||||
buf := make([]byte, 64)
|
||||
for {
|
||||
n, err := f.Read(buf)
|
||||
data = append(data, buf[:n]...)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
f.Close()
|
||||
if len(data) == 0 {
|
||||
return errors.New("empty clipboard payload")
|
||||
}
|
||||
return serveClipboard(string(data), timeout, nil)
|
||||
}
|
||||
|
||||
// readClipboardSelection requests the current CLIPBOARD contents as
|
||||
// UTF8_STRING (equivalent of "xclip -o -selection clipboard").
|
||||
func readClipboardSelection() (string, error) {
|
||||
c, err := xgb.NewConn()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot connect to X server: %v", err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
atoms, err := internAtoms(c, allAtomNames()...)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
screen := xproto.Setup(c).DefaultScreen(c)
|
||||
wid, err := c.NewId()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := xproto.CreateWindowChecked(c, 0, xproto.Window(wid), screen.Root,
|
||||
-1, -1, 1, 1, 0, 0, 0, 0, nil).Check(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
xproto.ConvertSelection(c, xproto.Window(wid), atoms[selClipboard],
|
||||
atoms[atomUTF8], atoms[propName], xproto.TimeCurrentTime)
|
||||
|
||||
// Wait for the SelectionNotify reply.
|
||||
var prop xproto.Atom
|
||||
found := false
|
||||
deadline := time.Now().Add(5 * time.Second)
|
||||
for !found {
|
||||
if time.Now().After(deadline) {
|
||||
return "", errors.New("timed out waiting for the clipboard owner")
|
||||
}
|
||||
ev, err := c.WaitForEvent()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if sn, ok := ev.(xproto.SelectionNotifyEvent); ok {
|
||||
if sn.Selection != atoms[selClipboard] {
|
||||
continue
|
||||
}
|
||||
if sn.Property == xproto.AtomNone {
|
||||
return "", errors.New("clipboard owner refused the request")
|
||||
}
|
||||
prop = sn.Property
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
||||
rep, err := xproto.GetProperty(c, false, xproto.Window(wid), prop,
|
||||
xproto.GetPropertyTypeAny, 0, 1<<20).Reply()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(rep.Value), nil
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
//go:build linux
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Live X11 round trip: take ownership of the CLIPBOARD selection, then read
|
||||
// it back as a separate X client.
|
||||
func TestClipboardRoundTrip(t *testing.T) {
|
||||
if os.Getenv("DISPLAY") == "" {
|
||||
t.Skip("no X11 display available")
|
||||
}
|
||||
|
||||
text := "TestPassword123"
|
||||
ready := make(chan struct{})
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- serveClipboard(text, 10*time.Second, ready) }()
|
||||
|
||||
select {
|
||||
case <-ready:
|
||||
case err := <-done:
|
||||
t.Fatalf("clipboard server exited early: %v", err)
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("timed out waiting for clipboard ownership")
|
||||
}
|
||||
|
||||
// Reading immediately can race with clipboard managers stealing the
|
||||
// selection; poll briefly for the expected content.
|
||||
deadline := time.Now().Add(5 * time.Second)
|
||||
for {
|
||||
got, err := readClipboardSelection()
|
||||
if err == nil && got == text {
|
||||
return // success
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("clipboard round trip failed: last read = %q, err = %v", got, err)
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
@@ -1,322 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
password "github.com/waozixyz/pass"
|
||||
"github.com/waozixyz/pass/vault"
|
||||
)
|
||||
|
||||
const environmentVariable = "LESSPASS_MASTER_PASSWORD"
|
||||
|
||||
// promptVaultPassphrase asks for the vault passphrase on the terminal, or
|
||||
// reads it from standard input when stdin is piped ("echo pw | pass ...").
|
||||
func promptVaultPassphrase() (string, error) {
|
||||
if info, err := os.Stdin.Stat(); err == nil && info.Mode()&os.ModeCharDevice == 0 {
|
||||
line, err := bufio.NewReader(os.Stdin).ReadString('\n')
|
||||
if err != nil && line == "" {
|
||||
return "", err
|
||||
}
|
||||
return strings.TrimRight(line, "\r\n"), nil
|
||||
}
|
||||
return readPassword("Vault passphrase: ")
|
||||
}
|
||||
|
||||
// readVaultPassphrase is the hook tests replace to decrypt a synthetic vault.
|
||||
var readVaultPassphrase = promptVaultPassphrase
|
||||
|
||||
func main() {
|
||||
if err := run(os.Args[1:], os.Stdout, os.Stderr); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "pass: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run(arguments []string, stdout, stderr io.Writer) error {
|
||||
config, err := loadConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
options := password.DefaultOptions()
|
||||
flags := flag.NewFlagSet("pass", flag.ContinueOnError)
|
||||
flags.SetOutput(stderr)
|
||||
flags.Usage = func() { printHelp(stderr) }
|
||||
|
||||
flags.IntVar(&options.Length, "L", options.Length, "password length")
|
||||
flags.IntVar(&options.Length, "length", options.Length, "password length")
|
||||
flags.Uint64Var(&options.Counter, "C", options.Counter, "generation counter")
|
||||
flags.Uint64Var(&options.Counter, "counter", options.Counter, "generation counter")
|
||||
flags.BoolVar(&options.Lowercase, "l", options.Lowercase, "include lowercase letters")
|
||||
flags.BoolVar(&options.Lowercase, "lowercase", options.Lowercase, "include lowercase letters")
|
||||
flags.BoolVar(&options.Uppercase, "u", options.Uppercase, "include uppercase letters")
|
||||
flags.BoolVar(&options.Uppercase, "uppercase", options.Uppercase, "include uppercase letters")
|
||||
flags.BoolVar(&options.Digits, "d", options.Digits, "include digits")
|
||||
flags.BoolVar(&options.Digits, "digits", options.Digits, "include digits")
|
||||
flags.BoolVar(&options.Symbols, "s", options.Symbols, "include symbols")
|
||||
flags.BoolVar(&options.Symbols, "symbols", options.Symbols, "include symbols")
|
||||
var noLowercase, noUppercase, noDigits, noSymbols bool
|
||||
flags.BoolVar(&noLowercase, "no-lowercase", false, "exclude lowercase letters")
|
||||
flags.BoolVar(&noUppercase, "no-uppercase", false, "exclude uppercase letters")
|
||||
flags.BoolVar(&noDigits, "no-digits", false, "exclude digits")
|
||||
flags.BoolVar(&noSymbols, "no-symbols", false, "exclude symbols")
|
||||
flags.StringVar(&options.Exclude, "exclude", "", "characters to exclude")
|
||||
|
||||
var forcePrompt, copyPassword, noCopy, showVersion, readClipboard, serveClipboard bool
|
||||
flags.BoolVar(&forcePrompt, "p", false, "prompt for the master password")
|
||||
flags.BoolVar(&forcePrompt, "prompt", false, "prompt for the master password")
|
||||
flags.BoolVar(©Password, "c", false, "copy the password to the clipboard")
|
||||
flags.BoolVar(©Password, "copy", false, "copy the password to the clipboard")
|
||||
flags.BoolVar(&noCopy, "no-copy", false, "print instead of copying when the profile says to copy")
|
||||
flags.BoolVar(&showVersion, "v", false, "show version")
|
||||
flags.BoolVar(&showVersion, "version", false, "show version")
|
||||
|
||||
var profileName, vaultFlag string
|
||||
var clearAfter time.Duration
|
||||
flags.StringVar(&profileName, "P", "", "use a named profile from the configuration file")
|
||||
flags.StringVar(&profileName, "profile", "", "use a named profile from the configuration file")
|
||||
flags.StringVar(&vaultFlag, "vault", "", "read the master password from an OpenSSL-encrypted vault")
|
||||
flags.DurationVar(&clearAfter, "clear-after", 0, "clear the clipboard after this long; 0 keeps it until replaced (built-in X11 clipboard only)")
|
||||
flags.BoolVar(&readClipboard, "read-clipboard", false, "print the current clipboard contents")
|
||||
flags.BoolVar(&serveClipboard, "serve-clipboard", false, "") // internal: detached clipboard daemon mode
|
||||
|
||||
if err := flags.Parse(normalizeArguments(arguments)); err != nil {
|
||||
if errors.Is(err, flag.ErrHelp) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
explicit := map[string]bool{}
|
||||
flags.Visit(func(f *flag.Flag) { explicit[f.Name] = true })
|
||||
if noLowercase {
|
||||
options.Lowercase = false
|
||||
}
|
||||
if noUppercase {
|
||||
options.Uppercase = false
|
||||
}
|
||||
if noDigits {
|
||||
options.Digits = false
|
||||
}
|
||||
if noSymbols {
|
||||
options.Symbols = false
|
||||
}
|
||||
if showVersion {
|
||||
fmt.Fprintf(stdout, "pass %s\n", password.Version)
|
||||
return nil
|
||||
}
|
||||
if serveClipboard {
|
||||
return runClipboardDaemon(clearAfter)
|
||||
}
|
||||
if readClipboard {
|
||||
text, err := readClipboardSelection()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(stdout, text)
|
||||
return nil
|
||||
}
|
||||
|
||||
positional := flags.Args()
|
||||
if profileName == "" && len(positional) == 2 && config != nil {
|
||||
if _, ok := config.Profiles[positional[0]]; ok {
|
||||
profileName = positional[0]
|
||||
positional = positional[1:]
|
||||
}
|
||||
}
|
||||
|
||||
var profile Profile
|
||||
if profileName != "" {
|
||||
if config == nil {
|
||||
return fmt.Errorf("unknown profile %q: no configuration file at %s", profileName, configPath())
|
||||
}
|
||||
found, ok := config.Profiles[profileName]
|
||||
if !ok {
|
||||
return fmt.Errorf("unknown profile %q", profileName)
|
||||
}
|
||||
if found.Login == "" {
|
||||
return fmt.Errorf("profile %q has no login", profileName)
|
||||
}
|
||||
profile = found
|
||||
profile.apply(&options, explicit)
|
||||
}
|
||||
|
||||
if profileName != "" {
|
||||
if len(positional) != 1 {
|
||||
printHelp(stderr)
|
||||
return errors.New("expected SITE with --profile")
|
||||
}
|
||||
} else if len(positional) < 2 || len(positional) > 3 {
|
||||
printHelp(stderr)
|
||||
return errors.New("expected SITE LOGIN and an optional MASTER_PASSWORD")
|
||||
}
|
||||
if forcePrompt && len(positional) == 3 {
|
||||
return errors.New("MASTER_PASSWORD cannot be supplied together with --prompt")
|
||||
}
|
||||
|
||||
site, login := positional[0], ""
|
||||
if profileName != "" {
|
||||
login = profile.Login
|
||||
} else {
|
||||
login = positional[1]
|
||||
}
|
||||
|
||||
// Explicit command-line password sources win. A configured vault beats
|
||||
// LESSPASS_MASTER_PASSWORD because profiles are meant to be complete
|
||||
// saved identities, including the master source.
|
||||
vaultPath := vaultFlag
|
||||
if vaultPath == "" {
|
||||
if !forcePrompt && len(positional) < 3 {
|
||||
switch {
|
||||
case profile.Vault != "":
|
||||
vaultPath = expandHome(profile.Vault)
|
||||
case config != nil && config.Vault != "":
|
||||
vaultPath = expandHome(config.Vault)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !noCopy && !anySet(explicit, "c", "copy") {
|
||||
switch {
|
||||
case profile.Copy != nil:
|
||||
copyPassword = *profile.Copy
|
||||
case config != nil && config.Copy != nil:
|
||||
copyPassword = *config.Copy
|
||||
}
|
||||
}
|
||||
if noCopy {
|
||||
copyPassword = false
|
||||
}
|
||||
if !anySet(explicit, "clear-after") {
|
||||
setting := profile.ClearAfter
|
||||
if setting == "" && config != nil {
|
||||
setting = config.ClearAfter
|
||||
}
|
||||
if setting != "" {
|
||||
duration, err := time.ParseDuration(setting)
|
||||
if err != nil {
|
||||
return fmt.Errorf("clear_after: %w", err)
|
||||
}
|
||||
clearAfter = duration
|
||||
}
|
||||
}
|
||||
|
||||
master, err := masterPassword(positional, forcePrompt, vaultPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
generated, err := password.Generate(site, login, master, options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if copyPassword {
|
||||
if err := copyToClipboard(generated, clearAfter); err != nil {
|
||||
return err
|
||||
}
|
||||
if clearAfter > 0 {
|
||||
fmt.Fprintf(stderr, "Password copied to the clipboard (auto-clears in %s).\n", clearAfter)
|
||||
} else {
|
||||
fmt.Fprintln(stderr, "Password copied to the clipboard.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintln(stdout, generated)
|
||||
return nil
|
||||
}
|
||||
|
||||
// normalizeArguments lets callers place options before or after SITE and
|
||||
// LOGIN. The standard flag package stops at the first positional argument,
|
||||
// while command wrappers naturally append profile options after the site.
|
||||
func normalizeArguments(arguments []string) []string {
|
||||
valueFlags := map[string]bool{
|
||||
"-L": true, "--length": true,
|
||||
"-C": true, "--counter": true,
|
||||
"--exclude": true,
|
||||
"-P": true, "--profile": true,
|
||||
"--vault": true, "--clear-after": true,
|
||||
}
|
||||
options := make([]string, 0, len(arguments))
|
||||
positional := make([]string, 0, 3)
|
||||
|
||||
for i := 0; i < len(arguments); i++ {
|
||||
argument := arguments[i]
|
||||
if argument == "--" {
|
||||
positional = append(positional, arguments[i+1:]...)
|
||||
break
|
||||
}
|
||||
if strings.HasPrefix(argument, "-") && argument != "-" {
|
||||
options = append(options, argument)
|
||||
if valueFlags[argument] && i+1 < len(arguments) {
|
||||
i++
|
||||
options = append(options, arguments[i])
|
||||
}
|
||||
continue
|
||||
}
|
||||
positional = append(positional, argument)
|
||||
}
|
||||
return append(options, positional...)
|
||||
}
|
||||
|
||||
func masterPassword(positional []string, forcePrompt bool, vaultPath string) (string, error) {
|
||||
if vaultPath != "" {
|
||||
if forcePrompt {
|
||||
return "", errors.New("--vault cannot be combined with --prompt")
|
||||
}
|
||||
if len(positional) == 3 {
|
||||
return "", errors.New("--vault cannot be combined with MASTER_PASSWORD")
|
||||
}
|
||||
passphrase, err := readVaultPassphrase()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return vault.Decrypt(vaultPath, passphrase)
|
||||
}
|
||||
if !forcePrompt && len(positional) == 3 {
|
||||
return positional[2], nil
|
||||
}
|
||||
if !forcePrompt {
|
||||
if value, exists := os.LookupEnv(environmentVariable); exists {
|
||||
return value, nil
|
||||
}
|
||||
}
|
||||
return readPassword("Master password: ")
|
||||
}
|
||||
|
||||
func printHelp(output io.Writer) {
|
||||
fmt.Fprintln(output, `Usage: pass [OPTIONS] SITE LOGIN [MASTER_PASSWORD]
|
||||
pass [OPTIONS] PROFILE SITE
|
||||
|
||||
Derive a site-specific password. If MASTER_PASSWORD is omitted, pass reads
|
||||
LESSPASS_MASTER_PASSWORD or asks for it on the controlling terminal. With
|
||||
--vault it instead decrypts an OpenSSL-encrypted vault and uses its contents
|
||||
as the master password. A named profile from the configuration file can be
|
||||
used either as "pass PROFILE SITE" or with --profile; it supplies the login
|
||||
and default settings.
|
||||
|
||||
Options:
|
||||
-L, --length N password length (default 16)
|
||||
-C, --counter N generation counter (default 1)
|
||||
-l, --lowercase include lowercase letters
|
||||
-u, --uppercase include uppercase letters
|
||||
-d, --digits include digits
|
||||
-s, --symbols include symbols
|
||||
--no-lowercase exclude lowercase letters
|
||||
--no-uppercase exclude uppercase letters
|
||||
--no-digits exclude digits
|
||||
--no-symbols exclude symbols
|
||||
--exclude CHARS remove characters from all enabled classes
|
||||
-p, --prompt always ask for the master password
|
||||
-c, --copy copy result without printing it
|
||||
--no-copy print instead of copying when the profile says to copy
|
||||
-P, --profile NAME use a named profile from the configuration file
|
||||
--vault PATH read the master password from an OpenSSL-encrypted vault
|
||||
--clear-after DUR clear the clipboard after DUR; 0 keeps it until replaced
|
||||
--read-clipboard print the current clipboard contents
|
||||
-v, --version show version
|
||||
-h, --help show this help`)
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
password "github.com/waozixyz/pass"
|
||||
)
|
||||
|
||||
// TestMain isolates every test in this package from the developer's real
|
||||
// profiles file: without this, a machine with ~/.config/pass/profiles.json
|
||||
// would feed private configuration into the tests.
|
||||
func TestMain(m *testing.M) {
|
||||
configPath = func() string {
|
||||
return filepath.Join(os.TempDir(), "pass-tests-absent-profiles.json")
|
||||
}
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestRunWithArgument(t *testing.T) {
|
||||
var output, diagnostics bytes.Buffer
|
||||
err := run([]string{"example.com", "alice", "correct horse battery staple"}, &output, &diagnostics)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, want := output.String(), "&vLf44D'/cSkP-_8\n"; got != want {
|
||||
t.Fatalf("output = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunUsesEnvironmentAndFlags(t *testing.T) {
|
||||
t.Setenv(environmentVariable, "correct horse battery staple")
|
||||
var output, diagnostics bytes.Buffer
|
||||
err := run([]string{"--length", "10", "--no-symbols", "--exclude", "aA0", "example.com", "alice"}, &output, &diagnostics)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := strings.TrimSpace(output.String())
|
||||
if len(got) != 10 {
|
||||
t.Fatalf("output length = %d, want 10", len(got))
|
||||
}
|
||||
if strings.ContainsAny(got, "aA0"+"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~") {
|
||||
t.Fatalf("output %q contains a disabled character", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunAcceptsFlagsAfterSiteAndLogin(t *testing.T) {
|
||||
t.Setenv(environmentVariable, "correct horse battery staple")
|
||||
var output, diagnostics bytes.Buffer
|
||||
err := run([]string{"example.com", "alice", "-C", "9", "-L", "23", "--no-symbols"}, &output, &diagnostics)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := strings.TrimSpace(output.String()); len(got) != 23 {
|
||||
t.Fatalf("output length = %d, want 23", len(got))
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunInformationOptions(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
argument string
|
||||
want string
|
||||
}{
|
||||
{"--version", "pass " + password.Version},
|
||||
{"--help", "Usage: pass"},
|
||||
} {
|
||||
var output, diagnostics bytes.Buffer
|
||||
if err := run([]string{test.argument}, &output, &diagnostics); err != nil {
|
||||
t.Errorf("run(%s): %v", test.argument, err)
|
||||
}
|
||||
combined := output.String() + diagnostics.String()
|
||||
if !strings.Contains(combined, test.want) {
|
||||
t.Errorf("run(%s) output %q does not contain %q", test.argument, combined, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunRejectsConflictingPasswordSources(t *testing.T) {
|
||||
var output, diagnostics bytes.Buffer
|
||||
err := run([]string{"--prompt", "example.com", "alice", "master"}, &output, &diagnostics)
|
||||
if err == nil || !strings.Contains(err.Error(), "cannot be supplied") {
|
||||
t.Fatalf("error = %v, want source conflict", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClipboardCommandsDoNotCarryPasswordData(t *testing.T) {
|
||||
secret := "this must travel only over standard input"
|
||||
for _, command := range clipboardCommands() {
|
||||
if command.program == secret {
|
||||
t.Fatal("secret appeared as clipboard executable")
|
||||
}
|
||||
for _, argument := range command.args {
|
||||
if strings.Contains(argument, secret) {
|
||||
t.Fatal("secret appeared in clipboard command arguments")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
password "github.com/waozixyz/pass"
|
||||
)
|
||||
|
||||
// Profile holds the saved settings for one named identity: a login plus the
|
||||
// generator options and clipboard behavior to use with it. Profiles contain
|
||||
// no secrets — the master password always comes from a prompt, the
|
||||
// environment, or an encrypted vault referenced by path.
|
||||
type Profile struct {
|
||||
Login string `json:"login"`
|
||||
Counter uint64 `json:"counter,omitempty"`
|
||||
Length int `json:"length,omitempty"`
|
||||
Lowercase *bool `json:"lowercase,omitempty"`
|
||||
Uppercase *bool `json:"uppercase,omitempty"`
|
||||
Digits *bool `json:"digits,omitempty"`
|
||||
Symbols *bool `json:"symbols,omitempty"`
|
||||
Exclude string `json:"exclude,omitempty"`
|
||||
Vault string `json:"vault,omitempty"`
|
||||
Copy *bool `json:"copy,omitempty"`
|
||||
ClearAfter string `json:"clear_after,omitempty"`
|
||||
}
|
||||
|
||||
// Config is the optional profiles file. Every field is a default that flags
|
||||
// and profile entries override; a missing file leaves pass fully stateless.
|
||||
type Config struct {
|
||||
Vault string `json:"vault,omitempty"`
|
||||
Copy *bool `json:"copy,omitempty"`
|
||||
ClearAfter string `json:"clear_after,omitempty"`
|
||||
Profiles map[string]Profile `json:"profiles"`
|
||||
}
|
||||
|
||||
// configPath is a variable so tests can point it at a temporary file.
|
||||
var configPath = defaultConfigPath
|
||||
|
||||
func defaultConfigPath() string {
|
||||
if dir := os.Getenv("XDG_CONFIG_HOME"); dir != "" {
|
||||
return filepath.Join(dir, "pass", "profiles.json")
|
||||
}
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return filepath.Join(home, ".config", "pass", "profiles.json")
|
||||
}
|
||||
|
||||
// loadConfig reads the profiles file. A missing file is not an error: the
|
||||
// feature is simply off and pass behaves as a plain stateless generator.
|
||||
func loadConfig() (*Config, error) {
|
||||
path := configPath()
|
||||
if path == "" {
|
||||
return nil, nil
|
||||
}
|
||||
raw, err := os.ReadFile(path)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var config Config
|
||||
if err := json.Unmarshal(raw, &config); err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", path, err)
|
||||
}
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
// apply fills the option fields that were not set explicitly on the command
|
||||
// line, so the precedence is always flag > profile > built-in default.
|
||||
func (p Profile) apply(options *password.Options, explicit map[string]bool) {
|
||||
if p.Length > 0 && !anySet(explicit, "L", "length") {
|
||||
options.Length = p.Length
|
||||
}
|
||||
if p.Counter > 0 && !anySet(explicit, "C", "counter") {
|
||||
options.Counter = p.Counter
|
||||
}
|
||||
if p.Lowercase != nil && !anySet(explicit, "l", "lowercase", "no-lowercase") {
|
||||
options.Lowercase = *p.Lowercase
|
||||
}
|
||||
if p.Uppercase != nil && !anySet(explicit, "u", "uppercase", "no-uppercase") {
|
||||
options.Uppercase = *p.Uppercase
|
||||
}
|
||||
if p.Digits != nil && !anySet(explicit, "d", "digits", "no-digits") {
|
||||
options.Digits = *p.Digits
|
||||
}
|
||||
if p.Symbols != nil && !anySet(explicit, "s", "symbols", "no-symbols") {
|
||||
options.Symbols = *p.Symbols
|
||||
}
|
||||
if p.Exclude != "" && !anySet(explicit, "exclude") {
|
||||
options.Exclude = p.Exclude
|
||||
}
|
||||
}
|
||||
|
||||
func anySet(explicit map[string]bool, names ...string) bool {
|
||||
for _, name := range names {
|
||||
if explicit[name] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// expandHome resolves a leading ~ so config entries stay portable.
|
||||
func expandHome(path string) string {
|
||||
if path == "~" || strings.HasPrefix(path, "~/") {
|
||||
if home, err := os.UserHomeDir(); err == nil {
|
||||
return filepath.Join(home, strings.TrimPrefix(path, "~"))
|
||||
}
|
||||
}
|
||||
return path
|
||||
}
|
||||
@@ -1,257 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
password "github.com/waozixyz/pass"
|
||||
)
|
||||
|
||||
// withConfig points the config loader at a temporary file for one test.
|
||||
func withConfig(t *testing.T, content string) {
|
||||
t.Helper()
|
||||
path := filepath.Join(t.TempDir(), "profiles.json")
|
||||
if err := os.WriteFile(path, []byte(content), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
original := configPath
|
||||
configPath = func() string { return path }
|
||||
t.Cleanup(func() { configPath = original })
|
||||
}
|
||||
|
||||
func withVaultPassphrase(t *testing.T, passphrase string) {
|
||||
t.Helper()
|
||||
original := readVaultPassphrase
|
||||
readVaultPassphrase = func() (string, error) { return passphrase, nil }
|
||||
t.Cleanup(func() { readVaultPassphrase = original })
|
||||
}
|
||||
|
||||
func TestRunWithProfileSettings(t *testing.T) {
|
||||
withConfig(t, `{
|
||||
"copy": true,
|
||||
"clear_after": "90s",
|
||||
"profiles": {
|
||||
"w": {"login": "alice", "counter": 9, "length": 23, "symbols": false}
|
||||
}
|
||||
}`)
|
||||
t.Setenv(environmentVariable, "correct horse battery staple")
|
||||
var output, diagnostics bytes.Buffer
|
||||
err := run([]string{"-P", "w", "--no-copy", "example.com"}, &output, &diagnostics)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want, err := password.Generate("example.com", "alice", "correct horse battery staple", password.Options{
|
||||
Length: 23, Counter: 9, Lowercase: true, Uppercase: true, Digits: true, Symbols: false,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := strings.TrimSpace(output.String()); got != want {
|
||||
t.Fatalf("output = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunWithProfileShorthand(t *testing.T) {
|
||||
withConfig(t, `{
|
||||
"profiles": {
|
||||
"w": {"login": "alice", "counter": 9, "length": 23, "symbols": false}
|
||||
}
|
||||
}`)
|
||||
t.Setenv(environmentVariable, "correct horse battery staple")
|
||||
var output, diagnostics bytes.Buffer
|
||||
err := run([]string{"w", "example.com", "--no-copy"}, &output, &diagnostics)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want, err := password.Generate("example.com", "alice", "correct horse battery staple", password.Options{
|
||||
Length: 23, Counter: 9, Lowercase: true, Uppercase: true, Digits: true, Symbols: false,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := strings.TrimSpace(output.String()); got != want {
|
||||
t.Fatalf("output = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProfileSettingsDoNotOverrideExplicitFlags(t *testing.T) {
|
||||
withConfig(t, `{"profiles": {"w": {"login": "alice", "length": 23, "symbols": false}}}`)
|
||||
t.Setenv(environmentVariable, "correct horse battery staple")
|
||||
var output, diagnostics bytes.Buffer
|
||||
err := run([]string{"-P", "w", "-L", "10", "example.com"}, &output, &diagnostics)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := strings.TrimSpace(output.String()); len(got) != 10 {
|
||||
t.Fatalf("output length = %d, want 10 (flag must beat profile)", len(got))
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunRejectsBadProfileNames(t *testing.T) {
|
||||
withConfig(t, `{"profiles": {"w": {"login": "alice"}, "n": {}}}`)
|
||||
t.Setenv(environmentVariable, "x")
|
||||
|
||||
var output, diagnostics bytes.Buffer
|
||||
if err := run([]string{"-P", "x", "example.com"}, &output, &diagnostics); err == nil ||
|
||||
!strings.Contains(err.Error(), "unknown profile") {
|
||||
t.Fatalf("error = %v, want unknown profile", err)
|
||||
}
|
||||
if err := run([]string{"-P", "n", "example.com"}, &output, &diagnostics); err == nil ||
|
||||
!strings.Contains(err.Error(), "has no login") {
|
||||
t.Fatalf("error = %v, want missing login", err)
|
||||
}
|
||||
// A profile without a configuration file at all.
|
||||
original := configPath
|
||||
configPath = func() string { return filepath.Join(t.TempDir(), "absent.json") }
|
||||
defer func() { configPath = original }()
|
||||
if err := run([]string{"-P", "w", "example.com"}, &output, &diagnostics); err == nil ||
|
||||
!strings.Contains(err.Error(), "no configuration file") {
|
||||
t.Fatalf("error = %v, want missing configuration", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunRejectsInvalidConfig(t *testing.T) {
|
||||
withConfig(t, `{"profiles":`)
|
||||
var output, diagnostics bytes.Buffer
|
||||
if err := run([]string{"example.com", "alice", "master"}, &output, &diagnostics); err == nil {
|
||||
t.Fatal("expected error for malformed configuration")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunRejectsInvalidClearAfter(t *testing.T) {
|
||||
withConfig(t, `{"clear_after": "not-a-duration", "profiles": {"w": {"login": "alice"}}}`)
|
||||
t.Setenv(environmentVariable, "x")
|
||||
var output, diagnostics bytes.Buffer
|
||||
err := run([]string{"-P", "w", "--no-copy", "example.com"}, &output, &diagnostics)
|
||||
if err == nil || !strings.Contains(err.Error(), "clear_after") {
|
||||
t.Fatalf("error = %v, want clear_after parse failure", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVaultMasterPasswordBeatsEnvironmentAndPositional(t *testing.T) {
|
||||
if _, err := exec.LookPath("openssl"); err != nil {
|
||||
t.Skip("openssl not available")
|
||||
}
|
||||
vaultFile := filepath.Join(t.TempDir(), ".vault")
|
||||
encrypt := `printf 'my-top-secret' | openssl enc -aes-256-cbc -md sha512 -a -pbkdf2 -iter 100000 -salt -pass pass:masterpw > ` + vaultFile
|
||||
if out, err := exec.Command("sh", "-c", encrypt).CombinedOutput(); err != nil {
|
||||
t.Fatalf("openssl encrypt failed: %v: %s", err, out)
|
||||
}
|
||||
|
||||
withVaultPassphrase(t, "masterpw")
|
||||
t.Setenv(environmentVariable, "environment-must-be-ignored")
|
||||
|
||||
var output, diagnostics bytes.Buffer
|
||||
err := run([]string{"--vault", vaultFile, "example.com", "alice"}, &output, &diagnostics)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want, err := password.Generate("example.com", "alice", "my-top-secret", password.DefaultOptions())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := strings.TrimSpace(output.String()); got != want {
|
||||
t.Fatalf("output = %q, want %q", got, want)
|
||||
}
|
||||
|
||||
if err := run([]string{"--vault", vaultFile, "example.com", "alice", "master"}, &output, &diagnostics); err == nil ||
|
||||
!strings.Contains(err.Error(), "cannot be combined") {
|
||||
t.Fatalf("error = %v, want source conflict with MASTER_PASSWORD", err)
|
||||
}
|
||||
if err := run([]string{"--vault", vaultFile, "--prompt", "example.com", "alice"}, &output, &diagnostics); err == nil ||
|
||||
!strings.Contains(err.Error(), "cannot be combined") {
|
||||
t.Fatalf("error = %v, want source conflict with --prompt", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigVaultIsUsedForProfile(t *testing.T) {
|
||||
if _, err := exec.LookPath("openssl"); err != nil {
|
||||
t.Skip("openssl not available")
|
||||
}
|
||||
vaultFile := filepath.Join(t.TempDir(), ".vault")
|
||||
encrypt := `printf 'cfg-secret' | openssl enc -aes-256-cbc -md sha512 -a -pbkdf2 -iter 100000 -salt -pass pass:masterpw > ` + vaultFile
|
||||
if out, err := exec.Command("sh", "-c", encrypt).CombinedOutput(); err != nil {
|
||||
t.Fatalf("openssl encrypt failed: %v: %s", err, out)
|
||||
}
|
||||
|
||||
withConfig(t, `{"vault": "`+vaultFile+`", "profiles": {"w": {"login": "alice"}}}`)
|
||||
withVaultPassphrase(t, "masterpw")
|
||||
t.Setenv(environmentVariable, "environment-must-be-ignored")
|
||||
|
||||
var output, diagnostics bytes.Buffer
|
||||
if err := run([]string{"w", "example.com", "--no-copy"}, &output, &diagnostics); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want, err := password.Generate("example.com", "alice", "cfg-secret", password.DefaultOptions())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := strings.TrimSpace(output.String()); got != want {
|
||||
t.Fatalf("output = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandHome(t *testing.T) {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
t.Skip("no home directory")
|
||||
}
|
||||
for _, test := range []struct{ in, want string }{
|
||||
{"~", home},
|
||||
{"~/bin/.vault", filepath.Join(home, "bin", ".vault")},
|
||||
{"/abs/path", "/abs/path"},
|
||||
{"relative", "relative"},
|
||||
} {
|
||||
if got := expandHome(test.in); got != test.want {
|
||||
t.Errorf("expandHome(%q) = %q, want %q", test.in, got, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestVaultPassphraseFromPipedStdin(t *testing.T) {
|
||||
if _, err := exec.LookPath("openssl"); err != nil {
|
||||
t.Skip("openssl not available")
|
||||
}
|
||||
vaultFile := filepath.Join(t.TempDir(), ".vault")
|
||||
encrypt := `printf 'piped-secret' | openssl enc -aes-256-cbc -md sha512 -a -pbkdf2 -iter 100000 -salt -pass pass:masterpw > ` + vaultFile
|
||||
if out, err := exec.Command("sh", "-c", encrypt).CombinedOutput(); err != nil {
|
||||
t.Fatalf("openssl encrypt failed: %v: %s", err, out)
|
||||
}
|
||||
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
contents string
|
||||
}{
|
||||
{"newline", "masterpw\n"},
|
||||
{"crlf", "masterpw\r\n"},
|
||||
{"no trailing newline", "masterpw"},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
input, err := os.CreateTemp(t.TempDir(), "stdin")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := input.WriteString(test.contents); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := input.Seek(0, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
previous := os.Stdin
|
||||
os.Stdin = input
|
||||
defer func() { os.Stdin = previous }()
|
||||
|
||||
got, err := promptVaultPassphrase()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != "masterpw" {
|
||||
t.Fatalf("passphrase = %q, want %q", got, "masterpw")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
//go:build linux
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func readPassword(label string) (string, error) {
|
||||
terminal, err := os.OpenFile("/dev/tty", os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot securely prompt without a controlling terminal: %w", err)
|
||||
}
|
||||
defer terminal.Close()
|
||||
|
||||
state, err := terminalState(terminal.Fd(), syscall.TCGETS, nil)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot read terminal settings: %w", err)
|
||||
}
|
||||
noEcho := *state
|
||||
noEcho.Lflag &^= syscall.ECHO
|
||||
if _, err := terminalState(terminal.Fd(), syscall.TCSETS, &noEcho); err != nil {
|
||||
return "", fmt.Errorf("cannot disable terminal echo: %w", err)
|
||||
}
|
||||
defer func() { _, _ = terminalState(terminal.Fd(), syscall.TCSETS, state) }()
|
||||
|
||||
if _, err := fmt.Fprint(terminal, label); err != nil {
|
||||
return "", err
|
||||
}
|
||||
line, readErr := bufio.NewReader(terminal).ReadString('\n')
|
||||
fmt.Fprintln(terminal)
|
||||
if readErr != nil && len(line) == 0 {
|
||||
return "", fmt.Errorf("cannot read master password: %w", readErr)
|
||||
}
|
||||
return strings.TrimSuffix(strings.TrimSuffix(line, "\n"), "\r"), nil
|
||||
}
|
||||
|
||||
func terminalState(fd uintptr, request uintptr, replacement *syscall.Termios) (*syscall.Termios, error) {
|
||||
state := replacement
|
||||
if state == nil {
|
||||
state = new(syscall.Termios)
|
||||
}
|
||||
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, fd, request, uintptr(unsafe.Pointer(state)))
|
||||
if errno != 0 {
|
||||
return nil, errno
|
||||
}
|
||||
return state, nil
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
//go:build !linux && !darwin && !dragonfly && !freebsd && !netbsd && !openbsd && !solaris && !windows
|
||||
|
||||
package main
|
||||
|
||||
import "errors"
|
||||
|
||||
func readPassword(_ string) (string, error) {
|
||||
return "", errors.New("secure terminal prompting is not supported on this operating system; use LESSPASS_MASTER_PASSWORD")
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
//go:build darwin || dragonfly || freebsd || netbsd || openbsd || solaris
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func readPassword(label string) (string, error) {
|
||||
terminal, err := os.OpenFile("/dev/tty", os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot securely prompt without a controlling terminal: %w", err)
|
||||
}
|
||||
defer terminal.Close()
|
||||
|
||||
stty, err := exec.LookPath("stty")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot securely prompt because stty is unavailable: %w", err)
|
||||
}
|
||||
original, err := runStty(stty, terminal, "-g")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot read terminal settings: %w", err)
|
||||
}
|
||||
if _, err := runStty(stty, terminal, "-echo"); err != nil {
|
||||
return "", fmt.Errorf("cannot disable terminal echo: %w", err)
|
||||
}
|
||||
defer func() { _, _ = runStty(stty, terminal, strings.TrimSpace(original)) }()
|
||||
|
||||
if _, err := fmt.Fprint(terminal, label); err != nil {
|
||||
return "", err
|
||||
}
|
||||
line, readErr := bufio.NewReader(terminal).ReadString('\n')
|
||||
fmt.Fprintln(terminal)
|
||||
if readErr != nil && len(line) == 0 {
|
||||
return "", fmt.Errorf("cannot read master password: %w", readErr)
|
||||
}
|
||||
return strings.TrimSuffix(strings.TrimSuffix(line, "\n"), "\r"), nil
|
||||
}
|
||||
|
||||
func runStty(path string, terminal *os.File, argument string) (string, error) {
|
||||
command := exec.Command(path, argument)
|
||||
command.Stdin = terminal
|
||||
command.Stderr = terminal
|
||||
output, err := command.Output()
|
||||
return string(output), err
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
//go:build windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const enableEchoInput = 0x0004
|
||||
|
||||
var (
|
||||
kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||
getConsoleMode = kernel32.NewProc("GetConsoleMode")
|
||||
setConsoleMode = kernel32.NewProc("SetConsoleMode")
|
||||
)
|
||||
|
||||
func readPassword(label string) (string, error) {
|
||||
input, err := os.OpenFile("CONIN$", os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot securely prompt without a console: %w", err)
|
||||
}
|
||||
defer input.Close()
|
||||
output, err := os.OpenFile("CONOUT$", os.O_WRONLY, 0)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot open the console for prompting: %w", err)
|
||||
}
|
||||
defer output.Close()
|
||||
|
||||
var original uint32
|
||||
if err := windowsCall(getConsoleMode, input.Fd(), uintptr(unsafe.Pointer(&original))); err != nil {
|
||||
return "", fmt.Errorf("cannot read console settings: %w", err)
|
||||
}
|
||||
if err := windowsCall(setConsoleMode, input.Fd(), uintptr(original&^enableEchoInput)); err != nil {
|
||||
return "", fmt.Errorf("cannot disable console echo: %w", err)
|
||||
}
|
||||
defer func() { _ = windowsCall(setConsoleMode, input.Fd(), uintptr(original)) }()
|
||||
|
||||
if _, err := fmt.Fprint(output, label); err != nil {
|
||||
return "", err
|
||||
}
|
||||
line, readErr := bufio.NewReader(input).ReadString('\n')
|
||||
fmt.Fprintln(output)
|
||||
if readErr != nil && len(line) == 0 {
|
||||
return "", fmt.Errorf("cannot read master password: %w", readErr)
|
||||
}
|
||||
return strings.TrimSuffix(strings.TrimSuffix(line, "\n"), "\r"), nil
|
||||
}
|
||||
|
||||
func windowsCall(procedure *syscall.LazyProc, arguments ...uintptr) error {
|
||||
result, _, callErr := procedure.Call(arguments...)
|
||||
if result != 0 {
|
||||
return nil
|
||||
}
|
||||
if callErr != nil && callErr != syscall.Errno(0) {
|
||||
return callErr
|
||||
}
|
||||
return syscall.EINVAL
|
||||
}
|
||||
@@ -7,6 +7,10 @@ android {
|
||||
compileSdk 36
|
||||
ndkVersion "28.2.13676358"
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += '../../vendor/kryon/src/platform/android/java'
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
@@ -23,12 +27,23 @@ android {
|
||||
|
||||
def releasePassword = project.findProperty('keystore.password') ?: ""
|
||||
|
||||
def releaseKeystorePath = getKeystorePath()
|
||||
def releaseKeystore = releaseKeystorePath ? file(releaseKeystorePath) : null
|
||||
// Sign release builds only when a keystore is actually available: CI and
|
||||
// local release builds pass -Pkeystore.* properties, while clean checkouts
|
||||
// (for example an F-Droid builder) produce an unsigned APK instead.
|
||||
def signRelease = !project.hasProperty('fDroidBuild') \
|
||||
&& releaseKeystore != null && releaseKeystore.exists() \
|
||||
&& releasePassword != ""
|
||||
|
||||
signingConfigs {
|
||||
release {
|
||||
storeFile getKeystorePath() ? file(getKeystorePath()) : null
|
||||
storePassword releasePassword
|
||||
keyAlias getKeystoreAlias()
|
||||
keyPassword releasePassword
|
||||
if (signRelease) {
|
||||
storeFile releaseKeystore
|
||||
storePassword releasePassword
|
||||
keyAlias getKeystoreAlias()
|
||||
keyPassword releasePassword
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +51,9 @@ android {
|
||||
applicationId 'xyz.waozi.pass'
|
||||
minSdk 21
|
||||
targetSdk 36
|
||||
versionCode 3
|
||||
versionName "0.2.2"
|
||||
versionCode 10
|
||||
versionName "0.2.9"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
// Default to the two realistic phone targets; override with
|
||||
// -Pabi=x86_64 etc. for emulator builds.
|
||||
def abis = project.findProperty('abi') ?: 'armeabi-v7a,arm64-v8a'
|
||||
@@ -46,9 +62,18 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
splits {
|
||||
abi {
|
||||
enable = (project.findProperty('splitApks') ?: 'false').toString().toBoolean()
|
||||
reset()
|
||||
include 'armeabi-v7a', 'arm64-v8a'
|
||||
universalApk true
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
signingConfig project.hasProperty('fDroidBuild') ? null : signingConfigs.release
|
||||
signingConfig signRelease ? signingConfigs.release : null
|
||||
minifyEnabled false
|
||||
}
|
||||
debug {
|
||||
@@ -72,3 +97,9 @@ android {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
androidTestImplementation 'androidx.test:runner:1.6.2'
|
||||
androidTestImplementation 'androidx.test:rules:1.6.1'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package xyz.waozi.pass;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.ext.junit.rules.ActivityScenarioRule;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class MainActivityImeTest {
|
||||
@Rule
|
||||
public ActivityScenarioRule<TextInputBridgeHarnessActivity> activityRule =
|
||||
new ActivityScenarioRule<>(TextInputBridgeHarnessActivity.class);
|
||||
|
||||
@Test
|
||||
public void keyboardBridgeCanHideAndReopen() {
|
||||
activityRule.getScenario().onActivity(activity -> {
|
||||
int startShows = activity.getShowRequests();
|
||||
int startHides = activity.getHideRequests();
|
||||
|
||||
activity.setTextInputVisible(true);
|
||||
assertTrue(activity.isTextInputFocused());
|
||||
|
||||
activity.setTextInputVisible(false);
|
||||
activity.setTextInputVisible(true);
|
||||
|
||||
assertTrue(activity.isTextInputFocused());
|
||||
assertTrue(activity.getShowRequests() >= startShows + 2);
|
||||
assertTrue(activity.getHideRequests() >= startHides + 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputConnectionForwardsTextEditingOnce() {
|
||||
activityRule.getScenario().onActivity(activity -> {
|
||||
activity.setTextInputVisible(true);
|
||||
activity.takeCommittedText();
|
||||
activity.takeBackspaceCount();
|
||||
activity.takeEnterCount();
|
||||
|
||||
EditorInfo info = new EditorInfo();
|
||||
InputConnection connection = activity.createInputConnection(info);
|
||||
assertNotNull(connection);
|
||||
|
||||
connection.commitText("site", 1);
|
||||
connection.deleteSurroundingText(1, 0);
|
||||
connection.performEditorAction(EditorInfo.IME_ACTION_DONE);
|
||||
|
||||
assertEquals("site", activity.takeCommittedText());
|
||||
assertEquals(1, activity.takeBackspaceCount());
|
||||
assertEquals(1, activity.takeEnterCount());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application>
|
||||
<activity
|
||||
android:name="xyz.waozi.pass.TextInputBridgeHarnessActivity"
|
||||
android:theme="@android:style/Theme.DeviceDefault.NoActionBar" />
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,81 @@
|
||||
package xyz.waozi.pass;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
|
||||
import com.kryonlabs.kryon.TextInputBridge;
|
||||
|
||||
public final class TextInputBridgeHarnessActivity extends Activity {
|
||||
private TextInputBridge bridge;
|
||||
private StringBuilder committedText = new StringBuilder();
|
||||
private int backspaceCount = 0;
|
||||
private int enterCount = 0;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
bridge = new TextInputBridge(this, new TextInputBridge.Callbacks() {
|
||||
@Override
|
||||
public void commitText(int codepoint) {
|
||||
committedText.appendCodePoint(codepoint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void composition(int phase, String text, int cursor,
|
||||
int selectionLength) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void backspace() {
|
||||
backspaceCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
enterCount++;
|
||||
}
|
||||
});
|
||||
addContentView(bridge.getView(), new ViewGroup.LayoutParams(1, 1));
|
||||
}
|
||||
|
||||
void setTextInputVisible(boolean visible) {
|
||||
bridge.setVisible(visible);
|
||||
}
|
||||
|
||||
int getShowRequests() {
|
||||
return bridge.showRequestsForTest();
|
||||
}
|
||||
|
||||
int getHideRequests() {
|
||||
return bridge.hideRequestsForTest();
|
||||
}
|
||||
|
||||
boolean isTextInputFocused() {
|
||||
return bridge.hasFocusForTest();
|
||||
}
|
||||
|
||||
InputConnection createInputConnection(EditorInfo info) {
|
||||
return bridge.createInputConnectionForTest(info);
|
||||
}
|
||||
|
||||
String takeCommittedText() {
|
||||
String value = committedText.toString();
|
||||
committedText.setLength(0);
|
||||
return value;
|
||||
}
|
||||
|
||||
int takeBackspaceCount() {
|
||||
int value = backspaceCount;
|
||||
backspaceCount = 0;
|
||||
return value;
|
||||
}
|
||||
|
||||
int takeEnterCount() {
|
||||
int value = enterCount;
|
||||
enterCount = 0;
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -9,15 +9,25 @@
|
||||
android:label="@string/app_name"
|
||||
android:allowBackup="false">
|
||||
<activity
|
||||
android:name="xyz.waozi.pass.MainActivity"
|
||||
android:name="xyz.waozi.pass.PassActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize|smallestScreenSize|uiMode"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask"
|
||||
android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
|
||||
android:windowSoftInputMode="adjustNothing"
|
||||
android:windowLayoutInDisplayCutoutMode="never">
|
||||
<meta-data
|
||||
android:name="android.app.lib_name"
|
||||
android:value="main" />
|
||||
<meta-data
|
||||
android:name="com.kryonlabs.kryon.SECURE_PREFERENCES"
|
||||
android:value="pass_secure" />
|
||||
<meta-data
|
||||
android:name="com.kryonlabs.kryon.SECURE_DEFAULT_KEY_PREFIX"
|
||||
android:value="pass_master_key" />
|
||||
<meta-data
|
||||
android:name="com.kryonlabs.kryon.APP_PREFERENCES"
|
||||
android:value="pass_preferences" />
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
||||
@@ -3,15 +3,31 @@ project(Pass C)
|
||||
|
||||
set(REPO_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../../../..")
|
||||
set(KRYON_DIR "${REPO_ROOT}/vendor/kryon")
|
||||
set(KRY_GENERATED_DIR "${CMAKE_BINARY_DIR}/krygen/c")
|
||||
set(RAYLIB_DIR "${KRYON_DIR}/vendor/raylib/src")
|
||||
set(KRYON_RAYLIB_GENERATED_DIR "${CMAKE_BINARY_DIR}/kryon/raylib_generated")
|
||||
set(KRYON_COMPAT_GENERATED_HEADER "${KRYON_RAYLIB_GENERATED_DIR}/kryon_compat.generated.h")
|
||||
set(KRYON_RAYLIB_BACKEND_RENAME_HEADER "${KRYON_RAYLIB_GENERATED_DIR}/raylib_backend_rename.h")
|
||||
set(KRYON_RAYLIB_WRAPPERS_C "${KRYON_RAYLIB_GENERATED_DIR}/kryon_raylib_wrappers.c")
|
||||
set(KRYON_NULL_BACKEND_C "${KRYON_RAYLIB_GENERATED_DIR}/kryon_null_backend.c")
|
||||
set(PASS_NATIVE_DIR "${REPO_ROOT}/native")
|
||||
set(NATIVE_APP_GLUE_DIR "${ANDROID_NDK}/sources/android/native_app_glue")
|
||||
include("${KRYON_DIR}/cmake/KryonKrySources.cmake")
|
||||
|
||||
file(GLOB_RECURSE KRYON_SOURCES CONFIGURE_DEPENDS "${KRYON_DIR}/src/*.c")
|
||||
# The src/backend/ software renderer implements raylib-named functions for
|
||||
# no-raylib hosts; Android links real raylib, so compiling both is a
|
||||
# duplicate-symbol link error.
|
||||
list(FILTER KRYON_SOURCES EXCLUDE REGEX "${KRYON_DIR}/src/backend/.*")
|
||||
list(APPEND KRYON_SOURCES
|
||||
"${KRYON_DIR}/src/backend/kry_event_wait.c"
|
||||
"${KRYON_DIR}/src/backend/kry_image.c"
|
||||
"${KRYON_DIR}/src/backend/kry_image_decode.c"
|
||||
"${KRYON_DIR}/src/backend/kry_input.c"
|
||||
"${KRYON_DIR}/src/backend/kry_instance.c"
|
||||
"${KRYON_DIR}/src/backend/kry_screenshot.c"
|
||||
"${KRYON_DIR}/src/backend/kry_sw_png.c"
|
||||
"${KRYON_DIR}/src/backend/kry_surface_math.c")
|
||||
# pass uses no 2D physics; mirror the desktop Makefile's physics filter.
|
||||
list(REMOVE_ITEM KRYON_SOURCES
|
||||
"${KRYON_DIR}/src/scene/physics_world.c"
|
||||
@@ -24,9 +40,50 @@ list(FILTER KRYON_SOURCES EXCLUDE REGEX "${KRYON_DIR}/src/ksync/.*")
|
||||
list(FILTER KRYON_SOURCES EXCLUDE REGEX "${KRYON_DIR}/src/runtime_assets/.*")
|
||||
list(FILTER KRYON_SOURCES EXCLUDE REGEX "${KRYON_DIR}/src/notification/.*")
|
||||
list(REMOVE_ITEM KRYON_SOURCES "${KRYON_DIR}/src/file_dialog/file_dialog.c")
|
||||
# Keep Android builds off platform implementations for other targets. These
|
||||
# directories can contain host SDK headers or symbols unavailable to the NDK.
|
||||
list(FILTER KRYON_SOURCES EXCLUDE REGEX "${KRYON_DIR}/src/platform/desktop/.*")
|
||||
list(FILTER KRYON_SOURCES EXCLUDE REGEX "${KRYON_DIR}/src/platform/desktop_tray/.*")
|
||||
list(FILTER KRYON_SOURCES EXCLUDE REGEX "${KRYON_DIR}/src/platform/plan9/.*")
|
||||
list(FILTER KRYON_SOURCES EXCLUDE REGEX "${KRYON_DIR}/src/platform/web/.*")
|
||||
|
||||
file(GLOB_RECURSE PASS_KRY_SOURCES CONFIGURE_DEPENDS "${REPO_ROOT}/app/*.kry")
|
||||
list(SORT PASS_KRY_SOURCES)
|
||||
kryon_generate_kry_sources(PASS_KRY_GENERATED_SOURCES PASS_KRY_INCLUDE_DIR
|
||||
TARGET pass_kry_generated
|
||||
KRYON_DIR "${KRYON_DIR}"
|
||||
ROOT "${REPO_ROOT}"
|
||||
OUT_DIR "${KRY_GENERATED_DIR}"
|
||||
NO_MAIN
|
||||
SOURCES ${PASS_KRY_SOURCES}
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
"${KRYON_COMPAT_GENERATED_HEADER}"
|
||||
"${KRYON_RAYLIB_BACKEND_RENAME_HEADER}"
|
||||
"${KRYON_RAYLIB_WRAPPERS_C}"
|
||||
"${KRYON_NULL_BACKEND_C}"
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${KRYON_RAYLIB_GENERATED_DIR}"
|
||||
COMMAND ${CMAKE_COMMAND} -E env KRYON_COMPAT_AUDIO=0
|
||||
sh "${KRYON_DIR}/tools/generate-kryon-compat.sh"
|
||||
"${RAYLIB_DIR}/raylib.h"
|
||||
"${KRYON_COMPAT_GENERATED_HEADER}"
|
||||
"${KRYON_RAYLIB_BACKEND_RENAME_HEADER}"
|
||||
"${KRYON_RAYLIB_WRAPPERS_C}"
|
||||
"${KRYON_NULL_BACKEND_C}"
|
||||
DEPENDS "${KRYON_DIR}/tools/generate-kryon-compat.sh" "${RAYLIB_DIR}/raylib.h"
|
||||
VERBATIM
|
||||
)
|
||||
add_custom_target(kryon_raylib_generated DEPENDS
|
||||
"${KRYON_COMPAT_GENERATED_HEADER}"
|
||||
"${KRYON_RAYLIB_BACKEND_RENAME_HEADER}"
|
||||
"${KRYON_RAYLIB_WRAPPERS_C}"
|
||||
"${KRYON_NULL_BACKEND_C}"
|
||||
)
|
||||
|
||||
set(PASS_FONT_ASSET "vendor/kryon/fonts/noto/NotoSans-Regular.ttf")
|
||||
set(PASS_EMOJI_FONT_ASSET "gui/assets/emoji.ttf")
|
||||
set(PASS_EMOJI_FONT_ASSET "assets/fonts/emoji.ttf")
|
||||
set(PASS_EMBEDDED_ASSETS_C "${CMAKE_BINARY_DIR}/pass_embedded_assets.c")
|
||||
add_custom_command(
|
||||
OUTPUT "${PASS_EMBEDDED_ASSETS_C}"
|
||||
@@ -43,6 +100,7 @@ add_library(raylib STATIC
|
||||
"${RAYLIB_DIR}/rtext.c"
|
||||
"${RAYLIB_DIR}/raudio.c"
|
||||
)
|
||||
add_dependencies(raylib kryon_raylib_generated)
|
||||
|
||||
target_compile_definitions(raylib PRIVATE
|
||||
PLATFORM_ANDROID
|
||||
@@ -63,6 +121,7 @@ target_compile_definitions(raylib PRIVATE
|
||||
)
|
||||
|
||||
target_compile_options(raylib PRIVATE
|
||||
-include "${KRYON_RAYLIB_BACKEND_RENAME_HEADER}"
|
||||
-Os
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
@@ -75,18 +134,22 @@ target_include_directories(raylib PUBLIC
|
||||
|
||||
add_library(main SHARED
|
||||
main.c
|
||||
pass_app.c
|
||||
android_bridge.c
|
||||
"${PASS_NATIVE_DIR}/pass_core.c"
|
||||
"${PASS_NATIVE_DIR}/pass_runtime.c"
|
||||
${PASS_KRY_GENERATED_SOURCES}
|
||||
"${PASS_EMBEDDED_ASSETS_C}"
|
||||
${KRYON_SOURCES}
|
||||
"${KRYON_RAYLIB_WRAPPERS_C}"
|
||||
"${NATIVE_APP_GLUE_DIR}/android_native_app_glue.c"
|
||||
)
|
||||
add_dependencies(main pass_kry_generated kryon_raylib_generated)
|
||||
|
||||
target_include_directories(main PRIVATE
|
||||
"${KRYON_DIR}/include"
|
||||
"${KRYON_DIR}/src"
|
||||
"${PASS_KRY_INCLUDE_DIR}"
|
||||
"${PASS_NATIVE_DIR}"
|
||||
"${CMAKE_CURRENT_LIST_DIR}"
|
||||
"${NATIVE_APP_GLUE_DIR}"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,492 +0,0 @@
|
||||
/* Minimal JNI bridge for the pass Android app: safe-area insets, display
|
||||
* density, soft-keyboard visibility, and soft-keyboard text input. Modeled
|
||||
* on inbe's android_device.c / android_insets.c. */
|
||||
|
||||
#include "android_bridge.h"
|
||||
|
||||
#if ANDROID_BUILD
|
||||
|
||||
#include "kryon.h"
|
||||
#include "theme.h"
|
||||
#include "ui_dpi.h"
|
||||
|
||||
#include <android/log.h>
|
||||
#include <android_native_app_glue.h>
|
||||
#include <jni.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
extern struct android_app *GetAndroidApp(void);
|
||||
|
||||
#ifndef JNI_VERSION_1_6
|
||||
#define JNI_VERSION_1_6 0x10060000
|
||||
#endif
|
||||
|
||||
#define LOG_TAG "PASS_JNI"
|
||||
|
||||
static pthread_mutex_t bridge_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static int insets_status_bar = 0;
|
||||
static int insets_nav_bar = 0;
|
||||
static int insets_cutout_top = 0;
|
||||
static int insets_cutout_bottom = 0;
|
||||
static int insets_ready = 0;
|
||||
static float device_density = 0.0f;
|
||||
|
||||
static int
|
||||
scaled_inset(int java_px, float density)
|
||||
{
|
||||
if(density <= 0.0f)
|
||||
density = 1.0f;
|
||||
return (int)(java_px / density + 0.5f);
|
||||
}
|
||||
|
||||
static int
|
||||
activity_env(JNIEnv **env_out, JavaVM **jvm_out, jobject *activity_out)
|
||||
{
|
||||
struct android_app *app = GetAndroidApp();
|
||||
JavaVM *jvm;
|
||||
JNIEnv *env = NULL;
|
||||
int attached = 0;
|
||||
|
||||
if(env_out == NULL || jvm_out == NULL || activity_out == NULL ||
|
||||
app == NULL || app->activity == NULL || app->activity->vm == NULL ||
|
||||
app->activity->clazz == NULL)
|
||||
return -1;
|
||||
|
||||
jvm = app->activity->vm;
|
||||
if((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_6) != JNI_OK) {
|
||||
if((*jvm)->AttachCurrentThread(jvm, &env, NULL) != JNI_OK || env == NULL)
|
||||
return -1;
|
||||
attached = 1;
|
||||
}
|
||||
*env_out = env;
|
||||
*jvm_out = jvm;
|
||||
*activity_out = app->activity->clazz;
|
||||
return attached;
|
||||
}
|
||||
|
||||
static void
|
||||
activity_env_done(JNIEnv *env, JavaVM *jvm, int attached)
|
||||
{
|
||||
if(env != NULL && (*env)->ExceptionCheck(env)) {
|
||||
(*env)->ExceptionDescribe(env);
|
||||
(*env)->ExceptionClear(env);
|
||||
}
|
||||
if(attached && jvm != NULL)
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
}
|
||||
|
||||
void
|
||||
android_bridge_init(void)
|
||||
{
|
||||
pthread_mutex_lock(&bridge_mutex);
|
||||
insets_status_bar = 0;
|
||||
insets_nav_bar = 0;
|
||||
insets_cutout_top = 0;
|
||||
insets_cutout_bottom = 0;
|
||||
insets_ready = 0;
|
||||
device_density = 0.0f;
|
||||
pthread_mutex_unlock(&bridge_mutex);
|
||||
}
|
||||
|
||||
static Color
|
||||
color_from_argb(jint argb)
|
||||
{
|
||||
Color color;
|
||||
|
||||
color.a = (unsigned char)((argb >> 24) & 0xff);
|
||||
color.r = (unsigned char)((argb >> 16) & 0xff);
|
||||
color.g = (unsigned char)((argb >> 8) & 0xff);
|
||||
color.b = (unsigned char)(argb & 0xff);
|
||||
if(color.a == 0)
|
||||
color.a = 0xff;
|
||||
return color;
|
||||
}
|
||||
|
||||
void
|
||||
android_bridge_apply_system_theme(void)
|
||||
{
|
||||
JavaVM *jvm;
|
||||
JNIEnv *env = NULL;
|
||||
jobject activity;
|
||||
jclass activity_class;
|
||||
jmethodID method;
|
||||
jintArray array;
|
||||
jint values[9];
|
||||
jsize len;
|
||||
int attached;
|
||||
|
||||
attached = activity_env(&env, &jvm, &activity);
|
||||
if(attached < 0)
|
||||
return;
|
||||
|
||||
memset(values, 0, sizeof(values));
|
||||
activity_class = (*env)->GetObjectClass(env, activity);
|
||||
if(activity_class == NULL)
|
||||
goto done;
|
||||
method = (*env)->GetMethodID(env, activity_class, "systemThemeColors", "()[I");
|
||||
if(method == NULL) {
|
||||
__android_log_write(ANDROID_LOG_ERROR, LOG_TAG, "systemThemeColors not found");
|
||||
goto done;
|
||||
}
|
||||
array = (jintArray)(*env)->CallObjectMethod(env, activity, method);
|
||||
if(array == NULL)
|
||||
goto done;
|
||||
len = (*env)->GetArrayLength(env, array);
|
||||
if(len < 9)
|
||||
goto done;
|
||||
(*env)->GetIntArrayRegion(env, array, 0, 9, values);
|
||||
SetSystemThemePalette("Android",
|
||||
color_from_argb(values[1]),
|
||||
color_from_argb(values[2]),
|
||||
color_from_argb(values[3]),
|
||||
color_from_argb(values[4]),
|
||||
color_from_argb(values[5]),
|
||||
color_from_argb(values[6]),
|
||||
color_from_argb(values[7]),
|
||||
color_from_argb(values[8]),
|
||||
values[0] != 0,
|
||||
1);
|
||||
|
||||
done:
|
||||
activity_env_done(env, jvm, attached);
|
||||
}
|
||||
|
||||
int
|
||||
android_bridge_top_reserved(void)
|
||||
{
|
||||
int status, cutout, top, ready;
|
||||
float density;
|
||||
|
||||
pthread_mutex_lock(&bridge_mutex);
|
||||
status = insets_status_bar;
|
||||
cutout = insets_cutout_top;
|
||||
density = device_density;
|
||||
ready = insets_ready;
|
||||
pthread_mutex_unlock(&bridge_mutex);
|
||||
|
||||
if(!ready)
|
||||
return 28; /* conservative status-bar guess until Java reports */
|
||||
top = status > cutout ? status : cutout;
|
||||
return scaled_inset(top, density);
|
||||
}
|
||||
|
||||
int
|
||||
android_bridge_bottom_reserved(void)
|
||||
{
|
||||
int nav, cutout, bottom, ready;
|
||||
float density;
|
||||
|
||||
pthread_mutex_lock(&bridge_mutex);
|
||||
nav = insets_nav_bar;
|
||||
cutout = insets_cutout_bottom;
|
||||
density = device_density;
|
||||
ready = insets_ready;
|
||||
pthread_mutex_unlock(&bridge_mutex);
|
||||
|
||||
if(!ready)
|
||||
return 48; /* conservative nav-bar guess until Java reports */
|
||||
bottom = nav > cutout ? nav : cutout;
|
||||
return scaled_inset(bottom, density);
|
||||
}
|
||||
|
||||
void
|
||||
android_bridge_set_soft_keyboard(int visible)
|
||||
{
|
||||
JavaVM *jvm;
|
||||
JNIEnv *env = NULL;
|
||||
jobject activity;
|
||||
jclass activity_class;
|
||||
jmethodID method;
|
||||
int attached;
|
||||
|
||||
attached = activity_env(&env, &jvm, &activity);
|
||||
if(attached < 0)
|
||||
return;
|
||||
|
||||
activity_class = (*env)->GetObjectClass(env, activity);
|
||||
if(activity_class == NULL)
|
||||
goto done;
|
||||
|
||||
method = (*env)->GetMethodID(env, activity_class, "setSoftKeyboardVisible", "(Z)V");
|
||||
if(method == NULL) {
|
||||
__android_log_write(ANDROID_LOG_ERROR, LOG_TAG, "setSoftKeyboardVisible not found");
|
||||
goto done;
|
||||
}
|
||||
|
||||
(*env)->CallVoidMethod(env, activity, method, visible ? JNI_TRUE : JNI_FALSE);
|
||||
|
||||
done:
|
||||
activity_env_done(env, jvm, attached);
|
||||
}
|
||||
|
||||
static int
|
||||
call_boolean_method(const char *name)
|
||||
{
|
||||
JavaVM *jvm;
|
||||
JNIEnv *env = NULL;
|
||||
jobject activity;
|
||||
jclass activity_class;
|
||||
jmethodID method;
|
||||
int attached;
|
||||
int result = 0;
|
||||
|
||||
attached = activity_env(&env, &jvm, &activity);
|
||||
if(attached < 0)
|
||||
return 0;
|
||||
activity_class = (*env)->GetObjectClass(env, activity);
|
||||
if(activity_class == NULL)
|
||||
goto done;
|
||||
method = (*env)->GetMethodID(env, activity_class, name, "()Z");
|
||||
if(method == NULL)
|
||||
goto done;
|
||||
result = (*env)->CallBooleanMethod(env, activity, method) ? 1 : 0;
|
||||
|
||||
done:
|
||||
activity_env_done(env, jvm, attached);
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
android_bridge_biometric_available(void)
|
||||
{
|
||||
return call_boolean_method("isBiometricAvailable");
|
||||
}
|
||||
|
||||
int
|
||||
android_bridge_biometric_setup_required(void)
|
||||
{
|
||||
return call_boolean_method("isBiometricSetupRequired");
|
||||
}
|
||||
|
||||
int
|
||||
android_bridge_master_saved(void)
|
||||
{
|
||||
return call_boolean_method("hasStoredMasterPassword");
|
||||
}
|
||||
|
||||
int
|
||||
android_bridge_master_biometric(void)
|
||||
{
|
||||
return call_boolean_method("isStoredMasterBiometric");
|
||||
}
|
||||
|
||||
void
|
||||
android_bridge_save_master(const char *master, int require_biometric)
|
||||
{
|
||||
JavaVM *jvm;
|
||||
JNIEnv *env = NULL;
|
||||
jobject activity;
|
||||
jclass activity_class;
|
||||
jmethodID method;
|
||||
jstring jmaster;
|
||||
int attached;
|
||||
|
||||
attached = activity_env(&env, &jvm, &activity);
|
||||
if(attached < 0)
|
||||
return;
|
||||
activity_class = (*env)->GetObjectClass(env, activity);
|
||||
if(activity_class == NULL)
|
||||
goto done;
|
||||
method = (*env)->GetMethodID(env, activity_class, "saveMasterPassword", "(Ljava/lang/String;Z)V");
|
||||
if(method == NULL)
|
||||
goto done;
|
||||
jmaster = (*env)->NewStringUTF(env, master != NULL ? master : "");
|
||||
if(jmaster == NULL)
|
||||
goto done;
|
||||
(*env)->CallVoidMethod(env, activity, method, jmaster, require_biometric ? JNI_TRUE : JNI_FALSE);
|
||||
(*env)->DeleteLocalRef(env, jmaster);
|
||||
|
||||
done:
|
||||
activity_env_done(env, jvm, attached);
|
||||
}
|
||||
|
||||
static void
|
||||
call_void_method(const char *name)
|
||||
{
|
||||
JavaVM *jvm;
|
||||
JNIEnv *env = NULL;
|
||||
jobject activity;
|
||||
jclass activity_class;
|
||||
jmethodID method;
|
||||
int attached;
|
||||
|
||||
attached = activity_env(&env, &jvm, &activity);
|
||||
if(attached < 0)
|
||||
return;
|
||||
activity_class = (*env)->GetObjectClass(env, activity);
|
||||
if(activity_class == NULL)
|
||||
goto done;
|
||||
method = (*env)->GetMethodID(env, activity_class, name, "()V");
|
||||
if(method == NULL)
|
||||
goto done;
|
||||
(*env)->CallVoidMethod(env, activity, method);
|
||||
|
||||
done:
|
||||
activity_env_done(env, jvm, attached);
|
||||
}
|
||||
|
||||
void
|
||||
android_bridge_unlock_master(void)
|
||||
{
|
||||
call_void_method("unlockMasterPassword");
|
||||
}
|
||||
|
||||
void
|
||||
android_bridge_clear_master(void)
|
||||
{
|
||||
call_void_method("clearMasterPassword");
|
||||
}
|
||||
|
||||
int
|
||||
android_bridge_secure_status(void)
|
||||
{
|
||||
JavaVM *jvm;
|
||||
JNIEnv *env = NULL;
|
||||
jobject activity;
|
||||
jclass activity_class;
|
||||
jmethodID method;
|
||||
int attached;
|
||||
int result = 0;
|
||||
|
||||
attached = activity_env(&env, &jvm, &activity);
|
||||
if(attached < 0)
|
||||
return 0;
|
||||
activity_class = (*env)->GetObjectClass(env, activity);
|
||||
if(activity_class == NULL)
|
||||
goto done;
|
||||
method = (*env)->GetMethodID(env, activity_class, "secureMasterStatus", "()I");
|
||||
if(method == NULL)
|
||||
goto done;
|
||||
result = (int)(*env)->CallIntMethod(env, activity, method);
|
||||
|
||||
done:
|
||||
activity_env_done(env, jvm, attached);
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
android_bridge_take_secure_result(char *out, int out_size)
|
||||
{
|
||||
JavaVM *jvm;
|
||||
JNIEnv *env = NULL;
|
||||
jobject activity;
|
||||
jclass activity_class;
|
||||
jmethodID method;
|
||||
jstring result;
|
||||
const char *chars;
|
||||
int attached;
|
||||
int status = 0;
|
||||
|
||||
if(out != NULL && out_size > 0)
|
||||
out[0] = '\0';
|
||||
attached = activity_env(&env, &jvm, &activity);
|
||||
if(attached < 0)
|
||||
return 0;
|
||||
activity_class = (*env)->GetObjectClass(env, activity);
|
||||
if(activity_class == NULL)
|
||||
goto done;
|
||||
method = (*env)->GetMethodID(env, activity_class, "secureMasterStatus", "()I");
|
||||
if(method == NULL)
|
||||
goto done;
|
||||
status = (int)(*env)->CallIntMethod(env, activity, method);
|
||||
method = (*env)->GetMethodID(env, activity_class, "takeSecureMasterResult", "()Ljava/lang/String;");
|
||||
if(method == NULL)
|
||||
goto done;
|
||||
result = (jstring)(*env)->CallObjectMethod(env, activity, method);
|
||||
if(result == NULL)
|
||||
goto done;
|
||||
chars = (*env)->GetStringUTFChars(env, result, NULL);
|
||||
if(chars != NULL) {
|
||||
if(out != NULL && out_size > 0)
|
||||
snprintf(out, (size_t)out_size, "%s", chars);
|
||||
(*env)->ReleaseStringUTFChars(env, result, chars);
|
||||
}
|
||||
(*env)->DeleteLocalRef(env, result);
|
||||
|
||||
done:
|
||||
activity_env_done(env, jvm, attached);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* ---- Java -> C natives (exported JNI symbols; RegisterNatives from
|
||||
* JNI_OnLoad resolves through the boot loader here and does not bind to the
|
||||
* activity's class, so we rely on standard dlsym resolution instead) ---- */
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_xyz_waozi_pass_MainActivity_nativeSetInsets(JNIEnv *env, jobject thiz,
|
||||
jint status_bar, jint nav_bar,
|
||||
jint cutout_left, jint cutout_top,
|
||||
jint cutout_right, jint cutout_bottom)
|
||||
{
|
||||
(void)env;
|
||||
(void)thiz;
|
||||
(void)cutout_left;
|
||||
(void)cutout_right;
|
||||
|
||||
pthread_mutex_lock(&bridge_mutex);
|
||||
insets_status_bar = status_bar;
|
||||
insets_nav_bar = nav_bar;
|
||||
insets_cutout_top = cutout_top;
|
||||
insets_cutout_bottom = cutout_bottom;
|
||||
insets_ready = 1;
|
||||
pthread_mutex_unlock(&bridge_mutex);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_xyz_waozi_pass_MainActivity_nativeSetDeviceDensity(JNIEnv *env, jobject thiz, jfloat density)
|
||||
{
|
||||
(void)env;
|
||||
(void)thiz;
|
||||
|
||||
if(density <= 0.0f)
|
||||
return;
|
||||
pthread_mutex_lock(&bridge_mutex);
|
||||
device_density = density;
|
||||
pthread_mutex_unlock(&bridge_mutex);
|
||||
SetUIDeviceDensity(density);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_xyz_waozi_pass_MainActivity_nativeTextInputCommit(JNIEnv *env, jobject thiz, jint codepoint)
|
||||
{
|
||||
(void)env;
|
||||
(void)thiz;
|
||||
QueueUITextInputCodepoint((int)codepoint);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_xyz_waozi_pass_MainActivity_nativeTextInputBackspace(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
(void)env;
|
||||
(void)thiz;
|
||||
QueueUITextInputBackspace();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_xyz_waozi_pass_MainActivity_nativeTextInputEnter(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
(void)env;
|
||||
(void)thiz;
|
||||
QueueUITextInputEnter();
|
||||
}
|
||||
|
||||
#else /* !ANDROID_BUILD */
|
||||
|
||||
void android_bridge_init(void) {}
|
||||
void android_bridge_apply_system_theme(void) {}
|
||||
int android_bridge_top_reserved(void) { return 0; }
|
||||
int android_bridge_bottom_reserved(void) { return 0; }
|
||||
void android_bridge_set_soft_keyboard(int visible) { (void)visible; }
|
||||
int android_bridge_biometric_available(void) { return 0; }
|
||||
int android_bridge_biometric_setup_required(void) { return 0; }
|
||||
int android_bridge_master_saved(void) { return 0; }
|
||||
int android_bridge_master_biometric(void) { return 0; }
|
||||
void android_bridge_save_master(const char *master, int require_biometric) { (void)master; (void)require_biometric; }
|
||||
void android_bridge_unlock_master(void) {}
|
||||
void android_bridge_clear_master(void) {}
|
||||
int android_bridge_secure_status(void) { return 0; }
|
||||
int android_bridge_take_secure_result(char *out, int out_size) { if(out != NULL && out_size > 0) out[0] = '\0'; return 0; }
|
||||
|
||||
#endif
|
||||
@@ -1,35 +0,0 @@
|
||||
#ifndef PASS_ANDROID_BRIDGE_H
|
||||
#define PASS_ANDROID_BRIDGE_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Call once before InitWindow. */
|
||||
void android_bridge_init(void);
|
||||
void android_bridge_apply_system_theme(void);
|
||||
|
||||
/* Safe-area insets converted to UI units (java px / density). Returns 0
|
||||
* until Java has reported real values; callers should treat 0 as "unknown"
|
||||
* and keep a conservative margin. */
|
||||
int android_bridge_top_reserved(void);
|
||||
int android_bridge_bottom_reserved(void);
|
||||
|
||||
/* Shows or hides the soft keyboard through the activity. */
|
||||
void android_bridge_set_soft_keyboard(int visible);
|
||||
|
||||
int android_bridge_biometric_available(void);
|
||||
int android_bridge_biometric_setup_required(void);
|
||||
int android_bridge_master_saved(void);
|
||||
int android_bridge_master_biometric(void);
|
||||
void android_bridge_save_master(const char *master, int require_biometric);
|
||||
void android_bridge_unlock_master(void);
|
||||
void android_bridge_clear_master(void);
|
||||
int android_bridge_secure_status(void);
|
||||
int android_bridge_take_secure_result(char *out, int out_size);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -9,8 +9,9 @@
|
||||
#include "ui_scaling.h"
|
||||
#include "ui_text.h"
|
||||
|
||||
#include "android_bridge.h"
|
||||
#include "pass_app.h"
|
||||
#include "android_host.h"
|
||||
#include "app/pass.h"
|
||||
#include "pass_runtime.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -21,7 +22,7 @@
|
||||
#endif
|
||||
|
||||
static const char *const FONT_ASSET_PATH = "vendor/kryon/fonts/noto/NotoSans-Regular.ttf";
|
||||
static const char *const EMOJI_FONT_ASSET_PATH = "gui/assets/emoji.ttf";
|
||||
static const char *const EMOJI_FONT_ASSET_PATH = "assets/fonts/emoji.ttf";
|
||||
|
||||
/* Kryon's shape drawing rides on a 1x1 white texture so rectangles tint
|
||||
* cleanly on the GL ES surface (same setup inbe performs on Android). */
|
||||
@@ -64,7 +65,7 @@ setup_emoji_font(void)
|
||||
{
|
||||
const EmbeddedAsset *asset = GetEmbeddedAsset(EMOJI_FONT_ASSET_PATH);
|
||||
int codepoint_count = 0;
|
||||
const int *codepoints = pass_app_master_emoji_codepoints(&codepoint_count);
|
||||
const int *codepoints = pass_runtime_master_emoji_codepoints(&codepoint_count);
|
||||
|
||||
if(asset == NULL || asset->data == NULL || asset->size == 0) {
|
||||
TraceLog(LOG_WARNING, "PASS: missing embedded emoji font asset");
|
||||
@@ -81,19 +82,26 @@ setup_emoji_font(void)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
PassApp *app;
|
||||
int window_width = 720;
|
||||
int window_height = 740;
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
#if ANDROID_BUILD
|
||||
__android_log_write(ANDROID_LOG_INFO, "PASS_MAIN", "main start");
|
||||
android_bridge_init();
|
||||
AndroidHostInit();
|
||||
SetAndroidViewportPolicy(AndroidViewportPolicyFull());
|
||||
if(chdir("/data/user/0/xyz.waozi.pass/files") != 0)
|
||||
TraceLog(LOG_WARNING, "PASS: failed to switch to files directory");
|
||||
window_width = 0;
|
||||
window_height = 0;
|
||||
#elif defined(PLATFORM_WEB)
|
||||
SetConfigFlags(GetWebWindowFlags());
|
||||
GetWebViewportSize(window_width, window_height, &window_width, &window_height);
|
||||
#endif
|
||||
|
||||
InitWindow(0, 0, "pass");
|
||||
InitWindow(window_width, window_height, "Pass");
|
||||
if(!IsWindowReady()) {
|
||||
TraceLog(LOG_ERROR, "PASS: InitWindow failed");
|
||||
return 1;
|
||||
@@ -101,32 +109,28 @@ main(int argc, char **argv)
|
||||
InitUIDPI();
|
||||
SetThemeStyle(THEME_STYLE_MATERIAL);
|
||||
SetCurrentTheme(GetDefaultThemeForThemeStyle(THEME_STYLE_MATERIAL), 0);
|
||||
android_bridge_apply_system_theme();
|
||||
SetThemeSource(THEME_SOURCE_SYSTEM);
|
||||
AndroidHostApplySystemTheme();
|
||||
SetThemeMode(THEME_MODE_SYSTEM);
|
||||
SetThemeSource(THEME_SOURCE_SYSTEM);
|
||||
ApplyCurrentUITheme();
|
||||
setup_ui_font();
|
||||
setup_emoji_font();
|
||||
setup_shapes_texture();
|
||||
SetUITextInputPlatformCallback(android_bridge_set_soft_keyboard);
|
||||
SetTextInputPlatformCallback(AndroidHostSetSoftKeyboardVisible);
|
||||
SetTargetFPS(60);
|
||||
|
||||
app = pass_app();
|
||||
pass_runtime_init();
|
||||
TraceLog(LOG_INFO, "PASS: app ready");
|
||||
while(!WindowShouldClose()) {
|
||||
int width = GetScreenWidth();
|
||||
int height = GetScreenHeight();
|
||||
Vector2 scale = GetWindowScaleDPI();
|
||||
float dpi = scale.x > 0.0f ? scale.x : 1.0f;
|
||||
|
||||
BeginDrawing();
|
||||
BeginUIFrame(width, height, dpi);
|
||||
pass_app_draw(app, width, height, dpi,
|
||||
android_bridge_top_reserved(),
|
||||
android_bridge_bottom_reserved());
|
||||
BeginFrame();
|
||||
BeginUIFrame(GetFrameWidth(), GetFrameHeight(), GetFrameScale());
|
||||
pass_runtime_tick();
|
||||
pass_frame();
|
||||
EndUIFrame();
|
||||
EndDrawing();
|
||||
EndFrame();
|
||||
}
|
||||
|
||||
pass_app_shutdown(app);
|
||||
pass_runtime_shutdown();
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifndef PASS_APP_H
|
||||
#define PASS_APP_H
|
||||
|
||||
typedef struct PassApp PassApp;
|
||||
|
||||
PassApp *pass_app(void);
|
||||
const int *pass_app_master_emoji_codepoints(int *count);
|
||||
|
||||
/* Draws one frame. Surface sizes are physical pixels; dpi is the display
|
||||
* scale. top/bottom_reserved are safe-area insets in UI units (dp). */
|
||||
void pass_app_draw(PassApp *app, int surface_w, int surface_h, float dpi,
|
||||
int top_reserved, int bottom_reserved);
|
||||
|
||||
/* Clears secrets held in memory. */
|
||||
void pass_app_shutdown(PassApp *app);
|
||||
|
||||
#endif
|
||||
@@ -1,498 +0,0 @@
|
||||
package xyz.waozi.pass;
|
||||
|
||||
import android.app.NativeActivity;
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Insets;
|
||||
import android.hardware.biometrics.BiometricPrompt;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.CancellationSignal;
|
||||
import android.security.keystore.KeyGenParameterSpec;
|
||||
import android.security.keystore.KeyProperties;
|
||||
import android.util.TypedValue;
|
||||
import android.view.DisplayCutout;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.WindowInsets;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.content.Context;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.GCMParameterSpec;
|
||||
|
||||
/**
|
||||
* NativeActivity glue for the kryon UI: routes soft-keyboard input and
|
||||
* window insets to the native side. Modeled on inbe's MainActivity.
|
||||
*/
|
||||
public class MainActivity extends NativeActivity {
|
||||
private static final String SECURE_PREFS = "pass_secure";
|
||||
private static final String KEY_ALIAS = "pass_master_key";
|
||||
private static final String PREF_CIPHERTEXT = "master_ciphertext";
|
||||
private static final String PREF_IV = "master_iv";
|
||||
private static final String PREF_BIOMETRIC = "master_biometric";
|
||||
private static final int SECURE_IDLE = 0;
|
||||
private static final int SECURE_PENDING = 1;
|
||||
private static final int SECURE_OK = 2;
|
||||
private static final int SECURE_ERROR = 3;
|
||||
|
||||
static {
|
||||
// Associate libmain with this class's loader so ART can resolve the
|
||||
// native methods below (NativeActivity loads it via the boot loader).
|
||||
System.loadLibrary("main");
|
||||
}
|
||||
|
||||
private int lastDeleteRepeatCount = -1;
|
||||
private final Object secureLock = new Object();
|
||||
private int secureStatus = SECURE_IDLE;
|
||||
private String secureResult = "";
|
||||
|
||||
private native void nativeSetInsets(int status, int nav,
|
||||
int cutoutLeft, int cutoutTop, int cutoutRight, int cutoutBottom);
|
||||
private native void nativeSetDeviceDensity(float density);
|
||||
private native void nativeTextInputCommit(int codepoint);
|
||||
private native void nativeTextInputBackspace();
|
||||
private native void nativeTextInputEnter();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
applySystemBars();
|
||||
setupInsetsListener();
|
||||
}
|
||||
|
||||
public int[] systemThemeColors() {
|
||||
boolean dark = (getResources().getConfiguration().uiMode
|
||||
& Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
|
||||
int background = dark ? 0xFF141218 : 0xFFFFFBFE;
|
||||
int surface = dark ? 0xFF211F26 : 0xFFF7F2FA;
|
||||
int text = dark ? 0xFFE6E0E9 : 0xFF1D1B20;
|
||||
int accent = resolveThemeColor(android.R.attr.colorAccent,
|
||||
dark ? 0xFFD0BCFF : 0xFF6750A4);
|
||||
int control = dark ? 0xFFE6E0E9 : 0xFF1D1B20;
|
||||
int button = blend(accent, background, dark ? 65 : 80);
|
||||
int buttonHover = blend(accent, background, dark ? 45 : 60);
|
||||
|
||||
return new int[] {
|
||||
dark ? 1 : 0,
|
||||
background,
|
||||
surface,
|
||||
text,
|
||||
accent,
|
||||
button,
|
||||
buttonHover,
|
||||
control,
|
||||
accent
|
||||
};
|
||||
}
|
||||
|
||||
private void applySystemBars() {
|
||||
int[] colors = systemThemeColors();
|
||||
boolean dark = colors[0] != 0;
|
||||
getWindow().setStatusBarColor(colors[1]);
|
||||
getWindow().setNavigationBarColor(colors[1]);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
int flags = getWindow().getDecorView().getSystemUiVisibility();
|
||||
if (!dark) {
|
||||
flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
flags |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
|
||||
}
|
||||
} else {
|
||||
flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
flags &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
|
||||
}
|
||||
}
|
||||
getWindow().getDecorView().setSystemUiVisibility(flags);
|
||||
}
|
||||
}
|
||||
|
||||
private int resolveThemeColor(int attr, int fallback) {
|
||||
TypedValue value = new TypedValue();
|
||||
if (!getTheme().resolveAttribute(attr, value, true)) {
|
||||
return fallback;
|
||||
}
|
||||
if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT
|
||||
&& value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
|
||||
return value.data;
|
||||
}
|
||||
if (value.resourceId != 0) {
|
||||
try {
|
||||
ColorStateList list;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
list = getResources().getColorStateList(value.resourceId, getTheme());
|
||||
} else {
|
||||
list = getResources().getColorStateList(value.resourceId);
|
||||
}
|
||||
if (list != null) {
|
||||
return list.getDefaultColor();
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
private static int blend(int from, int to, int percentTo) {
|
||||
int p = Math.max(0, Math.min(100, percentTo));
|
||||
int a = (((from >>> 24) & 0xff) * (100 - p) + ((to >>> 24) & 0xff) * p) / 100;
|
||||
int r = (((from >>> 16) & 0xff) * (100 - p) + ((to >>> 16) & 0xff) * p) / 100;
|
||||
int g = (((from >>> 8) & 0xff) * (100 - p) + ((to >>> 8) & 0xff) * p) / 100;
|
||||
int b = ((from & 0xff) * (100 - p) + (to & 0xff) * p) / 100;
|
||||
return (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
public boolean hasStoredMasterPassword() {
|
||||
SharedPreferences prefs = getSharedPreferences(SECURE_PREFS, MODE_PRIVATE);
|
||||
return prefs.contains(PREF_CIPHERTEXT) && prefs.contains(PREF_IV);
|
||||
}
|
||||
|
||||
public boolean isStoredMasterBiometric() {
|
||||
return getSharedPreferences(SECURE_PREFS, MODE_PRIVATE).getBoolean(PREF_BIOMETRIC, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean isBiometricAvailable() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false;
|
||||
try {
|
||||
FingerprintManager fm = (FingerprintManager)getSystemService(Context.FINGERPRINT_SERVICE);
|
||||
if (fm != null && fm.isHardwareDetected() && fm.hasEnrolledFingerprints()) return true;
|
||||
} catch (SecurityException ignored) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean isBiometricSetupRequired() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false;
|
||||
try {
|
||||
FingerprintManager fm = (FingerprintManager)getSystemService(Context.FINGERPRINT_SERVICE);
|
||||
if (fm == null || !fm.isHardwareDetected()) return false;
|
||||
KeyguardManager km = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
|
||||
return !fm.hasEnrolledFingerprints() || km == null || !km.isDeviceSecure();
|
||||
} catch (SecurityException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private String biometricUnavailableMessage() {
|
||||
if (isBiometricSetupRequired()) {
|
||||
return "Set up Android screen lock and fingerprint first";
|
||||
}
|
||||
return "Biometric unlock is not available on this device";
|
||||
}
|
||||
|
||||
public int secureMasterStatus() {
|
||||
synchronized (secureLock) {
|
||||
return secureStatus;
|
||||
}
|
||||
}
|
||||
|
||||
public String takeSecureMasterResult() {
|
||||
synchronized (secureLock) {
|
||||
String value = secureResult == null ? "" : secureResult;
|
||||
secureResult = "";
|
||||
secureStatus = SECURE_IDLE;
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public void saveMasterPassword(final String master, final boolean requireBiometric) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (master == null || master.length() == 0) {
|
||||
setSecureError("Enter a master password first");
|
||||
return;
|
||||
}
|
||||
if (requireBiometric && !isBiometricAvailable()) {
|
||||
setSecureError(biometricUnavailableMessage());
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, getOrCreateMasterKey());
|
||||
byte[] encrypted = cipher.doFinal(master.getBytes(StandardCharsets.UTF_8));
|
||||
byte[] iv = cipher.getIV();
|
||||
if (iv == null || iv.length == 0) {
|
||||
setSecureError("Save failed: missing encryption IV");
|
||||
return;
|
||||
}
|
||||
|
||||
SharedPreferences.Editor editor = getSharedPreferences(SECURE_PREFS, MODE_PRIVATE).edit();
|
||||
editor.putString(PREF_IV, b64(iv));
|
||||
editor.putString(PREF_CIPHERTEXT, b64(encrypted));
|
||||
editor.putBoolean(PREF_BIOMETRIC, requireBiometric);
|
||||
editor.apply();
|
||||
setSecureOk("Master password saved");
|
||||
} catch (Exception e) {
|
||||
setSecureError("Save failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void unlockMasterPassword() {
|
||||
if (!hasStoredMasterPassword()) {
|
||||
setSecureError("No saved master password");
|
||||
return;
|
||||
}
|
||||
if (isStoredMasterBiometric()) {
|
||||
authenticateThenDecrypt();
|
||||
return;
|
||||
}
|
||||
decryptStoredMaster();
|
||||
}
|
||||
|
||||
public void clearMasterPassword() {
|
||||
getSharedPreferences(SECURE_PREFS, MODE_PRIVATE).edit().clear().apply();
|
||||
setSecureOk("Saved master password removed");
|
||||
}
|
||||
|
||||
private void authenticateThenDecrypt() {
|
||||
if (!isBiometricAvailable()) {
|
||||
setSecureError(biometricUnavailableMessage());
|
||||
return;
|
||||
}
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
||||
setSecureError("Biometric prompt requires Android 9 or newer");
|
||||
return;
|
||||
}
|
||||
synchronized (secureLock) {
|
||||
secureStatus = SECURE_PENDING;
|
||||
secureResult = "Waiting for biometric unlock";
|
||||
}
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Executor executor = new Executor() {
|
||||
@Override
|
||||
public void execute(Runnable command) {
|
||||
runOnUiThread(command);
|
||||
}
|
||||
};
|
||||
BiometricPrompt prompt = new BiometricPrompt.Builder(MainActivity.this)
|
||||
.setTitle("Unlock master password")
|
||||
.setSubtitle("Use your fingerprint or device credential")
|
||||
.setDescription("pass will decrypt the saved master password after unlock")
|
||||
.setNegativeButton("Cancel", executor, (dialog, which) -> setSecureError("Unlock canceled"))
|
||||
.build();
|
||||
prompt.authenticate(new CancellationSignal(), executor,
|
||||
new BiometricPrompt.AuthenticationCallback() {
|
||||
@Override
|
||||
public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) {
|
||||
decryptStoredMaster();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationError(int errorCode, CharSequence errString) {
|
||||
setSecureError(errString == null ? "Unlock failed" : errString.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationFailed() {
|
||||
setSecureError("Biometric unlock failed");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void decryptStoredMaster() {
|
||||
try {
|
||||
SharedPreferences prefs = getSharedPreferences(SECURE_PREFS, MODE_PRIVATE);
|
||||
String ivText = prefs.getString(PREF_IV, "");
|
||||
String encryptedText = prefs.getString(PREF_CIPHERTEXT, "");
|
||||
if (ivText.length() == 0 || encryptedText.length() == 0) {
|
||||
setSecureError("No saved master password");
|
||||
return;
|
||||
}
|
||||
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, getOrCreateMasterKey(), new GCMParameterSpec(128, unb64(ivText)));
|
||||
byte[] decrypted = cipher.doFinal(unb64(encryptedText));
|
||||
setSecureOk(new String(decrypted, StandardCharsets.UTF_8));
|
||||
} catch (Exception e) {
|
||||
setSecureError("Unlock failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private SecretKey getOrCreateMasterKey() throws Exception {
|
||||
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
|
||||
keyStore.load(null);
|
||||
if (keyStore.containsAlias(KEY_ALIAS)) {
|
||||
return (SecretKey)keyStore.getKey(KEY_ALIAS, null);
|
||||
}
|
||||
KeyGenerator generator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
|
||||
KeyGenParameterSpec spec = new KeyGenParameterSpec.Builder(
|
||||
KEY_ALIAS, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
|
||||
.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
|
||||
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
|
||||
.setRandomizedEncryptionRequired(true)
|
||||
.build();
|
||||
generator.init(spec);
|
||||
return generator.generateKey();
|
||||
}
|
||||
|
||||
private void setSecureOk(String value) {
|
||||
synchronized (secureLock) {
|
||||
secureStatus = SECURE_OK;
|
||||
secureResult = value == null ? "" : value;
|
||||
}
|
||||
}
|
||||
|
||||
private void setSecureError(String value) {
|
||||
synchronized (secureLock) {
|
||||
secureStatus = SECURE_ERROR;
|
||||
secureResult = value == null ? "Secure storage failed" : value;
|
||||
}
|
||||
}
|
||||
|
||||
private static String b64(byte[] data) {
|
||||
return android.util.Base64.encodeToString(data, android.util.Base64.NO_WRAP);
|
||||
}
|
||||
|
||||
private static byte[] unb64(String text) {
|
||||
return android.util.Base64.decode(text, android.util.Base64.NO_WRAP);
|
||||
}
|
||||
|
||||
public void setSoftKeyboardVisible(final boolean visible) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
InputMethodManager imm =
|
||||
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
View view = getWindow() != null ? getWindow().getDecorView() : null;
|
||||
if (imm == null || view == null) return;
|
||||
|
||||
if (visible) {
|
||||
view.requestFocus();
|
||||
imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
|
||||
} else {
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
if (event != null && event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
int keyCode = event.getKeyCode();
|
||||
if (keyCode == KeyEvent.KEYCODE_DEL) {
|
||||
int repeatCount = event.getRepeatCount();
|
||||
int deleteCount = lastDeleteRepeatCount < 0
|
||||
? 1
|
||||
: Math.max(1, repeatCount - lastDeleteRepeatCount);
|
||||
lastDeleteRepeatCount = repeatCount;
|
||||
for (int i = 0; i < deleteCount; i++) {
|
||||
nativeTextInputBackspace();
|
||||
}
|
||||
} else if (keyCode == KeyEvent.KEYCODE_ENTER ||
|
||||
keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER) {
|
||||
lastDeleteRepeatCount = -1;
|
||||
nativeTextInputEnter();
|
||||
} else {
|
||||
lastDeleteRepeatCount = -1;
|
||||
int unicode = event.getUnicodeChar();
|
||||
if (unicode >= 32) {
|
||||
nativeTextInputCommit(unicode);
|
||||
}
|
||||
}
|
||||
} else if (event != null && event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
|
||||
lastDeleteRepeatCount = -1;
|
||||
}
|
||||
} else if (event != null && event.getAction() == KeyEvent.ACTION_MULTIPLE &&
|
||||
event.getCharacters() != null) {
|
||||
lastDeleteRepeatCount = -1;
|
||||
String chars = event.getCharacters();
|
||||
for (int i = 0; i < chars.length();) {
|
||||
int codepoint = chars.codePointAt(i);
|
||||
if (codepoint >= 32) {
|
||||
nativeTextInputCommit(codepoint);
|
||||
}
|
||||
i += Character.charCount(codepoint);
|
||||
}
|
||||
}
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
private void setupInsetsListener() {
|
||||
final View decorView = getWindow().getDecorView();
|
||||
|
||||
nativeSetDeviceDensity(getResources().getDisplayMetrics().density);
|
||||
|
||||
decorView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
|
||||
@Override
|
||||
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
|
||||
updateInsets(insets);
|
||||
return insets;
|
||||
}
|
||||
});
|
||||
|
||||
// Startup safety net: catch the initial layout pass.
|
||||
decorView.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||
new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
WindowInsets insets = decorView.getRootWindowInsets();
|
||||
if (insets != null) {
|
||||
updateInsets(insets);
|
||||
}
|
||||
}
|
||||
decorView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
}
|
||||
});
|
||||
|
||||
decorView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
decorView.requestApplyInsets();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateInsets(WindowInsets insets) {
|
||||
if (insets == null) return;
|
||||
|
||||
nativeSetDeviceDensity(getResources().getDisplayMetrics().density);
|
||||
|
||||
int statusBar = 0;
|
||||
int navBar = 0;
|
||||
int cLeft = 0, cTop = 0, cRight = 0, cBottom = 0;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
Insets systemBars = insets.getInsetsIgnoringVisibility(
|
||||
WindowInsets.Type.systemBars());
|
||||
statusBar = systemBars.top;
|
||||
navBar = systemBars.bottom;
|
||||
} else {
|
||||
statusBar = insets.getSystemWindowInsetTop();
|
||||
navBar = insets.getSystemWindowInsetBottom();
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
DisplayCutout cutout = insets.getDisplayCutout();
|
||||
if (cutout != null) {
|
||||
cLeft = cutout.getSafeInsetLeft();
|
||||
cTop = cutout.getSafeInsetTop();
|
||||
cRight = cutout.getSafeInsetRight();
|
||||
cBottom = cutout.getSafeInsetBottom();
|
||||
}
|
||||
}
|
||||
|
||||
nativeSetInsets(statusBar, navBar, cLeft, cTop, cRight, cBottom);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package xyz.waozi.pass;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.kryonlabs.kryon.KryonActivity;
|
||||
|
||||
public final class PassActivity extends KryonActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setSoftInputMode(
|
||||
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 614 B |
|
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 598 B |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 627 B |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 681 B |
|
Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 746 B |
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">pass</string>
|
||||
<string name="app_name">Pass</string>
|
||||
</resources>
|
||||
@@ -0,0 +1 @@
|
||||
Initial release: deterministic, LessPass-compatible password generation with configurable length, counter, character classes, and excluded characters. Everything is computed locally; nothing is stored or uploaded.
|
||||
@@ -0,0 +1,2 @@
|
||||
- Keep bottom navigation, password controls, and dialog icons readable with dark tints in light mode and light tints in dark mode.
|
||||
- Prevent taps in Theme Settings from reaching fields underneath or opening the keyboard when saving the theme.
|
||||
@@ -0,0 +1 @@
|
||||
New clipboard handling, vault support, and named profiles in the CLI, plus self-update checks in the desktop app. Android keeps the same local, stateless generator.
|
||||
@@ -0,0 +1,2 @@
|
||||
- Install pass on Android: a signed APK is now downloadable from pass.waozi.xyz alongside the desktop, terminal, and browser downloads.
|
||||
- Fix the Android master-password fingerprint and secure storage so the stored master password unlocks reliably across launches.
|
||||
@@ -0,0 +1,2 @@
|
||||
- Verify every download: releases now ship a SHA256SUMS file covering the command-line, desktop, Android, and browser downloads.
|
||||
- The Android app now builds entirely from source with no developer signing key, clearing the way for F-Droid distribution.
|
||||
@@ -0,0 +1,6 @@
|
||||
- Save and reuse Android master-password defaults with fingerprint unlock.
|
||||
- Clear unlocked master text and generated passwords after a timeout.
|
||||
- Autosave length, counter, character classes, excluded characters, and biometric display settings.
|
||||
- Keep Android fields visible while the keyboard is open.
|
||||
- Run the real Pass app at pass.waozi.xyz/app.
|
||||
- Publish universal and per-ABI Android APKs.
|
||||
@@ -0,0 +1,3 @@
|
||||
- Add Android appearance settings for following device colors, choosing light or dark mode, selecting a color palette, and switching widget style.
|
||||
- Use Android system Material colors for the app theme, with a stable Material fallback instead of the bright pink accent some devices report.
|
||||
- Recalculate the Android layout cleanly when rotating between portrait and landscape, keeping controls clear of system bars and navigation insets.
|
||||
@@ -0,0 +1 @@
|
||||
- Keep Android source builds self-contained so F-Droid and other source builds generate the Kry app sources automatically.
|
||||
@@ -0,0 +1 @@
|
||||
- Fix Android source builds in stricter environments such as F-Droid builders while keeping Kry app source generation automatic.
|
||||
@@ -0,0 +1,4 @@
|
||||
- Match LessPass clients for the same site, login, master password, counter, character classes, and length settings.
|
||||
- Limit password length to LessPass's 5 to 35 character range.
|
||||
- Require Android fingerprint unlock for saved master passwords and store them with an authenticated Android Keystore key.
|
||||
- Use the Sweet Material palette by default, with Sweet-Dark matched colors in dark mode, and show generated passwords in a dedicated output field.
|
||||
@@ -0,0 +1,17 @@
|
||||
Pass derives strong, repeatable passwords on your device. The same site, login, master password, and settings always produce the same result, so there is no password database to back up, sync, or lose.
|
||||
|
||||
Everything is computed locally. The app makes no network requests, keeps no accounts, and tracks nothing.
|
||||
|
||||
Features:
|
||||
|
||||
• Deterministic, LessPass-compatible password generation
|
||||
• Configurable length, counter, character classes, and excluded characters
|
||||
• Optional fingerprint unlock with the master password held in secure storage
|
||||
• No analytics, no tracking, no network access
|
||||
|
||||
Pass is an independent implementation of the LessPass algorithm. Compatibility does not imply endorsement by or affiliation with the LessPass project.
|
||||
|
||||
Source code: https://github.com/waozixyz/pass
|
||||
Website: https://pass.waozi.xyz
|
||||
|
||||
Licensed under BSD-3-Clause.
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 62 KiB |
|
After Width: | Height: | Size: 87 KiB |
|
After Width: | Height: | Size: 88 KiB |
|
After Width: | Height: | Size: 66 KiB |
@@ -0,0 +1 @@
|
||||
Deterministic passwords from site, login, and one master password.
|
||||
@@ -0,0 +1 @@
|
||||
Pass
|
||||
@@ -1,5 +0,0 @@
|
||||
module github.com/waozixyz/pass
|
||||
|
||||
go 1.24
|
||||
|
||||
require github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc
|
||||
@@ -1,2 +0,0 @@
|
||||
github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc h1:7D+Bh06CRPCJO3gr2F7h1sriovOZ8BMhca2Rg85c2nk=
|
||||
github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
@@ -1,41 +0,0 @@
|
||||
package main
|
||||
|
||||
import "time"
|
||||
|
||||
type clipboardLease struct {
|
||||
read func() string
|
||||
write func(string)
|
||||
now func() time.Time
|
||||
value string
|
||||
expires time.Time
|
||||
}
|
||||
|
||||
func (c *clipboardLease) copy(value string, lifetime time.Duration) {
|
||||
c.write(value)
|
||||
c.value = value
|
||||
if lifetime <= 0 {
|
||||
c.expires = time.Time{}
|
||||
return
|
||||
}
|
||||
c.expires = c.now().Add(lifetime)
|
||||
}
|
||||
|
||||
func (c *clipboardLease) tick() bool {
|
||||
if c.value == "" || c.expires.IsZero() || c.now().Before(c.expires) {
|
||||
return false
|
||||
}
|
||||
if c.read() == c.value {
|
||||
c.write("")
|
||||
}
|
||||
c.value = ""
|
||||
c.expires = time.Time{}
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *clipboardLease) clear() {
|
||||
if c.value != "" && c.read() == c.value {
|
||||
c.write("")
|
||||
}
|
||||
c.value = ""
|
||||
c.expires = time.Time{}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestClipboardLeaseClearsOnlyItsOwnExpiredValue(t *testing.T) {
|
||||
now := time.Unix(100, 0)
|
||||
clipboard := ""
|
||||
lease := clipboardLease{
|
||||
read: func() string { return clipboard },
|
||||
write: func(value string) { clipboard = value },
|
||||
now: func() time.Time { return now },
|
||||
}
|
||||
lease.copy("generated", 20*time.Second)
|
||||
if clipboard != "generated" {
|
||||
t.Fatalf("clipboard = %q", clipboard)
|
||||
}
|
||||
now = now.Add(19 * time.Second)
|
||||
if lease.tick() || clipboard == "" {
|
||||
t.Fatal("lease cleared too early")
|
||||
}
|
||||
clipboard = "user replacement"
|
||||
now = now.Add(2 * time.Second)
|
||||
if !lease.tick() || clipboard != "user replacement" {
|
||||
t.Fatal("lease overwrote newer clipboard content")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClipboardLeaseClearsExpiredValue(t *testing.T) {
|
||||
now := time.Unix(100, 0)
|
||||
clipboard := ""
|
||||
lease := clipboardLease{
|
||||
read: func() string { return clipboard },
|
||||
write: func(value string) { clipboard = value },
|
||||
now: func() time.Time { return now },
|
||||
}
|
||||
lease.copy("generated", time.Second)
|
||||
now = now.Add(time.Second)
|
||||
if !lease.tick() || clipboard != "" {
|
||||
t.Fatal("expired generated password was not cleared")
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
module github.com/waozixyz/pass/gui
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require (
|
||||
github.com/waozixyz/pass v0.0.0
|
||||
github.com/waozixyz/kryon/go/kryui v0.0.0
|
||||
)
|
||||
|
||||
replace github.com/waozixyz/pass => ..
|
||||
|
||||
replace github.com/waozixyz/kryon/go/kryui => ../vendor/kryon/go/kryui
|
||||
|
Before Width: | Height: | Size: 125 KiB |
@@ -1,442 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/waozixyz/kryon/go/kryui"
|
||||
password "github.com/waozixyz/pass"
|
||||
)
|
||||
|
||||
const clipboardLifetime = 20 * time.Second
|
||||
|
||||
type appView int
|
||||
|
||||
const (
|
||||
viewGenerate appView = iota
|
||||
viewProfiles
|
||||
viewSettings
|
||||
)
|
||||
|
||||
//go:embed icon.png
|
||||
var appIconPNG []byte
|
||||
|
||||
//go:embed assets/emoji.ttf
|
||||
var emojiFontTTF []byte
|
||||
|
||||
type app struct {
|
||||
site, login, master, exclude *kryui.TextFieldState
|
||||
profileName *kryui.TextFieldState
|
||||
length, counter int32
|
||||
lower, upper, digits, symbols bool
|
||||
reveal bool
|
||||
generated, message, fingerprint string
|
||||
clipboard clipboardLease
|
||||
clearAfter int32
|
||||
view appView
|
||||
settings guiSettings
|
||||
config guiConfig
|
||||
profiles []profileEntry
|
||||
selectedProfile int
|
||||
}
|
||||
|
||||
func newApp() *app {
|
||||
cfg, err := loadGUIConfig()
|
||||
a := &app{
|
||||
site: kryui.NewTextField(101, 256), login: kryui.NewTextField(102, 256),
|
||||
master: kryui.NewPasswordField(103, 1024), exclude: kryui.NewTextField(104, 128),
|
||||
profileName: kryui.NewTextField(105, 64),
|
||||
length: 16, counter: 1, lower: true, upper: true, digits: true, symbols: true,
|
||||
clipboard: clipboardLease{read: kryui.GetClipboardText, write: kryui.SetClipboardText, now: time.Now},
|
||||
settings: cfg.Settings,
|
||||
config: cfg,
|
||||
profiles: sortedProfiles(cfg.Profiles),
|
||||
clearAfter: int32(cfg.Settings.ClearAfter),
|
||||
view: viewGenerate,
|
||||
selectedProfile: -1,
|
||||
}
|
||||
if err != nil {
|
||||
a.message = err.Error()
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func main() {
|
||||
kryui.SetConfigFlags(kryui.FlagWindowResizable)
|
||||
kryui.InitWindow(720, 740, "pass")
|
||||
icon := kryui.LoadImageFromMemory(".png", appIconPNG)
|
||||
kryui.SetWindowIcon(icon)
|
||||
kryui.UnloadImage(icon)
|
||||
kryui.SetThemeStyle(kryui.ThemeStyleMaterial)
|
||||
kryui.SetCurrentTheme(11, true) // Cobalt dark (fallback palette)
|
||||
// Follow the system palette by default; Cobalt dark is the fallback when
|
||||
// no system theme can be read.
|
||||
kryui.SetThemeSource(kryui.ThemeSourceSystem)
|
||||
kryui.SetThemeMode(kryui.ThemeModeSystem)
|
||||
kryui.EnsureUIDefaultFont()
|
||||
// The emoji fingerprint font serves only the master-password emoji
|
||||
// codepoints; all other glyphs keep coming from the theme font.
|
||||
kryui.RegisterUIFixedFontData("pass-emoji", ".ttf", emojiFontTTF, password.MasterEmojiCodepoints())
|
||||
kryui.SetWindowMinSize(560, 620)
|
||||
kryui.EnableEventWaiting()
|
||||
|
||||
a := newApp()
|
||||
updateCheckStart()
|
||||
for !kryui.WindowShouldClose() && !updateQuitRequested() {
|
||||
a.clipboard.tick()
|
||||
updatePoll()
|
||||
kryui.BeginDrawing()
|
||||
w := kryui.GetScreenWidth()
|
||||
kryui.BeginUI(kryui.Key("pass/main"))
|
||||
a.draw(w)
|
||||
kryui.EndUI()
|
||||
a.handleUIEvents()
|
||||
kryui.EndDrawing()
|
||||
}
|
||||
a.master.Clear()
|
||||
a.clipboard.clear()
|
||||
kryui.CloseWindow()
|
||||
// With the window down and secrets cleared, a pending update re-execs
|
||||
// the staged AppImage here.
|
||||
updateExecAfterUI()
|
||||
}
|
||||
|
||||
func (a *app) draw(width int32) {
|
||||
bg := kryui.GetThemeBackground()
|
||||
scheme := kryui.GetUIMaterialScheme()
|
||||
height := kryui.GetScreenHeight()
|
||||
kryui.ClearBackground(bg)
|
||||
contentW := width - 64
|
||||
if contentW > 720 {
|
||||
contentW = 720
|
||||
}
|
||||
x := (width - contentW) / 2
|
||||
cardH := height - 104
|
||||
if cardH < 520 {
|
||||
cardH = 520
|
||||
}
|
||||
kryui.DrawRectangleRounded(kryui.NewRectangle(float32(x), 22, float32(contentW), float32(cardH)), .035, 10, scheme.Surface)
|
||||
kryui.DrawRectangleLinesEx(kryui.NewRectangle(float32(x), 22, float32(contentW), float32(cardH)), 1, scheme.Outline)
|
||||
|
||||
style := inputStyle()
|
||||
y := int32(46)
|
||||
switch a.view {
|
||||
case viewProfiles:
|
||||
a.drawProfiles(x+24, y, contentW-48, style)
|
||||
case viewSettings:
|
||||
a.drawSettings(x+24, y, contentW-48)
|
||||
default:
|
||||
a.drawGenerate(x+24, y, contentW-48, style)
|
||||
}
|
||||
|
||||
a.drawBottomNav(width, height)
|
||||
a.updateDrawRow(x+24, 22+cardH+18, contentW-48)
|
||||
}
|
||||
|
||||
func (a *app) drawBottomNav(width, height int32) {
|
||||
result := kryui.BottomNav(kryui.BottomNavProps{
|
||||
ViewWidth: width,
|
||||
ViewHeight: height,
|
||||
Items: []kryui.BottomNavItem{
|
||||
{Route: int32(viewGenerate), Label: "Generate", Active: a.view == viewGenerate},
|
||||
{Route: int32(viewProfiles), Label: "Profiles", Active: a.view == viewProfiles},
|
||||
{Route: int32(viewSettings), Label: "Settings", Active: a.view == viewSettings},
|
||||
},
|
||||
})
|
||||
if result.ClickedRoute >= int32(viewGenerate) && result.ClickedRoute <= int32(viewSettings) {
|
||||
a.view = appView(result.ClickedRoute)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *app) drawGenerate(x, y, width int32, style kryui.UITextInputStyle) {
|
||||
text := kryui.GetThemeText()
|
||||
scheme := kryui.GetUIMaterialScheme()
|
||||
kryui.DrawUIText("PASSWORD DETAILS", x, y, kryui.UIText12, scheme.Primary)
|
||||
y += 30
|
||||
a.field("Site", a.site, x, y, width, style)
|
||||
y += 76
|
||||
a.field("Login", a.login, x, y, width, style)
|
||||
y += 76
|
||||
kryui.DrawUIText("Master password", x, y, kryui.UIText14, text)
|
||||
a.master.SetSecure(!a.reveal)
|
||||
kryui.TextField(a.master, kryui.FieldProps{Bounds: kryui.NewRectangle(float32(x), float32(y+24), float32(width-126), 38), Font: kryui.UIText16, Style: style})
|
||||
if a.settings.ShowFingerprint && a.fingerprint != "" {
|
||||
fontToken := kryui.PushUIFont("pass-emoji")
|
||||
fpWidth := kryui.MeasureText(a.fingerprint, kryui.UIText16)
|
||||
kryui.DrawUIText(a.fingerprint, x+width-fpWidth, y, kryui.UIText16, scheme.OnSurfaceVariant)
|
||||
kryui.PopUIFont(fontToken)
|
||||
}
|
||||
kryui.Button(kryui.ButtonProps{Bounds: kryui.NewRectangle(float32(x+width-88), float32(y+24), 88, 38), Label: map[bool]string{true: "Hide", false: "Reveal"}[a.reveal], Style: kryui.UIButtonStyleSecondary, ID: 205})
|
||||
y += 76
|
||||
|
||||
kryui.DrawUIText("PASSWORD RULES", x, y-10, kryui.UIText12, scheme.Primary)
|
||||
y += 14
|
||||
kryui.DrawUIText("Length", x, y, kryui.UIText14, text)
|
||||
kryui.Spinbox(kryui.SpinboxProps{Bounds: kryui.NewRectangle(float32(x), float32(y+24), 130, 38), ID: 301, Min: 1, Max: 128, Step: 1, Value: &a.length})
|
||||
kryui.DrawUIText("Counter", x+158, y, kryui.UIText14, text)
|
||||
kryui.Spinbox(kryui.SpinboxProps{Bounds: kryui.NewRectangle(float32(x+158), float32(y+24), 130, 38), ID: 302, Min: 1, Max: 999999, Step: 1, Value: &a.counter})
|
||||
kryui.TextField(a.exclude, kryui.FieldProps{Bounds: kryui.NewRectangle(float32(x+316), float32(y+24), float32(width-316), 38), Font: kryui.UIText16, Style: style})
|
||||
kryui.DrawUIText("Excluded characters", x+316, y, kryui.UIText14, text)
|
||||
y += 76
|
||||
|
||||
kryui.DrawUICheckboxToggle(x, y, "Lowercase", &a.lower)
|
||||
kryui.DrawUICheckboxToggle(x+150, y, "Uppercase", &a.upper)
|
||||
kryui.DrawUICheckboxToggle(x+300, y, "Digits", &a.digits)
|
||||
kryui.DrawUICheckboxToggle(x+420, y, "Symbols", &a.symbols)
|
||||
y += 48
|
||||
kryui.Button(kryui.ButtonProps{Bounds: kryui.NewRectangle(float32(x), float32(y), 150, 42), Label: "Generate", Style: kryui.UIButtonStylePrimary, ID: 401})
|
||||
kryui.Button(kryui.ButtonProps{Bounds: kryui.NewRectangle(float32(x+166), float32(y), 150, 42), Label: "Copy", Style: kryui.UIButtonStyleSecondary, ID: 402, Disabled: a.generated == ""})
|
||||
kryui.Button(kryui.ButtonProps{Bounds: kryui.NewRectangle(float32(x+332), float32(y), 120, 42), Label: "Clear", Style: kryui.UIButtonStyleSecondary, ID: 403})
|
||||
y += 56
|
||||
kryui.DrawRectangleRounded(kryui.NewRectangle(float32(x), float32(y), float32(width), 72), .08, 10, scheme.SurfaceContainer)
|
||||
if a.generated != "" {
|
||||
kryui.SelectableText(a.generated, x+18, y+15, kryui.UIText20, text)
|
||||
} else {
|
||||
kryui.DrawUIText("Your generated password appears here", x+18, y+17, kryui.UIText16, scheme.OnSurfaceVariant)
|
||||
}
|
||||
if a.message != "" {
|
||||
kryui.DrawUIText(a.message, x+18, y+45, kryui.UIText12, scheme.OnSurfaceVariant)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *app) drawProfiles(x, y, width int32, style kryui.UITextInputStyle) {
|
||||
text := kryui.GetThemeText()
|
||||
scheme := kryui.GetUIMaterialScheme()
|
||||
|
||||
kryui.DrawUIText("PROFILE", x, y, kryui.UIText12, scheme.Primary)
|
||||
y += 30
|
||||
a.field("Name", a.profileName, x, y, width, style)
|
||||
y += 76
|
||||
kryui.Button(kryui.ButtonProps{Bounds: kryui.NewRectangle(float32(x), float32(y), 154, 42), Label: "Save Current", Style: kryui.UIButtonStylePrimary, ID: 501})
|
||||
kryui.Button(kryui.ButtonProps{Bounds: kryui.NewRectangle(float32(x+170), float32(y), 120, 42), Label: "Delete", Style: kryui.UIButtonStyleSecondary, ID: 502, Disabled: a.selectedProfile < 0})
|
||||
y += 62
|
||||
|
||||
kryui.DrawUIText("SAVED PROFILES", x, y, kryui.UIText12, scheme.Primary)
|
||||
y += 28
|
||||
if len(a.profiles) == 0 {
|
||||
kryui.DrawUIText("No profiles saved yet", x, y, kryui.UIText14, scheme.OnSurfaceVariant)
|
||||
y += 34
|
||||
}
|
||||
for i, p := range a.profiles {
|
||||
if i >= 7 {
|
||||
kryui.DrawUIText(fmt.Sprintf("%d more profiles in settings file", len(a.profiles)-i), x, y+8, kryui.UIText12, scheme.OnSurfaceVariant)
|
||||
y += 32
|
||||
break
|
||||
}
|
||||
label := p.Name
|
||||
if p.Data.Site != "" {
|
||||
label = fmt.Sprintf("%s - %s", p.Name, p.Data.Site)
|
||||
}
|
||||
style := kryui.UIButtonStyleSecondary
|
||||
if i == a.selectedProfile {
|
||||
style = kryui.UIButtonStylePrimary
|
||||
}
|
||||
kryui.Button(kryui.ButtonProps{Bounds: kryui.NewRectangle(float32(x), float32(y), float32(width), 40), Label: label, Style: style, ID: int32(600 + i)})
|
||||
y += 48
|
||||
}
|
||||
if a.message != "" {
|
||||
kryui.DrawUIText(a.message, x, y+8, kryui.UIText12, text)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *app) drawSettings(x, y, width int32) {
|
||||
text := kryui.GetThemeText()
|
||||
scheme := kryui.GetUIMaterialScheme()
|
||||
|
||||
kryui.DrawUIText("BEHAVIOR", x, y, kryui.UIText12, scheme.Primary)
|
||||
y += 32
|
||||
kryui.DrawUICheckboxToggle(x, y, "Auto-copy after Generate", &a.settings.AutoCopy)
|
||||
y += 42
|
||||
kryui.DrawUICheckboxToggle(x, y, "Show master fingerprint", &a.settings.ShowFingerprint)
|
||||
y += 48
|
||||
kryui.DrawUIText("Clipboard seconds", x, y, kryui.UIText14, text)
|
||||
kryui.Spinbox(kryui.SpinboxProps{Bounds: kryui.NewRectangle(float32(x), float32(y+24), 150, 38), ID: 701, Min: 0, Max: 3600, Step: 5, Value: &a.clearAfter})
|
||||
y += 82
|
||||
|
||||
kryui.DrawUIText("MASTER PASSWORD", x, y, kryui.UIText12, scheme.Primary)
|
||||
y += 30
|
||||
kryui.DrawUIText("Android can save and unlock the master password with system biometrics.", x, y, kryui.UIText14, scheme.OnSurfaceVariant)
|
||||
y += 34
|
||||
kryui.DrawUIText("Desktop keeps the master password only in memory for this session.", x, y, kryui.UIText14, scheme.OnSurfaceVariant)
|
||||
y += 54
|
||||
kryui.Button(kryui.ButtonProps{Bounds: kryui.NewRectangle(float32(x), float32(y), 140, 42), Label: "Save Settings", Style: kryui.UIButtonStylePrimary, ID: 503})
|
||||
y += 58
|
||||
if a.message != "" {
|
||||
kryui.DrawRectangleRounded(kryui.NewRectangle(float32(x), float32(y), float32(width), 56), .08, 10, scheme.SurfaceContainer)
|
||||
kryui.DrawUIText(a.message, x+16, y+20, kryui.UIText12, scheme.OnSurfaceVariant)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *app) field(label string, field *kryui.TextFieldState, x, y, width int32, style kryui.UITextInputStyle) {
|
||||
kryui.DrawUIText(label, x, y, kryui.UIText14, kryui.GetThemeText())
|
||||
kryui.TextField(field, kryui.FieldProps{Bounds: kryui.NewRectangle(float32(x), float32(y+24), float32(width), 38), Font: kryui.UIText16, Style: style})
|
||||
}
|
||||
|
||||
func (a *app) handleUIEvents() {
|
||||
for event, ok := kryui.NextUIEvent(); ok; event, ok = kryui.NextUIEvent() {
|
||||
switch event.Kind {
|
||||
case kryui.EventTextChanged:
|
||||
if event.Key == 103 {
|
||||
if master := a.master.Text(); master != "" {
|
||||
a.fingerprint = password.MasterPasswordEmojiString(master)
|
||||
} else {
|
||||
a.fingerprint = ""
|
||||
}
|
||||
}
|
||||
case kryui.EventClick:
|
||||
switch event.Key {
|
||||
case 205:
|
||||
a.reveal = !a.reveal
|
||||
case 401:
|
||||
a.generate()
|
||||
case 402:
|
||||
if a.generated != "" {
|
||||
a.copyGenerated()
|
||||
}
|
||||
case 403:
|
||||
a.master.Clear()
|
||||
a.fingerprint = ""
|
||||
a.generated = ""
|
||||
a.message = "Cleared"
|
||||
case 501:
|
||||
a.saveCurrentProfile()
|
||||
case 502:
|
||||
a.deleteSelectedProfile()
|
||||
case 503:
|
||||
a.saveSettings()
|
||||
default:
|
||||
if event.Key >= 600 && event.Key < kryui.UIKey(600+len(a.profiles)) {
|
||||
idx := int(event.Key - 600)
|
||||
a.selectedProfile = idx
|
||||
a.applyProfile(a.profiles[idx])
|
||||
a.view = viewGenerate
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (a *app) generate() {
|
||||
result, err := password.Generate(a.site.Text(), a.login.Text(), a.master.Text(), password.Options{Length: int(a.length), Counter: uint64(a.counter), Lowercase: a.lower, Uppercase: a.upper, Digits: a.digits, Symbols: a.symbols, Exclude: a.exclude.Text()})
|
||||
if err != nil {
|
||||
a.generated = ""
|
||||
a.message = err.Error()
|
||||
return
|
||||
}
|
||||
a.generated = result
|
||||
if a.settings.AutoCopy {
|
||||
a.copyGenerated()
|
||||
return
|
||||
}
|
||||
a.message = "Password generated locally"
|
||||
}
|
||||
|
||||
func (a *app) copyGenerated() {
|
||||
seconds := int(a.clearAfter)
|
||||
if seconds < 0 {
|
||||
seconds = 0
|
||||
}
|
||||
a.clipboard.copy(a.generated, clipboardDuration(seconds))
|
||||
if seconds > 0 {
|
||||
a.message = fmt.Sprintf("Copied; clipboard clears in %d seconds", seconds)
|
||||
} else {
|
||||
a.message = "Copied"
|
||||
}
|
||||
}
|
||||
|
||||
func clipboardDuration(seconds int) time.Duration {
|
||||
if seconds <= 0 {
|
||||
return 0
|
||||
}
|
||||
return time.Duration(seconds) * time.Second
|
||||
}
|
||||
|
||||
func (a *app) saveSettings() {
|
||||
if a.clearAfter < 0 {
|
||||
a.clearAfter = 0
|
||||
}
|
||||
a.settings.ClearAfter = int(a.clearAfter)
|
||||
a.config.Settings = a.settings
|
||||
if err := saveGUIConfig(a.config); err != nil {
|
||||
a.message = err.Error()
|
||||
return
|
||||
}
|
||||
a.message = "Settings saved"
|
||||
}
|
||||
|
||||
func (a *app) saveCurrentProfile() {
|
||||
name := strings.TrimSpace(a.profileName.Text())
|
||||
if name == "" {
|
||||
a.message = "Enter a profile name"
|
||||
return
|
||||
}
|
||||
if a.config.Profiles == nil {
|
||||
a.config.Profiles = map[string]storedProfile{}
|
||||
}
|
||||
a.config.Profiles[name] = storedProfile{
|
||||
Site: a.site.Text(),
|
||||
Login: a.login.Text(),
|
||||
Counter: uint64(a.counter),
|
||||
Length: int(a.length),
|
||||
Lowercase: a.lower,
|
||||
Uppercase: a.upper,
|
||||
Digits: a.digits,
|
||||
Symbols: a.symbols,
|
||||
Exclude: a.exclude.Text(),
|
||||
}
|
||||
a.config.Settings = a.settings
|
||||
if err := saveGUIConfig(a.config); err != nil {
|
||||
a.message = err.Error()
|
||||
return
|
||||
}
|
||||
a.profiles = sortedProfiles(a.config.Profiles)
|
||||
a.selectedProfile = -1
|
||||
for i, p := range a.profiles {
|
||||
if p.Name == name {
|
||||
a.selectedProfile = i
|
||||
break
|
||||
}
|
||||
}
|
||||
a.message = "Profile saved"
|
||||
}
|
||||
|
||||
func (a *app) deleteSelectedProfile() {
|
||||
if a.selectedProfile < 0 || a.selectedProfile >= len(a.profiles) {
|
||||
return
|
||||
}
|
||||
name := a.profiles[a.selectedProfile].Name
|
||||
delete(a.config.Profiles, name)
|
||||
if err := saveGUIConfig(a.config); err != nil {
|
||||
a.message = err.Error()
|
||||
return
|
||||
}
|
||||
a.profiles = sortedProfiles(a.config.Profiles)
|
||||
a.selectedProfile = -1
|
||||
a.profileName.SetText("")
|
||||
a.message = "Profile deleted"
|
||||
}
|
||||
|
||||
func (a *app) applyProfile(p profileEntry) {
|
||||
a.profileName.SetText(p.Name)
|
||||
a.site.SetText(p.Data.Site)
|
||||
a.login.SetText(p.Data.Login)
|
||||
if p.Data.Counter > 0 {
|
||||
a.counter = int32(p.Data.Counter)
|
||||
}
|
||||
if p.Data.Length > 0 {
|
||||
a.length = int32(p.Data.Length)
|
||||
}
|
||||
a.lower = p.Data.Lowercase
|
||||
a.upper = p.Data.Uppercase
|
||||
a.digits = p.Data.Digits
|
||||
a.symbols = p.Data.Symbols
|
||||
a.exclude.SetText(p.Data.Exclude)
|
||||
a.message = "Profile loaded"
|
||||
}
|
||||
|
||||
func inputStyle() kryui.UITextInputStyle {
|
||||
s := kryui.GetUIMaterialScheme()
|
||||
return kryui.UITextInputStyle{Background: s.SurfaceContainer, Border: s.Outline, FocusBorder: s.Primary, Text: s.OnSurface, Cursor: s.Primary, Radius: 6, PaddingX: 10, PaddingY: 8}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type storedProfile struct {
|
||||
Site string `json:"site,omitempty"`
|
||||
Login string `json:"login"`
|
||||
Counter uint64 `json:"counter,omitempty"`
|
||||
Length int `json:"length,omitempty"`
|
||||
Lowercase bool `json:"lowercase"`
|
||||
Uppercase bool `json:"uppercase"`
|
||||
Digits bool `json:"digits"`
|
||||
Symbols bool `json:"symbols"`
|
||||
Exclude string `json:"exclude,omitempty"`
|
||||
}
|
||||
|
||||
type guiSettings struct {
|
||||
AutoCopy bool `json:"auto_copy"`
|
||||
ClearAfter int `json:"clear_after_seconds"`
|
||||
ShowFingerprint bool `json:"show_fingerprint"`
|
||||
}
|
||||
|
||||
type guiConfig struct {
|
||||
Settings guiSettings `json:"settings"`
|
||||
Profiles map[string]storedProfile `json:"profiles"`
|
||||
}
|
||||
|
||||
type profileEntry struct {
|
||||
Name string
|
||||
Data storedProfile
|
||||
}
|
||||
|
||||
func defaultGUISettings() guiSettings {
|
||||
return guiSettings{ClearAfter: 20, ShowFingerprint: true}
|
||||
}
|
||||
|
||||
func configFilePath() string {
|
||||
if dir := os.Getenv("XDG_CONFIG_HOME"); dir != "" {
|
||||
return filepath.Join(dir, "pass", "profiles.json")
|
||||
}
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return filepath.Join(home, ".config", "pass", "profiles.json")
|
||||
}
|
||||
|
||||
func loadGUIConfig() (guiConfig, error) {
|
||||
cfg := guiConfig{Settings: defaultGUISettings(), Profiles: map[string]storedProfile{}}
|
||||
path := configFilePath()
|
||||
if path == "" {
|
||||
return cfg, nil
|
||||
}
|
||||
raw, err := os.ReadFile(path)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return cfg, nil
|
||||
}
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
if len(raw) == 0 {
|
||||
return cfg, nil
|
||||
}
|
||||
if err := json.Unmarshal(raw, &cfg); err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
if cfg.Profiles == nil {
|
||||
cfg.Profiles = map[string]storedProfile{}
|
||||
}
|
||||
if cfg.Settings.ClearAfter < 0 {
|
||||
cfg.Settings.ClearAfter = 0
|
||||
}
|
||||
if cfg.Settings.ClearAfter == 0 && !cfg.Settings.AutoCopy {
|
||||
cfg.Settings.ClearAfter = 20
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func saveGUIConfig(cfg guiConfig) error {
|
||||
path := configFilePath()
|
||||
if path == "" {
|
||||
return nil
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
|
||||
return err
|
||||
}
|
||||
raw, err := json.MarshalIndent(cfg, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path, append(raw, '\n'), 0o600)
|
||||
}
|
||||
|
||||
func sortedProfiles(profiles map[string]storedProfile) []profileEntry {
|
||||
names := make([]string, 0, len(profiles))
|
||||
for name := range profiles {
|
||||
names = append(names, name)
|
||||
}
|
||||
sort.Strings(names)
|
||||
out := make([]profileEntry, 0, len(names))
|
||||
for _, name := range names {
|
||||
out = append(out, profileEntry{Name: name, Data: profiles[name]})
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
package main
|
||||
|
||||
// Desktop update flow over kryon's kry_update_flow: check the release
|
||||
// appcast once per session, toast when a newer pass exists, and offer
|
||||
// download + restart in a small row under the main card. AppImage builds
|
||||
// self-update (verified download, atomic swap, re-exec); tarball, deb and
|
||||
// source installs stay on the release link.
|
||||
|
||||
import (
|
||||
"github.com/waozixyz/kryon/go/kryui"
|
||||
password "github.com/waozixyz/pass"
|
||||
)
|
||||
|
||||
const appcastURL = "https://github.com/waozixyz/pass/releases/latest/download/appcast.json"
|
||||
|
||||
const updateButtonID = 510
|
||||
|
||||
var (
|
||||
updater *kryui.UpdateFlow
|
||||
updateNoticed bool
|
||||
restartPending bool
|
||||
)
|
||||
|
||||
func updateCheckStart() {
|
||||
updater = kryui.StartUpdateFlow("pass", password.Version, appcastURL)
|
||||
}
|
||||
|
||||
func updatePoll() {
|
||||
if updater == nil {
|
||||
return
|
||||
}
|
||||
updater.Poll()
|
||||
if !updateNoticed && updater.State() == kryui.UpdateFlowAvailable {
|
||||
updateNoticed = true
|
||||
if updater.HasArtifact() {
|
||||
kryui.ShowToast("pass " + updater.NewVersion() + " available — update below")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func updateQuitRequested() bool {
|
||||
return restartPending
|
||||
}
|
||||
|
||||
// updateExecAfterUI re-execs the staged AppImage; call once the window is
|
||||
// closed and secrets are cleared. Does nothing when no restart is pending.
|
||||
func updateExecAfterUI() {
|
||||
if updater != nil && restartPending {
|
||||
updater.ExecPending()
|
||||
}
|
||||
}
|
||||
|
||||
// updateDrawRow renders the update row under the main card. Returns true
|
||||
// when it drew (the layout reserves the space unconditionally once an
|
||||
// update was seen, so the card doesn't jump while states change).
|
||||
func (a *app) updateDrawRow(x, y, width int32) bool {
|
||||
if updater == nil {
|
||||
return false
|
||||
}
|
||||
scheme := kryui.GetUIMaterialScheme()
|
||||
switch updater.State() {
|
||||
case kryui.UpdateFlowAvailable:
|
||||
if !updater.HasArtifact() {
|
||||
// system-managed or source install: one quiet link-out line
|
||||
if updater.ReleaseURL() == "" {
|
||||
return false
|
||||
}
|
||||
kryui.DrawUIText("pass "+updater.NewVersion()+" available", x, y, kryui.UIText12, scheme.OnSurfaceVariant)
|
||||
return true
|
||||
}
|
||||
kryui.DrawUIText("pass "+updater.NewVersion()+" available", x, y, kryui.UIText12, scheme.OnSurfaceVariant)
|
||||
if kryui.Button(kryui.ButtonProps{
|
||||
Bounds: kryui.NewRectangle(float32(x+width-96), float32(y-14), 96, 32),
|
||||
Label: "Download", Style: kryui.UIButtonStyleSecondary, ID: updateButtonID,
|
||||
}) {
|
||||
updater.Download()
|
||||
}
|
||||
case kryui.UpdateFlowDownloading:
|
||||
pct := int(updater.Progress()*100 + 0.5)
|
||||
if pct < 0 {
|
||||
pct = 0
|
||||
}
|
||||
kryui.DrawUIText("Downloading… "+itoa(pct)+"%", x, y, kryui.UIText12, scheme.OnSurfaceVariant)
|
||||
case kryui.UpdateFlowReady:
|
||||
kryui.DrawUIText("pass "+updater.NewVersion()+" ready to install", x, y, kryui.UIText12, scheme.OnSurfaceVariant)
|
||||
if kryui.Button(kryui.ButtonProps{
|
||||
Bounds: kryui.NewRectangle(float32(x+width-150), float32(y-14), 150, 32),
|
||||
Label: "Restart to update", Style: kryui.UIButtonStylePrimary, ID: updateButtonID,
|
||||
}) {
|
||||
if updater.Apply() {
|
||||
restartPending = true
|
||||
}
|
||||
}
|
||||
case kryui.UpdateFlowFailed:
|
||||
kryui.DrawUIText("Update failed: "+updater.Error(), x, y, kryui.UIText12, scheme.OnSurfaceVariant)
|
||||
if kryui.Button(kryui.ButtonProps{
|
||||
Bounds: kryui.NewRectangle(float32(x+width-96), float32(y-14), 96, 32),
|
||||
Label: "Retry", Style: kryui.UIButtonStyleSecondary, ID: updateButtonID,
|
||||
}) {
|
||||
updater.Download()
|
||||
}
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func itoa(n int) string {
|
||||
if n == 0 {
|
||||
return "0"
|
||||
}
|
||||
var buf [8]byte
|
||||
i := len(buf)
|
||||
for n > 0 {
|
||||
i--
|
||||
buf[i] = byte('0' + n%10)
|
||||
n /= 10
|
||||
}
|
||||
return string(buf[i:])
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package pass
|
||||
|
||||
import "crypto/sha256"
|
||||
|
||||
// masterEmojiTable is the fixed alphabet for the master-password fingerprint.
|
||||
// Entries are single-codepoint emoji with distinct silhouettes so a wrong
|
||||
// master password is obvious at a glance. The order is part of the public
|
||||
// derivation: never reorder or extend without treating it as a format change.
|
||||
var masterEmojiTable = []rune{
|
||||
// animals
|
||||
'🐶', '🐱', '🐭', '🐹', '🐰', '🦊', '🐻', '🐼',
|
||||
'🐨', '🐯', '🦁', '🐮', '🐷', '🐸', '🐵', '🐔',
|
||||
'🐧', '🦉', '🐺', '🐴', '🦄', '🐝', '🦋', '🐢',
|
||||
// food
|
||||
'🍎', '🍊', '🍋', '🍉', '🍇', '🍓', '🍒', '🍑',
|
||||
'🥑', '🌽', '🍕', '🍔', '🍟', '🍩',
|
||||
// nature
|
||||
'🌵', '🌲', '🌳', '🌴', '🌱', '🌻', '🌸', '🌈',
|
||||
'⭐', '🌙',
|
||||
// objects
|
||||
'🔥', '💧', '⛄', '🎉', '🎸', '🎯', '🎲', '🎁',
|
||||
'🚀', '🚗', '⚓', '🎨', '🔑', '💡', '📚', '🎧',
|
||||
}
|
||||
|
||||
// MasterEmojiCount is the number of emoji shown for one master password.
|
||||
const MasterEmojiCount = 4
|
||||
|
||||
// MasterPasswordEmoji derives a short emoji fingerprint from a master
|
||||
// password: the first bytes of its SHA-256 select MasterEmojiCount emoji from
|
||||
// masterEmojiTable. The same master password always produces the same emoji,
|
||||
// so a user can recognise a correctly typed master password across sessions
|
||||
// without the password ever being stored or displayed. The fingerprint leaks
|
||||
// only 24 bits of the hash, which does not help recover a strong master.
|
||||
func MasterPasswordEmoji(master string) []rune {
|
||||
sum := sha256.Sum256([]byte(master))
|
||||
emoji := make([]rune, MasterEmojiCount)
|
||||
for i := range emoji {
|
||||
emoji[i] = masterEmojiTable[int(sum[i])%len(masterEmojiTable)]
|
||||
}
|
||||
return emoji
|
||||
}
|
||||
|
||||
// MasterPasswordEmojiString is MasterPasswordEmoji as a display string.
|
||||
func MasterPasswordEmojiString(master string) string {
|
||||
return string(MasterPasswordEmoji(master))
|
||||
}
|
||||
|
||||
// MasterEmojiCodepoints lists the table's codepoints. Registration with a
|
||||
// font subset needs exactly these glyphs.
|
||||
func MasterEmojiCodepoints() []rune {
|
||||
codepoints := make([]rune, len(masterEmojiTable))
|
||||
copy(codepoints, masterEmojiTable)
|
||||
return codepoints
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package pass
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestMasterPasswordEmojiIsDeterministic(t *testing.T) {
|
||||
first := MasterPasswordEmojiString("correct horse battery staple")
|
||||
for i := 0; i < 8; i++ {
|
||||
if got := MasterPasswordEmojiString("correct horse battery staple"); got != first {
|
||||
t.Fatalf("fingerprint changed between calls: %q vs %q", got, first)
|
||||
}
|
||||
}
|
||||
if got := MasterPasswordEmojiString(""); got == "" || len([]rune(got)) != MasterEmojiCount {
|
||||
t.Fatalf("empty master fingerprint = %q, want %d emoji", got, MasterEmojiCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMasterPasswordEmojiDiffersForDifferentMasters(t *testing.T) {
|
||||
seen := map[string]string{
|
||||
MasterPasswordEmojiString("test"): "test",
|
||||
MasterPasswordEmojiString("test2"): "test2",
|
||||
MasterPasswordEmojiString("tset"): "tset",
|
||||
MasterPasswordEmojiString("hunter2"): "hunter2",
|
||||
MasterPasswordEmojiString("correct horse battery staple"): "correct horse battery staple",
|
||||
}
|
||||
// Five distinct short masters colliding on a 24-bit space would be
|
||||
// itself a sha256 anomaly; a single collision here means a table bug.
|
||||
if len(seen) != 5 {
|
||||
t.Fatalf("expected distinct fingerprints, got %d unique for 5 masters", len(seen))
|
||||
}
|
||||
}
|
||||
|
||||
func TestMasterPasswordEmojiUsesTableAlphabet(t *testing.T) {
|
||||
inTable := func(r rune) bool {
|
||||
for _, candidate := range masterEmojiTable {
|
||||
if candidate == r {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
if len(masterEmojiTable) != 64 {
|
||||
t.Fatalf("table has %d emoji, want 64", len(masterEmojiTable))
|
||||
}
|
||||
for _, master := range []string{"a", "b", "ab", "🔐", "фыв"} {
|
||||
for _, r := range MasterPasswordEmoji(master) {
|
||||
if !inTable(r) {
|
||||
t.Fatalf("master %q produced rune %U outside the table", master, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMasterEmojiCodepointsMatchTable(t *testing.T) {
|
||||
codepoints := MasterEmojiCodepoints()
|
||||
if len(codepoints) != len(masterEmojiTable) {
|
||||
t.Fatalf("got %d codepoints, want %d", len(codepoints), len(masterEmojiTable))
|
||||
}
|
||||
for i := range codepoints {
|
||||
if codepoints[i] != masterEmojiTable[i] {
|
||||
t.Fatalf("codepoint %d = %U, want %U", i, codepoints[i], masterEmojiTable[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
< /$objtype/mkfile
|
||||
|
||||
# Native Plan 9 build of Pass (Kryon libdraw backend). build/plan9 is
|
||||
# prepared on the host by: make kry-c-plan9
|
||||
|
||||
TARG=pass
|
||||
ROOT=/sys/src/pass
|
||||
|
||||
gensrc=`{cat $ROOT/build/plan9/generated-c-files.txt}
|
||||
appsrc=native/pass_core.c native/pass_runtime.c native/pass_plan9_main.c
|
||||
hostsrc=build/plan9/pass_embedded_assets.c
|
||||
APPCPPFLAGS=-I$ROOT/build/plan9/generated -I$ROOT/native
|
||||
LDLIBS=
|
||||
|
||||
< /sys/src/kryon/mk/plan9-app.mk
|
||||
@@ -0,0 +1,225 @@
|
||||
#include "pass_core.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef PASS_VERSION
|
||||
#define PASS_VERSION "dev"
|
||||
#endif
|
||||
|
||||
#define MASTER_ENV "LESSPASS_MASTER_PASSWORD"
|
||||
|
||||
typedef struct {
|
||||
PassOptions options;
|
||||
int prompt;
|
||||
int copy;
|
||||
int no_copy;
|
||||
int show_version;
|
||||
const char *site;
|
||||
const char *login;
|
||||
const char *master;
|
||||
} Cli;
|
||||
|
||||
static void
|
||||
usage(FILE *out)
|
||||
{
|
||||
fputs(
|
||||
"Usage: pass [OPTIONS] SITE LOGIN [MASTER_PASSWORD]\n"
|
||||
"\n"
|
||||
"Derive a site-specific password.\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" -L, --length N password length (default 16, min 5, max 35)\n"
|
||||
" -C, --counter N generation counter (default 1)\n"
|
||||
" -l, --lowercase include lowercase letters\n"
|
||||
" -u, --uppercase include uppercase letters\n"
|
||||
" -d, --digits include digits\n"
|
||||
" -s, --symbols include symbols\n"
|
||||
" --no-lowercase exclude lowercase letters\n"
|
||||
" --no-uppercase exclude uppercase letters\n"
|
||||
" --no-digits exclude digits\n"
|
||||
" --no-symbols exclude symbols\n"
|
||||
" --exclude CHARS remove characters from all enabled classes\n"
|
||||
" -p, --prompt read the master password from stdin\n"
|
||||
" -c, --copy reserved for GUI/runtime clipboard support\n"
|
||||
" --no-copy print instead of copying\n"
|
||||
" -v, --version show version\n"
|
||||
" -h, --help show this help\n",
|
||||
out);
|
||||
}
|
||||
|
||||
static int
|
||||
parse_int(const char *value, int *out)
|
||||
{
|
||||
char *end = NULL;
|
||||
long parsed;
|
||||
|
||||
if(value == NULL || value[0] == '\0')
|
||||
return 0;
|
||||
parsed = strtol(value, &end, 10);
|
||||
if(end == NULL || *end != '\0')
|
||||
return 0;
|
||||
*out = (int)parsed;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
read_line(char *out, size_t out_size)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if(out == NULL || out_size == 0)
|
||||
return 0;
|
||||
if(fgets(out, (int)out_size, stdin) == NULL)
|
||||
return 0;
|
||||
len = strlen(out);
|
||||
while(len > 0 && (out[len - 1] == '\n' || out[len - 1] == '\r')) {
|
||||
out[len - 1] = '\0';
|
||||
len--;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
take_value(int argc, char **argv, int *i, const char **value, const char *name)
|
||||
{
|
||||
if(*i + 1 >= argc) {
|
||||
fprintf(stderr, "pass: %s requires a value\n", name);
|
||||
return 0;
|
||||
}
|
||||
*i += 1;
|
||||
*value = argv[*i];
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_args(int argc, char **argv, Cli *cli)
|
||||
{
|
||||
int positional = 0;
|
||||
|
||||
for(int i = 1; i < argc; i++) {
|
||||
const char *arg = argv[i];
|
||||
const char *value = NULL;
|
||||
|
||||
if(strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) {
|
||||
usage(stdout);
|
||||
exit(0);
|
||||
} else if(strcmp(arg, "-v") == 0 || strcmp(arg, "--version") == 0) {
|
||||
cli->show_version = 1;
|
||||
} else if(strcmp(arg, "-L") == 0 || strcmp(arg, "--length") == 0) {
|
||||
if(!take_value(argc, argv, &i, &value, arg) ||
|
||||
!parse_int(value, &cli->options.length))
|
||||
return 0;
|
||||
} else if(strcmp(arg, "-C") == 0 || strcmp(arg, "--counter") == 0) {
|
||||
int counter;
|
||||
|
||||
if(!take_value(argc, argv, &i, &value, arg) ||
|
||||
!parse_int(value, &counter))
|
||||
return 0;
|
||||
cli->options.counter = (unsigned long long)(counter < 0 ? 0 : counter);
|
||||
} else if(strcmp(arg, "-l") == 0 || strcmp(arg, "--lowercase") == 0) {
|
||||
cli->options.lowercase = 1;
|
||||
} else if(strcmp(arg, "-u") == 0 || strcmp(arg, "--uppercase") == 0) {
|
||||
cli->options.uppercase = 1;
|
||||
} else if(strcmp(arg, "-d") == 0 || strcmp(arg, "--digits") == 0) {
|
||||
cli->options.digits = 1;
|
||||
} else if(strcmp(arg, "-s") == 0 || strcmp(arg, "--symbols") == 0) {
|
||||
cli->options.symbols = 1;
|
||||
} else if(strcmp(arg, "--no-lowercase") == 0) {
|
||||
cli->options.lowercase = 0;
|
||||
} else if(strcmp(arg, "--no-uppercase") == 0) {
|
||||
cli->options.uppercase = 0;
|
||||
} else if(strcmp(arg, "--no-digits") == 0) {
|
||||
cli->options.digits = 0;
|
||||
} else if(strcmp(arg, "--no-symbols") == 0) {
|
||||
cli->options.symbols = 0;
|
||||
} else if(strcmp(arg, "--exclude") == 0) {
|
||||
if(!take_value(argc, argv, &i, &value, arg))
|
||||
return 0;
|
||||
cli->options.exclude = value;
|
||||
} else if(strcmp(arg, "-p") == 0 || strcmp(arg, "--prompt") == 0) {
|
||||
cli->prompt = 1;
|
||||
} else if(strcmp(arg, "-c") == 0 || strcmp(arg, "--copy") == 0) {
|
||||
cli->copy = 1;
|
||||
} else if(strcmp(arg, "--no-copy") == 0) {
|
||||
cli->no_copy = 1;
|
||||
} else if(arg[0] == '-') {
|
||||
fprintf(stderr, "pass: unknown option %s\n", arg);
|
||||
return 0;
|
||||
} else if(positional == 0) {
|
||||
cli->site = arg;
|
||||
positional++;
|
||||
} else if(positional == 1) {
|
||||
cli->login = arg;
|
||||
positional++;
|
||||
} else if(positional == 2) {
|
||||
cli->master = arg;
|
||||
positional++;
|
||||
} else {
|
||||
fprintf(stderr, "pass: too many positional arguments\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
Cli cli;
|
||||
char master[1024];
|
||||
char out[256];
|
||||
char err[256];
|
||||
const char *env_master;
|
||||
|
||||
memset(&cli, 0, sizeof(cli));
|
||||
cli.options.length = 16;
|
||||
cli.options.counter = 1;
|
||||
cli.options.lowercase = 1;
|
||||
cli.options.uppercase = 1;
|
||||
cli.options.digits = 1;
|
||||
cli.options.symbols = 1;
|
||||
cli.options.exclude = "";
|
||||
|
||||
if(!parse_args(argc, argv, &cli)) {
|
||||
usage(stderr);
|
||||
return 2;
|
||||
}
|
||||
if(cli.show_version) {
|
||||
printf("pass %s\n", PASS_VERSION);
|
||||
return 0;
|
||||
}
|
||||
if(cli.site == NULL || cli.login == NULL) {
|
||||
usage(stderr);
|
||||
return 2;
|
||||
}
|
||||
if(cli.copy && !cli.no_copy) {
|
||||
fprintf(stderr, "pass: --copy is not available in the C CLI yet\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
memset(master, 0, sizeof(master));
|
||||
if(cli.master != NULL) {
|
||||
snprintf(master, sizeof(master), "%s", cli.master);
|
||||
} else if(!cli.prompt && (env_master = getenv(MASTER_ENV)) != NULL) {
|
||||
snprintf(master, sizeof(master), "%s", env_master);
|
||||
} else {
|
||||
if(!read_line(master, sizeof(master))) {
|
||||
fprintf(stderr, "pass: missing master password\n");
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
memset(out, 0, sizeof(out));
|
||||
memset(err, 0, sizeof(err));
|
||||
if(pass_core_generate(cli.site, cli.login, master, &cli.options,
|
||||
out, sizeof(out), err, sizeof(err)) != 0) {
|
||||
fprintf(stderr, "pass: %s\n", err);
|
||||
return 1;
|
||||
}
|
||||
printf("%s\n", out);
|
||||
memset(master, 0, sizeof(master));
|
||||
memset(out, 0, sizeof(out));
|
||||
return 0;
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
/* C port of the pass Go generator (pass.go, pbkdf2.go). The output is
|
||||
* byte-identical to the Go implementation; native/pass_core_test.c checks
|
||||
* the same fixed vectors the Go tests use. */
|
||||
/* LessPass-compatible generator used by the CLI and every Kry app target.
|
||||
* native/pass_core_test.c checks fixed vectors for byte stability. */
|
||||
|
||||
#include "pass_core.h"
|
||||
|
||||
@@ -176,11 +175,88 @@ sha256(const void *data, size_t len, uint8_t out[32])
|
||||
}
|
||||
|
||||
void
|
||||
pass_sha256(const void *data, size_t len, uint8_t out[32])
|
||||
pass_core_sha256(const void *data, size_t len, uint8_t out[32])
|
||||
{
|
||||
sha256(data, len, out);
|
||||
}
|
||||
|
||||
static const int MASTER_EMOJI_CODEPOINTS[] = {
|
||||
0x1F436, 0x1F431, 0x1F42D, 0x1F439, 0x1F430, 0x1F98A, 0x1F43B, 0x1F43C,
|
||||
0x1F428, 0x1F42F, 0x1F981, 0x1F42E, 0x1F437, 0x1F438, 0x1F435, 0x1F414,
|
||||
0x1F427, 0x1F989, 0x1F43A, 0x1F434, 0x1F984, 0x1F41D, 0x1F98B, 0x1F422,
|
||||
0x1F34E, 0x1F34A, 0x1F34B, 0x1F349, 0x1F347, 0x1F353, 0x1F352, 0x1F351,
|
||||
0x1F951, 0x1F33D, 0x1F355, 0x1F354, 0x1F35F, 0x1F369, 0x1F335, 0x1F332,
|
||||
0x1F333, 0x1F334, 0x1F331, 0x1F33B, 0x1F338, 0x1F308, 0x2B50, 0x1F319,
|
||||
0x1F525, 0x1F4A7, 0x26C4, 0x1F389, 0x1F3B8, 0x1F3AF, 0x1F3B2, 0x1F381,
|
||||
0x1F680, 0x1F697, 0x2693, 0x1F3A8, 0x1F511, 0x1F4A1, 0x1F4DA, 0x1F3A7,
|
||||
};
|
||||
|
||||
const int *
|
||||
pass_core_master_emoji_codepoints(int *count)
|
||||
{
|
||||
if(count != NULL)
|
||||
*count = (int)(sizeof(MASTER_EMOJI_CODEPOINTS) /
|
||||
sizeof(MASTER_EMOJI_CODEPOINTS[0]));
|
||||
return MASTER_EMOJI_CODEPOINTS;
|
||||
}
|
||||
|
||||
static size_t
|
||||
append_utf8(char *out, size_t used, size_t out_size, uint32_t codepoint)
|
||||
{
|
||||
unsigned char bytes[4];
|
||||
int len = 0;
|
||||
|
||||
if(out == NULL || out_size == 0)
|
||||
return 0;
|
||||
if(codepoint <= 0x7Fu) {
|
||||
bytes[0] = (unsigned char)codepoint;
|
||||
len = 1;
|
||||
} else if(codepoint <= 0x7FFu) {
|
||||
bytes[0] = (unsigned char)(0xC0u | (codepoint >> 6));
|
||||
bytes[1] = (unsigned char)(0x80u | (codepoint & 0x3Fu));
|
||||
len = 2;
|
||||
} else if(codepoint <= 0xFFFFu) {
|
||||
bytes[0] = (unsigned char)(0xE0u | (codepoint >> 12));
|
||||
bytes[1] = (unsigned char)(0x80u | ((codepoint >> 6) & 0x3Fu));
|
||||
bytes[2] = (unsigned char)(0x80u | (codepoint & 0x3Fu));
|
||||
len = 3;
|
||||
} else if(codepoint <= 0x10FFFFu) {
|
||||
bytes[0] = (unsigned char)(0xF0u | (codepoint >> 18));
|
||||
bytes[1] = (unsigned char)(0x80u | ((codepoint >> 12) & 0x3Fu));
|
||||
bytes[2] = (unsigned char)(0x80u | ((codepoint >> 6) & 0x3Fu));
|
||||
bytes[3] = (unsigned char)(0x80u | (codepoint & 0x3Fu));
|
||||
len = 4;
|
||||
}
|
||||
|
||||
if(len <= 0 || used + (size_t)len >= out_size) {
|
||||
out[used < out_size ? used : out_size - 1] = '\0';
|
||||
return used;
|
||||
}
|
||||
memcpy(out + used, bytes, (size_t)len);
|
||||
used += (size_t)len;
|
||||
out[used] = '\0';
|
||||
return used;
|
||||
}
|
||||
|
||||
void
|
||||
pass_core_master_emoji(const char *master, char *out, size_t out_size)
|
||||
{
|
||||
uint8_t sum[32];
|
||||
size_t used = 0;
|
||||
int table_count = 0;
|
||||
const int *table = pass_core_master_emoji_codepoints(&table_count);
|
||||
|
||||
if(out == NULL || out_size == 0)
|
||||
return;
|
||||
out[0] = '\0';
|
||||
if(master == NULL)
|
||||
master = "";
|
||||
pass_core_sha256(master, strlen(master), sum);
|
||||
for(int i = 0; i < PASS_MASTER_EMOJI_COUNT && table_count > 0; i++)
|
||||
used = append_utf8(out, used, out_size,
|
||||
(uint32_t)table[sum[i] % table_count]);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* HMAC-SHA256 */
|
||||
/* ------------------------------------------------------------------ */
|
||||
@@ -223,9 +299,9 @@ hmac_sha256(const void *key, size_t key_len,
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
void
|
||||
pass_derive_key(const char *password, size_t password_len,
|
||||
const char *salt, size_t salt_len,
|
||||
uint8_t out[32])
|
||||
pass_core_derive_key(const char *password, size_t password_len,
|
||||
const char *salt, size_t salt_len,
|
||||
uint8_t out[32])
|
||||
{
|
||||
uint8_t block_input[512];
|
||||
uint8_t previous[32];
|
||||
@@ -309,10 +385,10 @@ class_filtered(const char *characters, const char *exclude, char *out, int out_s
|
||||
}
|
||||
|
||||
int
|
||||
pass_generate(const char *site, const char *login, const char *master,
|
||||
const PassOptions *options,
|
||||
char *out, size_t out_size,
|
||||
char *err, size_t err_size)
|
||||
pass_core_generate(const char *site, const char *login, const char *master,
|
||||
const PassOptions *options,
|
||||
char *out, size_t out_size,
|
||||
char *err, size_t err_size)
|
||||
{
|
||||
static const char *class_names[4] = {"lowercase", "uppercase", "digits", "symbols"};
|
||||
static const char *class_sets[4] = {
|
||||
@@ -336,8 +412,12 @@ pass_generate(const char *site, const char *login, const char *master,
|
||||
char message[192];
|
||||
int i;
|
||||
|
||||
if(options->length < 1)
|
||||
return set_error(err, err_size, "password length must be positive");
|
||||
if(options->length < PASS_MIN_LENGTH || options->length > PASS_MAX_LENGTH) {
|
||||
snprintf(message, sizeof(message),
|
||||
"password length must be between %d and %d",
|
||||
PASS_MIN_LENGTH, PASS_MAX_LENGTH);
|
||||
return set_error(err, err_size, message);
|
||||
}
|
||||
|
||||
for(i = 0; i < 4; i++) {
|
||||
if(!class_enabled[i])
|
||||
@@ -363,6 +443,9 @@ pass_generate(const char *site, const char *login, const char *master,
|
||||
options->length, class_count);
|
||||
return set_error(err, err_size, message);
|
||||
}
|
||||
if(options->length == class_count)
|
||||
return set_error(err, err_size,
|
||||
"password length must leave room for generated characters");
|
||||
if((size_t)options->length + 1 > out_size || options->length + 1 > (int)sizeof(password))
|
||||
return set_error(err, err_size, "password length exceeds the output buffer");
|
||||
|
||||
@@ -384,10 +467,10 @@ pass_generate(const char *site, const char *login, const char *master,
|
||||
salt_len += login_len;
|
||||
}
|
||||
salt_len += (size_t)snprintf(salt + salt_len, sizeof(salt) - salt_len,
|
||||
"%llu", (unsigned long long)options->counter);
|
||||
"%llx", (unsigned long long)options->counter);
|
||||
|
||||
pass_derive_key(master != NULL ? master : "", master != NULL ? strlen(master) : 0,
|
||||
salt, salt_len, entropy);
|
||||
pass_core_derive_key(master != NULL ? master : "", master != NULL ? strlen(master) : 0,
|
||||
salt, salt_len, entropy);
|
||||
|
||||
password_length = options->length - class_count;
|
||||
for(i = 0; i < password_length; i++)
|
||||
@@ -397,7 +480,7 @@ pass_generate(const char *site, const char *login, const char *master,
|
||||
required[i] = classes[i][entropy_take_remainder(entropy, class_lengths[i])];
|
||||
|
||||
for(i = 0; i < class_count; i++) {
|
||||
int position = entropy_take_remainder(entropy, password_length + 1);
|
||||
int position = entropy_take_remainder(entropy, password_length);
|
||||
|
||||
memmove(password + position + 1, password + position,
|
||||
(size_t)(password_length - position));
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#define PASS_DERIVATION_ROUNDS 100000
|
||||
#define PASS_MASTER_EMOJI_COUNT 4
|
||||
#define PASS_MIN_LENGTH 5
|
||||
#define PASS_MAX_LENGTH 35
|
||||
|
||||
typedef struct {
|
||||
int length;
|
||||
@@ -18,20 +21,23 @@ typedef struct {
|
||||
|
||||
/* Derives the 32-byte PBKDF2-HMAC-SHA256 key (one block, 100000 rounds),
|
||||
* the byte-exact counterpart of the Go package's deriveKey. */
|
||||
void pass_derive_key(const char *password, size_t password_len,
|
||||
const char *salt, size_t salt_len,
|
||||
uint8_t out[32]);
|
||||
void pass_core_derive_key(const char *password, size_t password_len,
|
||||
const char *salt, size_t salt_len,
|
||||
uint8_t out[32]);
|
||||
|
||||
/* Computes SHA-256. Shared with UI code that must match the Go package's
|
||||
* master-password fingerprint derivation. */
|
||||
void pass_sha256(const void *data, size_t len, uint8_t out[32]);
|
||||
void pass_core_sha256(const void *data, size_t len, uint8_t out[32]);
|
||||
|
||||
const int *pass_core_master_emoji_codepoints(int *count);
|
||||
void pass_core_master_emoji(const char *master, char *out, size_t out_size);
|
||||
|
||||
/* Generates a LessPass-compatible password. Returns 0 on success and writes
|
||||
* the NUL-terminated password into out. Returns nonzero on invalid options
|
||||
* and writes the reason into err (English, matches the Go error strings). */
|
||||
int pass_generate(const char *site, const char *login, const char *master,
|
||||
const PassOptions *options,
|
||||
char *out, size_t out_size,
|
||||
char *err, size_t err_size);
|
||||
int pass_core_generate(const char *site, const char *login, const char *master,
|
||||
const PassOptions *options,
|
||||
char *out, size_t out_size,
|
||||
char *err, size_t err_size);
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Host-buildable vector test for pass_core.c. The vectors are copied from
|
||||
* the Go tests (pass_test.go) so the C generator stays byte-compatible. */
|
||||
/* Host-buildable vector test for pass_core.c. The vectors lock the generator
|
||||
* output so CLI, desktop, Android, and web stay byte-compatible. */
|
||||
|
||||
#include "pass_core.h"
|
||||
|
||||
@@ -19,7 +19,7 @@ check_generate(int index, const char *site, const char *login, const char *maste
|
||||
|
||||
memset(out, 0, sizeof(out));
|
||||
memset(err, 0, sizeof(err));
|
||||
result = pass_generate(site, login, master, &options, out, sizeof(out), err, sizeof(err));
|
||||
result = pass_core_generate(site, login, master, &options, out, sizeof(out), err, sizeof(err));
|
||||
|
||||
if(want_error) {
|
||||
if(result == 0) {
|
||||
@@ -52,7 +52,7 @@ check_derive(int index, const char *password, const char *salt, const char *want
|
||||
char hex[65];
|
||||
int i;
|
||||
|
||||
pass_derive_key(password, strlen(password), salt, strlen(salt), out);
|
||||
pass_core_derive_key(password, strlen(password), salt, strlen(salt), out);
|
||||
for(i = 0; i < 32; i++)
|
||||
sprintf(hex + i * 2, "%02x", out[i]);
|
||||
hex[64] = '\0';
|
||||
@@ -66,25 +66,146 @@ check_derive(int index, const char *password, const char *salt, const char *want
|
||||
}
|
||||
|
||||
static void
|
||||
check_sha256(void)
|
||||
check_derive_bytes(int index, const char *password, size_t password_len,
|
||||
const char *salt, size_t salt_len, const char *want_hex)
|
||||
{
|
||||
uint8_t out[32];
|
||||
char hex[65];
|
||||
int i;
|
||||
|
||||
pass_sha256("correct horse battery staple", strlen("correct horse battery staple"), out);
|
||||
pass_core_derive_key(password, password_len, salt, salt_len, out);
|
||||
for(i = 0; i < 32; i++)
|
||||
sprintf(hex + i * 2, "%02x", out[i]);
|
||||
hex[64] = '\0';
|
||||
|
||||
if(strcmp(hex, "c4bbcb1fbec99d65bf59d85c8cb62ee2db963f0fe106f483d9afa73bd4e39a8a") != 0) {
|
||||
printf("FAIL sha256: got %s\n", hex);
|
||||
if(strcmp(hex, want_hex) != 0) {
|
||||
printf("FAIL derive %d: got %s, want %s\n", index, hex, want_hex);
|
||||
failures++;
|
||||
} else {
|
||||
printf("ok sha256: %s\n", hex);
|
||||
printf("ok derive %d: %s\n", index, hex);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
check_sha256_hex(int index, const void *data, size_t len, const char *want_hex)
|
||||
{
|
||||
uint8_t out[32];
|
||||
char hex[65];
|
||||
int i;
|
||||
|
||||
pass_core_sha256(data, len, out);
|
||||
for(i = 0; i < 32; i++)
|
||||
sprintf(hex + i * 2, "%02x", out[i]);
|
||||
hex[64] = '\0';
|
||||
|
||||
if(strcmp(hex, want_hex) != 0) {
|
||||
printf("FAIL sha256 %d: got %s, want %s\n", index, hex, want_hex);
|
||||
failures++;
|
||||
} else {
|
||||
printf("ok sha256 %d: %s\n", index, hex);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
check_sha256(void)
|
||||
{
|
||||
char sixty[60];
|
||||
|
||||
memset(sixty, 'a', sizeof(sixty));
|
||||
check_sha256_hex(1, "", 0,
|
||||
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
|
||||
check_sha256_hex(2, "abc", 3,
|
||||
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
|
||||
check_sha256_hex(3, "correct horse battery staple",
|
||||
strlen("correct horse battery staple"),
|
||||
"c4bbcb1fbec99d65bf59d85c8cb62ee2db963f0fe106f483d9afa73bd4e39a8a");
|
||||
check_sha256_hex(4, sixty, sizeof(sixty),
|
||||
"11ee391211c6256460b6ed375957fadd8061cafbb31daf967db875aebd5aaad4");
|
||||
}
|
||||
|
||||
static int
|
||||
utf8_codepoint_count(const char *text)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
if(text == NULL)
|
||||
return 0;
|
||||
for(int i = 0; text[i] != '\0'; i++) {
|
||||
unsigned char c = (unsigned char)text[i];
|
||||
if((c & 0xC0u) != 0x80u)
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static void
|
||||
check_master_emoji(void)
|
||||
{
|
||||
char first[64];
|
||||
char again[64];
|
||||
char empty[64];
|
||||
char values[5][64];
|
||||
int table_count = 0;
|
||||
const int *table = pass_core_master_emoji_codepoints(&table_count);
|
||||
|
||||
if(table == NULL || table_count != 64) {
|
||||
printf("FAIL master emoji: table count %d, want 64\n", table_count);
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
|
||||
pass_core_master_emoji("correct horse battery staple", first, sizeof(first));
|
||||
pass_core_master_emoji("correct horse battery staple", again, sizeof(again));
|
||||
pass_core_master_emoji(NULL, empty, sizeof(empty));
|
||||
pass_core_master_emoji("ignored", NULL, sizeof(empty));
|
||||
pass_core_master_emoji("ignored", empty, 0);
|
||||
if(strcmp(first, again) != 0 ||
|
||||
utf8_codepoint_count(first) != PASS_MASTER_EMOJI_COUNT) {
|
||||
printf("FAIL master emoji: deterministic=%d count=%d value=%s\n",
|
||||
strcmp(first, again) == 0,
|
||||
utf8_codepoint_count(first), first);
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
|
||||
pass_core_master_emoji("", empty, sizeof(empty));
|
||||
if(utf8_codepoint_count(empty) != PASS_MASTER_EMOJI_COUNT) {
|
||||
printf("FAIL master emoji: empty count=%d value=%s\n",
|
||||
utf8_codepoint_count(empty), empty);
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
{
|
||||
char tiny[2];
|
||||
|
||||
tiny[0] = 'x';
|
||||
tiny[1] = '\0';
|
||||
pass_core_master_emoji("correct horse battery staple", tiny, sizeof(tiny));
|
||||
if(tiny[0] != '\0') {
|
||||
printf("FAIL master emoji: tiny buffer value=%s\n", tiny);
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
pass_core_master_emoji("test", values[0], sizeof(values[0]));
|
||||
pass_core_master_emoji("test2", values[1], sizeof(values[1]));
|
||||
pass_core_master_emoji("tset", values[2], sizeof(values[2]));
|
||||
pass_core_master_emoji("hunter2", values[3], sizeof(values[3]));
|
||||
pass_core_master_emoji("correct horse battery staple", values[4], sizeof(values[4]));
|
||||
for(int i = 0; i < 5; i++) {
|
||||
for(int j = i + 1; j < 5; j++) {
|
||||
if(strcmp(values[i], values[j]) == 0) {
|
||||
printf("FAIL master emoji: collision %d/%d = %s\n", i, j, values[i]);
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("ok master emoji: %s\n", first);
|
||||
}
|
||||
|
||||
static void
|
||||
check_shape(void)
|
||||
{
|
||||
@@ -99,7 +220,7 @@ check_shape(void)
|
||||
int i, j, has_lower, has_upper, has_digits, has_symbols;
|
||||
|
||||
memset(&options, 0, sizeof(options));
|
||||
options.length = 40;
|
||||
options.length = 35;
|
||||
options.counter = 3;
|
||||
options.lowercase = 1;
|
||||
options.uppercase = 1;
|
||||
@@ -107,13 +228,13 @@ check_shape(void)
|
||||
options.symbols = 1;
|
||||
options.exclude = exclude;
|
||||
|
||||
if(pass_generate("host", "account", "secret", &options, out, sizeof(out), err, sizeof(err)) != 0) {
|
||||
if(pass_core_generate("host", "account", "secret", &options, out, sizeof(out), err, sizeof(err)) != 0) {
|
||||
printf("FAIL shape: %s\n", err);
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
if((int)strlen(out) != 40) {
|
||||
printf("FAIL shape: length %zu, want 40\n", strlen(out));
|
||||
if((int)strlen(out) != 35) {
|
||||
printf("FAIL shape: length %zu, want 35\n", strlen(out));
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
@@ -143,7 +264,7 @@ check_shape(void)
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
printf("ok shape: 40 chars, all classes covered, exclusions honored\n");
|
||||
printf("ok shape: 35 chars, all classes covered, exclusions honored\n");
|
||||
}
|
||||
|
||||
int
|
||||
@@ -155,7 +276,22 @@ main(void)
|
||||
"0394a2ede332c9a13eb82e9b24631604c31df978b4e2f0fbd2c549944f9d79a5");
|
||||
check_derive(2, "", "examplealice1",
|
||||
"caa46554f5a676b76c15b368c655b0b24eaaad8595ef919999785c68e60fd5f5");
|
||||
check_derive(3, "test", "sitelogina",
|
||||
"91b368e6337bd9c7007041922ade15c2907bd53c450f73e0ba1a001e10bff7eb");
|
||||
{
|
||||
char long_password[80];
|
||||
char long_salt[700];
|
||||
|
||||
memset(long_password, 'a', sizeof(long_password));
|
||||
memset(long_salt, 'b', sizeof(long_salt));
|
||||
check_derive_bytes(4, long_password, sizeof(long_password), "salt", 4,
|
||||
"2ff041c8085dbce46f9dc5a4e8b9e5eb1d1727318c540f6697b5b0a368e158ad");
|
||||
check_derive_bytes(5, "password", strlen("password"),
|
||||
long_salt, sizeof(long_salt),
|
||||
"3a4d1af4f539070e6fb4b2a0709071d03e01c7fb6c2659f6a84811eae850150b");
|
||||
}
|
||||
check_sha256();
|
||||
check_master_emoji();
|
||||
|
||||
memset(&defaults, 0, sizeof(defaults));
|
||||
defaults.length = 16;
|
||||
@@ -167,7 +303,7 @@ main(void)
|
||||
defaults.exclude = "";
|
||||
|
||||
check_generate(1, "example.com", "alice", "correct horse battery staple",
|
||||
defaults, "&vLf44D'/cSkP-_8", 0);
|
||||
defaults, "&Lf4'/-cSk4DPv_8", 0);
|
||||
|
||||
{
|
||||
PassOptions o = defaults;
|
||||
@@ -175,7 +311,7 @@ main(void)
|
||||
o.length = 20;
|
||||
o.counter = 2;
|
||||
check_generate(2, "service.test", "[email protected]", "master",
|
||||
o, "j:x_Lo5X_jL0w%ez`1be", 0);
|
||||
o, "j:x_Lo5b1XL_j0we%z`e", 0);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -188,7 +324,7 @@ main(void)
|
||||
o.digits = 1;
|
||||
check_generate(3, "\xce\xb4\xce\xbf\xce\xba\xce\xb9\xce\xbc\xce\xae.example",
|
||||
"\xe3\x83\xa6\xe3\x83\xbc\xe3\x82\xb6\xe3\x83\xbc",
|
||||
"p\xc3\xa4ssword", o, "ioh5o2mhyghv", 0);
|
||||
"p\xc3\xa4ssword", o, "oih5omhygh2v", 0);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -197,18 +333,36 @@ main(void)
|
||||
o.length = 24;
|
||||
o.exclude = "0Ool1I!|";
|
||||
check_generate(4, "example.com", "alice", "correct horse battery staple",
|
||||
o, "7,a.Cp}YnF'ee7HqbX#PQhgH", 0);
|
||||
o, "7,.Cp}YnF'eeHHaqbX7#PQhg", 0);
|
||||
}
|
||||
|
||||
{
|
||||
PassOptions o;
|
||||
|
||||
memset(&o, 0, sizeof(o));
|
||||
o.length = 4;
|
||||
o.length = 5;
|
||||
o.counter = 0;
|
||||
o.uppercase = 1;
|
||||
o.digits = 1;
|
||||
check_generate(5, "x", "y", "", o, "9O7C", 0);
|
||||
check_generate(5, "x", "y", "", o, "C9O9I", 0);
|
||||
}
|
||||
|
||||
{
|
||||
PassOptions o = defaults;
|
||||
|
||||
check_generate(6, "lesspass.com", "[email protected]", "password",
|
||||
o, "\\g-A1-.OHEwrXjT#", 0);
|
||||
}
|
||||
|
||||
{
|
||||
PassOptions o = defaults;
|
||||
|
||||
o.counter = 10;
|
||||
check_generate(7, "site", "login", "test",
|
||||
o, "XFt0F*,r619:+}[.", 0);
|
||||
o.counter = 16;
|
||||
check_generate(8, "site", "login", "test",
|
||||
o, "l:`nzj>S7+0#uL_d", 0);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -217,7 +371,7 @@ main(void)
|
||||
memset(&o, 0, sizeof(o));
|
||||
o.length = 0;
|
||||
o.lowercase = 1;
|
||||
check_generate(6, "site", "login", "master", o, "", 1);
|
||||
check_generate(9, "site", "login", "master", o, "", 1);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -225,7 +379,7 @@ main(void)
|
||||
|
||||
memset(&o, 0, sizeof(o));
|
||||
o.length = 8;
|
||||
check_generate(7, "site", "login", "master", o, "", 1);
|
||||
check_generate(10, "site", "login", "master", o, "", 1);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -236,7 +390,7 @@ main(void)
|
||||
o.lowercase = 1;
|
||||
o.uppercase = 1;
|
||||
o.digits = 1;
|
||||
check_generate(8, "site", "login", "master", o, "", 1);
|
||||
check_generate(11, "site", "login", "master", o, "", 1);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -246,7 +400,42 @@ main(void)
|
||||
o.length = 8;
|
||||
o.digits = 1;
|
||||
o.exclude = "0123456789";
|
||||
check_generate(9, "site", "login", "master", o, "", 1);
|
||||
check_generate(12, "site", "login", "master", o, "", 1);
|
||||
}
|
||||
|
||||
{
|
||||
PassOptions o = defaults;
|
||||
|
||||
o.length = 4;
|
||||
check_generate(13, "site", "login", "master", o, "", 1);
|
||||
}
|
||||
|
||||
{
|
||||
PassOptions o = defaults;
|
||||
char out[4];
|
||||
char err[128];
|
||||
|
||||
memset(out, 0, sizeof(out));
|
||||
memset(err, 0, sizeof(err));
|
||||
if(pass_core_generate("site", "login", "master", &o,
|
||||
out, sizeof(out), err, sizeof(err)) == 0 ||
|
||||
strcmp(err, "password length exceeds the output buffer") != 0) {
|
||||
printf("FAIL small output buffer: %s\n", err);
|
||||
failures++;
|
||||
} else {
|
||||
printf("ok small output buffer: %s\n", err);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
PassOptions o = defaults;
|
||||
char long_text[700];
|
||||
|
||||
memset(long_text, 'x', sizeof(long_text) - 1);
|
||||
long_text[sizeof(long_text) - 1] = '\0';
|
||||
check_generate(14, long_text, "login", "master", o, "", 1);
|
||||
check_generate(15, "site", long_text, "master", o, "", 1);
|
||||
check_generate(16, NULL, NULL, NULL, o, "bb8^CBroRNj%4sP_", 0);
|
||||
}
|
||||
|
||||
check_shape();
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
/* Native Plan 9 entry point for Pass (Kryon libdraw backend).
|
||||
*
|
||||
* Mirrors droid/app/src/main/cpp/main.c: owns the window, theme, fonts,
|
||||
* and the frame loop. Switches to the user's home directory first so the
|
||||
* profiles file and kryon app-storage settings land in $home instead of
|
||||
* the source tree. */
|
||||
|
||||
#include "kryon.h"
|
||||
#include "embedded_assets.h"
|
||||
#include "app_runtime.h"
|
||||
#include "app/pass.h"
|
||||
#include "pass_runtime.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const char *const FONT_ASSET_PATH = "vendor/kryon/fonts/noto/NotoSans-Regular.ttf";
|
||||
static const char *const EMOJI_FONT_ASSET_PATH = "assets/fonts/emoji.ttf";
|
||||
|
||||
/* The generated project host references the app lifecycle hooks weakly,
|
||||
* and the native Plan 9 linker has no weak symbols; this entry point
|
||||
* drives the loop itself, so the hooks stay inert. */
|
||||
void *CreateApp(const char *project_path)
|
||||
{
|
||||
(void)project_path;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void DestroyApp(void *app)
|
||||
{
|
||||
(void)app;
|
||||
}
|
||||
|
||||
void ApplyRoute(void *app, const AppRouteInfo *route)
|
||||
{
|
||||
(void)app;
|
||||
(void)route;
|
||||
}
|
||||
|
||||
void BeginScreenDraw(void *app, Rectangle viewport)
|
||||
{
|
||||
(void)app;
|
||||
(void)viewport;
|
||||
}
|
||||
|
||||
static void
|
||||
setup_shapes_texture(void)
|
||||
{
|
||||
Image white = GenImageColor(1, 1, WHITE);
|
||||
Texture2D texture = LoadTextureFromImage(white);
|
||||
|
||||
UnloadImage(white);
|
||||
if(texture.id == 0)
|
||||
return;
|
||||
SetTextureFilter(texture, TEXTURE_FILTER_POINT);
|
||||
SetShapesTexture(texture, (Rectangle){0.0f, 0.0f, 1.0f, 1.0f});
|
||||
}
|
||||
|
||||
static int
|
||||
setup_ui_font(void)
|
||||
{
|
||||
const EmbeddedAsset *asset = GetEmbeddedAsset(FONT_ASSET_PATH);
|
||||
|
||||
if(asset == NULL || asset->data == NULL || asset->size == 0) {
|
||||
TraceLog(LOG_WARNING, "PASS: missing embedded font asset");
|
||||
return 0;
|
||||
}
|
||||
if(!RegisterUIFontSource("ui", GetEmbeddedAssetExtension(FONT_ASSET_PATH),
|
||||
asset->data, asset->size, NULL, 0)) {
|
||||
TraceLog(LOG_WARNING, "PASS: RegisterUIFontSource failed");
|
||||
return 0;
|
||||
}
|
||||
if(!UseUIFont("ui")) {
|
||||
TraceLog(LOG_WARNING, "PASS: UseUIFont failed");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
setup_emoji_font(void)
|
||||
{
|
||||
const EmbeddedAsset *asset = GetEmbeddedAsset(EMOJI_FONT_ASSET_PATH);
|
||||
int codepoint_count = 0;
|
||||
const int *codepoints = pass_runtime_master_emoji_codepoints(&codepoint_count);
|
||||
|
||||
if(asset == NULL || asset->data == NULL || asset->size == 0) {
|
||||
TraceLog(LOG_WARNING, "PASS: missing embedded emoji font asset");
|
||||
return 0;
|
||||
}
|
||||
if(!RegisterUIFixedFontSource("pass-emoji",
|
||||
GetEmbeddedAssetExtension(EMOJI_FONT_ASSET_PATH),
|
||||
asset->data, asset->size, codepoints, codepoint_count)) {
|
||||
TraceLog(LOG_WARNING, "PASS: RegisterUIFixedFontSource failed for emoji");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
const char *home;
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
home = getenv("home");
|
||||
if(home == NULL)
|
||||
home = getenv("HOME");
|
||||
if(home != NULL && home[0] != '\0') {
|
||||
if(chdir(home) != 0)
|
||||
TraceLog(LOG_WARNING, "PASS: failed to switch to home directory");
|
||||
}
|
||||
|
||||
InitWindow(540, 700, "Pass");
|
||||
if(!IsWindowReady()) {
|
||||
TraceLog(LOG_ERROR, "PASS: InitWindow failed");
|
||||
return 1;
|
||||
}
|
||||
InitUIDPI();
|
||||
SetThemeStyle(THEME_STYLE_MATERIAL);
|
||||
SetCurrentTheme(GetDefaultThemeForThemeStyle(THEME_STYLE_MATERIAL), 0);
|
||||
ApplyCurrentUITheme();
|
||||
setup_ui_font();
|
||||
setup_emoji_font();
|
||||
setup_shapes_texture();
|
||||
SetTargetFPS(60);
|
||||
|
||||
pass_runtime_init();
|
||||
TraceLog(LOG_INFO, "PASS: app ready");
|
||||
while(!WindowShouldClose()) {
|
||||
BeginFrame();
|
||||
BeginUIFrame(GetFrameWidth(), GetFrameHeight(), GetFrameScale());
|
||||
pass_runtime_tick();
|
||||
pass_frame();
|
||||
EndUIFrame();
|
||||
EndFrame();
|
||||
}
|
||||
|
||||
pass_runtime_shutdown();
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,758 @@
|
||||
#include "pass_runtime.h"
|
||||
|
||||
#include "pass_core.h"
|
||||
|
||||
#include "android_host.h"
|
||||
#include "app_storage.h"
|
||||
#include "kryon.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define PASS_MAX_PROFILES 64
|
||||
#define PASS_NAME_SIZE 64
|
||||
#define PASS_SITE_SIZE 256
|
||||
#define PASS_LOGIN_SIZE 256
|
||||
#define PASS_EXCLUDE_SIZE 128
|
||||
#define PASS_PASSWORD_SIZE 256
|
||||
#define PASS_STATUS_SIZE 256
|
||||
#define PASS_SETTINGS_SCOPE "pass"
|
||||
|
||||
typedef struct {
|
||||
char name[PASS_NAME_SIZE];
|
||||
char site[PASS_SITE_SIZE];
|
||||
char login[PASS_LOGIN_SIZE];
|
||||
int length;
|
||||
int counter;
|
||||
int lower;
|
||||
int upper;
|
||||
int digits;
|
||||
int symbols;
|
||||
char exclude[PASS_EXCLUDE_SIZE];
|
||||
} PassProfile;
|
||||
|
||||
typedef struct {
|
||||
int auto_copy;
|
||||
int clear_seconds;
|
||||
int show_fingerprint;
|
||||
int length;
|
||||
int counter;
|
||||
int lower;
|
||||
int upper;
|
||||
int digits;
|
||||
int symbols;
|
||||
char exclude[PASS_EXCLUDE_SIZE];
|
||||
int theme_source;
|
||||
int theme_mode;
|
||||
int theme_id;
|
||||
int theme_style;
|
||||
} PassRuntimeSettings;
|
||||
|
||||
typedef struct {
|
||||
PassRuntimeSettings settings;
|
||||
PassProfile profiles[PASS_MAX_PROFILES];
|
||||
int profile_count;
|
||||
char generated[PASS_PASSWORD_SIZE];
|
||||
char status[PASS_STATUS_SIZE];
|
||||
char fingerprint_status[PASS_STATUS_SIZE];
|
||||
char master_emoji[32];
|
||||
char profile_label[PASS_SITE_SIZE + PASS_LOGIN_SIZE + PASS_NAME_SIZE + 16];
|
||||
char unlocked_master[1024];
|
||||
int has_unlocked_master;
|
||||
int secure_action;
|
||||
double clipboard_clear_at;
|
||||
} PassRuntime;
|
||||
|
||||
enum {
|
||||
PASS_SECURE_ACTION_NONE = 0,
|
||||
PASS_SECURE_ACTION_SAVE,
|
||||
PASS_SECURE_ACTION_UNLOCK
|
||||
};
|
||||
|
||||
static PassRuntime runtime;
|
||||
static const char *const PASS_SECURE_MASTER_KEY = "default";
|
||||
|
||||
static void
|
||||
copy_text(char *dst, size_t dst_size, const char *src)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if(dst == NULL || dst_size == 0)
|
||||
return;
|
||||
if(src == NULL)
|
||||
src = "";
|
||||
len = strlen(src);
|
||||
if(len >= dst_size)
|
||||
len = dst_size - 1;
|
||||
memcpy(dst, src, len);
|
||||
dst[len] = '\0';
|
||||
}
|
||||
|
||||
static int
|
||||
clamp_length(int length)
|
||||
{
|
||||
if(length < PASS_MIN_LENGTH)
|
||||
return PASS_MIN_LENGTH;
|
||||
if(length > PASS_MAX_LENGTH)
|
||||
return PASS_MAX_LENGTH;
|
||||
return length;
|
||||
}
|
||||
|
||||
static void
|
||||
runtime_defaults(void)
|
||||
{
|
||||
memset(&runtime, 0, sizeof(runtime));
|
||||
runtime.settings.auto_copy = 0;
|
||||
runtime.settings.clear_seconds = 20;
|
||||
runtime.settings.show_fingerprint = 1;
|
||||
runtime.settings.length = 16;
|
||||
runtime.settings.counter = 1;
|
||||
runtime.settings.lower = 1;
|
||||
runtime.settings.upper = 1;
|
||||
runtime.settings.digits = 1;
|
||||
runtime.settings.symbols = 1;
|
||||
runtime.settings.exclude[0] = '\0';
|
||||
runtime.settings.theme_source = THEME_SOURCE_APP;
|
||||
runtime.settings.theme_mode = THEME_MODE_SYSTEM;
|
||||
runtime.settings.theme_id = THEME_SWEET;
|
||||
runtime.settings.theme_style = THEME_STYLE_MATERIAL;
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Ready");
|
||||
copy_text(runtime.fingerprint_status, sizeof(runtime.fingerprint_status), "No saved master password");
|
||||
}
|
||||
|
||||
static void
|
||||
trim_newline(char *s)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if(s == NULL)
|
||||
return;
|
||||
len = strlen(s);
|
||||
while(len > 0 && (s[len - 1] == '\n' || s[len - 1] == '\r')) {
|
||||
s[len - 1] = '\0';
|
||||
len--;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
load_legacy_settings(void)
|
||||
{
|
||||
FILE *f = fopen("settings.cfg", "r");
|
||||
char line[256];
|
||||
|
||||
if(f == NULL)
|
||||
return;
|
||||
while(fgets(line, sizeof(line), f) != NULL) {
|
||||
char *value;
|
||||
|
||||
trim_newline(line);
|
||||
value = strchr(line, '=');
|
||||
if(value == NULL)
|
||||
continue;
|
||||
*value++ = '\0';
|
||||
if(strcmp(line, "auto_copy") == 0)
|
||||
runtime.settings.auto_copy = atoi(value) != 0;
|
||||
else if(strcmp(line, "clear_after_seconds") == 0)
|
||||
runtime.settings.clear_seconds = atoi(value);
|
||||
else if(strcmp(line, "show_fingerprint") == 0)
|
||||
runtime.settings.show_fingerprint = atoi(value) != 0;
|
||||
else if(strcmp(line, "length") == 0)
|
||||
runtime.settings.length = clamp_length(atoi(value));
|
||||
else if(strcmp(line, "counter") == 0)
|
||||
runtime.settings.counter = atoi(value);
|
||||
else if(strcmp(line, "lower") == 0)
|
||||
runtime.settings.lower = atoi(value) != 0;
|
||||
else if(strcmp(line, "upper") == 0)
|
||||
runtime.settings.upper = atoi(value) != 0;
|
||||
else if(strcmp(line, "digits") == 0)
|
||||
runtime.settings.digits = atoi(value) != 0;
|
||||
else if(strcmp(line, "symbols") == 0)
|
||||
runtime.settings.symbols = atoi(value) != 0;
|
||||
else if(strcmp(line, "exclude") == 0)
|
||||
copy_text(runtime.settings.exclude, sizeof(runtime.settings.exclude), value);
|
||||
else if(strcmp(line, "theme_source") == 0)
|
||||
runtime.settings.theme_source = atoi(value);
|
||||
else if(strcmp(line, "theme_mode") == 0)
|
||||
runtime.settings.theme_mode = atoi(value);
|
||||
else if(strcmp(line, "theme_id") == 0)
|
||||
runtime.settings.theme_id = atoi(value);
|
||||
else if(strcmp(line, "theme_style") == 0)
|
||||
runtime.settings.theme_style = atoi(value);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void
|
||||
load_settings(void)
|
||||
{
|
||||
load_legacy_settings();
|
||||
KryAppStorageGetInt(PASS_SETTINGS_SCOPE, "auto_copy",
|
||||
runtime.settings.auto_copy,
|
||||
&runtime.settings.auto_copy);
|
||||
KryAppStorageGetInt(PASS_SETTINGS_SCOPE, "clear_after_seconds",
|
||||
runtime.settings.clear_seconds,
|
||||
&runtime.settings.clear_seconds);
|
||||
KryAppStorageGetInt(PASS_SETTINGS_SCOPE, "show_fingerprint",
|
||||
runtime.settings.show_fingerprint,
|
||||
&runtime.settings.show_fingerprint);
|
||||
KryAppStorageGetInt(PASS_SETTINGS_SCOPE, "length",
|
||||
runtime.settings.length,
|
||||
&runtime.settings.length);
|
||||
runtime.settings.length = clamp_length(runtime.settings.length);
|
||||
KryAppStorageGetInt(PASS_SETTINGS_SCOPE, "counter",
|
||||
runtime.settings.counter,
|
||||
&runtime.settings.counter);
|
||||
KryAppStorageGetInt(PASS_SETTINGS_SCOPE, "lower",
|
||||
runtime.settings.lower,
|
||||
&runtime.settings.lower);
|
||||
KryAppStorageGetInt(PASS_SETTINGS_SCOPE, "upper",
|
||||
runtime.settings.upper,
|
||||
&runtime.settings.upper);
|
||||
KryAppStorageGetInt(PASS_SETTINGS_SCOPE, "digits",
|
||||
runtime.settings.digits,
|
||||
&runtime.settings.digits);
|
||||
KryAppStorageGetInt(PASS_SETTINGS_SCOPE, "symbols",
|
||||
runtime.settings.symbols,
|
||||
&runtime.settings.symbols);
|
||||
KryAppStorageGetString(PASS_SETTINGS_SCOPE, "exclude",
|
||||
runtime.settings.exclude,
|
||||
runtime.settings.exclude,
|
||||
sizeof(runtime.settings.exclude));
|
||||
KryAppStorageGetInt(PASS_SETTINGS_SCOPE, "theme_source",
|
||||
runtime.settings.theme_source,
|
||||
&runtime.settings.theme_source);
|
||||
KryAppStorageGetInt(PASS_SETTINGS_SCOPE, "theme_mode",
|
||||
runtime.settings.theme_mode,
|
||||
&runtime.settings.theme_mode);
|
||||
KryAppStorageGetInt(PASS_SETTINGS_SCOPE, "theme_id",
|
||||
runtime.settings.theme_id,
|
||||
&runtime.settings.theme_id);
|
||||
KryAppStorageGetInt(PASS_SETTINGS_SCOPE, "theme_style",
|
||||
runtime.settings.theme_style,
|
||||
&runtime.settings.theme_style);
|
||||
}
|
||||
|
||||
static void
|
||||
migrate_default_theme_settings(void)
|
||||
{
|
||||
int legacy_system_default =
|
||||
runtime.settings.theme_source == THEME_SOURCE_SYSTEM &&
|
||||
runtime.settings.theme_mode == THEME_MODE_SYSTEM &&
|
||||
(runtime.settings.theme_id == THEME_MINT ||
|
||||
runtime.settings.theme_id == THEME_SWEET) &&
|
||||
(runtime.settings.theme_style == THEME_STYLE_SYSTEM ||
|
||||
runtime.settings.theme_style == THEME_STYLE_MATERIAL);
|
||||
|
||||
if(!legacy_system_default)
|
||||
return;
|
||||
|
||||
runtime.settings.theme_source = THEME_SOURCE_APP;
|
||||
runtime.settings.theme_mode = THEME_MODE_SYSTEM;
|
||||
runtime.settings.theme_id = THEME_SWEET;
|
||||
runtime.settings.theme_style = THEME_STYLE_MATERIAL;
|
||||
}
|
||||
|
||||
static int
|
||||
write_settings(void)
|
||||
{
|
||||
int ok = 1;
|
||||
|
||||
ok &= KryAppStorageSetInt(PASS_SETTINGS_SCOPE, "auto_copy",
|
||||
runtime.settings.auto_copy ? 1 : 0);
|
||||
ok &= KryAppStorageSetInt(PASS_SETTINGS_SCOPE, "clear_after_seconds",
|
||||
runtime.settings.clear_seconds);
|
||||
ok &= KryAppStorageSetInt(PASS_SETTINGS_SCOPE, "show_fingerprint",
|
||||
runtime.settings.show_fingerprint ? 1 : 0);
|
||||
ok &= KryAppStorageSetInt(PASS_SETTINGS_SCOPE, "length",
|
||||
runtime.settings.length);
|
||||
ok &= KryAppStorageSetInt(PASS_SETTINGS_SCOPE, "counter",
|
||||
runtime.settings.counter);
|
||||
ok &= KryAppStorageSetInt(PASS_SETTINGS_SCOPE, "lower",
|
||||
runtime.settings.lower ? 1 : 0);
|
||||
ok &= KryAppStorageSetInt(PASS_SETTINGS_SCOPE, "upper",
|
||||
runtime.settings.upper ? 1 : 0);
|
||||
ok &= KryAppStorageSetInt(PASS_SETTINGS_SCOPE, "digits",
|
||||
runtime.settings.digits ? 1 : 0);
|
||||
ok &= KryAppStorageSetInt(PASS_SETTINGS_SCOPE, "symbols",
|
||||
runtime.settings.symbols ? 1 : 0);
|
||||
ok &= KryAppStorageSetString(PASS_SETTINGS_SCOPE, "exclude",
|
||||
runtime.settings.exclude);
|
||||
ok &= KryAppStorageSetInt(PASS_SETTINGS_SCOPE, "theme_source",
|
||||
runtime.settings.theme_source);
|
||||
ok &= KryAppStorageSetInt(PASS_SETTINGS_SCOPE, "theme_mode",
|
||||
runtime.settings.theme_mode);
|
||||
ok &= KryAppStorageSetInt(PASS_SETTINGS_SCOPE, "theme_id",
|
||||
runtime.settings.theme_id);
|
||||
ok &= KryAppStorageSetInt(PASS_SETTINGS_SCOPE, "theme_style",
|
||||
runtime.settings.theme_style);
|
||||
if(!ok) {
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Could not save settings");
|
||||
return 1;
|
||||
}
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Settings saved");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
read_field(char **cursor, char *dst, size_t dst_size)
|
||||
{
|
||||
char *start;
|
||||
char *tab;
|
||||
|
||||
if(cursor == NULL || *cursor == NULL)
|
||||
return 0;
|
||||
start = *cursor;
|
||||
tab = strchr(start, '\t');
|
||||
if(tab != NULL) {
|
||||
*tab = '\0';
|
||||
*cursor = tab + 1;
|
||||
} else {
|
||||
*cursor = NULL;
|
||||
}
|
||||
copy_text(dst, dst_size, start);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
load_profiles(void)
|
||||
{
|
||||
FILE *f = fopen("profiles.tsv", "r");
|
||||
char line[1024];
|
||||
|
||||
runtime.profile_count = 0;
|
||||
if(f == NULL)
|
||||
return;
|
||||
while(runtime.profile_count < PASS_MAX_PROFILES &&
|
||||
fgets(line, sizeof(line), f) != NULL) {
|
||||
PassProfile *p = &runtime.profiles[runtime.profile_count];
|
||||
char *cursor = line;
|
||||
char scratch[64];
|
||||
|
||||
trim_newline(line);
|
||||
memset(p, 0, sizeof(*p));
|
||||
if(!read_field(&cursor, p->name, sizeof(p->name)) ||
|
||||
!read_field(&cursor, p->site, sizeof(p->site)) ||
|
||||
!read_field(&cursor, p->login, sizeof(p->login)) ||
|
||||
!read_field(&cursor, scratch, sizeof(scratch)))
|
||||
continue;
|
||||
p->length = clamp_length(atoi(scratch));
|
||||
if(!read_field(&cursor, scratch, sizeof(scratch)))
|
||||
continue;
|
||||
p->counter = atoi(scratch);
|
||||
if(!read_field(&cursor, scratch, sizeof(scratch)))
|
||||
continue;
|
||||
p->lower = atoi(scratch) != 0;
|
||||
if(!read_field(&cursor, scratch, sizeof(scratch)))
|
||||
continue;
|
||||
p->upper = atoi(scratch) != 0;
|
||||
if(!read_field(&cursor, scratch, sizeof(scratch)))
|
||||
continue;
|
||||
p->digits = atoi(scratch) != 0;
|
||||
if(!read_field(&cursor, scratch, sizeof(scratch)))
|
||||
continue;
|
||||
p->symbols = atoi(scratch) != 0;
|
||||
if(cursor != NULL)
|
||||
copy_text(p->exclude, sizeof(p->exclude), cursor);
|
||||
runtime.profile_count++;
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static int
|
||||
write_profiles(void)
|
||||
{
|
||||
FILE *f = fopen("profiles.tsv", "w");
|
||||
int i;
|
||||
|
||||
if(f == NULL) {
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Could not save profiles");
|
||||
return 1;
|
||||
}
|
||||
for(i = 0; i < runtime.profile_count; i++) {
|
||||
PassProfile *p = &runtime.profiles[i];
|
||||
|
||||
fprintf(f, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%s\n",
|
||||
p->name, p->site, p->login, p->length, p->counter,
|
||||
p->lower ? 1 : 0, p->upper ? 1 : 0,
|
||||
p->digits ? 1 : 0, p->symbols ? 1 : 0, p->exclude);
|
||||
}
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
find_profile(const char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < runtime.profile_count; i++) {
|
||||
if(strcmp(runtime.profiles[i].name, name) == 0)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
pass_runtime_init(void)
|
||||
{
|
||||
runtime_defaults();
|
||||
load_settings();
|
||||
migrate_default_theme_settings();
|
||||
load_profiles();
|
||||
}
|
||||
|
||||
void
|
||||
pass_runtime_tick(void)
|
||||
{
|
||||
char result[1024];
|
||||
int status = AndroidSecureStoreTakeResult(PASS_SECURE_MASTER_KEY,
|
||||
result, sizeof(result));
|
||||
|
||||
if(status == 2) {
|
||||
if(runtime.secure_action == PASS_SECURE_ACTION_UNLOCK) {
|
||||
copy_text(runtime.unlocked_master, sizeof(runtime.unlocked_master), result);
|
||||
runtime.has_unlocked_master = result[0] != '\0';
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Master unlocked");
|
||||
} else {
|
||||
copy_text(runtime.status, sizeof(runtime.status),
|
||||
result[0] ? result : "Master password saved");
|
||||
}
|
||||
runtime.secure_action = PASS_SECURE_ACTION_NONE;
|
||||
} else if(status == 3) {
|
||||
copy_text(runtime.status, sizeof(runtime.status), result[0] ? result : "Secure master failed");
|
||||
runtime.secure_action = PASS_SECURE_ACTION_NONE;
|
||||
}
|
||||
|
||||
if(runtime.clipboard_clear_at > 0.0 && GetTime() >= runtime.clipboard_clear_at) {
|
||||
SetClipboardText("");
|
||||
runtime.clipboard_clear_at = 0.0;
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Clipboard cleared");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pass_runtime_shutdown(void)
|
||||
{
|
||||
memset(runtime.generated, 0, sizeof(runtime.generated));
|
||||
memset(runtime.unlocked_master, 0, sizeof(runtime.unlocked_master));
|
||||
runtime.has_unlocked_master = 0;
|
||||
}
|
||||
|
||||
const int *
|
||||
pass_runtime_master_emoji_codepoints(int *count)
|
||||
{
|
||||
return pass_core_master_emoji_codepoints(count);
|
||||
}
|
||||
|
||||
int
|
||||
pass_generate(const char *site, const char *login, const char *master,
|
||||
int length, int counter,
|
||||
int lower, int upper, int digits, int symbols,
|
||||
const char *exclude)
|
||||
{
|
||||
PassOptions options;
|
||||
char err[PASS_STATUS_SIZE];
|
||||
|
||||
memset(&options, 0, sizeof(options));
|
||||
options.length = length;
|
||||
options.counter = (unsigned long long)(counter < 0 ? 0 : counter);
|
||||
options.lowercase = lower != 0;
|
||||
options.uppercase = upper != 0;
|
||||
options.digits = digits != 0;
|
||||
options.symbols = symbols != 0;
|
||||
options.exclude = exclude != NULL ? exclude : "";
|
||||
memset(err, 0, sizeof(err));
|
||||
|
||||
if(pass_core_generate(site, login, master, &options,
|
||||
runtime.generated, sizeof(runtime.generated),
|
||||
err, sizeof(err)) != 0) {
|
||||
memset(runtime.generated, 0, sizeof(runtime.generated));
|
||||
copy_text(runtime.status, sizeof(runtime.status), err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(runtime.settings.auto_copy)
|
||||
pass_copy();
|
||||
else
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Password generated locally");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *
|
||||
pass_generated(void)
|
||||
{
|
||||
return runtime.generated;
|
||||
}
|
||||
|
||||
char *
|
||||
pass_master_emoji(const char *master)
|
||||
{
|
||||
if(master == NULL || master[0] == '\0') {
|
||||
runtime.master_emoji[0] = '\0';
|
||||
return runtime.master_emoji;
|
||||
}
|
||||
pass_core_master_emoji(master, runtime.master_emoji,
|
||||
sizeof(runtime.master_emoji));
|
||||
return runtime.master_emoji;
|
||||
}
|
||||
|
||||
char *
|
||||
pass_status(void)
|
||||
{
|
||||
return runtime.status;
|
||||
}
|
||||
|
||||
int
|
||||
pass_copy(void)
|
||||
{
|
||||
if(runtime.generated[0] == '\0') {
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Generate a password first");
|
||||
return 1;
|
||||
}
|
||||
SetClipboardText(runtime.generated);
|
||||
if(runtime.settings.clear_seconds > 0) {
|
||||
runtime.clipboard_clear_at = GetTime() + runtime.settings.clear_seconds;
|
||||
snprintf(runtime.status, sizeof(runtime.status),
|
||||
"Copied for %d seconds", runtime.settings.clear_seconds);
|
||||
} else {
|
||||
runtime.clipboard_clear_at = 0.0;
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Copied");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pass_save_profile(const char *name, const char *site, const char *login,
|
||||
int length, int counter,
|
||||
int lower, int upper, int digits, int symbols,
|
||||
const char *exclude)
|
||||
{
|
||||
int index;
|
||||
PassProfile *p;
|
||||
|
||||
if(name == NULL || name[0] == '\0') {
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Profile name required");
|
||||
return 1;
|
||||
}
|
||||
index = find_profile(name);
|
||||
if(index < 0) {
|
||||
if(runtime.profile_count >= PASS_MAX_PROFILES) {
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Profile limit reached");
|
||||
return 1;
|
||||
}
|
||||
index = runtime.profile_count++;
|
||||
}
|
||||
p = &runtime.profiles[index];
|
||||
copy_text(p->name, sizeof(p->name), name);
|
||||
copy_text(p->site, sizeof(p->site), site);
|
||||
copy_text(p->login, sizeof(p->login), login);
|
||||
p->length = length;
|
||||
p->counter = counter;
|
||||
p->lower = lower != 0;
|
||||
p->upper = upper != 0;
|
||||
p->digits = digits != 0;
|
||||
p->symbols = symbols != 0;
|
||||
copy_text(p->exclude, sizeof(p->exclude), exclude);
|
||||
|
||||
if(write_profiles() != 0)
|
||||
return 1;
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Profile saved");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pass_profile_count(void)
|
||||
{
|
||||
return runtime.profile_count;
|
||||
}
|
||||
|
||||
char *
|
||||
pass_profile_label(int index)
|
||||
{
|
||||
PassProfile *p;
|
||||
|
||||
if(index < 0 || index >= runtime.profile_count) {
|
||||
runtime.profile_label[0] = '\0';
|
||||
return runtime.profile_label;
|
||||
}
|
||||
p = &runtime.profiles[index];
|
||||
snprintf(runtime.profile_label, sizeof(runtime.profile_label),
|
||||
"%s %s / %s", p->name, p->site, p->login);
|
||||
return runtime.profile_label;
|
||||
}
|
||||
|
||||
int
|
||||
pass_generate_profile(int index, const char *master)
|
||||
{
|
||||
PassProfile *p;
|
||||
|
||||
if(index < 0 || index >= runtime.profile_count) {
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Profile not found");
|
||||
return 1;
|
||||
}
|
||||
p = &runtime.profiles[index];
|
||||
return pass_generate(p->site, p->login, master, p->length, p->counter,
|
||||
p->lower, p->upper, p->digits, p->symbols, p->exclude);
|
||||
}
|
||||
|
||||
int
|
||||
pass_delete_profile(int index)
|
||||
{
|
||||
int i;
|
||||
|
||||
if(index < 0 || index >= runtime.profile_count) {
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Profile not found");
|
||||
return 1;
|
||||
}
|
||||
for(i = index; i + 1 < runtime.profile_count; i++)
|
||||
runtime.profiles[i] = runtime.profiles[i + 1];
|
||||
runtime.profile_count--;
|
||||
if(write_profiles() != 0)
|
||||
return 1;
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Profile deleted");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pass_save_settings(int auto_copy, int clear_seconds, int show_fingerprint,
|
||||
int length, int counter,
|
||||
int lower, int upper, int digits, int symbols,
|
||||
const char *exclude,
|
||||
int theme_source, int theme_mode,
|
||||
int theme_id, int theme_style)
|
||||
{
|
||||
runtime.settings.auto_copy = auto_copy != 0;
|
||||
runtime.settings.clear_seconds = clear_seconds < 0 ? 0 : clear_seconds;
|
||||
runtime.settings.show_fingerprint = show_fingerprint != 0;
|
||||
runtime.settings.length = clamp_length(length);
|
||||
runtime.settings.counter = counter < 1 ? 1 : counter;
|
||||
runtime.settings.lower = lower != 0;
|
||||
runtime.settings.upper = upper != 0;
|
||||
runtime.settings.digits = digits != 0;
|
||||
runtime.settings.symbols = symbols != 0;
|
||||
copy_text(runtime.settings.exclude, sizeof(runtime.settings.exclude), exclude);
|
||||
runtime.settings.theme_source = theme_source;
|
||||
runtime.settings.theme_mode = theme_mode;
|
||||
runtime.settings.theme_id = theme_id;
|
||||
runtime.settings.theme_style = theme_style;
|
||||
return write_settings();
|
||||
}
|
||||
|
||||
int
|
||||
pass_load_settings(int *auto_copy, int *clear_seconds, int *show_fingerprint,
|
||||
int *length, int *counter,
|
||||
int *lower, int *upper, int *digits, int *symbols,
|
||||
char *exclude, int exclude_size,
|
||||
int *theme_source, int *theme_mode,
|
||||
int *theme_id, int *theme_style)
|
||||
{
|
||||
if(auto_copy != NULL)
|
||||
*auto_copy = runtime.settings.auto_copy;
|
||||
if(clear_seconds != NULL)
|
||||
*clear_seconds = runtime.settings.clear_seconds;
|
||||
if(show_fingerprint != NULL)
|
||||
*show_fingerprint = runtime.settings.show_fingerprint;
|
||||
if(length != NULL)
|
||||
*length = runtime.settings.length;
|
||||
if(counter != NULL)
|
||||
*counter = runtime.settings.counter;
|
||||
if(lower != NULL)
|
||||
*lower = runtime.settings.lower;
|
||||
if(upper != NULL)
|
||||
*upper = runtime.settings.upper;
|
||||
if(digits != NULL)
|
||||
*digits = runtime.settings.digits;
|
||||
if(symbols != NULL)
|
||||
*symbols = runtime.settings.symbols;
|
||||
if(exclude != NULL && exclude_size > 0)
|
||||
copy_text(exclude, (size_t)exclude_size, runtime.settings.exclude);
|
||||
if(theme_source != NULL)
|
||||
*theme_source = runtime.settings.theme_source;
|
||||
if(theme_mode != NULL)
|
||||
*theme_mode = runtime.settings.theme_mode;
|
||||
if(theme_id != NULL)
|
||||
*theme_id = runtime.settings.theme_id;
|
||||
if(theme_style != NULL)
|
||||
*theme_style = runtime.settings.theme_style;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pass_save_master(const char *master, int require_biometric)
|
||||
{
|
||||
if(master == NULL || master[0] == '\0') {
|
||||
runtime.secure_action = PASS_SECURE_ACTION_NONE;
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Enter master password first");
|
||||
return 1;
|
||||
}
|
||||
if(require_biometric && !AndroidSecureStoreBiometricAvailable()) {
|
||||
runtime.secure_action = PASS_SECURE_ACTION_NONE;
|
||||
copy_text(runtime.status, sizeof(runtime.status),
|
||||
AndroidSecureStoreBiometricSetupRequired()
|
||||
? "Set up Android fingerprint first"
|
||||
: "Fingerprint unlock unavailable");
|
||||
return 1;
|
||||
}
|
||||
runtime.secure_action = PASS_SECURE_ACTION_SAVE;
|
||||
AndroidSecureStoreSaveSecret(PASS_SECURE_MASTER_KEY, master,
|
||||
require_biometric, "master password");
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Saving master");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pass_unlock_master(void)
|
||||
{
|
||||
if(!AndroidSecureStoreHasSecret(PASS_SECURE_MASTER_KEY)) {
|
||||
runtime.secure_action = PASS_SECURE_ACTION_NONE;
|
||||
copy_text(runtime.status, sizeof(runtime.status), "No saved master password");
|
||||
return 1;
|
||||
}
|
||||
runtime.secure_action = PASS_SECURE_ACTION_UNLOCK;
|
||||
AndroidSecureStoreUnlockSecret(PASS_SECURE_MASTER_KEY, "master password");
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Unlock requested");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pass_clear_master(void)
|
||||
{
|
||||
AndroidSecureStoreClearSecret(PASS_SECURE_MASTER_KEY);
|
||||
memset(runtime.unlocked_master, 0, sizeof(runtime.unlocked_master));
|
||||
runtime.has_unlocked_master = 0;
|
||||
runtime.secure_action = PASS_SECURE_ACTION_NONE;
|
||||
copy_text(runtime.status, sizeof(runtime.status), "Saved master forgotten");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *
|
||||
pass_fingerprint_status(void)
|
||||
{
|
||||
if(!AndroidSecureStoreBiometricAvailable()) {
|
||||
copy_text(runtime.fingerprint_status, sizeof(runtime.fingerprint_status),
|
||||
AndroidSecureStoreBiometricSetupRequired()
|
||||
? "Android fingerprint setup required"
|
||||
: "Fingerprint unlock is not available");
|
||||
} else if(AndroidSecureStoreHasSecret(PASS_SECURE_MASTER_KEY)) {
|
||||
copy_text(runtime.fingerprint_status, sizeof(runtime.fingerprint_status),
|
||||
AndroidSecureStoreSecretUsesBiometric(PASS_SECURE_MASTER_KEY)
|
||||
? "Saved master uses fingerprint unlock"
|
||||
: "Saved master unlocks without fingerprint");
|
||||
} else {
|
||||
copy_text(runtime.fingerprint_status, sizeof(runtime.fingerprint_status),
|
||||
"No saved master password");
|
||||
}
|
||||
return runtime.fingerprint_status;
|
||||
}
|
||||
|
||||
int
|
||||
pass_take_unlocked_master(char *out)
|
||||
{
|
||||
if(out == NULL || !runtime.has_unlocked_master)
|
||||
return 0;
|
||||
copy_text(out, 1024, runtime.unlocked_master);
|
||||
memset(runtime.unlocked_master, 0, sizeof(runtime.unlocked_master));
|
||||
runtime.has_unlocked_master = 0;
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#ifndef PASS_RUNTIME_H
|
||||
#define PASS_RUNTIME_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void pass_runtime_init(void);
|
||||
void pass_runtime_tick(void);
|
||||
void pass_runtime_shutdown(void);
|
||||
|
||||
const int *pass_runtime_master_emoji_codepoints(int *count);
|
||||
char *pass_master_emoji(const char *master);
|
||||
|
||||
int pass_generate(const char *site, const char *login, const char *master,
|
||||
int length, int counter,
|
||||
int lower, int upper, int digits, int symbols,
|
||||
const char *exclude);
|
||||
char *pass_generated(void);
|
||||
char *pass_status(void);
|
||||
int pass_copy(void);
|
||||
|
||||
int pass_save_profile(const char *name, const char *site, const char *login,
|
||||
int length, int counter,
|
||||
int lower, int upper, int digits, int symbols,
|
||||
const char *exclude);
|
||||
int pass_profile_count(void);
|
||||
char *pass_profile_label(int index);
|
||||
int pass_generate_profile(int index, const char *master);
|
||||
int pass_delete_profile(int index);
|
||||
|
||||
int pass_save_settings(int auto_copy, int clear_seconds, int show_fingerprint,
|
||||
int length, int counter,
|
||||
int lower, int upper, int digits, int symbols,
|
||||
const char *exclude,
|
||||
int theme_source, int theme_mode,
|
||||
int theme_id, int theme_style);
|
||||
int pass_load_settings(int *auto_copy, int *clear_seconds, int *show_fingerprint,
|
||||
int *length, int *counter,
|
||||
int *lower, int *upper, int *digits, int *symbols,
|
||||
char *exclude, int exclude_size,
|
||||
int *theme_source, int *theme_mode,
|
||||
int *theme_id, int *theme_style);
|
||||
int pass_save_master(const char *master, int require_biometric);
|
||||
int pass_unlock_master(void);
|
||||
int pass_clear_master(void);
|
||||
char *pass_fingerprint_status(void);
|
||||
int pass_take_unlocked_master(char *out);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,400 @@
|
||||
#include "pass_runtime.h"
|
||||
|
||||
#include "android_host.h"
|
||||
#include "pass_core.h"
|
||||
#include "kryon.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int failures = 0;
|
||||
static double fake_time = 0.0;
|
||||
static char fake_clipboard[256];
|
||||
static int fake_biometric_available = 0;
|
||||
static int fake_biometric_setup_required = 0;
|
||||
static int fake_master_saved = 0;
|
||||
static int fake_master_biometric = 0;
|
||||
static int fake_secure_status = 0;
|
||||
static char fake_secure_result[1024];
|
||||
static char fake_saved_master[1024];
|
||||
static int fake_saved_require_biometric = 0;
|
||||
|
||||
void AndroidHostInit(void) {}
|
||||
void AndroidHostApplySystemTheme(void) {}
|
||||
int AndroidHostLeftReserved(void) { return 0; }
|
||||
int AndroidHostTopReserved(void) { return 0; }
|
||||
int AndroidHostRightReserved(void) { return 0; }
|
||||
int AndroidHostBottomReserved(void) { return 0; }
|
||||
void AndroidHostSetSoftKeyboardVisible(int visible) { (void)visible; }
|
||||
int AndroidSecureStoreBiometricAvailable(void) { return fake_biometric_available; }
|
||||
int AndroidSecureStoreBiometricSetupRequired(void) { return fake_biometric_setup_required; }
|
||||
int AndroidSecureStoreHasSecret(const char *key) { (void)key; return fake_master_saved; }
|
||||
int AndroidSecureStoreSecretUsesBiometric(const char *key) { (void)key; return fake_master_biometric; }
|
||||
int AndroidSecureStoreStatus(const char *key) { (void)key; return fake_secure_status; }
|
||||
|
||||
void
|
||||
AndroidSecureStoreSaveSecret(const char *key, const char *master,
|
||||
int require_biometric, const char *label)
|
||||
{
|
||||
(void)key;
|
||||
(void)label;
|
||||
snprintf(fake_saved_master, sizeof(fake_saved_master), "%s", master != NULL ? master : "");
|
||||
fake_saved_require_biometric = require_biometric != 0;
|
||||
fake_master_saved = 1;
|
||||
fake_master_biometric = require_biometric != 0;
|
||||
}
|
||||
|
||||
void
|
||||
AndroidSecureStoreUnlockSecret(const char *key, const char *label)
|
||||
{
|
||||
(void)key;
|
||||
(void)label;
|
||||
}
|
||||
|
||||
void
|
||||
AndroidSecureStoreClearSecret(const char *key)
|
||||
{
|
||||
(void)key;
|
||||
fake_master_saved = 0;
|
||||
fake_master_biometric = 0;
|
||||
fake_saved_master[0] = '\0';
|
||||
}
|
||||
|
||||
int
|
||||
AndroidSecureStoreTakeResult(const char *key, char *out, int out_size)
|
||||
{
|
||||
int status = fake_secure_status;
|
||||
|
||||
(void)key;
|
||||
if(out != NULL && out_size > 0)
|
||||
snprintf(out, (size_t)out_size, "%s", fake_secure_result);
|
||||
fake_secure_status = 0;
|
||||
fake_secure_result[0] = '\0';
|
||||
return status;
|
||||
}
|
||||
|
||||
double GetTime(void) { return fake_time; }
|
||||
|
||||
void
|
||||
SetClipboardText(const char *text)
|
||||
{
|
||||
snprintf(fake_clipboard, sizeof(fake_clipboard), "%s", text != NULL ? text : "");
|
||||
}
|
||||
|
||||
static void
|
||||
check_int(const char *name, int got, int want)
|
||||
{
|
||||
if(got != want) {
|
||||
printf("FAIL runtime %s: got %d, want %d\n", name, got, want);
|
||||
failures++;
|
||||
} else {
|
||||
printf("ok runtime %s: %d\n", name, got);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
check_str(const char *name, const char *got, const char *want)
|
||||
{
|
||||
if(strcmp(got != NULL ? got : "", want) != 0) {
|
||||
printf("FAIL runtime %s: got \"%s\", want \"%s\"\n",
|
||||
name, got != NULL ? got : "", want);
|
||||
failures++;
|
||||
} else {
|
||||
printf("ok runtime %s: \"%s\"\n", name, got != NULL ? got : "");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
write_initial_files(void)
|
||||
{
|
||||
FILE *f = fopen("settings.cfg", "w");
|
||||
|
||||
if(f == NULL) {
|
||||
perror("settings.cfg");
|
||||
exit(1);
|
||||
}
|
||||
fputs("ignored line\n", f);
|
||||
fputs("auto_copy=1\n", f);
|
||||
fputs("clear_after_seconds=3\n", f);
|
||||
fputs("show_fingerprint=0\n", f);
|
||||
fputs("length=99\n", f);
|
||||
fputs("counter=7\n", f);
|
||||
fputs("lower=1\n", f);
|
||||
fputs("upper=0\n", f);
|
||||
fputs("digits=1\n", f);
|
||||
fputs("symbols=0\n", f);
|
||||
fputs("exclude=01\n", f);
|
||||
fputs("theme_source=1\n", f);
|
||||
fputs("theme_mode=0\n", f);
|
||||
fputs("theme_id=10\n", f);
|
||||
fputs("theme_style=0\n", f);
|
||||
fclose(f);
|
||||
|
||||
f = fopen("profiles.tsv", "w");
|
||||
if(f == NULL) {
|
||||
perror("profiles.tsv");
|
||||
exit(1);
|
||||
}
|
||||
fputs("broken\n", f);
|
||||
fputs("Loaded\tloaded.example\talice\t99\t2\t1\t0\t1\t0\t0\n", f);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void
|
||||
remove_storage_files(void)
|
||||
{
|
||||
remove(".kryon_pass_auto_copy.txt");
|
||||
remove(".kryon_pass_clear_after_seconds.txt");
|
||||
remove(".kryon_pass_show_fingerprint.txt");
|
||||
remove(".kryon_pass_length.txt");
|
||||
remove(".kryon_pass_counter.txt");
|
||||
remove(".kryon_pass_lower.txt");
|
||||
remove(".kryon_pass_upper.txt");
|
||||
remove(".kryon_pass_digits.txt");
|
||||
remove(".kryon_pass_symbols.txt");
|
||||
remove(".kryon_pass_exclude.txt");
|
||||
remove(".kryon_pass_theme_source.txt");
|
||||
remove(".kryon_pass_theme_mode.txt");
|
||||
remove(".kryon_pass_theme_id.txt");
|
||||
remove(".kryon_pass_theme_style.txt");
|
||||
}
|
||||
|
||||
static void
|
||||
check_loaded_settings(void)
|
||||
{
|
||||
int auto_copy = -1;
|
||||
int clear_seconds = -1;
|
||||
int show_fingerprint = -1;
|
||||
int length = -1;
|
||||
int counter = -1;
|
||||
int lower = -1;
|
||||
int upper = -1;
|
||||
int digits = -1;
|
||||
int symbols = -1;
|
||||
int theme_source = -1;
|
||||
int theme_mode = -1;
|
||||
int theme_id = -1;
|
||||
int theme_style = -1;
|
||||
char exclude[16];
|
||||
|
||||
memset(exclude, 0, sizeof(exclude));
|
||||
pass_load_settings(&auto_copy, &clear_seconds, &show_fingerprint,
|
||||
&length, &counter, &lower, &upper, &digits,
|
||||
&symbols, exclude, sizeof(exclude),
|
||||
&theme_source, &theme_mode, &theme_id, &theme_style);
|
||||
check_int("loaded auto_copy", auto_copy, 1);
|
||||
check_int("loaded clear_seconds", clear_seconds, 3);
|
||||
check_int("loaded show_fingerprint", show_fingerprint, 0);
|
||||
check_int("loaded length clamp", length, PASS_MAX_LENGTH);
|
||||
check_int("loaded counter", counter, 7);
|
||||
check_int("loaded lower", lower, 1);
|
||||
check_int("loaded upper", upper, 0);
|
||||
check_int("loaded digits", digits, 1);
|
||||
check_int("loaded symbols", symbols, 0);
|
||||
check_str("loaded exclude", exclude, "01");
|
||||
check_int("migrated theme_source", theme_source, THEME_SOURCE_APP);
|
||||
check_int("migrated theme_mode", theme_mode, THEME_MODE_SYSTEM);
|
||||
check_int("migrated theme_id", theme_id, THEME_SWEET);
|
||||
check_int("migrated theme_style", theme_style, THEME_STYLE_MATERIAL);
|
||||
|
||||
pass_load_settings(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, 0, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
check_generation_and_clipboard(void)
|
||||
{
|
||||
check_str("initial status", pass_status(), "Ready");
|
||||
check_str("empty emoji", pass_master_emoji(""), "");
|
||||
check_int("nonempty emoji", (int)strlen(pass_master_emoji("master")) > 0, 1);
|
||||
|
||||
check_int("generate", pass_generate("lesspass.com", "[email protected]",
|
||||
"password", 16, 1, 1, 1, 1, 1, ""), 0);
|
||||
check_str("generated", pass_generated(), "\\g-A1-.OHEwrXjT#");
|
||||
check_str("auto clipboard", fake_clipboard, "\\g-A1-.OHEwrXjT#");
|
||||
check_str("copy status", pass_status(), "Copied for 3 seconds");
|
||||
|
||||
fake_time = 4.0;
|
||||
pass_runtime_tick();
|
||||
check_str("clipboard cleared", fake_clipboard, "");
|
||||
check_str("clipboard clear status", pass_status(), "Clipboard cleared");
|
||||
|
||||
check_int("save settings", pass_save_settings(0, -2, 1, 1, 0, 1, 1, 1, 1,
|
||||
NULL, 9, 8, 7, 6), 0);
|
||||
check_int("generate invalid", pass_generate("site", "login", "master",
|
||||
8, 1, 0, 0, 0, 0, ""), 1);
|
||||
check_str("invalid clears generated", pass_generated(), "");
|
||||
check_int("copy empty", pass_copy(), 1);
|
||||
|
||||
check_int("generate no autocopy", pass_generate("site", "login", "master",
|
||||
16, -4, 1, 1, 1, 1, ""), 0);
|
||||
check_str("manual generate status", pass_status(), "Password generated locally");
|
||||
check_int("copy no timeout", pass_copy(), 0);
|
||||
check_str("copy no timeout status", pass_status(), "Copied");
|
||||
}
|
||||
|
||||
static void
|
||||
check_profiles(void)
|
||||
{
|
||||
check_int("loaded profile count", pass_profile_count(), 1);
|
||||
check_str("loaded profile label", pass_profile_label(0),
|
||||
"Loaded loaded.example / alice");
|
||||
check_str("missing profile label", pass_profile_label(-1), "");
|
||||
check_int("generate loaded profile", pass_generate_profile(0, "secret"), 0);
|
||||
check_int("missing profile generate", pass_generate_profile(100, "secret"), 1);
|
||||
check_int("empty profile name", pass_save_profile("", "site", "login", 16, 1,
|
||||
1, 1, 1, 1, ""), 1);
|
||||
check_int("save profile", pass_save_profile("Work", "work.example", "me", 16, 1,
|
||||
1, 1, 1, 1, ""), 0);
|
||||
check_int("overwrite profile", pass_save_profile("Work", "work.example", "you", 18, 2,
|
||||
1, 0, 1, 0, "01"), 0);
|
||||
check_str("saved profile label", pass_profile_label(1),
|
||||
"Work work.example / you");
|
||||
check_int("delete missing profile", pass_delete_profile(99), 1);
|
||||
check_int("save second profile", pass_save_profile("Home", "home.example", "me", 16, 1,
|
||||
1, 1, 1, 1, ""), 0);
|
||||
check_int("delete first profile", pass_delete_profile(0), 0);
|
||||
check_str("shifted profile label", pass_profile_label(0),
|
||||
"Work work.example / you");
|
||||
check_int("delete profile", pass_delete_profile(0), 0);
|
||||
|
||||
for(int i = pass_profile_count(); i < 64; i++) {
|
||||
char name[32];
|
||||
|
||||
snprintf(name, sizeof(name), "Fill%d", i);
|
||||
if(pass_save_profile(name, "fill.example", "me", 16, 1,
|
||||
1, 1, 1, 1, "") != 0) {
|
||||
printf("FAIL runtime fill profile %d: %s\n", i, pass_status());
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
check_int("profile limit", pass_save_profile("Overflow", "fill.example", "me", 16, 1,
|
||||
1, 1, 1, 1, ""), 1);
|
||||
}
|
||||
|
||||
static void
|
||||
check_secure_master(void)
|
||||
{
|
||||
char unlocked[1024];
|
||||
int count = 0;
|
||||
|
||||
check_int("emoji count", pass_runtime_master_emoji_codepoints(&count) != NULL, 1);
|
||||
check_int("emoji count value", count, 64);
|
||||
check_int("save empty master", pass_save_master("", 1), 1);
|
||||
check_str("save empty status", pass_status(), "Enter master password first");
|
||||
|
||||
fake_biometric_available = 0;
|
||||
fake_biometric_setup_required = 0;
|
||||
check_int("save unavailable master", pass_save_master("secret", 1), 1);
|
||||
check_str("save unavailable status", pass_status(), "Fingerprint unlock unavailable");
|
||||
|
||||
fake_biometric_setup_required = 1;
|
||||
check_int("save setup master", pass_save_master("secret", 1), 1);
|
||||
check_str("save setup status", pass_status(), "Set up Android fingerprint first");
|
||||
|
||||
fake_biometric_available = 1;
|
||||
fake_biometric_setup_required = 0;
|
||||
check_int("save master", pass_save_master("secret", 1), 0);
|
||||
check_str("saving status", pass_status(), "Saving master");
|
||||
check_str("saved master stub", fake_saved_master, "secret");
|
||||
check_int("saved master biometric flag", fake_saved_require_biometric, 1);
|
||||
snprintf(fake_secure_result, sizeof(fake_secure_result), "%s", "");
|
||||
fake_secure_status = 2;
|
||||
pass_runtime_tick();
|
||||
check_str("saved status result", pass_status(), "Master password saved");
|
||||
|
||||
check_int("can unlock", AndroidSecureStoreHasSecret("default") &&
|
||||
AndroidSecureStoreSecretUsesBiometric("default") &&
|
||||
AndroidSecureStoreBiometricAvailable(), 1);
|
||||
check_int("master saved", AndroidSecureStoreHasSecret("default"), 1);
|
||||
check_int("biometric available", AndroidSecureStoreBiometricAvailable(), 1);
|
||||
check_str("fingerprint saved", pass_fingerprint_status(),
|
||||
"Saved master uses fingerprint unlock");
|
||||
fake_master_biometric = 0;
|
||||
check_str("fingerprint saved no biometric", pass_fingerprint_status(),
|
||||
"Saved master unlocks without fingerprint");
|
||||
fake_master_biometric = 1;
|
||||
|
||||
check_int("unlock master", pass_unlock_master(), 0);
|
||||
check_str("unlock requested", pass_status(), "Unlock requested");
|
||||
snprintf(fake_secure_result, sizeof(fake_secure_result), "%s", "secret");
|
||||
fake_secure_status = 2;
|
||||
pass_runtime_tick();
|
||||
check_str("unlocked status", pass_status(), "Master unlocked");
|
||||
memset(unlocked, 0, sizeof(unlocked));
|
||||
check_int("take unlocked", pass_take_unlocked_master(unlocked), 1);
|
||||
check_str("unlocked value", unlocked, "secret");
|
||||
check_int("take unlocked empty", pass_take_unlocked_master(unlocked), 0);
|
||||
check_int("take unlocked null", pass_take_unlocked_master(NULL), 0);
|
||||
|
||||
check_int("clear master", pass_clear_master(), 0);
|
||||
check_int("unlock missing master", pass_unlock_master(), 1);
|
||||
fake_biometric_available = 0;
|
||||
fake_biometric_setup_required = 1;
|
||||
check_str("fingerprint setup required", pass_fingerprint_status(),
|
||||
"Android fingerprint setup required");
|
||||
fake_biometric_setup_required = 0;
|
||||
check_str("fingerprint unavailable", pass_fingerprint_status(),
|
||||
"Fingerprint unlock is not available");
|
||||
fake_biometric_available = 1;
|
||||
check_str("fingerprint none saved", pass_fingerprint_status(),
|
||||
"No saved master password");
|
||||
|
||||
check_int("save master no biometric", pass_save_master("plain", 0), 0);
|
||||
snprintf(fake_secure_result, sizeof(fake_secure_result), "%s", "denied");
|
||||
fake_secure_status = 3;
|
||||
pass_runtime_tick();
|
||||
check_str("secure failure", pass_status(), "denied");
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char original_cwd[1024];
|
||||
|
||||
if(getcwd(original_cwd, sizeof(original_cwd)) == NULL) {
|
||||
perror("getcwd");
|
||||
return 1;
|
||||
}
|
||||
mkdir("build", 0777);
|
||||
mkdir("build/coverage", 0777);
|
||||
mkdir("build/coverage/runtime-work", 0777);
|
||||
if(chdir("build/coverage/runtime-work") != 0) {
|
||||
perror("chdir");
|
||||
return 1;
|
||||
}
|
||||
unlink("settings.cfg");
|
||||
unlink("profiles.tsv");
|
||||
remove_storage_files();
|
||||
write_initial_files();
|
||||
|
||||
pass_runtime_init();
|
||||
check_loaded_settings();
|
||||
check_generation_and_clipboard();
|
||||
check_profiles();
|
||||
check_secure_master();
|
||||
pass_runtime_shutdown();
|
||||
check_str("shutdown generated", pass_generated(), "");
|
||||
unlink("settings.cfg");
|
||||
unlink("profiles.tsv");
|
||||
remove_storage_files();
|
||||
pass_runtime_init();
|
||||
check_int("default profile count", pass_profile_count(), 0);
|
||||
check_str("default status", pass_status(), "Ready");
|
||||
remove_storage_files();
|
||||
|
||||
if(chdir(original_cwd) != 0) {
|
||||
perror("restore cwd");
|
||||
return 1;
|
||||
}
|
||||
if(failures != 0) {
|
||||
printf("%d runtime failure(s)\n", failures);
|
||||
return 1;
|
||||
}
|
||||
printf("all runtime tests pass\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<component type="desktop-application">
|
||||
<id>xyz.waozi.pass</id>
|
||||
<name>pass</name>
|
||||
<name>Pass</name>
|
||||
<summary>Generate deterministic passwords locally</summary>
|
||||
<metadata_license>CC0-1.0</metadata_license>
|
||||
<project_license>BSD-3-Clause</project_license>
|
||||
<description>
|
||||
<p>pass derives repeatable passwords from a site, login, master password, and generation settings without storing a password database.</p>
|
||||
<p>Pass derives repeatable passwords from a site, login, master password, and generation settings without storing a password database.</p>
|
||||
</description>
|
||||
<launchable type="desktop-id">xyz.waozi.pass.desktop</launchable>
|
||||
<url type="homepage">https://github.com/waozixyz/pass</url>
|
||||
<provides><binary>pass-gui</binary></provides>
|
||||
<releases><release version="0.2.2" date="2026-08-20"/><release version="0.2.1" date="2026-08-19"/><release version="0.2.0" date="2026-08-18"/><release version="0.1.3" date="2026-08-17"/><release version="0.1.2" date="2026-08-17"/><release version="0.1.1" date="2026-08-17"/><release version="0.1.0" date="2026-08-17"/></releases>
|
||||
<releases><release version="0.2.9" date="2026-09-05"/><release version="0.2.8" date="2026-08-26"/><release version="0.2.7" date="2026-08-24"/><release version="0.2.6" date="2026-08-24"/><release version="0.2.5" date="2026-08-24"/><release version="0.2.4" date="2026-08-22"/><release version="0.2.3" date="2026-08-21"/><release version="0.2.2" date="2026-08-20"/><release version="0.2.1" date="2026-08-19"/><release version="0.2.0" date="2026-08-18"/><release version="0.1.3" date="2026-08-17"/><release version="0.1.2" date="2026-08-17"/><release version="0.1.1" date="2026-08-17"/><release version="0.1.0" date="2026-08-17"/></releases>
|
||||
</component>
|
||||
@@ -1,6 +1,6 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=pass
|
||||
Name=Pass
|
||||
Comment=Generate deterministic passwords locally
|
||||
Exec=pass-gui
|
||||
Icon=pass
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
// Package pass derives site-specific passwords without storing them.
|
||||
package pass
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
LowercaseCharacters = "abcdefghijklmnopqrstuvwxyz"
|
||||
UppercaseCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
DigitCharacters = "0123456789"
|
||||
SymbolCharacters = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
|
||||
)
|
||||
|
||||
// Options controls the shape of a generated password.
|
||||
type Options struct {
|
||||
Length int
|
||||
Counter uint64
|
||||
Lowercase bool
|
||||
Uppercase bool
|
||||
Digits bool
|
||||
Symbols bool
|
||||
Exclude string
|
||||
}
|
||||
|
||||
// DefaultOptions returns the standard generator settings.
|
||||
func DefaultOptions() Options {
|
||||
return Options{
|
||||
Length: 16,
|
||||
Counter: 1,
|
||||
Lowercase: true,
|
||||
Uppercase: true,
|
||||
Digits: true,
|
||||
Symbols: true,
|
||||
}
|
||||
}
|
||||
|
||||
// Generate derives a password from site, login, master password, and options.
|
||||
func Generate(site, login, master string, options Options) (string, error) {
|
||||
classes, alphabet, err := availableCharacters(options)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if options.Length < len(classes) {
|
||||
return "", fmt.Errorf("password length %d is smaller than the %d enabled character classes", options.Length, len(classes))
|
||||
}
|
||||
|
||||
salt := []byte(site + login + strconv.FormatUint(options.Counter, 10))
|
||||
entropy := new(big.Int).SetBytes(deriveKey([]byte(master), salt))
|
||||
|
||||
password := make([]byte, 0, options.Length)
|
||||
for range options.Length - len(classes) {
|
||||
password = append(password, alphabet[takeRemainder(entropy, len(alphabet))])
|
||||
}
|
||||
|
||||
required := make([]byte, len(classes))
|
||||
for i, class := range classes {
|
||||
required[i] = class[takeRemainder(entropy, len(class))]
|
||||
}
|
||||
|
||||
for _, character := range required {
|
||||
position := takeRemainder(entropy, len(password)+1)
|
||||
password = append(password, 0)
|
||||
copy(password[position+1:], password[position:])
|
||||
password[position] = character
|
||||
}
|
||||
|
||||
return string(password), nil
|
||||
}
|
||||
|
||||
func availableCharacters(options Options) ([][]byte, []byte, error) {
|
||||
if options.Length < 1 {
|
||||
return nil, nil, errors.New("password length must be positive")
|
||||
}
|
||||
|
||||
excluded := make(map[byte]bool, len(options.Exclude))
|
||||
for _, character := range []byte(options.Exclude) {
|
||||
excluded[character] = true
|
||||
}
|
||||
|
||||
configured := []struct {
|
||||
enabled bool
|
||||
name string
|
||||
value string
|
||||
}{
|
||||
{options.Lowercase, "lowercase", LowercaseCharacters},
|
||||
{options.Uppercase, "uppercase", UppercaseCharacters},
|
||||
{options.Digits, "digits", DigitCharacters},
|
||||
{options.Symbols, "symbols", SymbolCharacters},
|
||||
}
|
||||
|
||||
var classes [][]byte
|
||||
var alphabet []byte
|
||||
for _, candidate := range configured {
|
||||
if !candidate.enabled {
|
||||
continue
|
||||
}
|
||||
filtered := make([]byte, 0, len(candidate.value))
|
||||
for i := range len(candidate.value) {
|
||||
if !excluded[candidate.value[i]] {
|
||||
filtered = append(filtered, candidate.value[i])
|
||||
}
|
||||
}
|
||||
if len(filtered) == 0 {
|
||||
return nil, nil, fmt.Errorf("enabled %s character class is empty after exclusions", candidate.name)
|
||||
}
|
||||
classes = append(classes, filtered)
|
||||
alphabet = append(alphabet, filtered...)
|
||||
}
|
||||
if len(classes) == 0 {
|
||||
return nil, nil, errors.New("at least one character class must be enabled")
|
||||
}
|
||||
return classes, alphabet, nil
|
||||
}
|
||||
|
||||
func takeRemainder(entropy *big.Int, divisor int) int {
|
||||
quotient := new(big.Int)
|
||||
remainder := new(big.Int)
|
||||
quotient.QuoRem(entropy, big.NewInt(int64(divisor)), remainder)
|
||||
entropy.Set(quotient)
|
||||
return int(remainder.Int64())
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
package pass
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDeriveKeyKnownResults(t *testing.T) {
|
||||
tests := []struct {
|
||||
password string
|
||||
salt string
|
||||
want string
|
||||
}{
|
||||
{"password", "salt", "0394a2ede332c9a13eb82e9b24631604c31df978b4e2f0fbd2c549944f9d79a5"},
|
||||
{"", "examplealice1", "caa46554f5a676b76c15b368c655b0b24eaaad8595ef919999785c68e60fd5f5"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
got := hex.EncodeToString(deriveKey([]byte(test.password), []byte(test.salt)))
|
||||
if got != test.want {
|
||||
t.Errorf("deriveKey(%q, %q) = %s, want %s", test.password, test.salt, got, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateKnownResults(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
site, login, key string
|
||||
options Options
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "defaults",
|
||||
site: "example.com", login: "alice", key: "correct horse battery staple",
|
||||
options: DefaultOptions(), want: "&vLf44D'/cSkP-_8",
|
||||
},
|
||||
{
|
||||
name: "counter and length",
|
||||
site: "service.test", login: "[email protected]", key: "master",
|
||||
options: Options{Length: 20, Counter: 2, Lowercase: true, Uppercase: true, Digits: true, Symbols: true},
|
||||
want: "j:x_Lo5X_jL0w%ez`1be",
|
||||
},
|
||||
{
|
||||
name: "utf8 inputs and two classes",
|
||||
site: "δοκιμή.example", login: "ユーザー", key: "pässword",
|
||||
options: Options{Length: 12, Counter: 7, Lowercase: true, Digits: true},
|
||||
want: "ioh5o2mhyghv",
|
||||
},
|
||||
{
|
||||
name: "excluded characters",
|
||||
site: "example.com", login: "alice", key: "correct horse battery staple",
|
||||
options: Options{Length: 24, Counter: 1, Lowercase: true, Uppercase: true, Digits: true, Symbols: true, Exclude: "0Ool1I!|"},
|
||||
want: "7,a.Cp}YnF'ee7HqbX#PQhgH",
|
||||
},
|
||||
{
|
||||
name: "empty master and zero counter",
|
||||
site: "x", login: "y", key: "",
|
||||
options: Options{Length: 4, Counter: 0, Uppercase: true, Digits: true},
|
||||
want: "9O7C",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got, err := Generate(test.site, test.login, test.key, test.options)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != test.want {
|
||||
t.Fatalf("Generate() = %q, want %q", got, test.want)
|
||||
}
|
||||
independent := referenceGenerate(test.site, test.login, test.key, test.options)
|
||||
if got != independent {
|
||||
t.Fatalf("Generate() = %q, separate reference = %q", got, independent)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeneratedPasswordMeetsRequestedShape(t *testing.T) {
|
||||
options := Options{
|
||||
Length: 40,
|
||||
Counter: 3,
|
||||
Lowercase: true,
|
||||
Uppercase: true,
|
||||
Digits: true,
|
||||
Symbols: true,
|
||||
Exclude: "abcXYZ019!@",
|
||||
}
|
||||
got, err := Generate("host", "account", "secret", options)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(got) != options.Length {
|
||||
t.Fatalf("length = %d, want %d", len(got), options.Length)
|
||||
}
|
||||
for _, excluded := range options.Exclude {
|
||||
if strings.ContainsRune(got, excluded) {
|
||||
t.Errorf("result contains excluded character %q", excluded)
|
||||
}
|
||||
}
|
||||
for name, set := range map[string]string{
|
||||
"lowercase": removeCharacters(LowercaseCharacters, options.Exclude),
|
||||
"uppercase": removeCharacters(UppercaseCharacters, options.Exclude),
|
||||
"digits": removeCharacters(DigitCharacters, options.Exclude),
|
||||
"symbols": removeCharacters(SymbolCharacters, options.Exclude),
|
||||
} {
|
||||
if !strings.ContainsAny(got, set) {
|
||||
t.Errorf("result has no %s character", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func removeCharacters(value, excluded string) string {
|
||||
return strings.Map(func(character rune) rune {
|
||||
if strings.ContainsRune(excluded, character) {
|
||||
return -1
|
||||
}
|
||||
return character
|
||||
}, value)
|
||||
}
|
||||
|
||||
func TestRejectsInvalidOptions(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
options Options
|
||||
}{
|
||||
{"nonpositive length", Options{Length: 0, Lowercase: true}},
|
||||
{"no class", Options{Length: 8}},
|
||||
{"too few positions", Options{Length: 2, Lowercase: true, Uppercase: true, Digits: true}},
|
||||
{"emptied class", Options{Length: 8, Digits: true, Exclude: DigitCharacters}},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if _, err := Generate("site", "login", "master", test.options); err == nil {
|
||||
t.Fatal("Generate() succeeded for invalid options")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package pass
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
const derivationRounds = 100_000
|
||||
|
||||
func deriveKey(password, salt []byte) []byte {
|
||||
blockInput := make([]byte, len(salt)+4)
|
||||
copy(blockInput, salt)
|
||||
binary.BigEndian.PutUint32(blockInput[len(salt):], 1)
|
||||
|
||||
mac := hmac.New(sha256.New, password)
|
||||
_, _ = mac.Write(blockInput)
|
||||
previous := mac.Sum(nil)
|
||||
key := append([]byte(nil), previous...)
|
||||
|
||||
for round := 1; round < derivationRounds; round++ {
|
||||
mac.Reset()
|
||||
_, _ = mac.Write(previous)
|
||||
previous = mac.Sum(previous[:0])
|
||||
for i := range key {
|
||||
key[i] ^= previous[i]
|
||||
}
|
||||
}
|
||||
return key
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package pass
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"math/big"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// referenceGenerate is intentionally self-contained so the examples exercise
|
||||
// the public generator against a second implementation of the specification.
|
||||
func referenceGenerate(site, login, master string, options Options) string {
|
||||
definitions := []struct {
|
||||
on bool
|
||||
set string
|
||||
}{
|
||||
{options.Lowercase, "abcdefghijklmnopqrstuvwxyz"},
|
||||
{options.Uppercase, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"},
|
||||
{options.Digits, "0123456789"},
|
||||
{options.Symbols, "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"},
|
||||
}
|
||||
classes := make([]string, 0, 4)
|
||||
pool := ""
|
||||
for _, definition := range definitions {
|
||||
if !definition.on {
|
||||
continue
|
||||
}
|
||||
filtered := ""
|
||||
for _, character := range definition.set {
|
||||
if !strings.ContainsRune(options.Exclude, character) {
|
||||
filtered += string(character)
|
||||
}
|
||||
}
|
||||
classes = append(classes, filtered)
|
||||
pool += filtered
|
||||
}
|
||||
|
||||
salt := []byte(site + login + strconv.FormatUint(options.Counter, 10))
|
||||
message := append(append([]byte(nil), salt...), 0, 0, 0, 1)
|
||||
mac := hmac.New(sha256.New, []byte(master))
|
||||
_, _ = mac.Write(message)
|
||||
last := mac.Sum(nil)
|
||||
derived := append([]byte(nil), last...)
|
||||
for iteration := 2; iteration <= 100_000; iteration++ {
|
||||
mac.Reset()
|
||||
_, _ = mac.Write(last)
|
||||
last = mac.Sum(nil)
|
||||
for i, value := range last {
|
||||
derived[i] ^= value
|
||||
}
|
||||
}
|
||||
|
||||
value := new(big.Int).SetBytes(derived)
|
||||
draw := func(size int) int {
|
||||
base := big.NewInt(int64(size))
|
||||
remainder := new(big.Int)
|
||||
value.DivMod(value, base, remainder)
|
||||
return int(remainder.Int64())
|
||||
}
|
||||
|
||||
result := make([]byte, options.Length-len(classes))
|
||||
for i := range result {
|
||||
result[i] = pool[draw(len(pool))]
|
||||
}
|
||||
required := make([]byte, len(classes))
|
||||
for i, class := range classes {
|
||||
required[i] = class[draw(len(class))]
|
||||
}
|
||||
for _, character := range required {
|
||||
at := draw(len(result) + 1)
|
||||
next := make([]byte, 0, len(result)+1)
|
||||
next = append(next, result[:at]...)
|
||||
next = append(next, character)
|
||||
next = append(next, result[at:]...)
|
||||
result = next
|
||||
}
|
||||
return string(result)
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
root_dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
apk="$root_dir/build/pass-android-debug.apk"
|
||||
package_name="${PASS_ANDROID_PACKAGE:-xyz.waozi.pass}"
|
||||
|
||||
if [ ! -s "$apk" ]; then
|
||||
echo "android smoke: missing APK artifact: $apk" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! command -v adb >/dev/null 2>&1; then
|
||||
echo "android smoke: skipped, adb is not installed" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
device="${PASS_ANDROID_DEVICE:-}"
|
||||
if [ -z "$device" ]; then
|
||||
device=$(adb devices | awk 'NR > 1 && $2 == "device" { print $1; exit }')
|
||||
fi
|
||||
if [ -z "$device" ]; then
|
||||
echo "android smoke: skipped, no connected adb device" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
adb -s "$device" install -r "$apk" >/dev/null
|
||||
adb -s "$device" shell monkey -p "$package_name" 1 >/dev/null
|
||||
sleep 2
|
||||
if ! adb -s "$device" shell pidof "$package_name" >/dev/null; then
|
||||
echo "android smoke: $package_name did not stay running on $device" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "android smoke: launched $package_name on $device"
|
||||
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
root="${1:-.}"
|
||||
cd "$root"
|
||||
|
||||
emit_error() {
|
||||
local file="$1"
|
||||
local message="$2"
|
||||
if [ -n "${GITHUB_ACTIONS:-}" ]; then
|
||||
printf '::error file=%s::%s\n' "$file" "$message" >&2
|
||||
else
|
||||
printf '%s: %s\n' "$file" "$message" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
check_gitmodules_file() {
|
||||
local file="$1"
|
||||
local line key url
|
||||
local status=0
|
||||
local entries=()
|
||||
|
||||
[ -f "$file" ] || return 0
|
||||
|
||||
if ! mapfile -t entries < <(git config --file "$file" --get-regexp '^submodule\..*\.url$'); then
|
||||
emit_error "$file" "has no submodule URL entries"
|
||||
return 1
|
||||
fi
|
||||
|
||||
for line in "${entries[@]}"; do
|
||||
key="${line%% *}"
|
||||
url="${line#* }"
|
||||
case "$url" in
|
||||
https://*) ;;
|
||||
*)
|
||||
emit_error "$file" "$key uses non-HTTPS submodule URL: $url"
|
||||
status=1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
printf 'checked %s\n' "$file"
|
||||
return "$status"
|
||||
}
|
||||
|
||||
queue=(".")
|
||||
|
||||
for ((i = 0; i < ${#queue[@]}; i++)); do
|
||||
repo="${queue[$i]}"
|
||||
modules_file="$repo/.gitmodules"
|
||||
[ -f "$modules_file" ] || continue
|
||||
|
||||
check_gitmodules_file "$modules_file"
|
||||
|
||||
mapfile -t submodule_paths < <(
|
||||
git -C "$repo" config --file .gitmodules --get-regexp '^submodule\..*\.path$' \
|
||||
| sed 's/^[^ ]* //'
|
||||
)
|
||||
|
||||
for path in "${submodule_paths[@]}"; do
|
||||
if [ ! -d "$repo/$path" ]; then
|
||||
emit_error "$modules_file" "submodule path is not checked out: $path"
|
||||
exit 1
|
||||
fi
|
||||
queue+=("$repo/$path")
|
||||
done
|
||||
done
|
||||
|
||||
echo "all discovered submodule URLs use public HTTPS"
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
cli=${1:-./pass}
|
||||
tmp=${TMPDIR:-/tmp}/pass-cli-test.$$
|
||||
|
||||
cleanup()
|
||||
{
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
mkdir -p "$tmp"
|
||||
|
||||
fail()
|
||||
{
|
||||
echo "FAIL cli: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
expect_out()
|
||||
{
|
||||
name=$1
|
||||
want=$2
|
||||
shift 2
|
||||
got=$("$@")
|
||||
test "$got" = "$want" || fail "$name: got '$got', want '$want'"
|
||||
echo "ok cli: $name"
|
||||
}
|
||||
|
||||
expect_fail()
|
||||
{
|
||||
name=$1
|
||||
status=$2
|
||||
needle=$3
|
||||
shift 3
|
||||
set +e
|
||||
"$@" >"$tmp/out" 2>"$tmp/err"
|
||||
got_status=$?
|
||||
set -e
|
||||
test "$got_status" -eq "$status" || fail "$name: status $got_status, want $status"
|
||||
grep -F -- "$needle" "$tmp/err" >/dev/null || fail "$name: missing '$needle'"
|
||||
echo "ok cli: $name"
|
||||
}
|
||||
|
||||
"$cli" --version >"$tmp/version"
|
||||
grep -F -- "pass " "$tmp/version" >/dev/null || fail "version text missing prefix"
|
||||
echo "ok cli: version"
|
||||
expect_out "argument master" "\\g-A1-.OHEwrXjT#" "$cli" lesspass.com [email protected] password
|
||||
expect_out "explicit classes" "\\g-A1-.OHEwrXjT#" "$cli" -l -u -d -s lesspass.com [email protected] password
|
||||
expect_out "environment master" "\\g-A1-.OHEwrXjT#" env LESSPASS_MASTER_PASSWORD=password "$cli" lesspass.com [email protected]
|
||||
expect_out "stdin master" "\\g-A1-.OHEwrXjT#" sh -c "printf 'password\r\n' | \"\$1\" --prompt lesspass.com [email protected]" sh "$cli"
|
||||
expect_out "copy disabled" "\\g-A1-.OHEwrXjT#" "$cli" --copy --no-copy lesspass.com [email protected] password
|
||||
|
||||
counter_zero=$("$cli" --counter 0 site login master)
|
||||
counter_negative=$("$cli" --counter -3 site login master)
|
||||
test "$counter_negative" = "$counter_zero" || fail "negative counter did not clamp to zero"
|
||||
echo "ok cli: negative counter clamp"
|
||||
|
||||
"$cli" --help >"$tmp/help"
|
||||
grep -F -- "Usage: pass" "$tmp/help" >/dev/null || fail "help text missing usage"
|
||||
echo "ok cli: help"
|
||||
|
||||
expect_fail "unknown option" 2 "unknown option" "$cli" --bogus
|
||||
expect_fail "missing option value" 2 "requires a value" "$cli" --length
|
||||
expect_fail "missing exclude value" 2 "requires a value" "$cli" --exclude
|
||||
expect_fail "invalid option value" 2 "Usage: pass" "$cli" --length nope site login master
|
||||
expect_fail "missing positional args" 2 "Usage: pass" "$cli" site
|
||||
expect_fail "too many positional args" 2 "too many positional arguments" "$cli" a b c d
|
||||
expect_fail "copy unavailable" 2 "--copy is not available" "$cli" --copy site login master
|
||||
expect_fail "missing stdin master" 2 "missing master password" sh -c "\"\$1\" site login </dev/null" sh "$cli"
|
||||
expect_fail "core validation" 1 "at least one character class" "$cli" --no-lowercase --no-uppercase --no-digits --no-symbols site login master
|
||||
|
||||
echo "all cli tests pass"
|
||||
@@ -0,0 +1,56 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
kryon_dir=${KRYON_DIR:-"$root/vendor/kryon"}
|
||||
arch=$(uname -m)
|
||||
if [ "$arch" = "amd64" ]; then
|
||||
arch=x86_64
|
||||
fi
|
||||
platform=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||
build_dir="$kryon_dir/build/$platform-$arch"
|
||||
k2c="$build_dir/bin/k2c"
|
||||
work=${TMPDIR:-/tmp}/pass-kry-smoke.$$
|
||||
kry_files=$(find "$root/app" -type f -name '*.kry' | LC_ALL=C sort)
|
||||
|
||||
cleanup()
|
||||
{
|
||||
rm -rf "$work"
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
make -C "$kryon_dir" k2c
|
||||
|
||||
mkdir -p "$work/c"
|
||||
"$k2c" --no-main --root "$root" -o "$work/c" $kry_files
|
||||
|
||||
sh "$kryon_dir/tests/check_clean_generated_output.sh" "$work/c"
|
||||
|
||||
c_amalgam="$work/pass_kry_generated.c"
|
||||
pass_c=
|
||||
for file in $(find "$work/c" -type f -name '*.c' | LC_ALL=C sort); do
|
||||
case "$file" in
|
||||
*/app/pass.c)
|
||||
pass_c=$file
|
||||
;;
|
||||
*)
|
||||
printf '#include "%s"\n' "$file" >> "$c_amalgam"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [ -n "$pass_c" ]; then
|
||||
printf '#include "%s"\n' "$pass_c" >> "$c_amalgam"
|
||||
fi
|
||||
|
||||
cc -fsyntax-only \
|
||||
-D_DEFAULT_SOURCE \
|
||||
-D_GNU_SOURCE \
|
||||
-D_FILE_OFFSET_BITS=64 \
|
||||
-I"$kryon_dir/include" \
|
||||
-I"$kryon_dir/src" \
|
||||
-I"$work/c" \
|
||||
-I"$root/native" \
|
||||
-I"$root/droid/app/src/main/cpp" \
|
||||
"$c_amalgam"
|
||||
|
||||
echo "pass .kry to C smoke ok"
|
||||
@@ -0,0 +1,139 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import hashlib
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
CHARACTER_SUBSETS = {
|
||||
"lowercase": "abcdefghijklmnopqrstuvwxyz",
|
||||
"uppercase": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
"digits": "0123456789",
|
||||
"symbols": "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
|
||||
}
|
||||
|
||||
|
||||
def consume_entropy(password, entropy, characters, max_length):
|
||||
while len(password) < max_length:
|
||||
entropy, remainder = divmod(entropy, len(characters))
|
||||
password += characters[remainder]
|
||||
return password, entropy
|
||||
|
||||
|
||||
def available_characters(rule, exclude):
|
||||
characters = "".join(c for c in CHARACTER_SUBSETS[rule] if c not in exclude)
|
||||
if not characters:
|
||||
raise ValueError(f"{rule} has no characters after exclusions")
|
||||
return characters
|
||||
|
||||
|
||||
def lesspass_password(profile, master):
|
||||
rules = [rule for rule in ("lowercase", "uppercase", "digits", "symbols")
|
||||
if profile[rule]]
|
||||
salt = profile["site"] + profile["login"] + format(profile["counter"], "x")
|
||||
entropy = int.from_bytes(
|
||||
hashlib.pbkdf2_hmac("sha256", master.encode("utf-8"),
|
||||
salt.encode("utf-8"), 100000, 32),
|
||||
"big",
|
||||
)
|
||||
alphabet = "".join(available_characters(rule, profile.get("exclude", ""))
|
||||
for rule in rules)
|
||||
password, entropy = consume_entropy("", entropy, alphabet,
|
||||
profile["length"] - len(rules))
|
||||
required = ""
|
||||
for rule in rules:
|
||||
value, entropy = consume_entropy(
|
||||
"", entropy, available_characters(rule, profile.get("exclude", "")), 1)
|
||||
required += value
|
||||
for char in required:
|
||||
entropy, position = divmod(entropy, len(password))
|
||||
password = password[:position] + char + password[position:]
|
||||
return password
|
||||
|
||||
|
||||
def pass_cli(cli, profile, master):
|
||||
cmd = [
|
||||
cli,
|
||||
"--length", str(profile["length"]),
|
||||
"--counter", str(profile["counter"]),
|
||||
]
|
||||
for rule in ("lowercase", "uppercase", "digits", "symbols"):
|
||||
if not profile[rule]:
|
||||
cmd.append(f"--no-{rule}")
|
||||
if profile.get("exclude"):
|
||||
cmd.extend(["--exclude", profile["exclude"]])
|
||||
cmd.extend([profile["site"], profile["login"], master])
|
||||
return subprocess.check_output(cmd, text=True).rstrip("\n")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--cli", default="./pass")
|
||||
args = parser.parse_args()
|
||||
|
||||
cases = [
|
||||
("reviewer default", {
|
||||
"site": "lesspass.com",
|
||||
"login": "[email protected]",
|
||||
"length": 16,
|
||||
"counter": 1,
|
||||
"lowercase": True,
|
||||
"uppercase": True,
|
||||
"digits": True,
|
||||
"symbols": True,
|
||||
}, "password"),
|
||||
("hex counter 10", {
|
||||
"site": "site",
|
||||
"login": "login",
|
||||
"length": 16,
|
||||
"counter": 10,
|
||||
"lowercase": True,
|
||||
"uppercase": True,
|
||||
"digits": True,
|
||||
"symbols": True,
|
||||
}, "test"),
|
||||
("hex counter 16", {
|
||||
"site": "site",
|
||||
"login": "login",
|
||||
"length": 16,
|
||||
"counter": 16,
|
||||
"lowercase": True,
|
||||
"uppercase": True,
|
||||
"digits": True,
|
||||
"symbols": True,
|
||||
}, "test"),
|
||||
("unicode and two classes", {
|
||||
"site": "δοκιμή.example",
|
||||
"login": "ユーザー",
|
||||
"length": 12,
|
||||
"counter": 7,
|
||||
"lowercase": True,
|
||||
"uppercase": False,
|
||||
"digits": True,
|
||||
"symbols": False,
|
||||
}, "pässword"),
|
||||
("excluded characters", {
|
||||
"site": "example.com",
|
||||
"login": "alice",
|
||||
"length": 24,
|
||||
"counter": 1,
|
||||
"lowercase": True,
|
||||
"uppercase": True,
|
||||
"digits": True,
|
||||
"symbols": True,
|
||||
"exclude": "0Ool1I!|",
|
||||
}, "correct horse battery staple"),
|
||||
]
|
||||
|
||||
for name, profile, master in cases:
|
||||
expected = lesspass_password(profile, master)
|
||||
actual = pass_cli(args.cli, profile, master)
|
||||
if actual != expected:
|
||||
print(f"FAIL {name}: got {actual!r}, want {expected!r}")
|
||||
return 1
|
||||
print(f"ok {name}: {actual}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -2,7 +2,7 @@
|
||||
set -eu
|
||||
|
||||
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
version=$(sed -n 's/^const Version = "\([^"]*\)"/\1/p' "$root/version.go")
|
||||
version=$(sed -n '1p' "$root/VERSION")
|
||||
arch=${APPIMAGE_ARCH:-$(uname -m)}
|
||||
linuxdeploy=${LINUXDEPLOY:-linuxdeploy}
|
||||
appdir="$root/build/package/appimage/pass.AppDir"
|
||||
|
||||