Object
The Verifier is used for verifying signatures. If you use the decode or from_file methods you can use either raw PEM encoded public keys or certificate.
Decodes a PEM encoded Certificate or Public Key and returns a Verifier object.
# File lib/ezsig.rb, line 137 def self.decode(encoded) case encoded when /-----BEGIN CERTIFICATE-----/ EzCrypto::Certificate.new(OpenSSL::X509::Certificate.new( encoded)) else begin EzCrypto::Verifier.new(OpenSSL::PKey::RSA.new( encoded)) rescue EzCrypto::Verifier.new(OpenSSL::PKey::DSA.new( encoded)) end end end
Decodes a PEM encoded Certificate or Public Key from a file and returns a Verifier object.
# File lib/ezsig.rb, line 153 def self.from_file(filename) file = File.read( filename ) decode(file) end
Load a certificate or public key from PKYP based on it’s hex digest
# File lib/ezsig.rb, line 161 def self.from_pkyp(digest) digest=digest.strip.downcase if digest=~/[0123456789abcdef]{40}/ # Net::HTTP.start("localhost", 9000) do |query| Net::HTTP.start("pkyp.org", 80) do |query| response=query.get "/#{digest}.pem" if response.code=="200" decode(response.body) else raise "Error occured (#{response.code}): #{response.body}" end end else raise "Invalid digest" end end
Decodes all certificates or public keys in a file and returns an array.
# File lib/ezsig.rb, line 181 def self.load_all_from_file(filename) file = File.read( filename ) certs=[] count=0 file.split( %{-----BEGIN}).each do |pem| if pem and pem!="" pem="-----BEGIN#{pem}\n" cert=decode(pem) if cert.is_a? EzCrypto::Verifier certs<<cert end end end certs end
Initializes a Verifier using a OpenSSL public key object.
# File lib/ezsig.rb, line 130 def initialize(pub) @pub=pub end
Is the Verifier a Certificate or not.
# File lib/ezsig.rb, line 200 def cert? false end
Returns the SHA1 hexdigest of the DER encoded public key. This can be used as a unique key identifier.
# File lib/ezsig.rb, line 214 def digest Digest::SHA1.hexdigest(@pub.to_der) end
Is this a DSA key?
# File lib/ezsig.rb, line 226 def dsa? @pub.is_a? OpenSSL::PKey::DSA end
Returns the OpenSSL public key object. You would normally not need to use this.
# File lib/ezsig.rb, line 207 def public_key @pub end
Register the public key or certificate at PKYP
# File lib/ezsig.rb, line 247 def register_with_pkyp send_to_pkyp(@pub.to_s) end
# File lib/ezsig.rb, line 253 def send_to_pkyp(pem) # Net::HTTP.start("localhost", 9000) do |query| Net::HTTP.start("pkyp.org", 80) do |query| output=URI.escape(pem).gsub("+","%2b") response=query.post "/register","body="+output if response.code=="302" response["Location"]=~/([0123456789abcdef]{40}$)/ $1 else raise "Error occured (#{response.code}): #{response.body}" end end end
Generated with the Darkfish Rdoc Generator 2.