io.undertow.security.impl.DigestQop Java Examples

The following examples show how to use io.undertow.security.impl.DigestQop. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParseDigestAuthorizationTokenTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Test
public void testChrome_22() {
    final String header = "username=\"userTwo\", realm=\"Digest_Realm\", nonce=\"Yxmkh5liIOYNMTM1MTUyNjQzMTE4NJziT7YLEOEJ4QEN1py4Yog=\", uri=\"/\", algorithm=MD5, response=\"5b26e00233607e8a714cd1d910692e08\", opaque=\"00000000000000000000000000000000\", qop=auth, nc=00000001, cnonce=\"8c008c8ce43dc0a7\"";

    Map<DigestAuthorizationToken, String> expected = new EnumMap<>(DigestAuthorizationToken.class);
    expected.put(DigestAuthorizationToken.USERNAME, "userTwo");
    expected.put(DigestAuthorizationToken.REALM, "Digest_Realm");
    expected.put(DigestAuthorizationToken.NONCE, "Yxmkh5liIOYNMTM1MTUyNjQzMTE4NJziT7YLEOEJ4QEN1py4Yog=");
    expected.put(DigestAuthorizationToken.DIGEST_URI, "/");
    expected.put(DigestAuthorizationToken.ALGORITHM, DigestAlgorithm.MD5.getToken());
    expected.put(DigestAuthorizationToken.RESPONSE, "5b26e00233607e8a714cd1d910692e08");
    expected.put(DigestAuthorizationToken.OPAQUE, "00000000000000000000000000000000");
    expected.put(DigestAuthorizationToken.MESSAGE_QOP, DigestQop.AUTH.getToken());
    expected.put(DigestAuthorizationToken.NONCE_COUNT, "00000001");
    expected.put(DigestAuthorizationToken.CNONCE, "8c008c8ce43dc0a7");

    doTest(header, expected);
}
 
Example #2
Source File: ParseDigestAuthorizationTokenTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Test
public void testCurl_7() {
    final String header = "username=\"userTwo\", realm=\"Digest_Realm\", nonce=\"5CgZ39vhie0NMTM1MTUyNDc4ODkwNMwr6sWKVSGfhXB4jBtkupY=\", uri=\"/\", cnonce=\"MTYwOTQ4\", nc=00000001, qop=\"auth\", response=\"c3c1ce9945a0c36d54860eda7846018b\", opaque=\"00000000000000000000000000000000\", algorithm=\"MD5\"";

    Map<DigestAuthorizationToken, String> expected = new EnumMap<>(DigestAuthorizationToken.class);
    expected.put(DigestAuthorizationToken.USERNAME, "userTwo");
    expected.put(DigestAuthorizationToken.REALM, "Digest_Realm");
    expected.put(DigestAuthorizationToken.NONCE, "5CgZ39vhie0NMTM1MTUyNDc4ODkwNMwr6sWKVSGfhXB4jBtkupY=");
    expected.put(DigestAuthorizationToken.DIGEST_URI, "/");
    expected.put(DigestAuthorizationToken.CNONCE, "MTYwOTQ4");
    expected.put(DigestAuthorizationToken.NONCE_COUNT, "00000001");
    expected.put(DigestAuthorizationToken.MESSAGE_QOP, DigestQop.AUTH.getToken());
    expected.put(DigestAuthorizationToken.RESPONSE, "c3c1ce9945a0c36d54860eda7846018b");
    expected.put(DigestAuthorizationToken.OPAQUE, "00000000000000000000000000000000");
    expected.put(DigestAuthorizationToken.ALGORITHM, DigestAlgorithm.MD5.getToken());

    doTest(header, expected);
}
 
