use of sugar.free.sightparser.authlayer.VerifyDisplayRequest in project SightRemote by TebbeUbben.
the class PairingEstablisher method onInboundMessage.
@Override
public void onInboundMessage(Object message, final Pipeline pipeline) throws Exception {
if (message instanceof ConnectionResponse) {
KeyRequest keyRequest = new KeyRequest();
keyRequest.setRandomBytes(getRandomBytes());
keyRequest.setPreMasterKey(keyToBytes(getKeyPair().getPublicKey()));
pipeline.setStatus(Status.EXCHANGING_KEYS);
pipeline.send(keyRequest);
} else if (message instanceof KeyResponse) {
KeyResponse keyResponse = (KeyResponse) message;
pipeline.setDerivedKeys(Cryptograph.deriveKeys(Cryptograph.decryptRSA(getKeyPair().getPrivateKey(), keyResponse.getPreMasterSecret()), getRandomBytes(), keyResponse.getRandomData()));
VerifyDisplayRequest verifyDisplayRequest = new VerifyDisplayRequest();
pipeline.setStatus(Status.WAITING_FOR_CODE_CONFIRMATION);
pipeline.send(verifyDisplayRequest);
} else if (message instanceof VerifyDisplayResponse) {
VerifyConfirmRequest verifyConfirmRequest = new VerifyConfirmRequest();
verifyConfirmRequest.setPairingStatus(PairingStatus.CONFIRMED);
pipeline.send(verifyConfirmRequest);
} else if (message instanceof VerifyConfirmResponse) {
VerifyConfirmResponse verifyConfirmResponse = (VerifyConfirmResponse) message;
PairingStatus pairingStatus = verifyConfirmResponse.getPairingStatus();
if (pairingStatus == PairingStatus.REJECTED) {
pipeline.setStatus(Status.CODE_REJECTED);
throw new DisconnectedError();
} else if (pairingStatus == PairingStatus.CONFIRMED) {
pipeline.setStatus(Status.APP_BINDING);
pipeline.send(new BindMessage());
} else if (pairingStatus == PairingStatus.PENDING) {
timer.schedule(new TimerTask() {
@Override
public void run() {
VerifyConfirmRequest verifyConfirmRequest = new VerifyConfirmRequest();
verifyConfirmRequest.setPairingStatus(PairingStatus.CONFIRMED);
pipeline.send(verifyConfirmRequest);
}
}, 2000);
}
} else if (message instanceof BindMessage) {
pipeline.setStatus(Status.CONNECTED);
}
}
Aggregations