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/kdc_response.rb
Views: 11765
# -*- coding: binary -*-12module Rex3module Proto4module Kerberos5module Model6# This class provides a representation of a Kerberos KDC-REP (response) data7# definition8class KdcResponse < 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 pa_data16# @return [Array<Rex::Proto::Kerberos::Model::PreAuthDataEntry>,nil] An array of PreAuthDataEntry. nil if not present.17attr_accessor :pa_data18# @!attribute crealm19# @return [String] The realm part of the client's principal identifier20attr_accessor :crealm21# @!attribute cname22# @return [Rex::Proto::Kerberos::Model::PrincipalName] The name part of the client's principal identifier23attr_accessor :cname24# @!attribute ticket25# @return [Rex::Proto::Kerberos::Model::Ticket] The issued ticket26attr_accessor :ticket27# @!attribute enc_part28# @return [Rex::Proto::Kerberos::Model::EncryptedData] The encrypted part of the response29attr_accessor :enc_part3031# Decodes the Rex::Proto::Kerberos::Model::KdcResponse from an input32#33# @param input [String, OpenSSL::ASN1::ASN1Data] the input to decode from34# @return [self] if decoding succeeds35# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed36def decode(input)37case input38when String39decode_string(input)40when OpenSSL::ASN1::ASN1Data41decode_asn1(input)42else43raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode KdcResponse, invalid input'44end4546self47end4849# Rex::Proto::Kerberos::Model::KdcResponse encoding isn't supported50#51# @raise [NotImplementedError]52def encode53raise ::NotImplementedError, 'KdcResponse encoding not supported'54end5556private5758# Decodes a Rex::Proto::Kerberos::Model::KdcResponse from an String59#60# @param input [String] the input to decode from61def decode_string(input)62asn1 = OpenSSL::ASN1.decode(input)6364decode_asn1(asn1)65end6667# Decodes a Rex::Proto::Kerberos::Model::KdcResponse68#69# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from70# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed71def decode_asn1(input)72input.value[0].value.each do |val|73case val.tag74when 075self.pvno = decode_pvno(val)76when 177self.msg_type = decode_msg_type(val)78when 279self.pa_data = decode_pa_data(val)80when 381self.crealm = decode_crealm(val)82when 483self.cname = decode_cname(val)84when 585self.ticket = decode_ticket(val)86when 687self.enc_part = decode_enc_part(val)88else89raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, "Failed to decode KDC-RESPONSE SEQUENCE (#{val.tag})"90end91end92end9394# Decodes the pvno from an OpenSSL::ASN1::ASN1Data95#96# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from97# @return [Integer]98def decode_pvno(input)99input.value[0].value.to_i100end101102# Decodes the msg_type from an OpenSSL::ASN1::ASN1Data103#104# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from105# @return [Integer]106def decode_msg_type(input)107input.value[0].value.to_i108end109110# Decodes the pa_data field111#112# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from113# @return [Array<Rex::Proto::Kerberos::Model::PreAuthDataEntry>]114def decode_pa_data(input)115pre_auth = []116input.value[0].value.each do |pre_auth_data|117pre_auth << Rex::Proto::Kerberos::Model::PreAuthDataEntry.decode(pre_auth_data)118end119120pre_auth121end122123# Decodes the crealm field124#125# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from126# @return [String]127def decode_crealm(input)128input.value[0].value129end130131# Decodes the cname field132#133# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from134# @return [Rex::Proto::Kerberos::Type::PrincipalName]135def decode_cname(input)136Rex::Proto::Kerberos::Model::PrincipalName.decode(input.value[0])137end138139# Decodes the ticket field140#141# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from142# @return [Rex::Proto::Kerberos::Type::Ticket]143def decode_ticket(input)144Rex::Proto::Kerberos::Model::Ticket.decode(input.value[0])145end146147# Decodes the enc_part148#149# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from150# @return [Rex::Proto::Kerberos::Model::EncryptedData]151def decode_enc_part(input)152Rex::Proto::Kerberos::Model::EncryptedData.decode(input.value[0])153end154end155end156end157end158end159160161