Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Empty terminal window opening and closing on each connection #30

Closed
RikuXan opened this issue Dec 28, 2021 · 3 comments
Closed

Empty terminal window opening and closing on each connection #30

RikuXan opened this issue Dec 28, 2021 · 3 comments

Comments

@RikuXan
Copy link

RikuXan commented Dec 28, 2021

Describe the bug
Everytime the socat fork executes a new instance of wsl2-ssh-pageant, an empty terminal window (Windows Terminal Preview, as it is my default terminal application, but it also happens when the normal conhost terminal is configured) opens for a second and then closes again. Should the PIN need to be put in, the window stays open until I have done so too. Because it opens in the foreground and steals input focus during its lifetime, this is moderately annoying. While this behaviour does not occur 100% of time, I am unsure which circumstances lead to the window appearing and which do not.

I believe that this has started to occur after upgrading my OS to Windows 11 (in-place upgrade, not a new installation). It also seems that the problem disappears with an upgrade of my GnuPG version (on Windows) from 2.2.28 to 2.3.4, but unfortunately this upgrade seems to break some other think regarding the YubiKey detection and Pageant connection (see e.g. #25) so I had to roll this back. As the issue was not appearing completely consistently with the old version either, it could also be that the new version is affected as well and just didn't show the behaviour during my time of experimenting with it.

I am not necessarily asserting that this is a bug with wsl2-ssh-pageant itself, it may well also be caused by my specific configuration, which is why I'm trying to provide as much information as I can below, maybe someone experiences similar issues and can see a similarity in circumstances. Also, the attached wsl2-ssh-pageant log at the bottom does contain an error, however this does not seem to impact functionality, but it might still be a possible cause?

To Reproduce

  1. Execute any command resulting in the GPG socket's usage, e.g. ssh-add -L, gpg --card-status or just any ssh <host>
  2. See a empty terminal window with wsl2-ssh-pageant's path as its title open up and close again immediately afterwards (or after PIN entry is complete)

Expected behavior
The execution of wsl2-ssh-pageant should not open up any window or cause any UI interaction.

Screenshots
wsl2-ssh-pageant-bug
Image of the empty Windows Terminal Preview window opening up in response to a ssh-add -L, with the executable's path set as the tab's/window's title

Desktop:

  • OS: Windows 11
  • Execution environment: Arch @ WSL2
  • Terminal: Windows Terminal Preview 1.12.3472.0
  • Software: Gpg4Win 3.1.16 & GnuPG 2.2.28

wsl2-ssh-pageant integration script

export SSH_AUTH_SOCK="$HOME/.ssh/agent.sock"
export GPG_AGENT_SOCK="$HOME/.gnupg/S.gpg-agent"
GPG_WINDOWS_SOCKETDIR=$(gpgconf.exe --list-dirs | grep socketdir | cut -f2- -d: | tr -d '\r\n' | sed -e 's|\\|/|g' -e 's|%3a|\\:|g')
WSL2_SSH_PAGEANT_LOG_DIR="$HOME/.local/log/wsl2-ssh-pageant"
WSL2_SSH_PAGEANT_BIN="$APPDATA/wsl2-ssh-pageant/wsl2-ssh-pageant.exe"

if test -x "$WSL2_SSH_PAGEANT_BIN"; then
  if ! ss -a | grep -q "$SSH_AUTH_SOCK"; then
    rm -f "$SSH_AUTH_SOCK"
    (setsid nohup socat UNIX-LISTEN:"$SSH_AUTH_SOCK,fork" EXEC:"$WSL2_SSH_PAGEANT_BIN --verbose --logfile $WSL2_SSH_PAGEANT_LOG_DIR/wsl2sp-ssh.log" > /dev/null 2>&1 &)
  fi
  if ! ss -a | grep -q "$GPG_AGENT_SOCK"; then
    rm -rf "$GPG_AGENT_SOCK"
    (setsid nohup socat UNIX-LISTEN:"$GPG_AGENT_SOCK,fork" EXEC:"$WSL2_SSH_PAGEANT_BIN --gpg S.gpg-agent --gpgConfigBasepath $GPG_WINDOWS_SOCKETDIR --verbose --logfile $WSL2_SSH_PAGEANT_LOG_DIR/wsl2sp-gpg.log" > /dev/null 2>&1 &)
  fi
else
  echo >&2 "WARNING: $wsl2_ssh_pageant_bin is not executable."
fi

Running socat processes (including --gpgConfigBasepath due to #26)

❯ ps aux | grep -i socat
philipp+  4788  0.0  0.0   7528  3536 ?        Ss   22:37   0:00 socat UNIX-LISTEN:/home/philipp.holler/.ssh/agent.sock,fork EXEC:/mnt/c/Users/philipp.holler/AppData/Roaming/wsl2-ssh-pageant/wsl2-ssh-pageant.exe --verbose --logfile /home/philipp.holler/.local/log/wsl2-ssh-pageant/wsl2sp-ssh.log
philipp+  4793  0.0  0.0   7528  2196 ?        Ss   22:37   0:00 socat UNIX-LISTEN:/home/philipp.holler/.gnupg/S.gpg-agent,fork EXEC:/mnt/c/Users/philipp.holler/AppData/Roaming/wsl2-ssh-pageant/wsl2-ssh-pageant.exe --gpg S.gpg-agent --gpgConfigBasepath C\:/Users/philipp.holler/AppData/Roaming/gnupg --verbose --logfile /home/philipp.holler/.local/log/wsl2-ssh-pageant/wsl2sp-gpg.log

SSH agent socket wsl2-ssh-pagent log snippet

2021/12/28 22:55:04 Starting exe
2021/12/28 22:55:04 Reading length: 1
2021/12/28 22:55:04 Querying pageant
2021/12/28 22:55:04 io.ReadFull length error 'EOF'
@tobiaskohlbau
Copy link
Collaborator

tobiaskohlbau commented Jan 3, 2022

Hello, can you provide the version of wsl2-ssh-pageant you are using? I would assume you've used the latest release and did not built it from source?

This window popping up is a regression from Microsoft introduced with the Store version of WSL. For wsl2-ss-pageant I've already fixed this in the mainline, I will try to cut a new release. Notice that GPG also brings up the window on the first run.

Edit:

I've release 1.4.0 please give it a try.

@RikuXan
Copy link
Author

RikuXan commented Jan 3, 2022

Your assumption was correct, I was using version 1.3.0 through the prebuilt binary from the releases page previously.
Upgrading to version 1.4.0 you just released fixes the issue, thank you for the amazing support.

@RikuXan RikuXan closed this as completed Jan 3, 2022
@tobiaskohlbau
Copy link
Collaborator

Glad that the release helped you, sorry for missing out the release. I assumed I've already released a version with that fix included.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants