int length;
int pos;
static string [] keywords = { "realm", "opaque", "nonce", "algorithm", "qop" };
- static char [] endSeparator = new char[] { '"', ',' };
string [] values = new string [keywords.Length];
public DigestHeaderParser (string header)
pos--;
}
- void SkipNonWhitespace ()
- {
- char c = 'a';
- while (pos < length && c != ' ' && c != '\t' && c != '\r' && c != '\n') {
- c = header [pos++];
- }
- pos--;
- }
-
string GetKey ()
{
SkipWhitespace ();
}
value = header.Substring (beginQ, pos - beginQ);
- pos += 2;
+ pos += useQuote ? 2 : 1;
return true;
}
}
// 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;
}
{
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);
}
lastUse = DateTime.Now;
NetworkCredential cred = credentials.GetCredential (request.RequestUri, "digest");
+ if (cred == null)
+ return null;
+
string userName = cred.UserName;
if (userName == null || userName == "")
return null;
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) {
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;
}
}
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)