Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2ddcb69a8 | ||
|
|
a69631e327 | ||
|
|
dd550dd58b | ||
|
|
36fd01fe5d | ||
|
|
0cb5600c14 | ||
|
|
ead336b215 | ||
|
|
6cea9233ef | ||
|
|
fbd7c4038a | ||
|
|
7bfa8fef2b | ||
|
|
bee76ab379 | ||
|
|
d8284a83e0 | ||
|
|
f2dad4b37f | ||
|
|
40f2cdf731 | ||
|
|
b193cbfa9f | ||
|
|
4e139b3ffb | ||
|
|
a5e69bb227 | ||
|
|
b0003dc032 | ||
|
|
e26d26f5db | ||
|
|
a45fd1d3ed | ||
|
|
2e5d765962 | ||
|
|
4d499720d8 | ||
|
|
ae502a322d | ||
|
|
1a4e0e0891 | ||
|
|
3b8c4eaf64 | ||
|
|
60a68d258a | ||
|
|
0a2ab3bb45 | ||
|
|
b9a6c6d350 | ||
|
|
b53050764b | ||
|
|
b8722b6b28 | ||
|
|
26047247f9 | ||
|
|
c801c62542 | ||
|
|
7601d7c58c | ||
|
|
47d77ab0ad | ||
|
|
09ac0a29f1 | ||
|
|
0fd42f7574 | ||
|
|
f5ea95a4ad | ||
|
|
a46090bb61 | ||
|
|
f596eadcd9 | ||
|
|
dd313c6497 | ||
|
|
bd283650e7 | ||
|
|
cdc1a27eaa | ||
|
|
7cbcba75d7 | ||
|
|
1532a077cc | ||
|
|
bf4c5aa90a | ||
|
|
af2cbb8700 | ||
|
|
3df6755173 | ||
|
|
d777510144 | ||
|
|
b66e4adac0 | ||
|
|
d768923212 | ||
|
|
0702855958 | ||
|
|
1b7056e520 | ||
|
|
3559cc6232 | ||
|
|
ac00936501 | ||
|
|
0d2c2b3a88 | ||
|
|
440da3f967 | ||
|
|
a63ff0658c | ||
|
|
503995197d | ||
|
|
c64c6bfa91 | ||
|
|
e0cbc46bf2 | ||
|
|
2007fbd0ed | ||
|
|
101247ccd7 | ||
|
|
a90700d08c | ||
|
|
005b0ddef1 | ||
|
|
67937e6eec | ||
|
|
667b6eb8fe | ||
|
|
b4d7720ce4 | ||
|
|
c681f186c4 | ||
|
|
e954637927 | ||
|
|
2ef4abeb1f | ||
|
|
8bd48e39cc | ||
|
|
a548c55e54 | ||
|
|
7fb12407e2 | ||
|
|
9396dfe752 | ||
|
|
4286940564 | ||
|
|
e0cc0dc5f5 | ||
|
|
b77cbfabfb | ||
|
|
7c4fc18a07 | ||
|
|
6b0f219f7e | ||
|
|
98d10e86bb | ||
|
|
c6db1e5fff | ||
|
|
9bd72cbf08 | ||
|
|
ca735590c2 | ||
|
|
4519c5db06 | ||
|
|
8540b489f1 | ||
|
|
952ff6c90c | ||
|
|
8e38f2f476 | ||
|
|
c25665bccc | ||
|
|
f2f4bccaf9 | ||
|
|
ef2c0d19ad | ||
|
|
d830e09e0a | ||
|
|
fd835f4627 | ||
|
|
2c7a4075da | ||
|
|
17b1662aca | ||
|
|
6ab16893a5 | ||
|
|
9181963a3b | ||
|
|
a2cbd49b8a | ||
|
|
27e6b2ceca | ||
|
|
b3e4abae8c | ||
|
|
942fa5a8fa | ||
|
|
d15a74c444 | ||
|
|
1a0b952c24 | ||
|
|
fee64de901 | ||
|
|
45694a2e0c | ||
|
|
c89856ba32 | ||
|
|
9ba2ea98f9 | ||
|
|
0586aa16e9 | ||
|
|
dc6cfa0db0 | ||
|
|
5972850f89 | ||
|
|
e6bfa121d2 | ||
|
|
720ad42405 | ||
|
|
88d2abba38 | ||
|
|
5349420989 | ||
|
|
7758a9d3c0 | ||
|
|
133b4b08b9 | ||
|
|
e5ad25fbdd | ||
|
|
1584763396 | ||
|
|
7ef2e2726d | ||
|
|
99cba65af5 | ||
|
|
35e8120dbe | ||
|
|
bc8e59fb5a |
No files matched your search
@@ -1,15 +1,16 @@
|
||||
build-essential
|
||||
cmake
|
||||
pkg-config
|
||||
libssl-dev
|
||||
zlib1g-dev
|
||||
libbrotli-dev
|
||||
libzstd-dev
|
||||
libsdl2-dev
|
||||
libgl-dev
|
||||
libx11-dev
|
||||
libdrm-dev
|
||||
libgbm-dev
|
||||
libegl-dev
|
||||
libgles-dev
|
||||
libcairo2-dev
|
||||
libfreetype6-dev
|
||||
libfontconfig1-dev
|
||||
libpango1.0-dev
|
||||
xvfb
|
||||
xauth
|
||||
libgtk-3-dev
|
||||
python3-pil
|
||||
tesseract-ocr
|
||||
imagemagick
|
||||
gnumeric
|
||||
zenity
|
||||
@@ -15,25 +15,26 @@ concurrency:
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
guard-submodule-urls:
|
||||
name: Submodule URLs are public HTTPS
|
||||
guard-package-urls:
|
||||
name: Package URLs are public HTTPS
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# Plain checkout on purpose: the guard validates URLs before allowing
|
||||
# recursive submodule checkout to continue.
|
||||
# Plain checkout on purpose: the guard validates URLs before fetching.
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Reject non-HTTPS submodule URLs
|
||||
run: scripts/check_submodule_urls.sh
|
||||
- name: Reject submodules and non-HTTPS package URLs
|
||||
run: scripts/check_package_urls.sh
|
||||
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
needs: guard-submodule-urls
|
||||
needs: guard-package-urls
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Install CLI test dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y openssl xclip xvfb xauth tesseract-ocr imagemagick
|
||||
- name: Install Emscripten
|
||||
run: |
|
||||
set -euo pipefail
|
||||
@@ -42,15 +43,21 @@ jobs:
|
||||
"$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
|
||||
- name: Test Ziran CLI, core, and native/portable app runtime
|
||||
run: make test
|
||||
- name: Build browser app
|
||||
run: make site
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
- name: Test browser input, storage, and offline launch
|
||||
env:
|
||||
WERK_WEB_BROWSER: google-chrome
|
||||
run: make web-smoke
|
||||
- name: Verify generated site
|
||||
run: |
|
||||
test -s build/site/index.html
|
||||
test -s build/site/app/index.html
|
||||
test -s build/site/app/index.wasm
|
||||
test -s build/site/index.wasm
|
||||
test -s build/site/sw.js
|
||||
test -s build/site/assets.json
|
||||
- name: Check fastlane metadata
|
||||
run: |
|
||||
set -eu
|
||||
@@ -76,7 +83,7 @@ jobs:
|
||||
|
||||
build-gui:
|
||||
name: GUI (${{ matrix.arch }})
|
||||
needs: guard-submodule-urls
|
||||
needs: guard-package-urls
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
@@ -87,8 +94,6 @@ jobs:
|
||||
runs-on: ${{ matrix.runner }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Install native dependencies
|
||||
run: |
|
||||
mapfile -t packages < .github/apt/gui-packages.txt
|
||||
@@ -96,23 +101,26 @@ jobs:
|
||||
sudo apt-get install -y "${packages[@]}"
|
||||
- name: Build GUI
|
||||
run: make gui
|
||||
- name: Render GUI on private display
|
||||
run: make gui-smoke
|
||||
- name: Build Debian package
|
||||
run: make package-deb
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: pass-gui-linux-${{ matrix.arch }}
|
||||
path: build/pass-gui
|
||||
name: werk-linux-${{ matrix.arch }}
|
||||
path: |
|
||||
build/werk
|
||||
build/apps
|
||||
build/pfp.png
|
||||
if-no-files-found: error
|
||||
|
||||
build-android:
|
||||
name: Android debug build
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
needs: guard-submodule-urls
|
||||
needs: guard-package-urls
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
@@ -135,15 +143,12 @@ jobs:
|
||||
path: |
|
||||
droid/app/.cxx
|
||||
droid/app/build/intermediates/cxx
|
||||
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/**') }}
|
||||
key: android-native-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('src/*.zi', 'apps/*/*.zi', 'droid/app/src/main/cpp/CMakeLists.txt', 'droid/app/build.gradle', 'ziran.lock') }}
|
||||
restore-keys: |
|
||||
android-native-${{ runner.os }}-${{ runner.arch }}-
|
||||
- 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"
|
||||
timeout-minutes: 15
|
||||
run: bash scripts/install_android_sdk.sh
|
||||
- name: Build debug APK
|
||||
run: |
|
||||
set -euo pipefail
|
||||
@@ -151,25 +156,31 @@ jobs:
|
||||
make android-debug
|
||||
|
||||
android-input-test:
|
||||
name: Android input instrumentation
|
||||
name: Android NativeActivity input
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
needs: guard-submodule-urls
|
||||
needs: guard-package-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
|
||||
timeout-minutes: 15
|
||||
run: bash scripts/install_android_sdk.sh 'platforms;android-30'
|
||||
- name: Install screenshot OCR
|
||||
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"
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y tesseract-ocr python3-pil
|
||||
# Without /dev/kvm access the emulator runs unaccelerated and is too
|
||||
# slow to answer input before Android reports it not responding.
|
||||
- name: Enable KVM for the emulator
|
||||
run: |
|
||||
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
|
||||
sudo udevadm control --reload-rules
|
||||
sudo udevadm trigger --name-match=kvm
|
||||
- name: Run Android input tests
|
||||
uses: reactivecircus/android-emulator-runner@v2
|
||||
with:
|
||||
@@ -178,12 +189,12 @@ jobs:
|
||||
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
|
||||
script: make android-emulator 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/
|
||||
build/android-input/
|
||||
build/workbook-android-test/
|
||||
if-no-files-found: ignore
|
||||
@@ -0,0 +1,56 @@
|
||||
name: Google Play testing bundle
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
bundle:
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: '21'
|
||||
- uses: gradle/actions/setup-gradle@v4
|
||||
- name: Install build tools
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential cmake pkg-config libssl-dev
|
||||
bash scripts/install_android_sdk.sh
|
||||
- name: Prepare preserved release key
|
||||
env:
|
||||
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
|
||||
run: |
|
||||
test -n "$KEYSTORE_BASE64"
|
||||
umask 077
|
||||
mkdir -p "$HOME/.android"
|
||||
printf '%s' "$KEYSTORE_BASE64" | base64 -d > "$HOME/.android/pass-release.keystore"
|
||||
- name: Build signed testing candidate
|
||||
env:
|
||||
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
||||
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
||||
run: |
|
||||
test -n "$KEYSTORE_PASSWORD"
|
||||
test -n "$KEY_ALIAS"
|
||||
make android-bundle
|
||||
- name: Validate the candidate
|
||||
run: |
|
||||
curl --fail --show-error --location --retry 3 \
|
||||
https://github.com/google/bundletool/releases/download/1.18.3/bundletool-all-1.18.3.jar \
|
||||
--output "$RUNNER_TEMP/bundletool.jar"
|
||||
python3 scripts/android-bundle-check.py "build/werk-$(cat VERSION).aab" \
|
||||
--bundletool "$RUNNER_TEMP/bundletool.jar" --version "$(cat VERSION)"
|
||||
- name: Remove temporary release key
|
||||
if: always()
|
||||
run: rm -f "$HOME/.android/pass-release.keystore"
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: werkzeug-play-testing
|
||||
path: build/*.aab
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
@@ -13,19 +13,19 @@ concurrency:
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
guard-submodule-urls:
|
||||
name: Submodule URLs are public HTTPS
|
||||
guard-package-urls:
|
||||
name: Package 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
|
||||
- name: Reject submodules and non-HTTPS package URLs
|
||||
run: scripts/check_package_urls.sh
|
||||
|
||||
cli:
|
||||
name: CLI (${{ matrix.arch }})
|
||||
needs: guard-submodule-urls
|
||||
needs: guard-package-urls
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
@@ -52,7 +52,7 @@ jobs:
|
||||
|
||||
gui:
|
||||
name: GUI (${{ matrix.arch }})
|
||||
needs: guard-submodule-urls
|
||||
needs: guard-package-urls
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
@@ -63,8 +63,6 @@ jobs:
|
||||
runs-on: ${{ matrix.runner }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Install native dependencies
|
||||
run: |
|
||||
mapfile -t packages < .github/apt/gui-packages.txt
|
||||
@@ -73,9 +71,9 @@ jobs:
|
||||
- run: make gui
|
||||
- name: Package GUI tarball and Debian package
|
||||
run: |
|
||||
name="pass-gui-linux-${{ matrix.arch }}"
|
||||
name="werk-linux-${{ matrix.arch }}"
|
||||
mkdir -p "build/release/$name"
|
||||
cp build/pass-gui LICENSE README.md "build/release/$name/"
|
||||
cp -R build/werk build/apps build/pfp.png LICENSE README.md assets/app/icon.png "build/release/$name/"
|
||||
tar -C build/release -czf "build/release/$name.tar.gz" "$name"
|
||||
make package-deb
|
||||
- name: Package AppImage
|
||||
@@ -92,7 +90,7 @@ jobs:
|
||||
with:
|
||||
name: gui-linux-${{ matrix.arch }}
|
||||
path: |
|
||||
build/release/pass-gui-linux-${{ matrix.arch }}.tar.gz
|
||||
build/release/werk-linux-${{ matrix.arch }}.tar.gz
|
||||
build/release/*.deb
|
||||
build/release/*.AppImage
|
||||
if-no-files-found: error
|
||||
@@ -101,11 +99,9 @@ jobs:
|
||||
name: Android
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
needs: guard-submodule-urls
|
||||
needs: guard-package-urls
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
@@ -128,15 +124,12 @@ 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('droid/app/src/main/cpp/CMakeLists.txt', 'droid/app/build.gradle', 'src/*.zi', 'apps/*/*.zi', 'ziran.lock') }}
|
||||
restore-keys: |
|
||||
android-native-${{ runner.os }}-${{ runner.arch }}-
|
||||
- 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"
|
||||
timeout-minutes: 15
|
||||
run: bash scripts/install_android_sdk.sh
|
||||
- name: Prepare Android signing key
|
||||
env:
|
||||
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
|
||||
@@ -154,7 +147,11 @@ 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
|
||||
export KRYON_DIR="$(./scripts/ziran.sh pkg path Kryon --locked)"
|
||||
export ZIRAN_ROOT="$(./scripts/ziran.sh pkg path ziran --locked)"
|
||||
export RAYLIB_DIR="$(./scripts/ziran.sh pkg path raylib --locked)/src"
|
||||
export LIBOQS_DIR="$(./scripts/ziran.sh pkg path liboqs --locked)"
|
||||
export MONOCYPHER_DIR="$(./scripts/ziran.sh pkg path monocypher --locked)"
|
||||
./droid/gradlew -p droid assembleRelease \
|
||||
-PsplitApks=true \
|
||||
-Pkeystore.path="$HOME/.android/pass-release.keystore" \
|
||||
@@ -163,18 +160,19 @@ jobs:
|
||||
--stacktrace
|
||||
VERSION=$(sed -n '1p' VERSION)
|
||||
mkdir -p build/release
|
||||
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"
|
||||
cp droid/app/build/outputs/apk/release/app-universal-release.apk build/release/werk-android.apk
|
||||
cp droid/app/build/outputs/apk/release/app-arm64-v8a-release.apk build/release/werk-android-arm64-v8a.apk
|
||||
cp droid/app/build/outputs/apk/release/app-armeabi-v7a-release.apk build/release/werk-android-armeabi-v7a.apk
|
||||
cp droid/app/build/outputs/apk/release/app-universal-release.apk "build/release/werk-$VERSION.apk"
|
||||
cp droid/app/build/outputs/apk/release/app-arm64-v8a-release.apk "build/release/werk-$VERSION-arm64-v8a.apk"
|
||||
cp droid/app/build/outputs/apk/release/app-armeabi-v7a-release.apk "build/release/werk-$VERSION-armeabi-v7a.apk"
|
||||
python3 scripts/android_apk_check.py build/release/werk-android*.apk
|
||||
test -s build/release/werk-android.apk
|
||||
test -s build/release/werk-android-arm64-v8a.apk
|
||||
test -s build/release/werk-android-armeabi-v7a.apk
|
||||
test -s "build/release/werk-$VERSION.apk"
|
||||
test -s "build/release/werk-$VERSION-arm64-v8a.apk"
|
||||
test -s "build/release/werk-$VERSION-armeabi-v7a.apk"
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: android
|
||||
@@ -183,11 +181,9 @@ jobs:
|
||||
|
||||
web:
|
||||
runs-on: ubuntu-latest
|
||||
needs: guard-submodule-urls
|
||||
needs: guard-package-urls
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Install Emscripten
|
||||
run: |
|
||||
set -euo pipefail
|
||||
@@ -201,26 +197,22 @@ jobs:
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cd build/site
|
||||
zip -qr ../pass-web.zip .
|
||||
zip -qr ../werk-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
|
||||
# The site root is the app: its page loads content-hashed script and
|
||||
# Wasm names, and the service worker caches the files in assets.json.
|
||||
mkdir -p ../werk-html5
|
||||
cp -R . ../werk-html5/
|
||||
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
|
||||
../werk-html5/index.html
|
||||
python3 - <<'PY'
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
root = Path("../pass-html5")
|
||||
root = Path("../werk-html5")
|
||||
manifest = json.loads((root / "manifest.webmanifest").read_text())
|
||||
manifest["start_url"] = "."
|
||||
manifest["scope"] = "."
|
||||
@@ -228,21 +220,15 @@ jobs:
|
||||
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 .
|
||||
cd ../werk-html5
|
||||
zip -qr ../werk-html5.zip .
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: web
|
||||
path: |
|
||||
build/pass-web.zip
|
||||
build/pass-html5.zip
|
||||
build/werk-web.zip
|
||||
build/werk-html5.zip
|
||||
if-no-files-found: error
|
||||
|
||||
publish:
|
||||
@@ -254,7 +240,6 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: recursive
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: build/artifacts
|
||||
@@ -278,7 +263,7 @@ jobs:
|
||||
set -euo pipefail
|
||||
VERSION=$(sed -n '1p' VERSION)
|
||||
TAG="v$VERSION"
|
||||
BASE="https://github.com/waozixyz/pass/releases/download/$TAG"
|
||||
BASE="https://github.com/${{ github.repository }}/releases/download/$TAG"
|
||||
# appcast channel names use dpkg arch naming (amd64/arm64);
|
||||
# the artifacts use uname -m naming (x86_64/aarch64)
|
||||
arch_name() {
|
||||
@@ -291,21 +276,21 @@ jobs:
|
||||
channels=()
|
||||
for img in build/artifacts/*.AppImage; do
|
||||
[ -e "$img" ] || continue
|
||||
arch=$(basename "$img" | sed -n 's/^pass-.*-\([^-]*\)\.AppImage$/\1/p')
|
||||
arch=$(basename "$img" | sed -n 's/^werk-.*-\([^-]*\)\.AppImage$/\1/p')
|
||||
channels+=("--channel" "appimage-$(arch_name "$arch")=$img")
|
||||
done
|
||||
DEB="$(find build/artifacts -maxdepth 1 -name '*.deb' -print -quit || true)"
|
||||
TAR="$(find build/artifacts -maxdepth 1 -name 'pass-gui-linux-*.tar.gz' -print -quit || true)"
|
||||
TAR="$(find build/artifacts -maxdepth 1 -name 'werk-linux-*.tar.gz' -print -quit || true)"
|
||||
[ -n "$DEB" ] && channels+=("--channel" "deb=$DEB")
|
||||
[ -n "$TAR" ] && channels+=("--channel" "tarball=$TAR")
|
||||
if [ ${#channels[@]} -eq 0 ]; then
|
||||
echo "no release artifacts found for the appcast"
|
||||
exit 1
|
||||
fi
|
||||
python3 vendor/kryon/scripts/make_appcast.py \
|
||||
python3 scripts/make_appcast.py \
|
||||
--version "$VERSION" \
|
||||
--base-url "$BASE" \
|
||||
--notes-url "https://github.com/waozixyz/pass/releases/tag/$TAG" \
|
||||
--notes-url "https://github.com/${{ github.repository }}/releases/tag/$TAG" \
|
||||
--changelog CHANGELOG.md \
|
||||
--out build/artifacts/appcast.json \
|
||||
"${channels[@]}"
|
||||
@@ -380,9 +365,9 @@ jobs:
|
||||
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"
|
||||
html5_zip="build/artifacts/werk-html5.zip"
|
||||
android_apk="build/artifacts/werk-android.apk"
|
||||
linux_appimage="build/artifacts/werk-$VERSION-x86_64.AppImage"
|
||||
|
||||
test -f "$html5_zip"
|
||||
test -f "$android_apk"
|
||||
@@ -395,7 +380,7 @@ jobs:
|
||||
log_file="$(mktemp)"
|
||||
|
||||
while [ "$attempt" -le 6 ]; do
|
||||
if butler push "$target" "waozi/pass:$channel" --userversion "$VERSION" 2>&1 | tee "$log_file"; then
|
||||
if butler push "$target" "waozi/werk:$channel" --userversion "$VERSION" 2>&1 | tee "$log_file"; then
|
||||
rm -f "$log_file"
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -14,23 +14,25 @@ concurrency:
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
guard-submodule-urls:
|
||||
name: Submodule URLs are public HTTPS
|
||||
guard-package-urls:
|
||||
name: Package 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
|
||||
- name: Reject submodules and non-HTTPS package URLs
|
||||
run: scripts/check_package_urls.sh
|
||||
|
||||
build:
|
||||
needs: guard-submodule-urls
|
||||
needs: guard-package-urls
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
node-version: '22'
|
||||
- name: Install Emscripten
|
||||
run: |
|
||||
set -euo pipefail
|
||||
@@ -44,11 +46,26 @@ jobs:
|
||||
set -euo pipefail
|
||||
make site
|
||||
test -s build/site/index.html
|
||||
test -s build/site/app/index.html
|
||||
test -s build/site/app/index.wasm
|
||||
test -s build/site/index.wasm
|
||||
test -s build/site/sw.js
|
||||
- name: Install screenshot OCR
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y tesseract-ocr imagemagick
|
||||
- name: Verify browser input, storage, cache upgrades, and offline launch
|
||||
env:
|
||||
WERK_WEB_BROWSER: google-chrome
|
||||
run: bash scripts/web_smoke.sh
|
||||
- name: Upload browser failure diagnostics
|
||||
if: failure()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: werk-browser-diagnostics
|
||||
path: build/web-test/*.png
|
||||
if-no-files-found: ignore
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: pass-site
|
||||
name: werk-site
|
||||
path: build/site
|
||||
if-no-files-found: error
|
||||
|
||||
@@ -60,14 +77,14 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: pass-site
|
||||
name: werk-site
|
||||
path: build/site
|
||||
- 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 }}
|
||||
command: pages deploy build/site --project-name=pass --branch=${{ github.head_ref || github.ref_name }} --commit-hash=${{ github.sha }}
|
||||
|
||||
deploy-production:
|
||||
name: Deploy Production
|
||||
@@ -77,11 +94,11 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: pass-site
|
||||
name: werk-site
|
||||
path: build/site
|
||||
- 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
|
||||
command: pages deploy build/site --project-name=pass --branch=master --commit-hash=${{ github.sha }}
|
||||
@@ -1,2 +1,9 @@
|
||||
/build/
|
||||
/pass
|
||||
/ziran.local.toml
|
||||
|
||||
__pycache__/
|
||||
*.pyc
|
||||
.wrangler/
|
||||
/backup/
|
||||
/work/
|
||||
@@ -1,3 +0,0 @@
|
||||
[submodule "vendor/kryon"]
|
||||
path = vendor/kryon
|
||||
url = https://github.com/kryonlabs/kryon.git
|
||||
@@ -0,0 +1,45 @@
|
||||
# Werkzeug repository rules
|
||||
|
||||
Werkzeug (formerly Pass) is a public repository. Read `~/Projects/AGENTS.md`
|
||||
first.
|
||||
|
||||
## Tools are separate apps
|
||||
|
||||
- Each tool builds into its own bundle, `build/apps/<tool>.zx`: Pass,
|
||||
Calculator and Clock from `apps/<tool>/`, Auth and Workbook from their own
|
||||
Ziran packages. The host (`src/apps.zi`) checks every call a bundle asks
|
||||
for and keeps each tool's files, assets and secret separate.
|
||||
- Tools never import another tool's modules. Code two tools need comes from
|
||||
a Ziran package, as SHA-256 and PBKDF2 come from `crypto`; no git
|
||||
submodules.
|
||||
- Keep the host interface small and generic (files, clock, clipboard,
|
||||
key derivation, device secret, input). A new host call needs a new host
|
||||
build before any bundle can use it.
|
||||
- Work the portable interpreter cannot do fast enough, such as Pass's
|
||||
100,000 PBKDF2 rounds, is a native host capability, never a step-limit
|
||||
increase.
|
||||
|
||||
## Data and secrets
|
||||
|
||||
- Never commit, print or log a real master password, Auth secret, otpauth
|
||||
link, export file or current code. Tests use fixture values only, such as
|
||||
the RFC 6238 keys.
|
||||
- Keep Pass's on-disk formats and `src/migrate.zi`. The owner's latest choice
|
||||
on 2026-10-23 is an update of the existing Android/F-Droid app: keep
|
||||
`xyz.waozi.pass` and its signing certificate, with the display name Werkzeug.
|
||||
Preserve existing Pass data and any separate `xyz.waozi.werk` installation.
|
||||
- Every file Werkzeug writes is private (0600 in 0700 folders).
|
||||
|
||||
## Platforms and tests
|
||||
|
||||
- Ziran only: C, Wasm and the browser loaders are compiler outputs. The
|
||||
Android app has no Java (`hasCode=false`); it reaches the platform through
|
||||
JNI from Ziran.
|
||||
- Desktop tests run on private Xvfb displays (`make gui-smoke gui-test`),
|
||||
the browser test in private headless Chromium (`make web-smoke`), and
|
||||
Android tests only on a private emulator (`make android-input-test`),
|
||||
never on a connected phone.
|
||||
- Run `make test` and `ziran fmt --check` before committing.
|
||||
- Releases follow `~/Projects/AGENTS.md`: add the numeric entry to
|
||||
`CHANGELOG.md` and run `./update_version.sh`; only the release workflow
|
||||
creates tags.
|
||||
@@ -1,5 +1,75 @@
|
||||
# Changelog
|
||||
|
||||
## [0.4.7] - 2026-10-28
|
||||
|
||||
- Use Workbook on Android and the web as well as Linux, with formulas, sheet tabs, automatic saving and document import/export.
|
||||
- Navigate Workbook cells with touch controls, and keep Android's keyboard focused while editing a cell.
|
||||
|
||||
## [0.4.6] - 2026-10-27
|
||||
|
||||
- Set an account alias with capitals, an @ or spaces; a taken alias now says so.
|
||||
|
||||
## [0.4.5] - 2026-10-26
|
||||
|
||||
- Fix Android opening to “Apps are unavailable”; Pass, Auth, Calculator and Clock load normally.
|
||||
|
||||
## [0.4.4] - 2026-10-23
|
||||
|
||||
- Werkzeug updates the existing Pass Android app using its original application ID and signing certificate, keeping its saved data.
|
||||
- The app continues to appear as Werkzeug, with Pass, Auth, Calculator and Clock together.
|
||||
|
||||
## [0.4.3] - 2026-10-23
|
||||
|
||||
- Werkzeug uses its own Android application ID, `xyz.waozi.werk`.
|
||||
- Werkzeug installs alongside legacy Pass, preserving the older app and its data.
|
||||
|
||||
## [0.4.2] - 2026-10-23
|
||||
|
||||
- Linux packages include the libraries needed for sync and importing QR-code pictures.
|
||||
- Packaging a new AppImage preserves previous downloads.
|
||||
|
||||
## [0.4.1] - 2026-10-23
|
||||
|
||||
- Open Pass, Auth, Calculator, Clock and Workbook directly from the Linux application menu, each with its own icon.
|
||||
- Desktop installs add shortcuts for Werkzeug and every tool to your configured desktop folder.
|
||||
- Tool windows show their own names and icons in the desktop switcher.
|
||||
|
||||
## [0.4.0] - 2026-10-19
|
||||
|
||||
- A new purple W logo across the app, Android and the website.
|
||||
- Calculator gets a Scientific mode.
|
||||
- Auth imports Google Authenticator, Aegis and Ente Auth exports, and on the desktop a picture of their QR code.
|
||||
- Rename an Auth account, note the websites it signs in to, or remove it.
|
||||
- Choose your own Daochi node, and pause sync without losing your account.
|
||||
- On the desktop, Profile manages your account: create it, import or back up its key, and link devices by QR code.
|
||||
- Sign in with a Daochi account key you already have, such as Inbe's.
|
||||
- `werk sync` and `werk auth` work without a window on Linux.
|
||||
- Reach every tool from the web app's mini version.
|
||||
- Fix the web version freezing when Clock opens.
|
||||
- Show π, √ and other symbols on phones older than Android 10.
|
||||
- Fix Profile breaking after choosing a file on desktops whose language writes decimals with a comma.
|
||||
- The `pass` command unlocks vaults whose text is wrapped with spaces or tabs on systems with OpenSSL 3.0.
|
||||
|
||||
## [0.3.1] - 2026-10-13
|
||||
|
||||
- Fix the web version on itch.io, which opened to a blank page.
|
||||
|
||||
## [0.3.0] - 2026-10-13
|
||||
|
||||
- Pass is now Werkzeug: a home screen of small private tools, each its own app and all preinstalled.
|
||||
- A new logo: a wrench with a keyhole. The website moves to werk.waozi.xyz.
|
||||
- Add Auth for two-factor sign-in codes from otpauth links or secret keys; copied codes clear after 30 seconds.
|
||||
- Add Calculator, and Clock with a stopwatch.
|
||||
- Add a profile with your name, a picture and the appearance every tool shares.
|
||||
- Sync Auth's accounts between your devices from Profile → Sync: create an account, then connect another device with a 12-character code. Accounts are encrypted on the device; the server never sees them.
|
||||
- Keep your Pass profiles, settings, theme and saved master password when updating.
|
||||
- On Android, keep every screen clear of the navigation bar and the keyboard.
|
||||
- Use Inbe's font, Noto Sans, in the browser and on phones older than Android 10.
|
||||
|
||||
## [0.2.10] - 2026-10-05
|
||||
|
||||
- Introduce the purple password asterisk and keyhole logo across Pass, website icons, Android launchers, and app listings.
|
||||
|
||||
## [0.2.9] - 2026-09-05
|
||||
|
||||
- Keep bottom navigation, password controls, and dialog icons readable with
|
||||
|
||||
@@ -1,209 +1,251 @@
|
||||
.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
|
||||
|
||||
.DEFAULT_GOAL := all
|
||||
ZIRAN ?= ./scripts/ziran.sh
|
||||
# Gradle invokes make again for portable bundles. Inherited environment
|
||||
# variables otherwise export these shell-derived paths while resolving them.
|
||||
unexport ZIRAN_ROOT KRYON_DIR RAYLIB_DIR MINGCUTE_DIR LIBOQS_DIR MONOCYPHER_DIR QRCODE_DIR WORKBOOK_DIR ENTITY_DIR APPS_DIR AUTH_DIR CRYPTO_DIR
|
||||
# Local overrides refer to the real root repositories. Published builds
|
||||
# require the exact versions recorded in the committed lock.
|
||||
LOCK_FLAGS := $(if $(wildcard ziran.local.toml),,--locked)
|
||||
ZIRAN_ROOT = $(shell $(ZIRAN) pkg path ziran $(LOCK_FLAGS))
|
||||
KRYON_DIR = $(shell $(ZIRAN) pkg path kryon $(LOCK_FLAGS))
|
||||
RAYLIB_DIR = $(shell $(ZIRAN) pkg path raylib $(LOCK_FLAGS))/src
|
||||
MINGCUTE_DIR = $(shell $(ZIRAN) pkg path mingcute $(LOCK_FLAGS))
|
||||
# Account sync: ML-DSA-44 account keys from liboqs, and Ed25519, X25519,
|
||||
# BLAKE2b and XChaCha20-Poly1305 from Monocypher.
|
||||
LIBOQS_DIR = $(shell $(ZIRAN) pkg path liboqs $(LOCK_FLAGS))
|
||||
MONOCYPHER_DIR = $(shell $(ZIRAN) pkg path monocypher $(LOCK_FLAGS))
|
||||
QRCODE_DIR = $(shell $(ZIRAN) pkg path qrcode $(LOCK_FLAGS))
|
||||
WORKBOOK_DIR = $(shell $(ZIRAN) pkg path workbook $(LOCK_FLAGS))
|
||||
ENTITY_DIR = $(shell $(ZIRAN) pkg path entity $(LOCK_FLAGS))
|
||||
APPS_DIR = $(shell $(ZIRAN) pkg path apps $(LOCK_FLAGS))
|
||||
# Auth is its own package; SHA-256 and PBKDF2 come from the crypto package.
|
||||
AUTH_DIR = $(shell $(ZIRAN) pkg path auth $(LOCK_FLAGS))
|
||||
CRYPTO_DIR = $(shell $(ZIRAN) pkg path crypto $(LOCK_FLAGS))
|
||||
LIBOQS_FLAGS := -DCMAKE_BUILD_TYPE=MinSizeRel -DBUILD_SHARED_LIBS=OFF -DOQS_BUILD_ONLY_LIB=ON \
|
||||
-DOQS_USE_OPENSSL=OFF -DOQS_DIST_BUILD=OFF -DOQS_OPT_TARGET=generic -DOQS_MINIMAL_BUILD=SIG_ml_dsa_44
|
||||
MONOCYPHER_SOURCES = $(MONOCYPHER_DIR)/src/monocypher.c $(MONOCYPHER_DIR)/src/optional/monocypher-ed25519.c
|
||||
CC ?= cc
|
||||
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
|
||||
DESKTOP_DIR ?= $(shell xdg-user-dir DESKTOP 2>/dev/null)
|
||||
# The tool bundles and Werkzeug's other files.
|
||||
LIB_DIR ?= $(HOME)/.local/lib/werk
|
||||
WEB_CC ?= $(if $(wildcard $(HOME)/emsdk/upstream/emscripten/emcc),$(HOME)/emsdk/upstream/emscripten/emcc,emcc)
|
||||
SOURCES := $(wildcard src/*.zi apps/*/*.zi)
|
||||
LIBRARY_SOURCES = $(wildcard $(KRYON_DIR)/src/ui/*.zi $(KRYON_DIR)/src/ui/*/module.zi $(KRYON_DIR)/src/kss/*.zi $(KRYON_DIR)/src/backend/*.zi $(KRYON_DIR)/src/backend/*/module.zi $(ZIRAN_ROOT)/std/*.zi)
|
||||
ZIRAN_RUNTIME_SOURCES = $(wildcard $(ZIRAN_ROOT)/cmd/zir/*.[ch] $(ZIRAN_ROOT)/include/*.h)
|
||||
ENTITY_SOURCES = $(wildcard $(ENTITY_DIR)/src/*.zi $(ENTITY_DIR)/assets/entity/*)
|
||||
CFLAGS := -std=c99 -O2 -Wno-unused-variable -I$(ZIRAN_ROOT)/include
|
||||
PROJECT := --project $(LOCK_FLAGS)
|
||||
ANDROID_ABIS ?= armeabi-v7a,arm64-v8a
|
||||
|
||||
.PHONY: all apps portable-apps cli gui native run test source-check core-test ziran-core-test cli-test pass-state-test app-logic-test lesspass-compat-test entity-account-test gui-smoke gui-test web web-canvas site web-smoke android-debug android-emulator android-release android-smoke android-input-test e2e check-package-urls install install-cli install-gui uninstall-cli uninstall-gui package-deb package-appimage
|
||||
all: cli gui
|
||||
native: all
|
||||
|
||||
build/generated/cli/.complete: $(SOURCES) ziran.toml ziran.lock
|
||||
rm -rf $(@D)
|
||||
mkdir -p $(@D)
|
||||
$(ZIRAN) build $(PROJECT) --target=c --entry cli:main -o $(@D) apps/pass/cli.zi
|
||||
touch $@
|
||||
build/pass: build/generated/cli/.complete
|
||||
$(CC) $(CFLAGS) -Ibuild/generated/cli build/generated/cli/*.c -o $@
|
||||
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 $@
|
||||
# Each app is its own bundle, shared by the desktop, web and Android hosts.
|
||||
APPS := pass calculator clock
|
||||
PORTABLE_BUNDLES := $(APPS:%=build/apps/%.zx) build/apps/auth.zx build/apps/entity.zx build/apps/apps.zx build/apps/workbook.zx
|
||||
APP_BUNDLES := $(PORTABLE_BUNDLES)
|
||||
CRYPTO_SOURCES = $(wildcard $(CRYPTO_DIR)/src/*.zi)
|
||||
APPS_UI_SOURCES = $(wildcard $(APPS_DIR)/src/*.zi $(APPS_DIR)/ui/*.zi $(APPS_DIR)/ui/locales/*.json)
|
||||
APP_MODULE_PATHS = --module-path crypto=$(CRYPTO_DIR)/src --module-path kryon=$(KRYON_DIR)/src/backend --module-path kryon=$(KRYON_DIR)/src/ui --module-path $(KRYON_DIR)/src/ui --module-path $(MINGCUTE_DIR)/src --module-path $(ZIRAN_ROOT)/std
|
||||
apps: $(APP_BUNDLES)
|
||||
portable-apps: $(PORTABLE_BUNDLES)
|
||||
# Compile the shared screen with the host's compiler and UI library. The
|
||||
# reviewed payload must match both the build pin and the native host pin.
|
||||
build/apps/apps.zx: $(APPS_UI_SOURCES) $(LIBRARY_SOURCES) $(ZIRAN_RUNTIME_SOURCES) ziran.lock apps-controller.sha256 Makefile scripts/ziran.sh
|
||||
mkdir -p $(@D)
|
||||
python3 '$(APPS_DIR)/scripts/generate-ui-locales.py' --check
|
||||
$(ZIRAN) bundle --root $(APPS_DIR)/ui --module-path $(APPS_DIR)/src $(APP_MODULE_PATHS) \
|
||||
--define KRYON_HOSTED_UI --entry apps:Main -o $@ $(APPS_DIR)/ui/apps.zi
|
||||
sha256sum $@ | cut -d ' ' -f 1 > $(@D)/apps.sha256
|
||||
test "$$(cat $(@D)/apps.sha256)" = "$$(cat apps-controller.sha256)"
|
||||
.SECONDEXPANSION:
|
||||
build/apps/%.zx: $$(wildcard apps/$$*/*.zi apps/$$*/assets/*) $(CRYPTO_SOURCES) $(LIBRARY_SOURCES) $(ZIRAN_RUNTIME_SOURCES) ziran.lock Makefile scripts/ziran.sh
|
||||
mkdir -p $(@D)
|
||||
$(ZIRAN) bundle --root . --module-path apps/$* $(APP_MODULE_PATHS) --define KRYON_HOSTED_UI --define WERK_APP \
|
||||
$(if $(wildcard apps/$*/assets),--asset-dir assets=apps/$*/assets) --entry $*:Main -o $@ apps/$*/$*.zi
|
||||
|
||||
build build/gui:
|
||||
mkdir -p $@
|
||||
build/apps/auth.zx: $(wildcard $(AUTH_DIR)/src/*.zi) $(CRYPTO_SOURCES) $(LIBRARY_SOURCES) $(ZIRAN_RUNTIME_SOURCES) ziran.lock Makefile scripts/ziran.sh
|
||||
mkdir -p $(@D)
|
||||
$(ZIRAN) bundle --root $(AUTH_DIR) --module-path $(AUTH_DIR)/src $(APP_MODULE_PATHS) --define KRYON_HOSTED_UI --define WERK_APP \
|
||||
--entry auth:Main -o $@ $(AUTH_DIR)/src/auth.zi
|
||||
|
||||
$(KRYON_BUILD_DIR)/libkryon.a: $(KRYON_RUNTIME_SOURCES) vendor/kryon/Makefile
|
||||
$(MAKE) -C vendor/kryon -f Makefile all
|
||||
build/apps/workbook.zx: $(wildcard $(WORKBOOK_DIR)/src/*.zi) $(LIBRARY_SOURCES) $(ZIRAN_RUNTIME_SOURCES) ziran.lock Makefile
|
||||
mkdir -p $(@D)
|
||||
$(ZIRAN) bundle --root $(WORKBOOK_DIR) --module-path $(WORKBOOK_DIR)/src $(APP_MODULE_PATHS) \
|
||||
--module-path kryon=$(KRYON_DIR)/src/backend --define KRYON_HOSTED_UI --entry app:Main -o $@ $(WORKBOOK_DIR)/src/app.zi
|
||||
|
||||
$(K2C): $(K2C_SOURCES) vendor/kryon/Makefile
|
||||
$(MAKE) -C vendor/kryon -f Makefile k2c
|
||||
build/apps/entity.zx: $(ENTITY_SOURCES) $(LIBRARY_SOURCES) $(ZIRAN_RUNTIME_SOURCES) ziran.lock Makefile
|
||||
mkdir -p $(@D)
|
||||
$(ZIRAN) bundle --root $(ENTITY_DIR) --module-path $(ENTITY_DIR)/src $(APP_MODULE_PATHS) --define KRYON_HOSTED_UI \
|
||||
--module-path qrcode=$(QRCODE_DIR)/src --asset-dir assets=$(ENTITY_DIR)/assets --entry entity:Main -o $@ $(ENTITY_DIR)/src/entity.zi
|
||||
|
||||
kry-c: $(KRY_C_STAMP)
|
||||
# The portable bundle runtime the host links, built from the locked Ziran.
|
||||
.PHONY: runtime-cache-force
|
||||
runtime-cache-force:
|
||||
build/ziran/.toolchain: runtime-cache-force scripts/runtime_cache.py
|
||||
python3 scripts/runtime_cache.py "$(ZIRAN_ROOT)" "$(abspath build/ziran)"
|
||||
build/ziran/libziran.a: ziran.lock $(ZIRAN_RUNTIME_SOURCES) build/ziran/.toolchain
|
||||
env -u DISPLAY -u WAYLAND_DISPLAY -u MAKEFLAGS -u MFLAGS -u MAKEOVERRIDES $(MAKE) -C $(ZIRAN_ROOT) BUILD_DIR=$(abspath build/ziran) $(abspath $@)
|
||||
|
||||
$(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)
|
||||
build/generated/desktop/.complete: $(wildcard src/*.zi) $(wildcard $(WORKBOOK_DIR)/src/*.zi) $(CRYPTO_SOURCES) $(LIBRARY_SOURCES) $(ENTITY_SOURCES) ziran.toml ziran.lock
|
||||
rm -rf $(@D)
|
||||
mkdir -p $(@D)
|
||||
$(ZIRAN) build $(PROJECT) --define PLATFORM_DESKTOP --target=c --entry desktop:main -o $(@D) src/desktop.zi
|
||||
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
|
||||
|
||||
build/liboqs/lib/liboqs.a: ziran.lock
|
||||
cmake -S $(LIBOQS_DIR) -B build/liboqs $(LIBOQS_FLAGS) > /dev/null
|
||||
cmake --build build/liboqs --target oqs > /dev/null
|
||||
build/werk: build/generated/desktop/.complete build/ziran/libziran.a build/liboqs/lib/liboqs.a Makefile
|
||||
$(CC) $(CFLAGS) -Ibuild/generated/desktop -I$(MONOCYPHER_DIR)/src -I$(MONOCYPHER_DIR)/src/optional \
|
||||
build/generated/desktop/*.c $(MONOCYPHER_SOURCES) build/ziran/libziran.a build/liboqs/lib/liboqs.a \
|
||||
$(shell pkg-config --libs sdl2 cairo freetype2 fontconfig pangocairo gtk+-3.0) -lX11 -l:libcurl.so.4 -lm -lpthread -o $@.new
|
||||
mv -f $@.new $@
|
||||
build/pfp.png: $(KRYON_DIR)/icons/pfp.png
|
||||
cp $< $@
|
||||
gui: build/werk build/pfp.png apps
|
||||
run: gui
|
||||
./build/pass-gui
|
||||
|
||||
install: install-cli install-gui
|
||||
|
||||
install-cli: cli
|
||||
mkdir -p $(BIN_DIR)
|
||||
install -m 0755 pass $(BIN_DIR)/pass
|
||||
|
||||
uninstall-cli:
|
||||
rm -f $(BIN_DIR)/pass
|
||||
|
||||
install-gui: gui
|
||||
mkdir -p $(BIN_DIR) $(DATA_DIR)/applications $(DATA_DIR)/icons/hicolor/512x512/apps
|
||||
install -m 0755 build/pass-gui $(BIN_DIR)/pass-gui
|
||||
cp packaging/linux/xyz.waozi.pass.desktop $(DATA_DIR)/applications/xyz.waozi.pass.desktop
|
||||
cp assets/app/icon.png $(DATA_DIR)/icons/hicolor/512x512/apps/pass.png
|
||||
|
||||
uninstall-gui:
|
||||
rm -f $(BIN_DIR)/pass-gui $(DATA_DIR)/applications/xyz.waozi.pass.desktop $(DATA_DIR)/icons/hicolor/512x512/apps/pass.png
|
||||
|
||||
test:
|
||||
$(MAKE) native-test cli-test runtime-test lesspass-compat-test kry-smoke
|
||||
|
||||
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
|
||||
./build/werk
|
||||
|
||||
source-check:
|
||||
python3 scripts/source_check.py
|
||||
$(ZIRAN) fmt --check $(SOURCES) tests/*.zi
|
||||
core-test ziran-core-test:
|
||||
sh scripts/ziran_core_test.sh "$(ZIRAN)"
|
||||
pass-state-test:
|
||||
sh scripts/pass_state_test.sh "$(ZIRAN)"
|
||||
app-logic-test:
|
||||
sh scripts/app_logic_test.sh "$(ZIRAN)"
|
||||
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
|
||||
entity-account-test: build/liboqs/lib/liboqs.a
|
||||
ZIRAN_BIN=$(ZIRAN) python3 scripts/entity_account_test.py
|
||||
.PHONY: android-sdk-install-test
|
||||
android-sdk-install-test:
|
||||
python3 scripts/install_android_sdk_test.py
|
||||
test: source-check core-test pass-state-test app-logic-test cli-test lesspass-compat-test entity-account-test android-sdk-install-test runtime-cache-test
|
||||
.PHONY: runtime-cache-test
|
||||
runtime-cache-test:
|
||||
python3 scripts/runtime_cache_test.py
|
||||
gui-smoke: gui
|
||||
sh scripts/gui_smoke.sh
|
||||
gui-test: gui
|
||||
python3 scripts/private-display.py python3 scripts/apps_gui_test.py
|
||||
sh scripts/werk_gui_test.sh
|
||||
python3 scripts/private-display.py python3 scripts/workbook_gui_test.py
|
||||
python3 scripts/private-display.py python3 scripts/launcher_gui_test.py
|
||||
sh scripts/migration_test.sh
|
||||
python3 -I scripts/auth_command_test.py
|
||||
|
||||
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: kry-c
|
||||
cd $(ANDROID_DIR) && ./gradlew assembleDebug -Pabi=$(ANDROID_ABIS) -PsplitApks=true
|
||||
mkdir -p build
|
||||
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:
|
||||
# The bundle runtime for the browser, built from the locked Ziran.
|
||||
WEB_AR ?= $(dir $(WEB_CC))emar
|
||||
build/web-runtime/.toolchain: runtime-cache-force scripts/runtime_cache.py
|
||||
python3 scripts/runtime_cache.py "$(ZIRAN_ROOT)" "$(abspath build/web-runtime)"
|
||||
build/web-runtime/libziran.a: ziran.lock build/web-runtime/.toolchain
|
||||
env -u DISPLAY -u WAYLAND_DISPLAY -u MAKEFLAGS -u MFLAGS -u MAKEOVERRIDES $(MAKE) -C $(ZIRAN_ROOT) BOOTSTRAP=1 BUILD_DIR=$(abspath build/web-runtime) \
|
||||
CC=$(WEB_CC) AR=$(WEB_AR) OBJCOPY=true CFLAGS=-O2 $(abspath $@)
|
||||
build/generated/browser/.complete: $(wildcard src/*.zi) $(wildcard $(WORKBOOK_DIR)/src/*.zi) $(CRYPTO_SOURCES) $(LIBRARY_SOURCES) ziran.toml ziran.lock
|
||||
rm -rf $(@D)
|
||||
mkdir -p $(@D)
|
||||
$(ZIRAN) build $(PROJECT) --define PLATFORM_WEB --target=c -o $(@D) src/browser.zi
|
||||
touch $@
|
||||
build/web-app/index.js: build/generated/browser/.complete build/web-runtime/libziran.a $(PORTABLE_BUNDLES) build/pfp.png assets/app/icon.png assets/fonts/NotoSans-Regular.ttf
|
||||
mkdir -p $(@D)
|
||||
$(WEB_CC) -O2 -Wno-parentheses-equality -I$(ZIRAN_ROOT)/include -iquote build/generated/browser build/generated/browser/*.c \
|
||||
build/web-runtime/libziran.a \
|
||||
--js-library $(ZIRAN_ROOT)/web/ziran_web.js -sEXPORTED_RUNTIME_METHODS=FS,IDBFS -lidbfs.js \
|
||||
-sASYNCIFY -sALLOW_MEMORY_GROWTH=1 -sSTACK_SIZE=16777216 -sASYNCIFY_STACK_SIZE=1048576 -sENVIRONMENT=web \
|
||||
--embed-file assets/fonts/NotoSans-Regular.ttf@/kryon-font.ttf \
|
||||
$(foreach bundle,$(PORTABLE_BUNDLES),--embed-file $(bundle)@/apps/$(notdir $(bundle))) --embed-file build/pfp.png@/pfp.png --embed-file assets/app/icon.png@/icon.png -o $@
|
||||
build/web-app/index.html: build/web-app/index.js web/site/index.html
|
||||
cp web/site/index.html $@
|
||||
build/generated/worker/.complete: src/service_worker.zi ziran.toml ziran.lock
|
||||
rm -rf $(@D)
|
||||
mkdir -p $(@D)
|
||||
$(ZIRAN) build $(PROJECT) --target=c -o $(@D) src/service_worker.zi
|
||||
touch $@
|
||||
build/web-app/sw.js: build/generated/worker/.complete
|
||||
$(WEB_CC) -O2 -I$(ZIRAN_ROOT)/include -iquote build/generated/worker build/generated/worker/*.c \
|
||||
--js-library $(ZIRAN_ROOT)/web/ziran_web.js -sENVIRONMENT=worker -sNO_EXIT_RUNTIME=1 \
|
||||
-sSINGLE_FILE=1 -sWASM_ASYNC_COMPILATION=0 -o $@
|
||||
web-canvas: build/web-app/index.html build/web-app/sw.js
|
||||
web site: web-canvas
|
||||
./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/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
|
||||
# CMake emits JNI and foreign ABI types separately for each Android ABI.
|
||||
android-debug: portable-apps
|
||||
cd droid && env WERK_ZIRAN_COMMAND="$(ZIRAN)" KRYON_DIR="$(KRYON_DIR)" ZIRAN_ROOT="$(ZIRAN_ROOT)" RAYLIB_DIR="$(RAYLIB_DIR)" LIBOQS_DIR="$(LIBOQS_DIR)" MONOCYPHER_DIR="$(MONOCYPHER_DIR)" ./gradlew assembleDebug -Pabi=$(ANDROID_ABIS) -PsplitApks=true $(GRADLE_ARGS)
|
||||
mkdir -p build
|
||||
cp droid/app/build/outputs/apk/debug/app-universal-debug.apk build/werk-android-debug.apk
|
||||
python3 scripts/android_apk_check.py build/werk-android-debug.apk
|
||||
cp droid/app/build/outputs/apk/debug/app-arm64-v8a-debug.apk build/werk-android-arm64-v8a-debug.apk
|
||||
cp droid/app/build/outputs/apk/debug/app-armeabi-v7a-debug.apk build/werk-android-armeabi-v7a-debug.apk
|
||||
android-emulator: portable-apps
|
||||
cd droid && env WERK_ZIRAN_COMMAND="$(ZIRAN)" KRYON_DIR="$(KRYON_DIR)" ZIRAN_ROOT="$(ZIRAN_ROOT)" RAYLIB_DIR="$(RAYLIB_DIR)" LIBOQS_DIR="$(LIBOQS_DIR)" MONOCYPHER_DIR="$(MONOCYPHER_DIR)" ./gradlew assembleDebug -Pabi=x86_64 $(GRADLE_ARGS)
|
||||
mkdir -p build
|
||||
cp droid/app/build/outputs/apk/debug/app-debug.apk build/werk-android-emulator.apk
|
||||
python3 scripts/android_apk_check.py build/werk-android-emulator.apk
|
||||
android-release: portable-apps
|
||||
cd droid && env WERK_ZIRAN_COMMAND="$(ZIRAN)" KRYON_DIR="$(KRYON_DIR)" ZIRAN_ROOT="$(ZIRAN_ROOT)" RAYLIB_DIR="$(RAYLIB_DIR)" LIBOQS_DIR="$(LIBOQS_DIR)" MONOCYPHER_DIR="$(MONOCYPHER_DIR)" ./gradlew assembleRelease -Pabi=$(ANDROID_ABIS) -PsplitApks=true $(GRADLE_ARGS)
|
||||
.PHONY: android-bundle
|
||||
android-bundle: portable-apps
|
||||
cd droid && env WERK_ZIRAN_COMMAND="$(ZIRAN)" KRYON_DIR="$(KRYON_DIR)" ZIRAN_ROOT="$(ZIRAN_ROOT)" RAYLIB_DIR="$(RAYLIB_DIR)" LIBOQS_DIR="$(LIBOQS_DIR)" MONOCYPHER_DIR="$(MONOCYPHER_DIR)" ./gradlew bundleRelease -Pabi=$(ANDROID_ABIS) $(GRADLE_ARGS)
|
||||
cp droid/app/build/outputs/bundle/release/app-release.aab build/werk-$(shell cat VERSION).aab
|
||||
.PHONY: android-fdroid
|
||||
# F-Droid compares this source build with the signed upstream release.
|
||||
android-fdroid:
|
||||
$(MAKE) android-release GRADLE_ARGS="$(GRADLE_ARGS) -PfDroidBuild=true"
|
||||
mkdir -p build/fdroid
|
||||
cp droid/app/build/outputs/apk/release/app-universal-release-unsigned.apk build/fdroid/werk.apk
|
||||
python3 scripts/android_apk_check.py build/fdroid/werk.apk
|
||||
android-smoke:
|
||||
bash scripts/android_smoke.sh
|
||||
android-input-test:
|
||||
python3 scripts/android_input_test.py
|
||||
python3 scripts/workbook_android_test.py
|
||||
|
||||
check-package-urls:
|
||||
bash scripts/check_package_urls.sh
|
||||
e2e: check-package-urls test gui-smoke gui-test web-smoke android-debug
|
||||
|
||||
install: install-cli install-gui
|
||||
install-cli: cli
|
||||
mkdir -p $(BIN_DIR)
|
||||
install -m 0755 pass $(BIN_DIR)/pass
|
||||
install-gui: gui
|
||||
mkdir -p "$(BIN_DIR)" "$(DATA_DIR)/applications" "$(DATA_DIR)/icons/hicolor/512x512/apps" "$(DATA_DIR)/mime/packages"
|
||||
install -d -m 0700 "$(LIB_DIR)" "$(LIB_DIR)/apps"
|
||||
install -m 0755 build/werk "$(BIN_DIR)/werk.new"
|
||||
mv -f "$(BIN_DIR)/werk.new" "$(BIN_DIR)/werk"
|
||||
install -m 0600 $(APP_BUNDLES) "$(LIB_DIR)/apps/"
|
||||
install -m 0644 build/pfp.png "$(LIB_DIR)/pfp.png"
|
||||
python3 scripts/install-launchers.py --data-dir "$(DATA_DIR)" --bin-dir "$(BIN_DIR)" $(if $(filter-out $(HOME),$(DESKTOP_DIR)),--desktop-dir "$(DESKTOP_DIR)")
|
||||
install -m 0644 packaging/linux/werk-bundle.xml "$(DATA_DIR)/mime/packages/werk-bundle.xml"
|
||||
@if command -v update-mime-database >/dev/null; then update-mime-database "$(DATA_DIR)/mime"; fi
|
||||
@if command -v update-desktop-database >/dev/null; then update-desktop-database "$(DATA_DIR)/applications"; fi
|
||||
uninstall-cli:
|
||||
rm -f $(BIN_DIR)/pass
|
||||
uninstall-gui:
|
||||
python3 scripts/install-launchers.py --data-dir "$(DATA_DIR)" $(if $(filter-out $(HOME),$(DESKTOP_DIR)),--desktop-dir "$(DESKTOP_DIR)") --uninstall
|
||||
rm -f $(BIN_DIR)/werk
|
||||
rm -rf $(LIB_DIR)
|
||||
package-deb: gui
|
||||
./scripts/package-deb.sh
|
||||
|
||||
package-appimage: gui
|
||||
./scripts/package-appimage.sh
|
||||
@@ -1,94 +1,47 @@
|
||||
<p align="center">
|
||||
<img src="assets/app/readme-banner.png" alt="Pass" width="100%">
|
||||
<img src="fastlane/metadata/android/en-US/images/featureGraphic.png" alt="Werkzeug" width="100%">
|
||||
</p>
|
||||
|
||||
# Werkzeug
|
||||
|
||||
Small, private tools for everyday life. Generate passwords, manage sign-in
|
||||
codes, calculate and keep time in one free, open-source app.
|
||||
|
||||
[Try it online](https://werk.waozi.xyz/)
|
||||
· [Download the latest release](https://github.com/waozixyz/werk/releases/latest)
|
||||
· [What's new](CHANGELOG.md)
|
||||
|
||||
## Your everyday tools
|
||||
|
||||
- **Pass:** generate the same password from your site, login, master password and settings. Save profiles without keeping a password database.
|
||||
- **Auth:** keep two-factor sign-in codes together. Import existing accounts, rename them and copy a code when you need it.
|
||||
- **Calculator:** everyday arithmetic and scientific functions, with a keypad or keyboard.
|
||||
- **Clock:** see the local time and use a stopwatch that keeps running while the app is closed.
|
||||
- **Workbook:** edit spreadsheets on Linux, Android and the web, with formulas, sheet tabs and portable workbook files.
|
||||
|
||||
<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>
|
||||
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/02-pass.png" alt="Pass password generation" width="30%">
|
||||
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/03-auth.png" alt="Auth sign-in codes" width="30%">
|
||||
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/04-calculator.png" alt="Scientific calculator" width="30%">
|
||||
</p>
|
||||
|
||||
# Pass
|
||||
## Make it yours
|
||||
|
||||
Website and browser app: [pass.waozi.xyz](https://pass.waozi.xyz/)
|
||||
Choose light or dark appearance, an accent color and your profile picture.
|
||||
On Linux, open each tool directly from its own application-menu or Desktop
|
||||
shortcut, with its own icon.
|
||||
|
||||
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
|
||||
LessPass project.
|
||||
## Your data and choices
|
||||
|
||||
## Install
|
||||
Password generation and local tools work on your device. Account sync and
|
||||
node connections are optional. Each tool keeps its own private files.
|
||||
|
||||
Prebuilt CLI and desktop downloads are available from
|
||||
[pass.waozi.xyz](https://pass.waozi.xyz/#downloads). To build from a checkout:
|
||||
Werkzeug was formerly Pass. Android keeps the original `xyz.waozi.pass`
|
||||
package and signing certificate so existing Pass installations can update
|
||||
to Werkzeug while keeping their saved data.
|
||||
|
||||
```sh
|
||||
git submodule update --init --recursive
|
||||
make cli
|
||||
```
|
||||
[F-Droid update submission (draft)](https://gitlab.com/fdroid/fdroiddata/-/merge_requests/53909)
|
||||
· [Report a problem](https://github.com/waozixyz/werk/issues)
|
||||
· [Build, command-line tools and data details](docs/development.md)
|
||||
|
||||
## Use
|
||||
|
||||
```text
|
||||
pass [OPTIONS] SITE LOGIN [MASTER_PASSWORD]
|
||||
```
|
||||
|
||||
The default password has 16 characters and includes lowercase letters,
|
||||
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 one line from standard input. Use
|
||||
`--prompt` to bypass the environment and read from standard input. For example:
|
||||
|
||||
```sh
|
||||
pass --prompt example.com alice
|
||||
pass --length 24 --counter 2 example.com alice
|
||||
pass --no-symbols --exclude '0O1Il' example.com alice
|
||||
```
|
||||
|
||||
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 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
|
||||
make gui
|
||||
./build/pass-gui
|
||||
```
|
||||
|
||||
## Android
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Copyright © 2026 Waozi. Distributed under the BSD 3-Clause License. See
|
||||
[`LICENSE`](LICENSE).
|
||||
BSD 3-Clause. See [LICENSE](LICENSE).
|
||||
@@ -1,60 +0,0 @@
|
||||
#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
|
||||
}
|
||||
}
|
||||
@@ -1,404 +0,0 @@
|
||||
#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)
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
#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)
|
||||
}
|
||||
@@ -1,242 +0,0 @@
|
||||
#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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
f6f4eed8f5234c35a7ab2ca0b316c4bbdedf620ecfc22f157b8838c4258934f0
|
||||
@@ -0,0 +1,550 @@
|
||||
// Evaluates calculator expressions: + − × ÷ (also - * /), ^ for powers,
|
||||
// postfix %, ², ³, ! and ⁻¹, unary signs, brackets, the functions sin cos tan
|
||||
// and their inverses (sin⁻¹ or asin) and hyperbolic forms, ln, log, √, ∛,
|
||||
// abs and exp, the constants π, e and Ans, and E for a power of ten, as in
|
||||
// 6.02E23. A number, constant or function next to another multiplies, so
|
||||
// 2π and 3sin(30) work. Brackets left open at the end are closed there.
|
||||
#import "text_buffer"
|
||||
#import "number_text"
|
||||
#import "math"
|
||||
|
||||
Answer :: struct {
|
||||
valid: bool
|
||||
value: float64
|
||||
error: string
|
||||
}
|
||||
|
||||
source: string;
|
||||
position: s32;
|
||||
failure: string;
|
||||
// Trigonometric angles are degrees when set, otherwise radians.
|
||||
degrees: bool;
|
||||
// The last result, for Ans.
|
||||
last_answer: float64;
|
||||
|
||||
PI_VALUE :: 3.141592653589793
|
||||
E_VALUE :: 2.718281828459045
|
||||
|
||||
EvaluateExpression :: (text: string) -> Answer {
|
||||
source = text
|
||||
position = 0
|
||||
failure = ""
|
||||
value := ParseSum()
|
||||
SkipSpaces()
|
||||
if failure == "" && position < cast(s32)source.count {
|
||||
failure = "Cannot read this expression"
|
||||
}
|
||||
if failure == "" && value != value {
|
||||
failure = "Not a real number"
|
||||
}
|
||||
if failure == "" && !Finite(value) {
|
||||
failure = "Result is too large"
|
||||
}
|
||||
if failure != "" {
|
||||
return Answer.{.error = failure}
|
||||
}
|
||||
if value == 0.0 {
|
||||
value = 0.0
|
||||
}
|
||||
return Answer.{.valid = true, .value = value}
|
||||
}
|
||||
|
||||
Finite :: (value: float64) -> bool {
|
||||
return value == value && value < 1.0e300 && value > -1.0e300
|
||||
}
|
||||
|
||||
SkipSpaces :: () {
|
||||
while position < cast(s32)source.count && source[position] == cast(u8)32 {
|
||||
position += 1
|
||||
}
|
||||
}
|
||||
|
||||
// Whether the next text is the given one, consuming it when it is.
|
||||
Take :: (symbol: string) -> bool {
|
||||
SkipSpaces()
|
||||
end := position + cast(s32)symbol.count
|
||||
if end > cast(s32)source.count || source[position:end] != symbol {
|
||||
return false
|
||||
}
|
||||
position = end
|
||||
return true
|
||||
}
|
||||
|
||||
// Whether the next text is the given one, without consuming it.
|
||||
Peek :: (symbol: string) -> bool {
|
||||
SkipSpaces()
|
||||
end := position + cast(s32)symbol.count
|
||||
return end <= cast(s32)source.count && source[position:end] == symbol
|
||||
}
|
||||
|
||||
ParseSum :: () -> float64 {
|
||||
value := ParseProduct()
|
||||
while failure == "" {
|
||||
if Take("+") {
|
||||
value += ParseProduct()
|
||||
} else if Take("-") || Take("−") {
|
||||
value -= ParseProduct()
|
||||
} else {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
ParseProduct :: () -> float64 {
|
||||
value := ParseSigned()
|
||||
while failure == "" {
|
||||
if Take("×") || Take("*") {
|
||||
value *= ParseSigned()
|
||||
} else if Take("÷") || Take("/") {
|
||||
divisor := ParseSigned()
|
||||
if divisor == 0.0 {
|
||||
failure = "Cannot divide by zero"
|
||||
return 0.0
|
||||
}
|
||||
value /= divisor
|
||||
} else if StartsFactor() {
|
||||
value *= ParsePower()
|
||||
} else {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// A factor follows without an operator, so the two multiply.
|
||||
StartsFactor :: () -> bool {
|
||||
SkipSpaces()
|
||||
if position >= cast(s32)source.count {
|
||||
return false
|
||||
}
|
||||
byte := source[position]
|
||||
if IsDigit(byte) || byte == cast(u8)46 || byte == cast(u8)40 {
|
||||
return true
|
||||
}
|
||||
// Letters start functions and constants; E alone is a number's exponent.
|
||||
if byte >= cast(u8)97 && byte <= cast(u8)122 || byte == cast(u8)65 {
|
||||
return true
|
||||
}
|
||||
return Peek("π") || Peek("√") || Peek("∛")
|
||||
}
|
||||
|
||||
ParseSigned :: () -> float64 {
|
||||
if Take("-") || Take("−") {
|
||||
return 0.0 - ParseSigned()
|
||||
}
|
||||
if Take("+") {
|
||||
return ParseSigned()
|
||||
}
|
||||
return ParsePower()
|
||||
}
|
||||
|
||||
ParsePower :: () -> float64 {
|
||||
base := ParsePostfix()
|
||||
if failure == "" && Take("^") {
|
||||
exponent := ParseSigned()
|
||||
return Power(base, exponent)
|
||||
}
|
||||
return base
|
||||
}
|
||||
|
||||
ParsePostfix :: () -> float64 {
|
||||
value := ParseAtom()
|
||||
while failure == "" {
|
||||
if Take("%") {
|
||||
value /= 100.0
|
||||
} else if Take("²") {
|
||||
value *= value
|
||||
} else if Take("³") {
|
||||
value = value * value * value
|
||||
} else if Take("⁻¹") {
|
||||
if value == 0.0 {
|
||||
failure = "Cannot divide by zero"
|
||||
return 0.0
|
||||
}
|
||||
value = 1.0 / value
|
||||
} else if Take("!") {
|
||||
value = Factorial(value)
|
||||
} else {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
ParseAtom :: () -> float64 {
|
||||
if failure != "" {
|
||||
return 0.0
|
||||
}
|
||||
if Take("(") {
|
||||
return Bracketed()
|
||||
}
|
||||
if Take("π") || Take("pi") {
|
||||
return PI_VALUE
|
||||
}
|
||||
if Take("Ans") {
|
||||
return last_answer
|
||||
}
|
||||
if Take("√") || Take("sqrt") {
|
||||
return Root(Argument(), 2)
|
||||
}
|
||||
if Take("∛") || Take("cbrt") {
|
||||
return Root(Argument(), 3)
|
||||
}
|
||||
// Longer names first: sinh⁻¹ before sinh before sin.
|
||||
names: [21]string = .["sinh⁻¹", "cosh⁻¹", "tanh⁻¹", "asinh", "acosh", "atanh",
|
||||
"sin⁻¹", "cos⁻¹", "tan⁻¹", "asin", "acos", "atan",
|
||||
"sinh", "cosh", "tanh", "sin", "cos", "tan", "ln", "log", "abs"]
|
||||
operations: [21]s32 = .[10, 11, 12, 10, 11, 12, 4, 5, 6, 4, 5, 6, 7, 8, 9, 1, 2, 3, 13, 14, 15]
|
||||
index: s32 = 0
|
||||
while index < 21 {
|
||||
if Take(names[index]) {
|
||||
return Apply(operations[index], Argument())
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
if Take("exp") {
|
||||
return Exponential(Argument())
|
||||
}
|
||||
if Take("e") {
|
||||
return E_VALUE
|
||||
}
|
||||
return ParseNumber()
|
||||
}
|
||||
|
||||
Bracketed :: () -> float64 {
|
||||
value := ParseSum()
|
||||
// A bracket still open at the end closes there.
|
||||
SkipSpaces()
|
||||
if !Take(")") && position < cast(s32)source.count && failure == "" {
|
||||
failure = "Missing closing bracket"
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// A function's argument: a bracketed expression, or the signed value that
|
||||
// follows, as in √9 or sin 30.
|
||||
Argument :: () -> float64 {
|
||||
if Take("(") {
|
||||
return Bracketed()
|
||||
}
|
||||
return ParseSigned()
|
||||
}
|
||||
|
||||
Apply :: (operation: s32, value: float64) -> float64 {
|
||||
if failure != "" {
|
||||
return 0.0
|
||||
}
|
||||
if operation == 1 {
|
||||
return Sine(value)
|
||||
}
|
||||
if operation == 2 {
|
||||
return Cosine(value)
|
||||
}
|
||||
if operation == 3 {
|
||||
return Tangent(value)
|
||||
}
|
||||
if operation >= 4 && operation <= 6 {
|
||||
if operation != 6 && (value > 1.0 || value < -1.0) {
|
||||
failure = "Not a real number"
|
||||
return 0.0
|
||||
}
|
||||
angle := ifx operation == 4 then Asin(value) else ifx operation == 5 then Acos(value) else Atan(value)
|
||||
return ifx degrees then angle * 180.0 / PI_VALUE else angle
|
||||
}
|
||||
if operation == 7 {
|
||||
return Sinh(value)
|
||||
}
|
||||
if operation == 8 {
|
||||
return Cosh(value)
|
||||
}
|
||||
if operation == 9 {
|
||||
return Tanh(value)
|
||||
}
|
||||
if operation == 10 {
|
||||
return Asinh(value)
|
||||
}
|
||||
if operation == 11 {
|
||||
return Checked(Acosh(value))
|
||||
}
|
||||
if operation == 12 {
|
||||
if value >= 1.0 || value <= -1.0 {
|
||||
failure = ifx value == 1.0 || value == -1.0 then "Result is too large" else "Not a real number"
|
||||
return 0.0
|
||||
}
|
||||
return Atanh(value)
|
||||
}
|
||||
if operation == 13 || operation == 14 {
|
||||
if value <= 0.0 {
|
||||
failure = ifx value == 0.0 then "Result is too large" else "Not a real number"
|
||||
return 0.0
|
||||
}
|
||||
return ifx operation == 13 then Log(value) else Log10Exact(value)
|
||||
}
|
||||
return ifx value < 0.0 then 0.0 - value else value
|
||||
}
|
||||
|
||||
// A NaN from a function outside its domain is an error, not a value.
|
||||
Checked :: (value: float64) -> float64 {
|
||||
if value != value && failure == "" {
|
||||
failure = "Not a real number"
|
||||
return 0.0
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// log10 exactly for powers of ten, which people expect to be whole.
|
||||
Log10Exact :: (value: float64) -> float64 {
|
||||
result := Log10(value)
|
||||
nearest := cast(float64)RoundToInteger(result)
|
||||
if nearest - result < 1.0e-12 && result - nearest < 1.0e-12 && Power(10.0, nearest) == value {
|
||||
return nearest
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// An angle in degrees, reduced to [0, 360).
|
||||
Degrees360 :: (value: float64) -> float64 {
|
||||
turns := cast(float64)RoundToInteger(value / 360.0)
|
||||
reduced := value - turns * 360.0
|
||||
if reduced < 0.0 {
|
||||
reduced += 360.0
|
||||
}
|
||||
return reduced
|
||||
}
|
||||
|
||||
Radians :: (value: float64) -> float64 {
|
||||
return ifx degrees then value * PI_VALUE / 180.0 else value
|
||||
}
|
||||
|
||||
// In degrees, whole quarter turns give exact results: sin 180° is 0.
|
||||
Sine :: (value: float64) -> float64 {
|
||||
if degrees && value < 1.0e15 && value > -1.0e15 {
|
||||
reduced := Degrees360(value)
|
||||
if reduced == 0.0 || reduced == 180.0 {
|
||||
return 0.0
|
||||
}
|
||||
if reduced == 90.0 {
|
||||
return 1.0
|
||||
}
|
||||
if reduced == 270.0 {
|
||||
return -1.0
|
||||
}
|
||||
if reduced == 30.0 || reduced == 150.0 {
|
||||
return 0.5
|
||||
}
|
||||
if reduced == 210.0 || reduced == 330.0 {
|
||||
return -0.5
|
||||
}
|
||||
}
|
||||
return Sin(Radians(value))
|
||||
}
|
||||
|
||||
Cosine :: (value: float64) -> float64 {
|
||||
if degrees && value < 1.0e15 && value > -1.0e15 {
|
||||
reduced := Degrees360(value)
|
||||
if reduced == 90.0 || reduced == 270.0 {
|
||||
return 0.0
|
||||
}
|
||||
if reduced == 0.0 {
|
||||
return 1.0
|
||||
}
|
||||
if reduced == 180.0 {
|
||||
return -1.0
|
||||
}
|
||||
if reduced == 60.0 || reduced == 300.0 {
|
||||
return 0.5
|
||||
}
|
||||
if reduced == 120.0 || reduced == 240.0 {
|
||||
return -0.5
|
||||
}
|
||||
}
|
||||
return Cos(Radians(value))
|
||||
}
|
||||
|
||||
Tangent :: (value: float64) -> float64 {
|
||||
if degrees && value < 1.0e15 && value > -1.0e15 {
|
||||
reduced := Degrees360(value)
|
||||
if reduced == 90.0 || reduced == 270.0 {
|
||||
failure = "Undefined"
|
||||
return 0.0
|
||||
}
|
||||
if reduced == 0.0 || reduced == 180.0 {
|
||||
return 0.0
|
||||
}
|
||||
if reduced == 45.0 || reduced == 225.0 {
|
||||
return 1.0
|
||||
}
|
||||
if reduced == 135.0 || reduced == 315.0 {
|
||||
return -1.0
|
||||
}
|
||||
}
|
||||
return Tan(Radians(value))
|
||||
}
|
||||
|
||||
Root :: (value: float64, degree: s32) -> float64 {
|
||||
if failure != "" {
|
||||
return 0.0
|
||||
}
|
||||
if degree == 2 {
|
||||
if value < 0.0 {
|
||||
failure = "Not a real number"
|
||||
return 0.0
|
||||
}
|
||||
return Sqrt(value)
|
||||
}
|
||||
return Cbrt(value)
|
||||
}
|
||||
|
||||
Exponential :: (value: float64) -> float64 {
|
||||
if failure != "" {
|
||||
return 0.0
|
||||
}
|
||||
return Exp(value)
|
||||
}
|
||||
|
||||
Factorial :: (value: float64) -> float64 {
|
||||
whole := RoundToInteger(value)
|
||||
if value < 0.0 || cast(float64)whole != value {
|
||||
failure = "Factorial needs a whole number"
|
||||
return 0.0
|
||||
}
|
||||
if whole > 170 {
|
||||
failure = "Result is too large"
|
||||
return 0.0
|
||||
}
|
||||
result: float64 = 1.0
|
||||
factor: s64 = 2
|
||||
while factor <= whole {
|
||||
result *= cast(float64)factor
|
||||
factor += 1
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
ParseNumber :: () -> float64 {
|
||||
SkipSpaces()
|
||||
value: float64 = 0.0
|
||||
digits: s32 = 0
|
||||
while position < cast(s32)source.count && IsDigit(source[position]) {
|
||||
value = value * 10.0 + cast(float64)(source[position] - cast(u8)48)
|
||||
position += 1
|
||||
digits += 1
|
||||
}
|
||||
if position < cast(s32)source.count && source[position] == cast(u8)46 {
|
||||
position += 1
|
||||
scale: float64 = 0.1
|
||||
while position < cast(s32)source.count && IsDigit(source[position]) {
|
||||
value += cast(float64)(source[position] - cast(u8)48) * scale
|
||||
scale /= 10.0
|
||||
position += 1
|
||||
digits += 1
|
||||
}
|
||||
}
|
||||
if digits == 0 {
|
||||
failure = ifx position >= cast(s32)source.count then "Incomplete expression" else "Cannot read this expression"
|
||||
return value
|
||||
}
|
||||
// E and a whole power of ten: 6.02E23, 1E−5.
|
||||
if position < cast(s32)source.count && source[position] == cast(u8)69 {
|
||||
position += 1
|
||||
negative := false
|
||||
if Take("-") || Take("−") {
|
||||
negative = true
|
||||
} else {
|
||||
unused Take("+")
|
||||
}
|
||||
power: s64 = 0
|
||||
power_digits: s32 = 0
|
||||
while position < cast(s32)source.count && IsDigit(source[position]) && power < 100000 {
|
||||
power = power * 10 + cast(s64)(source[position] - cast(u8)48)
|
||||
position += 1
|
||||
power_digits += 1
|
||||
}
|
||||
if power_digits == 0 {
|
||||
failure = ifx position >= cast(s32)source.count then "Incomplete expression" else "Cannot read this expression"
|
||||
return value
|
||||
}
|
||||
value *= Power(10.0, cast(float64)(ifx negative then 0 - power else power))
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
IsDigit :: (byte: u8) -> bool {
|
||||
return byte >= cast(u8)48 && byte <= cast(u8)57
|
||||
}
|
||||
|
||||
// Whole exponents multiply exactly; others use the real power, which a
|
||||
// negative base does not have.
|
||||
Power :: (base: float64, exponent: float64) -> float64 {
|
||||
if failure != "" {
|
||||
return 0.0
|
||||
}
|
||||
if base == 0.0 && exponent < 0.0 {
|
||||
failure = "Cannot divide by zero"
|
||||
return 0.0
|
||||
}
|
||||
whole := cast(float64)RoundToInteger(exponent) == exponent && exponent < 1.0e15 && exponent > -1.0e15
|
||||
if base < 0.0 && !whole {
|
||||
failure = "Not a real number"
|
||||
return 0.0
|
||||
}
|
||||
return Pow(base, exponent)
|
||||
}
|
||||
|
||||
// Up to ten significant digits; very large and very small numbers use an
|
||||
// exponent, such as 1.5e20.
|
||||
FormatNumber :: (value: float64, output: []u8) -> string {
|
||||
magnitude := ifx value < 0.0 then 0.0 - value else value
|
||||
if magnitude != 0.0 && (magnitude >= 1.0e15 || magnitude < 1.0e-9) {
|
||||
return FormatExponent(value, output)
|
||||
}
|
||||
whole_digits: s32 = 1
|
||||
bound: float64 = 10.0
|
||||
while magnitude >= bound && whole_digits < 15 {
|
||||
bound *= 10.0
|
||||
whole_digits += 1
|
||||
}
|
||||
places := 10 - whole_digits
|
||||
if places < 0 {
|
||||
places = 0
|
||||
}
|
||||
if places > 9 {
|
||||
places = 9
|
||||
}
|
||||
return FormatDecimal(value, places, output)
|
||||
}
|
||||
|
||||
FormatExponent :: (value: float64, output: []u8) -> string {
|
||||
negative := value < 0.0
|
||||
mantissa := ifx negative then 0.0 - value else value
|
||||
exponent: s32 = 0
|
||||
while mantissa >= 10.0 {
|
||||
mantissa /= 10.0
|
||||
exponent += 1
|
||||
}
|
||||
while mantissa < 1.0 {
|
||||
mantissa *= 10.0
|
||||
exponent -= 1
|
||||
}
|
||||
digits: [32]u8
|
||||
text := FormatDecimal(ifx negative then 0.0 - mantissa else mantissa, 9, digits[:])
|
||||
power: [24]u8
|
||||
exponent_text := FormatInteger(cast(s64)exponent, power[:])
|
||||
used: s32 = 0
|
||||
used = AppendTo(output, used, text)
|
||||
used = AppendTo(output, used, "e")
|
||||
used = AppendTo(output, used, exponent_text)
|
||||
return TextView(output[0:used])
|
||||
}
|
||||
|
||||
AppendTo :: (output: []u8, used: s32, text: string) -> s32 {
|
||||
index: s32 = 0
|
||||
while index < cast(s32)text.count && used < cast(s32)output.count - 1 {
|
||||
output[used] = text[index]
|
||||
used += 1
|
||||
index += 1
|
||||
}
|
||||
output[used] = cast(u8)0
|
||||
return used
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// The Calculator's expressions and number formatting.
|
||||
#import "arithmetic"
|
||||
|
||||
Shows :: (expression: string, expected: string) -> bool {
|
||||
answer := EvaluateExpression(expression)
|
||||
if !answer.valid {
|
||||
return false
|
||||
}
|
||||
output: [64]u8
|
||||
return FormatNumber(answer.value, output[:]) == expected
|
||||
}
|
||||
|
||||
Refuses :: (expression: string) -> bool {
|
||||
return !EvaluateExpression(expression).valid
|
||||
}
|
||||
|
||||
#program_export
|
||||
Run :: () -> s32 {
|
||||
degrees = false
|
||||
if !Shows("12+30×2", "72") || !Shows("12+30*2", "72") || !Shows("(1+2)×3", "9") {
|
||||
return 1
|
||||
}
|
||||
if !Shows("7÷2", "3.5") || !Shows("1÷3", "0.333333333") || !Shows("2^10", "1024") {
|
||||
return 2
|
||||
}
|
||||
if !Shows("50%", "0.5") || !Shows("−4+1", "-3") || !Shows("2×(3+4", "14") {
|
||||
return 3
|
||||
}
|
||||
if !Shows("0.1+0.2", "0.3") || !Shows("10^20", "1e20") || !Shows("2^-2", "0.25") {
|
||||
return 4
|
||||
}
|
||||
if !Refuses("1÷0") || !Refuses("3+") || !Refuses("4)") || !Refuses("(−8)^0.5") {
|
||||
return 5
|
||||
}
|
||||
// Powers, roots and logarithms.
|
||||
if !Shows("2^0.5", "1.414213562") || !Shows("√144", "12") || !Shows("√(2)", "1.414213562") ||
|
||||
!Shows("∛27", "3") || !Shows("∛(−8)", "-2") || !Shows("3²", "9") || !Shows("2³", "8") {
|
||||
return 6
|
||||
}
|
||||
if !Shows("ln(e)", "1") || !Shows("log(1000)", "3") || !Shows("e^(2)", "7.389056099") ||
|
||||
!Shows("10^(3)", "1000") || !Shows("exp(1)", "2.718281828") || !Refuses("ln(−1)") || !Refuses("√(−4)") {
|
||||
return 7
|
||||
}
|
||||
// Factorials, reciprocals, constants, Ans and E notation.
|
||||
if !Shows("5!", "120") || !Shows("0!", "1") || !Shows("4⁻¹", "0.25") || !Shows("2π", "6.283185307") ||
|
||||
!Shows("π", "3.141592654") || !Refuses("2.5!") || !Refuses("171!") || !Refuses("0⁻¹") {
|
||||
return 8
|
||||
}
|
||||
last_answer = 21.0
|
||||
if !Shows("Ans×2", "42") || !Shows("6.02E23", "6.02e23") || !Shows("1E−3", "0.001") || !Shows("2(3+4)", "14") ||
|
||||
!Shows("abs(−7)", "7") || !Shows("3sqrt(16)", "12") {
|
||||
return 9
|
||||
}
|
||||
// Radians.
|
||||
if !Shows("sin(π÷2)", "1") || !Shows("cos(0)", "1") || !Shows("tan(π÷4)", "1") ||
|
||||
!Shows("sin⁻¹(1)", "1.570796327") || !Shows("atan(1)×4", "3.141592654") {
|
||||
return 10
|
||||
}
|
||||
// Degrees, with exact quarter turns.
|
||||
degrees = true
|
||||
if !Shows("sin(30)", "0.5") || !Shows("sin(180)", "0") || !Shows("cos(90)", "0") || !Shows("cos(−60)", "0.5") ||
|
||||
!Shows("tan(45)", "1") || !Refuses("tan(90)") || !Shows("sin(390)", "0.5") || !Shows("sin 30 + 1", "1.5") {
|
||||
return 11
|
||||
}
|
||||
if !Shows("sin⁻¹(0.5)", "30") || !Shows("cos⁻¹(0)", "90") || !Shows("tan⁻¹(1)", "45") || !Refuses("asin(2)") {
|
||||
return 12
|
||||
}
|
||||
degrees = false
|
||||
// Hyperbolic functions and their inverses.
|
||||
if !Shows("sinh(1)", "1.175201194") || !Shows("cosh(0)", "1") || !Shows("tanh(1)", "0.761594156") ||
|
||||
!Shows("sinh⁻¹(1)", "0.881373587") || !Shows("cosh⁻¹(2)", "1.316957897") ||
|
||||
!Shows("tanh⁻¹(0.5)", "0.549306144") || !Refuses("acosh(0.5)") || !Refuses("atanh(1)") {
|
||||
return 13
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,460 @@
|
||||
// Calculator: a keypad and keyboard calculator. Basic covers ordinary
|
||||
// arithmetic with brackets; Scientific adds trigonometry in degrees or
|
||||
// radians, hyperbolic functions, powers, roots, logarithms, factorials and
|
||||
// constants. It keeps the expression in memory; the mode and angle unit are
|
||||
// saved.
|
||||
#import "session"
|
||||
#import "geometry"
|
||||
#import "text_props"
|
||||
#import "text_align"
|
||||
#import "text_widget"
|
||||
#import "button_props"
|
||||
#import "button_widget"
|
||||
#import "control_props"
|
||||
#import "box_props"
|
||||
#import "box_widget"
|
||||
#import "text_buffer"
|
||||
#import "number_text"
|
||||
#import "kryon/app_context"
|
||||
#import "kryon/app_protocol"
|
||||
#import "arithmetic"
|
||||
Icon :: #import "mingcute_regular_counter";
|
||||
DeleteBack :: #import "mingcute_regular_delete_back";
|
||||
|
||||
using ButtonTone;
|
||||
using ButtonEmphasis;
|
||||
|
||||
EXPRESSION_LIMIT :: 256
|
||||
|
||||
expression: [EXPRESSION_LIMIT]u8;
|
||||
expression_length: s32;
|
||||
result_text: [64]u8;
|
||||
// The expression shows the last result, which typing a number replaces.
|
||||
showing_result: bool;
|
||||
loaded: bool;
|
||||
scientific: bool;
|
||||
// One-shot shifts for the next scientific function key.
|
||||
second: bool;
|
||||
hyperbolic: bool;
|
||||
|
||||
ExpressionText :: () -> string {
|
||||
return TextView(expression[0:expression_length])
|
||||
}
|
||||
|
||||
Clear :: () {
|
||||
expression_length = 0
|
||||
result_text[0] = cast(u8)0
|
||||
showing_result = false
|
||||
}
|
||||
|
||||
// Whether text begins a new value rather than continuing the last one: a
|
||||
// result is replaced by a number, constant or function, and continued by
|
||||
// an operator.
|
||||
StartsValue :: (text: string) -> bool {
|
||||
first := text[0]
|
||||
if first >= cast(u8)48 && first <= cast(u8)57 || first == cast(u8)46 || first == cast(u8)40 {
|
||||
return true
|
||||
}
|
||||
if first >= cast(u8)97 && first <= cast(u8)122 || first == cast(u8)65 {
|
||||
return true
|
||||
}
|
||||
count := cast(s32)text.count
|
||||
return count >= 2 && text[0:2] == "π" || count >= 3 && (text[0:3] == "√" || text[0:3] == "∛")
|
||||
}
|
||||
|
||||
Append :: (text: string) {
|
||||
if text.count == 0 {
|
||||
return
|
||||
}
|
||||
if showing_result && StartsValue(text) {
|
||||
expression_length = 0
|
||||
}
|
||||
showing_result = false
|
||||
result_text[0] = cast(u8)0
|
||||
if expression_length + cast(s32)text.count > EXPRESSION_LIMIT {
|
||||
return
|
||||
}
|
||||
index: s32 = 0
|
||||
while index < cast(s32)text.count {
|
||||
expression[expression_length] = text[index]
|
||||
expression_length += 1
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
|
||||
Backspace :: () {
|
||||
showing_result = false
|
||||
result_text[0] = cast(u8)0
|
||||
if expression_length == 0 {
|
||||
return
|
||||
}
|
||||
expression_length -= 1
|
||||
// Remove a whole UTF-8 sequence, such as the multiplication sign.
|
||||
while expression_length > 0 && (expression[expression_length] & cast(u8)0xC0) == cast(u8)0x80 {
|
||||
expression_length -= 1
|
||||
}
|
||||
}
|
||||
|
||||
Evaluate :: () {
|
||||
if expression_length == 0 {
|
||||
return
|
||||
}
|
||||
answer := EvaluateExpression(ExpressionText())
|
||||
if !answer.valid {
|
||||
CopyResult(answer.error)
|
||||
return
|
||||
}
|
||||
last_answer = answer.value
|
||||
formatted: [64]u8
|
||||
text := FormatNumber(answer.value, formatted[:])
|
||||
expression_length = 0
|
||||
Append(text)
|
||||
showing_result = true
|
||||
result_text[0] = cast(u8)0
|
||||
}
|
||||
|
||||
CopyResult :: (text: string) {
|
||||
index: s32 = 0
|
||||
while index < cast(s32)text.count && index < 63 {
|
||||
result_text[index] = text[index]
|
||||
index += 1
|
||||
}
|
||||
result_text[index] = cast(u8)0
|
||||
}
|
||||
|
||||
// calculator.txt holds "scientific degrees" as 0 or 1 each.
|
||||
LoadSettings :: () {
|
||||
buffer: [16]u8
|
||||
count := ReadStore("calculator.txt", buffer[:])
|
||||
if count >= 3 {
|
||||
scientific = buffer[0] == cast(u8)49
|
||||
degrees = buffer[2] == cast(u8)49
|
||||
} else {
|
||||
degrees = true
|
||||
}
|
||||
}
|
||||
|
||||
SaveSettings :: () {
|
||||
buffer: [3]u8
|
||||
buffer[0] = cast(u8)(ifx scientific then 49 else 48)
|
||||
buffer[1] = cast(u8)32
|
||||
buffer[2] = cast(u8)(ifx degrees then 49 else 48)
|
||||
unused WriteStore("calculator.txt", TextView(buffer[0:3]))
|
||||
}
|
||||
|
||||
// Typed characters and keys act like the keypad; letters spell functions
|
||||
// such as sin and sqrt.
|
||||
Keyboard :: () {
|
||||
key := AppKey()
|
||||
typed := AppFieldInput().text
|
||||
index: s32 = 0
|
||||
while index < cast(s32)typed.count {
|
||||
byte := typed[index]
|
||||
if byte >= cast(u8)48 && byte <= cast(u8)57 || byte == cast(u8)46 || byte == cast(u8)40 ||
|
||||
byte == cast(u8)41 || byte == cast(u8)43 || byte == cast(u8)45 || byte == cast(u8)37 ||
|
||||
byte == cast(u8)94 || byte == cast(u8)33 || byte >= cast(u8)97 && byte <= cast(u8)122 ||
|
||||
byte >= cast(u8)65 && byte <= cast(u8)90 {
|
||||
Append(typed[index:index + 1])
|
||||
}
|
||||
if byte == cast(u8)42 {
|
||||
Append("×")
|
||||
}
|
||||
if byte == cast(u8)47 {
|
||||
Append("÷")
|
||||
}
|
||||
if byte == cast(u8)44 {
|
||||
Append(".")
|
||||
}
|
||||
if byte == cast(u8)61 {
|
||||
Evaluate()
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
// Text queued before a command key belongs to the expression it acts on.
|
||||
if key == 257 || key == 335 {
|
||||
Evaluate()
|
||||
}
|
||||
if key == 259 {
|
||||
Backspace()
|
||||
}
|
||||
if key == 256 {
|
||||
Clear()
|
||||
}
|
||||
}
|
||||
|
||||
ACTION_INSERT :: 0
|
||||
ACTION_CLEAR :: 1
|
||||
ACTION_DELETE :: 2
|
||||
ACTION_EVALUATE :: 3
|
||||
ACTION_SECOND :: 4
|
||||
ACTION_HYPERBOLIC :: 5
|
||||
ACTION_NEGATE :: 6
|
||||
|
||||
Key :: struct {
|
||||
label: string
|
||||
input: string
|
||||
action: s32
|
||||
accent: bool
|
||||
// A function key whose 2nd or hyp shift is used up when pressed.
|
||||
shifted: bool
|
||||
}
|
||||
|
||||
BASIC_KEYS :: 20
|
||||
|
||||
BasicKey :: (index: s32) -> Key {
|
||||
labels: [BASIC_KEYS]string = .["C", "(", ")", "÷",
|
||||
"7", "8", "9", "×",
|
||||
"4", "5", "6", "−",
|
||||
"1", "2", "3", "+",
|
||||
"", "0", ".", "="]
|
||||
inputs: [BASIC_KEYS]string = .["", "(", ")", "÷",
|
||||
"7", "8", "9", "×",
|
||||
"4", "5", "6", "-",
|
||||
"1", "2", "3", "+",
|
||||
"", "0", ".", ""]
|
||||
key := Key.{.label = labels[index], .input = inputs[index]}
|
||||
if index == 0 {
|
||||
key.action = ACTION_CLEAR
|
||||
}
|
||||
if index == 16 {
|
||||
key.action = ACTION_DELETE
|
||||
}
|
||||
if index == 19 {
|
||||
key.action = ACTION_EVALUATE
|
||||
key.accent = true
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
// Eight rows of five; = spans the last two columns.
|
||||
SCIENTIFIC_KEYS :: 39
|
||||
|
||||
ScientificKey :: (index: s32) -> Key {
|
||||
labels: [SCIENTIFIC_KEYS]string = .["2nd", "hyp", "sin", "cos", "tan",
|
||||
"x²", "xʸ", "√x", "ln", "log",
|
||||
"(", ")", "1/x", "n!", "π",
|
||||
"C", "", "%", "÷", "e",
|
||||
"7", "8", "9", "×", "EE",
|
||||
"4", "5", "6", "−", "Ans",
|
||||
"1", "2", "3", "+", "|x|",
|
||||
"±", "0", ".", "="]
|
||||
inputs: [SCIENTIFIC_KEYS]string = .["", "", "", "", "",
|
||||
"²", "^", "√(", "ln(", "log(",
|
||||
"(", ")", "⁻¹", "!", "π",
|
||||
"", "", "%", "÷", "e",
|
||||
"7", "8", "9", "×", "E",
|
||||
"4", "5", "6", "-", "Ans",
|
||||
"1", "2", "3", "+", "abs(",
|
||||
"", "0", ".", ""]
|
||||
key := Key.{.label = labels[index], .input = inputs[index]}
|
||||
if index == 0 {
|
||||
key.action = ACTION_SECOND
|
||||
key.accent = second
|
||||
}
|
||||
if index == 1 {
|
||||
key.action = ACTION_HYPERBOLIC
|
||||
key.accent = hyperbolic
|
||||
}
|
||||
if index >= 2 && index <= 4 {
|
||||
names: [3]string = .["sin", "cos", "tan"]
|
||||
hyperbolic_names: [3]string = .["sinh", "cosh", "tanh"]
|
||||
inverse_names: [3]string = .["sin⁻¹", "cos⁻¹", "tan⁻¹"]
|
||||
inverse_hyperbolic_names: [3]string = .["sinh⁻¹", "cosh⁻¹", "tanh⁻¹"]
|
||||
name := names[index - 2]
|
||||
if hyperbolic {
|
||||
name = ifx second then inverse_hyperbolic_names[index - 2] else hyperbolic_names[index - 2]
|
||||
} else if second {
|
||||
name = inverse_names[index - 2]
|
||||
}
|
||||
key.label = name
|
||||
key.shifted = true
|
||||
}
|
||||
if second {
|
||||
if index == 5 {
|
||||
key.label = "x³"
|
||||
key.input = "³"
|
||||
}
|
||||
if index == 6 {
|
||||
key.label = "ʸ√x"
|
||||
key.input = "^(1÷"
|
||||
}
|
||||
if index == 7 {
|
||||
key.label = "∛x"
|
||||
key.input = "∛("
|
||||
}
|
||||
if index == 8 {
|
||||
key.label = "eˣ"
|
||||
key.input = "e^("
|
||||
}
|
||||
if index == 9 {
|
||||
key.label = "10ˣ"
|
||||
key.input = "10^("
|
||||
}
|
||||
}
|
||||
if index >= 5 && index <= 9 {
|
||||
key.shifted = true
|
||||
}
|
||||
if index == 15 {
|
||||
key.action = ACTION_CLEAR
|
||||
}
|
||||
if index == 16 {
|
||||
key.action = ACTION_DELETE
|
||||
}
|
||||
if index == 35 {
|
||||
key.action = ACTION_NEGATE
|
||||
}
|
||||
if index == 38 {
|
||||
key.action = ACTION_EVALUATE
|
||||
key.accent = true
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
Press :: (key: Key) {
|
||||
if key.action == ACTION_CLEAR {
|
||||
Clear()
|
||||
} else if key.action == ACTION_DELETE {
|
||||
Backspace()
|
||||
} else if key.action == ACTION_EVALUATE {
|
||||
Evaluate()
|
||||
} else if key.action == ACTION_SECOND {
|
||||
second = !second
|
||||
} else if key.action == ACTION_HYPERBOLIC {
|
||||
hyperbolic = !hyperbolic
|
||||
} else if key.action == ACTION_NEGATE {
|
||||
Append("−")
|
||||
} else if key.input != "" {
|
||||
Append(key.input)
|
||||
} else {
|
||||
// A trigonometric key: its name and an opening bracket.
|
||||
text: [24]u8
|
||||
used: s32 = AppendTo(text[:], 0, key.label)
|
||||
used = AppendTo(text[:], used, "(")
|
||||
Append(TextView(text[0:used]))
|
||||
}
|
||||
if key.shifted {
|
||||
second = false
|
||||
hyperbolic = false
|
||||
}
|
||||
}
|
||||
|
||||
Tab :: (session: Session, id: s32, label: string, bounds: Rectangle, active: bool) -> bool {
|
||||
props := ButtonProps.{.key = cast(u64)id, .id = id, .bounds = bounds, .label = label,
|
||||
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisSoft}
|
||||
if active {
|
||||
props.tone = ButtonTone.ButtonToneAccent
|
||||
props.emphasis = ButtonEmphasis.ButtonEmphasisFilled
|
||||
}
|
||||
return Button(session, props) != 0
|
||||
}
|
||||
|
||||
DrawKey :: (session: Session, index: s32, key: Key, bounds: Rectangle) {
|
||||
props := ButtonProps.{.key = cast(u64)(100 + index), .id = 100 + index, .bounds = bounds,
|
||||
.label = key.label,
|
||||
.tone = cast(ButtonTone)(ifx key.accent then ButtonToneAccent else ButtonToneNeutral),
|
||||
.emphasis = cast(ButtonEmphasis)(ifx key.accent then ButtonEmphasisFilled else ButtonEmphasisSoft)}
|
||||
// Delete is an icon on a key as wide as the others.
|
||||
if key.action == ACTION_DELETE {
|
||||
props.icon_shape = DeleteBack.Shape
|
||||
props.label = ""
|
||||
}
|
||||
if Button(session, props) != 0 {
|
||||
Press(key)
|
||||
}
|
||||
}
|
||||
|
||||
Draw :: () {
|
||||
session := AppSession()
|
||||
area := AppBounds()
|
||||
gap: float32 = 8.0
|
||||
width := area.width - 32.0
|
||||
if width > 460.0 {
|
||||
width = 460.0
|
||||
}
|
||||
left := area.x + (area.width - width) * 0.5
|
||||
top := area.y + 12.0
|
||||
half := (width - gap) / 2.0
|
||||
if Tab(session, 1, "Basic", Rectangle.{left, top, half, 36.0}, !scientific) && scientific {
|
||||
scientific = false
|
||||
SaveSettings()
|
||||
}
|
||||
if Tab(session, 2, "Scientific", Rectangle.{left + half + gap, top, half, 36.0}, scientific) && !scientific {
|
||||
scientific = true
|
||||
SaveSettings()
|
||||
}
|
||||
top += 36.0 + gap
|
||||
display_height: float32 = ifx scientific then 104.0 else 112.0
|
||||
display := Rectangle.{left, top, width, display_height}
|
||||
Box(session, BoxProps.{.key = cast(u64)3, .bounds = display, .radius = 12.0})
|
||||
shown := ExpressionText()
|
||||
if shown == "" {
|
||||
shown = "0"
|
||||
}
|
||||
font: s32 = 32
|
||||
if shown.count > 18 {
|
||||
font = 24
|
||||
}
|
||||
if shown.count > 28 {
|
||||
font = 18
|
||||
}
|
||||
Text(session, TextProps.{.key = cast(u64)4,
|
||||
.bounds = Rectangle.{left + 16.0, top + 14.0, width - 32.0, 48.0},
|
||||
.text = shown, .font = font, .align = TextAlign.TextAlignEnd, .wrap = TextWrap.TextWrapEllipsis})
|
||||
Text(session, TextProps.{.key = cast(u64)5,
|
||||
.bounds = Rectangle.{left + 16.0, top + display_height - 36.0, width - 32.0, 24.0},
|
||||
.text = TextUntilNul(result_text[:]), .font = 16, .align = TextAlign.TextAlignEnd})
|
||||
if scientific {
|
||||
// The angle unit, switched by tapping it.
|
||||
unit := ButtonProps.{.key = cast(u64)6, .id = 6, .bounds = Rectangle.{left + 10.0, top + display_height - 38.0, 64.0, 28.0},
|
||||
.label = ifx degrees then "DEG" else "RAD", .size = ControlSize.ControlSizeSmall,
|
||||
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisSoft}
|
||||
if Button(session, unit) != 0 {
|
||||
degrees = !degrees
|
||||
SaveSettings()
|
||||
}
|
||||
}
|
||||
pad_top := top + display_height + gap * 2.0
|
||||
columns: s32 = ifx scientific then 5 else 4
|
||||
rows: s32 = ifx scientific then 8 else 5
|
||||
key_width := (width - gap * cast(float32)(columns - 1)) / cast(float32)columns
|
||||
key_height := (area.y + area.height - 16.0 - pad_top - gap * cast(float32)(rows - 1)) / cast(float32)rows
|
||||
if key_height > 72.0 {
|
||||
key_height = 72.0
|
||||
}
|
||||
if key_height < 34.0 {
|
||||
key_height = 34.0
|
||||
}
|
||||
count: s32 = ifx scientific then SCIENTIFIC_KEYS else BASIC_KEYS
|
||||
index: s32 = 0
|
||||
while index < count {
|
||||
key := ifx scientific then ScientificKey(index) else BasicKey(index)
|
||||
column := cast(float32)(index % columns)
|
||||
row := cast(float32)(index / columns)
|
||||
bounds := Rectangle.{left + column * (key_width + gap), pad_top + row * (key_height + gap),
|
||||
key_width, key_height}
|
||||
if scientific && index == SCIENTIFIC_KEYS - 1 {
|
||||
bounds.width = key_width * 2.0 + gap
|
||||
}
|
||||
DrawKey(session, index, key, bounds)
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
|
||||
#program_export "CalculatorMain"
|
||||
Main :: () -> s32 {
|
||||
if AppMode() == APP_IDENTIFY {
|
||||
AppIdentity("calculator")
|
||||
AppDescribe("Calculator", Icon.Shape)
|
||||
return APP_PROTOCOL
|
||||
}
|
||||
if AppMode() != APP_FRAME {
|
||||
return 0
|
||||
}
|
||||
if !loaded {
|
||||
LoadSettings()
|
||||
loaded = true
|
||||
}
|
||||
Keyboard()
|
||||
Draw()
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
// Clock: the local time and date, and a stopwatch that keeps running while
|
||||
// the app is closed.
|
||||
#import "session"
|
||||
#import "geometry"
|
||||
#import "text_props"
|
||||
#import "text_align"
|
||||
#import "text_widget"
|
||||
#import "button_props"
|
||||
#import "button_widget"
|
||||
#import "control_props"
|
||||
#import "text_buffer"
|
||||
#import "number_text"
|
||||
#import "kryon/app_context"
|
||||
#import "kryon/app_protocol"
|
||||
Icon :: #import "mingcute_regular_time";
|
||||
|
||||
VIEW_CLOCK :: 0
|
||||
VIEW_STOPWATCH :: 1
|
||||
|
||||
Civil :: struct {
|
||||
year: s64
|
||||
month: s32
|
||||
day: s32
|
||||
weekday: s32
|
||||
}
|
||||
|
||||
view: s32;
|
||||
loaded: bool;
|
||||
running: bool;
|
||||
// While running, the wall time it started from; the time counted before
|
||||
// that start is in elapsed.
|
||||
started_at: float64;
|
||||
elapsed: float64;
|
||||
session: Session;
|
||||
local_offset: s32;
|
||||
local_offset_read_at: float64 = -61.0;
|
||||
|
||||
// The civil date of a day count since 1970-01-01 (proleptic Gregorian).
|
||||
CivilFromDays :: (days: s64) -> Civil {
|
||||
shifted := days + 719468
|
||||
era := ifx shifted >= 0 then shifted / 146097 else (shifted - 146096) / 146097
|
||||
day_of_era := shifted - era * 146097
|
||||
year_of_era := (day_of_era - day_of_era / 1460 + day_of_era / 36524 - day_of_era / 146096) / 365
|
||||
day_of_year := day_of_era - (365 * year_of_era + year_of_era / 4 - year_of_era / 100)
|
||||
month_index := (5 * day_of_year + 2) / 153
|
||||
result: Civil
|
||||
result.day = cast(s32)(day_of_year - (153 * month_index + 2) / 5 + 1)
|
||||
result.month = cast(s32)(ifx month_index < 10 then month_index + 3 else month_index - 9)
|
||||
result.year = year_of_era + era * 400 + (ifx result.month <= 2 then 1 else 0)
|
||||
weekday := (days + 4) % 7
|
||||
if weekday < 0 {
|
||||
weekday += 7
|
||||
}
|
||||
result.weekday = cast(s32)weekday
|
||||
return result
|
||||
}
|
||||
|
||||
Append :: (output: []u8, used: s32, text: string) -> s32 {
|
||||
index: s32 = 0
|
||||
while index < cast(s32)text.count && used < cast(s32)output.count - 1 {
|
||||
output[used] = text[index]
|
||||
used += 1
|
||||
index += 1
|
||||
}
|
||||
output[used] = cast(u8)0
|
||||
return used
|
||||
}
|
||||
|
||||
AppendTwoDigits :: (output: []u8, used: s32, value: s64) -> s32 {
|
||||
digits: [3]u8
|
||||
digits[0] = cast(u8)(48 + cast(s32)((value / 10) % 10))
|
||||
digits[1] = cast(u8)(48 + cast(s32)(value % 10))
|
||||
return Append(output, used, TextView(digits[0:2]))
|
||||
}
|
||||
|
||||
AppendNumber :: (output: []u8, used: s32, value: s64) -> s32 {
|
||||
number: [24]u8
|
||||
return Append(output, used, FormatInteger(value, number[:]))
|
||||
}
|
||||
|
||||
LocalSeconds :: () -> s64 {
|
||||
now := AppNow()
|
||||
if now - local_offset_read_at > 60.0 {
|
||||
local_offset = AppLocalOffset()
|
||||
local_offset_read_at = now
|
||||
}
|
||||
seconds := cast(s64)now
|
||||
if cast(float64)seconds > now {
|
||||
seconds -= 1
|
||||
}
|
||||
return seconds + cast(s64)local_offset
|
||||
}
|
||||
|
||||
TimeText :: (output: []u8) -> string {
|
||||
seconds := LocalSeconds()
|
||||
of_day := seconds % 86400
|
||||
if of_day < 0 {
|
||||
of_day += 86400
|
||||
}
|
||||
used := AppendTwoDigits(output, 0, of_day / 3600)
|
||||
used = Append(output, used, ":")
|
||||
used = AppendTwoDigits(output, used, (of_day / 60) % 60)
|
||||
used = Append(output, used, ":")
|
||||
used = AppendTwoDigits(output, used, of_day % 60)
|
||||
return TextView(output[0:used])
|
||||
}
|
||||
|
||||
DateText :: (output: []u8) -> string {
|
||||
seconds := LocalSeconds()
|
||||
days := seconds / 86400
|
||||
if seconds < 0 && seconds % 86400 != 0 {
|
||||
days -= 1
|
||||
}
|
||||
date := CivilFromDays(days)
|
||||
weekdays: [7]string = .["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
|
||||
months: [12]string = .["January", "February", "March", "April", "May", "June", "July",
|
||||
"August", "September", "October", "November", "December"]
|
||||
used := Append(output, 0, weekdays[date.weekday])
|
||||
used = Append(output, used, ", ")
|
||||
used = AppendNumber(output, used, cast(s64)date.day)
|
||||
used = Append(output, used, " ")
|
||||
used = Append(output, used, months[date.month - 1])
|
||||
used = Append(output, used, " ")
|
||||
used = AppendNumber(output, used, date.year)
|
||||
return TextView(output[0:used])
|
||||
}
|
||||
|
||||
StopwatchSeconds :: () -> float64 {
|
||||
total := elapsed
|
||||
if running {
|
||||
total += AppNow() - started_at
|
||||
}
|
||||
if total < 0.0 {
|
||||
return 0.0
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
// h:mm:ss.t, or m:ss.t under an hour.
|
||||
StopwatchText :: (output: []u8) -> string {
|
||||
tenths := cast(s64)(StopwatchSeconds() * 10.0)
|
||||
seconds := tenths / 10
|
||||
used: s32 = 0
|
||||
if seconds >= 3600 {
|
||||
used = AppendNumber(output, used, seconds / 3600)
|
||||
used = Append(output, used, ":")
|
||||
used = AppendTwoDigits(output, used, (seconds / 60) % 60)
|
||||
} else {
|
||||
used = AppendNumber(output, used, seconds / 60)
|
||||
}
|
||||
used = Append(output, used, ":")
|
||||
used = AppendTwoDigits(output, used, seconds % 60)
|
||||
used = Append(output, used, ".")
|
||||
used = AppendNumber(output, used, tenths % 10)
|
||||
return TextView(output[0:used])
|
||||
}
|
||||
|
||||
// stopwatch.txt holds "running started_at elapsed" in milliseconds.
|
||||
LoadStopwatch :: () {
|
||||
buffer: [128]u8
|
||||
count := ReadStore("stopwatch.txt", buffer[:])
|
||||
if count <= 0 {
|
||||
return
|
||||
}
|
||||
values: [3]s64
|
||||
field: s32 = 0
|
||||
index: s32 = 0
|
||||
negative := false
|
||||
while index < count && field < 3 {
|
||||
byte := buffer[index]
|
||||
if byte == cast(u8)32 {
|
||||
if negative {
|
||||
values[field] = 0 - values[field]
|
||||
}
|
||||
field += 1
|
||||
negative = false
|
||||
} else if byte == cast(u8)45 {
|
||||
negative = true
|
||||
} else if byte >= cast(u8)48 && byte <= cast(u8)57 {
|
||||
values[field] = values[field] * 10 + cast(s64)(byte - cast(u8)48)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
if field < 3 && negative {
|
||||
values[field] = 0 - values[field]
|
||||
}
|
||||
if field < 2 {
|
||||
return
|
||||
}
|
||||
running = values[0] == 1
|
||||
started_at = cast(float64)values[1] / 1000.0
|
||||
elapsed = cast(float64)values[2] / 1000.0
|
||||
}
|
||||
|
||||
SaveStopwatch :: () {
|
||||
buffer: [128]u8
|
||||
used := AppendNumber(buffer[:], 0, ifx running then 1 else 0)
|
||||
used = Append(buffer[:], used, " ")
|
||||
used = AppendNumber(buffer[:], used, cast(s64)(started_at * 1000.0))
|
||||
used = Append(buffer[:], used, " ")
|
||||
used = AppendNumber(buffer[:], used, cast(s64)(elapsed * 1000.0))
|
||||
unused WriteStore("stopwatch.txt", TextView(buffer[0:used]))
|
||||
}
|
||||
|
||||
Big :: (key: u64, text: string, area: Rectangle, y: float32, font: s32) {
|
||||
Text(session, TextProps.{.key = key, .bounds = Rectangle.{area.x + 16.0, y, area.width - 32.0, cast(float32)(font + 16)},
|
||||
.text = text, .font = font, .align = TextAlign.TextAlignCenter})
|
||||
}
|
||||
|
||||
Action :: (id: s32, label: string, bounds: Rectangle, accent: bool) -> bool {
|
||||
props := ButtonProps.{.key = cast(u64)id, .id = id, .bounds = bounds, .label = label,
|
||||
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisSoft}
|
||||
if accent {
|
||||
props.tone = ButtonTone.ButtonToneAccent
|
||||
props.emphasis = ButtonEmphasis.ButtonEmphasisFilled
|
||||
}
|
||||
return Button(session, props) != 0
|
||||
}
|
||||
|
||||
Draw :: () {
|
||||
session = AppSession()
|
||||
area := AppBounds()
|
||||
width := area.width - 32.0
|
||||
if width > 420.0 {
|
||||
width = 420.0
|
||||
}
|
||||
left := area.x + (area.width - width) * 0.5
|
||||
half := (width - 8.0) / 2.0
|
||||
if Action(1, "Clock", Rectangle.{left, area.y + 16.0, half, 40.0}, view == VIEW_CLOCK) {
|
||||
view = VIEW_CLOCK
|
||||
}
|
||||
if Action(2, "Stopwatch", Rectangle.{left + half + 8.0, area.y + 16.0, half, 40.0}, view == VIEW_STOPWATCH) {
|
||||
view = VIEW_STOPWATCH
|
||||
}
|
||||
middle := area.y + area.height * 0.35
|
||||
text: [64]u8
|
||||
if view == VIEW_CLOCK {
|
||||
Big(cast(u64)10, TimeText(text[:]), area, middle - 40.0, 56)
|
||||
date: [96]u8
|
||||
Big(cast(u64)11, DateText(date[:]), area, middle + 40.0, 18)
|
||||
return
|
||||
}
|
||||
Big(cast(u64)20, StopwatchText(text[:]), area, middle - 40.0, 56)
|
||||
buttons_y := middle + 56.0
|
||||
if Action(21, ifx running then "Stop" else "Start", Rectangle.{left, buttons_y, half, 48.0}, true) {
|
||||
now := AppNow()
|
||||
if running {
|
||||
elapsed += now - started_at
|
||||
} else {
|
||||
started_at = now
|
||||
}
|
||||
running = !running
|
||||
SaveStopwatch()
|
||||
}
|
||||
if Action(22, "Reset", Rectangle.{left + half + 8.0, buttons_y, half, 48.0}, false) {
|
||||
running = false
|
||||
elapsed = 0.0
|
||||
started_at = 0.0
|
||||
SaveStopwatch()
|
||||
}
|
||||
}
|
||||
|
||||
#program_export "ClockMain"
|
||||
Main :: () -> s32 {
|
||||
if AppMode() == APP_IDENTIFY {
|
||||
AppIdentity("clock")
|
||||
AppDescribe("Clock", Icon.Shape)
|
||||
return APP_PROTOCOL
|
||||
}
|
||||
if AppMode() != APP_FRAME {
|
||||
return 0
|
||||
}
|
||||
if !loaded {
|
||||
LoadStopwatch()
|
||||
loaded = true
|
||||
}
|
||||
Draw()
|
||||
return 0
|
||||
}
|
||||
|
After Width: | Height: | Size: 93 KiB |
@@ -0,0 +1,189 @@
|
||||
#import "pass_core"
|
||||
#import "pass_text"
|
||||
#import "byte_text_linux"
|
||||
#import "version"
|
||||
#import "c_string"
|
||||
#import "text_buffer"
|
||||
#import "cli_profiles"
|
||||
#import "cli_native"
|
||||
|
||||
libc :: #system_library "libc";
|
||||
Write :: (fd: s32, bytes: *u8, count: usize) -> isize #foreign libc "write";
|
||||
GetEnv :: (name: *u8) -> *u8 #foreign libc "getenv";
|
||||
|
||||
Usage :: #string END
|
||||
Usage: pass [OPTIONS] SITE LOGIN [MASTER_PASSWORD]
|
||||
pass [OPTIONS] PROFILE SITE
|
||||
|
||||
Derive a site-specific password.
|
||||
|
||||
Options:
|
||||
-L, --length N password length (default 16, min 5, max 35)
|
||||
-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 read the master password from stdin
|
||||
-P, --profile NAME use a saved login and generation settings
|
||||
--vault PATH unlock an OpenSSL-encrypted master password
|
||||
--clear-after TIME release copied password after e.g. 90s
|
||||
-c, --copy copy the result to the X11 clipboard
|
||||
--no-copy print instead of copying
|
||||
-v, --version show version
|
||||
-h, --help show this help
|
||||
END;
|
||||
|
||||
Print :: (fd: s32, value: string) {
|
||||
buffer: [4096]u8
|
||||
offset: s32 = 0
|
||||
while offset < cast(s32)value.count {
|
||||
count: s32 = cast(s32)value.count - offset
|
||||
if count > 4096 { count = 4096 }
|
||||
index: s32 = 0
|
||||
while index < count { buffer[index] = value[offset + index]; index += 1 }
|
||||
written: s32 = 0
|
||||
while written < count {
|
||||
result: isize = Write(fd, *buffer[written], cast(usize)(count - written))
|
||||
if result <= cast(isize)0 { return }
|
||||
written += cast(s32)result
|
||||
}
|
||||
offset += count
|
||||
}
|
||||
}
|
||||
|
||||
Error :: (message: string) -> s32 {
|
||||
Print(2, "pass: "); Print(2, message); Print(2, "\n")
|
||||
return 2
|
||||
}
|
||||
|
||||
#program_export
|
||||
main :: (argc: s32, argv: **u8) -> s32 {
|
||||
options: PassOptions
|
||||
options.length = 16; options.counter = cast(u64)1
|
||||
options.lowercase = true; options.uppercase = true
|
||||
options.digits = true; options.symbols = true
|
||||
prompt: bool; copy: bool; no_copy: bool; version: bool
|
||||
profile_name: string; vault_path: string; clear_after: string
|
||||
explicit: u32
|
||||
positional: [3]string
|
||||
count: s32 = 0
|
||||
index: s32 = 1
|
||||
while index < argc {
|
||||
arg := TextFromCString(argv[index])
|
||||
if arg == "-h" || arg == "--help" { Print(1, Usage); return 0 }
|
||||
if arg == "-v" || arg == "--version" { version = true }
|
||||
else if arg == "-L" || arg == "--length" || arg == "-C" ||
|
||||
arg == "--counter" || arg == "--exclude" || arg == "-P" ||
|
||||
arg == "--profile" || arg == "--vault" || arg == "--clear-after" {
|
||||
if index + 1 >= argc {
|
||||
Print(2, "pass: "); Print(2, arg); Print(2, " requires a value\n")
|
||||
Print(2, Usage); return 2
|
||||
}
|
||||
index += 1
|
||||
value := TextFromCString(argv[index])
|
||||
if arg == "--exclude" { options.exclude = value; explicit |= cast(u32)64 }
|
||||
else if arg == "-P" || arg == "--profile" { profile_name = value }
|
||||
else if arg == "--vault" { vault_path = value }
|
||||
else if arg == "--clear-after" { clear_after = value }
|
||||
else {
|
||||
number := ParseNumber(value)
|
||||
if !number.valid { Print(2, Usage); return 2 }
|
||||
if arg == "-L" || arg == "--length" {
|
||||
if number.value > 2147483647 || number.value < -2147483647 { Print(2, Usage); return 2 }
|
||||
options.length = cast(s32)number.value
|
||||
explicit |= cast(u32)1
|
||||
} else {
|
||||
if number.value < 0 { number.value = 0 }
|
||||
options.counter = cast(u64)number.value
|
||||
explicit |= cast(u32)2
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handled: bool = true
|
||||
if arg == "-l" || arg == "--lowercase" { options.lowercase = true; explicit |= cast(u32)4 }
|
||||
else if arg == "-u" || arg == "--uppercase" { options.uppercase = true; explicit |= cast(u32)8 }
|
||||
else if arg == "-d" || arg == "--digits" { options.digits = true; explicit |= cast(u32)16 }
|
||||
else if arg == "-s" || arg == "--symbols" { options.symbols = true; explicit |= cast(u32)32 }
|
||||
else if arg == "--no-lowercase" { options.lowercase = false; explicit |= cast(u32)4 }
|
||||
else if arg == "--no-uppercase" { options.uppercase = false; explicit |= cast(u32)8 }
|
||||
else if arg == "--no-digits" { options.digits = false; explicit |= cast(u32)16 }
|
||||
else if arg == "--no-symbols" { options.symbols = false; explicit |= cast(u32)32 }
|
||||
else if arg == "-p" || arg == "--prompt" { prompt = true }
|
||||
else if arg == "-c" || arg == "--copy" { copy = true }
|
||||
else if arg == "--no-copy" { no_copy = true }
|
||||
else { handled = false }
|
||||
if !handled {
|
||||
if arg.count > 0 && arg[0] == cast(u8)45 { return Error("unknown option") }
|
||||
if count >= 3 { return Error("too many positional arguments") }
|
||||
positional[count] = arg; count += 1
|
||||
}
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
if version { Print(1, "pass "); Print(1, Version); Print(1, "\n"); return 0 }
|
||||
site: string; login: string; clear_ms: s64
|
||||
// Keep the decoded profile alive until generation has finished.
|
||||
profile: LegacyProfile
|
||||
if profile_name != "" {
|
||||
if count != 1 { return Error("expected SITE with --profile") }
|
||||
} else if count < 2 { Print(2, Usage); return 2 }
|
||||
candidate := profile_name
|
||||
if candidate == "" && count == 2 { candidate = positional[0] }
|
||||
profile = LoadLegacyProfile(candidate, profile_name != "", *options, explicit)
|
||||
if !profile.valid { return Error("invalid CLI profiles configuration or unknown profile") }
|
||||
if profile.found {
|
||||
site = ifx profile_name != "" then positional[0] else positional[1]
|
||||
login = TextUntilNul(profile.login[:])
|
||||
if (explicit & cast(u32)64) == cast(u32)0 { options.exclude = TextUntilNul(profile.exclude[:]) }
|
||||
} else { site = positional[0]; login = positional[1] }
|
||||
if !copy { copy = profile.copy }
|
||||
clear_ms = profile.clear_ms
|
||||
if clear_after != "" {
|
||||
clear_ms = DurationMilliseconds(clear_after)
|
||||
if clear_ms < 0 { return Error("invalid --clear-after duration") }
|
||||
}
|
||||
if vault_path == "" && !prompt && count != 3 { vault_path = TextUntilNul(profile.vault[:]) }
|
||||
if vault_path != "" && (prompt || count == 3) { return Error("--vault cannot be combined with --prompt or MASTER_PASSWORD") }
|
||||
if prompt && count == 3 { return Error("MASTER_PASSWORD cannot be supplied together with --prompt") }
|
||||
master: [1024]u8
|
||||
defer { ClearBytes(master[:]) }
|
||||
if count == 3 {
|
||||
if !CopyText(positional[2], master[:]) { return Error("master password is too long") }
|
||||
} else {
|
||||
unlocked: bool
|
||||
if vault_path != "" {
|
||||
if !DecryptVault(vault_path, master[:]) { return Error("cannot unlock vault: wrong passphrase, unreadable or corrupted vault") }
|
||||
unlocked = true
|
||||
}
|
||||
if !unlocked {
|
||||
name: [32]u8
|
||||
CopyCString("LESSPASS_MASTER_PASSWORD", name[:])
|
||||
environment: *u8 = GetEnv(*name[0])
|
||||
if !prompt && environment != null {
|
||||
if !CopyText(TextFromCString(environment), master[:]) { return Error("master password is too long") }
|
||||
} else {
|
||||
if !ReadSecret(master[:], "Master password: ") { return Error("missing master password") }
|
||||
}
|
||||
}
|
||||
}
|
||||
generated := PassGenerate(site, login, TextUntilNul(master[:]), options)
|
||||
defer { ClearBytes(generated.password[:]) }
|
||||
ClearBytes(master[:])
|
||||
if !generated.valid {
|
||||
Print(2, "pass: "); Print(2, generated.error); Print(2, "\n"); return 1
|
||||
}
|
||||
if copy && !no_copy {
|
||||
if !CopyPassword(TextView(generated.password[0:generated.length]), clear_ms) {
|
||||
return Error("clipboard unavailable; install xclip or use --no-copy")
|
||||
}
|
||||
Print(2, "Password copied to the clipboard.\n"); return 0
|
||||
}
|
||||
Print(1, TextView(generated.password[0:generated.length])); Print(1, "\n")
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
#import "pass_text"
|
||||
#import "std/c_string"
|
||||
#import "std/text_buffer"
|
||||
#import "std/byte_text_linux"
|
||||
Capture :: #import "std/process_capture_linux";
|
||||
Channel :: #import "std/process_channel_linux";
|
||||
Socket :: #import "std/socket_linux";
|
||||
Timer :: #import "std/timer_linux";
|
||||
|
||||
libc :: #system_library "libc";
|
||||
NativeRead :: (fd: s32, bytes: *u8, count: usize) -> isize #foreign libc "read";
|
||||
NativeWrite :: (fd: s32, bytes: *u8, count: usize) -> isize #foreign libc "write";
|
||||
NativeOpen :: (path: *u8, flags: s32) -> s32 #foreign libc "open";
|
||||
NativeClose :: (fd: s32) -> s32 #foreign libc "close";
|
||||
NativeEnv :: (name: *u8) -> *u8 #foreign libc "getenv";
|
||||
NativeIsTty :: (fd: s32) -> s32 #foreign libc "isatty";
|
||||
NativeGetTerminal :: (fd: s32, state: *void) -> s32 #foreign libc "tcgetattr";
|
||||
NativeSetTerminal :: (fd: s32, action: s32, state: *void) -> s32 #foreign libc "tcsetattr";
|
||||
NativeSession :: () -> s32 #foreign libc "setsid";
|
||||
NativeShutdown :: (fd: s32, direction: s32) -> s32 #foreign libc "shutdown";
|
||||
NativePipe :: (fds: *s32) -> s32 #foreign libc "pipe";
|
||||
NativeDescriptorFlags :: (fd: s32, command: s32, value: s32) -> s32 #foreign libc "fcntl";
|
||||
NativeFork :: () -> s32 #foreign libc "fork";
|
||||
NativeDup :: (source: s32, destination: s32) -> s32 #foreign libc "dup2";
|
||||
NativeExit :: (code: s32) -> void #foreign libc "_exit";
|
||||
NativeWait :: (pid: s32, status: *s32, options: s32) -> s32 #foreign libc "waitpid";
|
||||
SignalHandler :: #type (signal: s32) #c_call;
|
||||
NativeSignal :: (signal: s32, handler: SignalHandler) -> SignalHandler #foreign libc "signal";
|
||||
|
||||
terminal_fd: s32 = -1;
|
||||
terminal_state: [32]u64;
|
||||
|
||||
RestoreTerminalOnSignal :: (signal: s32) {
|
||||
if terminal_fd >= 0 { unused NativeSetTerminal(terminal_fd, 0, cast(*void)*terminal_state[0]) }
|
||||
NativeExit(128 + signal)
|
||||
}
|
||||
|
||||
EnvironmentText :: (name: string) -> string {
|
||||
bytes: [128]u8
|
||||
if !CopyCString(name, bytes[:]) { return "" }
|
||||
value := NativeEnv(*bytes[0])
|
||||
if value == null { return "" }
|
||||
return TextFromCString(value)
|
||||
}
|
||||
|
||||
ExpandHomePath :: (value: string, output: []u8) -> bool {
|
||||
if value == "~" || (value.count >= 2 && value[0:2] == "~/") {
|
||||
home := EnvironmentText("HOME")
|
||||
if home == "" { return false }
|
||||
return AppendText(output, AppendText(output, 0, home), value[1:]) >= 0
|
||||
}
|
||||
return CopyCString(value, output)
|
||||
}
|
||||
|
||||
// 0 means no file; -1 is an unreadable, oversized or invalid configuration.
|
||||
ReadProfileDocument :: (output: []u8) -> s32 {
|
||||
path: [4096]u8
|
||||
base := EnvironmentText("XDG_CONFIG_HOME")
|
||||
if base != "" { if !CopyCString(base, path[:]) { return -1 } }
|
||||
else if !ExpandHomePath("~/.config", path[:]) { return 0 }
|
||||
if AppendText(path[:], cast(s32)TextUntilNul(path[:]).count, "/pass/profiles.json") < 0 { return -1 }
|
||||
fd := NativeOpen(*path[0], 0)
|
||||
if fd < 0 { if Socket.LinuxErrno() == 2 { return 0 }; return -1 }
|
||||
defer { unused NativeClose(fd) }
|
||||
used: s32
|
||||
while used < cast(s32)output.count - 1 {
|
||||
count := NativeRead(fd, *output[used], cast(usize)(cast(s32)output.count - 1 - used))
|
||||
if count < cast(isize)0 { return -1 }
|
||||
if count == cast(isize)0 { output[used] = cast(u8)0; return used + 1 }
|
||||
used += cast(s32)count
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
ReadSecret :: (buffer: []u8, prompt: string) -> bool {
|
||||
fd: s32 = 0
|
||||
terminal := NativeIsTty(fd) == 1
|
||||
previous: [4]SignalHandler
|
||||
signals: [4]s32 = .[1, 2, 3, 15]
|
||||
if terminal {
|
||||
if NativeGetTerminal(fd, cast(*void)*terminal_state[0]) != 0 { return false }
|
||||
terminal_fd = fd
|
||||
for i: 0..3 { previous[i] = NativeSignal(signals[i], RestoreTerminalOnSignal) }
|
||||
}
|
||||
defer {
|
||||
if terminal {
|
||||
unused NativeSetTerminal(fd, 0, cast(*void)*terminal_state[0])
|
||||
terminal_fd = -1
|
||||
restored: s32 = 0
|
||||
while restored < 4 {
|
||||
unused NativeSignal(signals[restored], previous[restored]); restored += 1
|
||||
}
|
||||
newline: [1]u8 = .[cast(u8)10]
|
||||
unused NativeWrite(2, *newline[0], cast(usize)1)
|
||||
}
|
||||
}
|
||||
if terminal {
|
||||
// stty owns the platform-specific termios layout. The opaque saved
|
||||
// state is restored even when input is cancelled with Ctrl-C.
|
||||
ignored: [128]u8
|
||||
args: [8]string = .["stty", "-echo", "-isig", "-icanon", "min", "1", "time", "0"]
|
||||
changed := Capture.CaptureOutput(args[:], ignored[:])
|
||||
if changed.error || changed.code != 0 { return false }
|
||||
message: [128]u8
|
||||
if CopyCString(prompt, message[:]) { unused NativeWrite(2, *message[0], cast(usize)prompt.count) }
|
||||
}
|
||||
used: s32
|
||||
while used < cast(s32)buffer.count - 1 {
|
||||
byte: u8
|
||||
if NativeRead(fd, *byte, cast(usize)1) != cast(isize)1 { return used > 0 }
|
||||
if byte == cast(u8)0 || byte == cast(u8)3 || byte == cast(u8)4 { return false }
|
||||
if terminal && (byte == cast(u8)8 || byte == cast(u8)127) {
|
||||
if used > 0 { used -= 1; buffer[used] = cast(u8)0 }
|
||||
continue
|
||||
}
|
||||
if terminal && byte == cast(u8)21 { ClearBytes(buffer); used = 0; continue }
|
||||
if byte == cast(u8)10 {
|
||||
if used > 0 && buffer[used - 1] == cast(u8)13 { used -= 1 }
|
||||
buffer[used] = cast(u8)0; return true
|
||||
}
|
||||
buffer[used] = byte; used += 1
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
DecryptVault :: (vault: string, output: []u8) -> bool {
|
||||
path: [4096]u8
|
||||
if !ExpandHomePath(vault, path[:]) { return false }
|
||||
passphrase: [1024]u8
|
||||
defer { ClearBytes(passphrase[:]) }
|
||||
if !ReadSecret(passphrase[:], "Vault passphrase: ") { return false }
|
||||
// Legacy vaults may wrap their base64 with spaces, tabs or CRLF, which
|
||||
// OpenSSL 3.0 rejects. Send it without whitespace through a pipe that
|
||||
// openssl opens as its input; stdin stays the passphrase.
|
||||
encoded: [60000]u8
|
||||
file := NativeOpen(*path[0], 0)
|
||||
if file < 0 { return false }
|
||||
size: s32 = 0
|
||||
while true {
|
||||
byte: u8
|
||||
count := NativeRead(file, *byte, cast(usize)1)
|
||||
if count != cast(isize)1 { break }
|
||||
if byte == cast(u8)32 || (byte >= cast(u8)9 && byte <= cast(u8)13) { continue }
|
||||
if size >= cast(s32)encoded.count - 1 { unused NativeClose(file); return false }
|
||||
encoded[size] = byte; size += 1
|
||||
}
|
||||
unused NativeClose(file)
|
||||
encoded[size] = cast(u8)10
|
||||
pipe: [2]s32
|
||||
if NativePipe(*pipe[0]) != 0 { return false }
|
||||
// Only openssl keeps the reading end; the writer closes before it starts.
|
||||
if NativeDescriptorFlags(pipe[1], 2, 1) != 0 ||
|
||||
NativeWrite(pipe[1], *encoded[0], cast(usize)(size + 1)) != cast(isize)(size + 1) {
|
||||
unused NativeClose(pipe[0]); unused NativeClose(pipe[1]); return false
|
||||
}
|
||||
unused NativeClose(pipe[1])
|
||||
defer { unused NativeClose(pipe[0]) }
|
||||
digits: [12]u8; place: s32 = 11; number := pipe[0]
|
||||
while true { place -= 1; digits[place] = cast(u8)(48 + number % 10); number /= 10; if number == 0 { break } }
|
||||
input: [32]u8
|
||||
if AppendText(input[:], AppendText(input[:], 0, "/dev/fd/"), TextView(digits[place:11])) < 0 { return false }
|
||||
args: [16]string = .["openssl", "enc", "-d", "-aes-256-cbc", "-md", "sha512", "-a", "-A", "-pbkdf2", "-iter", "100000", "-in", TextUntilNul(input[:]), "-pass", "stdin", "-salt"]
|
||||
child := Channel.StartChannel(args[:], false)
|
||||
if child.error != 0 { return false }
|
||||
defer { unused Channel.CloseChannel(*child, 1000) }
|
||||
length := cast(s32)TextUntilNul(passphrase[:]).count
|
||||
passphrase[length] = cast(u8)10
|
||||
if Channel.ChannelSend(child, passphrase[0:length + 1], 3000) < 0 { return false }
|
||||
unused NativeShutdown(child.socket.fd, 1)
|
||||
used: s32
|
||||
while used < cast(s32)output.count - 1 {
|
||||
count := Channel.ChannelReceive(child, output[used:cast(s32)output.count - 1], 10000)
|
||||
if count < 0 { return false }
|
||||
if count == 0 { break }
|
||||
used += cast(s32)count
|
||||
}
|
||||
if used >= cast(s32)output.count - 1 || !Channel.WaitChannel(*child, 1000) || child.code != 0 { return false }
|
||||
while used > 0 && output[used - 1] == cast(u8)10 { used -= 1 }
|
||||
for i: 0..used - 1 { if output[i] == cast(u8)0 { return false } }
|
||||
output[used] = cast(u8)0
|
||||
return true
|
||||
}
|
||||
|
||||
// A detached supervisor retains only its own clipboard child. Expiration
|
||||
// releases that selection; it never clears a replacement owner's clipboard.
|
||||
CopyPassword :: (value: string, clear_ms: s64) -> bool {
|
||||
if EnvironmentText("DISPLAY") == "" { return false }
|
||||
ready: [2]s32
|
||||
if NativePipe(*ready[0]) != 0 { return false }
|
||||
pid := NativeFork()
|
||||
if pid < 0 { unused NativeClose(ready[0]); unused NativeClose(ready[1]); return false }
|
||||
if pid == 0 {
|
||||
unused NativeClose(ready[0]); unused NativeSession()
|
||||
null_path: [16]u8; CopyCString("/dev/null", null_path[:])
|
||||
null_fd := NativeOpen(*null_path[0], 2)
|
||||
if null_fd >= 0 {
|
||||
for i: 0..2 { unused NativeDup(null_fd, cast(s32)i) }
|
||||
if null_fd > 2 { unused NativeClose(null_fd) }
|
||||
}
|
||||
args: [5]string = .["xclip", "-selection", "clipboard", "-in", "-quiet"]
|
||||
child := Channel.StartChannel(args[:], false)
|
||||
ok := child.error == 0
|
||||
if ok {
|
||||
payload: [36]u8
|
||||
ok = CopyCString(value, payload[:])
|
||||
if ok { ok = Channel.ChannelSend(child, payload[0:value.count], 3000) >= 0 }
|
||||
ClearBytes(payload[:])
|
||||
unused NativeShutdown(child.socket.fd, 1)
|
||||
if Channel.WaitChannel(*child, 100) { ok = false }
|
||||
}
|
||||
answer: u8 = ifx ok then cast(u8)1 else cast(u8)0
|
||||
unused NativeWrite(ready[1], *answer, cast(usize)1)
|
||||
unused NativeClose(ready[1])
|
||||
if ok {
|
||||
started := Timer.MonotonicMilliseconds()
|
||||
while !Channel.WaitChannel(*child, 100) {
|
||||
if child.error != 0 || (clear_ms > 0 && Timer.MonotonicMilliseconds() - started >= clear_ms) { break }
|
||||
}
|
||||
}
|
||||
unused Channel.CloseChannel(*child, 0)
|
||||
NativeExit(0)
|
||||
}
|
||||
unused NativeClose(ready[1])
|
||||
answer: u8
|
||||
ok := NativeRead(ready[0], *answer, cast(usize)1) == cast(isize)1 && answer == cast(u8)1
|
||||
unused NativeClose(ready[0])
|
||||
if !ok { status: s32; unused NativeWait(pid, *status, 0) }
|
||||
return ok
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
Json :: #import "std/json_scan";
|
||||
#import "pass_core"
|
||||
#import "pass_text"
|
||||
#import "cli_native"
|
||||
#import "std/text_buffer"
|
||||
|
||||
LegacyProfile :: struct {
|
||||
found: bool
|
||||
valid: bool
|
||||
login: [1024]u8
|
||||
vault: [4096]u8
|
||||
exclude: [1024]u8
|
||||
copy: bool
|
||||
clear_ms: s64
|
||||
}
|
||||
|
||||
profile_document: [65536]u8;
|
||||
|
||||
ProfileString :: (document: string, object: s32, name: string, output: []u8) -> bool {
|
||||
at := Json.FieldAt(document, object, name)
|
||||
if at < 0 || Json.MatchLiteral(document, at, "null") { return true }
|
||||
return Json.ReadStringText(document, at, output) >= 0
|
||||
}
|
||||
|
||||
ProfileBool :: (document: string, object: s32, name: string, value: *bool) -> bool {
|
||||
at := Json.FieldAt(document, object, name)
|
||||
if at < 0 || Json.MatchLiteral(document, at, "null") { return true }
|
||||
if Json.MatchLiteral(document, at, "true") { <<value = true; return true }
|
||||
if Json.MatchLiteral(document, at, "false") { <<value = false; return true }
|
||||
return false
|
||||
}
|
||||
|
||||
// The original CLI accepted Go-style durations; keep seconds, minutes, hours
|
||||
// and fractional/composite values without placing any secrets in a command.
|
||||
DurationMilliseconds :: (value: string) -> s64 {
|
||||
if value == "0" { return 0 }
|
||||
at: s32; total: float64
|
||||
while at < cast(s32)value.count {
|
||||
number := Json.ReadNumber(value, at)
|
||||
if !number.valid || number.value < 0 { return -1 }
|
||||
at = number.after
|
||||
scale: float64
|
||||
if at + 2 <= cast(s32)value.count && value[at:at + 2] == "ms" { scale = 1; at += 2 }
|
||||
else if at < cast(s32)value.count && value[at] == cast(u8)115 { scale = 1000; at += 1 }
|
||||
else if at < cast(s32)value.count && value[at] == cast(u8)109 { scale = 60000; at += 1 }
|
||||
else if at < cast(s32)value.count && value[at] == cast(u8)104 { scale = 3600000; at += 1 }
|
||||
else { return -1 }
|
||||
total += number.value * scale
|
||||
if total > 2147483647 { return -1 }
|
||||
}
|
||||
if at == 0 { return -1 }
|
||||
return cast(s64)total
|
||||
}
|
||||
|
||||
ProfileDefaults :: (document: string, object: s32, result: *LegacyProfile) -> bool {
|
||||
if !ProfileString(document, object, "vault", result.vault[:]) ||
|
||||
!ProfileBool(document, object, "copy", *result.copy) { return false }
|
||||
duration: [128]u8
|
||||
if !ProfileString(document, object, "clear_after", duration[:]) { return false }
|
||||
if duration[0] != cast(u8)0 {
|
||||
result.clear_ms = DurationMilliseconds(TextUntilNul(duration[:]))
|
||||
if result.clear_ms < 0 { return false }
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
LoadLegacyProfile :: (name: string, required: bool, options: *PassOptions,
|
||||
explicit: u32) -> LegacyProfile {
|
||||
result: LegacyProfile
|
||||
loaded := ReadProfileDocument(profile_document[:])
|
||||
if loaded < 0 { return result }
|
||||
if loaded == 0 { result.valid = !required; return result }
|
||||
document := TextUntilNul(profile_document[:])
|
||||
start := Json.Space(document, 0)
|
||||
end := Json.ValueEnd(document, start, 0)
|
||||
if start >= cast(s32)document.count || document[start] != cast(u8)123 ||
|
||||
end < 0 || Json.Space(document, end) != cast(s32)document.count { return result }
|
||||
if !ProfileDefaults(document, start, *result) { return result }
|
||||
profiles := Json.FieldAt(document, start, "profiles")
|
||||
profile := Json.FieldAt(document, profiles, name)
|
||||
if name == "" || profile < 0 { result.valid = !required; return result }
|
||||
if document[profile] != cast(u8)123 ||
|
||||
!ProfileString(document, profile, "login", result.login[:]) ||
|
||||
result.login[0] == cast(u8)0 || !ProfileDefaults(document, profile, *result) { return result }
|
||||
names: [2]string = .["length", "counter"]
|
||||
for i: 0..1 {
|
||||
at := Json.FieldAt(document, profile, names[i])
|
||||
if at >= 0 && !Json.MatchLiteral(document, at, "null") {
|
||||
after := Json.ValueEnd(document, at, 0)
|
||||
number := ParseNumber(document[at:after])
|
||||
if !number.valid || number.value < 0 { return result }
|
||||
if i == 0 && number.value > 2147483647 { return result }
|
||||
if number.value > 0 && (explicit & (cast(u32)1 << i)) == cast(u32)0 {
|
||||
if i == 0 { options.length = cast(s32)number.value }
|
||||
else { options.counter = cast(u64)number.value }
|
||||
}
|
||||
}
|
||||
}
|
||||
if (explicit & cast(u32)4) == cast(u32)0 && !ProfileBool(document, profile, "lowercase", *options.lowercase) { return result }
|
||||
if (explicit & cast(u32)8) == cast(u32)0 && !ProfileBool(document, profile, "uppercase", *options.uppercase) { return result }
|
||||
if (explicit & cast(u32)16) == cast(u32)0 && !ProfileBool(document, profile, "digits", *options.digits) { return result }
|
||||
if (explicit & cast(u32)32) == cast(u32)0 && !ProfileBool(document, profile, "symbols", *options.symbols) { return result }
|
||||
if !ProfileString(document, profile, "exclude", result.exclude[:]) { return result }
|
||||
result.found = true; result.valid = true
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,491 @@
|
||||
// Pass: a stateless password generator. The same site, login, master
|
||||
// password and settings always give the same password, with no database.
|
||||
#import "session"
|
||||
#import "geometry"
|
||||
#import "text_props"
|
||||
#import "text_widget"
|
||||
#import "text_input_props"
|
||||
#import "text_field_widget"
|
||||
#import "button_props"
|
||||
#import "button_widget"
|
||||
#import "control_props"
|
||||
#import "checkbox_props"
|
||||
#import "checkbox_widget"
|
||||
#import "spinbox_props"
|
||||
#import "spinbox_widget"
|
||||
#import "box_props"
|
||||
#import "box_widget"
|
||||
#import "image_props"
|
||||
#import "image_widget"
|
||||
#import "scroll_props"
|
||||
#import "scroll_widget"
|
||||
#import "tree"
|
||||
#import "text_buffer"
|
||||
#import "utf8"
|
||||
#import "kryon/app_context"
|
||||
#import "kryon/app_protocol"
|
||||
#import "pass_core"
|
||||
#import "pass_state"
|
||||
#import "pass_text"
|
||||
Icon :: #import "mingcute_regular_keyhole";
|
||||
|
||||
FieldState :: struct {
|
||||
cursor: s32
|
||||
anchor: s32
|
||||
scroll_x: s32
|
||||
}
|
||||
|
||||
initialized: bool;
|
||||
view: s32;
|
||||
focused: s32;
|
||||
fields: [5]FieldState;
|
||||
site: [256]u8;
|
||||
login: [256]u8;
|
||||
master: [1024]u8;
|
||||
profile_name: [64]u8;
|
||||
reveal: bool;
|
||||
scroll_offsets: [3]s32;
|
||||
emoji: [32]u8;
|
||||
session: Session;
|
||||
|
||||
Label :: (value: string, x: float32, y: float32, width: float32, font: s32) {
|
||||
props: TextProps
|
||||
props.bounds = Rectangle.{x, y, width, cast(float32)(font + 8)}
|
||||
props.text = value
|
||||
props.font = font
|
||||
Text(session, props)
|
||||
}
|
||||
|
||||
Action :: (id: s32, label: string, bounds: Rectangle, accent: bool, disabled: bool) -> bool {
|
||||
props: ButtonProps
|
||||
props.key = cast(u64)id
|
||||
props.id = id
|
||||
props.bounds = bounds
|
||||
props.label = label
|
||||
props.disabled = disabled
|
||||
props.tone = ButtonTone.ButtonToneNeutral
|
||||
props.emphasis = ButtonEmphasis.ButtonEmphasisSoft
|
||||
if accent {
|
||||
props.tone = ButtonTone.ButtonToneAccent
|
||||
props.emphasis = ButtonEmphasis.ButtonEmphasisFilled
|
||||
}
|
||||
return Button(session, props) == 1
|
||||
}
|
||||
|
||||
ApplyEdit :: (buffer: []u8, edit: TextFieldEdit) -> bool {
|
||||
if !edit.changed {
|
||||
return false
|
||||
}
|
||||
length: s32 = 0
|
||||
while length < cast(s32)buffer.count && buffer[length] != cast(u8)0 {
|
||||
length += 1
|
||||
}
|
||||
if edit.start < 0 || edit.end < edit.start || edit.end > length {
|
||||
return false
|
||||
}
|
||||
replacement: [1024]u8
|
||||
used := length - (edit.end - edit.start) + cast(s32)edit.replacement.count
|
||||
if used >= cast(s32)buffer.count || used >= 1024 {
|
||||
return false
|
||||
}
|
||||
position: s32 = 0
|
||||
while position < edit.start {
|
||||
replacement[position] = buffer[position]
|
||||
position += 1
|
||||
}
|
||||
index: s32 = 0
|
||||
while index < cast(s32)edit.replacement.count {
|
||||
replacement[position] = edit.replacement[index]
|
||||
position += 1
|
||||
index += 1
|
||||
}
|
||||
index = edit.end
|
||||
while index < length {
|
||||
replacement[position] = buffer[index]
|
||||
position += 1
|
||||
index += 1
|
||||
}
|
||||
index = 0
|
||||
while index < cast(s32)buffer.count {
|
||||
buffer[index] = ifx index < used then replacement[index] else cast(u8)0
|
||||
index += 1
|
||||
}
|
||||
for wipe: 0..1023 {
|
||||
replacement[wipe] = cast(u8)0
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Field :: (index: s32, label: string, buffer: []u8, bounds: Rectangle, secure: bool) {
|
||||
snapshot: [1024]u8
|
||||
mask: [1024]u8
|
||||
// The views of the copies end with this block, before they are wiped.
|
||||
{
|
||||
props: TextFieldProps
|
||||
position: s32 = 0
|
||||
while position < cast(s32)buffer.count && position < 1023 {
|
||||
snapshot[position] = buffer[position]
|
||||
if buffer[position] == cast(u8)0 {
|
||||
break
|
||||
}
|
||||
position += 1
|
||||
}
|
||||
props.key = cast(u64)(100 + index)
|
||||
props.focus_id = 100 + index
|
||||
props.bounds = bounds
|
||||
props.label = label
|
||||
props.value = TextUntilNul(snapshot[:])
|
||||
props.cursor = fields[index].cursor
|
||||
props.anchor = fields[index].anchor
|
||||
props.scroll_x = fields[index].scroll_x
|
||||
props.focused = focused == index + 1
|
||||
props.max_bytes = cast(s32)buffer.count - 1
|
||||
props.max_codepoints = props.max_bytes
|
||||
props.secure = secure
|
||||
if secure {
|
||||
count := Codepoints(props.value)
|
||||
if count > 1023 {
|
||||
count = 1023
|
||||
}
|
||||
masked: s32 = 0
|
||||
while masked < count {
|
||||
mask[masked] = cast(u8)42
|
||||
masked += 1
|
||||
}
|
||||
props.display_value = TextView(mask[0:count])
|
||||
}
|
||||
if props.focused {
|
||||
props.input = AppFieldInput()
|
||||
}
|
||||
result := TextField(session, props)
|
||||
fields[index].cursor = result.cursor
|
||||
fields[index].anchor = result.anchor
|
||||
fields[index].scroll_x = result.scroll_x
|
||||
unused ApplyEdit(buffer, result.edit)
|
||||
if result.focused {
|
||||
focused = index + 1
|
||||
}
|
||||
if result.escaped && focused == index + 1 {
|
||||
focused = 0
|
||||
}
|
||||
}
|
||||
for wipe: 0..1023 {
|
||||
snapshot[wipe] = cast(u8)0
|
||||
mask[wipe] = cast(u8)0
|
||||
}
|
||||
}
|
||||
|
||||
// The number of characters in UTF-8 text.
|
||||
Codepoints :: (text: string) -> s32 {
|
||||
count: s32 = 0
|
||||
index: s64 = 0
|
||||
while index < text.count {
|
||||
if (text[index] & cast(u8)0xC0) != cast(u8)0x80 {
|
||||
count += 1
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
Check :: (id: s32, label: string, value: bool, bounds: Rectangle) -> bool {
|
||||
props: CheckboxProps
|
||||
props.key = cast(u64)id
|
||||
props.id = id
|
||||
props.label = label
|
||||
props.bounds = bounds
|
||||
props.checked = value
|
||||
return Checkbox(session, props).checked
|
||||
}
|
||||
|
||||
Integer :: (id: s32, label: string, value: s32, low: s32, high: s32, x: float32, y: float32, width: float32) -> s32 {
|
||||
Label(label, x, y + 8.0, width - 160.0, 16)
|
||||
props: SpinboxProps
|
||||
props.key = cast(u64)id
|
||||
props.id = id
|
||||
props.label = label
|
||||
props.bounds = Rectangle.{x + width - 150.0, y, 150.0, 38.0}
|
||||
props.value = value
|
||||
props.min = low
|
||||
props.max = high
|
||||
props.step = 1
|
||||
return Spinbox(session, props).value
|
||||
}
|
||||
|
||||
CurrentOptions :: () -> PassOptions {
|
||||
options: PassOptions
|
||||
options.length = runtime.settings.length
|
||||
options.counter = cast(u64)runtime.settings.counter
|
||||
options.lowercase = runtime.settings.lower
|
||||
options.uppercase = runtime.settings.upper
|
||||
options.digits = runtime.settings.digits
|
||||
options.symbols = runtime.settings.symbols
|
||||
options.exclude = TextUntilNul(runtime.settings.exclude[:])
|
||||
return options
|
||||
}
|
||||
|
||||
CurrentProfile :: () -> Profile {
|
||||
profile: Profile
|
||||
profile.name = profile_name
|
||||
profile.site = site
|
||||
profile.login = login
|
||||
profile.exclude = runtime.settings.exclude
|
||||
profile.length = runtime.settings.length
|
||||
profile.counter = runtime.settings.counter
|
||||
profile.lower = runtime.settings.lower
|
||||
profile.upper = runtime.settings.upper
|
||||
profile.digits = runtime.settings.digits
|
||||
profile.symbols = runtime.settings.symbols
|
||||
return profile
|
||||
}
|
||||
|
||||
// The four fingerprint emoji that let you notice a mistyped master password.
|
||||
Fingerprint :: (x: float32, y: float32) {
|
||||
used := MasterEmoji(TextUntilNul(master[:]), emoji[:])
|
||||
atlas := AppAssetPath("fingerprint.png")
|
||||
position: s32 = 0
|
||||
for index: 0..3 {
|
||||
decoded := Decode(TextView(emoji[0:used]), position)
|
||||
glyph: s32 = 0
|
||||
while glyph < 63 && cast(u32)master_emoji_codepoints[glyph] != decoded.value {
|
||||
glyph += 1
|
||||
}
|
||||
props: ImageProps
|
||||
props.asset_path = atlas
|
||||
props.alt_text = TextView(emoji[position:decoded.after])
|
||||
props.bounds = Rectangle.{x + cast(float32)index * 28.0, y, 24.0, 24.0}
|
||||
props.source = Rectangle.{cast(float32)(glyph % 8) * 64.0, cast(float32)(glyph / 8) * 64.0, 64.0, 64.0}
|
||||
props.tint = ifx AppDark() then cast(u32)0xe8e8e8ff else cast(u32)0x202c29ff
|
||||
Image(session, props)
|
||||
position = decoded.after
|
||||
}
|
||||
}
|
||||
|
||||
MasterField :: (x: float32, y: float32, width: float32) -> float32 {
|
||||
Label("Master password", x, y, width, 14)
|
||||
Field(2, "Master password", master[:], Rectangle.{x, y + 24.0, width - 86.0, 40.0}, !reveal)
|
||||
if Action(13, ifx reveal then "Hide" else "Show", Rectangle.{x + width - 78.0, y + 24.0, 78.0, 40.0}, false, false) {
|
||||
reveal = !reveal
|
||||
}
|
||||
y += 76.0
|
||||
if runtime.settings.show_fingerprint && master[0] != cast(u8)0 {
|
||||
Fingerprint(x, y)
|
||||
y += 34.0
|
||||
}
|
||||
if HasSavedMaster() {
|
||||
if Action(14, "Unlock master password", Rectangle.{x, y, width, 38.0}, false, false) {
|
||||
focused = 0
|
||||
unused UnlockMaster()
|
||||
}
|
||||
y += 48.0
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
OptionsForm :: (x: float32, y: float32, width: float32) -> float32 {
|
||||
runtime.settings.length = Integer(20, "Length", runtime.settings.length, 5, 35, x, y, width)
|
||||
y += 50.0
|
||||
runtime.settings.counter = Integer(21, "Counter", runtime.settings.counter, 1, 999999, x, y, width)
|
||||
y += 50.0
|
||||
part := width / 4.0
|
||||
runtime.settings.lower = Check(31, "a-z", runtime.settings.lower, Rectangle.{x, y, part, 36.0})
|
||||
runtime.settings.upper = Check(32, "A-Z", runtime.settings.upper, Rectangle.{x + part, y, part, 36.0})
|
||||
runtime.settings.digits = Check(33, "0-9", runtime.settings.digits, Rectangle.{x + part * 2.0, y, part, 36.0})
|
||||
runtime.settings.symbols = Check(34, "#", runtime.settings.symbols, Rectangle.{x + part * 3.0, y, part, 36.0})
|
||||
y += 48.0
|
||||
Label("Exclude", x, y, width, 14)
|
||||
Field(3, "Exclude", runtime.settings.exclude[:], Rectangle.{x, y + 24.0, width, 40.0}, false)
|
||||
return y + 76.0
|
||||
}
|
||||
|
||||
GenerateForm :: (x: float32, y: float32, width: float32) {
|
||||
Label("Site", x, y, width, 14)
|
||||
Field(0, "Site", site[:], Rectangle.{x, y + 24.0, width, 40.0}, false)
|
||||
y += 76.0
|
||||
Label("Login", x, y, width, 14)
|
||||
Field(1, "Login", login[:], Rectangle.{x, y + 24.0, width, 40.0}, false)
|
||||
y += 76.0
|
||||
y = MasterField(x, y, width)
|
||||
y = OptionsForm(x, y, width)
|
||||
if Action(40, "Generate", Rectangle.{x, y, width, 44.0}, true, false) {
|
||||
focused = 0
|
||||
unused Generate(TextUntilNul(site[:]), TextUntilNul(login[:]), TextUntilNul(master[:]), CurrentOptions())
|
||||
scroll_offsets[0] = 10000
|
||||
}
|
||||
y += 60.0
|
||||
Label("Generated password", x, y, width, 14)
|
||||
y += 28.0
|
||||
props: BoxProps
|
||||
props.key = cast(u64)42
|
||||
props.bounds = Rectangle.{x, y, width, 54.0}
|
||||
props.radius = 8.0
|
||||
Box(session, props)
|
||||
Label(ifx Generated() == "" then "Password will appear here" else Generated(), x + 10.0, y + 16.0, width - 20.0, 16)
|
||||
y += 68.0
|
||||
if Action(41, "Copy", Rectangle.{x, y, width, 40.0}, false, false) {
|
||||
unused CopyPassword()
|
||||
}
|
||||
}
|
||||
|
||||
ProfilesForm :: (x: float32, y: float32, width: float32) {
|
||||
Label("Profile name", x, y, width, 14)
|
||||
Field(4, "Profile name", profile_name[:], Rectangle.{x, y + 24.0, width, 40.0}, false)
|
||||
y += 76.0
|
||||
if Action(210, "Save Current Profile", Rectangle.{x, y, width, 42.0}, true, false) {
|
||||
unused SaveProfile(CurrentProfile())
|
||||
}
|
||||
y += 60.0
|
||||
if runtime.profile_count == 0 {
|
||||
Label("No saved profiles", x, y, width, 16)
|
||||
}
|
||||
index: s32 = 0
|
||||
while index < runtime.profile_count {
|
||||
Label(TextUntilNul(runtime.profiles[index].name[:]), x, y, width, 16)
|
||||
Label(TextUntilNul(runtime.profiles[index].site[:]), x, y + 26.0, width, 12)
|
||||
if Action(300 + index, "Generate", Rectangle.{x, y + 50.0, width * 0.6 - 4.0, 36.0}, false, false) {
|
||||
unused GenerateProfile(index, TextUntilNul(master[:]))
|
||||
view = 0
|
||||
focused = 0
|
||||
scroll_offsets[0] = 10000
|
||||
}
|
||||
if Action(400 + index, "Delete", Rectangle.{x + width * 0.6 + 4.0, y + 50.0, width * 0.4 - 4.0, 36.0}, false, false) {
|
||||
unused DeleteProfile(index)
|
||||
break
|
||||
}
|
||||
y += 102.0
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
|
||||
SettingsForm :: (x: float32, y: float32, width: float32) {
|
||||
runtime.settings.auto_copy = Check(501, "Auto-copy after Generate", runtime.settings.auto_copy, Rectangle.{x, y, width, 36.0})
|
||||
y += 48.0
|
||||
runtime.settings.clear_seconds = Integer(502, "Clipboard seconds", runtime.settings.clear_seconds, 0, 3600, x, y, width)
|
||||
y += 50.0
|
||||
runtime.settings.show_fingerprint = Check(503, "Show master fingerprint", runtime.settings.show_fingerprint, Rectangle.{x, y, width, 36.0})
|
||||
y += 54.0
|
||||
Label("Generation defaults", x, y, width, 20)
|
||||
y += 38.0
|
||||
y = OptionsForm(x, y, width)
|
||||
if Action(510, "Save Settings", Rectangle.{x, y, width, 42.0}, true, false) {
|
||||
unused SaveSettings()
|
||||
}
|
||||
y += 60.0
|
||||
Label("Secure master password", x, y, width, 20)
|
||||
y += 38.0
|
||||
y = MasterField(x, y, width)
|
||||
Label(FingerprintStatus(), x, y, width, 12)
|
||||
y += 36.0
|
||||
if Action(520, "Save", Rectangle.{x, y, width / 2.0 - 4.0, 42.0}, true, !CanSaveMaster()) {
|
||||
focused = 0
|
||||
unused SaveMaster(TextUntilNul(master[:]))
|
||||
}
|
||||
if Action(522, "Forget", Rectangle.{x + width / 2.0 + 4.0, y, width / 2.0 - 4.0, 42.0}, false, !HasSavedMaster()) {
|
||||
unused ForgetMaster()
|
||||
}
|
||||
}
|
||||
|
||||
// Tab moves between the fields of the current view.
|
||||
FocusNext :: () {
|
||||
if AppKey() != 258 {
|
||||
return
|
||||
}
|
||||
if view == 0 {
|
||||
if (AppModifiers() & 1) != 0 {
|
||||
focused = ((focused + 2) % 4) + 1
|
||||
} else {
|
||||
focused = (focused % 4) + 1
|
||||
}
|
||||
}
|
||||
if view == 1 {
|
||||
focused = 5
|
||||
}
|
||||
if view == 2 {
|
||||
focused = 3
|
||||
}
|
||||
}
|
||||
|
||||
Draw :: () {
|
||||
session = AppSession()
|
||||
area := AppBounds()
|
||||
if runtime.has_unlocked_master {
|
||||
master = runtime.unlocked_master
|
||||
runtime.unlocked_master = .{}
|
||||
runtime.has_unlocked_master = false
|
||||
fields[2] = FieldState.{}
|
||||
}
|
||||
FocusNext()
|
||||
pad: float32 = 18.0
|
||||
width := area.width - pad * 2.0
|
||||
if width > 480.0 {
|
||||
width = 480.0
|
||||
}
|
||||
left := area.x + (area.width - width) * 0.5
|
||||
height := area.height - 110.0
|
||||
if height < 60.0 {
|
||||
height = 60.0
|
||||
}
|
||||
content_height: s32 = 648
|
||||
if runtime.settings.show_fingerprint && master[0] != cast(u8)0 {
|
||||
content_height += 34
|
||||
}
|
||||
if HasSavedMaster() {
|
||||
content_height += 48
|
||||
}
|
||||
if view == 1 {
|
||||
content_height = 180 + runtime.profile_count * 102
|
||||
}
|
||||
if view == 2 {
|
||||
content_height = 760
|
||||
}
|
||||
props: ScrollProps
|
||||
props.key = cast(u64)(10 + view)
|
||||
props.bounds = Rectangle.{left, area.y + 12.0, width, height}
|
||||
props.content_height = content_height
|
||||
props.scroll_offset = scroll_offsets[view]
|
||||
props.scale = 1.0
|
||||
scroll := Scroll(session, props)
|
||||
scroll_offsets[view] = scroll.scroll_offset
|
||||
if scroll.opened {
|
||||
if view == 0 {
|
||||
GenerateForm(scroll.content.x, scroll.content.y, scroll.content.width - 10.0)
|
||||
}
|
||||
if view == 1 {
|
||||
ProfilesForm(scroll.content.x, scroll.content.y, scroll.content.width - 10.0)
|
||||
}
|
||||
if view == 2 {
|
||||
SettingsForm(scroll.content.x, scroll.content.y, scroll.content.width - 10.0)
|
||||
}
|
||||
End(session)
|
||||
}
|
||||
Label(Status(), left, area.y + area.height - 88.0, width, 12)
|
||||
labels: [3]string = .{"Generate", "Profiles", "Settings"}
|
||||
for index: 0..2 {
|
||||
tab := cast(s32)index
|
||||
bounds := Rectangle.{left + cast(float32)index * width / 3.0, area.y + area.height - 58.0, width / 3.0 - 4.0, 46.0}
|
||||
if Action(700 + tab, labels[index], bounds, view == tab, false) {
|
||||
view = tab
|
||||
focused = 0
|
||||
}
|
||||
}
|
||||
AppKeyboard(focused != 0)
|
||||
}
|
||||
|
||||
#program_export "PassMain"
|
||||
Main :: () -> s32 {
|
||||
if AppMode() == APP_IDENTIFY {
|
||||
AppIdentity("pass")
|
||||
AppDescribe("Pass", Icon.Shape)
|
||||
return APP_PROTOCOL
|
||||
}
|
||||
if AppMode() != APP_FRAME {
|
||||
return 0
|
||||
}
|
||||
if !initialized {
|
||||
Initialize()
|
||||
initialized = true
|
||||
}
|
||||
Tick()
|
||||
Draw()
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
#import "crypto/sha256"
|
||||
#if #defined(WERK_APP) {
|
||||
#import "kryon/app_context"
|
||||
}
|
||||
|
||||
PassOptions :: struct {
|
||||
length: s32
|
||||
counter: u64
|
||||
lowercase: bool
|
||||
uppercase: bool
|
||||
digits: bool
|
||||
symbols: bool
|
||||
exclude: string
|
||||
}
|
||||
|
||||
PassClass :: struct {
|
||||
bytes: [32]u8
|
||||
count: s32
|
||||
}
|
||||
|
||||
PassResult :: struct {
|
||||
valid: bool
|
||||
password: [36]u8
|
||||
length: s32
|
||||
error: string
|
||||
}
|
||||
|
||||
EntropyState :: struct {
|
||||
bytes: [32]u8
|
||||
}
|
||||
EntropyResult :: struct {
|
||||
entropy: EntropyState
|
||||
value: s32
|
||||
}
|
||||
|
||||
master_emoji_codepoints: [64]s32 = .[
|
||||
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
|
||||
];
|
||||
|
||||
|
||||
// Whether the last DeriveKey failed; only the Werkzeug host can refuse.
|
||||
derive_failed: bool;
|
||||
|
||||
DeriveKey :: (password: string, salt: string) -> [32]u8 {
|
||||
derive_failed = false
|
||||
// Inside Werkzeug the host derives the key natively; the portable
|
||||
// interpreter would take minutes for 100,000 rounds.
|
||||
#if #defined(WERK_APP) {
|
||||
output: [32]u8
|
||||
derive_failed = !AppPbkdf2Sha256(password, salt, 100000, output[:])
|
||||
return output
|
||||
} else {
|
||||
return Pbkdf2Sha256(password, ifx salt.count > PASS_SALT_LIMIT then salt[0:PASS_SALT_LIMIT] else salt, 100000)
|
||||
}
|
||||
}
|
||||
|
||||
// Werkzeug's key derivation has always read at most this many salt bytes,
|
||||
// and existing vault keys depend on it; the host derives the same way.
|
||||
PASS_SALT_LIMIT :: 508
|
||||
|
||||
|
||||
PassClassEmptyError :: (class_index: s32) -> string {
|
||||
if class_index == 0 {
|
||||
return "enabled lowercase character class is empty after exclusions"
|
||||
}
|
||||
if class_index == 1 {
|
||||
return "enabled uppercase character class is empty after exclusions"
|
||||
}
|
||||
if class_index == 2 {
|
||||
return "enabled digits character class is empty after exclusions"
|
||||
}
|
||||
return "enabled symbols character class is empty after exclusions"
|
||||
}
|
||||
|
||||
PassFailure :: (message: string) -> PassResult {
|
||||
result: PassResult
|
||||
result.error = message
|
||||
return result
|
||||
}
|
||||
|
||||
PassFilterClass :: (characters: string, options: PassOptions) -> PassClass {
|
||||
result: PassClass
|
||||
character_index: s32 = 0
|
||||
while character_index < cast(s32)characters.count {
|
||||
excluded := false
|
||||
exclude_index: s32 = 0
|
||||
while exclude_index < cast(s32)options.exclude.count {
|
||||
if options.exclude[exclude_index] == characters[character_index] {
|
||||
excluded = true
|
||||
break
|
||||
}
|
||||
exclude_index += 1
|
||||
}
|
||||
if !excluded && result.count < cast(s32)result.bytes.count {
|
||||
result.bytes[result.count] = characters[character_index]
|
||||
result.count += 1
|
||||
}
|
||||
character_index += 1
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
PassAppendCounter :: (salt: []u8, offset: s32, counter: u64) -> s32 {
|
||||
digits: [16]u8
|
||||
digit_count: s32 = 0
|
||||
value := counter
|
||||
while value > cast(u64)0 {
|
||||
nibble: u64 = value % cast(u64)16
|
||||
if nibble < cast(u64)10 {
|
||||
digits[digit_count] = cast(u8)(nibble + cast(u64)48)
|
||||
} else {
|
||||
digits[digit_count] = cast(u8)(nibble + cast(u64)87)
|
||||
}
|
||||
digit_count += 1
|
||||
value /= cast(u64)16
|
||||
}
|
||||
if digit_count == 0 {
|
||||
salt[offset] = cast(u8)48
|
||||
return offset + 1
|
||||
}
|
||||
digit_index: s32 = digit_count - 1
|
||||
while digit_index >= 0 {
|
||||
salt[offset + (digit_count - digit_index - 1)] = digits[digit_index]
|
||||
digit_index -= 1
|
||||
}
|
||||
return offset + digit_count
|
||||
}
|
||||
|
||||
EntropyTake :: (entropy: EntropyState, divisor: s32) -> EntropyResult {
|
||||
carry: u32 = 0
|
||||
index: s32 = 0
|
||||
while index < 32 {
|
||||
current: u32 = carry * cast(u32)256 +
|
||||
cast(u32)entropy.bytes[index]
|
||||
entropy.bytes[index] = cast(u8)(current / cast(u32)divisor)
|
||||
carry = current % cast(u32)divisor
|
||||
index += 1
|
||||
}
|
||||
return EntropyResult.{entropy, cast(s32)carry}
|
||||
}
|
||||
|
||||
PassGenerate :: (site: string, login: string, master: string,
|
||||
options: PassOptions) -> PassResult {
|
||||
if options.length < 5 || options.length > 35 {
|
||||
return PassFailure(
|
||||
"password length must be between 5 and 35")
|
||||
}
|
||||
|
||||
class_sets: [4]string = .[
|
||||
"abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
"0123456789", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
|
||||
]
|
||||
class_names: [4]string = .[
|
||||
"lowercase", "uppercase", "digits", "symbols"
|
||||
]
|
||||
class_enabled: [4]bool = .[
|
||||
options.lowercase, options.uppercase,
|
||||
options.digits, options.symbols
|
||||
]
|
||||
classes: [4]PassClass
|
||||
class_count: s32 = 0
|
||||
alphabet: [128]u8
|
||||
alphabet_count: s32 = 0
|
||||
class_index: s32 = 0
|
||||
while class_index < 4 {
|
||||
if class_enabled[class_index] {
|
||||
classes[class_count] = PassFilterClass(
|
||||
class_sets[class_index], options)
|
||||
if classes[class_count].count == 0 {
|
||||
return PassFailure(PassClassEmptyError(class_index))
|
||||
}
|
||||
copy_index: s32 = 0
|
||||
while copy_index < classes[class_count].count {
|
||||
alphabet[alphabet_count] =
|
||||
classes[class_count].bytes[copy_index]
|
||||
alphabet_count += 1
|
||||
copy_index += 1
|
||||
}
|
||||
class_count += 1
|
||||
}
|
||||
class_index += 1
|
||||
}
|
||||
if class_count == 0 {
|
||||
return PassFailure("at least one character class must be enabled")
|
||||
}
|
||||
if options.length < class_count {
|
||||
return PassFailure(
|
||||
"password length is smaller than the enabled character classes")
|
||||
}
|
||||
if options.length == class_count {
|
||||
return PassFailure(
|
||||
"password length must leave room for generated characters")
|
||||
}
|
||||
|
||||
salt: [640]u8
|
||||
salt_length: s32 = 0
|
||||
if cast(s32)site.count >= cast(s32)salt.count {
|
||||
return PassFailure("site name is too long")
|
||||
}
|
||||
site_index: s32 = 0
|
||||
while site_index < cast(s32)site.count {
|
||||
salt[salt_length] = site[site_index]
|
||||
salt_length += 1
|
||||
site_index += 1
|
||||
}
|
||||
if cast(s64)salt_length + login.count + 16 > salt.count {
|
||||
return PassFailure("login is too long")
|
||||
}
|
||||
login_index: s32 = 0
|
||||
while login_index < cast(s32)login.count {
|
||||
salt[salt_length] = login[login_index]
|
||||
salt_length += 1
|
||||
login_index += 1
|
||||
}
|
||||
salt_length = PassAppendCounter(salt[:], salt_length, options.counter)
|
||||
|
||||
entropy: EntropyState
|
||||
entropy.bytes = DeriveKey(master, TextView(salt[0:salt_length]))
|
||||
if derive_failed { return PassFailure("Could not derive the password") }
|
||||
|
||||
password_length := options.length - class_count
|
||||
password: [36]u8
|
||||
generated_index: s32 = 0
|
||||
while generated_index < password_length {
|
||||
taken := EntropyTake(entropy, alphabet_count)
|
||||
entropy = taken.entropy
|
||||
password[generated_index] = alphabet[taken.value]
|
||||
generated_index += 1
|
||||
}
|
||||
|
||||
required: [4]u8
|
||||
required_index: s32 = 0
|
||||
while required_index < class_count {
|
||||
taken := EntropyTake(entropy, classes[required_index].count)
|
||||
entropy = taken.entropy
|
||||
required[required_index] = classes[required_index].bytes[taken.value]
|
||||
required_index += 1
|
||||
}
|
||||
|
||||
insertion_index: s32 = 0
|
||||
while insertion_index < class_count {
|
||||
taken := EntropyTake(entropy, password_length)
|
||||
entropy = taken.entropy
|
||||
position := taken.value
|
||||
move_index := password_length
|
||||
while move_index > position {
|
||||
password[move_index] = password[move_index - 1]
|
||||
move_index -= 1
|
||||
}
|
||||
password[position] = required[insertion_index]
|
||||
password_length += 1
|
||||
insertion_index += 1
|
||||
}
|
||||
|
||||
result: PassResult
|
||||
result.valid = true
|
||||
result.length = password_length
|
||||
result_index: s32 = 0
|
||||
while result_index < password_length {
|
||||
result.password[result_index] = password[result_index]
|
||||
result_index += 1
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
MasterEmojiAppendUtf8 :: (output: []u8, used: s32, codepoint: u32) -> s32 {
|
||||
if used < 0 || used >= cast(s32)output.count { return used }
|
||||
length: s32 = 0
|
||||
if codepoint <= cast(u32)0x7f {
|
||||
length = 1
|
||||
} else if codepoint <= cast(u32)0x7ff {
|
||||
length = 2
|
||||
} else if codepoint <= cast(u32)0xffff {
|
||||
length = 3
|
||||
} else if codepoint <= cast(u32)0x10ffff {
|
||||
length = 4
|
||||
} else {
|
||||
output[used] = cast(u8)0
|
||||
return used
|
||||
}
|
||||
|
||||
if used + length >= cast(s32)output.count {
|
||||
output[used] = cast(u8)0
|
||||
return used
|
||||
}
|
||||
|
||||
if length == 1 {
|
||||
output[used] = cast(u8)codepoint
|
||||
} else if length == 2 {
|
||||
output[used] = cast(u8)(cast(u32)0xc0 | (codepoint >> cast(u32)6))
|
||||
output[used + 1] = cast(u8)(cast(u32)0x80 |
|
||||
(codepoint & cast(u32)0x3f))
|
||||
} else if length == 3 {
|
||||
output[used] = cast(u8)(cast(u32)0xe0 | (codepoint >> cast(u32)12))
|
||||
output[used + 1] = cast(u8)(cast(u32)0x80 |
|
||||
((codepoint >> cast(u32)6) & cast(u32)0x3f))
|
||||
output[used + 2] = cast(u8)(cast(u32)0x80 |
|
||||
(codepoint & cast(u32)0x3f))
|
||||
} else {
|
||||
output[used] = cast(u8)(cast(u32)0xf0 | (codepoint >> cast(u32)18))
|
||||
output[used + 1] = cast(u8)(cast(u32)0x80 |
|
||||
((codepoint >> cast(u32)12) & cast(u32)0x3f))
|
||||
output[used + 2] = cast(u8)(cast(u32)0x80 |
|
||||
((codepoint >> cast(u32)6) & cast(u32)0x3f))
|
||||
output[used + 3] = cast(u8)(cast(u32)0x80 |
|
||||
(codepoint & cast(u32)0x3f))
|
||||
}
|
||||
|
||||
used += length
|
||||
output[used] = cast(u8)0
|
||||
return used
|
||||
}
|
||||
|
||||
MasterEmoji :: (master: string, output: []u8) -> s32 {
|
||||
if output.count <= 0 { return 0 }
|
||||
output[0] = cast(u8)0
|
||||
|
||||
digest := Sha256Of(master)
|
||||
used: s32 = 0
|
||||
for index: 0..3 {
|
||||
codepoint: u32 = cast(u32)master_emoji_codepoints[
|
||||
cast(s32)digest[index] & 63]
|
||||
used = MasterEmojiAppendUtf8(output, used, codepoint)
|
||||
}
|
||||
return used
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
#import "pass_core"
|
||||
#import "crypto/sha256"
|
||||
|
||||
#program_export
|
||||
DigestMatches :: (left: [32]u8, right: [32]u8) -> bool {
|
||||
for index: 0..31 {
|
||||
if left[index] != right[index] { return false }
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
#program_export
|
||||
Answer :: () -> s32 {
|
||||
empty := Sha256Of("")
|
||||
abc := Sha256Of("abc")
|
||||
derived := DeriveKey("password", "salt")
|
||||
if empty[0] != cast(u8)0xe3 || empty[31] != cast(u8)0x55 { return 1 }
|
||||
if abc[0] != cast(u8)0xba || abc[31] != cast(u8)0xad { return 2 }
|
||||
expected: [32]u8 = .[
|
||||
0x03, 0x94, 0xa2, 0xed, 0xe3, 0x32, 0xc9, 0xa1,
|
||||
0x3e, 0xb8, 0x2e, 0x9b, 0x24, 0x63, 0x16, 0x04,
|
||||
0xc3, 0x1d, 0xf9, 0x78, 0xb4, 0xe2, 0xf0, 0xfb,
|
||||
0xd2, 0xc5, 0x49, 0x94, 0x4f, 0x9d, 0x79, 0xa5
|
||||
]
|
||||
if !DigestMatches(derived, expected) { return 3 }
|
||||
long_password: [80]u8
|
||||
for index: 0..79 { long_password[index] = cast(u8)97 }
|
||||
long_derived := DeriveKey(TextView(long_password[0:80]), "salt")
|
||||
long_password_expected: [32]u8 = .[
|
||||
0x2f, 0xf0, 0x41, 0xc8, 0x08, 0x5d, 0xbc, 0xe4,
|
||||
0x6f, 0x9d, 0xc5, 0xa4, 0xe8, 0xb9, 0xe5, 0xeb,
|
||||
0x1d, 0x17, 0x27, 0x31, 0x8c, 0x54, 0x0f, 0x66,
|
||||
0x97, 0xb5, 0xb0, 0xa3, 0x68, 0xe1, 0x58, 0xad
|
||||
]
|
||||
if !DigestMatches(long_derived, long_password_expected) { return 4 }
|
||||
long_salt: [700]u8
|
||||
for index: 0..699 { long_salt[index] = cast(u8)98 }
|
||||
truncated_salt := DeriveKey("password", TextView(long_salt[0:700]))
|
||||
truncated_salt_expected: [32]u8 = .[
|
||||
0x3a, 0x4d, 0x1a, 0xf4, 0xf5, 0x39, 0x07, 0x0e,
|
||||
0x6f, 0xb4, 0xb2, 0xa0, 0x70, 0x90, 0x71, 0xd0,
|
||||
0x3e, 0x01, 0xc7, 0xfb, 0x6c, 0x26, 0x59, 0xf6,
|
||||
0xa8, 0x48, 0x11, 0xea, 0xe8, 0x50, 0x15, 0x0b
|
||||
]
|
||||
if !DigestMatches(truncated_salt, truncated_salt_expected) { return 5 }
|
||||
|
||||
defaults := DefaultPassOptions()
|
||||
generated := PassGenerate(
|
||||
"example.com", "alice", "correct horse battery staple", defaults)
|
||||
if !PassTextMatches(generated, "&Lf4'/-cSk4DPv_8") { return 6 }
|
||||
|
||||
excluded := defaults
|
||||
excluded.length = 24
|
||||
excluded.exclude = "0Ool1I!|"
|
||||
generated = PassGenerate(
|
||||
"example.com", "alice", "correct horse battery staple", excluded)
|
||||
if !PassTextMatches(
|
||||
generated, "7,.Cp}YnF'eeHHaqbX7#PQhg") { return 7 }
|
||||
|
||||
subset: PassOptions
|
||||
subset.length = 12
|
||||
subset.counter = 7
|
||||
subset.lowercase = true
|
||||
subset.digits = true
|
||||
subset.exclude = ""
|
||||
generated = PassGenerate(
|
||||
"δοκιμή.example", "ユーザー", "pässword", subset)
|
||||
if !PassTextMatches(generated, "oih5omhygh2v") { return 8 }
|
||||
|
||||
empty_subset: PassOptions
|
||||
empty_subset.length = 5
|
||||
empty_subset.uppercase = true
|
||||
empty_subset.digits = true
|
||||
generated = PassGenerate("x", "y", "", empty_subset)
|
||||
if !PassTextMatches(generated, "C9O9I") { return 9 }
|
||||
|
||||
lesspass := PassGenerate(
|
||||
"lesspass.com", "[email protected]", "password", defaults)
|
||||
if !PassTextMatches(lesspass, "\\g-A1-.OHEwrXjT#") { return 10 }
|
||||
|
||||
counters := defaults
|
||||
counters.counter = 10
|
||||
generated = PassGenerate("site", "login", "test", counters)
|
||||
if !PassTextMatches(generated, "XFt0F*,r619:+}[.") { return 11 }
|
||||
counters.counter = 16
|
||||
generated = PassGenerate("site", "login", "test", counters)
|
||||
if !PassTextMatches(generated, "l:`nzj>S7+0#uL_d") { return 12 }
|
||||
|
||||
empty_inputs := PassGenerate("", "", "", defaults)
|
||||
if !PassTextMatches(empty_inputs, "bb8^CBroRNj%4sP_") { return 13 }
|
||||
invalid := defaults
|
||||
invalid.digits = true
|
||||
invalid.exclude = "0123456789"
|
||||
if PassGenerate("", "", "", invalid).valid { return 14 }
|
||||
|
||||
emoji: [64]u8
|
||||
emoji_length := MasterEmoji(
|
||||
"correct horse battery staple", emoji[:])
|
||||
if !TextMatches(TextView(emoji[0:emoji_length]),
|
||||
"🐰🎨🐮🍑") { return 15 }
|
||||
|
||||
empty_emoji: [64]u8
|
||||
empty_emoji_length := MasterEmoji("", empty_emoji[:])
|
||||
if empty_emoji_length != 16 ||
|
||||
!TextMatches(TextView(empty_emoji[0:empty_emoji_length]),
|
||||
"🍔🔥🐰🐭") { return 16 }
|
||||
|
||||
tiny_emoji: [2]u8
|
||||
tiny_emoji[0] = cast(u8)120
|
||||
tiny_emoji_length := MasterEmoji(
|
||||
"correct horse battery staple", tiny_emoji[:])
|
||||
if tiny_emoji_length != 0 || tiny_emoji[0] != cast(u8)0 {
|
||||
return 17
|
||||
}
|
||||
return 42
|
||||
}
|
||||
|
||||
#program_export
|
||||
PortableAnswer :: () -> s32 {
|
||||
digest := HmacSha256Of("password", "salt")
|
||||
if digest[0] != cast(u8)0xfc || digest[31] != cast(u8)0xd0 {
|
||||
return 1
|
||||
}
|
||||
return 42
|
||||
}
|
||||
|
||||
|
||||
TextMatches :: (actual: string, expected: string) -> bool {
|
||||
if actual.count != expected.count { return false }
|
||||
index: s32 = 0
|
||||
while index < cast(s32)actual.count {
|
||||
if actual[index] != expected[index] { return false }
|
||||
index += 1
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
PassTextMatches :: (result: PassResult, expected: string) -> bool {
|
||||
if !result.valid || result.length != cast(s32)expected.count {
|
||||
return false
|
||||
}
|
||||
index: s32 = 0
|
||||
while index < result.length {
|
||||
if result.password[index] != expected[index] { return false }
|
||||
index += 1
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
DefaultPassOptions :: () -> PassOptions {
|
||||
options: PassOptions
|
||||
options.length = 16
|
||||
options.counter = 1
|
||||
options.lowercase = true
|
||||
options.uppercase = true
|
||||
options.digits = true
|
||||
options.symbols = true
|
||||
options.exclude = ""
|
||||
return options
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
// Pass's settings, saved profiles and generation. Everything is computed on
|
||||
// the device; the master password is never written unless the device keeps
|
||||
// it behind its own authentication.
|
||||
#import "pass_core"
|
||||
#import "pass_text"
|
||||
#import "text_buffer"
|
||||
#import "number_text"
|
||||
#import "kryon/app_context"
|
||||
|
||||
Profile :: struct {
|
||||
name: [64]u8
|
||||
site: [256]u8
|
||||
login: [256]u8
|
||||
exclude: [128]u8
|
||||
length: s32
|
||||
counter: s32
|
||||
lower: bool
|
||||
upper: bool
|
||||
digits: bool
|
||||
symbols: bool
|
||||
}
|
||||
|
||||
Settings :: struct {
|
||||
auto_copy: bool
|
||||
clear_seconds: s32
|
||||
show_fingerprint: bool
|
||||
length: s32
|
||||
counter: s32
|
||||
lower: bool
|
||||
upper: bool
|
||||
digits: bool
|
||||
symbols: bool
|
||||
exclude: [128]u8
|
||||
}
|
||||
|
||||
Runtime :: struct {
|
||||
settings: Settings
|
||||
profiles: [64]Profile
|
||||
profile_count: s32
|
||||
generated: [36]u8
|
||||
status: [256]u8
|
||||
unlocked_master: [1024]u8
|
||||
has_unlocked_master: bool
|
||||
secure_action: s32
|
||||
}
|
||||
|
||||
runtime: Runtime;
|
||||
store_buffer: [65536]u8;
|
||||
|
||||
SetStatus :: (value: string) { CopyText(value, runtime.status[:]) }
|
||||
Status :: () -> string { return TextUntilNul(runtime.status[:]) }
|
||||
Generated :: () -> string { return TextUntilNul(runtime.generated[:]) }
|
||||
|
||||
Clamp :: (value: s32, low: s32, high: s32) -> s32 {
|
||||
if value < low { return low }
|
||||
if value > high { return high }
|
||||
return value
|
||||
}
|
||||
|
||||
DefaultSettings :: () -> Settings {
|
||||
settings: Settings
|
||||
settings.length = 16; settings.counter = 1; settings.clear_seconds = 20
|
||||
settings.show_fingerprint = true
|
||||
settings.lower = true; settings.upper = true
|
||||
settings.digits = true; settings.symbols = true
|
||||
return settings
|
||||
}
|
||||
|
||||
StoreName :: (key: string, output: []u8) -> string {
|
||||
used := AppendText(output, 0, ".kryon_pass_")
|
||||
used = AppendText(output, used, key)
|
||||
used = AppendText(output, used, ".txt")
|
||||
if used < 0 { return "" }
|
||||
return TextUntilNul(output)
|
||||
}
|
||||
|
||||
ReadSetting :: (key: string, output: []u8) -> bool {
|
||||
name: [256]u8
|
||||
return ReadStore(StoreName(key, name[:]), output) >= 0
|
||||
}
|
||||
WriteSetting :: (key: string, value: string) -> bool {
|
||||
name: [256]u8
|
||||
return WriteStore(StoreName(key, name[:]), value)
|
||||
}
|
||||
ReadInteger :: (key: string, fallback: s32) -> s32 {
|
||||
buffer: [64]u8
|
||||
if !ReadSetting(key, buffer[:]) { return fallback }
|
||||
number := ParseNumber(TextUntilNul(buffer[:]))
|
||||
if !number.valid || number.value > 2147483647 || number.value < -2147483647 { return fallback }
|
||||
return cast(s32)number.value
|
||||
}
|
||||
WriteInteger :: (key: string, value: s32) -> bool {
|
||||
buffer: [32]u8
|
||||
return WriteSetting(key, FormatInteger(cast(s64)value, buffer[:]))
|
||||
}
|
||||
|
||||
ApplySetting :: (key: string, value: string) {
|
||||
number := ParseNumber(value)
|
||||
if key == "exclude" { CopyText(value, runtime.settings.exclude[:]); return }
|
||||
if !number.valid || number.value > 2147483647 || number.value < -2147483647 { return }
|
||||
integer := cast(s32)number.value
|
||||
if key == "auto_copy" { runtime.settings.auto_copy = integer != 0 }
|
||||
if key == "clear_after_seconds" { runtime.settings.clear_seconds = integer }
|
||||
if key == "show_fingerprint" { runtime.settings.show_fingerprint = integer != 0 }
|
||||
if key == "length" { runtime.settings.length = integer }
|
||||
if key == "counter" { runtime.settings.counter = integer }
|
||||
if key == "lower" { runtime.settings.lower = integer != 0 }
|
||||
if key == "upper" { runtime.settings.upper = integer != 0 }
|
||||
if key == "digits" { runtime.settings.digits = integer != 0 }
|
||||
if key == "symbols" { runtime.settings.symbols = integer != 0 }
|
||||
}
|
||||
|
||||
LoadSettings :: () {
|
||||
count := ReadStore("settings.cfg", store_buffer[:])
|
||||
if count > 0 {
|
||||
text := TextView(store_buffer[0:count])
|
||||
start: s32 = 0
|
||||
index: s32 = 0
|
||||
separator: s32 = -1
|
||||
while index <= count {
|
||||
if index == count || text[index] == cast(u8)10 {
|
||||
end := index
|
||||
if end > start && text[end - 1] == cast(u8)13 { end -= 1 }
|
||||
if separator >= start { ApplySetting(text[start:separator], text[separator + 1:end]) }
|
||||
start = index + 1; separator = -1
|
||||
} else {
|
||||
if text[index] == cast(u8)61 && separator < 0 { separator = index }
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
keys: [10]string = .{"auto_copy", "clear_after_seconds", "show_fingerprint", "length", "counter", "lower", "upper", "digits", "symbols", "exclude"}
|
||||
for index: 0..9 {
|
||||
buffer: [256]u8
|
||||
if ReadSetting(keys[index], buffer[:]) { ApplySetting(keys[index], TextUntilNul(buffer[:])) }
|
||||
}
|
||||
runtime.settings.length = Clamp(runtime.settings.length, 5, 35)
|
||||
runtime.settings.counter = Clamp(runtime.settings.counter, 1, 999999)
|
||||
runtime.settings.clear_seconds = Clamp(runtime.settings.clear_seconds, 0, 3600)
|
||||
}
|
||||
|
||||
SaveSettings :: () -> bool {
|
||||
settings := runtime.settings
|
||||
ok := WriteInteger("auto_copy", cast(s32)settings.auto_copy)
|
||||
ok = WriteInteger("clear_after_seconds", settings.clear_seconds) && ok
|
||||
ok = WriteInteger("show_fingerprint", cast(s32)settings.show_fingerprint) && ok
|
||||
ok = WriteInteger("length", settings.length) && ok
|
||||
ok = WriteInteger("counter", settings.counter) && ok
|
||||
ok = WriteInteger("lower", cast(s32)settings.lower) && ok
|
||||
ok = WriteInteger("upper", cast(s32)settings.upper) && ok
|
||||
ok = WriteInteger("digits", cast(s32)settings.digits) && ok
|
||||
ok = WriteInteger("symbols", cast(s32)settings.symbols) && ok
|
||||
ok = WriteSetting("exclude", TextUntilNul(runtime.settings.exclude[:])) && ok
|
||||
if ok { SetStatus("Settings saved") } else { SetStatus("Could not save settings") }
|
||||
return ok
|
||||
}
|
||||
|
||||
ProfileOptions :: (profile: Profile) -> PassOptions {
|
||||
options: PassOptions
|
||||
options.length = profile.length
|
||||
options.counter = cast(u64)Clamp(profile.counter, 0, 2147483647)
|
||||
options.lowercase = profile.lower; options.uppercase = profile.upper
|
||||
options.digits = profile.digits; options.symbols = profile.symbols
|
||||
return options
|
||||
}
|
||||
|
||||
Generate :: (site: string, login: string, master: string, options: PassOptions) -> bool {
|
||||
result := PassGenerate(site, login, master, options)
|
||||
runtime.generated = result.password
|
||||
if !result.valid { SetStatus(result.error); return false }
|
||||
SetStatus("Password generated locally")
|
||||
if runtime.settings.auto_copy { CopyPassword() }
|
||||
return true
|
||||
}
|
||||
|
||||
CopyPassword :: () -> bool {
|
||||
value := Generated()
|
||||
if value == "" { SetStatus("Generate a password first"); return false }
|
||||
if !ClipboardCopy(value, runtime.settings.clear_seconds) { SetStatus("Clipboard is unavailable"); return false }
|
||||
SetStatus("Copied")
|
||||
return true
|
||||
}
|
||||
|
||||
LoadProfiles :: () {
|
||||
runtime.profile_count = 0
|
||||
count := ReadStore("profiles.tsv", store_buffer[:])
|
||||
if count <= 0 { return }
|
||||
text := TextView(store_buffer[0:count])
|
||||
start: s32 = 0
|
||||
index: s32 = 0
|
||||
while index <= count && runtime.profile_count < 64 {
|
||||
if index == count || text[index] == cast(u8)10 {
|
||||
end := index
|
||||
if end > start && text[end - 1] == cast(u8)13 { end -= 1 }
|
||||
line := text[start:end]
|
||||
fields: [10]string
|
||||
field: s32 = 0
|
||||
position: s32 = 0
|
||||
previous: s32 = 0
|
||||
while position <= cast(s32)line.count && field < 10 {
|
||||
if position == cast(s32)line.count || line[position] == cast(u8)9 {
|
||||
fields[field] = line[previous:position]
|
||||
field += 1; previous = position + 1
|
||||
}
|
||||
position += 1
|
||||
}
|
||||
if field >= 9 {
|
||||
profile: Profile
|
||||
valid := CopyText(fields[0], profile.name[:]) && CopyText(fields[1], profile.site[:]) && CopyText(fields[2], profile.login[:]) && CopyText(fields[9], profile.exclude[:])
|
||||
numbers: [6]s32
|
||||
for number_index: 0..5 {
|
||||
number := ParseNumber(fields[number_index + 3])
|
||||
if !number.valid || number.value > 2147483647 || number.value < -2147483647 { valid = false }
|
||||
numbers[number_index] = cast(s32)number.value
|
||||
}
|
||||
profile.length = Clamp(numbers[0], 5, 35); profile.counter = numbers[1]
|
||||
profile.lower = numbers[2] != 0; profile.upper = numbers[3] != 0
|
||||
profile.digits = numbers[4] != 0; profile.symbols = numbers[5] != 0
|
||||
if valid && profile.name[0] != cast(u8)0 {
|
||||
runtime.profiles[runtime.profile_count] = profile
|
||||
runtime.profile_count += 1
|
||||
}
|
||||
}
|
||||
start = index + 1
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
|
||||
WriteProfiles :: () -> bool {
|
||||
used: s32 = 0
|
||||
index: s32 = 0
|
||||
while index < runtime.profile_count {
|
||||
profile := runtime.profiles[index]
|
||||
used = AppendText(store_buffer[:], used, TextUntilNul(profile.name[:]))
|
||||
used = AppendText(store_buffer[:], used, "\t")
|
||||
used = AppendText(store_buffer[:], used, TextUntilNul(profile.site[:]))
|
||||
used = AppendText(store_buffer[:], used, "\t")
|
||||
used = AppendText(store_buffer[:], used, TextUntilNul(profile.login[:]))
|
||||
values: [6]s32 = .{profile.length, profile.counter, cast(s32)profile.lower, cast(s32)profile.upper, cast(s32)profile.digits, cast(s32)profile.symbols}
|
||||
for number_index: 0..5 {
|
||||
buffer: [32]u8
|
||||
used = AppendText(store_buffer[:], used, "\t")
|
||||
used = AppendText(store_buffer[:], used, FormatInteger(cast(s64)values[number_index], buffer[:]))
|
||||
}
|
||||
used = AppendText(store_buffer[:], used, "\t")
|
||||
used = AppendText(store_buffer[:], used, TextUntilNul(profile.exclude[:]))
|
||||
used = AppendText(store_buffer[:], used, "\n")
|
||||
if used < 0 { SetStatus("Could not save profiles"); return false }
|
||||
index += 1
|
||||
}
|
||||
if !WriteStore("profiles.tsv", TextView(store_buffer[0:used])) { SetStatus("Could not save profiles"); return false }
|
||||
return true
|
||||
}
|
||||
|
||||
SaveProfile :: (profile: Profile) -> bool {
|
||||
candidate := profile
|
||||
name := TextUntilNul(candidate.name[:])
|
||||
if name == "" { SetStatus("Profile name required"); return false }
|
||||
if !SafeField(name) || !SafeField(TextUntilNul(candidate.site[:])) || !SafeField(TextUntilNul(candidate.login[:])) || !SafeField(TextUntilNul(candidate.exclude[:])) { SetStatus("Profile fields cannot contain tabs or newlines"); return false }
|
||||
index: s32 = 0
|
||||
while index < runtime.profile_count {
|
||||
if TextUntilNul(runtime.profiles[index].name[:]) == name { break }
|
||||
index += 1
|
||||
}
|
||||
if index >= 64 { SetStatus("Profile limit reached"); return false }
|
||||
original := runtime.profiles[index]
|
||||
original_count := runtime.profile_count
|
||||
runtime.profiles[index] = candidate
|
||||
if index == runtime.profile_count { runtime.profile_count += 1 }
|
||||
if !WriteProfiles() { runtime.profiles[index] = original; runtime.profile_count = original_count; return false }
|
||||
SetStatus("Profile saved"); return true
|
||||
}
|
||||
|
||||
DeleteProfile :: (index: s32) -> bool {
|
||||
if index < 0 || index >= runtime.profile_count { SetStatus("Profile not found"); return false }
|
||||
original := runtime.profiles
|
||||
count := runtime.profile_count
|
||||
position := index
|
||||
while position + 1 < runtime.profile_count { runtime.profiles[position] = runtime.profiles[position + 1]; position += 1 }
|
||||
runtime.profile_count -= 1
|
||||
if !WriteProfiles() { runtime.profiles = original; runtime.profile_count = count; return false }
|
||||
runtime.profiles[runtime.profile_count] = Profile.{}
|
||||
SetStatus("Profile deleted"); return true
|
||||
}
|
||||
|
||||
GenerateProfile :: (index: s32, master: string) -> bool {
|
||||
if index < 0 || index >= runtime.profile_count { SetStatus("Profile not found"); return false }
|
||||
profile := runtime.profiles[index]
|
||||
options := ProfileOptions(profile)
|
||||
options.exclude = TextUntilNul(profile.exclude[:])
|
||||
return Generate(TextUntilNul(profile.site[:]), TextUntilNul(profile.login[:]), master, options)
|
||||
}
|
||||
|
||||
SaveMaster :: (master: string) -> bool {
|
||||
if master == "" { SetStatus("Enter master password first"); return false }
|
||||
if !SecureAvailable() { SetStatus("Device authentication unavailable"); return false }
|
||||
if !SecureRequest(master, true) { SetStatus("Secure master failed"); return false }
|
||||
runtime.secure_action = 1; SetStatus("Saving master"); return true
|
||||
}
|
||||
UnlockMaster :: () -> bool {
|
||||
if !SecureSaved() { SetStatus("No saved master password"); return false }
|
||||
if !SecureRequest("", false) { SetStatus("Secure master failed"); return false }
|
||||
runtime.secure_action = 2; SetStatus("Unlock requested"); return true
|
||||
}
|
||||
ForgetMaster :: () -> bool {
|
||||
if !SecureForget() { SetStatus("Could not forget saved master"); return false }
|
||||
runtime.unlocked_master = .{}
|
||||
runtime.has_unlocked_master = false; runtime.secure_action = 0
|
||||
SetStatus("Saved master forgotten"); return true
|
||||
}
|
||||
FingerprintStatus :: () -> string {
|
||||
if !SecureAvailable() { return "Device authentication is not available" }
|
||||
if SecureSaved() { return "Saved master uses device authentication" }
|
||||
return "No saved master password"
|
||||
}
|
||||
HasSavedMaster :: () -> bool { return SecureSaved() }
|
||||
CanSaveMaster :: () -> bool { return SecureAvailable() }
|
||||
|
||||
Tick :: () {
|
||||
buffer: [1024]u8
|
||||
result := SecurePoll(buffer[:])
|
||||
if result == 2 {
|
||||
if runtime.secure_action == 2 {
|
||||
runtime.unlocked_master = buffer
|
||||
runtime.has_unlocked_master = true
|
||||
SetStatus("Master unlocked")
|
||||
} else {
|
||||
SetStatus("Master password saved")
|
||||
}
|
||||
runtime.secure_action = 0
|
||||
}
|
||||
if result == 3 { SetStatus("Secure master failed or cancelled"); runtime.secure_action = 0 }
|
||||
for index: 0..1023 { buffer[index] = cast(u8)0 }
|
||||
}
|
||||
Initialize :: () {
|
||||
runtime = Runtime.{}
|
||||
runtime.settings = DefaultSettings()
|
||||
SetStatus("Ready")
|
||||
LoadSettings(); LoadProfiles()
|
||||
}
|
||||
Shutdown :: () {
|
||||
runtime.generated = .{}; runtime.unlocked_master = .{}
|
||||
runtime.has_unlocked_master = false
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#import "c_string"
|
||||
#import "text_buffer"
|
||||
|
||||
ClearBytes :: (bytes: []u8) {
|
||||
at: s32 = 0
|
||||
while at < cast(s32)bytes.count { bytes[at] = cast(u8)0; at += 1 }
|
||||
}
|
||||
|
||||
CopyText :: (value: string, output: []u8) -> bool {
|
||||
if output.count == 0 { return false }
|
||||
if value.count >= output.count { return false }
|
||||
return CopyCString(value, output)
|
||||
}
|
||||
|
||||
AppendText :: (output: []u8, used: s32, value: string) -> s32 {
|
||||
if used < 0 || cast(s64)used + cast(s64)value.count >= cast(s64)output.count { return -1 }
|
||||
index: s32 = 0
|
||||
while index < cast(s32)value.count {
|
||||
output[used + index] = value[index]
|
||||
index += 1
|
||||
}
|
||||
used += cast(s32)value.count
|
||||
output[used] = cast(u8)0
|
||||
return used
|
||||
}
|
||||
|
||||
Number :: struct { valid: bool; value: s64; }
|
||||
|
||||
ParseNumber :: (text: string) -> Number {
|
||||
result: Number
|
||||
if text.count == 0 { return result }
|
||||
index: s32 = 0
|
||||
negative: bool = text[0] == cast(u8)45
|
||||
if negative || text[0] == cast(u8)43 { index = 1 }
|
||||
if index == cast(s32)text.count { return result }
|
||||
while index < cast(s32)text.count {
|
||||
byte: u8 = text[index]
|
||||
if byte < cast(u8)48 || byte > cast(u8)57 { return result }
|
||||
digit: s64 = cast(s64)(byte - cast(u8)48)
|
||||
if result.value > (9223372036854775807 - digit) / 10 { return Number.{} }
|
||||
result.value = result.value * 10 + digit
|
||||
index += 1
|
||||
}
|
||||
if negative { result.value = 0 - result.value }
|
||||
result.valid = true
|
||||
return result
|
||||
}
|
||||
|
||||
SafeField :: (value: string) -> bool {
|
||||
index: s32 = 0
|
||||
while index < cast(s32)value.count {
|
||||
if value[index] == cast(u8)0 || value[index] == cast(u8)9 ||
|
||||
value[index] == cast(u8)10 || value[index] == cast(u8)13 { return false }
|
||||
index += 1
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 208 KiB |
@@ -1,39 +0,0 @@
|
||||
<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>
|
||||
|
Before Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 485 KiB After Width: | Height: | Size: 84 KiB |
|
Before Width: | Height: | Size: 283 KiB After Width: | Height: | Size: 20 KiB |
@@ -0,0 +1,94 @@
|
||||
Copyright 2022 The Noto Project Authors (https://github.com/notofonts/)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License,
|
||||
Version 1.1.
|
||||
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font
|
||||
creation efforts of academic and linguistic communities, and to
|
||||
provide a free and open framework in which fonts may be shared and
|
||||
improved in partnership with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply to
|
||||
any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software
|
||||
components as distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to,
|
||||
deleting, or substituting -- in part or in whole -- any of the
|
||||
components of the Original Version, by changing formats or by porting
|
||||
the Font Software to a new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed,
|
||||
modify, redistribute, and sell modified and unmodified copies of the
|
||||
Font Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components, in
|
||||
Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the
|
||||
corresponding Copyright Holder. This restriction only applies to the
|
||||
primary font name as presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created using
|
||||
the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
@@ -0,0 +1,214 @@
|
||||
# Werkzeug development and data
|
||||
|
||||
[Back to Werkzeug](../README.md).
|
||||
|
||||
## Privacy
|
||||
|
||||
Everything is computed on the device. Werkzeug makes no network requests
|
||||
unless you set up sync or explicitly request an account or device-link action.
|
||||
Each tool keeps its own files, readable only by your user:
|
||||
|
||||
| Platform | Data |
|
||||
|---|---|
|
||||
| Linux | `$XDG_DATA_HOME/werk` (or `~/.local/share/werk`) |
|
||||
| Android | the app's private storage |
|
||||
| Browser | IndexedDB on this site |
|
||||
|
||||
Auth's accounts are synced records: `otpauth` links in the private
|
||||
`records/auth.txt`, protected by the file permissions of your account or the
|
||||
Android app sandbox.
|
||||
|
||||
## Sync
|
||||
|
||||
Profile uses the shared Self bundle. Desktop Account management shows the
|
||||
public ID, alias, sync status and queued changes, and provides account creation,
|
||||
key-file import, backups, device linking and logout. Switching accounts asks
|
||||
whether to keep and merge local Auth records or replace them. A private rollback
|
||||
journal preserves the previous key and records if a switch is interrupted.
|
||||
|
||||
The account can use a [Daochi](https://github.com/kryonlabs/daochi) node,
|
||||
`api.waozi.xyz` by default. Tools work locally without an account. Saved nodes
|
||||
and the preferred node live in Profile → Nodes; choosing a node preserves the
|
||||
account and its paused state. The sync switch pauses automatic synchronization
|
||||
and stays paused after restarting. Logout keeps local Auth records.
|
||||
|
||||
Desktop key backups retain Werkzeug's Auth vault key as protected recovery
|
||||
context. Use a passphrase to encrypt the backup. Importing a legacy account key
|
||||
for the already-connected identity preserves its existing vault key. The shared
|
||||
QR workflow also preserves that context and asks both devices to compare digits
|
||||
before connecting. Legacy clients cannot read the extended QR payload when
|
||||
Werkzeug vault context is included.
|
||||
|
||||
Desktop Self and participating native apps share public profile preferences only
|
||||
for the same verified account ID. Account keys and Auth records stay in the
|
||||
host's private store. Android retains its existing native Account screen and
|
||||
legacy device-link flow. In the browser, Profile opens the shared manager at
|
||||
https://entity.waozi.xyz. Public name, picture and appearance follow the active
|
||||
waozi.xyz profile. Werkzeug's browser tool data stays local; account sync for
|
||||
those tool records is unavailable.
|
||||
|
||||
The embedded web app (`/app/?mini`) shows only the tools, as large tiles,
|
||||
with no Profile; `werk --mini` does the same on the desktop. Use
|
||||
`?mini&app=pass`, `auth`, `calculator` or `clock` to open a particular tool
|
||||
first; Back returns to the tiles. Browser sync is currently unavailable.
|
||||
|
||||
- Each record is sealed on the device with XChaCha20-Poly1305 under a random
|
||||
vault key that is never sent to the node unencrypted. The seal covers the
|
||||
account, the record and the time of the change, so the server can neither
|
||||
read nor alter a record or a removal.
|
||||
- The account key (ML-DSA-44) signs in and signs each sync together with
|
||||
the device's own Ed25519 key.
|
||||
- Desktop device linking uses the shared Self QR/code exchange with X25519
|
||||
and encrypted key transfer. Confirm the matching number on both devices.
|
||||
Android's existing 12-character connection code remains available in its
|
||||
native account screen.
|
||||
- The server can still withhold changes or serve an older copy to a device
|
||||
that has not seen a newer one. A lost device keeps the keys it had: stop
|
||||
syncing there if you can, and replace two-factor secrets you care about.
|
||||
|
||||
`scripts/sync_e2e_test.sh` runs two devices against a local Daochi node.
|
||||
|
||||
## The `werk sync` and `werk auth` commands
|
||||
|
||||
On Linux, the same data works without a window, for devices without a
|
||||
screen and for scripts:
|
||||
|
||||
```text
|
||||
werk sync status | create | show | join [CODE] | key [FILE] | now
|
||||
werk auth list
|
||||
werk auth code ID
|
||||
werk auth import [FILE]
|
||||
werk auth rename ID SERVICE ACCOUNT
|
||||
werk auth sites ID [WEBSITE ...]
|
||||
werk auth remove ID
|
||||
```
|
||||
|
||||
`werk sync show` prints a code for another device to enter; `werk sync join`
|
||||
reads one from its argument or standard input. `werk sync key` signs in with
|
||||
an account key from FILE or standard input; for a key with a passphrase, give
|
||||
FILE and the passphrase on standard input. `werk auth list` prints the
|
||||
accounts as JSON with their ids and websites, never their secrets.
|
||||
`werk auth code ID` prints the current code and the seconds it stays valid.
|
||||
`werk auth import` reads a file, or standard input: otpauth links, Google
|
||||
Authenticator export links, an unencrypted Aegis export, or a PNG or JPEG of
|
||||
an export's QR code when GdkPixbuf and ZBar (`libzbar0`) are installed.
|
||||
Changes sync right away when the device has an account. `werk --app auth`
|
||||
opens the window on one tool, as Harmony's Auth entry does.
|
||||
|
||||
## Tools are separate apps
|
||||
|
||||
Each tool is built into its own portable bundle, `build/apps/<tool>.zx`:
|
||||
Pass, Calculator and Clock from `apps/<tool>/`, Auth from its own Ziran
|
||||
package ([waozixyz/auth](https://github.com/waozixyz/auth)), and Workbook from
|
||||
[waozixyz/workbook](https://github.com/waozixyz/workbook). All five are
|
||||
preinstalled. A tool reaches the host only through Kryon's app context (its
|
||||
private files, clipboard, clock, key derivation and device-protected
|
||||
secret), and the host checks every call a bundle asks for before it runs.
|
||||
Tools never import each other; what two need, such as SHA-256 and PBKDF2,
|
||||
comes from a Ziran package (`crypto`).
|
||||
|
||||
## Build and test
|
||||
|
||||
Dependencies and the compiler are pinned in `ziran.lock`. Desktop builds need
|
||||
SDL2, Cairo, FreeType, Fontconfig, Pango, GTK 3 and X11 development packages.
|
||||
Workbook uses its built-in spreadsheet engine on Android and the web; Linux
|
||||
also uses the installed Gnumeric library for imported documents. Linux file choosers need Zenity. Browser
|
||||
builds need Emscripten; Android builds need JDK 21 and the SDK/NDK versions in
|
||||
`droid/app/build.gradle`. Desktop tests use Xvfb, xdotool, xclip and
|
||||
ImageMagick on private displays.
|
||||
|
||||
```sh
|
||||
make gui # build/werk and the app bundles in build/apps
|
||||
make install-gui # Werkzeug and each tool in the app menu and on the desktop
|
||||
make test # Pass/CLI, Auth, Calculator and private account recovery fixtures
|
||||
make gui-smoke # light and dark home screens on a private Xvfb display
|
||||
make gui-test # every tool, clipboard and profile on a private display,
|
||||
# and werk auth without one
|
||||
make site # build/site: browser app and offline worker
|
||||
make web-smoke # private headless Chromium
|
||||
make android-debug # ARM32, ARM64 and universal APKs
|
||||
make android-fdroid # unsigned F-Droid candidate, same Android ID and version
|
||||
make android-emulator # the x86_64 APK for a private emulator
|
||||
```
|
||||
|
||||
Linux installs include separate Pass, Auth, Calculator, Clock and Workbook
|
||||
launchers, each with its own icon. They open the selected tool directly and
|
||||
share Werkzeug's existing private data. `make install-gui` also adds shortcuts
|
||||
to the desktop folder configured by `xdg-user-dir`; set `DESKTOP_DIR=` to skip
|
||||
those shortcuts. Debian packages include the same application-menu entries.
|
||||
|
||||
F-Droid metadata is maintained in `packaging/fdroid`. The `android-fdroid`
|
||||
target disables developer signing even when a release keystore is configured
|
||||
and writes `build/fdroid/werk.apk` for comparison with the signed release. It adds no version or
|
||||
package suffix, preserving existing installations and reference-APK checks.
|
||||
The unsigned candidate is for builders, not installation. Werkzeug currently
|
||||
has no built-in updater: F-Droid or your chosen installer handles updates.
|
||||
Android requires the same signing certificate for an in-place update; the
|
||||
F-Droid recipe retains the developer-signature reproducibility requirement.
|
||||
|
||||
The [F-Droid TODO](../packaging/fdroid/TODO.md) records completed checks, the
|
||||
remaining submission/reproducibility steps and the prepared merge-request text.
|
||||
|
||||
For development with the real project repositories, create an ignored
|
||||
`ziran.local.toml`:
|
||||
|
||||
```toml
|
||||
[overrides]
|
||||
kryon = "../../kryonlabs/kryon"
|
||||
ziran = "../../ziranlang/ziran"
|
||||
```
|
||||
|
||||
## The `pass` command
|
||||
|
||||
```text
|
||||
pass [OPTIONS] SITE LOGIN [MASTER_PASSWORD]
|
||||
pass [OPTIONS] PROFILE SITE
|
||||
```
|
||||
|
||||
`make cli` builds it and `make install-cli` installs it. The default password
|
||||
has 16 characters and includes lowercase letters, 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 one line from standard input. Use
|
||||
`--prompt` to bypass the environment and read from standard input:
|
||||
|
||||
```sh
|
||||
pass --prompt example.com alice
|
||||
pass --length 24 --counter 2 example.com alice
|
||||
pass --no-symbols --exclude '0O1Il' example.com alice
|
||||
```
|
||||
|
||||
The Linux CLI also reads saved identities from
|
||||
`$XDG_CONFIG_HOME/pass/profiles.json` (or `~/.config/pass/profiles.json`).
|
||||
`pass w example.com` and `pass --profile w example.com` use the saved login
|
||||
and generation options. Existing OpenSSL-encrypted vaults are unlocked with
|
||||
a hidden `Vault passphrase:` prompt. A configured vault takes precedence over
|
||||
`LESSPASS_MASTER_PASSWORD`; `--prompt` bypasses it. Explicit flags override
|
||||
profile defaults. Profiles and vaults are read without changing them.
|
||||
|
||||
`--copy` or a profile's `copy` setting copies through `xclip` on X11;
|
||||
`--clear-after 90s` releases that clipboard selection after the given time
|
||||
without erasing a later copy from another application. Use `--no-copy` to
|
||||
print the generated password instead. Run `pass --help` for all flags.
|
||||
|
||||
## Source layout
|
||||
|
||||
```text
|
||||
apps/pass/ Pass: LessPass core, settings and profiles, screens, CLI
|
||||
auth (package) Auth: TOTP, otpauth links, exports, accounts and screens (waozixyz/auth)
|
||||
apps/calculator/ Calculator
|
||||
apps/clock/ Clock and stopwatch
|
||||
src/werk.zi home screen, profile screen and the bar above a tool
|
||||
src/apps.zi loads, checks and runs the app bundles
|
||||
src/platform.zi files, clock, clipboard and secrets per platform
|
||||
src/desktop.zi, src/android_main.zi, src/browser.zi platform main loops
|
||||
src/command.zi werk sync and werk auth without a window
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Copyright © 2026 Waozi. Distributed under the BSD 3-Clause License. See
|
||||
[`LICENSE`](../LICENSE).
|
||||
@@ -7,15 +7,6 @@ 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
|
||||
}
|
||||
|
||||
def keystorePropsFile = rootProject.file("local.properties")
|
||||
def keystoreProps = new Properties()
|
||||
if (keystorePropsFile.exists()) {
|
||||
@@ -23,16 +14,17 @@ android {
|
||||
}
|
||||
|
||||
def getKeystorePath = { -> project.findProperty('keystore.path') ?: keystoreProps['keystore.path'] ?: System.getenv("HOME") + "/.android/pass-release.keystore" }
|
||||
def getKeystoreAlias = { -> project.findProperty('keystore.alias') ?: keystoreProps['keystore.alias'] ?: "pass-key" }
|
||||
def getKeystoreAlias = { -> project.findProperty('keystore.alias') ?: keystoreProps['keystore.alias'] ?: System.getenv('KEY_ALIAS') ?: "pass-key" }
|
||||
|
||||
def releasePassword = project.findProperty('keystore.password') ?: ""
|
||||
def releasePassword = project.findProperty('keystore.password') ?: System.getenv('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') \
|
||||
def fdroidBuild = (project.findProperty('fDroidBuild') ?: 'false').toString().toBoolean()
|
||||
def signRelease = !fdroidBuild \
|
||||
&& releaseKeystore != null && releaseKeystore.exists() \
|
||||
&& releasePassword != ""
|
||||
|
||||
@@ -51,9 +43,8 @@ android {
|
||||
applicationId 'xyz.waozi.pass'
|
||||
minSdk 21
|
||||
targetSdk 36
|
||||
versionCode 10
|
||||
versionName "0.2.9"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
versionCode 21
|
||||
versionName "0.4.7"
|
||||
// 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'
|
||||
@@ -89,6 +80,7 @@ android {
|
||||
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
includeInBundle = false
|
||||
}
|
||||
|
||||
packaging {
|
||||
@@ -98,8 +90,32 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
androidTestImplementation 'androidx.test:runner:1.6.2'
|
||||
androidTestImplementation 'androidx.test:rules:1.6.1'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
|
||||
// Bundle fonts without adding app or host Java code.
|
||||
def prepareFonts = tasks.register('prepareFonts', Copy) {
|
||||
into layout.buildDirectory.dir('generated/passAssets/fonts')
|
||||
from('../../assets/fonts/NotoSans-Regular.ttf') { rename { 'ui.ttf' } }
|
||||
from('../../assets/fonts/NotoSans-OFL.txt')
|
||||
from('../../assets/fonts/emoji.ttf')
|
||||
from('../../assets/fonts/emoji-OFL.txt')
|
||||
}
|
||||
android.sourceSets.main.assets.srcDir(layout.buildDirectory.dir('generated/passAssets'))
|
||||
tasks.named('preBuild').configure { dependsOn prepareFonts }
|
||||
|
||||
// The tool apps are portable bundles, built once for every ABI.
|
||||
def makeApps = tasks.register('makeApps', Exec) {
|
||||
workingDir '../..'
|
||||
commandLine 'make', 'portable-apps'
|
||||
}
|
||||
def kryonSource = providers.exec {
|
||||
workingDir '../..'
|
||||
commandLine rootProject.file('../scripts/ziran.sh').absolutePath, 'pkg', 'path', 'kryon'
|
||||
}.standardOutput.asText.map { it.trim() }
|
||||
android.sourceSets.main.assets.srcDir(layout.buildDirectory.dir('generated/appAssets'))
|
||||
def prepareImages = tasks.register('prepareImages', Sync) {
|
||||
dependsOn makeApps
|
||||
from('../../assets/app/icon.png')
|
||||
from(kryonSource.map { "${it}/icons/pfp.png" })
|
||||
from('../../build/apps') { include '*.zx'; into 'apps' }
|
||||
into layout.buildDirectory.dir('generated/appAssets')
|
||||
}
|
||||
tasks.named('preBuild').configure { dependsOn prepareImages }
|
||||
@@ -1,62 +0,0 @@
|
||||
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());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?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>
|
||||
@@ -1,81 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -2,32 +2,25 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
|
||||
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
||||
<!-- Only for sync, which is off until the owner sets up an account. -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:hasCode="true"
|
||||
android:hasCode="false"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:allowBackup="false">
|
||||
<activity
|
||||
android:name="xyz.waozi.pass.PassActivity"
|
||||
android:name="android.app.NativeActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize|smallestScreenSize|uiMode"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask"
|
||||
android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
|
||||
android:windowSoftInputMode="adjustNothing"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
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" />
|
||||
|
||||
@@ -1,189 +1,97 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
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"
|
||||
"${KRYON_DIR}/src/scene/node_body2d.c"
|
||||
"${KRYON_DIR}/src/scene/node_area2d.c"
|
||||
"${KRYON_DIR}/src/scene/node_collision_shape2d.c")
|
||||
# Ksync account crypto requires liboqs and pass never syncs; runtime asset
|
||||
# downloads need an Android download backend pass does not provide.
|
||||
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 "assets/fonts/emoji.ttf")
|
||||
set(PASS_EMBEDDED_ASSETS_C "${CMAKE_BINARY_DIR}/pass_embedded_assets.c")
|
||||
add_custom_command(
|
||||
OUTPUT "${PASS_EMBEDDED_ASSETS_C}"
|
||||
COMMAND sh "${KRYON_DIR}/scripts/embed-assets.sh" "${PASS_EMBEDDED_ASSETS_C}" "${PASS_FONT_ASSET}" "${PASS_EMOJI_FONT_ASSET}"
|
||||
DEPENDS "${KRYON_DIR}/scripts/embed-assets.sh" "${KRYON_DIR}/fonts/noto/NotoSans-Regular.ttf" "${REPO_ROOT}/${PASS_EMOJI_FONT_ASSET}"
|
||||
WORKING_DIRECTORY "${REPO_ROOT}"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
add_library(raylib STATIC
|
||||
"${RAYLIB_DIR}/rcore.c"
|
||||
"${RAYLIB_DIR}/rshapes.c"
|
||||
"${RAYLIB_DIR}/rtextures.c"
|
||||
"${RAYLIB_DIR}/rtext.c"
|
||||
"${RAYLIB_DIR}/raudio.c"
|
||||
)
|
||||
add_dependencies(raylib kryon_raylib_generated)
|
||||
|
||||
target_compile_definitions(raylib PRIVATE
|
||||
PLATFORM_ANDROID
|
||||
GRAPHICS_API_OPENGL_ES2
|
||||
SUPPORT_SCREEN_CAPTURE=0
|
||||
SUPPORT_COMPRESSION_API=0
|
||||
SUPPORT_AUTOMATION_EVENTS=0
|
||||
SUPPORT_CLIPBOARD_IMAGE=0
|
||||
SUPPORT_FILEFORMAT_BMP=0
|
||||
SUPPORT_FILEFORMAT_GIF=0
|
||||
SUPPORT_FILEFORMAT_QOI=0
|
||||
SUPPORT_FILEFORMAT_DDS=0
|
||||
SUPPORT_FILEFORMAT_TTF=1
|
||||
SUPPORT_FILEFORMAT_JPG=1
|
||||
SUPPORT_FILEFORMAT_PNG=1
|
||||
SUPPORT_FILEFORMAT_OGG=1
|
||||
SUPPORT_MODULE_RAUDIO=1
|
||||
)
|
||||
|
||||
target_compile_options(raylib PRIVATE
|
||||
-include "${KRYON_RAYLIB_BACKEND_RENAME_HEADER}"
|
||||
-Os
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
)
|
||||
|
||||
target_include_directories(raylib PUBLIC
|
||||
"${RAYLIB_DIR}"
|
||||
"${NATIVE_APP_GLUE_DIR}"
|
||||
)
|
||||
|
||||
add_library(main SHARED
|
||||
main.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}"
|
||||
)
|
||||
|
||||
target_compile_definitions(main PRIVATE
|
||||
PLATFORM_ANDROID
|
||||
ANDROID_BUILD=1
|
||||
_DEFAULT_SOURCE
|
||||
_GNU_SOURCE
|
||||
_FILE_OFFSET_BITS=64
|
||||
UI_EMBEDDED_ONLY=1
|
||||
KRYON_WITH_PHYSICS=0
|
||||
)
|
||||
|
||||
target_compile_options(main PRIVATE
|
||||
-Os
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
-fvisibility=hidden
|
||||
)
|
||||
|
||||
target_link_options(main PRIVATE
|
||||
-Wl,--gc-sections
|
||||
-Wl,--strip-all
|
||||
-Wl,--wrap=fopen
|
||||
-Wl,-z,max-page-size=16384
|
||||
-Wl,-z,common-page-size=16384
|
||||
)
|
||||
|
||||
target_link_libraries(main
|
||||
raylib
|
||||
android
|
||||
log
|
||||
OpenSLES
|
||||
EGL
|
||||
GLESv2
|
||||
m
|
||||
)
|
||||
project(Werkzeug C)
|
||||
get_filename_component(REPO_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../../../.." ABSOLUTE)
|
||||
set(ZIRAN "${REPO_ROOT}/scripts/ziran.sh")
|
||||
if(DEFINED ENV{WERK_ZIRAN_COMMAND} AND NOT "$ENV{WERK_ZIRAN_COMMAND}" STREQUAL "")
|
||||
get_filename_component(ZIRAN "$ENV{WERK_ZIRAN_COMMAND}" ABSOLUTE BASE_DIR "${REPO_ROOT}")
|
||||
endif()
|
||||
set(GENERATED "${CMAKE_BINARY_DIR}/ziran")
|
||||
set(DEFINES --define ANDROID_BUILD)
|
||||
if(ANDROID_ABI STREQUAL "arm64-v8a")
|
||||
list(APPEND DEFINES --define __aarch64__)
|
||||
elseif(ANDROID_ABI STREQUAL "armeabi-v7a")
|
||||
list(APPEND DEFINES --define __arm__)
|
||||
elseif(ANDROID_ABI STREQUAL "x86_64")
|
||||
list(APPEND DEFINES --define __x86_64__)
|
||||
elseif(ANDROID_ABI STREQUAL "x86")
|
||||
list(APPEND DEFINES --define __i386__)
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported Android ABI: ${ANDROID_ABI}")
|
||||
endif()
|
||||
set(LOCK_FLAGS --locked)
|
||||
if(EXISTS "${REPO_ROOT}/ziran.local.toml")
|
||||
set(LOCK_FLAGS)
|
||||
endif()
|
||||
# Plain Gradle builds resolve the same packages as Make. F-Droid needs no
|
||||
# source patches or machine-specific environment variables in its recipe.
|
||||
function(werk_package variable package suffix)
|
||||
if(NOT "$ENV{${variable}}" STREQUAL "")
|
||||
set(path "$ENV{${variable}}")
|
||||
else()
|
||||
execute_process(COMMAND "${ZIRAN}" pkg path "${package}" ${LOCK_FLAGS}
|
||||
WORKING_DIRECTORY "${REPO_ROOT}" OUTPUT_VARIABLE path
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY)
|
||||
string(APPEND path "${suffix}")
|
||||
endif()
|
||||
set(${variable} "${path}" CACHE PATH "Locked ${package} source" FORCE)
|
||||
endfunction()
|
||||
werk_package(KRYON_DIR kryon "")
|
||||
werk_package(ZIRAN_ROOT ziran "")
|
||||
werk_package(RAYLIB_DIR raylib "/src")
|
||||
werk_package(LIBOQS_DIR liboqs "")
|
||||
werk_package(MONOCYPHER_DIR monocypher "")
|
||||
werk_package(WORKBOOK_DIR workbook "")
|
||||
file(GLOB_RECURSE SOURCE_INPUTS CONFIGURE_DEPENDS
|
||||
"${REPO_ROOT}/src/*.zi" "${WORKBOOK_DIR}/src/*.zi" "${KRYON_DIR}/src/*.zi" "${ZIRAN_ROOT}/std/*.zi")
|
||||
list(APPEND SOURCE_INPUTS "${REPO_ROOT}/ziran.toml" "${REPO_ROOT}/ziran.lock" "${REPO_ROOT}/scripts/runtime_cache.py")
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${SOURCE_INPUTS})
|
||||
execute_process(COMMAND "${ZIRAN}" build --project ${LOCK_FLAGS} ${DEFINES}
|
||||
# Native linker callbacks are reached through raylib, outside Zi's entry
|
||||
# graph. Keep them as the shared Android source generator does.
|
||||
--target=c --no-main -o "${GENERATED}" src/android_main.zi
|
||||
WORKING_DIRECTORY "${REPO_ROOT}" COMMAND_ERROR_IS_FATAL ANY)
|
||||
file(GLOB GENERATED_SOURCES CONFIGURE_DEPENDS "${GENERATED}/*.c")
|
||||
# Kryon's Android glue compiles its thread configurator with the same zi2c.
|
||||
foreach(candidate "${ZIRAN_ROOT}/build/bin/zi2c" "${REPO_ROOT}/build/ziran-bootstrap/build/bin/zi2c")
|
||||
if(NOT ZI2C_BIN AND EXISTS "${candidate}")
|
||||
set(ZI2C_BIN "${candidate}")
|
||||
endif()
|
||||
endforeach()
|
||||
include("${KRYON_DIR}/cmake/KryonAndroid.cmake")
|
||||
kryon_android_raylib("${RAYLIB_DIR}")
|
||||
# The portable runtime that runs the app bundles, built from the locked Ziran
|
||||
# for this ABI.
|
||||
set(BUNDLE_RUNTIME_DIR "${CMAKE_BINARY_DIR}/bundle-runtime")
|
||||
execute_process(COMMAND python3 "${REPO_ROOT}/scripts/runtime_cache.py" "${ZIRAN_ROOT}" "${BUNDLE_RUNTIME_DIR}"
|
||||
COMMAND_ERROR_IS_FATAL ANY)
|
||||
execute_process(COMMAND make -C "${ZIRAN_ROOT}" BOOTSTRAP=1 "BUILD_DIR=${BUNDLE_RUNTIME_DIR}"
|
||||
"CC=${CMAKE_C_COMPILER} --target=${CMAKE_C_COMPILER_TARGET} --sysroot=${CMAKE_SYSROOT}"
|
||||
"AR=${CMAKE_AR}" "OBJCOPY=${CMAKE_OBJCOPY}" "CFLAGS=-O2 -fPIC"
|
||||
"FRAMEFLAGS=-Wframe-larger-than=16384" "${BUNDLE_RUNTIME_DIR}/libziran.a"
|
||||
COMMAND_ERROR_IS_FATAL ANY)
|
||||
# Account sync: liboqs for ML-DSA-44 account keys, Monocypher for the rest.
|
||||
set(OQS_BUILD_ONLY_LIB ON CACHE BOOL "" FORCE)
|
||||
set(OQS_USE_OPENSSL OFF CACHE BOOL "" FORCE)
|
||||
set(OQS_MINIMAL_BUILD "SIG_ml_dsa_44" CACHE STRING "" FORCE)
|
||||
set(OQS_DIST_BUILD OFF CACHE BOOL "" FORCE)
|
||||
set(OQS_OPT_TARGET generic CACHE STRING "" FORCE)
|
||||
foreach(oqs_x86_feature
|
||||
ADX AES AVX AVX2 AVX512 AVX512BW AVX512DQ AVX512F
|
||||
BMI1 BMI2 FMA PCLMULQDQ POPCNT SSE SSE2 SSE3 VPCLMULQDQ)
|
||||
set(OQS_USE_${oqs_x86_feature}_INSTRUCTIONS OFF CACHE BOOL "" FORCE)
|
||||
endforeach()
|
||||
add_subdirectory("${LIBOQS_DIR}" "${CMAKE_BINARY_DIR}/liboqs")
|
||||
add_library(main SHARED ${GENERATED_SOURCES}
|
||||
"${MONOCYPHER_DIR}/src/monocypher.c" "${MONOCYPHER_DIR}/src/optional/monocypher-ed25519.c")
|
||||
target_include_directories(main PRIVATE "${GENERATED}" "${ZIRAN_ROOT}/include"
|
||||
"${MONOCYPHER_DIR}/src" "${MONOCYPHER_DIR}/src/optional")
|
||||
target_link_libraries(main oqs)
|
||||
kryon_android_app(main)
|
||||
target_link_libraries(main "${BUNDLE_RUNTIME_DIR}/libziran.a")
|
||||
target_link_options(main PRIVATE -Wl,--wrap=pthread_attr_init)
|
||||
# Linker build IDs include debug-path differences even after stripping. The
|
||||
# installed code is identical; omit this note for reproducible signed APKs.
|
||||
# https://f-droid.org/docs/Reproducible_Builds/#ndk-build-id
|
||||
target_link_options(main PRIVATE -Wl,--build-id=none)
|
||||
# Werkzeug has no handwritten native sources; every app translation unit above is
|
||||
# generated from .zi for this ABI. raylib and the NDK own native_app_glue.
|
||||
@@ -1,136 +0,0 @@
|
||||
/* Android entry point for pass. Raylib's Android backend provides
|
||||
* android_main and calls main(); this file owns window, theme, fonts, and
|
||||
* the frame loop. */
|
||||
|
||||
#include "kryon.h"
|
||||
#include "embedded_assets.h"
|
||||
#include "ui_dpi.h"
|
||||
#include "ui_core.h"
|
||||
#include "ui_scaling.h"
|
||||
#include "ui_text.h"
|
||||
|
||||
#include "android_host.h"
|
||||
#include "app/pass.h"
|
||||
#include "pass_runtime.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if ANDROID_BUILD
|
||||
#include <android/log.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
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";
|
||||
|
||||
/* 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). */
|
||||
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)
|
||||
{
|
||||
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");
|
||||
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(window_width, window_height, "Pass");
|
||||
if(!IsWindowReady()) {
|
||||
TraceLog(LOG_ERROR, "PASS: InitWindow failed");
|
||||
return 1;
|
||||
}
|
||||
InitUIDPI();
|
||||
SetThemeStyle(THEME_STYLE_MATERIAL);
|
||||
SetCurrentTheme(GetDefaultThemeForThemeStyle(THEME_STYLE_MATERIAL), 0);
|
||||
AndroidHostApplySystemTheme();
|
||||
SetThemeMode(THEME_MODE_SYSTEM);
|
||||
SetThemeSource(THEME_SOURCE_SYSTEM);
|
||||
ApplyCurrentUITheme();
|
||||
setup_ui_font();
|
||||
setup_emoji_font();
|
||||
setup_shapes_texture();
|
||||
SetTextInputPlatformCallback(AndroidHostSetSoftKeyboardVisible);
|
||||
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;
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
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: 614 B After Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 598 B After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 627 B After Width: | Height: | Size: 7.5 KiB |
|
Before Width: | Height: | Size: 681 B After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 746 B After Width: | Height: | Size: 25 KiB |
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">Pass</string>
|
||||
<string name="app_name">Werkzeug</string>
|
||||
</resources>
|
||||
@@ -13,5 +13,5 @@ dependencyResolutionManagement {
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "pass"
|
||||
rootProject.name = "werk"
|
||||
include ':app'
|
||||
@@ -0,0 +1 @@
|
||||
- Introduce the purple password asterisk and keyhole logo across Pass, website icons, Android launchers, and app listings.
|
||||
@@ -0,0 +1,5 @@
|
||||
- Pass is now Werkzeug: a home screen of small private tools, each its own app and all preinstalled.
|
||||
- A new logo: a wrench with a keyhole. The website moves to werk.waozi.xyz.
|
||||
- Add Auth for two-factor sign-in codes from otpauth links or secret keys; copied codes clear after 30 seconds.
|
||||
- Add Calculator, and Clock with a stopwatch.
|
||||
- Add a profile with your name, a picture and the appearance every tool shares.
|
||||
@@ -0,0 +1 @@
|
||||
- Fix the web version on itch.io, which opened to a blank page.
|
||||
@@ -0,0 +1,6 @@
|
||||
- A new purple W logo.
|
||||
- Calculator gets a Scientific mode.
|
||||
- Auth imports Google Authenticator, Aegis and Ente Auth exports.
|
||||
- Rename an Auth account, note its websites, or remove it.
|
||||
- Choose your own Daochi node, and pause sync without losing your account.
|
||||
- Show π, √ and other symbols on phones older than Android 10.
|
||||
@@ -0,0 +1,3 @@
|
||||
- Open Pass, Auth, Calculator, Clock and Workbook directly from the Linux application menu, each with its own icon.
|
||||
- Desktop installs add shortcuts for Werkzeug and every tool to your configured desktop folder.
|
||||
- Tool windows show their own names and icons in the desktop switcher.
|
||||
@@ -0,0 +1,2 @@
|
||||
- Linux packages include the libraries needed for sync and importing QR-code pictures.
|
||||
- Packaging a new AppImage preserves previous downloads.
|
||||
@@ -0,0 +1,2 @@
|
||||
- Werkzeug uses its own Android application ID, `xyz.waozi.werk`.
|
||||
- Werkzeug installs alongside legacy Pass, preserving the older app and its data.
|
||||
@@ -0,0 +1,2 @@
|
||||
- Werkzeug updates the existing Pass Android app using its original application ID and signing certificate, keeping its saved data.
|
||||
- The app continues to appear as Werkzeug, with Pass, Auth, Calculator and Clock together.
|
||||
@@ -0,0 +1 @@
|
||||
- Fix Android opening to “Apps are unavailable”; Pass, Auth, Calculator and Clock load normally.
|
||||
@@ -0,0 +1 @@
|
||||
- Set an account alias with capitals, an @ or spaces; a taken alias now says so.
|
||||
@@ -0,0 +1,2 @@
|
||||
- Use Workbook on Android and the web as well as Linux, with formulas, sheet tabs, automatic saving and document import/export.
|
||||
- Navigate Workbook cells with touch controls, and keep Android's keyboard focused while editing a cell.
|
||||
@@ -1,17 +1,18 @@
|
||||
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.
|
||||
Werkzeug holds small private tools in one app. Everything is computed on your device and nothing is tracked. It makes no network requests unless you turn on sync.
|
||||
|
||||
Everything is computed locally. The app makes no network requests, keeps no accounts, and tracks nothing.
|
||||
• Pass derives strong, repeatable passwords. 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. It is LessPass-compatible, with configurable length, counter, character classes and excluded characters, and an optional master password kept behind device authentication.
|
||||
• Auth shows two-factor sign-in codes (TOTP with SHA-1, SHA-256 or SHA-512). Add accounts by secret key or from otpauth links, Google Authenticator export links, unencrypted Aegis exports or Ente Auth's plain-text export. Rename an account or note the websites where it signs in. Copied codes are cleared from the clipboard after 30 seconds. Optional sync keeps them on all your devices, encrypted on the device so the server never sees them.
|
||||
• Calculator handles everyday arithmetic with brackets, powers and percent, and has a Scientific mode with trigonometry, logarithms, roots, factorials, π and e.
|
||||
• Clock shows the local time and date and has a stopwatch.
|
||||
• Workbook edits spreadsheets with formulas, multiple sheets and automatic saving. Import or export a Gnumeric workbook through Android's file chooser, and use the same document on the desktop or web.
|
||||
|
||||
Features:
|
||||
A profile with your name and picture sets the appearance every tool shares.
|
||||
|
||||
• 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
|
||||
Every tool works without a Daochi account. In Profile → Sync you can choose your own node before connecting an account, or pause sync without forgetting your keys and local records. Sync stays off after restarting until you turn it on again.
|
||||
|
||||
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
|
||||
Source code: https://github.com/waozixyz/werk
|
||||
Website: https://werk.waozi.xyz
|
||||
|
||||
Licensed under BSD-3-Clause.
|
||||
|
After Width: | Height: | Size: 99 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 208 KiB |
|
Before Width: | Height: | Size: 62 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 87 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
Before Width: | Height: | Size: 88 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
Before Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 86 KiB |
@@ -1 +1 @@
|
||||
Deterministic passwords from site, login, and one master password.
|
||||
Private tools: deterministic passwords, 2FA codes, calculator and clock.
|
||||
@@ -1 +1 @@
|
||||
Pass
|
||||
Werkzeug
|
||||
@@ -1,15 +0,0 @@
|
||||
< /$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
|
||||
@@ -1,225 +0,0 @@
|
||||
#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,496 +0,0 @@
|
||||
/* 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"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char LOWERCASE_CHARACTERS[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
static const char UPPERCASE_CHARACTERS[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
static const char DIGIT_CHARACTERS[] = "0123456789";
|
||||
static const char SYMBOL_CHARACTERS[] = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* SHA-256 */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
typedef struct {
|
||||
uint32_t state[8];
|
||||
uint64_t bitlen;
|
||||
uint8_t buffer[64];
|
||||
size_t buffer_len;
|
||||
} Sha256;
|
||||
|
||||
static const uint32_t SHA256_K[64] = {
|
||||
0x428a2f98u, 0x71374491u, 0xb5c0fbcfu, 0xe9b5dba5u, 0x3956c25bu,
|
||||
0x59f111f1u, 0x923f82a4u, 0xab1c5ed5u, 0xd807aa98u, 0x12835b01u,
|
||||
0x243185beu, 0x550c7dc3u, 0x72be5d74u, 0x80deb1feu, 0x9bdc06a7u,
|
||||
0xc19bf174u, 0xe49b69c1u, 0xefbe4786u, 0x0fc19dc6u, 0x240ca1ccu,
|
||||
0x2de92c6fu, 0x4a7484aau, 0x5cb0a9dcu, 0x76f988dau, 0x983e5152u,
|
||||
0xa831c66du, 0xb00327c8u, 0xbf597fc7u, 0xc6e00bf3u, 0xd5a79147u,
|
||||
0x06ca6351u, 0x14292967u, 0x27b70a85u, 0x2e1b2138u, 0x4d2c6dfcu,
|
||||
0x53380d13u, 0x650a7354u, 0x766a0abbu, 0x81c2c92eu, 0x92722c85u,
|
||||
0xa2bfe8a1u, 0xa81a664bu, 0xc24b8b70u, 0xc76c51a3u, 0xd192e819u,
|
||||
0xd6990624u, 0xf40e3585u, 0x106aa070u, 0x19a4c116u, 0x1e376c08u,
|
||||
0x2748774cu, 0x34b0bcb5u, 0x391c0cb3u, 0x4ed8aa4au, 0x5b9cca4fu,
|
||||
0x682e6ff3u, 0x748f82eeu, 0x78a5636fu, 0x84c87814u, 0x8cc70208u,
|
||||
0x90befffau, 0xa4506cebu, 0xbef9a3f7u, 0xc67178f2u
|
||||
};
|
||||
|
||||
static uint32_t
|
||||
rotr32(uint32_t value, unsigned bits)
|
||||
{
|
||||
return (value >> bits) | (value << (32 - bits));
|
||||
}
|
||||
|
||||
static void
|
||||
sha256_init(Sha256 *ctx)
|
||||
{
|
||||
ctx->state[0] = 0x6a09e667u;
|
||||
ctx->state[1] = 0xbb67ae85u;
|
||||
ctx->state[2] = 0x3c6ef372u;
|
||||
ctx->state[3] = 0xa54ff53au;
|
||||
ctx->state[4] = 0x510e527fu;
|
||||
ctx->state[5] = 0x9b05688cu;
|
||||
ctx->state[6] = 0x1f83d9abu;
|
||||
ctx->state[7] = 0x5be0cd19u;
|
||||
ctx->bitlen = 0;
|
||||
ctx->buffer_len = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
sha256_block(Sha256 *ctx, const uint8_t block[64])
|
||||
{
|
||||
uint32_t w[64];
|
||||
uint32_t a, b, c, d, e, f, g, h;
|
||||
uint32_t t1, t2;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 16; i++)
|
||||
w[i] = ((uint32_t)block[i * 4] << 24) |
|
||||
((uint32_t)block[i * 4 + 1] << 16) |
|
||||
((uint32_t)block[i * 4 + 2] << 8) |
|
||||
(uint32_t)block[i * 4 + 3];
|
||||
for(i = 16; i < 64; i++) {
|
||||
uint32_t s0 = rotr32(w[i - 15], 7) ^ rotr32(w[i - 15], 18) ^ (w[i - 15] >> 3);
|
||||
uint32_t s1 = rotr32(w[i - 2], 17) ^ rotr32(w[i - 2], 19) ^ (w[i - 2] >> 10);
|
||||
w[i] = w[i - 16] + s0 + w[i - 7] + s1;
|
||||
}
|
||||
|
||||
a = ctx->state[0];
|
||||
b = ctx->state[1];
|
||||
c = ctx->state[2];
|
||||
d = ctx->state[3];
|
||||
e = ctx->state[4];
|
||||
f = ctx->state[5];
|
||||
g = ctx->state[6];
|
||||
h = ctx->state[7];
|
||||
|
||||
for(i = 0; i < 64; i++) {
|
||||
uint32_t s1 = rotr32(e, 6) ^ rotr32(e, 11) ^ rotr32(e, 25);
|
||||
uint32_t ch = (e & f) ^ (~e & g);
|
||||
t1 = h + s1 + ch + SHA256_K[i] + w[i];
|
||||
uint32_t s0 = rotr32(a, 2) ^ rotr32(a, 13) ^ rotr32(a, 22);
|
||||
uint32_t maj = (a & b) ^ (a & c) ^ (b & c);
|
||||
t2 = s0 + maj;
|
||||
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + t1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = t1 + t2;
|
||||
}
|
||||
|
||||
ctx->state[0] += a;
|
||||
ctx->state[1] += b;
|
||||
ctx->state[2] += c;
|
||||
ctx->state[3] += d;
|
||||
ctx->state[4] += e;
|
||||
ctx->state[5] += f;
|
||||
ctx->state[6] += g;
|
||||
ctx->state[7] += h;
|
||||
}
|
||||
|
||||
static void
|
||||
sha256_update(Sha256 *ctx, const void *data, size_t len)
|
||||
{
|
||||
const uint8_t *p = (const uint8_t *)data;
|
||||
|
||||
ctx->bitlen += (uint64_t)len * 8u;
|
||||
while(len > 0) {
|
||||
size_t take = 64 - ctx->buffer_len;
|
||||
|
||||
if(take > len)
|
||||
take = len;
|
||||
memcpy(ctx->buffer + ctx->buffer_len, p, take);
|
||||
ctx->buffer_len += take;
|
||||
p += take;
|
||||
len -= take;
|
||||
if(ctx->buffer_len == 64) {
|
||||
sha256_block(ctx, ctx->buffer);
|
||||
ctx->buffer_len = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sha256_final(Sha256 *ctx, uint8_t out[32])
|
||||
{
|
||||
uint64_t bitlen = ctx->bitlen;
|
||||
int i;
|
||||
|
||||
ctx->buffer[ctx->buffer_len++] = 0x80u;
|
||||
if(ctx->buffer_len > 56) {
|
||||
while(ctx->buffer_len < 64)
|
||||
ctx->buffer[ctx->buffer_len++] = 0;
|
||||
sha256_block(ctx, ctx->buffer);
|
||||
ctx->buffer_len = 0;
|
||||
}
|
||||
while(ctx->buffer_len < 56)
|
||||
ctx->buffer[ctx->buffer_len++] = 0;
|
||||
for(i = 7; i >= 0; i--)
|
||||
ctx->buffer[ctx->buffer_len++] = (uint8_t)(bitlen >> (i * 8));
|
||||
sha256_block(ctx, ctx->buffer);
|
||||
|
||||
for(i = 0; i < 8; i++) {
|
||||
out[i * 4] = (uint8_t)(ctx->state[i] >> 24);
|
||||
out[i * 4 + 1] = (uint8_t)(ctx->state[i] >> 16);
|
||||
out[i * 4 + 2] = (uint8_t)(ctx->state[i] >> 8);
|
||||
out[i * 4 + 3] = (uint8_t)ctx->state[i];
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sha256(const void *data, size_t len, uint8_t out[32])
|
||||
{
|
||||
Sha256 ctx;
|
||||
|
||||
sha256_init(&ctx);
|
||||
sha256_update(&ctx, data, len);
|
||||
sha256_final(&ctx, out);
|
||||
}
|
||||
|
||||
void
|
||||
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 */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
static void
|
||||
hmac_sha256(const void *key, size_t key_len,
|
||||
const void *message, size_t message_len,
|
||||
uint8_t out[32])
|
||||
{
|
||||
uint8_t block_key[64];
|
||||
uint8_t pad[64];
|
||||
uint8_t inner[32];
|
||||
Sha256 ctx;
|
||||
size_t i;
|
||||
|
||||
memset(block_key, 0, sizeof(block_key));
|
||||
if(key_len > 64) {
|
||||
sha256(key, key_len, block_key);
|
||||
} else {
|
||||
memcpy(block_key, key, key_len);
|
||||
}
|
||||
|
||||
for(i = 0; i < 64; i++)
|
||||
pad[i] = block_key[i] ^ 0x36u;
|
||||
sha256_init(&ctx);
|
||||
sha256_update(&ctx, pad, 64);
|
||||
sha256_update(&ctx, message, message_len);
|
||||
sha256_final(&ctx, inner);
|
||||
|
||||
for(i = 0; i < 64; i++)
|
||||
pad[i] = block_key[i] ^ 0x5cu;
|
||||
sha256_init(&ctx);
|
||||
sha256_update(&ctx, pad, 64);
|
||||
sha256_update(&ctx, inner, 32);
|
||||
sha256_final(&ctx, out);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* PBKDF2 (single block, dkLen = 32) */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
void
|
||||
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];
|
||||
size_t input_len;
|
||||
int round;
|
||||
|
||||
/* salt || INT(32, big-endian) == salt || 00 00 00 01 */
|
||||
input_len = salt_len;
|
||||
if(input_len > sizeof(block_input) - 4)
|
||||
input_len = sizeof(block_input) - 4;
|
||||
if(input_len > 0)
|
||||
memcpy(block_input, salt, input_len);
|
||||
block_input[input_len] = 0;
|
||||
block_input[input_len + 1] = 0;
|
||||
block_input[input_len + 2] = 0;
|
||||
block_input[input_len + 3] = 1;
|
||||
input_len += 4;
|
||||
|
||||
hmac_sha256(password, password_len, block_input, input_len, previous);
|
||||
memcpy(out, previous, 32);
|
||||
|
||||
for(round = 1; round < PASS_DERIVATION_ROUNDS; round++) {
|
||||
hmac_sha256(password, password_len, previous, 32, previous);
|
||||
for(int i = 0; i < 32; i++)
|
||||
out[i] ^= previous[i];
|
||||
}
|
||||
memset(block_input, 0, sizeof(block_input));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Entropy draws (big-endian 256-bit value, successive remainders) */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
static int
|
||||
entropy_take_remainder(uint8_t entropy[32], int divisor)
|
||||
{
|
||||
unsigned carry = 0;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 32; i++) {
|
||||
unsigned current = carry * 256u + entropy[i];
|
||||
|
||||
entropy[i] = (uint8_t)(current / (unsigned)divisor);
|
||||
carry = current % (unsigned)divisor;
|
||||
}
|
||||
return (int)carry;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Generator */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
static int
|
||||
set_error(char *err, size_t err_size, const char *message)
|
||||
{
|
||||
if(err != NULL && err_size > 0)
|
||||
snprintf(err, err_size, "%s", message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
class_filtered(const char *characters, const char *exclude, char *out, int out_size)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
for(const char *c = characters; *c != '\0'; c++) {
|
||||
int excluded = 0;
|
||||
|
||||
if(exclude != NULL) {
|
||||
for(const char *e = exclude; *e != '\0'; e++) {
|
||||
if(*e == *c) {
|
||||
excluded = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!excluded && count < out_size)
|
||||
out[count++] = *c;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
static const char *class_names[4] = {"lowercase", "uppercase", "digits", "symbols"};
|
||||
static const char *class_sets[4] = {
|
||||
LOWERCASE_CHARACTERS, UPPERCASE_CHARACTERS, DIGIT_CHARACTERS, SYMBOL_CHARACTERS
|
||||
};
|
||||
const int class_enabled[4] = {
|
||||
options->lowercase != 0, options->uppercase != 0,
|
||||
options->digits != 0, options->symbols != 0
|
||||
};
|
||||
char classes[4][32];
|
||||
int class_lengths[4];
|
||||
int class_count = 0;
|
||||
char alphabet[128];
|
||||
int alphabet_length = 0;
|
||||
char salt[640];
|
||||
size_t salt_len;
|
||||
uint8_t entropy[32];
|
||||
char password[136];
|
||||
int password_length;
|
||||
char required[4];
|
||||
char message[192];
|
||||
int i;
|
||||
|
||||
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])
|
||||
continue;
|
||||
class_lengths[class_count] =
|
||||
class_filtered(class_sets[i], options->exclude,
|
||||
classes[class_count], (int)sizeof(classes[class_count]));
|
||||
if(class_lengths[class_count] == 0) {
|
||||
snprintf(message, sizeof(message),
|
||||
"enabled %s character class is empty after exclusions", class_names[i]);
|
||||
return set_error(err, err_size, message);
|
||||
}
|
||||
memcpy(alphabet + alphabet_length, classes[class_count],
|
||||
(size_t)class_lengths[class_count]);
|
||||
alphabet_length += class_lengths[class_count];
|
||||
class_count++;
|
||||
}
|
||||
if(class_count == 0)
|
||||
return set_error(err, err_size, "at least one character class must be enabled");
|
||||
if(options->length < class_count) {
|
||||
snprintf(message, sizeof(message),
|
||||
"password length %d is smaller than the %d enabled character classes",
|
||||
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");
|
||||
|
||||
salt_len = 0;
|
||||
if(site != NULL) {
|
||||
size_t site_len = strlen(site);
|
||||
|
||||
if(salt_len + site_len >= sizeof(salt))
|
||||
return set_error(err, err_size, "site name is too long");
|
||||
memcpy(salt + salt_len, site, site_len);
|
||||
salt_len += site_len;
|
||||
}
|
||||
if(login != NULL) {
|
||||
size_t login_len = strlen(login);
|
||||
|
||||
if(salt_len + login_len >= sizeof(salt))
|
||||
return set_error(err, err_size, "login is too long");
|
||||
memcpy(salt + salt_len, login, login_len);
|
||||
salt_len += login_len;
|
||||
}
|
||||
salt_len += (size_t)snprintf(salt + salt_len, sizeof(salt) - salt_len,
|
||||
"%llx", (unsigned long long)options->counter);
|
||||
|
||||
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++)
|
||||
password[i] = alphabet[entropy_take_remainder(entropy, alphabet_length)];
|
||||
|
||||
for(i = 0; i < class_count; i++)
|
||||
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);
|
||||
|
||||
memmove(password + position + 1, password + position,
|
||||
(size_t)(password_length - position));
|
||||
password[position] = required[i];
|
||||
password_length++;
|
||||
}
|
||||
|
||||
memcpy(out, password, (size_t)password_length);
|
||||
out[password_length] = '\0';
|
||||
memset(password, 0, sizeof(password));
|
||||
memset(required, 0, sizeof(required));
|
||||
return 0;
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
#ifndef PASS_CORE_H
|
||||
#define PASS_CORE_H
|
||||
|
||||
#include <stddef.h>
|
||||
#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;
|
||||
uint64_t counter;
|
||||
int lowercase;
|
||||
int uppercase;
|
||||
int digits;
|
||||
int symbols;
|
||||
const char *exclude; /* NUL-terminated; may be NULL or empty */
|
||||
} PassOptions;
|
||||
|
||||
/* Derives the 32-byte PBKDF2-HMAC-SHA256 key (one block, 100000 rounds),
|
||||
* the byte-exact counterpart of the Go package's deriveKey. */
|
||||
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_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_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,449 +0,0 @@
|
||||
/* 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"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static int failures = 0;
|
||||
|
||||
static void
|
||||
check_generate(int index, const char *site, const char *login, const char *master,
|
||||
PassOptions options, const char *want, int want_error)
|
||||
{
|
||||
char out[256];
|
||||
char err[256];
|
||||
int result;
|
||||
|
||||
memset(out, 0, sizeof(out));
|
||||
memset(err, 0, sizeof(err));
|
||||
result = pass_core_generate(site, login, master, &options, out, sizeof(out), err, sizeof(err));
|
||||
|
||||
if(want_error) {
|
||||
if(result == 0) {
|
||||
printf("FAIL %d: expected error, got password \"%s\"\n", index, out);
|
||||
failures++;
|
||||
} else if(err[0] == '\0') {
|
||||
printf("FAIL %d: error returned but message is empty\n", index);
|
||||
failures++;
|
||||
} else {
|
||||
printf("ok %d: rejected (%s)\n", index, err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(result != 0) {
|
||||
printf("FAIL %d: unexpected error: %s\n", index, err);
|
||||
failures++;
|
||||
} else if(strcmp(out, want) != 0) {
|
||||
printf("FAIL %d: got \"%s\", want \"%s\"\n", index, out, want);
|
||||
failures++;
|
||||
} else {
|
||||
printf("ok %d: \"%s\"\n", index, out);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
check_derive(int index, const char *password, const char *salt, const char *want_hex)
|
||||
{
|
||||
uint8_t out[32];
|
||||
char hex[65];
|
||||
int i;
|
||||
|
||||
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';
|
||||
|
||||
if(strcmp(hex, want_hex) != 0) {
|
||||
printf("FAIL derive %d: got %s, want %s\n", index, hex, want_hex);
|
||||
failures++;
|
||||
} else {
|
||||
printf("ok derive %d: %s\n", index, hex);
|
||||
}
|
||||
}
|
||||
|
||||
static 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_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, want_hex) != 0) {
|
||||
printf("FAIL derive %d: got %s, want %s\n", index, hex, want_hex);
|
||||
failures++;
|
||||
} else {
|
||||
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)
|
||||
{
|
||||
PassOptions options;
|
||||
char out[256];
|
||||
char err[256];
|
||||
static const char *exclude = "abcXYZ019!@";
|
||||
static const char *lower = "abcdefghijklmnopqrstuvwxyz";
|
||||
static const char *upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
static const char *digits = "0123456789";
|
||||
static const char *symbols = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
|
||||
int i, j, has_lower, has_upper, has_digits, has_symbols;
|
||||
|
||||
memset(&options, 0, sizeof(options));
|
||||
options.length = 35;
|
||||
options.counter = 3;
|
||||
options.lowercase = 1;
|
||||
options.uppercase = 1;
|
||||
options.digits = 1;
|
||||
options.symbols = 1;
|
||||
options.exclude = exclude;
|
||||
|
||||
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) != 35) {
|
||||
printf("FAIL shape: length %zu, want 35\n", strlen(out));
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
for(i = 0; exclude[i] != '\0'; i++) {
|
||||
if(strchr(out, exclude[i]) != NULL) {
|
||||
printf("FAIL shape: contains excluded character '%c'\n", exclude[i]);
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
has_lower = has_upper = has_digits = has_symbols = 0;
|
||||
for(i = 0; out[i] != '\0'; i++) {
|
||||
if(strchr(lower, out[i]))
|
||||
has_lower = 1;
|
||||
if(strchr(upper, out[i]))
|
||||
has_upper = 1;
|
||||
if(strchr(digits, out[i]))
|
||||
has_digits = 1;
|
||||
for(j = 0; symbols[j] != '\0'; j++) {
|
||||
if(out[i] == symbols[j])
|
||||
has_symbols = 1;
|
||||
}
|
||||
}
|
||||
if(!has_lower || !has_upper || !has_digits || !has_symbols) {
|
||||
printf("FAIL shape: class coverage lower=%d upper=%d digits=%d symbols=%d\n",
|
||||
has_lower, has_upper, has_digits, has_symbols);
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
printf("ok shape: 35 chars, all classes covered, exclusions honored\n");
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
PassOptions defaults;
|
||||
|
||||
check_derive(1, "password", "salt",
|
||||
"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;
|
||||
defaults.counter = 1;
|
||||
defaults.lowercase = 1;
|
||||
defaults.uppercase = 1;
|
||||
defaults.digits = 1;
|
||||
defaults.symbols = 1;
|
||||
defaults.exclude = "";
|
||||
|
||||
check_generate(1, "example.com", "alice", "correct horse battery staple",
|
||||
defaults, "&Lf4'/-cSk4DPv_8", 0);
|
||||
|
||||
{
|
||||
PassOptions o = defaults;
|
||||
|
||||
o.length = 20;
|
||||
o.counter = 2;
|
||||
check_generate(2, "service.test", "[email protected]", "master",
|
||||
o, "j:x_Lo5b1XL_j0we%z`e", 0);
|
||||
}
|
||||
|
||||
{
|
||||
PassOptions o;
|
||||
|
||||
memset(&o, 0, sizeof(o));
|
||||
o.length = 12;
|
||||
o.counter = 7;
|
||||
o.lowercase = 1;
|
||||
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, "oih5omhygh2v", 0);
|
||||
}
|
||||
|
||||
{
|
||||
PassOptions o = defaults;
|
||||
|
||||
o.length = 24;
|
||||
o.exclude = "0Ool1I!|";
|
||||
check_generate(4, "example.com", "alice", "correct horse battery staple",
|
||||
o, "7,.Cp}YnF'eeHHaqbX7#PQhg", 0);
|
||||
}
|
||||
|
||||
{
|
||||
PassOptions o;
|
||||
|
||||
memset(&o, 0, sizeof(o));
|
||||
o.length = 5;
|
||||
o.counter = 0;
|
||||
o.uppercase = 1;
|
||||
o.digits = 1;
|
||||
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);
|
||||
}
|
||||
|
||||
{
|
||||
PassOptions o;
|
||||
|
||||
memset(&o, 0, sizeof(o));
|
||||
o.length = 0;
|
||||
o.lowercase = 1;
|
||||
check_generate(9, "site", "login", "master", o, "", 1);
|
||||
}
|
||||
|
||||
{
|
||||
PassOptions o;
|
||||
|
||||
memset(&o, 0, sizeof(o));
|
||||
o.length = 8;
|
||||
check_generate(10, "site", "login", "master", o, "", 1);
|
||||
}
|
||||
|
||||
{
|
||||
PassOptions o;
|
||||
|
||||
memset(&o, 0, sizeof(o));
|
||||
o.length = 2;
|
||||
o.lowercase = 1;
|
||||
o.uppercase = 1;
|
||||
o.digits = 1;
|
||||
check_generate(11, "site", "login", "master", o, "", 1);
|
||||
}
|
||||
|
||||
{
|
||||
PassOptions o;
|
||||
|
||||
memset(&o, 0, sizeof(o));
|
||||
o.length = 8;
|
||||
o.digits = 1;
|
||||
o.exclude = "0123456789";
|
||||
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();
|
||||
|
||||
if(failures != 0) {
|
||||
printf("%d failure(s)\n", failures);
|
||||
return 1;
|
||||
}
|
||||
printf("all vectors pass\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
/* 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;
|
||||
}
|
||||
@@ -1,758 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
#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
|
||||
@@ -1,400 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/config/
|
||||
/repo/
|
||||
/tmp/
|
||||
/logs/
|
||||
@@ -0,0 +1,5 @@
|
||||
# Update Pass to Werkzeug
|
||||
|
||||
Update the existing `xyz.waozi.pass` app to Werkzeug. The package ID and signing certificate are preserved for in-place updates.
|
||||
|
||||
Listing text and screenshots are maintained upstream in Fastlane.
|
||||
@@ -0,0 +1,17 @@
|
||||
# Werkzeug F-Droid update status
|
||||
|
||||
The owner's latest request is an update of the existing Pass app. Keep `xyz.waozi.pass`, the existing author signing certificate and private app data. The visible name remains Werkzeug. Preserve any separate `xyz.waozi.werk` installation as well.
|
||||
|
||||
- [x] Prepare the original Android application ID and matching artifact verifiers.
|
||||
- [x] Prepare 0.4.4 with version code 18 through `update_version.sh`.
|
||||
- [x] Build the compatible ARM and private-emulator candidates with matching ZX dependencies and current app bundles.
|
||||
- [x] Verify both ARM native libraries match byte for byte after independent builds in different directories.
|
||||
- [ ] Publish the compatible candidate through the normal release workflow and pin its exact source revision in the recipe.
|
||||
- [ ] Complete source-build and reproducibility verification against its reference APK.
|
||||
- [ ] Resolve missing explicit dependency licenses and remaining GitLab pipeline results.
|
||||
- [ ] Obtain owner approval before marking the update ready for review.
|
||||
- [ ] Verify catalog publication after maintainers merge and F-Droid publishes it.
|
||||
|
||||
[Update draft](https://gitlab.com/fdroid/fdroiddata/-/merge_requests/53909) · [Recipe](metadata/xyz.waozi.pass.yml) · [Merge-request text](MERGE_REQUEST.md)
|
||||
|
||||
The local recipe is being prepared; its source pin still needs the verified compatible candidate. A Draft or a successful source build does not imply F-Droid catalog publication.
|
||||
@@ -0,0 +1,51 @@
|
||||
Categories:
|
||||
- Password & 2FA
|
||||
- Security
|
||||
License: BSD-3-Clause
|
||||
AuthorName: Waozi
|
||||
WebSite: https://werk.waozi.xyz
|
||||
SourceCode: https://github.com/waozixyz/werk
|
||||
IssueTracker: https://github.com/waozixyz/werk/issues
|
||||
Changelog: https://github.com/waozixyz/werk/blob/HEAD/CHANGELOG.md
|
||||
|
||||
AutoName: Werkzeug
|
||||
|
||||
RepoType: git
|
||||
Repo: https://github.com/waozixyz/werk.git
|
||||
Binaries: https://github.com/waozixyz/pass/releases/download/v%v/pass-%v.apk
|
||||
|
||||
Builds:
|
||||
- versionName: 0.2.9
|
||||
versionCode: 10
|
||||
commit: f9d721f179e54c924e048d3fd17c5e96de1047ba
|
||||
subdir: droid/app
|
||||
submodules: true
|
||||
sudo:
|
||||
- apt-get update
|
||||
- apt-get install -y gcc libc-dev
|
||||
gradle:
|
||||
- yes
|
||||
scandelete:
|
||||
- vendor/kryon/vendor
|
||||
ndk: 28.2.13676358
|
||||
|
||||
- versionName: 0.4.4
|
||||
versionCode: 18
|
||||
commit: b53050764b8402a96e2e6b9b8c90d6567a3bea77
|
||||
subdir: droid/app
|
||||
sudo:
|
||||
- apt-get update
|
||||
- apt-get install -y build-essential cmake libssl-dev
|
||||
gradle:
|
||||
- yes
|
||||
binary: https://github.com/waozixyz/werk/releases/download/v%v/werk-%v.apk
|
||||
ndk: 28.2.13676358
|
||||
gradleprops:
|
||||
- fDroidBuild=true
|
||||
|
||||
AllowedAPKSigningKeys: 1ac82db5bc8f742b8161fdd7083cefc16b39524dce7d103a7eb7f1ee19589c2d
|
||||
|
||||
AutoUpdateMode: Version
|
||||
UpdateCheckMode: Tags
|
||||
CurrentVersion: 0.4.4
|
||||
CurrentVersionCode: 18
|
||||
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
|
||||
<mime-type type="application/x-ziran-bundle">
|
||||
<comment>Ziran application bundle</comment>
|
||||
<glob pattern="*.zx"/>
|
||||
</mime-type>
|
||||
</mime-info>
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<component type="desktop-application">
|
||||
<id>xyz.waozi.pass</id>
|
||||
<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>
|
||||
</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.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>
|
||||