Search in sources :

Example 1 with AuthLayerMessage

use of sugar.free.sightparser.authlayer.AuthLayerMessage in project SightRemote by TebbeUbben.

the class AuthLayerProcessor method onInboundMessage.

@Override
public void onInboundMessage(Object message, Pipeline pipeline) throws Exception {
    if (!(message instanceof ByteBuf))
        return;
    ByteBuf data = (ByteBuf) message;
    while (data.size() >= 37) {
        int length = data.getUInt16LE(4);
        if (data.size() < length + 8)
            return;
        try {
            AuthLayerMessage authLayerMessage = AuthLayerMessage.deserialize(data, pipeline.getLastNonceReceived(), pipeline.getDerivedKeys() != null ? pipeline.getDerivedKeys().getIncomingKey() : null);
            pipeline.setLastNonceReceived(authLayerMessage.getNonce());
            pipeline.setCommID(authLayerMessage.getCommID());
            pipeline.receive(authLayerMessage);
        } catch (InvalidNonceError | InvalidAuthCRCError | InvalidTrailerError e) {
            data.shift(data.size());
            throw e;
        }
    }
}
Also used : AuthLayerMessage(sugar.free.sightparser.authlayer.AuthLayerMessage) CRCAuthLayerMessage(sugar.free.sightparser.authlayer.CRCAuthLayerMessage) InvalidNonceError(sugar.free.sightparser.error.InvalidNonceError) InvalidAuthCRCError(sugar.free.sightparser.error.InvalidAuthCRCError) ByteBuf(sugar.free.sightparser.pipeline.ByteBuf) InvalidTrailerError(sugar.free.sightparser.error.InvalidTrailerError)

Example 2 with AuthLayerMessage

use of sugar.free.sightparser.authlayer.AuthLayerMessage in project SightRemote by TebbeUbben.

the class AuthLayerProcessor method onOutboundMessage.

@Override
public void onOutboundMessage(Object message, Pipeline pipeline) throws Exception {
    if (!(message instanceof AuthLayerMessage))
        return;
    AuthLayerMessage data = (AuthLayerMessage) message;
    BigInteger nonce = pipeline.getLastNonceSent();
    if (!(data instanceof CRCAuthLayerMessage))
        nonce = nonce.add(BigInteger.ONE);
    pipeline.send(data.serialize(nonce, (message instanceof KeyRequest) ? 1 : pipeline.getCommID(), pipeline.getDerivedKeys() != null ? pipeline.getDerivedKeys().getOutgoingKey() : null));
    pipeline.setLastNonceSent(nonce);
}
Also used : AuthLayerMessage(sugar.free.sightparser.authlayer.AuthLayerMessage) CRCAuthLayerMessage(sugar.free.sightparser.authlayer.CRCAuthLayerMessage) CRCAuthLayerMessage(sugar.free.sightparser.authlayer.CRCAuthLayerMessage) BigInteger(java.math.BigInteger) KeyRequest(sugar.free.sightparser.authlayer.KeyRequest)

Aggregations

AuthLayerMessage (sugar.free.sightparser.authlayer.AuthLayerMessage)2 CRCAuthLayerMessage (sugar.free.sightparser.authlayer.CRCAuthLayerMessage)2 BigInteger (java.math.BigInteger)1 KeyRequest (sugar.free.sightparser.authlayer.KeyRequest)1 InvalidAuthCRCError (sugar.free.sightparser.error.InvalidAuthCRCError)1 InvalidNonceError (sugar.free.sightparser.error.InvalidNonceError)1 InvalidTrailerError (sugar.free.sightparser.error.InvalidTrailerError)1 ByteBuf (sugar.free.sightparser.pipeline.ByteBuf)1