LOG.debug("Authenticating challenge for app {}.", challenge.appId); engine = new AuthEngine(challenge.appId, secret, conf); ServerResponse response = engine.respond(challenge); ByteBuf responseData = Unpooled.buffer(response.encodedLength()); response.encode(responseData);
LOG.debug("Authenticating challenge for app {}.", challenge.appId); engine = new AuthEngine(challenge.appId, secret, conf); ServerResponse response = engine.respond(challenge); ByteBuf responseData = Unpooled.buffer(response.encodedLength()); response.encode(responseData);
LOG.debug("Authenticating challenge for app {}.", challenge.appId); engine = new AuthEngine(challenge.appId, secret, conf); ServerResponse response = engine.respond(challenge); ByteBuf responseData = Unpooled.buffer(response.encodedLength()); response.encode(responseData);
@Test(expected = IllegalArgumentException.class) public void testBadChallenge() throws Exception { AuthEngine engine = new AuthEngine("appId", "secret", conf); ClientChallenge challenge = engine.challenge(); byte[] badChallenge = new byte[challenge.challenge.length]; engine.respond(new ClientChallenge(challenge.appId, challenge.kdf, challenge.iterations, challenge.cipher, challenge.keyLength, challenge.nonce, badChallenge)); }
@Test(expected = IllegalArgumentException.class) public void testBadChallenge() throws Exception { AuthEngine engine = new AuthEngine("appId", "secret", conf); ClientChallenge challenge = engine.challenge(); byte[] badChallenge = new byte[challenge.challenge.length]; engine.respond(new ClientChallenge(challenge.appId, challenge.kdf, challenge.iterations, challenge.cipher, challenge.keyLength, challenge.nonce, badChallenge)); }
@Test(expected = IllegalArgumentException.class) public void testWrongNonce() throws Exception { AuthEngine engine = new AuthEngine("appId", "secret", conf); ClientChallenge challenge = engine.challenge(); byte[] badChallenge = engine.challenge(challenge.appId.getBytes(UTF_8), new byte[] { 0x00 }, engine.rawResponse(engine.challenge)); engine.respond(new ClientChallenge(challenge.appId, challenge.kdf, challenge.iterations, challenge.cipher, challenge.keyLength, challenge.nonce, badChallenge)); }
@Test(expected = IllegalArgumentException.class) public void testWrongNonce() throws Exception { AuthEngine engine = new AuthEngine("appId", "secret", conf); ClientChallenge challenge = engine.challenge(); byte[] badChallenge = engine.challenge(challenge.appId.getBytes(UTF_8), new byte[] { 0x00 }, engine.rawResponse(engine.challenge)); engine.respond(new ClientChallenge(challenge.appId, challenge.kdf, challenge.iterations, challenge.cipher, challenge.keyLength, challenge.nonce, badChallenge)); }
@Test public void testMismatchedSecret() throws Exception { AuthEngine client = new AuthEngine("appId", "secret", conf); AuthEngine server = new AuthEngine("appId", "different_secret", conf); ClientChallenge clientChallenge = client.challenge(); try { server.respond(clientChallenge); fail("Should have failed to validate response."); } catch (IllegalArgumentException e) { // Expected. } }
@Test public void testMismatchedSecret() throws Exception { AuthEngine client = new AuthEngine("appId", "secret", conf); AuthEngine server = new AuthEngine("appId", "different_secret", conf); ClientChallenge clientChallenge = client.challenge(); try { server.respond(clientChallenge); fail("Should have failed to validate response."); } catch (IllegalArgumentException e) { // Expected. } }
@Test(expected = IllegalArgumentException.class) public void testWrongAppId() throws Exception { AuthEngine engine = new AuthEngine("appId", "secret", conf); ClientChallenge challenge = engine.challenge(); byte[] badChallenge = engine.challenge(new byte[] { 0x00 }, challenge.nonce, engine.rawResponse(engine.challenge)); engine.respond(new ClientChallenge(challenge.appId, challenge.kdf, challenge.iterations, challenge.cipher, challenge.keyLength, challenge.nonce, badChallenge)); }
@Test(expected = IllegalArgumentException.class) public void testWrongAppId() throws Exception { AuthEngine engine = new AuthEngine("appId", "secret", conf); ClientChallenge challenge = engine.challenge(); byte[] badChallenge = engine.challenge(new byte[] { 0x00 }, challenge.nonce, engine.rawResponse(engine.challenge)); engine.respond(new ClientChallenge(challenge.appId, challenge.kdf, challenge.iterations, challenge.cipher, challenge.keyLength, challenge.nonce, badChallenge)); }
@Test public void testAuthEngine() throws Exception { AuthEngine client = new AuthEngine("appId", "secret", conf); AuthEngine server = new AuthEngine("appId", "secret", conf); try { ClientChallenge clientChallenge = client.challenge(); ServerResponse serverResponse = server.respond(clientChallenge); client.validate(serverResponse); TransportCipher serverCipher = server.sessionCipher(); TransportCipher clientCipher = client.sessionCipher(); assertTrue(Arrays.equals(serverCipher.getInputIv(), clientCipher.getOutputIv())); assertTrue(Arrays.equals(serverCipher.getOutputIv(), clientCipher.getInputIv())); assertEquals(serverCipher.getKey(), clientCipher.getKey()); } finally { client.close(); server.close(); } }
@Test public void testAuthEngine() throws Exception { AuthEngine client = new AuthEngine("appId", "secret", conf); AuthEngine server = new AuthEngine("appId", "secret", conf); try { ClientChallenge clientChallenge = client.challenge(); ServerResponse serverResponse = server.respond(clientChallenge); client.validate(serverResponse); TransportCipher serverCipher = server.sessionCipher(); TransportCipher clientCipher = client.sessionCipher(); assertTrue(Arrays.equals(serverCipher.getInputIv(), clientCipher.getOutputIv())); assertTrue(Arrays.equals(serverCipher.getOutputIv(), clientCipher.getInputIv())); assertEquals(serverCipher.getKey(), clientCipher.getKey()); } finally { client.close(); server.close(); } }