# rpk --- retrieve public key class from openpksd.org # Author: Hironobu SUZUKI # License: GPL 2 # $Id: rpk.rb,v 1.10 2004/04/06 05:10:22 hironobu Exp $ # if (VERSION < "1.8.0") printf "Use Ruby 1.8.0 or later, your Ruby version: %s...bye\n",VERSION exit(1) end require 'open-uri' class RetrievePublicKey def initialize () @keyid_hash = Hash.new @emailaddr="" @output=STDOUT @debug=0 @openpksd_site="openpksd.org" i="$Id: rpk.rb,v 1.10 2004/04/06 05:10:22 hironobu Exp $".split(' ') @version="Retrieve Public Key (RCSRev:"< 5 ) print uri,"\n" end begin keyserv=open(uri,"User-Agent" => @version) rescue printf "OpenPKSD keyserver site \"%s\" can't open...bye\n",@openpksd_site exit (1) end keyserv.each{|line| if (line =~ /^\/) @keyid_hash[$1]=true elsif (line =~ /^Key was not found:/ ) printf "Specified email address was not found in keyserver: %s\n",@emailaddr exit(0); end } keyserv.close end # # Get Key by key id # def getKeyByKeyid @keyid_hash.each_key{|longkey| uri=sprintf("http://%s/cgi-bin/lookup?search=%s",@openpksd_site,longkey) if (@debug > 5 ) print uri,"\n"; end begin keyserv=open(uri,"User-Agent" => @version) rescue printf "OpenPKSD keyserver site \"%s\" can't open...bye\n",@openpksd_site exit (1) end openblock=false keyserv.each{|line| if ( line =~ /^-----BEGIN PGP PUBLIC KEY BLOCK-----/ ) openblock=true elsif ( line =~/^-----END PGP PUBLIC KEY BLOCK-----/ ) openblock=false @output.print line end if ( openblock == true ) @output.print line end } keyserv.close } begin @output.close rescue end end # # Get Public Key # Email address or key id(s) must pre-set in an instance. # def getPublicKey if @emailaddr != nil self.getKeyidByEmailAddr end self.getKeyByKeyid end end