2014-12-18 23:40:06 +00:00
|
|
|
# -*- coding: binary -*-
|
|
|
|
|
2014-12-18 06:30:47 +00:00
|
|
|
module Rex
|
|
|
|
module Proto
|
|
|
|
module Kerberos
|
|
|
|
module CredentialCache
|
2014-12-18 23:12:58 +00:00
|
|
|
# This class provides a representation of a Kerberos Credential Cache.
|
2014-12-18 06:30:47 +00:00
|
|
|
class Cache < Element
|
2014-12-18 23:12:58 +00:00
|
|
|
|
|
|
|
# @!attribute version
|
2017-01-17 20:09:27 +00:00
|
|
|
# @return [Integer] The file format version
|
2014-12-18 22:31:46 +00:00
|
|
|
attr_accessor :version
|
2014-12-18 23:12:58 +00:00
|
|
|
# @!attribute headers
|
|
|
|
# @return [Array<String>] The header tags
|
2014-12-18 22:31:46 +00:00
|
|
|
attr_accessor :headers
|
2014-12-18 23:12:58 +00:00
|
|
|
# @!attribute primary_principal
|
|
|
|
# @return [Rex::Proto::Kerberos::CredentialCache::Principal] The principal cache's owner
|
2014-12-18 06:30:47 +00:00
|
|
|
attr_accessor :primary_principal
|
2014-12-18 23:12:58 +00:00
|
|
|
# @!attribute credentials
|
|
|
|
# @return [Array<Rex::Proto::Kerberos::CredentialCache::Credential>] The primary principal credentials
|
2014-12-18 06:30:47 +00:00
|
|
|
attr_accessor :credentials
|
|
|
|
|
2014-12-18 23:12:58 +00:00
|
|
|
# Encodes the Rex::Proto::Kerberos::CredentialCache::Cache into an String
|
|
|
|
#
|
|
|
|
# @return [String] encoded cache
|
2014-12-18 06:30:47 +00:00
|
|
|
def encode
|
|
|
|
encoded = ''
|
|
|
|
encoded << encode_version
|
|
|
|
encoded << encode_headers
|
|
|
|
encoded << encode_primary_principal
|
|
|
|
encoded << encode_credentials
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2014-12-18 23:12:58 +00:00
|
|
|
# Encodes the version field
|
|
|
|
#
|
|
|
|
# @return [String]
|
2014-12-18 06:30:47 +00:00
|
|
|
def encode_version
|
2014-12-18 22:31:46 +00:00
|
|
|
[version].pack('n')
|
2014-12-18 06:30:47 +00:00
|
|
|
end
|
|
|
|
|
2014-12-18 23:12:58 +00:00
|
|
|
# Encodes the headers field
|
|
|
|
#
|
|
|
|
# @return [String]
|
2014-12-18 06:30:47 +00:00
|
|
|
def encode_headers
|
2014-12-18 22:31:46 +00:00
|
|
|
headers_encoded = ''
|
|
|
|
headers_encoded << [headers.length].pack('n')
|
|
|
|
headers.each do |h|
|
|
|
|
headers_encoded << h
|
|
|
|
end
|
|
|
|
|
2014-12-18 06:30:47 +00:00
|
|
|
encoded = ''
|
2014-12-18 22:31:46 +00:00
|
|
|
encoded << [headers_encoded.length].pack('n')
|
|
|
|
encoded << headers_encoded
|
2014-12-18 06:30:47 +00:00
|
|
|
|
|
|
|
encoded
|
|
|
|
end
|
|
|
|
|
2014-12-18 23:12:58 +00:00
|
|
|
# Encodes the primary_principal field
|
|
|
|
#
|
|
|
|
# @return [String]
|
2014-12-18 06:30:47 +00:00
|
|
|
def encode_primary_principal
|
|
|
|
primary_principal.encode
|
|
|
|
end
|
|
|
|
|
2014-12-18 23:12:58 +00:00
|
|
|
# Encodes the credentials field
|
|
|
|
#
|
|
|
|
# @return [String]
|
2014-12-18 06:30:47 +00:00
|
|
|
def encode_credentials
|
|
|
|
encoded = ''
|
|
|
|
credentials.each do |cred|
|
|
|
|
encoded << cred.encode
|
|
|
|
end
|
|
|
|
encoded
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|