mail-gpg 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Rakefile +1 -0
- data/lib/hkp.rb +22 -2
- data/lib/mail/gpg/version.rb +1 -1
- data/test/gpghome/random_seed +0 -0
- metadata +1 -1
data/History.txt
CHANGED
data/Rakefile
CHANGED
data/lib/hkp.rb
CHANGED
@@ -1,26 +1,46 @@
|
|
1
1
|
require 'open-uri'
|
2
|
+
require 'gpgme'
|
3
|
+
|
4
|
+
# simple HKP client for public key retrieval
|
2
5
|
class Hkp
|
3
6
|
def initialize(keyserver = 'http://pool.sks-keyservers.net:11371')
|
4
7
|
@keyserver = keyserver
|
5
8
|
end
|
6
9
|
|
10
|
+
# hkp.search 'user@host.com'
|
11
|
+
# will return an array of arrays, one for each matching key found, containing
|
12
|
+
# the key id as the first elment and any further info returned by the key
|
13
|
+
# server in the following elements.
|
14
|
+
# see http://tools.ietf.org/html/draft-shaw-openpgp-hkp-00#section-5.2 for
|
15
|
+
# what that *might* be. unfortunately key servers seem to differ in how much
|
16
|
+
# and what info they return besides the key id
|
7
17
|
def search(name)
|
8
18
|
[].tap do |results|
|
9
19
|
open("#{@keyserver}/pks/lookup?options=mr&search=#{URI.escape name}") do |f|
|
10
20
|
f.each_line do |l|
|
11
|
-
|
12
|
-
|
21
|
+
components = l.strip.split(':')
|
22
|
+
if components.shift == 'pub'
|
23
|
+
results << components
|
13
24
|
end
|
14
25
|
end
|
15
26
|
end
|
16
27
|
end
|
17
28
|
end
|
18
29
|
|
30
|
+
# returns the key data as returned from the server as a string
|
19
31
|
def fetch(id)
|
20
32
|
open("#{@keyserver}/pks/lookup?options=mr&op=get&search=0x#{URI.escape id}") do |f|
|
21
33
|
return clean_key f.read
|
22
34
|
end
|
35
|
+
end
|
23
36
|
|
37
|
+
# fetches key data by id and imports the found key(s) into GPG, returning the full hex fingerprints of the
|
38
|
+
# imported key(s) as an array. Given there are no collisions with the id given / the server has returned
|
39
|
+
# exactly one key this will be a one element array.
|
40
|
+
def fetch_and_import(id)
|
41
|
+
if key = fetch(id)
|
42
|
+
GPGME::Key.import(key).imports.map(&:fpr)
|
43
|
+
end
|
24
44
|
end
|
25
45
|
|
26
46
|
private
|
data/lib/mail/gpg/version.rb
CHANGED
data/test/gpghome/random_seed
CHANGED
Binary file
|