Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/proto/kerberos/model/transited_encoding.rb
Views: 11766
# -*- coding: binary -*-12module Rex::Proto::Kerberos::Model3# This class provides a representation of a Kerberos ticket that helps4# a client authenticate to a service.5class TransitedEncoding < Element67# @return [Integer] [0] Int32 -- must be registered --8attr_accessor :tr_type9# @return [String] [1] OCTET STRING10attr_accessor :contents111213# Decodes the Rex::Proto::Kerberos::Model::TransitedEncoding from an input14#15# @param input [String, OpenSSL::ASN1::ASN1Data] the input to decode from16# @return [self] if decoding succeeds17# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed18def decode(input)19case input20when String21decode_string(input)22when OpenSSL::ASN1::ASN1Data23decode_asn1(input)24else25raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode TransitedEncoding, invalid input'26end2728self29end3031# Encodes a Rex::Proto::Kerberos::Model::TransitedEncoding into an ASN.1 String32#33# @return [String]34def encode35to_asn1.to_der36end3738# Encodes a Rex::Proto::Kerberos::Model::TransitedEncoding into ASN.139#40# @return [OpenSSL::ASN1::ASN1Data] The TransitedEncoding ASN1Data41def to_asn142elems = []43elems << OpenSSL::ASN1::ASN1Data.new([encode_tr_type], 0, :CONTEXT_SPECIFIC)44elems << OpenSSL::ASN1::ASN1Data.new([encode_contents], 1, :CONTEXT_SPECIFIC)4546OpenSSL::ASN1::Sequence.new(elems)47end4849private5051# Decodes a Rex::Proto::Kerberos::Model::TicketEncPart from an String52#53# @param input [String] the input to decode from54def decode_string(input)55asn1 = OpenSSL::ASN1.decode(input)5657decode_asn1(asn1)58end5960# Decodes a Rex::Proto::Kerberos::Model::TransitedEncoding61#62# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from63# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed64#65# TransitedEncoding ::= SEQUENCE {66# tr-type [0] Int32 -- must be registered --,67# contents [1] OCTET STRING68# }69def decode_asn1(input)70input.value.each do |val|71case val.tag72when 0 # tr-type [0] Int32 -- must be registered --,73self.tr_type = decode_tr_type(val)74when 1 # contents [1] OCTET STRING75self.contents = decode_contents(val)76else77raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode TransitedEncoding SEQUENCE'78end79end80end8182# Decodes the type from an OpenSSL::ASN1::ASN1Data83#84# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from85# @return [Integer]86def decode_tr_type(input)87input.value[0].value.to_i88end8990# Encodes the type91#92# @return [OpenSSL::ASN1::Integer]93def encode_tr_type94bn = OpenSSL::BN.new(tr_type.to_s)95OpenSSL::ASN1::Integer.new(bn)96end9798# Decodes the address from an OpenSSL::ASN1::ASN1Data99#100# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from101# @return [String]102def decode_contents(input)103input.value[0].value104end105106# Encodes the contents107#108# @return [OpenSSL::ASN1::OctetString]109def encode_contents110OpenSSL::ASN1::OctetString.new(contents)111end112end113end114115116