Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Any tips on how to easily fetch the key length of DKIM-Keys from DNS? Just by looking at the DNS entries I can't easily determine the key length ;)


Fetch the TXT record; you should see something like,

  k=rsa; … p=<a bunch of base64 data>
The base64 data is an RSA public key. You can print in textual form with something like,

  your-clipboard-paste-command | base64 -d | openssl rsa -pubin -noout -inform der -text
The first line of output will be something like,

  Public-Key: (2048 bit)
Which is the key length.

If you fetch with `dig`, note that sometimes dig will do this:

  example.com. 1800 IN TXT "k=rsa; t=s; p=blahblahblahblah" "blahblahblah"
I.e., it breaks it up with a `" "`; remove those, that's not part of the data. I.e., concat the strings dig returns, then parse out the p=, then base64 decode, then openssl.

(You can also do what the article does, but without Python, which is jam that base64 between some PEM header guards like the article does, and then feed it to openssl. Same command, but you don't need the -inform der b/c the "in[put] form[at]" is now pem, which is the default.)


An easy way is to check the length of the p= value in the DKIM record. If it's around 216 characters, it's likely a 1024-bit key. A 2048-bit key usually has about 388 characters.


If you're going to do this you should also check for k=rsa since other key types will be different lengths. But I'd really recommend something like in the other comment where you base64 decode and parse it with something like openssl.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: