Sha256: c4bf8aacf086d30b852ccf6d0ffe10f6ee3c694299c33f47989e6e4d850be8a1

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module HasGlobalSession
  class Directory
    attr_reader :authorities, :my_private_key, :my_authority_name

    def initialize(keystore_directory)
      certs = Dir[File.join(keystore_directory, '*.pub')]
      keys  = Dir[File.join(keystore_directory, '*.key')]

      @authorities = {}
      certs.each do |cert_file|
        basename = File.basename(cert_file)
        authority = basename[0...(basename.rindex('.'))] #chop trailing .ext
        @authorities[authority] = OpenSSL::PKey::RSA.new(File.read(cert_file))
        raise TypeError, "Expected #{basename} to contain an RSA public key" unless @authorities[authority].public?
      end

      raise ArgumentError, "Excepted 0 or 1 key files, found #{keys.size}" if ![0, 1].include?(keys.size)
      if (key_file = keys[0])
        basename = File.basename(key_file)
        @my_private_key  = OpenSSL::PKey::RSA.new(File.read(key_file))
        raise TypeError, "Expected #{basename} to contain an RSA private key" unless @my_private_key.private?
        @my_authority_name = basename[0...(basename.rindex('.'))] #chop trailing .ext
      end
    end

    def trusted_authority?(authority)
      Configuration['trust'].blank? ||
      authority == my_authority_name ||
      Configuration['trust'].include?(authority)      
    end

    def invalidated_session?(uuid)
      false
    end
  end  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
has_global_session-0.8.2 lib/has_global_session/directory.rb