Example #3
Source File: ParseDigestAuthorizationTokenTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Test
public void testFirefox_16() {
    final String header = "username=\"userOne\", realm=\"Digest_Realm\", nonce=\"nBhFxtSS6rkNMTM1MTUyNjE2MjgyNWA/xW/LOH53vhXGq/2B/yQ=\", uri=\"/\", algorithm=MD5, response=\"b0adb1025da2de0d16f44131858bad6f\", opaque=\"00000000000000000000000000000000\", qop=auth, nc=00000001, cnonce=\"8127726535363b07\"";

    Map<DigestAuthorizationToken, String> expected = new EnumMap<>(DigestAuthorizationToken.class);
    expected.put(DigestAuthorizationToken.USERNAME, "userOne");
    expected.put(DigestAuthorizationToken.REALM, "Digest_Realm");
    expected.put(DigestAuthorizationToken.NONCE, "nBhFxtSS6rkNMTM1MTUyNjE2MjgyNWA/xW/LOH53vhXGq/2B/yQ=");
    expected.put(DigestAuthorizationToken.DIGEST_URI, "/");
    expected.put(DigestAuthorizationToken.ALGORITHM, DigestAlgorithm.MD5.getToken());
    expected.put(DigestAuthorizationToken.RESPONSE, "b0adb1025da2de0d16f44131858bad6f");
    expected.put(DigestAuthorizationToken.OPAQUE, "00000000000000000000000000000000");
    expected.put(DigestAuthorizationToken.MESSAGE_QOP, DigestQop.AUTH.getToken());
    expected.put(DigestAuthorizationToken.NONCE_COUNT, "00000001");
    expected.put(DigestAuthorizationToken.CNONCE, "8127726535363b07");

    doTest(header, expected);
}
 
Example #4
Source File: ParseDigestAuthorizationTokenTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Test
public void testOpera_12() {
    final String header = "username=\"userOne\", realm=\"Digest_Realm\", uri=\"/\", algorithm=MD5, nonce=\"D2floAc+FhkNMTM1MTUyMzY2ODc4Mhbi2Zrcuv1lvdgEaPXa+bg=\", cnonce=\"v722VYJEeG28C3SoXS8BEWThGHPDOlXgUCCts70i7Fc=\", opaque=\"00000000000000000000000000000000\", qop=auth, nc=00000001, response=\"8106a5d19bc67982527cbb576658f9d6\"";

    Map<DigestAuthorizationToken, String> expected = new EnumMap<>(DigestAuthorizationToken.class);
    expected.put(DigestAuthorizationToken.USERNAME, "userOne");
    expected.put(DigestAuthorizationToken.REALM, "Digest_Realm");
    expected.put(DigestAuthorizationToken.DIGEST_URI, "/");
    expected.put(DigestAuthorizationToken.ALGORITHM, DigestAlgorithm.MD5.getToken());
    expected.put(DigestAuthorizationToken.NONCE, "D2floAc+FhkNMTM1MTUyMzY2ODc4Mhbi2Zrcuv1lvdgEaPXa+bg=");
    expected.put(DigestAuthorizationToken.CNONCE, "v722VYJEeG28C3SoXS8BEWThGHPDOlXgUCCts70i7Fc=");
    expected.put(DigestAuthorizationToken.OPAQUE, "00000000000000000000000000000000");
    expected.put(DigestAuthorizationToken.MESSAGE_QOP, DigestQop.AUTH.getToken());
    expected.put(DigestAuthorizationToken.NONCE_COUNT, "00000001");
    expected.put(DigestAuthorizationToken.RESPONSE, "8106a5d19bc67982527cbb576658f9d6");

    doTest(header, expected);
}
 
Example #5
Source File: DigestAuthenticationAuthTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
private static String createAuthorizationLine(final String userName, final String password, final String method, final String uri,
        final String nonce, final int nonceCount, final String cnonce, final String opaque) throws Exception {
    StringBuilder sb = new StringBuilder(DIGEST.toString());
    sb.append(" ");
    sb.append(DigestAuthorizationToken.USERNAME.getName()).append("=").append("\"userOne\"").append(",");
    sb.append(DigestAuthorizationToken.REALM.getName()).append("=\"").append(REALM_NAME).append("\",");
    sb.append(DigestAuthorizationToken.NONCE.getName()).append("=\"").append(nonce).append("\",");
    sb.append(DigestAuthorizationToken.DIGEST_URI.getName()).append("=\"" + uri + "\",");
    String nonceCountHex = toHex(nonceCount);
    String response = createResponse(userName, REALM_NAME, password, method, uri, nonce, nonceCountHex, cnonce);
    sb.append(DigestAuthorizationToken.RESPONSE.getName()).append("=\"").append(response).append("\",");
    sb.append(DigestAuthorizationToken.ALGORITHM.getName()).append("=\"").append(DigestAlgorithm.MD5.getToken())
            .append("\",");
    sb.append(DigestAuthorizationToken.CNONCE.getName()).append("=\"").append(cnonce).append("\",");
    sb.append(DigestAuthorizationToken.OPAQUE.getName()).append("=\"").append(opaque).append("\",");
    sb.append(DigestAuthorizationToken.MESSAGE_QOP.getName()).append("=\"").append(DigestQop.AUTH.getToken()).append("\",");
    sb.append(DigestAuthorizationToken.NONCE_COUNT.getName()).append("=").append(nonceCountHex);

    return sb.toString();
}
 
