public static ClientChallenge decodeMessage(ByteBuffer buffer) { ByteBuf buf = Unpooled.wrappedBuffer(buffer); if (buf.readByte() != TAG_BYTE) { throw new IllegalArgumentException("Expected ClientChallenge, received something else."); } return new ClientChallenge( Encoders.Strings.decode(buf), Encoders.Strings.decode(buf), buf.readInt(), Encoders.Strings.decode(buf), buf.readInt(), Encoders.ByteArrays.decode(buf), Encoders.ByteArrays.decode(buf)); }
public static ClientChallenge decodeMessage(ByteBuffer buffer) { ByteBuf buf = Unpooled.wrappedBuffer(buffer); if (buf.readByte() != TAG_BYTE) { throw new IllegalArgumentException("Expected ClientChallenge, received something else."); } return new ClientChallenge( Encoders.Strings.decode(buf), Encoders.Strings.decode(buf), buf.readInt(), Encoders.Strings.decode(buf), buf.readInt(), Encoders.ByteArrays.decode(buf), Encoders.ByteArrays.decode(buf)); }
public static ClientChallenge decodeMessage(ByteBuffer buffer) { ByteBuf buf = Unpooled.wrappedBuffer(buffer); if (buf.readByte() != TAG_BYTE) { throw new IllegalArgumentException("Expected ClientChallenge, received something else."); } return new ClientChallenge( Encoders.Strings.decode(buf), Encoders.Strings.decode(buf), buf.readInt(), Encoders.Strings.decode(buf), buf.readInt(), Encoders.ByteArrays.decode(buf), Encoders.ByteArrays.decode(buf)); }
@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)); }
/** * Create the client challenge. * * @return A challenge to be sent the remote side. */ ClientChallenge challenge() throws GeneralSecurityException { this.authNonce = randomBytes(conf.encryptionKeyLength() / Byte.SIZE); SecretKeySpec authKey = generateKey(conf.keyFactoryAlgorithm(), conf.keyFactoryIterations(), authNonce, conf.encryptionKeyLength()); initializeForAuth(conf.cipherTransformation(), authNonce, authKey); this.challenge = randomBytes(conf.encryptionKeyLength() / Byte.SIZE); return new ClientChallenge(new String(appId, UTF_8), conf.keyFactoryAlgorithm(), conf.keyFactoryIterations(), conf.cipherTransformation(), conf.encryptionKeyLength(), authNonce, challenge(appId, authNonce, challenge)); }
/** * Create the client challenge. * * @return A challenge to be sent the remote side. */ ClientChallenge challenge() throws GeneralSecurityException { this.authNonce = randomBytes(conf.encryptionKeyLength() / Byte.SIZE); SecretKeySpec authKey = generateKey(conf.keyFactoryAlgorithm(), conf.keyFactoryIterations(), authNonce, conf.encryptionKeyLength()); initializeForAuth(conf.cipherTransformation(), authNonce, authKey); this.challenge = randomBytes(conf.encryptionKeyLength() / Byte.SIZE); return new ClientChallenge(new String(appId, UTF_8), conf.keyFactoryAlgorithm(), conf.keyFactoryIterations(), conf.cipherTransformation(), conf.encryptionKeyLength(), authNonce, challenge(appId, authNonce, challenge)); }
/** * Create the client challenge. * * @return A challenge to be sent the remote side. */ ClientChallenge challenge() throws GeneralSecurityException, IOException { this.authNonce = randomBytes(conf.encryptionKeyLength() / Byte.SIZE); SecretKeySpec authKey = generateKey(conf.keyFactoryAlgorithm(), conf.keyFactoryIterations(), authNonce, conf.encryptionKeyLength()); initializeForAuth(conf.cipherTransformation(), authNonce, authKey); this.challenge = randomBytes(conf.encryptionKeyLength() / Byte.SIZE); return new ClientChallenge(new String(appId, UTF_8), conf.keyFactoryAlgorithm(), conf.keyFactoryIterations(), conf.cipherTransformation(), conf.encryptionKeyLength(), authNonce, challenge(appId, authNonce, challenge)); }
@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 testClientChallenge() { ClientChallenge msg = new ClientChallenge(string(), string(), integer(), string(), integer(), byteArray(), byteArray()); ClientChallenge decoded = ClientChallenge.decodeMessage(encode(msg)); assertEquals(msg.appId, decoded.appId); assertEquals(msg.kdf, decoded.kdf); assertEquals(msg.iterations, decoded.iterations); assertEquals(msg.cipher, decoded.cipher); assertEquals(msg.keyLength, decoded.keyLength); assertTrue(Arrays.equals(msg.nonce, decoded.nonce)); assertTrue(Arrays.equals(msg.challenge, decoded.challenge)); }
@Test public void testClientChallenge() { ClientChallenge msg = new ClientChallenge(string(), string(), integer(), string(), integer(), byteArray(), byteArray()); ClientChallenge decoded = ClientChallenge.decodeMessage(encode(msg)); assertEquals(msg.appId, decoded.appId); assertEquals(msg.kdf, decoded.kdf); assertEquals(msg.iterations, decoded.iterations); assertEquals(msg.cipher, decoded.cipher); assertEquals(msg.keyLength, decoded.keyLength); assertTrue(Arrays.equals(msg.nonce, decoded.nonce)); assertTrue(Arrays.equals(msg.challenge, decoded.challenge)); }