class Rex::Proto::Kerberos::Model::PreAuthData

This class provides a representation for Kerberos pre authenticated data

Attributes

type[RW]

@!attribute type

@return [Fixnum] The padata type
value[RW]

@!attribute value

@return [String] The padata value

Public Instance Methods

decode(input) click to toggle source

Decodes a Rex::Proto::Kerberos::Model::PreAuthData

@param input [String, OpenSSL::ASN1::Sequence] the input to decode from @return [self] if decoding succeeds @raise [RuntimeError] if decoding doesn't succeed

# File lib/rex/proto/kerberos/model/pre_auth_data.rb, line 22
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
end
encode() click to toggle source

Encodes a Rex::Proto::Kerberos::Model::PreAuthData into an ASN.1 String

@return [String]

# File lib/rex/proto/kerberos/model/pre_auth_data.rb, line 38
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])

  seq.to_der
end

Private Instance Methods

decode_asn1(input) click to toggle source

Decodes a Rex::Proto::Kerberos::Model::PreAuthData from an OpenSSL::ASN1::Sequence

@param input [OpenSSL::ASN1::Sequence] the input to decode from

# File lib/rex/proto/kerberos/model/pre_auth_data.rb, line 78
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_type(input) click to toggle source

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

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

# File lib/rex/proto/kerberos/model/pre_auth_data.rb, line 88
def decode_asn1_type(input)
  input.value[0].value.to_i
end
decode_asn1_value(input) click to toggle source

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

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

# File lib/rex/proto/kerberos/model/pre_auth_data.rb, line 96
def decode_asn1_value(input)
  input.value[0].value
end
decode_string(input) click to toggle source

Decodes a Rex::Proto::Kerberos::Model::PreAuthData

@param input [String] the input to decode from

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

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

Encodes the type

@return [OpenSSL::ASN1::Integer]

# File lib/rex/proto/kerberos/model/pre_auth_data.rb, line 51
def encode_type
  int_bn = OpenSSL::BN.new(type.to_s)
  int = OpenSSL::ASN1::Integer.new(int_bn)

  int
end
encode_value() click to toggle source

Encodes the value

@return [OpenSSL::ASN1::OctetString]

# File lib/rex/proto/kerberos/model/pre_auth_data.rb, line 61
def encode_value
  OpenSSL::ASN1::OctetString.new(value)
end