public static KrbTgsReq CreateTgsReq( string spn, KrbEncryptionKey tgtSessionKey, KrbKdcRep kdcRep, KdcOptions options, KrbTicket user2UserTicket = null ) { var tgtApReq = CreateApReq(kdcRep, tgtSessionKey); var pacOptions = new KrbPaPacOptions { Flags = PacOptions.ResourceBasedConstrainedDelegation | PacOptions.Claims | PacOptions.BranchAware }.Encode(); var paData = new List <KrbPaData>() { new KrbPaData { Type = PaDataType.PA_TGS_REQ, Value = tgtApReq.EncodeApplication() }, new KrbPaData { Type = PaDataType.PA_PAC_OPTIONS, Value = pacOptions.AsMemory() } }; var tgt = kdcRep.Ticket; var sname = spn.Split('/', '@'); var tgs = new KrbTgsReq { PaData = paData.ToArray(), Body = new KrbKdcReqBody { EType = KerberosConstants.ETypes.ToArray(), KdcOptions = options, Nonce = KerberosConstants.GetNonce(), Realm = tgt.Realm, SName = new KrbPrincipalName() { Type = PrincipalNameType.NT_SRV_HST, Name = sname }, Till = KerberosConstants.EndOfTime }, }; if (options.HasFlag(KdcOptions.EncTktInSkey) && user2UserTicket != null) { tgs.Body.AdditionalTickets = new[] { user2UserTicket }; } return(tgs); }
public static KrbTgsReq CreateTgsReq( RequestServiceTicket rst, KrbEncryptionKey tgtSessionKey, KrbKdcRep kdcRep, out KrbEncryptionKey subkey ) { var sname = rst.ServicePrincipalName.Split('/', '@'); var tgt = kdcRep.Ticket; var additionalTickets = new List <KrbTicket>(); if (rst.KdcOptions.HasFlag(KdcOptions.EncTktInSkey) && rst.UserToUserTicket != null) { additionalTickets.Add(rst.UserToUserTicket); } if (!string.IsNullOrWhiteSpace(rst.S4uTarget)) { rst.KdcOptions |= KdcOptions.Forwardable; } if (rst.S4uTicket != null) { rst.KdcOptions |= KdcOptions.ConstrainedDelegation; additionalTickets.Add(rst.S4uTicket); } var body = new KrbKdcReqBody { EType = KerberosConstants.ETypes.ToArray(), KdcOptions = rst.KdcOptions, Nonce = KerberosConstants.GetNonce(), Realm = tgt.Realm, SName = new KrbPrincipalName() { Type = PrincipalNameType.NT_SRV_HST, Name = sname }, Till = KerberosConstants.EndOfTime }; if (additionalTickets.Count > 0) { body.AdditionalTickets = additionalTickets.ToArray(); } var bodyChecksum = KrbChecksum.Create( body.Encode().AsMemory(), tgtSessionKey.AsKey(), KeyUsage.PaTgsReqChecksum ); var tgtApReq = CreateApReq(kdcRep, tgtSessionKey, bodyChecksum, out subkey); var pacOptions = new KrbPaPacOptions { Flags = PacOptions.ResourceBasedConstrainedDelegation | PacOptions.Claims | PacOptions.BranchAware }.Encode(); var paData = new List <KrbPaData>() { new KrbPaData { Type = PaDataType.PA_TGS_REQ, Value = tgtApReq.EncodeApplication() }, new KrbPaData { Type = PaDataType.PA_PAC_OPTIONS, Value = pacOptions.AsMemory() } }; if (!string.IsNullOrWhiteSpace(rst.S4uTarget)) { paData.Add(new KrbPaData { Type = PaDataType.PA_FOR_USER, Value = EncodeS4URequest(rst.S4uTarget, tgt.Realm, tgtSessionKey) }); } var tgs = new KrbTgsReq { PaData = paData.ToArray(), Body = body }; return(tgs); }