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/ticket_enc_part.rb
Views: 11766
# -*- coding: binary -*-12module Rex::Proto::Kerberos::Model3# This class provides a representation of a Kerberos ticket encrypted part that helps4# a client authenticate to a service.5class TicketEncPart < Element67attr_accessor :flags # [0] TicketFlags,8attr_accessor :key # [1] EncryptionKey,9attr_accessor :crealm # [2] Realm,10attr_accessor :cname # [3] PrincipalName,11attr_accessor :transited # [4] TransitedEncoding,12attr_accessor :authtime # [5] KerberosTime,13attr_accessor :starttime # [6] KerberosTime OPTIONAL,14attr_accessor :endtime # [7] KerberosTime,15attr_accessor :renew_till # [8] KerberosTime OPTIONAL,16attr_accessor :caddr # [9] HostAddresses OPTIONAL,17attr_accessor :authorization_data # [10] AuthorizationData OPTIONAL181920# Decodes the Rex::Proto::Kerberos::Model::TicketEncPart from an input21#22# @param input [String, OpenSSL::ASN1::ASN1Data] the input to decode from23# @return [self] if decoding succeeds24# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed25def decode(input)26case input27when String28decode_string(input)29when OpenSSL::ASN1::ASN1Data30decode_asn1(input)31else32raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode TicketEncPart, invalid input'33end3435self36end3738# Encodes a Rex::Proto::Kerberos::Model::TicketEncPart into an ASN.1 String39#40# @return [String]41def encode42to_asn1.to_der43end444546# Encodes a Rex::Proto::Kerberos::Model::TicketEncPart into ASN.147#48# @return [OpenSSL::ASN1::ASN1Data] The TicketEncPart ASN1Data49def to_asn150elems = []51elems << OpenSSL::ASN1::ASN1Data.new([encode_flags], 0, :CONTEXT_SPECIFIC)52elems << OpenSSL::ASN1::ASN1Data.new([encode_key], 1, :CONTEXT_SPECIFIC)53elems << OpenSSL::ASN1::ASN1Data.new([encode_crealm], 2, :CONTEXT_SPECIFIC)54elems << OpenSSL::ASN1::ASN1Data.new([encode_cname], 3, :CONTEXT_SPECIFIC)55elems << OpenSSL::ASN1::ASN1Data.new([encode_transited], 4, :CONTEXT_SPECIFIC)56elems << OpenSSL::ASN1::ASN1Data.new([encode_authtime], 5, :CONTEXT_SPECIFIC)57elems << OpenSSL::ASN1::ASN1Data.new([encode_starttime], 6, :CONTEXT_SPECIFIC) if starttime58elems << OpenSSL::ASN1::ASN1Data.new([encode_endtime], 7, :CONTEXT_SPECIFIC)59elems << OpenSSL::ASN1::ASN1Data.new([encode_renew_till], 8, :CONTEXT_SPECIFIC) if renew_till60elems << OpenSSL::ASN1::ASN1Data.new([encode_caddr], 9, :CONTEXT_SPECIFIC) if caddr61elems << OpenSSL::ASN1::ASN1Data.new([encode_authorization_data], 10, :CONTEXT_SPECIFIC) if authorization_data6263seq = OpenSSL::ASN1::Sequence.new(elems)64OpenSSL::ASN1::ASN1Data.new([seq], 3, :APPLICATION)65end6667private6869# Decodes a Rex::Proto::Kerberos::Model::TicketEncPart from an String70#71# @param input [String] the input to decode from72def decode_string(input)73asn1 = OpenSSL::ASN1.decode(input)7475decode_asn1(asn1)76end7778# Decodes a Rex::Proto::Kerberos::Model::TicketEncPart79#80# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from81# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed82#83# EncTicketPart ::= [APPLICATION 3] SEQUENCE {84# flags [0] TicketFlags,85# key [1] EncryptionKey,86# crealm [2] Realm,87# cname [3] PrincipalName,88# transited [4] TransitedEncoding,89# authtime [5] KerberosTime,90# starttime [6] KerberosTime OPTIONAL,91# endtime [7] KerberosTime,92# renew-till [8] KerberosTime OPTIONAL,93# caddr [9] HostAddresses OPTIONAL,94# authorization-data [10] AuthorizationData OPTIONAL95# }96def decode_asn1(input)97input.value[0].value.each do |val|98case val.tag99when 0 # flags [0] TicketFlags100self.flags = decode_flags(val)101when 1 # key [1] EncryptionKey102self.key = decode_key(val)103when 2 # crealm [2] Realm104self.crealm = decode_crealm(val)105when 3 # cname [3] PrincipalName106self.cname = decode_cname(val)107when 4 # transited [4] TransitedEncoding108self.transited = decode_transited(val)109when 5 # authtime [5] KerberosTime110self.authtime = decode_authtime(val)111when 6 # starttime [6] KerberosTime OPTIONAL112self.starttime = decode_starttime(val)113when 7 # endtime [7] KerberosTime114self.endtime = decode_endtime(val)115when 8 # renew-till [8] KerberosTime OPTIONAL116self.renew_till = decode_renew_till(val)117when 9 # caddr [9] HostAddresses OPTIONAL118self.caddr = decode_caddr(val)119when 10 # authorization-data [10] AuthorizationData OPTIONAL120self.authorization_data = decode_authorization_data(val)121else122raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode TicketEncPart SEQUENCE'123end124end125end126127# Decodes the flags from an OpenSSL::ASN1::ASN1Data128#129# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from130# @return [TicketFlags]131def decode_flags(input)132Rex::Proto::Kerberos::Model::TicketFlags.new(input.value[0].value.unpack1('N'))133end134135# Encodes the flags136#137# @return [OpenSSL::ASN1::BitString]138def encode_flags139OpenSSL::ASN1::BitString.new([flags.value].pack('N'))140end141142# Decodes the key from an OpenSSL::ASN1::ASN1Data143#144# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from145# @return [EncryptionKey]146def decode_key(input)147Rex::Proto::Kerberos::Model::EncryptionKey.decode(input.value[0])148end149150# Encodes the key151#152# @return [OpenSSL::ASN1::Sequence]153def encode_key154key.encode155end156157# Decodes the crealm from an OpenSSL::ASN1::ASN1Data158#159# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from160# @return [String]161def decode_crealm(input)162input.value[0].value163end164165# Encodes the crealm166#167# @return [OpenSSL::ASN1::GeneralString]168def encode_crealm169OpenSSL::ASN1::GeneralString.new(crealm)170end171172# Decodes the cname from an OpenSSL::ASN1::ASN1Data173#174# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from175# @return [PrincipalName]176def decode_cname(input)177Rex::Proto::Kerberos::Model::PrincipalName.decode(input.value[0])178end179180# Encodes the cname181#182# @return [String]183def encode_cname184cname.encode185end186187# Decodes the transited from an OpenSSL::ASN1::ASN1Data188#189# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from190# @return [TransitedEncoding]191def decode_transited(input)192Rex::Proto::Kerberos::Model::TransitedEncoding.decode(input.value[0])193end194195# Encodes the transited196#197# @return [String]198def encode_transited199transited.encode200end201202# Decodes the authtime from an OpenSSL::ASN1::ASN1Data203#204# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from205# @return [Time]206def decode_authtime(input)207input.value[0].value208end209210# Encodes the authtime211#212# @return [OpenSSL::ASN1::GeneralizedTime]213def encode_authtime214OpenSSL::ASN1::GeneralizedTime.new(authtime)215end216217# Decodes the starttime from an OpenSSL::ASN1::ASN1Data218#219# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from220# @return [Time]221def decode_starttime(input)222input.value[0].value223end224225# Encodes the starttime226#227# @return [OpenSSL::ASN1::GeneralizedTime]228def encode_starttime229OpenSSL::ASN1::GeneralizedTime.new(starttime)230end231232# Decodes the endtime from an OpenSSL::ASN1::ASN1Data233#234# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from235# @return [Time]236def decode_endtime(input)237input.value[0].value238end239240# Encodes the endtime241#242# @return [OpenSSL::ASN1::GeneralizedTime]243def encode_endtime244OpenSSL::ASN1::GeneralizedTime.new(endtime)245end246247# Decodes the renew_till from an OpenSSL::ASN1::ASN1Data248#249# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from250# @return [Time]251def decode_renew_till(input)252input.value[0].value253end254255# Encodes the renew_till256#257# @return [OpenSSL::ASN1::GeneralizedTime]258def encode_renew_till259OpenSSL::ASN1::GeneralizedTime.new(renew_till)260end261262# Decodes the caddr from an OpenSSL::ASN1::ASN1Data263#264# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from265# @return [HostAddress]266def decode_caddr(input)267Rex::Proto::Kerberos::Model::HostAddress.decode(input)268end269270# Encodes the caddr271#272# @return [String]273def encode_caddr274caddr.encode275end276277# Decodes the authorization_data from an OpenSSL::ASN1::ASN1Data278#279# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from280# @return [AuthorizationData]281def decode_authorization_data(input)282Rex::Proto::Kerberos::Model::AuthorizationData.decode(input.value[0])283end284285# Encodes the authorization_data286#287# @return [String]288def encode_authorization_data289authorization_data.encode290end291end292end293294295