Delete namespaces from model classes

bug/bundler_fix
jvazquez-r7 2014-12-14 19:18:30 -06:00
parent 13ae624738
commit 78c76092dd
10 changed files with 1159 additions and 1177 deletions

View File

@ -70,4 +70,4 @@ require 'rex/proto/kerberos/model/pre_auth_data'
require 'rex/proto/kerberos/model/kdc_request_body'
require 'rex/proto/kerberos/model/kdc_request'
require 'rex/proto/kerberos/model/krb_error'
require 'rex/proto/kerberos/model/kdc_response'
#require 'rex/proto/kerberos/model/kdc_response'

View File

@ -4,169 +4,167 @@ module Rex
module Proto
module Kerberos
module Model
module Type
# This class provides a representation of an encrypted message.
class EncryptedData < Element
# This class provides a representation of an encrypted message.
class EncryptedData < Element
include Rex::Proto::Kerberos::Crypto::Rc4Hmac
include Rex::Proto::Kerberos::Crypto::Rc4Hmac
# @!attribute name_type
# @return [Fixnum] The encryption algorithm
attr_accessor :etype
# @!attribute kvno
# @return [Fixnum] The version number of the key
# attr_accessor :kvno
# @!attribute cipher
# @return [String] The enciphered text
attr_accessor :cipher
# @!attribute name_type
# @return [Fixnum] The encryption algorithm
attr_accessor :etype
# @!attribute kvno
# @return [Fixnum] The version number of the key
# attr_accessor :kvno
# @!attribute cipher
# @return [String] The enciphered text
attr_accessor :cipher
# Decodes a Rex::Proto::Kerberos::Model::Type::EncryptedData
#
# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from
# @return [self]
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::Sequence
decode_asn1(input)
else
raise ::RuntimeError, 'Failed to decode EncryptedData Name, invalid input'
end
self
end
# Encodes a Rex::Proto::Kerberos::Model::Type::EncryptedData into an ASN.1 String
#
# @return [String]
def encode
elems = []
etype_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_etype], 0, :CONTEXT_SPECIFIC)
elems << etype_asn1
#TODO: support kvno
#if kvno
#kvno_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_kvno], 1, :CONTEXT_SPECIFIC)
#elems << kvno_asn1
#end
cipher_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_cipher], 2, :CONTEXT_SPECIFIC)
elems << cipher_asn1
seq = OpenSSL::ASN1::Sequence.new(elems)
seq.to_der
end
# Decrypts the cipher with etype encryption schema
#
# @param key [String] the key to decrypt
# @param msg_type [Fixnum] the message type
# @return [String] the decrypted `cipher`
# @raise [RuntimeError] if decryption doesn't succeed
def decrypt(key, msg_type)
if cipher.nil? || cipher.empty?
return ''
end
res = ''
case etype
when KERB_ETYPE_RC4_HMAC
res = decrypt_rc4_hmac(cipher, key, msg_type)
raise ::RuntimeError, 'EncryptedData failed to decrypt' if res.length < 8
res = res[8, res.length - 1]
else
raise ::RuntimeError, 'EncryptedData schema is not supported'
end
res
end
private
# Encodes the etype
#
# @return [OpenSSL::ASN1::Integer]
def encode_etype
bn = OpenSSL::BN.new(etype)
int = OpenSSL::ASN1::Integer(bn)
int
end
# Encodes the kvno (unsupported)
#
# @raise [RuntimeError]
def encode_kvno
raise RuntimeError, 'Encoding EncryptedData failed, kvno not supported'
end
# Encodes the cipher
#
# @return [OpenSSL::ASN1::OctetString]
def encode_cipher
OpenSSL::ASN1::OctetString.new(cipher)
end
# Decodes a Rex::Proto::Kerberos::Model::Type::EncryptedData from an String
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
decode_asn1(asn1)
end
# Decodes a Rex::Proto::Kerberos::Model::Type::EncryptedData from an
# OpenSSL::ASN1::Sequence
#
# @param input [OpenSSL::ASN1::Sequence] the input to decode from
# @raise [RuntimeError] if decoding doesn't succeed
def decode_asn1(input)
seq_values = input.value
seq_values.each do |val|
case val.tag
when 0
self.etype = decode_etype(val)
#TODO: support kvno
#when 1
#self.kvno = decode_kvno(val)
when 2
self.cipher = decode_cipher(val)
else
raise ::RuntimeError, 'Failed to decode EncryptedData SEQUENCE'
end
end
end
# Decodes the etype from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_etype(input)
input.value[0].value.to_i
end
# Decodes the kvno from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_kvno(input)
input.value[0].value.to_i
end
# Decodes the cipher from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Sting]
def decode_cipher(input)
input.value[0].value
# Decodes a Rex::Proto::Kerberos::Model::Type::EncryptedData
#
# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from
# @return [self]
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::Sequence
decode_asn1(input)
else
raise ::RuntimeError, 'Failed to decode EncryptedData Name, invalid input'
end
self
end
# Encodes a Rex::Proto::Kerberos::Model::Type::EncryptedData into an ASN.1 String
#
# @return [String]
def encode
elems = []
etype_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_etype], 0, :CONTEXT_SPECIFIC)
elems << etype_asn1
#TODO: support kvno
#if kvno
#kvno_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_kvno], 1, :CONTEXT_SPECIFIC)
#elems << kvno_asn1
#end
cipher_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_cipher], 2, :CONTEXT_SPECIFIC)
elems << cipher_asn1
seq = OpenSSL::ASN1::Sequence.new(elems)
seq.to_der
end
# Decrypts the cipher with etype encryption schema
#
# @param key [String] the key to decrypt
# @param msg_type [Fixnum] the message type
# @return [String] the decrypted `cipher`
# @raise [RuntimeError] if decryption doesn't succeed
def decrypt(key, msg_type)
if cipher.nil? || cipher.empty?
return ''
end
res = ''
case etype
when KERB_ETYPE_RC4_HMAC
res = decrypt_rc4_hmac(cipher, key, msg_type)
raise ::RuntimeError, 'EncryptedData failed to decrypt' if res.length < 8
res = res[8, res.length - 1]
else
raise ::RuntimeError, 'EncryptedData schema is not supported'
end
res
end
private
# Encodes the etype
#
# @return [OpenSSL::ASN1::Integer]
def encode_etype
bn = OpenSSL::BN.new(etype)
int = OpenSSL::ASN1::Integer(bn)
int
end
# Encodes the kvno (unsupported)
#
# @raise [RuntimeError]
def encode_kvno
raise RuntimeError, 'Encoding EncryptedData failed, kvno not supported'
end
# Encodes the cipher
#
# @return [OpenSSL::ASN1::OctetString]
def encode_cipher
OpenSSL::ASN1::OctetString.new(cipher)
end
# Decodes a Rex::Proto::Kerberos::Model::Type::EncryptedData from an String
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
decode_asn1(asn1)
end
# Decodes a Rex::Proto::Kerberos::Model::Type::EncryptedData from an
# OpenSSL::ASN1::Sequence
#
# @param input [OpenSSL::ASN1::Sequence] the input to decode from
# @raise [RuntimeError] if decoding doesn't succeed
def decode_asn1(input)
seq_values = input.value
seq_values.each do |val|
case val.tag
when 0
self.etype = decode_etype(val)
#TODO: support kvno
#when 1
#self.kvno = decode_kvno(val)
when 2
self.cipher = decode_cipher(val)
else
raise ::RuntimeError, 'Failed to decode EncryptedData SEQUENCE'
end
end
end
# Decodes the etype from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_etype(input)
input.value[0].value.to_i
end
# Decodes the kvno from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_kvno(input)
input.value[0].value.to_i
end
# Decodes the cipher from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Sting]
def decode_cipher(input)
input.value[0].value
end
end
end
end