Example #6
Source File: DigestAuthentication2069TestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AuthenticationMechanism> getTestMechanisms() {
    List<DigestQop> qopList = Collections.emptyList();
    AuthenticationMechanism mechanism = new DigestAuthenticationMechanism(Collections.singletonList(DigestAlgorithm.MD5),
            qopList, REALM_NAME, "/", new SimpleNonceManager());

    return Collections.singletonList(mechanism);
}
 
Example #7
Source File: DigestAuthenticationAuthTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a response value from the supplied parameters.
 *
 * @return The generated Hex encoded MD5 digest based response.
 */
private static String createResponse(final String userName, final String realm, final String password, final String method,
        final String uri, final String nonce, final String nonceCount, final String cnonce) throws Exception {
    MessageDigest digest = MessageDigest.getInstance("MD5");
    digest.update(userName.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(realm.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(password.getBytes(UTF_8));

    byte[] ha1 = HexConverter.convertToHexBytes(digest.digest());

    digest.update(method.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(uri.getBytes(UTF_8));

    byte[] ha2 = HexConverter.convertToHexBytes(digest.digest());

    digest.update(ha1);
    digest.update((byte) ':');
    digest.update(nonce.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(nonceCount.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(cnonce.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(DigestQop.AUTH.getToken().getBytes(UTF_8));
    digest.update((byte) ':');

    digest.update(ha2);

    return HexConverter.convertToHexString(digest.digest());
}
 
Example #8
Source File: DigestAuthenticationAuthTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
private static String createRspAuth(final String userName, final String realm, final String password, final String uri,
        final String nonce, final String nonceCount, final String cnonce) throws Exception {
    MessageDigest digest = MessageDigest.getInstance("MD5");
    digest.update(userName.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(realm.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(password.getBytes(UTF_8));

    byte[] ha1 = HexConverter.convertToHexBytes(digest.digest());

    digest.update((byte) ':');
    digest.update(uri.getBytes(UTF_8));

    byte[] ha2 = HexConverter.convertToHexBytes(digest.digest());

    digest.update(ha1);
    digest.update((byte) ':');
    digest.update(nonce.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(nonceCount.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(cnonce.getBytes(UTF_8));
    digest.update((byte) ':');
    digest.update(DigestQop.AUTH.getToken().getBytes(UTF_8));
    digest.update((byte) ':');

    digest.update(ha2);

    return HexConverter.convertToHexString(digest.digest());
}
 
Example #9
Source File: LogoutHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public LogoutHandler(final String realmName) {
    List<DigestAlgorithm> digestAlgorithms = Collections.singletonList(DigestAlgorithm.MD5);
    List<DigestQop> digestQops = Collections.emptyList();
    digestMechanism = new DigestAuthenticationMechanism(digestAlgorithms, digestQops, realmName, "/management",
            new SimpleNonceManager());
    fakeRealmdigestMechanism = new DigestAuthenticationMechanism(digestAlgorithms, digestQops, HIT_ESCAPE,
            "/management", new SimpleNonceManager());
    basicMechanism = new BasicAuthenticationMechanism(realmName);
    fakeRealmBasicMechanism = new BasicAuthenticationMechanism(HIT_ESCAPE);
}
 
Example #10
Source File: DigestAuthenticationAuthTestCase.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
static AuthenticationMechanism getTestMechanism() {
    return new DigestAuthenticationMechanism(Collections.singletonList(DigestAlgorithm.MD5),
            Collections.singletonList(DigestQop.AUTH), REALM_NAME, "/", new SimpleNonceManager());
}