simple-gnupg-keyserver 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -90,6 +90,53 @@ the use of humans:
90
90
  * uploadForm.html
91
91
  * footer.html
92
92
 
93
+ == SYNCHRONIZATION
94
+
95
+ A 'simpleHKP/echo' class has been added which knows how to echo keys from
96
+ one key server to another.
97
+
98
+ So that for example the following ruby script could be placed into one
99
+ of your machine's /etc/daily directories and the script would ensure
100
+ all key servers are synchronized daily.
101
+
102
+ #!/usr/bin/env ruby
103
+
104
+ # A simple key server sychronization example
105
+ #
106
+ # We use a hub-spoke model. We choose one "hub" key server to act as
107
+ # the master key server and amalgamate all of the keys from the spoke
108
+ # key server back to the hub key server. We then push the amalgamated
109
+ # keys in the hub back to the spokes, so that after two passes, all key
110
+ # servers have the same keys.
111
+
112
+ require 'simpleHKP/echo'
113
+
114
+ hubKeyServer = 'hubKeyServer'
115
+ spokeKeyServers = [
116
+ 'spokeKeyServer1',
117
+ 'spokeKeyServer2',
118
+ 'spokeKeyServer3'
119
+ ]
120
+
121
+ # Start by bringing all spoke keys into the hub
122
+ #
123
+ spokeKeyServers.each do | aKeyServer |
124
+ SimpleHKPEcho.echoFromTo(aKeyServer, hubKeyServer)
125
+ end
126
+
127
+ # now send the amalgamated hub keys back to each spoke
128
+ #
129
+ spokeKeyServers.each do | aKeyServer |
130
+ SimpleHKPEcho.echoFromTo(hubKeyServer, aKeyServer)
131
+ end
132
+
133
+ Where the "hubKeyServer" and "spokeKeyServersX" are the fully qualified
134
+ domain or IP address of each of your key servers.
135
+
136
+ The SimpleHKPEcho.echoFromTo method fails gracefully if a given key
137
+ server is offline, by simply returning. In the example above, all other
138
+ echo pairs (from, to) will be tried.
139
+
93
140
  == REQUIREMENTS:
94
141
 
95
142
  There are explicitly no external Ruby requirements other than Ruby and
@@ -41,7 +41,7 @@ require 'fileutils'
41
41
 
42
42
  class SimpleHKP
43
43
 
44
- VERSION = "1.2.0"
44
+ VERSION = "1.3.0"
45
45
 
46
46
  def saveLastKey(lastKey)
47
47
  lastKey['colonData'].gsub!(/\\x3a/,':') if
@@ -0,0 +1,86 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'pp'
4
+
5
+ # This code provides a simple way to ensure keys are synchronized
6
+ # between a pair of key servers.
7
+
8
+ # It conforms to: The OpenPGP HTTP Keyserver Protocol (HKP)
9
+ # draft-shaw-openpgp-hkp-00.txt
10
+ # http://tools.ietf.org/html/draft-shaw-openpgp-hkp-00
11
+
12
+ # See also the doc/DETAILS file in the gnupg2 source code
13
+
14
+ # Copyright (C) 2015 Stephen Gaito
15
+ #
16
+ # (The MIT License)
17
+ #
18
+ # Copyright (c) 2015 Stephen Gaito
19
+ #
20
+ # Permission is hereby granted, free of charge, to any person obtaining a
21
+ # copy of this software and associated documentation files (the
22
+ # 'Software'), to deal in the Software without restriction, including
23
+ # without limitation the rights to use, copy, modify, merge, publish,
24
+ # distribute, sublicense, and/or sell copies of the Software, and to
25
+ # permit persons to whom the Software is furnished to do so, subject to
26
+ # the following conditions:
27
+ #
28
+ # The above copyright notice and this permission notice shall be included
29
+ # in all copies or substantial portions of the Software.
30
+ #
31
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS
32
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
34
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
35
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
36
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
37
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38
+
39
+ class SimpleHKPEcho
40
+
41
+ class << self
42
+
43
+ def convertToHttp(aKeyServerStr)
44
+ aKeyServerStr = aKeyServerStr+':11371' unless
45
+ aKeyServerStr =~ /:/
46
+ aKeyServerStr = 'http://'+aKeyServerStr unless
47
+ aKeyServerStr =~ /^http/
48
+ aKeyServerStr
49
+ end
50
+
51
+ def echoFromTo(fromKeyServer, toKeyServer, options = {})
52
+ begin
53
+ debug = options.delete('debug')
54
+ puts fromKeyServer if debug
55
+ fromKeyServer = convertToHttp(fromKeyServer)
56
+ puts fromKeyServer if debug
57
+ puts toKeyServer if debug
58
+ toKeyServer = convertToHttp(toKeyServer)
59
+ puts toKeyServer if debug
60
+
61
+ keys = Array.new
62
+ url = URI.parse(fromKeyServer+'/lookup?search=&op=index&options=mr')
63
+ response = Net::HTTP.get_response(url)
64
+ response.body.each_line do | aLine |
65
+ next unless aLine =~ /^pub/
66
+ keys.push(aLine.split(/:/)[1])
67
+ end
68
+ pp keys if debug
69
+ keys.each do | aKey |
70
+ keyData = ""
71
+ url = URI.parse(fromKeyServer+"/lookup?op=get&options=mr&search=#{aKey}")
72
+ response = Net::HTTP.get_response(url)
73
+ keyData = response.body
74
+ puts aKey if debug
75
+ puts keyData if debug
76
+ url = URI.parse(toKeyServer+'/add')
77
+ Net::HTTP.post_form(url, { 'keytext' => keyData })
78
+ end
79
+ rescue SocketError => se
80
+ puts "Cound not echo keys from #{fromKeyServer} to #{toKeyServer}"
81
+ end
82
+ end
83
+
84
+ end
85
+
86
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-gnupg-keyserver
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -64,6 +64,7 @@ files:
64
64
  - README.rdoc
65
65
  - Rakefile
66
66
  - lib/simpleHKP.rb
67
+ - lib/simpleHKP/echo.rb
67
68
  homepage: https://github.com/stephengaito/rGem-simple-gnupg-keyserver
68
69
  licenses:
69
70
  - MIT