Class: Rex::Proto::Kerberos::Model::AuthorizationData
- Defined in:
- lib/rex/proto/kerberos/model/authorization_data.rb
Overview
This class provides a representation of a Kerberos AuthorizationData data definition.
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
-
#elements ⇒ Array<Hash{Symbol => Integer, String)}
] The type of the authorization data.
Instance Method Summary collapse
-
#decode(input) ⇒ self
Decodes the Rex::Proto::Kerberos::Model::AuthorizationData from an input.
-
#decode_asn1(input) ⇒ Object
Decodes a Rex::Proto::Kerberos::Model::AuthorizationData.
-
#decode_string(input) ⇒ Object
Decodes a Rex::Proto::Kerberos::Model::AuthorizationData from an String.
-
#encode ⇒ String
Encodes a Rex::Proto::Kerberos::Model::AuthorizationData into an ASN.1 String.
-
#encrypt(etype, key) ⇒ String
Encrypts the Rex::Proto::Kerberos::Model::AuthorizationData.
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
#elements ⇒ Array<Hash{Symbol => Integer, String)}
Returns ] The type of the authorization data.
14 15 16 |
# File 'lib/rex/proto/kerberos/model/authorization_data.rb', line 14 def elements @elements end |
Instance Method Details
#decode(input) ⇒ self
Decodes the Rex::Proto::Kerberos::Model::AuthorizationData from an input
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rex/proto/kerberos/model/authorization_data.rb', line 21 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 AuthorizationData, invalid input' end self end |
#decode_asn1(input) ⇒ Object
Decodes a Rex::Proto::Kerberos::Model::AuthorizationData
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rex/proto/kerberos/model/authorization_data.rb', line 71 def decode_asn1(input) self.elements = [] input.each do |elem| element = {} elem.value.each do |val| case val.tag when 0 # ad-type [0] Int32 element[:type] = decode_type(val) when 1 # ad-data [1] OCTET STRING element[:data] = decode_data(val) else raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode AuthorizationData SEQUENCE' end end self.elements << element end end |
#decode_string(input) ⇒ Object
Decodes a Rex::Proto::Kerberos::Model::AuthorizationData from an String
56 57 58 59 60 |
# File 'lib/rex/proto/kerberos/model/authorization_data.rb', line 56 def decode_string(input) asn1 = OpenSSL::ASN1.decode(input) decode_asn1(asn1) end |
#encode ⇒ String
Encodes a Rex::Proto::Kerberos::Model::AuthorizationData into an ASN.1 String
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rex/proto/kerberos/model/authorization_data.rb', line 37 def encode seqs = [] elements.each do |elem| elems = [] type_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_type(elem[:type])], 0, :CONTEXT_SPECIFIC) elems << type_asn1 data_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_data(elem[:data])], 1, :CONTEXT_SPECIFIC) elems << data_asn1 seqs << OpenSSL::ASN1::Sequence.new(elems) end seq = OpenSSL::ASN1::Sequence.new(seqs) seq.to_der end |
#encrypt(etype, key) ⇒ String
Encrypts the Rex::Proto::Kerberos::Model::AuthorizationData
95 96 97 98 99 100 |
# File 'lib/rex/proto/kerberos/model/authorization_data.rb', line 95 def encrypt(etype, key) data = self.encode encryptor = Rex::Proto::Kerberos::Crypto::Encryption::from_etype(etype) encryptor.encrypt(data, key, 5) end |