Sha256: 053c0a6fd8190cd24e5ad3b623b21ce5132360c48d9aea75c7649f092f373d61

Contents?: true

Size: 1.29 KB

Versions: 25

Compression:

Stored size: 1.29 KB

Contents

require 'pact_broker/certificates/certificate'
require 'pact_broker/logging'
require 'openssl'

module PactBroker
  module Certificates
    module Service

      extend self
      extend PactBroker::Logging
      include PactBroker::Logging

      def cert_store
        cert_store = OpenSSL::X509::Store.new
        cert_store.set_default_paths
        find_all_certificates.each do | certificate |
          begin
            logger.debug("Loading certificate #{certificate.subject} in to cert store")
            cert_store.add_cert(certificate)
          rescue StandardError => e
            logger.warn("Error adding certificate object #{certificate.to_s} to store", e)
          end
        end
        cert_store
      end

      def find_all_certificates
        Certificate.collect do | certificate |
          cert_arr = certificate.content.split(/(-----END [^\-]+-----)/).each_slice(2).map(&:join).map(&:strip).select{|s| !s.empty?}
          cert_arr.collect do |c|
            begin
              OpenSSL::X509::Certificate.new(c)
            rescue StandardError => e
              logger.warn("Error creating certificate object from certificate #{certificate.uuid} '#{certificate.description}'", e)
              nil
            end
          end
        end.flatten.compact
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
pact_broker-2.79.1 lib/pact_broker/certificates/service.rb
pact_broker-2.79.0 lib/pact_broker/certificates/service.rb
pact_broker-2.78.1 lib/pact_broker/certificates/service.rb
pact_broker-2.78.0 lib/pact_broker/certificates/service.rb
pact_broker-2.77.0 lib/pact_broker/certificates/service.rb
pact_broker-2.76.2 lib/pact_broker/certificates/service.rb
pact_broker-2.76.1 lib/pact_broker/certificates/service.rb
pact_broker-2.76.0 lib/pact_broker/certificates/service.rb
pact_broker-2.75.0 lib/pact_broker/certificates/service.rb
pact_broker-2.74.1 lib/pact_broker/certificates/service.rb
pact_broker-2.74.0 lib/pact_broker/certificates/service.rb
pact_broker-2.73.0 lib/pact_broker/certificates/service.rb
pact_broker-2.72.0 lib/pact_broker/certificates/service.rb
pact_broker-2.71.0 lib/pact_broker/certificates/service.rb
pact_broker-2.70.0 lib/pact_broker/certificates/service.rb
pact_broker-2.69.0 lib/pact_broker/certificates/service.rb
pact_broker-2.68.1 lib/pact_broker/certificates/service.rb
pact_broker-2.68.0 lib/pact_broker/certificates/service.rb
pact_broker-2.67.0 lib/pact_broker/certificates/service.rb
pact_broker-2.66.0 lib/pact_broker/certificates/service.rb