View File

@ -4,160 +4,158 @@ module Rex
module Proto
module Kerberos
module Model
module Message
class KdcRequest < Element
# @!attribute pvno
# @return [Fixnum] The protocol version number
attr_accessor :pvno
# @!attribute msg_type
# @return [Fixnum] The type of a protocol message
attr_accessor :msg_type
# @!attribute pa_data
# @return [Array<Rex::Proto::Kerberos::Model::Field::PreAuthData>] Authentication information which may
# be needed before credentials can be issued or decrypted
attr_accessor :pa_data
# @!attribute req_body
# @return [Rex::Proto::Kerberos::Model::Field::KdcRequestBody] The request body
attr_accessor :req_body
class KdcRequest < Element
# @!attribute pvno
# @return [Fixnum] The protocol version number
attr_accessor :pvno
# @!attribute msg_type
# @return [Fixnum] The type of a protocol message
attr_accessor :msg_type
# @!attribute pa_data
# @return [Array<Rex::Proto::Kerberos::Model::Field::PreAuthData>] Authentication information which may
# be needed before credentials can be issued or decrypted
attr_accessor :pa_data
# @!attribute req_body
# @return [Rex::Proto::Kerberos::Model::Field::KdcRequestBody] The request body
attr_accessor :req_body
# Decodes the Rex::Proto::Kerberos::Model::Message::KdcRequest from an input
#
# @param input [String, OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::ASN1Data
decode_asn1(input)
# Decodes the Rex::Proto::Kerberos::Model::Message::KdcRequest from an input
#
# @param input [String, OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::ASN1Data
decode_asn1(input)
else
raise ::RuntimeError, 'Failed to decode KDC Request, invalid input'
end
self
end
# Encodes the Rex::Proto::Kerberos::Model::Message::KdcRequest into an ASN.1 String
#
# @return [String]
def encode
pvno_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_pvno], 1, :CONTEXT_SPECIFIC)
msg_type_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_msg_type], 2, :CONTEXT_SPECIFIC)
pa_data_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_pa_data], 3, :CONTEXT_SPECIFIC)
req_body_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_req_body], 4, :CONTEXT_SPECIFIC)
seq = OpenSSL::ASN1::Sequence.new([pvno_asn1, msg_type_asn1, pa_data_asn1, req_body_asn1])
seq_asn1 = OpenSSL::ASN1::ASN1Data.new([seq], msg_type, :APPLICATION)
seq_asn1.to_der
end
private
# Encodes the etype field
#
# @return [OpenSSL::ASN1::Integer]
def encode_pvno
bn = OpenSSL::BN.new(pvno)
int = OpenSSL::ASN1::Integer(bn)
int
end
# Encodes the msg_type field
#
# @return [OpenSSL::ASN1::Integer]
def encode_msg_type
bn = OpenSSL::BN.new(msg_type)
int = OpenSSL::ASN1::Integer(bn)
int
end
# Encodes the pa_data field
#
# @return [String]
def encode_pa_data
elems = []
pa_data.each do |data|
elems << data.encode
end
OpenSSL::ASN1::Sequence.new(elems)
end
# Encodes the req_body field
#
# @return [String]
def encode_req_body
req_body.encode
end
# Decodes a Rex::Proto::Kerberos::Model::Message::KdcRequest from an String
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
decode_asn1(asn1)
end
# Decodes a Rex::Proto::Kerberos::Model::Message::KdcRequest
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @raise [RuntimeError] if decoding doesn't succeed
def decode_asn1(input)
input.value[0].value.each do |val|
case val.tag
when 1
self.pvno = decode_asn1_pvno(val)
when 2
self.msg_type = decode_asn1_msg_type(val)
when 3
self.pa_data = decode_asn1_pa_data(val)
when 4
self.req_body = decode_asn1_req_body(val)
else
raise ::RuntimeError, 'Failed to decode KDC Request, invalid input'
end
self
end
# Encodes the Rex::Proto::Kerberos::Model::Message::KdcRequest into an ASN.1 String
#
# @return [String]
def encode
pvno_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_pvno], 1, :CONTEXT_SPECIFIC)
msg_type_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_msg_type], 2, :CONTEXT_SPECIFIC)
pa_data_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_pa_data], 3, :CONTEXT_SPECIFIC)
req_body_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_req_body], 4, :CONTEXT_SPECIFIC)
seq = OpenSSL::ASN1::Sequence.new([pvno_asn1, msg_type_asn1, pa_data_asn1, req_body_asn1])
seq_asn1 = OpenSSL::ASN1::ASN1Data.new([seq], msg_type, :APPLICATION)
seq_asn1.to_der
end
private
# Encodes the etype field
#
# @return [OpenSSL::ASN1::Integer]
def encode_pvno
bn = OpenSSL::BN.new(pvno)
int = OpenSSL::ASN1::Integer(bn)
int
end
# Encodes the msg_type field
#
# @return [OpenSSL::ASN1::Integer]
def encode_msg_type
bn = OpenSSL::BN.new(msg_type)
int = OpenSSL::ASN1::Integer(bn)
int
end
# Encodes the pa_data field
#
# @return [String]
def encode_pa_data
elems = []
pa_data.each do |data|
elems << data.encode
end
OpenSSL::ASN1::Sequence.new(elems)
end
# Encodes the req_body field
#
# @return [String]
def encode_req_body
req_body.encode
end
# Decodes a Rex::Proto::Kerberos::Model::Message::KdcRequest from an String
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
decode_asn1(asn1)
end
# Decodes a Rex::Proto::Kerberos::Model::Message::KdcRequest
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @raise [RuntimeError] if decoding doesn't succeed
def decode_asn1(input)
input.value[0].value.each do |val|
case val.tag
when 1
self.pvno = decode_asn1_pvno(val)
when 2
self.msg_type = decode_asn1_msg_type(val)
when 3
self.pa_data = decode_asn1_pa_data(val)
when 4
self.req_body = decode_asn1_req_body(val)
else
raise ::RuntimeError, 'Filed to decode KdcRequest SEQUENCE'
end
raise ::RuntimeError, 'Filed to decode KdcRequest SEQUENCE'
end
end
end
# Decodes the pvno from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_asn1_pvno(input)
input.value[0].value.to_i
# Decodes the pvno from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_asn1_pvno(input)
input.value[0].value.to_i
end
# Decodes the msg_type from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_asn1_msg_type(input)
input.value[0].value.to_i
end
# Decodes the pa_data from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Array<Rex::Proto::Kerberos::Model::Field::PreAuthData>]
def decode_asn1_pa_data(input)
pre_auth = []
input.value[0].value.each do |pre_auth_data|
pre_auth << Rex::Proto::Kerberos::Model::Field::PreAuthData.decode(pre_auth_data)
end
# Decodes the msg_type from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_asn1_msg_type(input)
input.value[0].value.to_i
end
pre_auth
end
# Decodes the pa_data from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Array<Rex::Proto::Kerberos::Model::Field::PreAuthData>]
def decode_asn1_pa_data(input)
pre_auth = []
input.value[0].value.each do |pre_auth_data|
pre_auth << Rex::Proto::Kerberos::Model::Field::PreAuthData.decode(pre_auth_data)
end
pre_auth
end
# Decodes the req_body from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Model::Field::KdcRequestBody]
def decode_asn1_req_body(input)
Rex::Proto::Kerberos::Model::Field::KdcRequestBody.decode(input.value[0])
end
# Decodes the req_body from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Model::Field::KdcRequestBody]
def decode_asn1_req_body(input)
Rex::Proto::Kerberos::Model::Field::KdcRequestBody.decode(input.value[0])
end
end
end

