internal static bool Parse(KerberosAuthorizationDataPACEntryType type, byte[] data, out KerberosAuthorizationDataPACEntry entry) { entry = null; if (data.Length < 12) { return(false); } int upn_length = BitConverter.ToUInt16(data, 0); int upn_offset = BitConverter.ToUInt16(data, 2); int dns_length = BitConverter.ToUInt16(data, 4); int dns_offset = BitConverter.ToUInt16(data, 6); KerberosUpnDnsInfoFlags flags = (KerberosUpnDnsInfoFlags)BitConverter.ToInt32(data, 8); if (upn_length + upn_offset > data.Length || dns_length + dns_offset > data.Length) { return(false); } string upn = Encoding.Unicode.GetString(data, upn_offset, upn_length); string dns = Encoding.Unicode.GetString(data, dns_offset, dns_length); entry = new KerberosAuthorizationDataPACUpnDnsInfo(type, data, flags, upn, dns); return(true); }
internal static bool Parse(byte[] data, out KerberosAuthorizationDataPAC auth_data) { auth_data = null; if (data.Length < 8) { return(false); } BinaryReader reader = new BinaryReader(new MemoryStream(data)); long count = reader.ReadInt32(); int version = reader.ReadInt32(); if (version != 0) { return(false); } if (reader.RemainingLength() < count * 16) { return(false); } List <KerberosAuthorizationDataPACEntry> entries = new List <KerberosAuthorizationDataPACEntry>(); for (long i = 0; i < count; ++i) { int type = reader.ReadInt32(); int length = reader.ReadInt32(); long offset = reader.ReadInt64(); if (offset >= data.LongLength || (offset + length) > data.LongLength) { return(false); } byte[] entry_data = new byte[length]; Buffer.BlockCopy(data, (int)offset, entry_data, 0, length); KerberosAuthorizationDataPACEntryType entry_type = (KerberosAuthorizationDataPACEntryType)type; KerberosAuthorizationDataPACEntry pac_entry = null; switch (entry_type) { case KerberosAuthorizationDataPACEntryType.UserClaims: case KerberosAuthorizationDataPACEntryType.DeviceClaims: if (!KerberosAuthorizationDataPACClaimSet.Parse(entry_type, entry_data, out pac_entry)) { pac_entry = null; } break; case KerberosAuthorizationDataPACEntryType.KDCChecksum: case KerberosAuthorizationDataPACEntryType.ServerChecksum: if (!KerberosAuthorizationDataPACSignature.Parse(entry_type, entry_data, out pac_entry)) { pac_entry = null; } break; case KerberosAuthorizationDataPACEntryType.ClientInfo: if (!KerberosAuthorizationDataPACClientInfo.Parse(entry_type, entry_data, out pac_entry)) { pac_entry = null; } break; case KerberosAuthorizationDataPACEntryType.UserPrincipalName: if (!KerberosAuthorizationDataPACUpnDnsInfo.Parse(entry_type, entry_data, out pac_entry)) { pac_entry = null; } break; } if (pac_entry == null) { pac_entry = new KerberosAuthorizationDataPACEntry(entry_type, entry_data); } entries.Add(pac_entry); } auth_data = new KerberosAuthorizationDataPAC(data, entries.AsReadOnly()); return(true); }