private String newClientNonce() { Random random = new Random(); byte[] bytes = new byte[8]; random.nextBytes(bytes); return toHexString(bytes); }
String hashA1 = toHexString(digester.digest(A1.getBytes(charset))); A2 += ":" + toHexString(digester.digest(content)); String hashA2 = toHexString(digester.digest(A2.getBytes(charset))); if (qop != null) nonceCount = nextNonceCount(); clientNonce = newClientNonce(); A3 = hashA1 + ":" + nonce + ":" + nonceCount + ":" + clientNonce + ":" + qop + ":" + hashA2; A3 = hashA1 + ":" + nonce + ":" + hashA2; String hashA3 = toHexString(digester.digest(A3.getBytes(charset)));
String hashA1 = toHexString(digester.digest(A1.getBytes(charset))); A2 += ":" + toHexString(digester.digest(content)); String hashA2 = toHexString(digester.digest(A2.getBytes(charset))); if (qop != null) nonceCount = nextNonceCount(); clientNonce = newClientNonce(); A3 = hashA1 + ":" + nonce + ":" + nonceCount + ":" + clientNonce + ":" + qop + ":" + hashA2; A3 = hashA1 + ":" + nonce + ":" + hashA2; String hashA3 = toHexString(digester.digest(A3.getBytes(charset)));
String hashA1 = toHexString(digester.digest(A1.getBytes(StandardCharsets.ISO_8859_1))); String A2 = request.getMethod() + ":" + uri; if ("auth-int".equals(qop)) A2 += ":" + toHexString(digester.digest(content)); String hashA2 = toHexString(digester.digest(A2.getBytes(StandardCharsets.ISO_8859_1))); if (qop != null) nonceCount = nextNonceCount(); clientNonce = newClientNonce(); A3 = hashA1 + ":" + nonce + ":" + nonceCount + ":" + clientNonce + ":" + qop + ":" + hashA2; A3 = hashA1 + ":" + nonce + ":" + hashA2; String hashA3 = toHexString(digester.digest(A3.getBytes(StandardCharsets.ISO_8859_1)));
@Override public Result authenticate(Request request, ContentResponse response, String wwwAuthenticate, Attributes context) { // Avoid case sensitivity problems on the 'D' character String type = "igest"; wwwAuthenticate = wwwAuthenticate.substring(wwwAuthenticate.indexOf(type) + type.length()); Map<String, String> params = parseParams(wwwAuthenticate); String nonce = params.get("nonce"); if (nonce == null || nonce.length() == 0) return null; String opaque = params.get("opaque"); String algorithm = params.get("algorithm"); if (algorithm == null) algorithm = "MD5"; MessageDigest digester = getMessageDigest(algorithm); if (digester == null) return null; String serverQOP = params.get("qop"); String clientQOP = null; if (serverQOP != null) { List<String> serverQOPValues = Arrays.asList(serverQOP.split(",")); if (serverQOPValues.contains("auth")) clientQOP = "auth"; else if (serverQOPValues.contains("auth-int")) clientQOP = "auth-int"; } return new DigestResult(request.getURI(), response.getContent(), realm, user, password, algorithm, nonce, clientQOP, opaque); }
@Override public Result authenticate(Request request, ContentResponse response, String wwwAuthenticate, Attributes context) { // Avoid case sensitivity problems on the 'D' character String type = "igest"; wwwAuthenticate = wwwAuthenticate.substring(wwwAuthenticate.indexOf(type) + type.length()); Map<String, String> params = parseParams(wwwAuthenticate); String nonce = params.get("nonce"); if (nonce == null || nonce.length() == 0) return null; String opaque = params.get("opaque"); String algorithm = params.get("algorithm"); if (algorithm == null) algorithm = "MD5"; MessageDigest digester = getMessageDigest(algorithm); if (digester == null) return null; String serverQOP = params.get("qop"); String clientQOP = null; if (serverQOP != null) { List<String> serverQOPValues = Arrays.asList(serverQOP.split(",")); if (serverQOPValues.contains("auth")) clientQOP = "auth"; else if (serverQOPValues.contains("auth-int")) clientQOP = "auth-int"; } return new DigestResult(request.getURI(), response.getContent(), realm, user, password, algorithm, nonce, clientQOP, opaque); }
@Override public Result authenticate(Request request, ContentResponse response, HeaderInfo headerInfo, Attributes context) { Map<String, String> params = headerInfo.getParameters(); String nonce = params.get("nonce"); if (nonce == null || nonce.length() == 0) return null; String opaque = params.get("opaque"); String algorithm = params.get("algorithm"); if (algorithm == null) algorithm = "MD5"; MessageDigest digester = getMessageDigest(algorithm); if (digester == null) return null; String serverQOP = params.get("qop"); String clientQOP = null; if (serverQOP != null) { List<String> serverQOPValues = StringUtil.csvSplit(null,serverQOP,0,serverQOP.length()); if (serverQOPValues.contains("auth")) clientQOP = "auth"; else if (serverQOPValues.contains("auth-int")) clientQOP = "auth-int"; } String realm = getRealm(); if (ANY_REALM.equals(realm)) realm = headerInfo.getRealm(); return new DigestResult(headerInfo.getHeader(), response.getContent(), realm, user, password, algorithm, nonce, clientQOP, opaque); }
private String newClientNonce() { Random random = new Random(); byte[] bytes = new byte[8]; random.nextBytes(bytes); return toHexString(bytes); }
private String newClientNonce() { Random random = new Random(); byte[] bytes = new byte[8]; random.nextBytes(bytes); return toHexString(bytes); }