Search in sources :

Example 1 with ServiceChallengeMessage

use of sugar.free.sightparser.applayer.messages.connection.ServiceChallengeMessage in project SightRemote by TebbeUbben.

the class RequestWorker method requestNext.

private void requestNext(Pipeline pipeline) {
    if (messageRequests.size() == 0)
        return;
    MessageRequest messageRequest = null;
    while (messageRequests.size() != 0) {
        messageRequest = messageRequests.get(0);
        if (!messageRequest.getBinder().isBinderAlive()) {
            messageRequests.remove(messageRequest);
            if (messageRequests.size() == 0)
                return;
            else
                continue;
        } else
            break;
    }
    Service service = messageRequest.getAppLayerMessage().getService();
    if (!pipeline.getActivatedServices().contains(service)) {
        messageRequest.setMessageStatus(MessageStatus.ACTIVATING_SERVICE);
        if (service.getServicePassword() != null) {
            if (service.getServicePassword().length() != 16)
                pipeline.receive(new InvalidServicePasswordError(messageRequest.getAppLayerMessage().getClass(), (short) 0x99F0));
            else {
                ServiceChallengeMessage serviceChallenge = new ServiceChallengeMessage();
                serviceChallenge.setServiceID(service.getServiceID());
                serviceChallenge.setVersion(service.getVersion());
                pipeline.send(serviceChallenge);
            }
        } else {
            ActivateServiceMessage activateService = new ActivateServiceMessage();
            activateService.setServiceID(service.getServiceID());
            activateService.setVersion(service.getVersion());
            activateService.setServicePassword(new byte[16]);
            pipeline.send(activateService);
        }
    } else {
        messageRequest.setMessageStatus(MessageStatus.PENDING);
        if (service.getServicePassword() != null && service.getServicePassword().length() != 16)
            pipeline.receive(new InvalidServicePasswordError(messageRequest.getAppLayerMessage().getClass(), (short) 0x99F0));
        else
            pipeline.send(messageRequest.getAppLayerMessage());
    }
}
Also used : InvalidServicePasswordError(sugar.free.sightparser.error.InvalidServicePasswordError) ActivateServiceMessage(sugar.free.sightparser.applayer.messages.connection.ActivateServiceMessage) MessageRequest(sugar.free.sightparser.handling.MessageRequest) ServiceChallengeMessage(sugar.free.sightparser.applayer.messages.connection.ServiceChallengeMessage) Service(sugar.free.sightparser.applayer.descriptors.Service)

Example 2 with ServiceChallengeMessage

use of sugar.free.sightparser.applayer.messages.connection.ServiceChallengeMessage in project SightRemote by TebbeUbben.

the class RequestWorker method onInboundMessage.

@Override
public void onInboundMessage(final Object message, Pipeline pipeline) throws Exception {
    synchronized (messageRequests) {
        if (messageRequests.size() == 0)
            return;
        if (message instanceof DisconnectedError) {
            for (MessageRequest messageRequest : new ArrayList<>(messageRequests)) {
                sendError(messageRequest, (Exception) message);
                messageRequests.remove(messageRequest);
            }
            return;
        }
        MessageRequest messageRequest = messageRequests.get(0);
        if (message instanceof Exception) {
            sendError(messageRequest, (Exception) message);
            messageRequests.remove(messageRequest);
            requestNext(pipeline);
            return;
        }
        if (messageRequest.getMessageStatus() == MessageStatus.ACTIVATING_SERVICE) {
            Service service = messageRequest.getAppLayerMessage().getService();
            if (message instanceof ServiceChallengeMessage) {
                byte[] password = Cryptograph.getServicePasswordHash(service.getServicePassword(), ((ServiceChallengeMessage) message).getRandomData());
                ActivateServiceMessage activateService = new ActivateServiceMessage();
                activateService.setServicePassword(password);
                activateService.setServiceID(service.getServiceID());
                activateService.setVersion(service.getVersion());
                pipeline.send(activateService);
            } else if (message instanceof ActivateServiceMessage) {
                pipeline.getActivatedServices().add(service);
                requestNext(pipeline);
            }
        } else if (messageRequest.getMessageStatus() == MessageStatus.PENDING && message instanceof AppLayerMessage) {
            sendMessage(messageRequest, (AppLayerMessage) message);
            messageRequests.remove(messageRequest);
            requestNext(pipeline);
        }
    }
}
Also used : ActivateServiceMessage(sugar.free.sightparser.applayer.messages.connection.ActivateServiceMessage) AppLayerMessage(sugar.free.sightparser.applayer.messages.AppLayerMessage) MessageRequest(sugar.free.sightparser.handling.MessageRequest) ServiceChallengeMessage(sugar.free.sightparser.applayer.messages.connection.ServiceChallengeMessage) ArrayList(java.util.ArrayList) Service(sugar.free.sightparser.applayer.descriptors.Service) DisconnectedError(sugar.free.sightparser.error.DisconnectedError)

Aggregations

Service (sugar.free.sightparser.applayer.descriptors.Service)2 ActivateServiceMessage (sugar.free.sightparser.applayer.messages.connection.ActivateServiceMessage)2 ServiceChallengeMessage (sugar.free.sightparser.applayer.messages.connection.ServiceChallengeMessage)2 MessageRequest (sugar.free.sightparser.handling.MessageRequest)2 ArrayList (java.util.ArrayList)1 AppLayerMessage (sugar.free.sightparser.applayer.messages.AppLayerMessage)1 DisconnectedError (sugar.free.sightparser.error.DisconnectedError)1 InvalidServicePasswordError (sugar.free.sightparser.error.InvalidServicePasswordError)1