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_request.rb
Views: 11766
# -*- coding: binary -*-12module Rex3module Proto4module Kerberos5module Model6# This class provides a representation of a Kerberos KDC-REQ (request) data7# definition8class KdcRequest < 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>] Authentication information which may17# be needed before credentials can be issued or decrypted18attr_accessor :pa_data19# @!attribute req_body20# @return [Rex::Proto::Kerberos::Model:::KdcRequestBody] The request body21attr_accessor :req_body2223# Decodes the Rex::Proto::Kerberos::Model::KdcRequest from an input24#25# @param input [String, OpenSSL::ASN1::ASN1Data] the input to decode from26# @return [self] if decoding succeeds27# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed28def decode(input)29case input30when String31decode_string(input)32when OpenSSL::ASN1::ASN1Data33decode_asn1(input)34else35raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode KdcRequest, invalid input'36end3738self39end4041# Encodes the Rex::Proto::Kerberos::Model::KdcRequest into an ASN.1 String42#43# @return [String]44def encode45pvno_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_pvno], 1, :CONTEXT_SPECIFIC)46msg_type_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_msg_type], 2, :CONTEXT_SPECIFIC)47pa_data_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_pa_data], 3, :CONTEXT_SPECIFIC)48req_body_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_req_body], 4, :CONTEXT_SPECIFIC)49seq = OpenSSL::ASN1::Sequence.new([pvno_asn1, msg_type_asn1, pa_data_asn1, req_body_asn1])50seq_asn1 = OpenSSL::ASN1::ASN1Data.new([seq], msg_type, :APPLICATION)51seq_asn1.to_der52end5354private5556# Encodes the pvno field57#58# @return [OpenSSL::ASN1::Integer]59def encode_pvno60bn = OpenSSL::BN.new(pvno.to_s)61int = OpenSSL::ASN1::Integer.new(bn)6263int64end6566# Encodes the msg_type field67#68# @return [OpenSSL::ASN1::Integer]69def encode_msg_type70bn = OpenSSL::BN.new(msg_type.to_s)71int = OpenSSL::ASN1::Integer.new(bn)7273int74end7576# Encodes the pa_data field77#78# @return [String]79def encode_pa_data80elems = []81pa_data.each do |data|82elems << data.encode83end8485OpenSSL::ASN1::Sequence.new(elems)86end8788# Encodes the req_body field89#90# @return [String]91def encode_req_body92req_body.encode93end9495# Decodes a Rex::Proto::Kerberos::Model::KdcRequest from an String96#97# @param input [String] the input to decode from98def decode_string(input)99asn1 = OpenSSL::ASN1.decode(input)100101decode_asn1(asn1)102end103104# Decodes a Rex::Proto::Kerberos::Model::KdcRequest105#106# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from107# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed108def decode_asn1(input)109input.value[0].value.each do |val|110case val.tag111when 1112self.pvno = decode_asn1_pvno(val)113when 2114self.msg_type = decode_asn1_msg_type(val)115when 3116self.pa_data = decode_asn1_pa_data(val)117when 4118self.req_body = decode_asn1_req_body(val)119else120raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode KdcRequest SEQUENCE'121end122end123end124125# Decodes the pvno from an OpenSSL::ASN1::ASN1Data126#127# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from128# @return [Integer]129def decode_asn1_pvno(input)130input.value[0].value.to_i131end132133# Decodes the msg_type from an OpenSSL::ASN1::ASN1Data134#135# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from136# @return [Integer]137def decode_asn1_msg_type(input)138input.value[0].value.to_i139end140141# Decodes the pa_data from an OpenSSL::ASN1::ASN1Data142#143# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from144# @return [Array<Rex::Proto::Kerberos::Model::PreAuthDataEntry>]145def decode_asn1_pa_data(input)146pre_auth = []147input.value[0].value.each do |pre_auth_data|148pre_auth << Rex::Proto::Kerberos::Model::PreAuthDataEntry.decode(pre_auth_data)149end150151pre_auth152end153154# Decodes the req_body from an OpenSSL::ASN1::ASN1Data155#156# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from157# @return [Rex::Proto::Kerberos::Model::KdcRequestBody]158def decode_asn1_req_body(input)159Rex::Proto::Kerberos::Model::KdcRequestBody.decode(input.value[0])160end161end162end163end164end165end166167168