From 7b5eb8968cfdae18eb72e587fb6da02c9d6c4248 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Fri, 22 Feb 2019 23:45:41 +0100 Subject: [PATCH] Handle common HKP queries using nginx. - Fixes #46. --- nginx.conf | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/nginx.conf b/nginx.conf index 55f12a6..2793b26 100644 --- a/nginx.conf +++ b/nginx.conf @@ -17,7 +17,7 @@ http { root dist/public; location /by-email/ { - rewrite ^/by-email/([^/][^/])(..*)$ /by-email/$1/$2 break; + rewrite "^/by-email/([^/]{2})([^/]*)$" /by-email/$1/$2 break; default_type application/pgp-keys; try_files /$uri =404; } @@ -34,6 +34,31 @@ http { try_files /$uri =404; } + # Common HKP requests. + location /pks/lookup { + # sq keyserver get , gpg --receive-keys + if ($args ~* "^op=get&options=mr&search=0x([A-F0-9]{2})([A-F0-9]{14})$") { + set $dir $1; + set $file $2; + rewrite . /by-keyid/$dir/$file; + } + + # gpg --receive-keys + if ($args ~* "^op=get&options=mr&search=0x([A-F0-9]{2})([A-F0-9]{38})$") { + set $dir $1; + set $file $2; + rewrite . /by-fingerprint/$dir/$file; + } + + # gpg --locate-key + if ($args ~* "^op=get&options=mr&search=(..)([^&]*)@([^&]*)") { + set $dir $1; + set $local $2; + set $horst $3; + rewrite . /by-email/$dir/$local%40$horst; + } + } + location = / { proxy_pass http://127.0.0.1:8080; }