class SimpleHKPEcho

Copyright © 2015 Stephen Gaito

(The MIT License)

Copyright © 2015 Stephen Gaito

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Public Class Methods

convertToHttp(aKeyServerStr) click to toggle source
# File lib/simpleHKP/echo.rb, line 44
def convertToHttp(aKeyServerStr)
  aKeyServerStr = aKeyServerStr+':11371' unless
    aKeyServerStr =~ /:/
  aKeyServerStr = 'http://'+aKeyServerStr unless 
    aKeyServerStr =~ /^http/
  aKeyServerStr
end
echoFromTo(fromKeyServer, toKeyServer, options = {}) click to toggle source
# File lib/simpleHKP/echo.rb, line 120
def echoFromTo(fromKeyServer, toKeyServer, options = {})
  echoKeysFromTo(fromKeyServer, toKeyServer, options)
  echoIdentitiesFromTo(fromKeyServer, toKeyServer, options)
end
echoIdentitiesFromTo(fromKeyServer, toKeyServer, options = {}) click to toggle source
# File lib/simpleHKP/echo.rb, line 86
def echoIdentitiesFromTo(fromKeyServer, toKeyServer, options = {})
  begin
    debug = options.delete('debug')
    puts fromKeyServer if debug
    fromKeyServer = convertToHttp(fromKeyServer)
    puts fromKeyServer if debug
    puts toKeyServer if debug
    toKeyServer   = convertToHttp(toKeyServer)
    puts toKeyServer if debug

    identities = Array.new
    url = URI.parse(fromKeyServer+'/pis/lookup?search=&op=index&options=mr')
    response = Net::HTTP.get_response(url)
    response.body.each_line do | aLine |
      next unless aLine =~ /^idn/
      identities.push(aLine.split(/:/)[1])
    end
    pp identities if debug
    identities.each do | anIdFile |
      idData = ""
      url = URI.parse(fromKeyServer+"/pis/lookup?op=get&options=mr&search=#{anIdFile}")
      response = Net::HTTP.get_response(url)
      idData = response.body
      puts anIdFile if debug
      puts idData if debug
      url = URI.parse(toKeyServer+'/pis/add')
      Net::HTTP.post_form(url, { 'keytext' => idData })
    end
  rescue Exception => ex
    puts "Cound not echo identities from #{fromKeyServer} to #{toKeyServer}"
    puts ex
  end
end
echoKeysFromTo(fromKeyServer, toKeyServer, options = {}) click to toggle source
# File lib/simpleHKP/echo.rb, line 52
def echoKeysFromTo(fromKeyServer, toKeyServer, options = {})
  begin
    debug = options.delete('debug')
    puts fromKeyServer if debug
    fromKeyServer = convertToHttp(fromKeyServer)
    puts fromKeyServer if debug
    puts toKeyServer if debug
    toKeyServer   = convertToHttp(toKeyServer)
    puts toKeyServer if debug

    keys = Array.new
    url = URI.parse(fromKeyServer+'/pks/lookup?search=&op=index&options=mr')
    response = Net::HTTP.get_response(url)
    response.body.each_line do | aLine |
      next unless aLine =~ /^pub/
      keys.push(aLine.split(/:/)[1])
    end
    pp keys if debug
    keys.each do | aKey |
      keyData = ""
      url = URI.parse(fromKeyServer+"/pks/lookup?op=get&options=mr&search=#{aKey}")
      response = Net::HTTP.get_response(url)
      keyData = response.body
      puts aKey if debug
      puts keyData if debug
      url = URI.parse(toKeyServer+'/pks/add')
      Net::HTTP.post_form(url, { 'keytext' => keyData })
    end
  rescue Exception => ex
    puts "Cound not echo keys from #{fromKeyServer} to #{toKeyServer}"
    puts ex
  end
end