summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/nickserver/email_address.rb4
-rw-r--r--lib/nickserver/reel_server.rb2
-rw-r--r--lib/nickserver/wkd/Readme.md8
-rw-r--r--lib/nickserver/wkd/source.rb16
-rw-r--r--lib/nickserver/wkd/url.rb31
-rw-r--r--lib/zbase32.rb19
6 files changed, 79 insertions, 1 deletions
diff --git a/lib/nickserver/email_address.rb b/lib/nickserver/email_address.rb
index c5d5df7..20f642c 100644
--- a/lib/nickserver/email_address.rb
+++ b/lib/nickserver/email_address.rb
@@ -37,6 +37,10 @@ module Nickserver
address.split('@')[1]
end
+ def local_part
+ address.split('@')[0]
+ end
+
def to_s
address
end
diff --git a/lib/nickserver/reel_server.rb b/lib/nickserver/reel_server.rb
index 9626466..db38e50 100644
--- a/lib/nickserver/reel_server.rb
+++ b/lib/nickserver/reel_server.rb
@@ -43,7 +43,7 @@ module Nickserver
handler.respond_to params(request), request.headers
end
end
- rescue StandardError => e
+ rescue StandardError
request.respond 500, "{}"
end
diff --git a/lib/nickserver/wkd/Readme.md b/lib/nickserver/wkd/Readme.md
new file mode 100644
index 0000000..c93e08c
--- /dev/null
+++ b/lib/nickserver/wkd/Readme.md
@@ -0,0 +1,8 @@
+Allow querying keys from web key directories offered by the users
+provider.
+
+Summary is here:
+ https://wiki.gnupg.org/WKD
+
+Specs are here:
+ https://tools.ietf.org/html/draft-koch-openpgp-webkey-service-00
diff --git a/lib/nickserver/wkd/source.rb b/lib/nickserver/wkd/source.rb
new file mode 100644
index 0000000..01f376e
--- /dev/null
+++ b/lib/nickserver/wkd/source.rb
@@ -0,0 +1,16 @@
+require 'nickserver/source'
+require 'nickserver/response'
+
+module Nickserver
+ module Wkd
+ class Source < Nickserver::Source
+
+ def query(email)
+ url = Url.new(email)
+ status, body = adapter.get url
+ return Nickserver::Response.new(status, body)
+ end
+
+ end
+ end
+end
diff --git a/lib/nickserver/wkd/url.rb b/lib/nickserver/wkd/url.rb
new file mode 100644
index 0000000..965e7ec
--- /dev/null
+++ b/lib/nickserver/wkd/url.rb
@@ -0,0 +1,31 @@
+require 'digest/sha1'
+require 'zbase32'
+
+module Nickserver
+ module Wkd
+ class Url
+
+ def initialize(email)
+ @domain = email.domain.downcase
+ @local_part = email.local_part.downcase
+ end
+
+ def to_s
+ "https://#{domain}/.well-known/openpgpkey" +
+ "/hu/#{domain}/#{encoded_digest}"
+ end
+
+ protected
+
+ attr_reader :domain, :local_part
+
+ def encoded_digest
+ ZBase32.encode32(digest.to_i(16).to_s(2))
+ end
+
+ def digest
+ Digest::SHA1.hexdigest local_part
+ end
+ end
+ end
+end
diff --git a/lib/zbase32.rb b/lib/zbase32.rb
new file mode 100644
index 0000000..754213d
--- /dev/null
+++ b/lib/zbase32.rb
@@ -0,0 +1,19 @@
+module ZBase32
+
+ ALPHABET = 'ybndrfg8ejkmcpqxot1uwisza345h769'.split('').freeze
+
+ def self.encode32(bin_string)
+ bin_string.scan(/[01]{1,5}/).map do |bits|
+ ALPHABET[bits.ljust(5, '0').to_i(2)]
+ end.join
+ end
+
+ def self.decode32(enc)
+ bin = enc.split('').map do |char|
+ ALPHABET.index(char).to_s(2).rjust(5, '0')
+ end.join
+ bin[0, (8 * (bin.length / 8))]
+ # .sub /10*$/ ,'1'
+ end
+
+end