View File

@ -4,290 +4,288 @@ module Rex
module Proto
module Kerberos
module Model
module Field
class KdcRequestBody < Element
# @!attribute options
# @return [Fixnum] The ticket flags
attr_accessor :options
# @!attribute cname
# @return [Rex::Proto::Kerberos::Type::PrincipalName] The name part of the client's principal identifier
attr_accessor :cname
# @!attribute realm
# @return [String] The realm part of the server's principal identifier
attr_accessor :realm
# @!attribute sname
# @return [Rex::Proto::Kerberos::Type::PrincipalName] The name part of the server's identity
attr_accessor :sname
# @!attribute from
# @return [Time] Start time when the ticket is to be postdated
attr_accessor :from
# @!attribute till
# @return [Time] Expiration date requested by the client
attr_accessor :till
# @!attribute rtime
# @return [Time] Optional requested renew-till time
attr_accessor :rtime
# @!attribute nonce
# @return [Fixnum] random number
attr_accessor :nonce
# @!attribute etype
# @return [Array<Fixnum>] The desired encryption algorithm to be used in the response
attr_accessor :etype
# @!attribute enc_auth_data
# @return [Rex::Proto::Kerberos::Type::EncryptedData] An encoding of the desired authorization-data encrypted
attr_accessor :enc_auth_data
class KdcRequestBody < Element
# @!attribute options
# @return [Fixnum] The ticket flags
attr_accessor :options
# @!attribute cname
# @return [Rex::Proto::Kerberos::Type::PrincipalName] The name part of the client's principal identifier
attr_accessor :cname
# @!attribute realm
# @return [String] The realm part of the server's principal identifier
attr_accessor :realm
# @!attribute sname
# @return [Rex::Proto::Kerberos::Type::PrincipalName] The name part of the server's identity
attr_accessor :sname
# @!attribute from
# @return [Time] Start time when the ticket is to be postdated
attr_accessor :from
# @!attribute till
# @return [Time] Expiration date requested by the client
attr_accessor :till
# @!attribute rtime
# @return [Time] Optional requested renew-till time
attr_accessor :rtime
# @!attribute nonce
# @return [Fixnum] random number
attr_accessor :nonce
# @!attribute etype
# @return [Array<Fixnum>] The desired encryption algorithm to be used in the response
attr_accessor :etype
# @!attribute enc_auth_data
# @return [Rex::Proto::Kerberos::Type::EncryptedData] An encoding of the desired authorization-data encrypted
attr_accessor :enc_auth_data
# Decodes the Rex::Proto::Kerberos::Model::Field::KdcRequestBody attributes from input
#
# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::Sequence
decode_asn1(input)
else
raise ::RuntimeError, 'Failed to decode KdcRequestBody, invalid input'
end
self
# Decodes the Rex::Proto::Kerberos::Model::Field::KdcRequestBody attributes from input
#
# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::Sequence
decode_asn1(input)
else
raise ::RuntimeError, 'Failed to decode KdcRequestBody, invalid input'
end
# Encodes the Rex::Proto::Kerberos::Model::Field::KdcRequestBody into an ASN.1 String
#
# @return [String]
def encode
elems = []
self
end
elems << OpenSSL::ASN1::ASN1Data.new([encode_options], 0, :CONTEXT_SPECIFIC) if options
elems << OpenSSL::ASN1::ASN1Data.new([encode_cname], 1, :CONTEXT_SPECIFIC) if cname
elems << OpenSSL::ASN1::ASN1Data.new([encode_realm], 2, :CONTEXT_SPECIFIC) if realm
elems << OpenSSL::ASN1::ASN1Data.new([encode_sname], 3, :CONTEXT_SPECIFIC) if sname
elems << OpenSSL::ASN1::ASN1Data.new([encode_from], 4, :CONTEXT_SPECIFIC) if from
elems << OpenSSL::ASN1::ASN1Data.new([encode_till], 5, :CONTEXT_SPECIFIC) if till
elems << OpenSSL::ASN1::ASN1Data.new([encode_rtime], 6, :CONTEXT_SPECIFIC) if rtime
elems << OpenSSL::ASN1::ASN1Data.new([encode_nonce], 7, :CONTEXT_SPECIFIC) if nonce
elems << OpenSSL::ASN1::ASN1Data.new([encode_etype], 8, :CONTEXT_SPECIFIC) if etype
elems << OpenSSL::ASN1::ASN1Data.new([encode_enc_auth_data], 10, :CONTEXT_SPECIFIC) if enc_auth_data
# Encodes the Rex::Proto::Kerberos::Model::Field::KdcRequestBody into an ASN.1 String
#
# @return [String]
def encode
elems = []
seq = OpenSSL::ASN1::Sequence.new(elems)
elems << OpenSSL::ASN1::ASN1Data.new([encode_options], 0, :CONTEXT_SPECIFIC) if options
elems << OpenSSL::ASN1::ASN1Data.new([encode_cname], 1, :CONTEXT_SPECIFIC) if cname
elems << OpenSSL::ASN1::ASN1Data.new([encode_realm], 2, :CONTEXT_SPECIFIC) if realm
elems << OpenSSL::ASN1::ASN1Data.new([encode_sname], 3, :CONTEXT_SPECIFIC) if sname
elems << OpenSSL::ASN1::ASN1Data.new([encode_from], 4, :CONTEXT_SPECIFIC) if from
elems << OpenSSL::ASN1::ASN1Data.new([encode_till], 5, :CONTEXT_SPECIFIC) if till
elems << OpenSSL::ASN1::ASN1Data.new([encode_rtime], 6, :CONTEXT_SPECIFIC) if rtime
elems << OpenSSL::ASN1::ASN1Data.new([encode_nonce], 7, :CONTEXT_SPECIFIC) if nonce
elems << OpenSSL::ASN1::ASN1Data.new([encode_etype], 8, :CONTEXT_SPECIFIC) if etype
elems << OpenSSL::ASN1::ASN1Data.new([encode_enc_auth_data], 10, :CONTEXT_SPECIFIC) if enc_auth_data
seq.to_der
end
seq = OpenSSL::ASN1::Sequence.new(elems)
private
seq.to_der
end
# Encodes the options
#
# @return [OpenSSL::ASN1::BitString]
def encode_options
OpenSSL::ASN1::BitString.new([options].pack('N'))
end
private
# Encodes the cname
#
# @return [String]
def encode_cname
cname.encode
end
# Encodes the options
#
# @return [OpenSSL::ASN1::BitString]
def encode_options
OpenSSL::ASN1::BitString.new([options].pack('N'))
end
# Encodes the realm
#
# @return [OpenSSL::ASN1::GeneralString]
def encode_realm
OpenSSL::ASN1::GeneralString.new(realm)
end
# Encodes the cname
#
# @return [String]
def encode_cname
cname.encode
end
# Encodes the sname
#
# @return [String]
def encode_sname
sname.encode
end
# Encodes the realm
#
# @return [OpenSSL::ASN1::GeneralString]
def encode_realm
OpenSSL::ASN1::GeneralString.new(realm)
end
# Encodes the from
#
# @return [OpenSSL::ASN1::GeneralizedTime]
def encode_from
OpenSSL::ASN1::GeneralizedTime.new(from)
end
# Encodes the sname
#
# @return [String]
def encode_sname
sname.encode
end
# Encodes the till
#
# @return [OpenSSL::ASN1::GeneralizedTime]
def encode_till
OpenSSL::ASN1::GeneralizedTime.new(till)
end
# Encodes the from
#
# @return [OpenSSL::ASN1::GeneralizedTime]
def encode_from
OpenSSL::ASN1::GeneralizedTime.new(from)
end
# Encodes the rtime
#
# @return [OpenSSL::ASN1::GeneralizedTime]
def encode_rtime
OpenSSL::ASN1::GeneralizedTime.new(rtime)
end
# Encodes the till
#
# @return [OpenSSL::ASN1::GeneralizedTime]
def encode_till
OpenSSL::ASN1::GeneralizedTime.new(till)
end
# Encodes the nonce
#
# @return [OpenSSL::ASN1::Integer]
def encode_nonce
bn = OpenSSL::BN.new(nonce)
# Encodes the rtime
#
# @return [OpenSSL::ASN1::GeneralizedTime]
def encode_rtime
OpenSSL::ASN1::GeneralizedTime.new(rtime)
end
# Encodes the nonce
#
# @return [OpenSSL::ASN1::Integer]
def encode_nonce
bn = OpenSSL::BN.new(nonce)
int = OpenSSL::ASN1::Integer(bn)
int
end
# Encodes the etype
#
# @return [OpenSSL::ASN1::Sequence]
def encode_etype
encoded_types = []
etype.each do |member|
bn = OpenSSL::BN.new(member)
int = OpenSSL::ASN1::Integer(bn)
int
encoded_types << int
end
# Encodes the etype
#
# @return [OpenSSL::ASN1::Sequence]
def encode_etype
encoded_types = []
etype.each do |member|
bn = OpenSSL::BN.new(member)
int = OpenSSL::ASN1::Integer(bn)
encoded_types << int
end
OpenSSL::ASN1::Sequence.new(encoded_types)
end
OpenSSL::ASN1::Sequence.new(encoded_types)
end
# Encodes the enc_auth_data
#
# @return [String]
def encode_enc_auth_data
enc_auth_data.encode
end
# Encodes the enc_auth_data
#
# @return [String]
def encode_enc_auth_data
enc_auth_data.encode
end
# Decodes a Rex::Proto::Kerberos::Model::Field::KdcRequestBody from an String
#
# @param input [String] the input to decode from
# @raise [RuntimeError] if decoding doesn't succeed
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
# Decodes a Rex::Proto::Kerberos::Model::Field::KdcRequestBody from an String
#
# @param input [String] the input to decode from
# @raise [RuntimeError] if decoding doesn't succeed
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
decode_asn1(asn1)
end
decode_asn1(asn1)
end
# Decodes a Rex::Proto::Kerberos::Model::Field::KdcRequestBody from an
# OpenSSL::ASN1::Sequence
#
# @param input [OpenSSL::ASN1::Sequence] the input to decode from
# @raise [RuntimeError] if decoding doesn't succeed
def decode_asn1(input)
seq_values = input.value
# Decodes a Rex::Proto::Kerberos::Model::Field::KdcRequestBody from an
# OpenSSL::ASN1::Sequence
#
# @param input [OpenSSL::ASN1::Sequence] the input to decode from
# @raise [RuntimeError] if decoding doesn't succeed
def decode_asn1(input)
seq_values = input.value
seq_values.each do |val|
case val.tag
when 0
self.options = decode_options(val)
when 1
self.cname = decode_cname(val)
when 2
self.realm = decode_realm(val)
when 3
self.sname = decode_sname(val)
when 4
self.from = decode_from(val)
when 5
self.till = decode_till(val)
when 6
self.rtime = decode_rtime(val)
when 7
self.nonce = decode_nonce(val)
when 8
self.etype = decode_etype(val)
when 10
self.enc_auth_data = decode_enc_auth_data(val)
else
raise ::RuntimeError, 'Failed to decode KdcRequestBody SEQUENCE'
end
seq_values.each do |val|
case val.tag
when 0
self.options = decode_options(val)
when 1
self.cname = decode_cname(val)
when 2
self.realm = decode_realm(val)
when 3
self.sname = decode_sname(val)
when 4
self.from = decode_from(val)
when 5
self.till = decode_till(val)
when 6
self.rtime = decode_rtime(val)
when 7
self.nonce = decode_nonce(val)
when 8
self.etype = decode_etype(val)
when 10
self.enc_auth_data = decode_enc_auth_data(val)
else
raise ::RuntimeError, 'Failed to decode KdcRequestBody SEQUENCE'
end
end
end
# Decodes the options field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_options(input)
input.value[0].value.unpack('N')[0]
end
# Decodes the options field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_options(input)
input.value[0].value.unpack('N')[0]
end
# Decodes the cname field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Type::PrincipalName]
def decode_cname(input)
Rex::Proto::Kerberos::Model::Type::PrincipalName.decode(input.value[0])
end
# Decodes the cname field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Type::PrincipalName]
def decode_cname(input)
Rex::Proto::Kerberos::Model::Type::PrincipalName.decode(input.value[0])
end
# Decodes the realm field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [String]
def decode_realm(input)
input.value[0].value
end
# Decodes the realm field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [String]
def decode_realm(input)
input.value[0].value
end
# Decodes the sname field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Type::PrincipalName]
def decode_sname(input)
Rex::Proto::Kerberos::Model::Type::PrincipalName.decode(input.value[0])
end
# Decodes the sname field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Type::PrincipalName]
def decode_sname(input)
Rex::Proto::Kerberos::Model::Type::PrincipalName.decode(input.value[0])
end
# Decodes the from field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Time]
def decode_from(input)
input.value[0].value
end
# Decodes the from field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Time]
def decode_from(input)
input.value[0].value
end
# Decodes the till field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Time]
def decode_till(input)
input.value[0].value
end
# Decodes the till field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Time]
def decode_till(input)
input.value[0].value
end
# Decodes the rtime field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Time]
def decode_rtime(input)
input.value[0].value
end
# Decodes the rtime field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Time]
def decode_rtime(input)
input.value[0].value
end
# Decodes the nonce field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_nonce(input)
input.value[0].value.to_i
end
# Decodes the nonce field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_nonce(input)
input.value[0].value.to_i
end
# Decodes the etype field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Array<Fixnum>]
def decode_etype(input)
encs = []
input.value[0].value.each do |enc|
encs << enc.value.to_i
end
encs
# Decodes the etype field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Array<Fixnum>]
def decode_etype(input)
encs = []
input.value[0].value.each do |enc|
encs << enc.value.to_i
end
encs
end
# Decodes the enc_auth_data field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Model::Type::EncryptedData]
def decode_enc_auth_data(input)
Rex::Proto::Kerberos::Model::Type::EncryptedData.decode(input.value[0])
end
# Decodes the enc_auth_data field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Model::Type::EncryptedData]
def decode_enc_auth_data(input)
Rex::Proto::Kerberos::Model::Type::EncryptedData.decode(input.value[0])
end
end
end

