summaryrefslogtreecommitdiff
path: root/lib/nickserver/hkp/fetch_key.rb
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-06-10 10:28:09 +0200
committerAzul <azul@riseup.net>2016-06-10 10:28:09 +0200
commit10a57e4f92432ff2b82c4a6bb5027bb3bcbdfab9 (patch)
treebcd543481044813f3d556fba6f833f4555d8d453 /lib/nickserver/hkp/fetch_key.rb
parentb4075771b2b1f3c688496d18d7a5a5f1db952004 (diff)
turn Hkp::FetchKey into Hkp::Source
The source was really just an empty shell now that we pushed the em specific stuff further down.
Diffstat (limited to 'lib/nickserver/hkp/fetch_key.rb')
-rw-r--r--lib/nickserver/hkp/fetch_key.rb59
1 files changed, 0 insertions, 59 deletions
diff --git a/lib/nickserver/hkp/fetch_key.rb b/lib/nickserver/hkp/fetch_key.rb
deleted file mode 100644
index 10c4926..0000000
--- a/lib/nickserver/hkp/fetch_key.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-require 'em-http'
-require 'nickserver/response'
-require 'nickserver/hkp/response'
-
-#
-# Fetch keys via HKP
-# http://tools.ietf.org/html/draft-shaw-openpgp-hkp-00
-#
-
-module Nickserver; module Hkp
-
- class FetchKey
-
- def initialize(adapter)
- @adapter = adapter
- end
-
- def get(nick, &block)
- FetchKeyInfo.new.search(nick).callback {|key_info_list|
- best = pick_best_key(key_info_list)
- get_key_by_fingerprint(nick, best.keyid, &block)
- }.errback {|status, msg|
- yield Nickserver::Response.new(status, msg)
- }
- end
-
- #
- # fetches ascii armored OpenPGP public key from the keyserver
- #
- def get_key_by_fingerprint(nick, key_id)
- params = {op: 'get', search: "0x" + key_id, exact: 'on', options: 'mr'}
- http = EventMachine::HttpRequest.new(Config.hkp_url).get(query: params)
- http.callback {
- status = http.response_header.status
- if status != 200
- yield Nickserver::Response.new status, "HKP Request failed"
- else
- yield Response.new nick, http.response
- end
- }
- http.errback {
- yield Nickserver::Response.new 500, http.error
- }
- end
-
- protected
-
- #
- # for now, just pick the newest key.
- #
- # in the future, we should perhaps pick the newest key
- # that is signed by the oldest key.
- #
- def pick_best_key(key_info_list)
- key_info_list.sort {|a,b| a.creationdate <=> b.creationdate}.last
- end
- end
-
-end; end