Ejemplo n.º 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);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Try and parse data into an ASN1 authentication token.
        /// </summary>
        /// <param name="data">The data to parse.</param>
        /// <param name="token">The Negotiate authentication token.</param>
        /// <param name="values">Parsed DER Values.</param>
        internal static bool TryParse(byte[] data, DERValue[] values, out KerberosAuthenticationToken token)
        {
            token = null;
            try
            {
                var ret = new KerberosTGTResponseAuthenticationToken(data, values);

                if (values.Length != 1 || !values[0].HasChildren())
                {
                    return(false);
                }

                Queue <DERValue> queue = new Queue <DERValue>(values[0].Children);
                while (queue.Count > 0)
                {
                    var next = queue.Dequeue();
                    if (next.Type != DERTagType.ContextSpecific)
                    {
                        return(false);
                    }
                    switch (next.Tag)
                    {
                    case 0:
                        if (next.ReadChildInteger() != 5)
                        {
                            return(false);
                        }
                        break;

                    case 1:
                        if ((KRB_MSG_TYPE)next.ReadChildInteger() != KRB_MSG_TYPE.KRB_TGT_REP)
                        {
                            return(false);
                        }
                        break;

                    case 2:
                        if (!next.HasChildren())
                        {
                            return(false);
                        }
                        ret.Ticket = KerberosTicket.Parse(next.Children[0]);
                        break;

                    default:
                        return(false);
                    }
                }
                token = ret;
                return(true);
            }
            catch (InvalidDataException)
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Try and parse data into an ASN1 authentication token.
        /// </summary>
        /// <param name="data">The data to parse.</param>
        /// <param name="token">The Negotiate authentication token.</param>
        /// <param name="values">Parsed DER Values.</param>
        internal static bool TryParse(byte[] data, DERValue[] values, out KerberosAuthenticationToken token)
        {
            token = null;
            try
            {
                var ret = new KerberosTGTReplyAuthenticationToken(data, values);

                if (values.Length != 1 || !values[0].HasChildren())
                {
                    return(false);
                }

                foreach (var next in values[0].Children)
                {
                    if (next.Type != DERTagType.ContextSpecific)
                    {
                        return(false);
                    }
                    switch (next.Tag)
                    {
                    case 0:
                        if (next.ReadChildInteger() != 5)
                        {
                            return(false);
                        }
                        break;

                    case 1:
                        if ((KerberosMessageType)next.ReadChildInteger() != KerberosMessageType.KRB_TGT_REP)
                        {
                            return(false);
                        }
                        break;

                    case 2:
                        if (!next.HasChildren())
                        {
                            return(false);
                        }
                        ret.Ticket = KerberosTicket.Parse(next.Children[0]);
                        break;

                    default:
                        return(false);
                    }
                }
                token = ret;
                return(true);
            }
            catch (InvalidDataException)
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Try and parse data into an ASN1 authentication token.
        /// </summary>
        /// <param name="data">The data to parse.</param>
        /// <param name="token">The Negotiate authentication token.</param>
        /// <param name="values">Parsed DER Values.</param>
        internal static bool TryParse(byte[] data, DERValue[] values, out KerberosAuthenticationToken token)
        {
            token = null;
            try
            {
                var ret = new KerberosAPRequestAuthenticationToken(data, values);

                if (values.Length != 1 || !values[0].CheckApplication(14) || !values[0].HasChildren())
                {
                    return(false);
                }

                values = values[0].Children;
                if (values.Length != 1 || !values[0].CheckSequence() || !values[0].HasChildren())
                {
                    return(false);
                }

                Queue <DERValue> queue = new Queue <DERValue>(values[0].Children);
                while (queue.Count > 0)
                {
                    var next = queue.Dequeue();
                    if (next.Type != DERTagType.ContextSpecific)
                    {
                        return(false);
                    }
                    switch (next.Tag)
                    {
                    case 0:
                        if (next.ReadChildInteger() != 5)
                        {
                            return(false);
                        }
                        break;

                    case 1:
                        if ((KRB_MSG_TYPE)next.ReadChildInteger() != KRB_MSG_TYPE.KRB_AP_REQ)
                        {
                            return(false);
                        }
                        break;

                    case 2:
                        if (!next.Children[0].CheckPrimitive(UniversalTag.BIT_STRING))
                        {
                            return(false);
                        }
                        var bits    = next.Children[0].ReadBitString();
                        var options = KerberosAPRequestOptions.None;
                        if (bits[1])
                        {
                            options |= KerberosAPRequestOptions.UseSessionKey;
                        }
                        if (bits[2])
                        {
                            options |= KerberosAPRequestOptions.MutualAuthRequired;
                        }
                        ret.Options = options;
                        break;

                    case 3:
                        if (!next.HasChildren())
                        {
                            return(false);
                        }
                        ret.Ticket = KerberosTicket.Parse(next.Children[0]);
                        break;

                    case 4:
                        if (!next.HasChildren())
                        {
                            return(false);
                        }
                        ret.Authenticator = KerberosEncryptedData.Parse(next.Children[0]);
                        break;

                    default:
                        return(false);
                    }
                }
                token = ret;
                return(true);
            }
            catch (InvalidDataException)
            {
                return(false);
            }
        }