Module: Facter::Util::RhsmCaName

Defined in:
lib/facter/rhsm_ca_name.rb

Overview

Client Identity from the SSL certificate

Class Method Summary collapse

Class Method Details

.rhsm_ca_name(cafile) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/facter/rhsm_ca_name.rb', line 23

def rhsm_ca_name(cafile)
  ca = nil
  if File.exist?(cafile)
    begin
      cert = OpenSSL::X509::Certificate.new(File.open(cafile, 'r').read)
      if cert.subject.to_s =~ %r{.+CN=(.+)}
        ca = Regexp.last_match(1).chomp
      end
    rescue StandardError => e
      Facter.debug("#{e.backtrace[0]}: #{$ERROR_INFO}.") unless $ERROR_INFO.nil?
    end
  end
  ca
end