Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple database with --pw-stdin #2916

Merged
merged 5 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ The following libraries are required:
* libmicrohttpd
* libxi, libxtst, qtx11extras (optional for auto-type on X11)
* libsodium (>= 1.0.12, optional for KeePassXC-Browser support)
* libargon2
* argon2
* qrencode
* yubikey ykpers (optional to support YubiKey)

Prepare the Building Environment
================================
Expand Down
2 changes: 1 addition & 1 deletion src/cli/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ namespace Utils
return password;
}

TextStream in(STDIN, QIODevice::ReadOnly);
static TextStream in(STDIN, QIODevice::ReadOnly);

setStdinEcho(false);
QString line = in.readLine();
Expand Down
3 changes: 1 addition & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ int main(int argc, char** argv)
if (pwstdin) {
// we always need consume a line of STDIN if --pw-stdin is set to clear out the
// buffer for native messaging, even if the specified file does not exist
static QTextStream in(stdin, QIODevice::ReadOnly);
static QTextStream out(stdout, QIODevice::WriteOnly);
QTextStream out(stdout, QIODevice::WriteOnly);
out << QObject::tr("Database password: ") << flush;
password = Utils::getPassword();
}
Expand Down
16 changes: 8 additions & 8 deletions utils/keepassx-kwallet → utils/keepassxc-kdewallet
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/bash
#!/usr/bin/env bash
# fetch KeePass database passwords from kdewallet

### change the path to suit your installation or set KDBX_SEARCH before calling ###
: ${KDBX_SEARCH:=~/.KeePass/*.kdbx}

PROG="$(basename $0)"
PROG="${0##*/}"
KEEPASSXC=$(which -a keepassxc | sed -e "\\,$0,d" -e 'q')

function daemon_main {
# open kdewallet
Expand All @@ -12,16 +14,14 @@ function daemon_main {
sleep 1
done

# fetch KeePass database passwords from kdewallet
declare -A DBs
for DBPATH in $KDBX_SEARCH; do
[[ -L "$DBPATH" ]] && DBPATH=$(readlink --canonicalize "$DBPATH")
DBs[$DBPATH]=$(qdbus org.kde.kwalletd5 /modules/kwalletd5 org.kde.KWallet.readPassword "$handle" "Passwords" "$DBPATH" "$PROG")
for DBPATH in $(ls -r $KDBX_SEARCH); do
DBs[$(realpath $DBPATH)]=$(qdbus org.kde.kwalletd5 /modules/kwalletd5 org.kde.KWallet.readPassword "$handle" "Passwords" "${DBPATH##*/}" "$PROG")
done

# launch keepassx
# launch real keepassxc
IFS=$'\n\n\n'
keepassx --pw-stdin "${!DBs[@]}" <<<"${DBs[*]}" &
"$KEEPASSXC" --pw-stdin "${!DBs[@]}" <<<"${DBs[*]}" &

# done with kdewallet
qdbus org.kde.kwalletd5 /modules/kwalletd5 org.kde.KWallet.close "$handle" "false" "$PROG"
Expand Down
29 changes: 29 additions & 0 deletions utils/keepassxc-keychain
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# fetch KeePass database passwords from keychain

### change the path to suit your installation or set KDBX_SEARCH before calling ###
: ${KDBX_SEARCH:=~/.KeePass/*.kdbx}

PROG="$(basename $0)"
KeePassXC=$(ls -f {/usr/local,/Applications}/KeePassXC.app/Contents/MacOS/KeePassXC 2>/dev/null | head -1)

function daemon_main {
declare -A DBs
for DBPATH in $KDBX_SEARCH; do
DBs[$(python -c "import os; print os.path.realpath('$DBPATH')")]=$(security find-generic-password -a $USER -s "${DBPATH##*/}" -w)
done

# launch keepassxc
IFS=$'\n\n\n'
$KeePassXC --pw-stdin "${!DBs[@]}" <<<"${DBs[*]}" &
}

if [[ '-d' = "$1" ]]; then
exec >&~/tmp/$PROG.log
set -vx
daemon_main
else
cd /
daemon_main </dev/null >&/dev/null &
disown
fi