For face or fingerprint unlock methods that log in but don't unlock the keyring
This works on Pop OS and probably any Ubuntu based distro
Uses https://codeberg.org/umglurf/gnome-keyring-unlock and https://github.com/tpm2-software/tpm2-tools
This is required to use the TPM
sudo usermod -aG tss your_username
log out and back in, and check that you are in the tss group:
groups
sudo apt install tpm2-tools
git clone https://codeberg.org/umglurf/gnome-keyring-unlock.git
mkdir -p ~/.tpm && cd ~/.tpm
tpm2_createprimary -c primary.ctx
tpm2_create -C primary.ctx -Gaes128 -u key.pub -r key.priv
tpm2_load -C primary.ctx -u key.pub -r key.priv -c key.ctx
read password
tpm2_encryptdecrypt -c key.ctx -o password.enc <<<$password
Save the following as ~/Scripts/unlockKeyring.sh
:
#!/bin/bash
# Load a TPM Context key, decode password and unlock the gnome keyring
tpm2_createprimary -Q -c ~/.tpm/primary.ctx
tpm2_load -Q -C ~/.tpm/primary.ctx -u ~/.tpm/key.pub -r ~/.tpm/key.priv -c ~/.tpm/key.ctx
tpm2_encryptdecrypt -Qd -c ~/.tpm/key.ctx ~/.tpm/password.enc | ~/gnome-keyring-unlock/unlock.py
Add the following to the end of your ~/.profile
:
# Wait 5 seconds then try to unlock the keyring
(sleep 5; ~/Scripts/unlockKeyring.sh &> ~/Scripts/unlockKeyring.log) &
Worked for me but with a slight change.
My TPM doesn't support EncryptDecrypt. I have had this error when trying to use
tpm2_encryptdecrypt
: Esys_EncryptDecrypt(0xB0143) - rmt:error(2.0): command code not supported.So I used a workaround, insipred by solution provided here. This workaround solution does not provide an example of passing an encrypted password to encrypt or decrypt a key, so I have modified it to fit my needs. Now I am sharing my solution with you.
Here is what I have done on my Ubuntu 22.04.
The first steps are as in original post.
The following steps differ from the originally proposed method and use
openssl
instead oftpm2_encryptdecrypt
:Generate encrypted password
This encrypted password will be later passed as an argument to
unlock.py
.Note.
openssl
command does not expand~
(tilde) to your user's home directory (e.g./home/john
) , so make sure you use environment variable$HOME
when providing paths.Generate TPM primary object
Create Unlock Script
Save this script anywhere and make it executable.
Note. you can always copy
unlock.py
to any other directory accessible for your user if you don't want to store git directorygnome-keyring-unlock
in your home dir.As in original post, add the following to the end of your
~/.profile
:Note. You can always sleep for less if your computer succeeds to start up quickly. These 5 seconds here are just to make sure the required daemons are already launched and running during system startup. I have removed the
sleep
and it stil works fine.