Using pass under Windows with WSL
Today I got my a new SSD for my gaming PC and decided to reinstall everything and start with a blank canvas.
So of course after installing the most basic tools I wanted to get my mails working. But the only place where I have my mail password is inside my pass folder.
So I started with activating WSL and installing Ubuntu. Inside ubuntu I added my GPG key from an encrypted USB-Stick and copied an old version of my password folder.
After updating the passwords I had a working environment under linux, but this is still very inconvenient under windows to open wsl, get the password, copy from there to clipboard and from clipboard to where I needed it to be.
Copy passwords to Clipboard
Here comes the power of WSL, fzf and AutoHotKey.
First I installed fzf under ubuntu, then AutoHotKey under Windows.
Then I created the following Script for AutoHotKey:
!^p::
Run, ubuntu.exe run pass show $(find /home/pflug/.password-store/ -type f -iname "*.gpg" | sed 's/.\{4\}$//' | sed 's/\(.\{28\}\)//' | /home/pflug/.fzf/bin/fzf) | clip.exe
return
If you know the basic syntax of Autohotkey, then the first and last line should be no surprise. My keybinding is Ctrl+Alt+P for copying a password to clipboard.
After pass show
I added a little script to first print all gpg files to stdout.
Then remove the last 4 characters per line (.gpg) and after that the first 28
(/home/pflug/.password-store/). If you want to copy the script, you will
probably have to change this number.
This is then piped to fzf, which will make a fuzzy search on the input
and replace the command with the best result.
Now comes the magic of WSL. You can simply call Windows command inside of WSL.
So i piped my wanted password to clip.exe
, which will copy it to
clipboard and the WSL window will close after that.
I then added my AutoHotKey Script to startup and the first part was done.
Firefox integration
I have the firefox plugin installed and would ideally like to use it with my wsl pass folder.
This has been a bit trickier. First install the passff addon to firefox. Then install the host-app both under linux and windows.
I modified bat install script under windows and removed the check for python3, as I will not be using the python file under windows and don't have python installed.
After installing both host scripts, I removed the python file under windows and
replaced the last line in the passff.bat file, which can both be found under
%APPDATA%\Roaming\passff
.
The new last line now calls wsl and runs the python file in wsl.
ubuntu.exe run export DISPLAY=:0; python3 /home/pflug/.mozilla/native-messaging-hosts/passff.py %*
Now just restart firefox and see that it partially working.
What is not working at the moment is entering the pin with firefox as pinentry is done on the console and the firefox plugin does not support console input.
Fixing Pinentry
To fix the pinentry some more things have to be done. First install a gui pinentry-program under linux:
sudo apt install pinentry-gtk2
gtk2 was one that worked for me, there are more available. Choose one of your liking.
After that, install a X11 server for windows like Xming and start it. We are already exporting the display value in our bat script. So no need for change there and everything should now be working.