예제 #1
0
        public Authorization?Authenticate(string challenge, HttpURLConnection request, ICredentials credentials)
        {
            if (credentials == null || challenge == null)
            {
                Logger.Log(LogLevel.Info, LOG_APP, "No credentials or no challenge");
                return(null);
            }

            string header = challenge.Trim();

            if (header.IndexOf("digest", StringComparison.OrdinalIgnoreCase) == -1)
            {
                Logger.Log(LogLevel.Info, LOG_APP, "Not a digest auth request");
                return(null);
            }

            var currDS = new AuthDigestSession();

            if (!currDS.Parse(challenge))
            {
                Logger.Log(LogLevel.Info, LOG_APP, "Unable to parse challenge");
                return(null);
            }

            var uri              = new Uri(request.URL?.ToString() !);
            int hashcode         = uri.GetHashCode() ^ credentials.GetHashCode() ^ (currDS.Nonce?.GetHashCode() ?? 1);
            AuthDigestSession?ds = null;
            bool addDS           = false;

            if (!Cache.TryGetValue(hashcode, out ds) || ds == null)
            {
                addDS = true;
            }

            if (addDS)
            {
                ds = currDS;
            }
            else if (!ds !.Parse(challenge))
            {
                Logger.Log(LogLevel.Info, LOG_APP, "Current DS failed to parse the challenge");
                return(null);
            }

            if (addDS)
            {
                Cache.Add(hashcode, ds);
            }

            return(ds.Authenticate(request, credentials));
        }
예제 #2
0
        // IAuthenticationModule

        public Authorization Authenticate(string challenge, WebRequest webRequest, ICredentials credentials)
        {
            if (credentials == null || challenge == null)
            {
                return(null);
            }

            string header = challenge.Trim();

            if (header.ToLower().IndexOf("digest") == -1)
            {
                return(null);
            }

            HttpWebRequest request = webRequest as HttpWebRequest;

            if (request == null)
            {
                return(null);
            }

            DigestSession currDS = new DigestSession();

            if (!currDS.Parse(challenge))
            {
                return(null);
            }

            int           hashcode = request.Address.GetHashCode() ^ credentials.GetHashCode() ^ currDS.Nonce.GetHashCode();
            DigestSession ds       = (DigestSession)Cache [hashcode];
            bool          addDS    = (ds == null);

            if (addDS)
            {
                ds = currDS;
            }
            else if (!ds.Parse(challenge))
            {
                return(null);
            }

            if (addDS)
            {
                Cache.Add(hashcode, ds);
            }

            return(ds.Authenticate(webRequest, credentials));
        }
예제 #3
0
        public Authorization PreAuthenticate(WebRequest webRequest, ICredentials credentials)
        {
            HttpWebRequest httpWebRequest = webRequest as HttpWebRequest;

            if (httpWebRequest == null)
            {
                return(null);
            }
            if (credentials == null)
            {
                return(null);
            }
            int num = httpWebRequest.Address.GetHashCode() ^ credentials.GetHashCode();

            return(((DigestSession)Cache[num])?.Authenticate(webRequest, credentials));
        }
예제 #4
0
        public Authorization Authenticate(string challenge, HttpURLConnection request, ICredentials credentials)
        {
            if (credentials == null || challenge == null)
            {
                return(null);
            }

            string header = challenge.Trim();

            if (header.IndexOf("digest", StringComparison.OrdinalIgnoreCase) == -1)
            {
                return(null);
            }

            var currDS = new AuthDigestSession();

            if (!currDS.Parse(challenge))
            {
                return(null);
            }

            var uri              = new Uri(request.URL.ToString());
            int hashcode         = uri.GetHashCode() ^ credentials.GetHashCode() ^ currDS.Nonce.GetHashCode();
            AuthDigestSession ds = null;
            bool addDS           = false;

            if (!Cache.TryGetValue(hashcode, out ds) || ds == null)
            {
                addDS = true;
            }

            if (addDS)
            {
                ds = currDS;
            }
            else if (!ds.Parse(challenge))
            {
                return(null);
            }

            if (addDS)
            {
                Cache.Add(hashcode, ds);
            }

            return(ds.Authenticate(request, credentials));
        }
