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/enc_kdc_response.rb
Views: 11766
# -*- coding: binary -*-12module Rex3module Proto4module Kerberos5module Model6# Based on https://datatracker.ietf.org/doc/html/rfc6806.html#section-117# EncKDCRepPart ::= SEQUENCE {8# key [0] EncryptionKey,9# last-req [1] LastReq,10# nonce [2] UInt32,11# key-expiration [3] KerberosTime OPTIONAL,12# flags [4] TicketFlags,13# authtime [5] KerberosTime,14# starttime [6] KerberosTime OPTIONAL,15# endtime [7] KerberosTime,16# renew-till [8] KerberosTime OPTIONAL,17# srealm [9] Realm,18# sname [10] PrincipalName,19# caddr [11] HostAddresses OPTIONAL20# encrypted-pa-data [12] SEQUENCE OF PA-DATA OPTIONAL21# }22class EncKdcResponse < Element23# @!attribute key24# @return [Rex::Proto::Kerberos::Model::EncryptionKey] The session key25attr_accessor :key26# @!attribute last_req27# @return [Array<Rex::Proto::Kerberos::Model::LastRequest>] This field is returned by the KDC and specifies the time(s)28# of the last request by a principal29attr_accessor :last_req30# @!attribute nonce31# @return [Integer] random number32attr_accessor :nonce33# @!attribute key_expiration34# @return [Time] The key-expiration field is part of the response from the35# KDC and specifies the time that the client's secret key is due to expire36attr_accessor :key_expiration37# @!attribute flags38# @return [Rex::Proto::Kerberos::Model::KdcOptionFlags] This field indicates which of various options were used or39# requested when the ticket was issued40attr_accessor :flags41# @!attribute auth_time42# @return [Time] the time of initial authentication for the named principal43attr_accessor :auth_time44# @!attribute start_time45# @return [Time] Specifies the time after which the ticket is valid46attr_accessor :start_time47# @!attribute end_time48# @return [Time] This field contains the time after which the ticket will49# not be honored (its expiration time)50attr_accessor :end_time51# @!attribute renew_till52# @return [Time] This field is only present in tickets that have the53# RENEWABLE flag set in the flags field. It indicates the maximum54# endtime that may be included in a renewal55attr_accessor :renew_till56# @!attribute srealm57# @return [String] The realm part of the server's principal identifier58attr_accessor :srealm59# @!attribute sname60# @return [Rex::Proto::Kerberos::Model::PrincipalName] The name part of the server's identity61attr_accessor :sname62# @!attribute caddr63# @return [Rex::Proto::Kerberos::Model::HostAddress] These are the addresses from which the ticket can be used64attr_accessor :caddr65# @!attribute pa_data66# @return [Array<Rex::Proto::Kerberos::Model::PreAuthDataEntry>,nil] An array of PreAuthDataEntry. nil if not present.67attr_accessor :pa_data6869# Decodes the Rex::Proto::Kerberos::Model::EncKdcResponse from an input70#71# @param input [String, OpenSSL::ASN1::ASN1Data] the input to decode from72# @return [self] if decoding succeeds73# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed74def decode(input)75case input76when String77decode_string(input)78when OpenSSL::ASN1::ASN1Data79decode_asn1(input)80else81raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode EncKdcResponse, invalid input'82end8384self85end8687# Rex::Proto::Kerberos::Model::EncKdcResponse encoding isn't supported88#89# @raise [NotImplementedError]90def encode91raise ::NotImplementedError, 'EncKdcResponse encoding not supported'92end9394private9596# Decodes a Rex::Proto::Kerberos::Model::EncKdcResponse from an String97#98# @param input [String] the input to decode from99def decode_string(input)100asn1 = OpenSSL::ASN1.decode(input)101102decode_asn1(asn1)103end104105# Decodes a Rex::Proto::Kerberos::Model::EncKdcResponse106#107# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from108# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed109def decode_asn1(input)110input.value[0].value.each do |val|111case val.tag112when 0113self.key = decode_key(val)114when 1115self.last_req = decode_last_req(val)116when 2117self.nonce = decode_nonce(val)118when 3119self.key_expiration = decode_key_expiration(val)120when 4121self.flags = decode_flags(val)122when 5123self.auth_time = decode_auth_time(val)124when 6125self.start_time = decode_start_time(val)126when 7127self.end_time = decode_end_time(val)128when 8129self.renew_till = decode_renew_till(val)130when 9131self.srealm = decode_srealm(val)132when 10133self.sname = decode_sname(val)134when 11135self.caddr = decode_caddr(val)136when 12137self.pa_data = decode_pa_data(val)138else139raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, "Failed to decode tag #{val.tag.inspect} in ENC-KDC-RESPONSE SEQUENCE"140end141end142end143144# Decodes the key from an OpenSSL::ASN1::ASN1Data145#146# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from147# @return [EncryptionKey]148def decode_key(input)149Rex::Proto::Kerberos::Model::EncryptionKey.decode(input.value[0])150end151152# Decodes the last_req from an OpenSSL::ASN1::ASN1Data153#154# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from155# @return [Array<Rex::Proto::Kerberos::Model::LastRequest>]156def decode_last_req(input)157last_requests = []158input.value[0].value.each do |last_request|159last_requests << Rex::Proto::Kerberos::Model::LastRequest.decode(last_request)160end161162last_requests163end164165# Decodes the nonce field166#167# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from168# @return [Integer]169def decode_nonce(input)170input.value[0].value.to_i171end172173# Decodes the key_expiration field174#175# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from176# @return [Time]177def decode_key_expiration(input)178input.value[0].value179end180181# Decodes the flags field182#183# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from184# @return [Rex::Proto::Kerberos::Model::KdcOptionFlags]185def decode_flags(input)186flags = input.value[0].value.unpack1('N')187# == OpenSSL::ASN1::BitString188#189# === Additional attributes190# _unused_bits_: if the underlying BIT STRING's191# length is a multiple of 8 then _unused_bits_ is 0. Otherwise192# _unused_bits_ indicates the number of bits that are to be ignored in193# the final octet of the BitString's _value_.194unused_bits = input.value[0].unused_bits195flags >>= unused_bits196Rex::Proto::Kerberos::Model::KdcOptionFlags.new(flags)197end198199# Decodes the auth_time field200#201# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from202# @return [Time]203def decode_auth_time(input)204input.value[0].value205end206207# Decodes the start_time field208#209# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from210# @return [Time]211def decode_start_time(input)212input.value[0].value213end214215# Decodes the end_time field216#217# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from218# @return [Time]219def decode_end_time(input)220input.value[0].value221end222223# Decodes the renew_till field224#225# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from226# @return [Time]227def decode_renew_till(input)228input.value[0].value229end230231# Decodes the srealm field232#233# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from234# @return [String]235def decode_srealm(input)236input.value[0].value237end238239# Decodes the sname field240#241# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from242# @return [Rex::Proto::Kerberos::Type::PrincipalName]243def decode_sname(input)244Rex::Proto::Kerberos::Model::PrincipalName.decode(input.value[0])245end246247# Decodes the caddr field248#249# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from250# @return [Array<Rex::Proto::Model::HostAddress>]251def decode_caddr(input)252caddr = []253input.value[0].value.each do |host_address_data|254caddr << Rex::Proto::Kerberos::Model::HostAddress.decode(host_address_data)255end256caddr257end258259# Decodes the pa_data field260#261# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from262# @return [Array<Rex::Proto::Kerberos::Model::PreAuthDataEntry>]263def decode_pa_data(input)264pre_auth = []265input.value[0].value.each do |pre_auth_data|266pre_auth << Rex::Proto::Kerberos::Model::PreAuthDataEntry.decode(pre_auth_data)267end268269pre_auth270end271end272end273end274end275end276277278