metasploit-framework/lib/rex/proto/kerberos/model/authorization_data.rb

85 lines
2.5 KiB
Ruby
Raw Normal View History

2014-12-17 05:21:13 +00:00
# -*- coding: binary -*-
module Rex
module Proto
module Kerberos
module Model
# This class provides a representation of a Kerberos AuthorizationData data
# definition.
2014-12-17 05:21:13 +00:00
class AuthorizationData < Element
# @!attribute elements
# @return [Hash{Symbol => <Fixnum, String>}] The type of the authorization data
# @option [Fixnum] :type
# @option [String] :data
attr_accessor :elements
# Rex::Proto::Kerberos::Model::AuthorizationData decoding isn't supported
#
2014-12-24 01:59:37 +00:00
# @raise [NotImplementedError]
2014-12-17 05:21:13 +00:00
def decode(input)
2014-12-24 01:59:37 +00:00
raise ::NotImplementedError, 'Authorization Data decoding not supported'
2014-12-17 05:21:13 +00:00
end
# Encodes a Rex::Proto::Kerberos::Model::AuthorizationData into an ASN.1 String
#
# @return [String]
def encode
seqs = []
elements.each do |elem|
elems = []
type_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_type(elem[:type])], 0, :CONTEXT_SPECIFIC)
elems << type_asn1
data_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_data(elem[:data])], 1, :CONTEXT_SPECIFIC)
elems << data_asn1
seqs << OpenSSL::ASN1::Sequence.new(elems)
end
seq = OpenSSL::ASN1::Sequence.new(seqs)
seq.to_der
end
2014-12-18 00:55:30 +00:00
# Encrypts the Rex::Proto::Kerberos::Model::AuthorizationData
#
# @param etype [Fixnum] the crypto schema to encrypt
# @param key [String] the key to encrypt
# @return [String] the encrypted result
2014-12-24 01:59:37 +00:00
# @raise [NotImplementedError] if encryption schema isn't supported
2014-12-18 00:55:30 +00:00
def encrypt(etype, key)
data = self.encode
res = ''
case etype
2014-12-22 17:57:35 +00:00
when RC4_HMAC
2014-12-18 00:55:30 +00:00
res = encrypt_rc4_hmac(data, key, 5)
else
2014-12-24 01:59:37 +00:00
raise ::NotImplementedError, 'EncryptedData schema is not supported'
2014-12-18 00:55:30 +00:00
end
res
end
2014-12-17 05:21:13 +00:00
private
# Encodes the type
#
# @return [OpenSSL::ASN1::Integer]
def encode_type(type)
bn = OpenSSL::BN.new(type.to_s)
2014-12-23 00:37:07 +00:00
int = OpenSSL::ASN1::Integer.new(bn)
2014-12-17 05:21:13 +00:00
int
end
# Encodes the data
#
# @return [OpenSSL::ASN1::OctetString]
def encode_data(data)
OpenSSL::ASN1::OctetString.new(data)
end
end
end
end
end
end