View File

@ -4,116 +4,114 @@ module Rex
module Proto
module Kerberos
module Model
module Message
class KdcResponse < Element
# @!attribute pvno
# @return [Fixnum] The protocol version number
attr_accessor :pvno
# @!attribute msg_type
# @return [Fixnum] The type of a protocol message
attr_accessor :msg_type
# @!attribute crealm
# @return [String] The realm part of the client's principal identifier
attr_accessor :crealm
# @!attribute cname
# @return [Rex::Proto::Kerberos::Type::PrincipalName] The name part of the client's principal identifier
attr_accessor :cname
# @!attribute ticket
# @return [Rex::Proto::Kerberos::Type::PrincipalName] The name part of the client's principal identifier
attr_accessor :ticket
# @!attribute enc_auth_data
# @return [Rex::Proto::Kerberos::Type::EncryptedData] The newly issued ticket
attr_accessor :enc_part
class KdcResponse < Element
# @!attribute pvno
# @return [Fixnum] The protocol version number
attr_accessor :pvno
# @!attribute msg_type
# @return [Fixnum] The type of a protocol message
attr_accessor :msg_type
# @!attribute crealm
# @return [String] The realm part of the client's principal identifier
attr_accessor :crealm
# @!attribute cname
# @return [Rex::Proto::Kerberos::Type::PrincipalName] The name part of the client's principal identifier
attr_accessor :cname
# @!attribute ticket
# @return [Rex::Proto::Kerberos::Type::PrincipalName] The name part of the client's principal identifier
attr_accessor :ticket
# @!attribute enc_auth_data
# @return [Rex::Proto::Kerberos::Type::EncryptedData] The newly issued ticket
attr_accessor :enc_part
# Decodes the Rex::Proto::Kerberos::Model::Message::KrbError from an input
#
# @param input [String, OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::ASN1Data
decode_asn1(input)
# Decodes the Rex::Proto::Kerberos::Model::Message::KrbError from an input
#
# @param input [String, OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::ASN1Data
decode_asn1(input)
else
raise ::RuntimeError, 'Failed to decode KRB Error, invalid input'
end
self
end
def encode
raise ::RuntimeError, 'KrbError encoding not supported'
end
private
# Decodes a Rex::Proto::Kerberos::Model::Message::KrbError from an String
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
decode_asn1(asn1)
end
# Decodes a Rex::Proto::Kerberos::Model::Message::KrbError
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @raise [RuntimeError] if decoding doesn't succeed
def decode_asn1(input)
input.value[0].value.each do |val|
case val.tag
when 0
self.pvno = decode_pvno(val)
when 1
self.msg_type = decode_msg_type(val)
when 3
self.crealm = decode_crealm(val)
when 4
self.cname = decode_cname(val)
when 5
self.ticket = decode_ticket(val)
when 6
self.enc_part = decode_enc_part(val)
else
raise ::RuntimeError, 'Failed to decode KRB Error, invalid input'
end
self
end
def encode
raise ::RuntimeError, 'KrbError encoding not supported'
end
private
# Decodes a Rex::Proto::Kerberos::Model::Message::KrbError from an String
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
decode_asn1(asn1)
end
# Decodes a Rex::Proto::Kerberos::Model::Message::KrbError
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @raise [RuntimeError] if decoding doesn't succeed
def decode_asn1(input)
input.value[0].value.each do |val|
case val.tag
when 0
self.pvno = decode_pvno(val)
when 1
self.msg_type = decode_msg_type(val)
when 3
self.crealm = decode_crealm(val)
when 4
self.cname = decode_cname(val)
when 5
self.ticket = decode_ticket(val)
when 6
self.enc_part = decode_enc_part(val)
else
raise ::RuntimeError, 'Failed to decode KDC-RESPONSE SEQUENCE'
end
raise ::RuntimeError, 'Failed to decode KDC-RESPONSE SEQUENCE'
end
end
end
# Decodes the pvno from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_pvno(input)
input.value[0].value.to_i
end
# Decodes the pvno from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_pvno(input)
input.value[0].value.to_i
end
# Decodes the msg_type from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_msg_type(input)
input.value[0].value.to_i
end
# Decodes the msg_type from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_msg_type(input)
input.value[0].value.to_i
end
# Decodes the crealm field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [String]
def decode_crealm(input)
input.value[0].value
end
# Decodes the crealm field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [String]
def decode_crealm(input)
input.value[0].value
end
# Decodes the cname field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Type::PrincipalName]
def decode_cname(input)
Rex::Proto::Kerberos::Model::Type::PrincipalName.decode(input.value[0])
end
# Decodes the cname field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Type::PrincipalName]
def decode_cname(input)
Rex::Proto::Kerberos::Model::Type::PrincipalName.decode(input.value[0])
end
end
end

