public static KrbCred WrapTicket(KrbTicket ticket, KrbCredInfo credInfo) { if (ticket is null) { throw new ArgumentNullException(nameof(ticket)); } if (credInfo is null) { throw new ArgumentNullException(nameof(credInfo)); } Now(out DateTimeOffset timestamp, out int usec); var encPart = new KrbEncKrbCredPart { Timestamp = timestamp, USec = usec, TicketInfo = new[] { credInfo } }; var cred = new KrbCred { EncryptedPart = new KrbEncryptedData { Cipher = encPart.EncodeApplication() }, Tickets = new[] { ticket }, }; return(cred); }
internal static void Decode <T>(AsnReader reader, Asn1Tag expectedTag, out T decoded) where T : KrbEncKrbCredPart, new() { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = new T(); AsnReader sequenceReader = reader.ReadSequence(expectedTag); AsnReader explicitReader; AsnReader collectionReader; explicitReader = sequenceReader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 0)); // Decode SEQUENCE OF for TicketInfo { collectionReader = explicitReader.ReadSequence(); var tmpList = new List <KrbCredInfo>(); KrbCredInfo tmpItem; while (collectionReader.HasData) { KrbCredInfo.Decode <KrbCredInfo>(collectionReader, out KrbCredInfo tmp); tmpItem = tmp; tmpList.Add(tmpItem); } decoded.TicketInfo = tmpList.ToArray(); } explicitReader.ThrowIfNotEmpty(); if (sequenceReader.HasData && sequenceReader.PeekTag().HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1))) { explicitReader = sequenceReader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 1)); if (explicitReader.TryReadInt32(out int tmpNonce)) { decoded.Nonce = tmpNonce; } else { explicitReader.ThrowIfNotEmpty(); } explicitReader.ThrowIfNotEmpty(); } if (sequenceReader.HasData && sequenceReader.PeekTag().HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 2))) { explicitReader = sequenceReader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 2)); decoded.Timestamp = explicitReader.ReadGeneralizedTime(); explicitReader.ThrowIfNotEmpty(); } if (sequenceReader.HasData && sequenceReader.PeekTag().HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 3))) { explicitReader = sequenceReader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 3)); if (explicitReader.TryReadInt32(out int tmpUSec)) { decoded.USec = tmpUSec; } else { explicitReader.ThrowIfNotEmpty(); } explicitReader.ThrowIfNotEmpty(); } if (sequenceReader.HasData && sequenceReader.PeekTag().HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 4))) { explicitReader = sequenceReader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 4)); KrbHostAddress.Decode <KrbHostAddress>(explicitReader, out KrbHostAddress tmpSAddress); decoded.SAddress = tmpSAddress; explicitReader.ThrowIfNotEmpty(); } if (sequenceReader.HasData && sequenceReader.PeekTag().HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 5))) { explicitReader = sequenceReader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 5)); KrbHostAddress.Decode <KrbHostAddress>(explicitReader, out KrbHostAddress tmpRAddress); decoded.RAddress = tmpRAddress; explicitReader.ThrowIfNotEmpty(); } sequenceReader.ThrowIfNotEmpty(); }