if (qopVariant == QOP_AUTH_INT) {
throw new IOException(Messages.getString("DigestAuthentication.unsupportedQop")); //$NON-NLS-1$
}
Hash hash = new Hash(new MD5Digest());
// 3.2.2.2: Calculating digest
StringBuffer tmp = new StringBuffer(uname.length() + realm.length() + pwd.length() + 2);
tmp.append(uname);
tmp.append(':');
tmp.append(realm);
tmp.append(':');
tmp.append(pwd);
// unq(username-value) ":" unq(realm-value) ":" passwd
String a1 = tmp.toString();
// a1 is suitable for MD5 algorithm
if (algorithm.equals("MD5-sess")) { //$NON-NLS-1$
// H( unq(username-value) ":" unq(realm-value) ":" passwd )
// ":" unq(nonce-value)
// ":" unq(cnonce-value)
hash.putBytes(a1.getBytes("US-ASCII")); //$NON-NLS-1$
String tmp2 = encode(hash.doFinal());
StringBuffer tmp3 = new StringBuffer(tmp2.length() + nonce.length() + cnonce.length() + 2);
tmp3.append(tmp2);
tmp3.append(':');
tmp3.append(nonce);
tmp3.append(':');
tmp3.append(cnonce);
a1 = tmp3.toString();
} else if (!algorithm.equals("MD5")) { //$NON-NLS-1$
}
hash.reset();
hash.putBytes(a1.getBytes("US-ASCII")); //$NON-NLS-1$
String md5a1 = encode(hash.doFinal());
String a2 = null;
if (qopVariant == QOP_AUTH_INT) {
// we do not have access to the entity-body or its hash
// TODO: add Method ":" digest-uri-value ":" H(entity-body)
} else {
a2 = method + ":" + uri; //$NON-NLS-1$
}
hash.reset();
hash.putBytes(a2.getBytes("US-ASCII")); //$NON-NLS-1$
String md5a2 = encode(hash.doFinal());
// 3.2.2.1
String serverDigestValue;
if (qopVariant == QOP_MISSING) {
StringBuffer tmp2 = new StringBuffer(md5a1.length() + nonce.length() + md5a2.length());
tmp2.append(md5a1);
tmp2.append(':');
tmp2.append(nonce);
tmp2.append(':');
tmp2.append(md5a2);
serverDigestValue = tmp2.toString();
} else {
String qopOption = getQopVariantString();
StringBuffer tmp2 = new StringBuffer(md5a1.length() + nonce.length() + NC.length() + cnonce.length()
+ qopOption.length() + md5a2.length() + 5);
tmp2.append(md5a1);
tmp2.append(':');
tmp2.append(nonce);
tmp2.append(':');
tmp2.append(NC);
tmp2.append(':');
tmp2.append(cnonce);
tmp2.append(':');
tmp2.append(qopOption);
tmp2.append(':');
tmp2.append(md5a2);
serverDigestValue = tmp2.toString();
}
hash.reset();
hash.putBytes(serverDigestValue.getBytes("US-ASCII")); //$NON-NLS-1$
String serverDigest = encode(hash.doFinal());
return serverDigest;
}