class Rex::Proto::Kerberos::Model::Ticket
This class provides a representation of a Kerberos
ticket that helps a client authenticate to a service.
Attributes
@!attribute enc_part
@return [Rex::Proto::Kerberos::Model::EncryptedData] The encrypted part of the ticket
@!attribute realm
@return [String] The realm that issued the ticket
@!attribute sname
@return [Rex::Proto::Kerberos::Model::PrincipalName] The name part of the server's identity
@!attribute tkt_vno
@return [Fixnum] The ticket version number
Public Instance Methods
Decodes the Rex::Proto::Kerberos::Model::KrbError
from an input
@param input [String, OpenSSL::ASN1::ASN1Data] the input to decode from @return [self] if decoding succeeds @raise [RuntimeError] if decoding doesn't succeed
# File lib/rex/proto/kerberos/model/ticket.rb, line 27 def decode(input) case input when String decode_string(input) when OpenSSL::ASN1::ASN1Data decode_asn1(input) else raise ::RuntimeError, 'Failed to decode Ticket, invalid input' end self end
# File lib/rex/proto/kerberos/model/ticket.rb, line 40 def encode elems = [] elems << OpenSSL::ASN1::ASN1Data.new([encode_tkt_vno], 0, :CONTEXT_SPECIFIC) elems << OpenSSL::ASN1::ASN1Data.new([encode_realm], 1, :CONTEXT_SPECIFIC) elems << OpenSSL::ASN1::ASN1Data.new([encode_sname], 2, :CONTEXT_SPECIFIC) elems << OpenSSL::ASN1::ASN1Data.new([encode_enc_part], 3, :CONTEXT_SPECIFIC) seq = OpenSSL::ASN1::Sequence.new(elems) seq_asn1 = OpenSSL::ASN1::ASN1Data.new([seq], TICKET, :APPLICATION) seq_asn1.to_der end
Private Instance Methods
Decodes a Rex::Proto::Kerberos::Model::Ticket
@param input [OpenSSL::ASN1::ASN1Data] the input to decode from @raise [RuntimeError] if decoding doesn't succeed
# File lib/rex/proto/kerberos/model/ticket.rb, line 99 def decode_asn1(input) input.value[0].value.each do |val| case val.tag when 0 self.tkt_vno = decode_tkt_vno(val) when 1 self.realm = decode_realm(val) when 2 self.sname = decode_sname(val) when 3 self.enc_part = decode_enc_part(val) else raise ::RuntimeError, 'Failed to decode Ticket SEQUENCE' end end end
Decodes the enc_part
from an OpenSSL::ASN1::ASN1Data
@param input [OpenSSL::ASN1::ASN1Data] the input to decode from @return [Rex::Proto::Kerberos::Model::EncryptedData]
# File lib/rex/proto/kerberos/model/ticket.rb, line 143 def decode_enc_part(input) Rex::Proto::Kerberos::Model::EncryptedData.decode(input.value[0]) end
@param input [OpenSSL::ASN1::ASN1Data] the input to decode from @return [String]
# File lib/rex/proto/kerberos/model/ticket.rb, line 127 def decode_realm(input) input.value[0].value end
Decodes the sname field
@param input [OpenSSL::ASN1::ASN1Data] the input to decode from @return [Rex::Proto::Kerberos::Model::PrincipalName]
# File lib/rex/proto/kerberos/model/ticket.rb, line 135 def decode_sname(input) Rex::Proto::Kerberos::Model::PrincipalName.decode(input.value[0]) end
Decodes a Rex::Proto::Kerberos::Model::Ticket
from an String
@param input [String] the input to decode from
# File lib/rex/proto/kerberos/model/ticket.rb, line 89 def decode_string(input) asn1 = OpenSSL::ASN1.decode(input) decode_asn1(asn1) end
Decodes the tkt_vno
from an OpenSSL::ASN1::ASN1Data
@param input [OpenSSL::ASN1::ASN1Data] the input to decode from @return [Fixnum]
# File lib/rex/proto/kerberos/model/ticket.rb, line 120 def decode_tkt_vno(input) input.value[0].value.to_i end
Encodes the enc_part
field
@return [String]
# File lib/rex/proto/kerberos/model/ticket.rb, line 82 def encode_enc_part enc_part.encode end
Encodes the realm field
@return [OpenSSL::ASN1::GeneralString]
# File lib/rex/proto/kerberos/model/ticket.rb, line 68 def encode_realm OpenSSL::ASN1::GeneralString.new(realm) end
Encodes the sname field
@return [String]
# File lib/rex/proto/kerberos/model/ticket.rb, line 75 def encode_sname sname.encode end
Encodes the tkt_vno
field
@return [OpenSSL::ASN1::Integer]
# File lib/rex/proto/kerberos/model/ticket.rb, line 58 def encode_tkt_vno bn = OpenSSL::BN.new(tkt_vno.to_s) int = OpenSSL::ASN1::Integer.new(bn) int end