Engine/UncategorisedDevelopmentThemes/ExtractingKeys
In order to extract private keys from keys.db one could use this crude C program, which only requires libsqlite3.
This crude quickly-written program extract each private key found in a p≡p key database and copies it into a file named after the key FPR, suitable to be imported into GPG’s key ring.
gcc --static -Wall -ggdb -Og recover-keys.c -lsqlite3 -lm -o recover-keys
Of course the program can work on copies or symlinks of the keys.db files — The -shm
and -wal
files should be made available to this as well.
The program expects keys.db
to be in the current working directory when it is run.
One can do, for example,
cp ~luca/.pEp/keys.db* .
Crude instructions for using this program, not adapted and generalised.
Sva, I have prepared a little program that extracts secret keys from your
~/.pEp/keys.db database. This is something dangerous that we do not
particularly want users to do, but we technical people can afford the risk.
Become root:
sudo su
As root:
adduser --disabled-password peprecovery
(push ENTER multiple times to accept the default for every question)
mkdir ~peprecovery/peprecovery
cp ~sva/.pEp/keys.db* ~peprecovery/peprecovery/
(in the line above replace "sva" with your ordinary Unix user name
if necessary: the user name you get by typing
whoami
in a NEW, freshly-opened, terminal)
chown -R peprecovery.peprecovery ~peprecovery/peprecovery/
su peprecovery
(from now on you are no longer root, you are peprecovery)
cd ~/peprecovery
wget https://ageinghacker.net/scratch-pep/recover-keys/recover-keys
chmod a+x recover-keys
./recover-keys
(now you should have some key files)
ls KEY-*
As a test, let us download an encrypted mail as well:
wget https://ageinghacker.net/scratch-pep/recover-keys/encrypted.eml
Let us import the keys into a GPG key ring:
gpg --import KEY-*
Now we should be able to use GPG to decrypt a saved messages, as peprecovery
gpg --decrypt WHATEVERMAILFILE
ONLY at the end of this entire thing, delete the peprecovery user and everything it owns:
sudo su
rm -rf ~peprecovery/peprecovery
deluser peprecovery