View File

@ -4,210 +4,208 @@ module Rex
module Proto
module Kerberos
module Model
module Message
class KrbError < Element
# @!attribute pvno
# @return [Fixnum] The protocol version number
attr_accessor :pvno
# @!attribute msg_type
# @return [Fixnum] The type of a protocol message
attr_accessor :msg_type
# @!attribute ctime
# @return [Time] The current time of the client's host
attr_accessor :ctime
# @!attribute cusec
# @return [Fixnum] The microseconds part of the client timestamp
attr_accessor :cusec
# @!attribute stime
# @return [Time] The current time of the server
attr_accessor :stime
# @!attribute susec
# @return [Fixnum] The microseconds part of the server timestamp
attr_accessor :susec
# @!attribute error_code
# @return [Fixnum] The error request returned by kerberos or the server when a request fails
attr_accessor :error_code
# @!attribute crealm
# @return [String] The realm part of the client's principal identifier
attr_accessor :crealm
# @!attribute cname
# @return [Rex::Proto::Kerberos::Type::PrincipalName] The name part of the client's principal identifier
attr_accessor :cname
# @!attribute realm
# @return [String] The realm part of the server's principal identifier
attr_accessor :realm
# @!attribute sname
# @return [Rex::Proto::Kerberos::Type::PrincipalName] The name part of the server's identity
attr_accessor :sname
# @!attribute e_data
# @return [String] additional data about the error (ASN.1 encoded data)
attr_accessor :e_data
class KrbError < Element
# @!attribute pvno
# @return [Fixnum] The protocol version number
attr_accessor :pvno
# @!attribute msg_type
# @return [Fixnum] The type of a protocol message
attr_accessor :msg_type
# @!attribute ctime
# @return [Time] The current time of the client's host
attr_accessor :ctime
# @!attribute cusec
# @return [Fixnum] The microseconds part of the client timestamp
attr_accessor :cusec
# @!attribute stime
# @return [Time] The current time of the server
attr_accessor :stime
# @!attribute susec
# @return [Fixnum] The microseconds part of the server timestamp
attr_accessor :susec
# @!attribute error_code
# @return [Fixnum] The error request returned by kerberos or the server when a request fails
attr_accessor :error_code
# @!attribute crealm
# @return [String] The realm part of the client's principal identifier
attr_accessor :crealm
# @!attribute cname
# @return [Rex::Proto::Kerberos::Type::PrincipalName] The name part of the client's principal identifier
attr_accessor :cname
# @!attribute realm
# @return [String] The realm part of the server's principal identifier
attr_accessor :realm
# @!attribute sname
# @return [Rex::Proto::Kerberos::Type::PrincipalName] The name part of the server's identity
attr_accessor :sname
# @!attribute e_data
# @return [String] additional data about the error (ASN.1 encoded data)
attr_accessor :e_data
# Decodes the Rex::Proto::Kerberos::Model::Message::KrbError from an input
#
# @param input [String, OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::ASN1Data
decode_asn1(input)
# Decodes the Rex::Proto::Kerberos::Model::Message::KrbError from an input
#
# @param input [String, OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::ASN1Data
decode_asn1(input)
else
raise ::RuntimeError, 'Failed to decode KRB Error, invalid input'
end
self
end
def encode
raise ::RuntimeError, 'KrbError encoding not supported'
end
private
# Decodes a Rex::Proto::Kerberos::Model::Message::KrbError from an String
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
decode_asn1(asn1)
end
# Decodes a Rex::Proto::Kerberos::Model::Message::KrbError
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @raise [RuntimeError] if decoding doesn't succeed
def decode_asn1(input)
input.value[0].value.each do |val|
case val.tag
when 0
self.pvno = decode_pvno(val)
when 1
self.msg_type = decode_msg_type(val)
when 2
self.ctime = decode_ctime(val)
when 3
self.cusec = decode_cusec(val)
when 4
self.stime = decode_stime(val)
when 5
self.susec = decode_susec(val)
when 6
self.error_code = decode_error_code(val)
when 7
self.crealm = decode_crealm(val)
when 8
self.cname = decode_cname(val)
when 9
self.realm = decode_realm(val)
when 10
self.sname = decode_sname(val)
when 12
self.e_data = decode_e_data(val)
else
raise ::RuntimeError, 'Failed to decode KRB Error, invalid input'
end
self
end
def encode
raise ::RuntimeError, 'KrbError encoding not supported'
end
private
# Decodes a Rex::Proto::Kerberos::Model::Message::KrbError from an String
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
decode_asn1(asn1)
end
# Decodes a Rex::Proto::Kerberos::Model::Message::KrbError
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @raise [RuntimeError] if decoding doesn't succeed
def decode_asn1(input)
input.value[0].value.each do |val|
case val.tag
when 0
self.pvno = decode_pvno(val)
when 1
self.msg_type = decode_msg_type(val)
when 2
self.ctime = decode_ctime(val)
when 3
self.cusec = decode_cusec(val)
when 4
self.stime = decode_stime(val)
when 5
self.susec = decode_susec(val)
when 6
self.error_code = decode_error_code(val)
when 7
self.crealm = decode_crealm(val)
when 8
self.cname = decode_cname(val)
when 9
self.realm = decode_realm(val)
when 10
self.sname = decode_sname(val)
when 12
self.e_data = decode_e_data(val)
else
raise ::RuntimeError, 'Failed to decode KRB-ERROR SEQUENCE'
end
raise ::RuntimeError, 'Failed to decode KRB-ERROR SEQUENCE'
end
end
end
# Decodes the pvno from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_pvno(input)
input.value[0].value.to_i
end
# Decodes the pvno from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_pvno(input)
input.value[0].value.to_i
end
# Decodes the msg_type from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_msg_type(input)
input.value[0].value.to_i
end
# Decodes the msg_type from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_msg_type(input)
input.value[0].value.to_i
end
# Decodes the ctime field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Time]
def decode_ctime(input)
input.value[0].value
end
# Decodes the ctime field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Time]
def decode_ctime(input)
input.value[0].value
end
# Decodes the cusec field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_cusec(input)
input.value[0].value
end
# Decodes the cusec field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_cusec(input)
input.value[0].value
end
# Decodes the stime field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Time]
def decode_stime(input)
input.value[0].value
end
# Decodes the stime field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Time]
def decode_stime(input)
input.value[0].value
end
# Decodes the susec field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_susec(input)
input.value[0].value.to_i
end
# Decodes the susec field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_susec(input)
input.value[0].value.to_i
end
# Decodes the error_code field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_error_code(input)
input.value[0].value.to_i
end
# Decodes the error_code field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_error_code(input)
input.value[0].value.to_i
end
# Decodes the crealm field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [String]
def decode_crealm(input)
input.value[0].value
end
# Decodes the crealm field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [String]
def decode_crealm(input)
input.value[0].value
end
# Decodes the cname field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Type::PrincipalName]
def decode_cname(input)
Rex::Proto::Kerberos::Model::Type::PrincipalName.decode(input.value[0])
end
# Decodes the cname field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Type::PrincipalName]
def decode_cname(input)
Rex::Proto::Kerberos::Model::Type::PrincipalName.decode(input.value[0])
end
# Decodes the realm field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [String]
def decode_realm(input)
input.value[0].value
end
# Decodes the realm field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [String]
def decode_realm(input)
input.value[0].value
end
# Decodes the sname field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Type::PrincipalName]
def decode_sname(input)
Rex::Proto::Kerberos::Model::Type::PrincipalName.decode(input.value[0])
end
# Decodes the sname field
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Rex::Proto::Kerberos::Type::PrincipalName]
def decode_sname(input)
Rex::Proto::Kerberos::Model::Type::PrincipalName.decode(input.value[0])
end
# Decodes the e_data from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [String]
def decode_e_data(input)
input.value[0].value
end
# Decodes the e_data from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [String]
def decode_e_data(input)
input.value[0].value
end
end
end

