Sha256: ac818063684046ff788e91cf47e86036a4cf71242bfbc99e86a5edcf114fb319

Contents?: true

Size: 822 Bytes

Versions: 9

Compression:

Stored size: 822 Bytes

Contents

require 'openssl'
require 'base64'

module Client
  class Cert
    attr_accessor :cert

    def initialize(cert)
      self.cert = extract(cert)
    end

    def uuid
      drop_cn_prefix_from_subject(@cert.subject.to_s)
    end

    private

    def extract(cert)
      if cert.empty?
        fail('Invalid cert provided. Ensure that the provided cert is not empty.')
      else
        cert = strip_cert(cert)
        cert = Base64.decode64(cert)

        OpenSSL::X509::Certificate.new(cert)
      end
    end

    def drop_cn_prefix_from_subject(subject_string)
      subject_string.sub(/\/CN=/i, '')
    end

    def strip_cert(cert)
      cert = cert.to_s.gsub("-----BEGIN CERTIFICATE-----", "").gsub("-----END CERTIFICATE-----", "")
      cert.gsub!(' ', '')
      cert.gsub!(/\n/, '')
      cert
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
katello-2.4.5 app/services/client/cert.rb
katello-2.4.4 app/services/client/cert.rb
katello-2.4.3 app/services/client/cert.rb
katello-2.4.2 app/services/client/cert.rb
katello-2.4.1 app/services/client/cert.rb
katello-2.4.0 app/services/client/cert.rb
katello-2.4.0.rc3 app/services/client/cert.rb
katello-2.4.0.rc2 app/services/client/cert.rb
katello-2.4.0.rc1 app/services/client/cert.rb