private void doSparkAuth(TransportClient client, Channel channel) throws GeneralSecurityException, IOException { String secretKey = secretKeyHolder.getSecretKey(appId); try (AuthEngine engine = new AuthEngine(appId, secretKey, conf)) { ClientChallenge challenge = engine.challenge(); ByteBuf challengeData = Unpooled.buffer(challenge.encodedLength()); challenge.encode(challengeData); ByteBuffer responseData = client.sendRpcSync(challengeData.nioBuffer(), conf.authRTTimeoutMs()); ServerResponse response = ServerResponse.decodeMessage(responseData); engine.validate(response); engine.sessionCipher().addToChannel(channel); } }
private void doSparkAuth(TransportClient client, Channel channel) throws GeneralSecurityException, IOException { String secretKey = secretKeyHolder.getSecretKey(appId); try (AuthEngine engine = new AuthEngine(appId, secretKey, conf)) { ClientChallenge challenge = engine.challenge(); ByteBuf challengeData = Unpooled.buffer(challenge.encodedLength()); challenge.encode(challengeData); ByteBuffer responseData = client.sendRpcSync(challengeData.nioBuffer(), conf.authRTTimeoutMs()); ServerResponse response = ServerResponse.decodeMessage(responseData); engine.validate(response); engine.sessionCipher().addToChannel(channel); } }
private void doSparkAuth(TransportClient client, Channel channel) throws GeneralSecurityException, IOException { String secretKey = secretKeyHolder.getSecretKey(appId); try (AuthEngine engine = new AuthEngine(appId, secretKey, conf)) { ClientChallenge challenge = engine.challenge(); ByteBuf challengeData = Unpooled.buffer(challenge.encodedLength()); challenge.encode(challengeData); ByteBuffer responseData = client.sendRpcSync(challengeData.nioBuffer(), conf.authRTTimeoutMs()); ServerResponse response = ServerResponse.decodeMessage(responseData); engine.validate(response); engine.sessionCipher().addToChannel(channel); } }
@Test public void testServerResponse() { ServerResponse msg = new ServerResponse(byteArray(), byteArray(), byteArray(), byteArray()); ServerResponse decoded = ServerResponse.decodeMessage(encode(msg)); assertTrue(Arrays.equals(msg.response, decoded.response)); assertTrue(Arrays.equals(msg.nonce, decoded.nonce)); assertTrue(Arrays.equals(msg.inputIv, decoded.inputIv)); assertTrue(Arrays.equals(msg.outputIv, decoded.outputIv)); }
@Test public void testServerResponse() { ServerResponse msg = new ServerResponse(byteArray(), byteArray(), byteArray(), byteArray()); ServerResponse decoded = ServerResponse.decodeMessage(encode(msg)); assertTrue(Arrays.equals(msg.response, decoded.response)); assertTrue(Arrays.equals(msg.nonce, decoded.nonce)); assertTrue(Arrays.equals(msg.inputIv, decoded.inputIv)); assertTrue(Arrays.equals(msg.outputIv, decoded.outputIv)); }