View File

@ -4,98 +4,96 @@ module Rex
module Proto
module Kerberos
module Model
module Field
class PreAuthData < Element
class PreAuthData < Element
# @!attribute type
# @return [Fixnum] The padata type
attr_accessor :type
# @!attribute value
# @return [String] The padata value
attr_accessor :value
# @!attribute type
# @return [Fixnum] The padata type
attr_accessor :type
# @!attribute value
# @return [String] The padata value
attr_accessor :value
# Decodes a Rex::Proto::Kerberos::Model::Field::PreAuthData
#
# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::Sequence
decode_asn1(input)
else
raise ::RuntimeError, 'Failed to decode PreAuthData, invalid input'
end
self
# Decodes a Rex::Proto::Kerberos::Model::Field::PreAuthData
#
# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::Sequence
decode_asn1(input)
else
raise ::RuntimeError, 'Failed to decode PreAuthData, invalid input'
end
# Encodes a Rex::Proto::Kerberos::Model::Field::PreAuthData into an ASN.1 String
#
# @return [String]
def encode
type_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_type], 1, :CONTEXT_SPECIFIC)
value_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_value], 2, :CONTEXT_SPECIFIC)
seq = OpenSSL::ASN1::Sequence.new([type_asn1, value_asn1])
self
end
seq.to_der
end
# Encodes a Rex::Proto::Kerberos::Model::Field::PreAuthData into an ASN.1 String
#
# @return [String]
def encode
type_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_type], 1, :CONTEXT_SPECIFIC)
value_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_value], 2, :CONTEXT_SPECIFIC)
seq = OpenSSL::ASN1::Sequence.new([type_asn1, value_asn1])
private
seq.to_der
end
# Encodes the type
#
# @return [OpenSSL::ASN1::Integer]
def encode_type
int_bn = OpenSSL::BN.new(type)
int = OpenSSL::ASN1::Integer(int_bn)
private
int
end
# Encodes the type
#
# @return [OpenSSL::ASN1::Integer]
def encode_type
int_bn = OpenSSL::BN.new(type)
int = OpenSSL::ASN1::Integer(int_bn)
# Encodes the value
#
# @return [OpenSSL::ASN1::OctetString]
def encode_value
OpenSSL::ASN1::OctetString.new(value)
end
int
end
# Decodes a Rex::Proto::Kerberos::Model::Field::PreAuthData
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
# Encodes the value
#
# @return [OpenSSL::ASN1::OctetString]
def encode_value
OpenSSL::ASN1::OctetString.new(value)
end
decode_asn1(asn1)
end
# Decodes a Rex::Proto::Kerberos::Model::Field::PreAuthData
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
# Decodes a Rex::Proto::Kerberos::Model::Type::PreAuthData from an
# OpenSSL::ASN1::Sequence
#
# @param input [OpenSSL::ASN1::Sequence] the input to decode from
def decode_asn1(input)
seq_values = input.value
self.type = decode_asn1_type(seq_values[0])
self.value = decode_asn1_value(seq_values[1])
end
decode_asn1(asn1)
end
# Decodes the type from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_asn1_type(input)
input.value[0].value.to_i
end
# Decodes a Rex::Proto::Kerberos::Model::Type::PreAuthData from an
# OpenSSL::ASN1::Sequence
#
# @param input [OpenSSL::ASN1::Sequence] the input to decode from
def decode_asn1(input)
seq_values = input.value
self.type = decode_asn1_type(seq_values[0])
self.value = decode_asn1_value(seq_values[1])
end
# Decodes the value from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_asn1_value(input)
input.value[0].value
end
# Decodes the type from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_asn1_type(input)
input.value[0].value.to_i
end
# Decodes the value from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_asn1_value(input)
input.value[0].value
end
end
end

