예제 #1
0
        /// <summary>
        /// Parse a structured authentication token.
        /// </summary>
        /// <param name="package_name">Name of the authentication package.</param>
        /// <param name="token_count">The count of the tokens before this one.</param>
        /// <param name="token">The token to parse.</param>
        /// <param name="client">Parse operation from a client.</param>
        /// <returns>The parsed authentication token. If can't parse any other format returns
        /// a raw AuthenticationToken.</returns>
        internal static AuthenticationToken Parse(string package_name, int token_count, bool client, byte[] token)
        {
            if (AuthenticationPackage.CheckNtlm(package_name) &&
                NtlmAuthenticationToken.TryParse(token, token_count, client, out NtlmAuthenticationToken ntlm_token))
            {
                return(ntlm_token);
            }

            if (AuthenticationPackage.CheckKerberos(package_name) &&
                KerberosAuthenticationToken.TryParse(token, token_count, client, out KerberosAuthenticationToken kerb_token))
            {
                return(kerb_token);
            }

            if (AuthenticationPackage.CheckNegotiate(package_name) &&
                NegotiateAuthenticationToken.TryParse(token, token_count,
                                                      client, out NegotiateAuthenticationToken nego_token))
            {
                return(nego_token);
            }

            if (ASN1AuthenticationToken.TryParse(token, token_count,
                                                 client, out ASN1AuthenticationToken asn1_token))
            {
                return(asn1_token);
            }

            return(new AuthenticationToken(token));
        }
        internal static AuthenticationToken Parse(string package_name, int token_count, bool client, byte[] token)
        {
            if (token.Length == 0)
            {
                return(new AuthenticationToken(token));
            }

            if (AuthenticationPackage.CheckNtlm(package_name) &&
                NtlmAuthenticationToken.TryParse(token, token_count, client, out NtlmAuthenticationToken ntlm_token))
            {
                return(ntlm_token);
            }

            if (AuthenticationPackage.CheckKerberos(package_name) &&
                KerberosAuthenticationToken.TryParse(token, token_count, client, out KerberosAuthenticationToken kerb_token))
            {
                return(kerb_token);
            }

            if (AuthenticationPackage.CheckNegotiate(package_name))
            {
                if (NegotiateAuthenticationToken.TryParse(token, token_count,
                                                          client, out NegotiateAuthenticationToken nego_token))
                {
                    return(nego_token);
                }
                if (NtlmAuthenticationToken.TryParse(token, token_count, client,
                                                     out NtlmAuthenticationToken nego_ntlm_token))
                {
                    return(nego_ntlm_token);
                }
                if (KerberosAuthenticationToken.TryParse(token, token_count, client,
                                                         out KerberosAuthenticationToken nego_kerb_token))
                {
                    return(nego_kerb_token);
                }
                return(new AuthenticationToken(token));
            }

            if (AuthenticationPackage.CheckDigest(package_name) &&
                DigestAuthenticationToken.TryParse(token, out DigestAuthenticationToken digest_token))
            {
                return(digest_token);
            }

            if ((AuthenticationPackage.CheckSChannel(package_name) || AuthenticationPackage.CheckCredSSP(package_name)) &&
                SchannelAuthenticationToken.TryParse(token, token_count, client, out SchannelAuthenticationToken schannel_token))
            {
                return(schannel_token);
            }

            if (ASN1AuthenticationToken.TryParse(token, token_count,
                                                 client, out ASN1AuthenticationToken asn1_token))
            {
                return(asn1_token);
            }

            return(new AuthenticationToken(token));
        }