|
| 1 | +# -*- coding: binary -*- |
| 2 | + |
| 3 | +module Rex |
| 4 | + module Proto |
| 5 | + module Kerberos |
| 6 | + module Model |
| 7 | + # This class provides a representation of a Kerberos KERB-SUPERSEDED-BY-USER |
| 8 | + # message as defined in [MS-KILE 2.2.13](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-kile/79170b21-ad15-4a1b-99c4-84b3992d9e70). |
| 9 | + class KerbSupersededByUser < Element |
| 10 | + |
| 11 | + attr_accessor :principal_name |
| 12 | + |
| 13 | + attr_accessor :realm |
| 14 | + |
| 15 | + def ==(other) |
| 16 | + realm == other.realm && principal_name == other.principal_name |
| 17 | + end |
| 18 | + |
| 19 | + def decode(input) |
| 20 | + case input |
| 21 | + when String |
| 22 | + decode_string(input) |
| 23 | + when OpenSSL::ASN1::Sequence |
| 24 | + decode_asn1(input) |
| 25 | + else |
| 26 | + raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode KerbSupersededByUser, invalid input' |
| 27 | + end |
| 28 | + |
| 29 | + self |
| 30 | + end |
| 31 | + |
| 32 | + def encode |
| 33 | + principal_name_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_principal_name], 1, :CONTEXT_SPECIFIC) |
| 34 | + realm_asn1 = OpenSSL::ASN1::ASN1Data.new([encode_realm], 2, :CONTEXT_SPECIFIC) |
| 35 | + seq = OpenSSL::ASN1::Sequence.new([principal_name_asn1, realm_asn1]) |
| 36 | + |
| 37 | + seq.to_der |
| 38 | + end |
| 39 | + |
| 40 | + private |
| 41 | + |
| 42 | + def decode_string(input) |
| 43 | + asn1 = OpenSSL::ASN1.decode(input) |
| 44 | + |
| 45 | + decode_asn1(asn1) |
| 46 | + end |
| 47 | + |
| 48 | + # Decodes a Rex::Proto::Kerberos::Model::KerbSupersededByUser from an |
| 49 | + # OpenSSL::ASN1::Sequence |
| 50 | + # |
| 51 | + # @param input [OpenSSL::ASN1::Sequence] the input to decode from |
| 52 | + def decode_asn1(input) |
| 53 | + seq_values = input.value |
| 54 | + self.principal_name = decode_principal_name(seq_values[0]) |
| 55 | + self.realm = decode_realm(seq_values[1]) |
| 56 | + end |
| 57 | + |
| 58 | + def decode_principal_name(input) |
| 59 | + PrincipalName.decode(input.value[0]) |
| 60 | + end |
| 61 | + |
| 62 | + # Decodes the realm from an OpenSSL::ASN1::ASN1Data |
| 63 | + # |
| 64 | + # @param input [OpenSSL::ASN1::ASN1Data] the input to decode from |
| 65 | + # @return [Array<String>] |
| 66 | + def decode_realm(input) |
| 67 | + input.value[0].value |
| 68 | + end |
| 69 | + |
| 70 | + def encode_principal_name |
| 71 | + self.principal_name.encode |
| 72 | + end |
| 73 | + |
| 74 | + def encode_realm |
| 75 | + OpenSSL::ASN1::OctetString.new(self.realm) |
| 76 | + end |
| 77 | + end |
| 78 | + end |
| 79 | + end |
| 80 | + end |
| 81 | +end |
0 commit comments