public PrivilegedAttributeCertificate(KrbAuthorizationData authz, SignatureMode mode = SignatureMode.Kdc) : base(authz?.Type ?? 0, AuthorizationDataType.AdWin2kPac) { var pac = authz.Data; this.pacData = new byte[pac.Length]; this.Mode = mode; pac.CopyTo(this.pacData); using (var stream = new NdrBuffer(pac, align: false)) { var count = stream.ReadInt32LittleEndian(); this.Version = stream.ReadInt32LittleEndian(); if (this.Version != PAC_VERSION) { throw new InvalidDataException($"Unknown PAC Version {this.Version}"); } var errors = new List <PacDecodeError>(); for (var i = 0; i < count; i++) { var type = (PacType)stream.ReadInt32LittleEndian(); var size = stream.ReadInt32LittleEndian(); var offset = stream.ReadInt64LittleEndian(); var pacInfoBuffer = pac.Slice((int)offset, size); int exclusionStart; int exclusionLength; try { this.ParsePacType(type, pacInfoBuffer, out exclusionStart, out exclusionLength); } catch (Exception ex) { errors.Add(new PacDecodeError() { Type = type, Data = pacInfoBuffer, Exception = ex }); throw; } if (exclusionStart > 0 && exclusionLength > 0) { this.pacData.Span.Slice((int)offset + exclusionStart, exclusionLength).Clear(); } } this.DecodingErrors = errors; } }
public PrivilegedAttributeCertificate(KrbAuthorizationData authz) : base(authz.Type, AuthorizationDataType.AdWin2kPac) { var pac = authz.Data; pacData = MemoryMarshal.AsMemory(pac); var stream = new NdrBuffer(pac, align: false); var count = stream.ReadInt32LittleEndian(); Version = stream.ReadInt32LittleEndian(); if (Version != PAC_VERSION) { throw new InvalidDataException($"Unknown PAC Version {Version}"); } var errors = new List <PacDecodeError>(); for (var i = 0; i < count; i++) { var type = (PacType)stream.ReadInt32LittleEndian(); var size = stream.ReadInt32LittleEndian(); var offset = stream.ReadInt64LittleEndian(); var pacInfoBuffer = pac.Slice((int)offset, size); int exclusionStart; int exclusionLength; try { ParsePacType(type, pacInfoBuffer, out exclusionStart, out exclusionLength); } catch (Exception ex) { errors.Add(new PacDecodeError() { Type = type, Data = pacInfoBuffer, Exception = ex }); throw; } if (exclusionStart > 0 && exclusionLength > 0) { pacData.Span.Slice((int)offset + exclusionStart, exclusionLength).Fill(0); } } DecodingErrors = errors; }