March 13, 2015

Publishing PGP keys in DNS

In most cases people publish their GPG Key on a key server which (typically) syncs keys with other key servers. Yesterday I learned that there’s an other option:

When you are in control of a DNS server you can publish your key (or more specifically: a pointer to that key) in a DNS TXT record. So what you’re doing is the following:

  • you export your public key to a file, preferably ASCII armored

  • you determine the fingerprint of your key, e.g., 1329A7635CB51DB6082DE985191F4CB8165D7A58

  • you publish the public key on your website, e.g.,

  • you create a DNS TXT record as follows: TXT “v=pka1;fpr=1329A7635CB51DB6082DE985191F4CB8165D7A58;uri=”

What you’re basically doing is to create a DNS record that links the identity (mail address) (the “@” is replaced by “_pka.”"), the fingerprint of the key, and the location where the key is stored. Nice idea.

After some minutes verify if the new DNS entry is already available by…

> dig +short TXT

If yes, continue. Now find the line with “auto-key-locate” in your ~/.gnupg/gpg.conf file and add “pka”. Maybe you only need to uncomment something like:

# auto-key-locate cert pka ldap whatever...

Now you can try if the new configuration works by trying to encrypt (-e) some file using the key we just put into DNS (-r). When you do not have a machine where this key is not installed yet use a temporary key ring. The needed key will be automatically located by the DNS TXT record, downloaded from your web site, put into your key ring and finally used for encryption:

> gpg -e -a --auto-key-locate pka -r some.file
gpg: requesting key 1329A763 from http server
gpg: key 1329A763: public key "Flupp <>" imported
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
gpg: automatically retrieved `' via PKA
gpg: 1329A763: There is no assurance this key belongs to the named user

pub  4096R/1329A763 2015-02-15 Flupp <>
 Primary key fingerprint: 1329 A763 5CB5 1DB6 082D E985 191F 4CB8 165D 7A58
      Subkey fingerprint: E985 191F 4CB8 165D 7A58 1329 A763 5CB5 1DB6 082D

It is NOT certain that the key belongs to the person named
in the user ID.  If you *really* know what you are doing,
you may answer the next question with yes.

Use this key anyway? (y/N) y


The “It is NOT certain” warning above is a little over-dramatic, as I think… The impostor would have to control your DNS (and your web server) in order to fake this result. This is quite difficult. But as this can never be ruled out, only trust a key that you have verified by yourself.

Further reading:

© ho1ger 2015 - 2022