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/krb_cred_info.rb
Views: 11766
# -*- coding: binary -*-12module Rex3module Proto4module Kerberos5module Model6# This class provides a representation of a KrbCredInfo object7class KrbCredInfo < Element8# @!attribute key9# @return [Rex::Proto::Kerberos::Model::EncryptionKey] The session key associated with a corresponding ticket in the enclosing KrbCred object10attr_accessor :key11# @!attribute prealm12# @return [String] The realm for the principal identity13attr_accessor :prealm14# @!attribute pname15# @return [Rex::Proto::Kerberos::Model::PrincipalName] The name of the principal identity16attr_accessor :pname17# @!attribute flags18# @return [Rex::Proto::Kerberos::Model::KdcOptionFlags] This field indicates which of various options were used or19# requested when the ticket was issued20attr_accessor :flags21# @!attribute auth_time22# @return [Time] the time of initial authentication for the named principal23attr_accessor :auth_time24# @!attribute start_time25# @return [Time] Specifies the time after which the ticket is valid26attr_accessor :start_time27# @!attribute end_time28# @return [Time] This field contains the time after which the ticket will29# not be honored (its expiration time)30attr_accessor :end_time31# @!attribute renew_till32# @return [Time] This field is only present in tickets that have the33# RENEWABLE flag set in the flags field. It indicates the maximum34# endtime that may be included in a renewal35attr_accessor :renew_till36# @!attribute srealm37# @return [String] The realm part of the server's principal identifier38attr_accessor :srealm39# @!attribute sname40# @return [Rex::Proto::Kerberos::Model::PrincipalName] The name part of the server's identity41attr_accessor :sname42# @!attribute caddr43# @return [Rex::Proto::Kerberos::Model::HostAddress] These are the addresses from which the ticket can be used44attr_accessor :caddr4546def ==(other)47key == other.key &&48prealm == other.prealm &&49pname == other.pname &&50flags == other.flags &&51auth_time == other.auth_time &&52start_time == other.start_time &&53end_time == other.end_time &&54renew_till == other.renew_till &&55srealm == other.srealm &&56sname == other.sname &&57caddr == other.caddr58end5960# Decodes the Rex::Proto::Kerberos::Model::KrbCredInfo from an input61#62# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from63# @return [self] if decoding succeeds64# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed65def decode(input)66case input67when String68decode_string(input)69when OpenSSL::ASN1::Sequence70decode_asn1(input)71else72raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode KrbCredInfo, invalid input'73end7475self76end7778def encode79elems = []80elems << OpenSSL::ASN1::ASN1Data.new([encode_key], 0, :CONTEXT_SPECIFIC)81elems << OpenSSL::ASN1::ASN1Data.new([encode_prealm], 1, :CONTEXT_SPECIFIC) if prealm82elems << OpenSSL::ASN1::ASN1Data.new([encode_pname], 2, :CONTEXT_SPECIFIC) if pname83elems << OpenSSL::ASN1::ASN1Data.new([encode_flags], 3, :CONTEXT_SPECIFIC) if flags84elems << OpenSSL::ASN1::ASN1Data.new([encode_auth_time], 4, :CONTEXT_SPECIFIC) if auth_time85elems << OpenSSL::ASN1::ASN1Data.new([encode_start_time], 5, :CONTEXT_SPECIFIC) if start_time86elems << OpenSSL::ASN1::ASN1Data.new([encode_end_time], 6, :CONTEXT_SPECIFIC) if end_time87elems << OpenSSL::ASN1::ASN1Data.new([encode_renew_till], 7, :CONTEXT_SPECIFIC) if renew_till88elems << OpenSSL::ASN1::ASN1Data.new([encode_srealm], 8, :CONTEXT_SPECIFIC) if srealm89elems << OpenSSL::ASN1::ASN1Data.new([encode_sname], 9, :CONTEXT_SPECIFIC) if sname90elems << OpenSSL::ASN1::ASN1Data.new([encode_caddr], 10, :CONTEXT_SPECIFIC) if caddr91seq = OpenSSL::ASN1::Sequence.new(elems)92seq.to_der93end9495private9697# Encodes the key field98#99# @return [String]100def encode_key101key.encode102end103104# Encodes the prealm field105#106# @return [OpenSSL::ASN1::GeneralString]107def encode_prealm108OpenSSL::ASN1::GeneralString.new(prealm)109end110111# Encodes the pname field112#113# @return [String]114def encode_pname115pname.encode116end117118# Encodes the flags119#120# @return [OpenSSL::ASN1::Integer]121def encode_flags122OpenSSL::ASN1::BitString.new([flags.value].pack('N'))123end124125# Encodes the auth_time126#127# @return [OpenSSL::ASN1::GeneralizedTime]128def encode_auth_time129OpenSSL::ASN1::GeneralizedTime.new(auth_time)130end131132# Encodes the start_time133#134# @return [OpenSSL::ASN1::GeneralizedTime]135def encode_start_time136OpenSSL::ASN1::GeneralizedTime.new(start_time)137end138139# Encodes the end_time140#141# @return [OpenSSL::ASN1::GeneralizedTime]142def encode_end_time143OpenSSL::ASN1::GeneralizedTime.new(end_time)144end145146# Encodes the renew_till147#148# @return [OpenSSL::ASN1::GeneralizedTime]149def encode_renew_till150OpenSSL::ASN1::GeneralizedTime.new(renew_till.nil? ? 0 : renew_till)151end152153# Encodes the srealm field154#155# @return [OpenSSL::ASN1::GeneralString]156def encode_srealm157OpenSSL::ASN1::GeneralString.new(srealm)158end159160# Encodes the sname field161#162# @return [String]163def encode_sname164sname.encode165end166167# Encodes the caddr168#169# @return [String]170def encode_caddr171caddr.encode172end173174# Decodes a Rex::Proto::Kerberos::Model::KrbCredInfo from a String175#176# @param input [String] the input to decode from177def decode_string(input)178asn1 = OpenSSL::ASN1.decode(input)179180decode_asn1(asn1)181end182183# Decodes a Rex::Proto::Kerberos::Model::KrbCredInfo184#185# @param input [OpenSSL::ASN1::Sequence] the input to decode from186# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed187def decode_asn1(input)188input.value.each do |val|189case val.tag190when 0191self.key = decode_key(val)192when 1193self.prealm = decode_prealm(val)194when 2195self.pname = decode_pname(val)196when 3197self.flags = decode_flags(val)198when 4199self.auth_time = decode_auth_time(val)200when 5201self.start_time = decode_start_time(val)202when 6203self.end_time = decode_end_time(val)204when 7205self.renew_till = decode_renew_till(val)206when 8207self.srealm = decode_srealm(val)208when 9209self.sname = decode_sname(val)210when 10211self.caddr = decode_caddr(val)212else213raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode KrbCredInfo SEQUENCE'214end215end216end217218# Decodes the key from an OpenSSL::ASN1::ASN1Data219#220# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from221# @return [EncryptionKey]222def decode_key(input)223Rex::Proto::Kerberos::Model::EncryptionKey.decode(input.value[0])224end225226# Decodes the flags field227#228# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from229# @return [Rex::Proto::Kerberos::Model::KdcOptionFlags]230def decode_flags(input)231flags = input.value[0].value.unpack1('N')232# == OpenSSL::ASN1::BitString233#234# === Additional attributes235# _unused_bits_: if the underlying BIT STRING's236# length is a multiple of 8 then _unused_bits_ is 0. Otherwise237# _unused_bits_ indicates the number of bits that are to be ignored in238# the final octet of the BitString's _value_.239unused_bits = input.value[0].unused_bits240flags >>= unused_bits241Rex::Proto::Kerberos::Model::KdcOptionFlags.new(flags)242end243244# Decodes the auth_time field245#246# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from247# @return [Time]248def decode_auth_time(input)249input.value[0].value250end251252# Decodes the start_time field253#254# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from255# @return [Time]256def decode_start_time(input)257input.value[0].value258end259260# Decodes the end_time field261#262# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from263# @return [Time]264def decode_end_time(input)265input.value[0].value266end267268# Decodes the renew_till field269#270# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from271# @return [Time]272def decode_renew_till(input)273input.value[0].value274end275276# Decodes the srealm field277#278# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from279# @return [String]280def decode_srealm(input)281input.value[0].value282end283284# Decodes the prealm field285#286# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from287# @return [String]288def decode_prealm(input)289input.value[0].value290end291292# Decodes the sname field293#294# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from295# @return [Rex::Proto::Kerberos::Type::PrincipalName]296def decode_sname(input)297Rex::Proto::Kerberos::Model::PrincipalName.decode(input.value[0])298end299300# Decodes the pname field301#302# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from303# @return [Rex::Proto::Kerberos::Type::PrincipalName]304def decode_pname(input)305Rex::Proto::Kerberos::Model::PrincipalName.decode(input.value[0])306end307308# Decodes the caddr field309#310# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from311# @return [Array<Rex::Proto::Model::HostAddress>]312def decode_caddr(input)313caddr = []314input.value[0].value.each do |host_address_data|315caddr << Rex::Proto::Kerberos::Model::HostAddress.decode(host_address_data)316end317caddr318end319320end321end322end323end324end325326327