class Rex::Proto::Kerberos::Model::PrincipalName
This class provides a representation of a principal, an asset (e.g., a workstation user or a network server) on a network.
Attributes
@!attribute name_string
@return [Array<String>] A sequence of strings that form a name.
@!attribute name_type
@return [Fixnum] The type of name
Public Instance Methods
Decodes a Rex::Proto::Kerberos::Model::PrincipalName
@param input [String, OpenSSL::ASN1::Sequence] the input to decode from @return [self] if decoding succeeds @raise [RuntimeError] if decoding doesn't succeed
# File lib/rex/proto/kerberos/model/principal_name.rb, line 22 def decode(input) case input when String decode_string(input) when OpenSSL::ASN1::Sequence decode_asn1(input) else raise ::RuntimeError, 'Failed to decode Principal Name, invalid input' end self end
Encodes a Rex::Proto::Kerberos::Model::PrincipalName
into an ASN.1 String
@return [String]
# File lib/rex/proto/kerberos/model/principal_name.rb, line 39 def encode integer_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_name_type], 0, :CONTEXT_SPECIFIC) string_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_name_string], 1, :CONTEXT_SPECIFIC) seq = OpenSSL::ASN1::Sequence.new([integer_asn1, string_asn1]) seq.to_der end
Private Instance Methods
Decodes a Rex::Proto::Kerberos::Model::PrincipalName
from an OpenSSL::ASN1::Sequence
@param input [OpenSSL::ASN1::Sequence] the input to decode from
# File lib/rex/proto/kerberos/model/principal_name.rb, line 85 def decode_asn1(input) seq_values = input.value self.name_type = decode_name_type(seq_values[0]) self.name_string = decode_name_string(seq_values[1]) end
Decodes the name_string
from an OpenSSL::ASN1::ASN1Data
@param input [OpenSSL::ASN1::ASN1Data] the input to decode from @return [Array<String>]
# File lib/rex/proto/kerberos/model/principal_name.rb, line 103 def decode_name_string(input) strings = [] input.value[0].value.each do |v| strings << v.value end strings end
Decodes the name_type
from an OpenSSL::ASN1::ASN1Data
@param input [OpenSSL::ASN1::ASN1Data] the input to decode from @return [Fixnum]
# File lib/rex/proto/kerberos/model/principal_name.rb, line 95 def decode_name_type(input) input.value[0].value.to_i end
Decodes a Rex::Proto::Kerberos::Model::PrincipalName
from an String
@param input [String] the input to decode from
# File lib/rex/proto/kerberos/model/principal_name.rb, line 75 def decode_string(input) asn1 = OpenSSL::ASN1.decode(input) decode_asn1(asn1) end
Encodes the name_string
@return [OpenSSL::ASN1::Sequence]
# File lib/rex/proto/kerberos/model/principal_name.rb, line 62 def encode_name_string strings = [] name_string.each do |s| strings << OpenSSL::ASN1::GeneralString.new(s) end seq_string = OpenSSL::ASN1::Sequence.new(strings) seq_string end
Encodes the name_type
@return [OpenSSL::ASN1::Integer]
# File lib/rex/proto/kerberos/model/principal_name.rb, line 52 def encode_name_type int_bn = OpenSSL::BN.new(name_type.to_s) int = OpenSSL::ASN1::Integer.new(int_bn) int end