Sending a message to a webmaster with his public key… The idea behind this I actually got from an April fools released by c&t magazine. To cut a long story short they claimed that weak GDPR phrasing could be a reason that common letter post might need to be properly encrypted. They even provided a tool that extracts a websites public key use it to encrypt a provided message.
Anyway. I was thinking how I could use this to send webmasters encrypted messages when they do not offer public keys emailing. And for some reason I do not was to ask them for keys. Maybe because I am incredibly clever and shy at the same time … never mind.
To get a basic understanding how symmetric and asymmetric encryption - to say the relationship between public and private keys - works just watch this video. I started adding captions in English. Hopefully they will be released into the wild soon.
THX @dunkelmunkel Feel free to watch more of his videos 😉
Grab the key
For this example I will use the website of my female fellow Wintermohn
Two things are needed: A public key and a way to send a message. For the message I think webmaster@ or postmaster@… will probably do.
But first things first. I need a key! (Sorry, played too much Blood lately.)
You should visit the target website beforehand using your browser to check if it loads normally and does not have an invalid or expired certificate.
I used this command to directly extract the public key:
gnutls-cli --print-cert wintermohn.de </dev/null 2>/dev/null|openssl x509 -pubkey -noout
gnutls-cli is a part of the
This should give us an output just like this:
—–BEGIN PUBLIC KEY—–
—–END PUBLIC KEY—–
The output may vary because certificates getting renewed from time to time which obviously causes keys to change.
For further processing the key should be saved into a file, pubkey.txt for example. This can easily be achieved by adding
> pubkey.txt behind the command above.
Use the key
As learned earlier a public key can be used to encrypt a message in a way that the only method to decrypt it is to own the private key. So let’s do it.
To make my live a bit easier first I created a simple text file with my message inside. I call it message.txt and it contains this:
——- PLAIN TEXT ——-
how are you?
——- PLAIN TEXT ——-
There is no need for the PLAIN TEXT stuff, I just added it for better understanding. I censored a part of the message because I want to know if Wintermohn is capable to decrypt the message ;-).
Alright, lets just do a quick summary:
pubkey.txtcontaining our public key
message.txtcontaining our unencrypted message.
encrypted.txtcontaining our encrypted message.
privkey.txtcontaining their private key. More on that one later.
For encrypting the message I used this command:
openssl rsautl -encrypt -pubin -inkey pubkey.txt -in message.txt | base64
The output should look like this:
We can put it directly into a file using
> encrypted.txt added to the command above.
This is actually not the “plain” encrypted message. It has been converted in a “human readable” way using
base64. Just try to open the encrypted message without
base64 and see the mess…
And done. All left to do is to send the message to the webmaster with some additional information about which public key has been used to encrypt it. Otherwise our receiver will have a very tough time… Or most likely simply discards your message.
Switching the roles
Now I am Wintermohn and received a message encrypted with the public key of my website.
First I need to grab my private key which is usually stored on the webserver and looks something like this:
—–BEGIN PRIVATE KEY—–
—–END PRIVATE KEY—–
Storing the key into a file makes it easier to use it in the command line, so new file:
Using this command I can decrypt the message:
base64 -d encrypted.txt |openssl rsautl -decrypt -inkey privkey.txt
I thought this might be interesting. And even not it was fun to write about it.