Merge pull request #2020 from tomjepp/master
[mono.git] / mcs / class / System / System.Net / DigestClient.cs
index 46650a76438e8689d75c5e7b076aa0d8a1d90702..f570a7396506149012bed764229b3562da8d7c98 100644 (file)
@@ -181,7 +181,7 @@ namespace System.Net
                        }
 
                        value = header.Substring (beginQ, pos - beginQ);
-                       pos += 2;
+                       pos += useQuote ? 2 : 1;
                        return true;
                }
        }
@@ -250,7 +250,7 @@ namespace System.Net
 
                        // build the hash object (only MD5 is defined in RFC2617)
                        if ((parser.Algorithm == null) || (parser.Algorithm.ToUpper ().StartsWith ("MD5")))
-                               hash = HashAlgorithm.Create ("MD5");
+                               hash = MD5.Create ();
 
                        return true;
                }
@@ -291,7 +291,7 @@ namespace System.Net
                {
                        string response = String.Format ("{0}:{1}:", HA1 (username, password), Nonce);
                        if (QOP != null)
-                               response += String.Format ("{0}:{1}:{2}:", _nc.ToString ("x8"), CNonce, QOP);
+                               response += String.Format ("{0}:{1}:{2}:", _nc.ToString ("X8"), CNonce, QOP);
                        response += HA2 (webRequest);
                        return HashToHexString (response);
                }
@@ -329,7 +329,7 @@ namespace System.Net
                        auth.AppendFormat ("response=\"{0}\", ", Response (userName, password, request));
 
                        if (QOP != null) { // quality of protection (server decision)
-                               auth.AppendFormat ("qop={0}, ", QOP);
+                               auth.AppendFormat ("qop=\"{0}\", ", QOP);
                        }
 
                        lock (this) {
@@ -360,21 +360,15 @@ namespace System.Net
        class DigestClient : IAuthenticationModule
        {
 
-               static Hashtable cache;
-
-               public DigestClient () {}
-
+               static readonly Hashtable cache = Hashtable.Synchronized (new Hashtable ());
+               
                static Hashtable Cache {
                        get {
-                               lock (typeof (DigestClient)) {
-                                       if (cache == null) {
-                                               cache = Hashtable.Synchronized (new Hashtable ());
-                                       } else {
-                                               CheckExpired (cache.Count);
-                                       }
-
-                                       return cache;
+                               lock (cache.SyncRoot) {
+                                       CheckExpired (cache.Count);
                                }
+                               
+                               return cache;
                        }
                }
 
@@ -419,13 +413,16 @@ namespace System.Net
                        if (request == null)
                                return null;
 
-                       int hashcode = request.Address.GetHashCode () ^ credentials.GetHashCode ();
+                       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 = new DigestSession ();
-
-                       if (!ds.Parse (challenge))
+                               ds = currDS;
+                       else if (!ds.Parse (challenge))
                                return null;
 
                        if (addDS)