Skip to content

Commit

Permalink
Automatically log into the dev client
Browse files Browse the repository at this point in the history
Most of the time we're developing the client, we are not testing the
login screen, and just want to quickly log in. With a combination of
xdotool and oathtool, we can script typing the correct values and login.

It's a bit fragile for two reasons. First, we're just blindly typing, so
if some other window takes focus or switch, it'll be typed into that
window. Second, we're kicking off a background process that sleeps,
launching the window in the foreground, and then the background process
will do the typing into the foreground.

Also this doesn't work on Wayland; there are some alternatives that use
uinput but they have other restrictions/consequences.

It would've been easier to just have this be in the client Python code
itself, but that would've meant it also gets shipped to production,
which I think we can avoid.
  • Loading branch information
legoktm committed Sep 23, 2024
1 parent 0c1cc43 commit 165d8ad
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions client/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,46 @@ fi
if [[ $XDG_SESSION_TYPE = "wayland" ]]; then
echo "Detected Wayland, will run with QT_QPA_PLATFORM variable..."
export QT_QPA_PLATFORM=wayland
if [[ "$1" == "--login" ]]; then
echo "--login is not yet supported on Wayland"
exit 1
fi
fi

wait

function check_login() {
# error if xdotool and oathtool are not installed
if ! command -v xdotool &> /dev/null; then
echo "--login requires xdotool to be installed"
exit 1
fi
if ! command -v oathtool &> /dev/null; then
echo "--login requires oathtool to be installed"
exit 1
fi
}

function login() {
# Wait for the window to open before typing
# (this is bad but we need to run this after the client starts, which is blocking)
sleep 3
xdotool type "journalist"
xdotool key Tab
xdotool type "correct horse battery staple profanity oil chewy"
xdotool key Tab
xdotool key Tab
xdotool type "$(oathtool --totp --base32 JHCOGO7VCER3EJ4L)"
xdotool key Return
}

echo "Starting client, home directory: $SDC_HOME"
# Create the log file ahead of time so we can tail it before the client launches
mkdir -p "$SDC_HOME/logs"
touch "$SDC_HOME/logs/client.log"
tail -f "$SDC_HOME/logs/client.log" &
if [[ $1 == "--login" ]]; then
check_login
login &
fi
LOGLEVEL=debug $PYTHON -m securedrop_client --sdc-home "$SDC_HOME" --no-proxy "$qubes_flag" "$@"

0 comments on commit 165d8ad

Please sign in to comment.