예제 #5
0
        public Authorization PreAuthenticate(HttpURLConnection request, ICredentials credentials)
        {
            if (request == null || credentials == null)
            {
                return(null);
            }

            var uri              = new Uri(request.URL.ToString());
            int hashcode         = uri.GetHashCode() ^ credentials.GetHashCode();
            AuthDigestSession ds = null;

            if (!Cache.TryGetValue(hashcode, out ds) || ds == null)
            {
                return(null);
            }

            return(ds.Authenticate(request, credentials));
        }
예제 #6
0
        public Authorization?PreAuthenticate(HttpURLConnection request, ICredentials credentials)
        {
            if (request == null || credentials == null)
            {
                Logger.Log(LogLevel.Info, LOG_APP, "No credentials or no challenge");
                return(null);
            }

            var uri              = new Uri(request.URL?.ToString() !);
            int hashcode         = uri.GetHashCode() ^ credentials.GetHashCode();
            AuthDigestSession?ds = null;

            if (!Cache.TryGetValue(hashcode, out ds) || ds == null)
            {
                return(null);
            }

            return(ds.Authenticate(request, credentials));
        }
예제 #7
0
        public Authorization PreAuthenticate(WebRequest webRequest, ICredentials credentials)
        {
            HttpWebRequest request = webRequest as HttpWebRequest;

            if (request == null)
            {
                return(null);
            }

            if (credentials == null)
            {
                return(null);
            }

            int           hashcode = request.Address.GetHashCode() ^ credentials.GetHashCode();
            DigestSession ds       = (DigestSession)Cache [hashcode];

            if (ds == null)
            {
                return(null);
            }

            return(ds.Authenticate(webRequest, credentials));
        }
예제 #8
0
        public Authorization Authenticate(string challenge, WebRequest webRequest, ICredentials credentials)
        {
            if (credentials == null || challenge == null)
            {
                return(null);
            }
            string text = challenge.Trim();

            if (text.ToLower().IndexOf("digest") == -1)
            {
                return(null);
            }
            HttpWebRequest httpWebRequest = webRequest as HttpWebRequest;

            if (httpWebRequest == null)
            {
                return(null);
            }
            int           num           = httpWebRequest.Address.GetHashCode() ^ credentials.GetHashCode();
            DigestSession digestSession = (DigestSession)DigestClient.Cache[num];
            bool          flag          = digestSession == null;

            if (flag)
            {
                digestSession = new DigestSession();
            }
            if (!digestSession.Parse(challenge))
            {
                return(null);
            }
            if (flag)
            {
                DigestClient.Cache.Add(num, digestSession);
            }
            return(digestSession.Authenticate(webRequest, credentials));
        }
예제 #9
0
파일: DigestClient.cs 프로젝트: GirlD/mono
		public Authorization PreAuthenticate (WebRequest webRequest, ICredentials credentials) 
		{
			HttpWebRequest request = webRequest as HttpWebRequest;
			if (request == null)
				return null;

			if (credentials == null)
				return null;

			int hashcode = request.Address.GetHashCode () ^ credentials.GetHashCode ();
			DigestSession ds = (DigestSession) Cache [hashcode];
			if (ds == null)
				return null;

			return ds.Authenticate (webRequest, credentials);
		}
예제 #10
0
파일: DigestClient.cs 프로젝트: GirlD/mono
		// IAuthenticationModule
	
		public Authorization Authenticate (string challenge, WebRequest webRequest, ICredentials credentials) 
		{
			if (credentials == null || challenge == null)
				return null;
	
			string header = challenge.Trim ();
			if (header.ToLower ().IndexOf ("digest") == -1)
				return null;

			HttpWebRequest request = webRequest as HttpWebRequest;
			if (request == null)
				return null;

			DigestSession currDS = new DigestSession();
			if (!currDS.Parse (challenge))
				return null;

			int hashcode = request.Address.GetHashCode () ^ credentials.GetHashCode () ^ currDS.Nonce.GetHashCode ();
			DigestSession ds = (DigestSession) Cache [hashcode];
			bool addDS = (ds == null);
			if (addDS)
				ds = currDS;
			else if (!ds.Parse (challenge))
				return null;

			if (addDS)
				Cache.Add (hashcode, ds);

			return ds.Authenticate (webRequest, credentials);
		}