Class: Rex::Proto::Kerberos::Model::EncApRepPart

Inherits:
Element
  • Object
show all
Defined in:
lib/rex/proto/kerberos/model/enc_ap_rep_part.rb

Overview

This class provides a representation of an EncAPRepPart, sent as the encrypted part of an AP-REP message

Constant Summary

Constants included from Rex::Proto::Kerberos::Model

AP_REP, AP_REQ, AS_REP, AS_REQ, AUTHENTICATOR, ENC_AP_REP_PART, ENC_KRB_CRED_PART, KRB_CRED, KRB_ERROR, TGS_REP, TGS_REQ, TICKET, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Element

attr_accessor, attributes, #attributes, decode, #initialize

Constructor Details

This class inherits a constructor from Rex::Proto::Kerberos::Model::Element

Instance Attribute Details

#ctimeTime

Returns The current time of the client’s host.

Returns:

  • (Time)

    The current time of the client's host



12
13
14
# File 'lib/rex/proto/kerberos/model/enc_ap_rep_part.rb', line 12

def ctime
  @ctime
end

#cusecInteger

Returns The microsecond part of the client’s timestamp.

Returns:

  • (Integer)

    The microsecond part of the client's timestamp



15
16
17
# File 'lib/rex/proto/kerberos/model/enc_ap_rep_part.rb', line 15

def cusec
  @cusec
end

#enc_key_usageRex::Proto::Kerberos::Crypto::KeyUsage, Integer

Returns The enc key usage number for this object.

Returns:



25
26
27
# File 'lib/rex/proto/kerberos/model/enc_ap_rep_part.rb', line 25

def enc_key_usage
  @enc_key_usage
end

#sequence_numberInteger

Returns The initial sequence number to be used for future communications.

Returns:

  • (Integer)

    The initial sequence number to be used for future communications



22
23
24
# File 'lib/rex/proto/kerberos/model/enc_ap_rep_part.rb', line 22

def sequence_number
  @sequence_number
end

#subkeyRex::Proto::Kerberos::Model::EncryptionKey

key which is to be used to protect this specific application session

Returns:



19
20
21
# File 'lib/rex/proto/kerberos/model/enc_ap_rep_part.rb', line 19

def subkey
  @subkey
end

Instance Method Details

#decode(input) ⇒ self

Decodes the Rex::Proto::Kerberos::Model::EncApRepPart from an input

Parameters:

  • input (String, OpenSSL::ASN1::ASN1Data)

    the input to decode from

Returns:

  • (self)

    if decoding succeeds

Raises:



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rex/proto/kerberos/model/enc_ap_rep_part.rb', line 32

def decode(input)
  case input
  when String
    decode_string(input)
  when OpenSSL::ASN1::ASN1Data
    decode_asn1(input)
  else
    raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode EncApRepPart, invalid input'
  end

  self
end

#encodeString

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

Returns:

  • (String)


48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rex/proto/kerberos/model/enc_ap_rep_part.rb', line 48

def encode
  elems = []
  elems << OpenSSL::ASN1::ASN1Data.new([encode_ctime], 0, :CONTEXT_SPECIFIC)
  elems << OpenSSL::ASN1::ASN1Data.new([encode_cusec], 1, :CONTEXT_SPECIFIC)
  elems << OpenSSL::ASN1::ASN1Data.new([encode_subkey], 2, :CONTEXT_SPECIFIC) if subkey
  elems << OpenSSL::ASN1::ASN1Data.new([encode_sequence_number], 3, :CONTEXT_SPECIFIC) if sequence_number

  seq = OpenSSL::ASN1::Sequence.new(elems)
  seq_asn1 = OpenSSL::ASN1::ASN1Data.new([seq], ENC_AP_REP_PART, :APPLICATION)

  seq_asn1.to_der
end

#encrypt(etype, key) ⇒ String

Encrypts the Rex::Proto::Kerberos::Model::EncApRepPart

Parameters:

  • etype (Integer)

    the crypto schema to encrypt

  • key (String)

    the key to encrypt

Returns:

  • (String)

    the encrypted result

Raises:

  • (NotImplementedError)

    if the encryption schema isn't supported



67
68
69
70
71
72
73
# File 'lib/rex/proto/kerberos/model/enc_ap_rep_part.rb', line 67

def encrypt(etype, key)
  raise ::Rex::Proto::Kerberos::Model::Error::KerberosError, 'Missing enc_key_usage' unless enc_key_usage

  data = self.encode
  encryptor = Rex::Proto::Kerberos::Crypto::Encryption::from_etype(etype)
  encryptor.encrypt(data, key, enc_key_usage)
end