module SSLTool::KeyHelper
Public Instance Methods
find_private_key_for_certificate(cert, keys)
click to toggle source
# File lib/ssltool/key_helper.rb, line 44 def find_private_key_for_certificate(cert, keys) keys.find { |key| cert.check_private_key(key) } end
find_private_key_for_certificate!(cert, keys)
click to toggle source
# File lib/ssltool/key_helper.rb, line 48 def find_private_key_for_certificate!(cert, keys) raise KeyNotPresentError if keys.empty? key = find_private_key_for_certificate(cert, keys) return key if key raise KeyNotFoundError.new(cert, keys) end
key(s)
click to toggle source
# File lib/ssltool/key_helper.rb, line 29 def key(s) error = -> { raise KeyMalformedError, "Key appears to be malformed, or is passphrase-protected." } case s when /\A-----BEGIN EC PRIVATE KEY/ then OpenSSL::PKey::EC.new(s, '').tap{|k| k.singleton_class.class_eval{ alias_method :private?, :private_key? }} when /\A-----BEGIN (RSA )?PRIVATE KEY/ then OpenSSL::PKey::RSA.new(s, '') else error[] end rescue OpenSSL::PKey::ECError, OpenSSL::PKey::RSAError => e error[] end
keys(*pems)
click to toggle source
# File lib/ssltool/key_helper.rb, line 40 def keys(*pems) pems.flatten.map { |s| key(s) } end
scan(s)
click to toggle source
# File lib/ssltool/key_helper.rb, line 25 def scan(s) PEMScanner.keys_from(s) end