/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* DigestAuthentication: Encapsulate an http server authentication using
* the "Digest" scheme, as described in RFC2069 and updated in RFC2617
*
* @author Bill Foote
*/
// Authentication parameters defined in RFC2617.
// One instance of these may be shared among several DigestAuthentication
// instances as a result of a single authorization (for multiple domains)
// The H(A1) string used for MD5-sess
// Force the HA1 value to be recalculated because the nonce has changed
private boolean redoCachedHA1 = true;
static {
}
Parameters () {
serverQop = false;
setNewCnonce();
}
boolean authQop () {
return serverQop;
}
synchronized void incrementNC() {
NCcount ++;
}
synchronized int getNCCount () {
return NCcount;
}
/* each call increments the counter */
if (cnonce_count >= cnonceRepeat) {
setNewCnonce();
}
cnonce_count++;
return cnonce;
}
synchronized void setNewCnonce () {
int x = bb[i] + 128;
}
cnonce_count = 0;
redoCachedHA1 = true;
}
while (st.hasMoreTokens()) {
serverQop = true;
return;
}
}
}
serverQop = false;
}
nonce=s;
NCcount = 0;
redoCachedHA1 = true;
}
}
if (redoCachedHA1) {
return null;
} else {
return cachedHA1;
}
}
cachedHA1=s;
redoCachedHA1=false;
}
}
/**
* Create a DigestAuthentication
*/
Parameters params) {
url,
realm);
this.authMethod = authMethod;
}
Parameters params) {
host,
port,
realm);
this.authMethod = authMethod;
}
/**
* @return true if this authentication supports preemptive authorization
*/
public boolean supportsPreemptiveAuthorization() {
return true;
}
/**
* Reclaculates the request-digest and returns it.
*
* <P> Used in the common case where the requestURI is simply the
* abs_path.
*
* @param url
* the URL
*
* @param method
* the HTTP method
*
* @return the value of the HTTP header this authentication wants set
*/
}
/**
* Reclaculates the request-digest and returns it.
*
* <P> Used when the requestURI is not the abs_path. The exact
* requestURI can be passed as a String.
*
* @param requestURI
* the Request-URI from the HTTP request line
*
* @param method
* the HTTP method
*
* @return the value of the HTTP header this authentication wants set
*/
}
/**
* Check if the header indicates that the current auth. parameters are stale.
* If so, then replace the relevant field with the new value
* and return true. Otherwise return false.
* returning false means we have to go back to the user to ask for a new
* username password.
*/
return false;
return false;
}
return true;
}
/**
* Set header(s) on the given connection.
* @param conn The connection to apply the header(s) to
* @param p A source of header values for this connection, if needed.
* @param raw Raw header values for this connection, if needed.
* @return true if all goes well, false if no headers were set.
*/
if (type == PROXY_AUTHENTICATION &&
} else {
try {
} catch (IOException e) {}
}
return false;
}
// Method seems to get converted to all lower case elsewhere.
// It really does need to start with an upper case letter
// here.
}
}
// If authQop is true, then the server is doing RFC2617 and
// has offered qop=auth. We do not support any other modes
// and if auth is not offered we fallback to the RFC2069 behavior
}
return true;
} else {
return false;
}
}
/* Calculate the Authorization header field given the request URI
* and based on the authorization information in params
*/
params.incrementNC ();
if (nccount != -1) {
if (len < 8)
}
try {
} catch (NoSuchAlgorithmException ex) {
return null;
}
if (qop) {
}
+ "\", realm=\"" + realm
+ "\", nonce=\"" + nonce
+ ncfield
+ ", uri=\"" + uri
+ "\", response=\"" + response
+ "\", algorithm=\"" + algorithm;
}
}
if (qop) {
}
return value;
}
throws IOException {
}
throws IOException {
throw new ProtocolException ("No authentication information in response");
}
if (nccount != -1) {
if (len < 8)
}
try {
throw new ProtocolException ("No digest in response");
}
throw new ProtocolException ("Response digest invalid");
}
/* Check if there is a nextnonce field */
}
} catch (NoSuchAlgorithmException ex) {
throw new ProtocolException ("Unsupported algorithm in response");
}
}
) throws NoSuchAlgorithmException
{
if (md5sess) {
}
} else {
}
if (isRequest) {
} else {
}
} else { /* for compatibility with RFC2069 */
nonceString + ":" +
}
return finalHash;
}
private final static char charArray[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
// 0 1 2 3 4 5 6 7
"00000000", "0000000", "000000", "00000", "0000", "000", "00", "0"
};
try {
assert false;
}
passwdBytes[i] = (byte)passwd[i];
}
}
}
}