Sha256: 5279f2fcea1d60105c92ee1e94e03dc0ef02dc41fb6bce4d6dc307b1a6cfc068

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

module HasGlobalSession
  class Directory
    attr_reader :authorities, :private_key, :local_authority_name

    def initialize(keystore_directory)
      certs = Dir[File.join(keystore_directory, '*.pub')]
      keys  = Dir[File.join(keystore_directory, '*.key')]
      raise ConfigurationError, "Excepted 0 or 1 key files, found #{keys.size}" unless [0, 1].include?(keys.size)

      @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 ConfigurationError, "Expected #{basename} to contain an RSA public key" unless @authorities[authority].public?
      end

      if (authority_name = Configuration['authority'])
        key_file = keys.detect { |kf| kf =~ /#{authority_name}.key$/ }
        raise ConfigurationError, "Key file #{authority_name}.key not found" unless key_file        
        @private_key  = OpenSSL::PKey::RSA.new(File.read(key_file))
        raise ConfigurationError, "Expected #{basename} to contain an RSA private key" unless @private_key.private?
        @local_authority_name = authority_name
      end
    end

    def trusted_authority?(authority)
      Configuration['trust'].include?(authority)
    end

    def valid_session?(uuid, expired_at)
      expired_at > Time.now
    end

    def report_invalid_session(uuid, expired_at)
      true
    end
    
    def report_exception(exception, cookie=nil)
      true
    end
  end  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
has_global_session-0.8.6 lib/has_global_session/directory.rb
has_global_session-0.8.5 lib/has_global_session/directory.rb