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_error.rb
Views: 11766
# -*- coding: binary -*-12module Rex3module Proto4module Kerberos5module Model6# This class provides a representation of a Kerberos KRB-ERROR (response error)7# message definition.8class KrbError < Element9# @!attribute pvno10# @return [Integer] The protocol version number11attr_accessor :pvno12# @!attribute msg_type13# @return [Integer] The type of a protocol message14attr_accessor :msg_type15# @!attribute ctime16# @return [Time] The current time of the client's host17attr_accessor :ctime18# @!attribute cusec19# @return [Integer] The microseconds part of the client timestamp20attr_accessor :cusec21# @!attribute stime22# @return [Time] The current time of the server23attr_accessor :stime24# @!attribute susec25# @return [Integer] The microseconds part of the server timestamp26attr_accessor :susec27# @!attribute error_code28# @return [Rex::Proto::Kerberos::Model::Error::ErrorCode] The error request returned by kerberos or the server when a request fails29attr_accessor :error_code30# @!attribute crealm31# @return [String] The realm part of the client's principal identifier32attr_accessor :crealm33# @!attribute cname34# @return [Rex::Proto::Kerberos::Model::PrincipalName] The name part of the client's principal identifier35attr_accessor :cname36# @!attribute realm37# @return [String] The realm part of the server's principal identifier38attr_accessor :realm39# @!attribute sname40# @return [Rex::Proto::Kerberos::Model::PrincipalName] The name part of the server's identity41attr_accessor :sname42# @!attribute etext43# @return [String] Additional text to help explain the error code44attr_accessor :etext45# @!attribute e_data46# @return [String] additional data about the error (ASN.1 encoded data)47attr_accessor :e_data4849# Decodes the Rex::Proto::Kerberos::Model::KrbError from an input50#51# @param input [String, OpenSSL::ASN1::ASN1Data] the input to decode from52# @return [self] if decoding succeeds53# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed54def decode(input)55case input56when String57decode_string(input)58when OpenSSL::ASN1::ASN1Data59decode_asn1(input)60else61raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode KrbError, invalid input'62end6364self65end6667# Rex::Proto::Kerberos::Model::KrbError encoding isn't supported68#69# @raise [NotImplementedError]70def encode71raise ::NotImplementedError, 'KrbError encoding not supported'72end7374# Decodes the e_data field as an Array<PreAuthDataEntry>75#76# @return [Array<Rex::Proto::Kerberos::Model::PreAuthDataEntry>]77def e_data_as_pa_data78pre_auth = []79decoded = OpenSSL::ASN1.decode(self.e_data)80decoded.each do |pre_auth_data|81pre_auth << Rex::Proto::Kerberos::Model::PreAuthDataEntry.decode(pre_auth_data)82end8384pre_auth85end8687# Decodes the e_data field as a PreAuthData88#89# @return [Rex::Proto::Kerberos::Model::PreAuthData]90def e_data_as_pa_data_entry91if self.e_data92decoded = OpenSSL::ASN1.decode(self.e_data)93Rex::Proto::Kerberos::Model::PreAuthDataEntry.decode(decoded)94else95# This is implementation-defined, so may be different in some cases96nil97end98end99100private101102# Decodes a Rex::Proto::Kerberos::Model::KrbError from an String103#104# @param input [String] the input to decode from105def decode_string(input)106asn1 = OpenSSL::ASN1.decode(input)107108decode_asn1(asn1)109end110111# Decodes a Rex::Proto::Kerberos::Model::KrbError112#113# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from114# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed115def decode_asn1(input)116input.value[0].value.each do |val|117case val.tag118when 0119self.pvno = decode_pvno(val)120when 1121self.msg_type = decode_msg_type(val)122when 2123self.ctime = decode_ctime(val)124when 3125self.cusec = decode_cusec(val)126when 4127self.stime = decode_stime(val)128when 5129self.susec = decode_susec(val)130when 6131self.error_code = decode_error_code(val)132when 7133self.crealm = decode_crealm(val)134when 8135self.cname = decode_cname(val)136when 9137self.realm = decode_realm(val)138when 10139self.sname = decode_sname(val)140when 11141self.etext = decode_etext(val)142when 12143self.e_data = decode_e_data(val)144else145raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, "Failed to decode KRB-ERROR SEQUENCE (#{val.tag})"146end147end148end149150# Decodes the pvno from an OpenSSL::ASN1::ASN1Data151#152# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from153# @return [Integer]154def decode_pvno(input)155input.value[0].value.to_i156end157158# Decodes the msg_type from an OpenSSL::ASN1::ASN1Data159#160# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from161# @return [Integer]162def decode_msg_type(input)163input.value[0].value.to_i164end165166# Decodes the ctime field167#168# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from169# @return [Time]170def decode_ctime(input)171input.value[0].value172end173174# Decodes the cusec field175#176# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from177# @return [Integer]178def decode_cusec(input)179input.value[0].value180end181182# Decodes the stime field183#184# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from185# @return [Time]186def decode_stime(input)187input.value[0].value188end189190# Decodes the susec field191#192# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from193# @return [Integer]194def decode_susec(input)195input.value[0].value.to_i196end197198# Decodes the error_code field199#200# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from201# @return [Rex::Proto::Kerberos::Model::Error::ErrorCode]202def decode_error_code(input)203value = input.value[0].value.to_i204205Error::ErrorCodes::ERROR_MAP[value] || Error::ErrorCode.new('UNKNOWN', value, 'Unknown error')206end207208# Decodes the crealm field209#210# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from211# @return [String]212def decode_crealm(input)213input.value[0].value214end215216# Decodes the cname field217#218# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from219# @return [Rex::Proto::Kerberos::Model::PrincipalName]220def decode_cname(input)221Rex::Proto::Kerberos::Model::PrincipalName.decode(input.value[0])222end223224# Decodes the realm field225#226# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from227# @return [String]228def decode_realm(input)229input.value[0].value230end231232# Decodes the sname field233#234# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from235# @return [Rex::Proto::Kerberos::Model::PrincipalName]236def decode_sname(input)237Rex::Proto::Kerberos::Model::PrincipalName.decode(input.value[0])238end239240# Decodes the e-text field241#242# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from243# @return [String]244def decode_etext(input)245input.value[0].value246end247248# Decodes the e_data from an OpenSSL::ASN1::ASN1Data249#250# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from251# @return [String]252def decode_e_data(input)253input.value[0].value254end255end256end257end258end259end260261262