diff options
author | Zara Gebru <zgebru@thoughtworks.com> | 2016-07-13 20:20:52 +0200 |
---|---|---|
committer | Zara Gebru <zgebru@thoughtworks.com> | 2016-07-13 20:35:55 +0200 |
commit | 59263baee9fc04524c8a69af1f7293fa4315d3ff (patch) | |
tree | b01cf32a0a95a11b3ea9bd279c2b251a1fb5b58e /lib | |
parent | a96a8f552074e8a624f1420d2f58db4e90c3762c (diff) |
[FEATURE] fetch key by fingerprint
- add fingerprint unit tests
- add integration test
- implement by_fingerprint
Diffstat (limited to 'lib')
-rw-r--r-- | lib/nickserver/hkp/client.rb | 4 | ||||
-rw-r--r-- | lib/nickserver/hkp/source.rb | 20 | ||||
-rw-r--r-- | lib/nickserver/request_handler.rb | 13 |
3 files changed, 23 insertions, 14 deletions
diff --git a/lib/nickserver/hkp/client.rb b/lib/nickserver/hkp/client.rb index 1fbe7a2..d53daad 100644 --- a/lib/nickserver/hkp/client.rb +++ b/lib/nickserver/hkp/client.rb @@ -27,8 +27,8 @@ module Nickserver; module Hkp # # fetches ascii armored OpenPGP public key from the keyserver # - def get_key_by_fingerprint(fingerprint, &block) - get op: 'get', search: "0x" + fingerprint, &block + def get_key_by_fingerprint(fingerprint) + get op: 'get', search: "0x" + fingerprint end protected diff --git a/lib/nickserver/hkp/source.rb b/lib/nickserver/hkp/source.rb index 0d79856..e104aa8 100644 --- a/lib/nickserver/hkp/source.rb +++ b/lib/nickserver/hkp/source.rb @@ -18,7 +18,7 @@ module Nickserver; module Hkp status, response = search(nick) if status == 200 best = pick_best_key(response) - get_key_by_fingerprint(nick, best.keyid) + get_key_by_fingerprint(best.keyid, nick) else Nickserver::Response.new(status, response) end @@ -30,6 +30,15 @@ module Nickserver; module Hkp return parser.status_for(nick), parser.response_for(nick) end + def get_key_by_fingerprint(fingerprint, nick = nil) + status, response = client.get_key_by_fingerprint fingerprint + if status == 200 + Response.new nick, response + else + Nickserver::Response.new status, "HKP Request failed" + end + end + protected # @@ -42,15 +51,6 @@ module Nickserver; module Hkp key_info_list.sort {|a,b| a.creationdate <=> b.creationdate}.last end - def get_key_by_fingerprint(nick, fingerprint) - status, response = client.get_key_by_fingerprint fingerprint - if status == 200 - Response.new nick, response - else - Nickserver::Response.new status, "HKP Request failed" - end - end - def client @client ||= Client.new(adapter) end diff --git a/lib/nickserver/request_handler.rb b/lib/nickserver/request_handler.rb index bc6d519..856ec5d 100644 --- a/lib/nickserver/request_handler.rb +++ b/lib/nickserver/request_handler.rb @@ -13,7 +13,7 @@ module Nickserver if params && params["address"] && params["address"].any? by_email(params, headers) elsif params && params["fingerprint"] && params["fingerprint"].any? - # do something else + by_fingerprint(params) else send_not_found end @@ -35,7 +35,16 @@ module Nickserver end end - #def by_fingerprint(params) + def by_fingerprint(params) + fingerprint = params["fingerprint"].first + if fingerprint.length == 40 && !fingerprint[/\H/] + source = Nickserver::Hkp::Source.new(adapter) + key_response = source.get_key_by_fingerprint(fingerprint) + send_response key_response.status, key_response.content + else + send_error('Fingerprint invalid: ' + fingerprint) + end + end def send_key(email, headers) if local_address?(email, headers) |