def ssl_available_files
certificates = []
key_files = []
%w(combined key crt cert pem).each do |ext|
contents = get_param("ssl.#{ext}", self.config_dir)
next if false == contents
this_fn = File.join(self.config_dir, "ssl.#{ext}")
this_cert = nil
this_key = nil
begin
this_cert = OpenSSL::X509::Certificate.new(contents)
rescue OpenSSL::OpenSSLError
this_cert = nil
end
begin
this_key = OpenSSL::PKey::RSA.new(contents)
rescue OpenSSL::OpenSSLError
this_key = nil
end
if this_key and this_cert and this_cert.check_private_key(this_key)
certificates << [this_fn, this_cert]
key_files << this_fn
elsif this_key and !this_cert
key_files << this_fn
elsif this_cert and !this_key
certificates << [this_fn, this_cert]
end
end
now = Time.now
certificate_files = certificates.sort_by { |fn, cert|
score = cert.not_after.to_i
score -= not_before.to_i if cert.not_before > now
score -= now.to_i if now > cert.not_after
-score
}.map { |fn, cert| fn }
[certificate_files, key_files]
end