Exemple #1
0
 internal static bool TryParse(KERB_EXTERNAL_TICKET ticket, out KerberosExternalTicket result)
 {
     result = null;
     try {
         var ret = new KerberosExternalTicket();
         ret.ServiceName         = ParseName(ticket.ServiceName);
         ret.TargetName          = ParseName(ticket.TargetName);
         ret.ClientName          = ParseName(ticket.ClientName);
         ret.DomainName          = ticket.DomainName.ToString();
         ret.TargetDomainName    = ticket.TargetDomainName.ToString();
         ret.AltTargetDomainName = ticket.AltTargetDomainName.ToString();
         ret.SessionKey          = ParseKey(ret.ServiceName, ret.DomainName, ticket.SessionKey);
         ret.TicketFlags         = (KerberosTicketFlags)ticket.TicketFlags.SwapEndian();
         ret.Flags             = ticket.Flags;
         ret.KeyExpirationTime = ticket.KeyExpirationTime.ToDateTime();
         ret.StartTime         = ticket.StartTime.ToDateTime();
         ret.EndTime           = ticket.EndTime.ToDateTime();
         ret.RenewUntil        = ticket.RenewUntil.ToDateTime();
         ret.TimeSkew          = new TimeSpan(ticket.TimeSkew.QuadPart);
         byte[]     ticket_data = ticket.ReadTicket();
         DERValue[] values      = DERParser.ParseData(ticket_data, 0);
         if (values.Length != 1)
         {
             return(false);
         }
         ret.Ticket = KerberosTicket.Parse(values[0], ticket_data);
         result     = ret;
         return(true);
     } catch (InvalidDataException) {
         return(false);
     }
 }
        private static NtResult <KerberosExternalTicket> QueryCachedTicket(SafeLsaLogonHandle handle, string target_name, KERB_RETRIEVE_TICKET_FLAGS flags,
                                                                           Luid logon_id, SecHandle sec_handle, bool throw_on_error)
        {
            var package = handle.LookupAuthPackage(AuthenticationPackage.KERBEROS_NAME, throw_on_error);

            if (!package.IsSuccess)
            {
                return(package.Cast <KerberosExternalTicket>());
            }

            using (var buffer = QueryCachedTicket(handle, package.Result, target_name, flags, logon_id, sec_handle, throw_on_error))
            {
                if (!buffer.IsSuccess)
                {
                    return(buffer.Cast <KerberosExternalTicket>());
                }

                KERB_EXTERNAL_TICKET ticket = buffer.Result.Read <KERB_EXTERNAL_TICKET>(0);
                if (!KerberosExternalTicket.TryParse(ticket, out KerberosExternalTicket ret))
                {
                    return(NtStatus.STATUS_INVALID_PARAMETER.CreateResultFromError <KerberosExternalTicket>(throw_on_error));
                }
                return(ret.CreateResult());
            }
        }