@Test public void testStrongDigest() throws Exception { String user = "user"; String pass = "pass"; String realm = "realm"; String nonce = "nonce"; String method = "GET"; Uri uri = Uri.create("http://ahc.io/foo"); String qop = "auth"; Realm orig = digestAuthRealm(user, pass) .setNonce(nonce) .setUri(uri) .setMethodName(method) .setRealmName(realm) .setQop(qop) .build(); String nc = orig.getNc(); String cnonce = orig.getCnonce(); String ha1 = getMd5(user + ":" + realm + ":" + pass); String ha2 = getMd5(method + ":" + uri.getPath()); String expectedResponse = getMd5(ha1 + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + ha2); assertEquals(orig.getResponse(), expectedResponse); }
private void testOldDigest(String qop) throws Exception { String user = "user"; String pass = "pass"; String realm = "realm"; String nonce = "nonce"; String method = "GET"; Uri uri = Uri.create("http://ahc.io/foo"); Realm orig = digestAuthRealm(user, pass) .setNonce(nonce) .setUri(uri) .setMethodName(method) .setRealmName(realm) .setQop(qop) .build(); String ha1 = getMd5(user + ":" + realm + ":" + pass); String ha2 = getMd5(method + ":" + uri.getPath()); String expectedResponse = getMd5(ha1 + ":" + nonce + ":" + ha2); assertEquals(orig.getResponse(), expectedResponse); }
public static Realm.Builder realm(Realm prototype) { return new Realm.Builder(prototype.getPrincipal(), prototype.getPassword()) .setRealmName(prototype.getRealmName()) .setAlgorithm(prototype.getAlgorithm()) .setNc(prototype.getNc()) .setNonce(prototype.getNonce()) .setCharset(prototype.getCharset()) .setOpaque(prototype.getOpaque()) .setQop(prototype.getQop()) .setScheme(prototype.getScheme()) .setUri(prototype.getUri()) .setUsePreemptiveAuth(prototype.isUsePreemptiveAuth()) .setNtlmDomain(prototype.getNtlmDomain()) .setNtlmHost(prototype.getNtlmHost()) .setUseAbsoluteURI(prototype.isUseAbsoluteURI()) .setOmitQuery(prototype.isOmitQuery()) .setServicePrincipalName(prototype.getServicePrincipalName()) .setUseCanonicalHostname(prototype.isUseCanonicalHostname()) .setCustomLoginConfig(prototype.getCustomLoginConfig()) .setLoginContextName(prototype.getLoginContextName()); }
protected Future<Response> execute(AsyncHttpClient client, boolean basic, boolean preemptive) { Realm.Builder realm; String url; if (basic) { realm = basicAuthRealm(USER, ADMIN); url = getTargetUrl(); } else { realm = digestAuthRealm(USER, ADMIN); url = getTargetUrl2(); if (preemptive) { realm.setRealmName("MyRealm"); realm.setAlgorithm("MD5"); realm.setQop("auth"); realm.setNonce("fFDVc60re9zt8fFDvht0tNrYuvqrcchN"); } } return client.prepareGet(url).setRealm(realm.setUsePreemptiveAuth(preemptive).build()).execute(); }
public Builder parseWWWAuthenticateHeader(String headerLine) { setRealmName(match(headerLine, "realm")) .setNonce(match(headerLine, "nonce")) .setOpaque(match(headerLine, "opaque")) .setScheme(isNonEmpty(nonce) ? AuthScheme.DIGEST : AuthScheme.BASIC); String algorithm = match(headerLine, "algorithm"); if (isNonEmpty(algorithm)) { setAlgorithm(algorithm); } // FIXME qop is different with proxy? String rawQop = match(headerLine, "qop"); if (rawQop != null) { setQop(parseRawQop(rawQop)); } return this; }
public Builder parseProxyAuthenticateHeader(String headerLine) { setRealmName(match(headerLine, "realm")) .setNonce(match(headerLine, "nonce")) .setOpaque(match(headerLine, "opaque")) .setScheme(isNonEmpty(nonce) ? AuthScheme.DIGEST : AuthScheme.BASIC); String algorithm = match(headerLine, "algorithm"); if (isNonEmpty(algorithm)) { setAlgorithm(algorithm); } // FIXME qop is different with proxy? setQop(match(headerLine, "qop")); return this; }