Module: SSLTool::KeyHelper
Defined Under Namespace
Classes: KeyHelperError, KeyMalformedError, KeyNotFoundError, KeyNotPresentError
Instance Method Summary
collapse
Instance Method Details
#find_private_key_for_certificate(cert, keys) ⇒ Object
44
45
46
|
# 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) ⇒ Object
48
49
50
51
52
53
|
# 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) ⇒ Object
29
30
31
32
33
34
35
36
37
38
|
# 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) ⇒ Object
40
41
42
|
# File 'lib/ssltool/key_helper.rb', line 40
def keys(*pems)
pems.flatten.map { |s| key(s) }
end
|