View File

@ -4,122 +4,120 @@ module Rex
module Proto
module Kerberos
module Model
module Field
# This class is a representation of a PA-ENC-TIMESTAMP, an encrypted timestamp
class PreAuthEncTimeStamp < Element
# This class is a representation of a PA-ENC-TIMESTAMP, an encrypted timestamp
class PreAuthEncTimeStamp < Element
include Rex::Proto::Kerberos::Crypto::Rc4Hmac
include Rex::Proto::Kerberos::Crypto::Rc4Hmac
CRYPTO_MSG_TYPE = 1
CRYPTO_MSG_TYPE = 1
# @!attribute pa_time_stamp
# @return [Time] client's time
attr_accessor :pa_time_stamp
# @!attribute pausec
# @return [Fixnum] optional microseconds client's time
attr_accessor :pausec
# @!attribute pa_time_stamp
# @return [Time] client's time
attr_accessor :pa_time_stamp
# @!attribute pausec
# @return [Fixnum] optional microseconds client's time
attr_accessor :pausec
# Decodes a Rex::Proto::Kerberos::Model::Field::PreAuthEncTimeStamp
#
# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::Sequence
decode_asn1(input)
else
raise ::RuntimeError, 'Failed to decode EncryptedData Name, invalid input'
end
self
# Decodes a Rex::Proto::Kerberos::Model::Field::PreAuthEncTimeStamp
#
# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::Sequence
decode_asn1(input)
else
raise ::RuntimeError, 'Failed to decode EncryptedData Name, invalid input'
end
# Encodes a Rex::Proto::Kerberos::Model::Field::PreAuthEncTimeStamp into an
# ASN.1 String
#
# @return [String]
def encode
pa_time_stamp_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_pa_time_stamp], 0, :CONTEXT_SPECIFIC)
pausec_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_pausec], 1, :CONTEXT_SPECIFIC)
seq = OpenSSL::ASN1::Sequence.new([pa_time_stamp_asn1, pausec_asn1])
self
end
seq.to_der
# Encodes a Rex::Proto::Kerberos::Model::Field::PreAuthEncTimeStamp into an
# ASN.1 String
#
# @return [String]
def encode
pa_time_stamp_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_pa_time_stamp], 0, :CONTEXT_SPECIFIC)
pausec_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_pausec], 1, :CONTEXT_SPECIFIC)
seq = OpenSSL::ASN1::Sequence.new([pa_time_stamp_asn1, pausec_asn1])
seq.to_der
end
# Encrypts the Rex::Proto::Kerberos::Model::Field::PreAuthEncTimeStamp
#
# @param etype [Fixnum] the crypto schema to encrypt
# @param key [String] the key to encrypt
# @return [String] the encrypted result
def encrypt(etype, key)
data = self.encode
res = ''
case etype
when KERB_ETYPE_RC4_HMAC
res = encrypt_rc4_hmac(data, key, CRYPTO_MSG_TYPE)
else
raise ::RuntimeError, 'EncryptedData schema is not supported'
end
# Encrypts the Rex::Proto::Kerberos::Model::Field::PreAuthEncTimeStamp
#
# @param etype [Fixnum] the crypto schema to encrypt
# @param key [String] the key to encrypt
# @return [String] the encrypted result
def encrypt(etype, key)
data = self.encode
res
end
res = ''
case etype
when KERB_ETYPE_RC4_HMAC
res = encrypt_rc4_hmac(data, key, CRYPTO_MSG_TYPE)
else
raise ::RuntimeError, 'EncryptedData schema is not supported'
end
private
res
end
# Encodes the pa_time_stamp
#
# @return [OpenSSL::ASN1::GeneralizedTime]
def encode_pa_time_stamp
OpenSSL::ASN1::GeneralizedTime.new(pa_time_stamp)
end
private
# Encodes the pausec
#
# @return [OpenSSL::ASN1::Integer]
def encode_pausec
int_bn = OpenSSL::BN.new(pausec)
int = OpenSSL::ASN1::Integer(int_bn)
# Encodes the pa_time_stamp
#
# @return [OpenSSL::ASN1::GeneralizedTime]
def encode_pa_time_stamp
OpenSSL::ASN1::GeneralizedTime.new(pa_time_stamp)
end
int
end
# Encodes the pausec
#
# @return [OpenSSL::ASN1::Integer]
def encode_pausec
int_bn = OpenSSL::BN.new(pausec)
int = OpenSSL::ASN1::Integer(int_bn)
# Decodes a Rex::Proto::Kerberos::Model::Field::PreAuthEncTimeStamp
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
int
end
decode_asn1(asn1)
end
# Decodes a Rex::Proto::Kerberos::Model::Field::PreAuthEncTimeStamp
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
# Decodes a Rex::Proto::Kerberos::Model::Type::PreAuthEncTimeStamp from an
# OpenSSL::ASN1::Sequence
#
# @param input [OpenSSL::ASN1::Sequence] the input to decode from
def decode_asn1(input)
self.pa_time_stamp = decode_pa_time_stamp(input.value[0])
self.pausec = decode_pausec(input.value[1])
end
decode_asn1(asn1)
end
# Decodes the decode_pa_time_stamp from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Boolean]
def decode_pa_time_stamp(input)
input.value[0].value
end
# Decodes a Rex::Proto::Kerberos::Model::Type::PreAuthEncTimeStamp from an
# OpenSSL::ASN1::Sequence
#
# @param input [OpenSSL::ASN1::Sequence] the input to decode from
def decode_asn1(input)
self.pa_time_stamp = decode_pa_time_stamp(input.value[0])
self.pausec = decode_pausec(input.value[1])
end
# Decodes the decode_pa_time_stamp from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Boolean]
def decode_pa_time_stamp(input)
input.value[0].value
end
# Decodes the pausec from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_pausec(input)
input.value[0].value.to_i
end
# Decodes the pausec from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_pausec(input)
input.value[0].value.to_i
end
end
end

View File

