class Rex::Proto::Kerberos::Model::KdcRequest

This class provides a representation of a Kerberos KDC-REQ (request) data definition

Attributes

msg_type[RW]

@!attribute msg_type

@return [Fixnum] The type of a protocol message
pa_data[RW]

@!attribute pa_data

@return [Array<Rex::Proto::Kerberos::Model::PreAuthData>] Authentication information which may
be needed before credentials can be issued or decrypted
pvno[RW]

@!attribute pvno

@return [Fixnum] The protocol version number
req_body[RW]

@!attribute req_body

@return [Rex::Proto::Kerberos::Model:::KdcRequestBody] The request body

Public Instance Methods

decode(input) click to toggle source

Decodes the Rex::Proto::Kerberos::Model::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

# File lib/rex/proto/kerberos/model/kdc_request.rb, line 28
def decode(input)
  case input
  when String
    decode_string(input)
  when OpenSSL::ASN1::ASN1Data
    decode_asn1(input)
  else
    raise ::RuntimeError, 'Failed to decode KdcRequest, invalid input'
  end

  self
end
encode() click to toggle source

Encodes the Rex::Proto::Kerberos::Model::KdcRequest into an ASN.1 String

@return [String]

# File lib/rex/proto/kerberos/model/kdc_request.rb, line 44
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 Instance Methods

decode_asn1(input) click to toggle source

Decodes a Rex::Proto::Kerberos::Model::KdcRequest

@param input [OpenSSL::ASN1::ASN1Data] the input to decode from @raise [RuntimeError] if decoding doesn't succeed

# File lib/rex/proto/kerberos/model/kdc_request.rb, line 108
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 KdcRequest SEQUENCE'
    end
  end
end
decode_asn1_msg_type(input) click to toggle source

Decodes the msg_type from an OpenSSL::ASN1::ASN1Data

@param input [OpenSSL::ASN1::ASN1Data] the input to decode from @return [Fixnum]

# File lib/rex/proto/kerberos/model/kdc_request.rb, line 137
def decode_asn1_msg_type(input)
  input.value[0].value.to_i
end
decode_asn1_pa_data(input) click to toggle source

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::PreAuthData>]

# File lib/rex/proto/kerberos/model/kdc_request.rb, line 145
def decode_asn1_pa_data(input)
  pre_auth = []
  input.value[0].value.each do |pre_auth_data|
    pre_auth << Rex::Proto::Kerberos::Model::PreAuthData.decode(pre_auth_data)
  end

  pre_auth
end
decode_asn1_pvno(input) click to toggle source

Decodes the pvno from an OpenSSL::ASN1::ASN1Data

@param input [OpenSSL::ASN1::ASN1Data] the input to decode from @return [Fixnum]

# File lib/rex/proto/kerberos/model/kdc_request.rb, line 129
def decode_asn1_pvno(input)
  input.value[0].value.to_i
end
decode_asn1_req_body(input) click to toggle source

Decodes the req_body from an OpenSSL::ASN1::ASN1Data

@param input [OpenSSL::ASN1::ASN1Data] the input to decode from @return [Rex::Proto::Kerberos::Model::KdcRequestBody]

# File lib/rex/proto/kerberos/model/kdc_request.rb, line 158
def decode_asn1_req_body(input)
  Rex::Proto::Kerberos::Model::KdcRequestBody.decode(input.value[0])
end
decode_string(input) click to toggle source

Decodes a Rex::Proto::Kerberos::Model::KdcRequest from an String

@param input [String] the input to decode from

# File lib/rex/proto/kerberos/model/kdc_request.rb, line 98
def decode_string(input)
  asn1 = OpenSSL::ASN1.decode(input)

  decode_asn1(asn1)
end
encode_msg_type() click to toggle source

Encodes the msg_type field

@return [OpenSSL::ASN1::Integer]

# File lib/rex/proto/kerberos/model/kdc_request.rb, line 69
def encode_msg_type
  bn = OpenSSL::BN.new(msg_type.to_s)
  int = OpenSSL::ASN1::Integer.new(bn)

  int
end
encode_pa_data() click to toggle source

Encodes the pa_data field

@return [String]

# File lib/rex/proto/kerberos/model/kdc_request.rb, line 79
def encode_pa_data
  elems = []
  pa_data.each do |data|
    elems << data.encode
  end

  OpenSSL::ASN1::Sequence.new(elems)
end
encode_pvno() click to toggle source

Encodes the pvno field

@return [OpenSSL::ASN1::Integer]

# File lib/rex/proto/kerberos/model/kdc_request.rb, line 59
def encode_pvno
  bn = OpenSSL::BN.new(pvno.to_s)
  int = OpenSSL::ASN1::Integer.new(bn)

  int
end
encode_req_body() click to toggle source

Encodes the req_body field

@return [String]

# File lib/rex/proto/kerberos/model/kdc_request.rb, line 91
def encode_req_body
  req_body.encode
end