Skip to content

Commit

Permalink
Merge branch 'zkytech-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Angoll committed Mar 18, 2022
2 parents 4d9724a + 9b4e44a commit 2f2fc72
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 35 deletions.
Binary file added KPass.v2.4.alfredworkflow
Binary file not shown.
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@

- List all entries from a KeePassXC database
- Get the password for the selected entry, and put it in the clipboard
- The password is copied to the transient clipboard.

- The password is copied to the transient clipboard.
- Allow to cache the keys to a file. Default `disabled`

## Setup

#### Prerequisites
- Alfred 4
- KeePassXC
- A created KeePassXC database
- jq installed ( https://stedolan.github.io/jq/download/ )

- Alfred 4
- KeePassXC
- A created KeePassXC database
- homebrew installed( <https://brew.sh/> )
- jq installed ( <https://stedolan.github.io/jq/download/> )

#### Configuration

Expand All @@ -29,6 +31,11 @@ Run **kpassinit** KPass Setup and follow the instructions:
4. Enter the password for the KeePassXC database selected
5. Done!

#### Enable the cache

In order to enable the cache, go to the Alfred workflow and into environment `[x]` set the env var `cacheFile` to a full file path where to store the cache. As an example `/Users/my_user/Library/Caches/kpass.cache`

Finally the env var `cacheTimeout` controlls the recreation of cache in seconds.

## Known problems

Expand All @@ -41,8 +48,9 @@ This Alfred workflow integrate with keepassxc using keepassxc cli, the script ad
Having a high transformation rounds allows to slow down bruteforce attacks so pickup a number that is seems right for you.

More information:
- https://github.com/Angoll/KPass/issues/17#issuecomment-888096305
- https://github.com/keepassxreboot/keepassxc/issues/6778

- <https://github.com/Angoll/KPass/issues/17#issuecomment-888096305>
- <https://github.com/keepassxreboot/keepassxc/issues/6778>

### Keepass file appears unselectable

Expand All @@ -54,11 +62,10 @@ Open the Alfred workflow from the Alfred App, double click the Run Script /usr/b

This will make any file selectable.


## References
- https://www.alfredapp.com/
- https://keepassxc.org/

- <https://www.alfredapp.com/>
- <https://keepassxc.org/>

Any feedback is welcome!

Expand Down
27 changes: 16 additions & 11 deletions scripts/getPassword.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
export PATH='/usr/local/bin/:/usr/bin:/Applications/KeePassXC.app/Contents/MacOS/:${PATH}'
export PATH='/bin:/usr/local/bin/:/usr/bin:/Applications/KeePassXC.app/Contents/MacOS/:/opt/homebrew/bin:${PATH}'

keePassKeyFile=""
if [[ ! -z ${keyfile} ]]; then
keePassKeyFile="--key-file \"${keyfile}\""
fi

function get_keys() {
security find-generic-password -a $(id -un) -c 'kpas' -C 'kpas' -s "${keychainItem}" -w "${keychain}" |\
keepassxc-cli show -q ${keePassKeyFile} -a Password "$database" "$1"
function get_keys {
if [ ! -z "${keePassKeyFile}" ]; then
security find-generic-password -a $(id -un) -c 'kpas' -C 'kpas' -s "${keychainItem}" -w "${keychain}" |\
keepassxc-cli show --key-file "${keePassKeyFile}" -q -a Password "${database}" "$1"
else
security find-generic-password -a $(id -un) -c 'kpas' -C 'kpas' -s "${keychainItem}" -w "${keychain}" |\
keepassxc-cli show -q -a Password "${database}" "$1"
fi
}

function get_errorInfo {
exec 3<&1
security find-generic-password -a $(id -un) -c 'kpas' -C 'kpas' -s "${keychainItem}" -w "${keychain}" 2>&3 |\
keepassxc-cli ls -R ${keePassKeyFile} -f "$database" 2>&3 | grep -Ev '(/|\[empty\]?)$'
if [ ! -z "${keePassKeyFile}" ]; then
security find-generic-password -a $(id -un) -c 'kpas' -C 'kpas' -s "${keychainItem}" -w "${keychain}" 2>&3 |\
keepassxc-cli ls -R --key-file "${keePassKeyFile}" -f "$database" 2>&3 | grep -Ev '(/|\[empty\]?)$'
else
security find-generic-password -a $(id -un) -c 'kpas' -C 'kpas' -s "${keychainItem}" -w "${keychain}" 2>&3 |\
keepassxc-cli ls -R -f "$database" 2>&3 | grep -Ev '(/|\[empty\]?)$'
fi
exec 3>&-
}

Expand Down
46 changes: 33 additions & 13 deletions scripts/listDatabase.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
export PATH='/usr/local/bin/:/usr/bin:/Applications/KeePassXC.app/Contents/MacOS/:${PATH}'


useKeePassKeyFile=""
if [[ ! -z ${keePassKeyFile} ]]; then
useKeePassKeyFile="--key-file ${keePassKeyFile}"
fi
export PATH='/bin:/usr/local/bin/:/usr/bin:/Applications/KeePassXC.app/Contents/MacOS/:/opt/homebrew/bin:${PATH}'

function get_db_keys {
if [ ! -z "${keePassKeyFile}" ]; then
security find-generic-password -a $(id -un) -c 'kpas' -C 'kpas' -s "${keychainItem}" -w "${keychain}" |\
keepassxc-cli locate --key-file "${keePassKeyFile}" "${database}" / -q
else
security find-generic-password -a $(id -un) -c 'kpas' -C 'kpas' -s "${keychainItem}" -w "${keychain}" |\
keepassxc-cli locate "${database}" / -q
fi
}

function get_keys() {
security find-generic-password -a $(id -un) -c 'kpas' -C 'kpas' -s "${keychainItem}" -w "${keychain}" |\
keepassxc-cli locate ${useKeePassKeyFile} "$database" / -q
function get_keys {
if [ -z "${cacheFile}" ]; then
get_db_keys
else
# Cache is enabled
if [ -f "${cacheFile}" ]; then
lastModifiedTime=$(GetFileInfo -d "${cacheFile}")
else
lastModifiedTime=$(date +"%m/%d/%Y %H:%M:%S")
fi
lastModifiedTime=$(date -jf "%m/%d/%Y %H:%M:%S" "${lastModifiedTime}" +%s)
currTime=$(date +%s)
interval=$( expr $currTime - $lastModifiedTime )
if [ ! -f "${cacheFile}" ] || [ "${interval}" -gt "${cacheTimeout}" ]; then
# Update cache
echo "$(get_db_keys)" > "${cacheFile}"
fi
# Get keys from the cache
cat "${cacheFile}" | grep -i "${query}"
fi
}

function get_errorInfo {
exec 3<&1
security find-generic-password -a $(id -un) -c 'kpas' -C 'kpas' -s "${keychainItem}" -w "${keychain}" 2>&3 |\
keepassxc-cli locate ${useKeePassKeyFile} "$database" / -q 2>&3
keepassxc-cli locate ${useKeePassKeyFile} '$database' / -q 2>&3
exec 3>&-
}

if [[ -z ${database} ]] || [[ -z ${keychain} ]];
if [[ -z "${database}" ]] || [[ -z "${keychain}" ]];
then
echo "{\"items\": [{\"title\":\"Not configured, please run: kpassinit\"}]}";
exit
Expand All @@ -32,5 +52,5 @@ if [ $? -ne 0 ]; then
echo "{\"items\": [{\"title\":\"Error listing database, please check config: Error: ${info}\"}]}";
exit
else
echo ${keys[@]} | sed 's/ \//\n\//g' | awk -v iconPath="${PWD}/icon.png" '{printf "{\"uid\":\"%s\", \"title\":\"%s\", \"subtitle\":\"%s\", \"arg\":\"%s\", \"autocomplete\": \"%s\", \"icon\":{\"type\":\"png\", \"path\": \"%s\"}}", $0, $0, $0, $0, $0, iconPath}' | jq -c -s '{"items": .}'
echo ${keys[@]} | sed 's/ \//\n\//g' | awk -v iconPath="${PWD}/icon.png" '{printf "{\"uid\":\"%s\", \"title\":\"%s\", \"subtitle\":\"%s\", \"arg\":\"%s\", \"autocomplete\": \"%s\", \"icon\":{\"type\":\"png\", \"path\": \"%s\"}}", $0, substr($0,2, length($0)), $0, $0, $0, iconPath}' | jq -c -s '{"items": .}'
fi

0 comments on commit 2f2fc72

Please sign in to comment.