@ -4,77 +4,75 @@ module Rex
module Proto
module Kerberos
module Model
module Field
# This class is a representation of a KERB-PA-PAC-REQUEST, it explicitly request
# to include or exclude a PAC in the ticket.
class PreAuthPacRequest < Element
# This class is a representation of a KERB-PA-PAC-REQUEST, it explicitly request
# to include or exclude a PAC in the ticket.
class PreAuthPacRequest < Element
# @!attribute value
# @return [Boolean]
attr_accessor :value
# @!attribute value
# @return [Boolean]
attr_accessor :value
# Decodes a Rex::Proto::Kerberos::Model::Field::PreAuthPacRequest
#
# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::Sequence
decode_asn1(input)
else
raise ::RuntimeError, 'Failed to decode PreAuthData, invalid input'
end
self
# Decodes a Rex::Proto::Kerberos::Model::Field::PreAuthPacRequest
#
# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::Sequence
decode_asn1(input)
else
raise ::RuntimeError, 'Failed to decode PreAuthData, invalid input'
end
# Encodes a Rex::Proto::Kerberos::Model::Field::PreAuthPacRequest into an
# ASN.1 String
#
# @return [String]
def encode
value_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_value], 0, :CONTEXT_SPECIFIC)
seq = OpenSSL::ASN1::Sequence.new([value_asn1])
self
end
seq.to_der
end
# Encodes a Rex::Proto::Kerberos::Model::Field::PreAuthPacRequest into an
# ASN.1 String
#
# @return [String]
def encode
value_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_value], 0, :CONTEXT_SPECIFIC)
seq = OpenSSL::ASN1::Sequence.new([value_asn1])
private
seq.to_der
end
# Encodes value attribute
#
# @return [OpenSSL::ASN1::Boolean]
def encode_value
OpenSSL::ASN1::Boolean.new(value)
end
private
# Decodes a Rex::Proto::Kerberos::Model::Field::PreAuthPacRequest
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
# Encodes value attribute
#
# @return [OpenSSL::ASN1::Boolean]
def encode_value
OpenSSL::ASN1::Boolean.new(value)
end
decode_asn1(asn1)
end
# Decodes a Rex::Proto::Kerberos::Model::Field::PreAuthPacRequest
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
# Decodes a Rex::Proto::Kerberos::Model::Type::PreAuthPacRequest from an
# OpenSSL::ASN1::Sequence
#
# @param input [OpenSSL::ASN1::Sequence] the input to decode from
def decode_asn1(input)
self.value = decode_asn1_value(input.value[0])
end
decode_asn1(asn1)
end
# Decodes the value from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Boolean]
def decode_asn1_value(input)
input.value[0].value
end
# Decodes a Rex::Proto::Kerberos::Model::Type::PreAuthPacRequest from an
# OpenSSL::ASN1::Sequence
#
# @param input [OpenSSL::ASN1::Sequence] the input to decode from
def decode_asn1(input)
self.value = decode_asn1_value(input.value[0])
end
# Decodes the value from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Boolean]
def decode_asn1_value(input)
input.value[0].value
end
end
end

View File

@ -4,112 +4,110 @@ module Rex
module Proto
module Kerberos
module Model
module Type
# This class provides a representation of a principal, an asset (e.g., a
# workstation user or a network server) on a network.
class PrincipalName < Element
# This class provides a representation of a principal, an asset (e.g., a
# workstation user or a network server) on a network.
class PrincipalName < Element
# @!attribute name_type
# @return [Fixnum] The type of name
attr_accessor :name_type
# @!attribute name_string
# @return [Array<String>] A sequence of strings that form a name.
attr_accessor :name_string
# @!attribute name_type
# @return [Fixnum] The type of name
attr_accessor :name_type
# @!attribute name_string
# @return [Array<String>] A sequence of strings that form a name.
attr_accessor :name_string
# Decodes a Rex::Proto::Kerberos::Model::Type::PrincipalName
#
# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::Sequence
decode_asn1(input)
else
raise ::RuntimeError, 'Failed to decode Principal Name, invalid input'
end
self
# Decodes a Rex::Proto::Kerberos::Model::Type::PrincipalName
#
# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::Sequence
decode_asn1(input)
else
raise ::RuntimeError, 'Failed to decode Principal Name, invalid input'
end
# Encodes a Rex::Proto::Kerberos::Model::Type::PrincipalName into an
# ASN.1 String
#
# @return [String]
def encode
integer_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_name_type], 0, :CONTEXT_SPECIFIC)
string_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_name_string], 1, :CONTEXT_SPECIFIC)
seq = OpenSSL::ASN1::Sequence.new([integer_asn1, string_asn1])
self
end
seq.to_der
# Encodes a Rex::Proto::Kerberos::Model::Type::PrincipalName into an
# ASN.1 String
#
# @return [String]
def encode
integer_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_name_type], 0, :CONTEXT_SPECIFIC)
string_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_name_string], 1, :CONTEXT_SPECIFIC)
seq = OpenSSL::ASN1::Sequence.new([integer_asn1, string_asn1])
seq.to_der
end
private
# Encodes the name_type
#
# @return [OpenSSL::ASN1::Integer]
def encode_name_type
int_bn = OpenSSL::BN.new(name_type)
int = OpenSSL::ASN1::Integer(int_bn)
int
end
# Encodes the name_string
#
# @return [OpenSSL::ASN1::Sequence]
def encode_name_string
strings = []
name_string.each do |s|
strings << OpenSSL::ASN1::GeneralString.new(s)
end
seq_string = OpenSSL::ASN1::Sequence.new(strings)
seq_string
end
# Decodes a Rex::Proto::Kerberos::Model::Type::PrincipalName from an String
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
decode_asn1(asn1)
end
# Decodes a Rex::Proto::Kerberos::Model::Type::PrincipalName from an
# OpenSSL::ASN1::Sequence
#
# @param input [OpenSSL::ASN1::Sequence] the input to decode from
def decode_asn1(input)
seq_values = input.value
self.name_type = decode_name_type(seq_values[0])
self.name_string = decode_name_string(seq_values[1])
end
# Decodes the name_type from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_name_type(input)
input.value[0].value.to_i
end
# Decodes the name_string from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Array<String>]
def decode_name_string(input)
strings = []
input.value[0].value.each do |v|
strings << v.value
end
private
# Encodes the name_type
#
# @return [OpenSSL::ASN1::Integer]
def encode_name_type
int_bn = OpenSSL::BN.new(name_type)
int = OpenSSL::ASN1::Integer(int_bn)
int
end
# Encodes the name_string
#
# @return [OpenSSL::ASN1::Sequence]
def encode_name_string
strings = []
name_string.each do |s|
strings << OpenSSL::ASN1::GeneralString.new(s)
end
seq_string = OpenSSL::ASN1::Sequence.new(strings)
seq_string
end
# Decodes a Rex::Proto::Kerberos::Model::Type::PrincipalName from an String
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
decode_asn1(asn1)
end
# Decodes a Rex::Proto::Kerberos::Model::Type::PrincipalName from an
# OpenSSL::ASN1::Sequence
#
# @param input [OpenSSL::ASN1::Sequence] the input to decode from
def decode_asn1(input)
seq_values = input.value
self.name_type = decode_name_type(seq_values[0])
self.name_string = decode_name_string(seq_values[1])
end
# Decodes the name_type from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_name_type(input)
input.value[0].value.to_i
end
# Decodes the name_string from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Array<String>]
def decode_name_string(input)
strings = []
input.value[0].value.each do |v|
strings << v.value
end
strings
end
strings
end
end
end