Class: Rex::Proto::Kerberos::Model::EncryptedData

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

Overview

This class provides a representation of an encrypted 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

#cipherString

Returns The enciphered text.

Returns:

  • (String)

    The enciphered text



17
18
19
# File 'lib/rex/proto/kerberos/model/encrypted_data.rb', line 17

def cipher
  @cipher
end

#etypeObject

Returns the value of attribute etype.



11
12
13
# File 'lib/rex/proto/kerberos/model/encrypted_data.rb', line 11

def etype
  @etype
end

#kvnoInteger

Returns The version number of the key.

Returns:

  • (Integer)

    The version number of the key



14
15
16
# File 'lib/rex/proto/kerberos/model/encrypted_data.rb', line 14

def kvno
  @kvno
end

#name_typeInteger

Returns The encryption algorithm.

Returns:

  • (Integer)

    The encryption algorithm



11
# File 'lib/rex/proto/kerberos/model/encrypted_data.rb', line 11

attr_accessor :etype

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  etype == other.etype &&
    kvno == other.kvno &&
    cipher == other.cipher
end

#decode(input) ⇒ self

Decodes a Rex::Proto::Kerberos::Model::EncryptedData

Parameters:

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

    the input to decode from

Returns:

  • (self)

Raises:



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rex/proto/kerberos/model/encrypted_data.rb', line 30

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

  self
end

#decrypt_asn1(key, msg_type) ⇒ String

Decrypts the cipher with etype encryption schema, presuming that the data is an ASN1 structure

Parameters:

  • key (String)

    the key to decrypt

  • msg_type (Integer)

    the message type

Returns:

  • (String)

    the decrypted 'cipher`

Raises:



72
73
74
75
76
77
78
79
# File 'lib/rex/proto/kerberos/model/encrypted_data.rb', line 72

def decrypt_asn1(key, msg_type)
  if cipher.nil? || cipher.empty?
    return ''
  end

  encryptor = Rex::Proto::Kerberos::Crypto::Encryption::from_etype(etype)
  encryptor.decrypt_asn1(cipher, key, msg_type)
end

#encodeString

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

Returns:

  • (String)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rex/proto/kerberos/model/encrypted_data.rb', line 46

def encode
  elems = []
  etype_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_etype], 0, :CONTEXT_SPECIFIC)
  elems << etype_asn1

  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