class Rex::Proto::Kerberos::Model::PreAuthEncTimeStamp

This class is a representation of a PA-ENC-TIMESTAMP, an encrypted timestamp sent as pre authenticated data

Constants

CRYPTO_MSG_TYPE

Attributes

pa_time_stamp[RW]

@!attribute pa_time_stamp

@return [Time] client's time
pausec[RW]

@!attribute pausec

@return [Fixnum] optional microseconds client's time

Public Instance Methods

decode(input) click to toggle source

Decodes a Rex::Proto::Kerberos::Model::PreAuthEncTimeStamp

@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_enc_time_stamp.rb, line 24
def decode(input)
  case input
  when String
    decode_string(input)
  when OpenSSL::ASN1::Sequence
    decode_asn1(input)
  else
    raise ::RuntimeError, 'Failed to decode PreAuthEncTimeStamp, invalid input'
  end

  self
end
encode() click to toggle source

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

@return [String]

# File lib/rex/proto/kerberos/model/pre_auth_enc_time_stamp.rb, line 41
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
encrypt(etype, key) click to toggle source

Encrypts the Rex::Proto::Kerberos::Model::PreAuthEncTimeStamp

@param etype [Fixnum] the crypto schema to encrypt @param key [String] the key to encrypt @return [String] the encrypted result @raise [NotImplementedError] if encryption schema isn't supported

# File lib/rex/proto/kerberos/model/pre_auth_enc_time_stamp.rb, line 55
def encrypt(etype, key)
  data = self.encode

  res = ''
  case etype
  when RC4_HMAC
    res = encrypt_rc4_hmac(data, key, CRYPTO_MSG_TYPE)
  else
    raise ::NotImplementedError, 'EncryptedData schema is not supported'
  end

  res
end

Private Instance Methods

decode_asn1(input) click to toggle source

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

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

# File lib/rex/proto/kerberos/model/pre_auth_enc_time_stamp.rb, line 101
def decode_asn1(input)
  self.pa_time_stamp = decode_pa_time_stamp(input.value[0])
  self.pausec = decode_pausec(input.value[1])
end
decode_pa_time_stamp(input) click to toggle source

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

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

# File lib/rex/proto/kerberos/model/pre_auth_enc_time_stamp.rb, line 110
def decode_pa_time_stamp(input)
  input.value[0].value
end
decode_pausec(input) click to toggle source

Decodes the pausec 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_enc_time_stamp.rb, line 118
def decode_pausec(input)
  input.value[0].value.to_i
end
decode_string(input) click to toggle source

Decodes a Rex::Proto::Kerberos::Model::PreAuthEncTimeStamp

@param input [String] the input to decode from

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

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

Encodes the pa_time_stamp

@return [OpenSSL::ASN1::GeneralizedTime]

# File lib/rex/proto/kerberos/model/pre_auth_enc_time_stamp.rb, line 74
def encode_pa_time_stamp
  OpenSSL::ASN1::GeneralizedTime.new(pa_time_stamp)
end
encode_pausec() click to toggle source

Encodes the pausec

@return [OpenSSL::ASN1::Integer]

# File lib/rex/proto/kerberos/model/pre_auth_enc_time_stamp.rb, line 81
def encode_pausec
  int_bn = OpenSSL::BN.new(pausec.to_s)
  int = OpenSSL::ASN1::Integer.new(int_bn)

  int
end