diff options
author | Azul <azul@riseup.net> | 2017-09-22 15:30:40 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2017-09-23 16:53:27 +0200 |
commit | 22c6c80310a8d3d3abbd1006598b4fbaec98ffd0 (patch) | |
tree | 23bcd565750f68c3ffb644c30be06138b4c3e341 /lib/nickserver/wkd | |
parent | 787287318c54b019a12ef79525c9f5b10d93724d (diff) |
wkd: implement basic lookup of keys through wkd
wkd is the web key directory. See the Readme.md in
/lib/nickserver/wkd
Diffstat (limited to 'lib/nickserver/wkd')
-rw-r--r-- | lib/nickserver/wkd/source.rb | 23 | ||||
-rw-r--r-- | lib/nickserver/wkd/url.rb | 3 |
2 files changed, 22 insertions, 4 deletions
diff --git a/lib/nickserver/wkd/source.rb b/lib/nickserver/wkd/source.rb index 01f376e..750d3fa 100644 --- a/lib/nickserver/wkd/source.rb +++ b/lib/nickserver/wkd/source.rb @@ -1,5 +1,7 @@ require 'nickserver/source' require 'nickserver/response' +require 'nickserver/wkd/url' +require 'nickserver/hkp/response' module Nickserver module Wkd @@ -7,10 +9,27 @@ module Nickserver def query(email) url = Url.new(email) - status, body = adapter.get url - return Nickserver::Response.new(status, body) + status, blob = adapter.get url + Hkp::Response.new(email.to_s, armor_key(blob)) if status == 200 end + protected + + def armor_key(blob) + header + encode(blob) + footer + end + + def encode(blob) + Base64.strict_encode64(blob).scan(/.{1,64}/).join "\n" + end + + def header + "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n" + end + + def footer + "\n-----END PGP PUBLIC KEY BLOCK-----\n" + end end end end diff --git a/lib/nickserver/wkd/url.rb b/lib/nickserver/wkd/url.rb index 965e7ec..1670628 100644 --- a/lib/nickserver/wkd/url.rb +++ b/lib/nickserver/wkd/url.rb @@ -11,8 +11,7 @@ module Nickserver end def to_s - "https://#{domain}/.well-known/openpgpkey" + - "/hu/#{domain}/#{encoded_digest}" + "https://#{domain}/.well-known/openpgpkey/hu/#{encoded_digest}" end protected |