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;
}
}
}
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);
}
Aggregations