Search in sources :

Example 1 with VerifyConfirmResponse

use of sugar.free.sightparser.authlayer.VerifyConfirmResponse 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);
    }
}
Also used : PairingStatus(sugar.free.sightparser.authlayer.PairingStatus) KeyResponse(sugar.free.sightparser.authlayer.KeyResponse) TimerTask(java.util.TimerTask) VerifyDisplayResponse(sugar.free.sightparser.authlayer.VerifyDisplayResponse) VerifyConfirmRequest(sugar.free.sightparser.authlayer.VerifyConfirmRequest) KeyRequest(sugar.free.sightparser.authlayer.KeyRequest) VerifyDisplayRequest(sugar.free.sightparser.authlayer.VerifyDisplayRequest) DisconnectedError(sugar.free.sightparser.error.DisconnectedError) VerifyConfirmResponse(sugar.free.sightparser.authlayer.VerifyConfirmResponse) ConnectionResponse(sugar.free.sightparser.authlayer.ConnectionResponse) BindMessage(sugar.free.sightparser.applayer.messages.connection.BindMessage)

Aggregations

TimerTask (java.util.TimerTask)1 BindMessage (sugar.free.sightparser.applayer.messages.connection.BindMessage)1 ConnectionResponse (sugar.free.sightparser.authlayer.ConnectionResponse)1 KeyRequest (sugar.free.sightparser.authlayer.KeyRequest)1 KeyResponse (sugar.free.sightparser.authlayer.KeyResponse)1 PairingStatus (sugar.free.sightparser.authlayer.PairingStatus)1 VerifyConfirmRequest (sugar.free.sightparser.authlayer.VerifyConfirmRequest)1 VerifyConfirmResponse (sugar.free.sightparser.authlayer.VerifyConfirmResponse)1 VerifyDisplayRequest (sugar.free.sightparser.authlayer.VerifyDisplayRequest)1 VerifyDisplayResponse (sugar.free.sightparser.authlayer.VerifyDisplayResponse)1 DisconnectedError (sugar.free.sightparser.error.DisconnectedError)1