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/host_address.rb
Views: 11766
# -*- coding: binary -*-12# This class provides a representation for Kerberos pre authenticated3# data4# https://datatracker.ietf.org/doc/html/rfc4120#section-5.2.55# HostAddress ::= SEQUENCE {6# addr-type [0] Int32,7# address [1] OCTET STRING8# }9class Rex::Proto::Kerberos::Model::HostAddress < Rex::Proto::Kerberos::Model::Element10# @!attribute type11# @return [Rex::Proto::Kerberos::Model::AddressType,Integer] The address addr-type12attr_accessor :type13# @!attribute address14# @return [String] The address value15attr_accessor :address1617# Decodes a Rex::Proto::Kerberos::Model::HostAddress18#19# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from20# @return [self] if decoding succeeds21# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed22def decode(input)23case input24when String25decode_string(input)26when OpenSSL::ASN1::Sequence27decode_asn1(input)28else29raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode HostAddress, invalid input'30end3132self33end3435# Encodes a Rex::Proto::Kerberos::Model::HostAddress into an ASN.1 String36#37# @return [String]38def encode39to_asn1.to_der40end4142# Encodes a Rex::Proto::Kerberos::Model::HostAddress into ASN.143#44# @return [OpenSSL::ASN1::ASN1Data] The HostAddress ASN1Data45def to_asn146type_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_type], 0, :CONTEXT_SPECIFIC)47address_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_address], 1, :CONTEXT_SPECIFIC)48seq = OpenSSL::ASN1::Sequence.new([type_asn1, address_asn1])4950seq51end5253private5455# Encodes the type56#57# @return [OpenSSL::ASN1::Integer]58def encode_type59int_bn = OpenSSL::BN.new(type.to_s)60int = OpenSSL::ASN1::Integer.new(int_bn)6162int63end6465# Encodes the address66#67# @return [OpenSSL::ASN1::OctetString]68def encode_address69OpenSSL::ASN1::OctetString.new(address)70end7172# Decodes a Rex::Proto::Kerberos::Model::HostAddress73#74# @param input [String] the input to decode from75def decode_string(input)76asn1 = OpenSSL::ASN1.decode(input)7778decode_asn1(asn1)79end8081# Decodes a Rex::Proto::Kerberos::Model::HostAddress from an82# OpenSSL::ASN1::Sequence83#84# @param input [OpenSSL::ASN1::Sequence] the input to decode from85def decode_asn1(input)86seq_values = input.value87self.type = decode_asn1_type(seq_values[0])88self.address = decode_asn1_address(seq_values[1])89end9091# Decodes the type from an OpenSSL::ASN1::ASN1Data92#93# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from94# @return [Integer]95def decode_asn1_type(input)96input.value[0].value.to_i97end9899# Decodes the address from an OpenSSL::ASN1::ASN1Data100#101# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from102# @return [Integer]103def decode_asn1_address(input)104input.value[0].value105end106end107108109