Search in sources :

Example 1 with InvalidSignatureException

use of com.github.dedis.popstellar.utility.error.InvalidSignatureException in project popstellar by dedis.

the class LaoHandler method handleStateLao.

/**
 * Process a StateLao message.
 *
 * @param context the HandlerContext of the message
 * @param stateLao the message that was received
 */
public static void handleStateLao(HandlerContext context, StateLao stateLao) throws DataHandlingException {
    LAORepository laoRepository = context.getLaoRepository();
    Channel channel = context.getChannel();
    Log.d(TAG, "Receive State Lao Broadcast msg=" + stateLao);
    Lao lao = laoRepository.getLaoByChannel(channel);
    Log.d(TAG, "Receive State Lao Broadcast " + stateLao.getName());
    if (!laoRepository.getMessageById().containsKey(stateLao.getModificationId())) {
        Log.d(TAG, "Can't find modification id : " + stateLao.getModificationId());
        // queue it if we haven't received the update message yet
        throw new InvalidMessageIdException(stateLao, stateLao.getModificationId());
    }
    Log.d(TAG, "Verifying signatures");
    for (PublicKeySignaturePair pair : stateLao.getModificationSignatures()) {
        if (!pair.getWitness().verify(pair.getSignature(), stateLao.getModificationId())) {
            throw new InvalidSignatureException(stateLao, pair.getSignature());
        }
    }
    Log.d(TAG, "Success to verify state lao signatures");
    // TODO: verify if lao/state_lao is consistent with the lao/update message
    lao.setId(stateLao.getId());
    lao.setWitnesses(stateLao.getWitnesses());
    lao.setName(stateLao.getName());
    lao.setLastModified(stateLao.getLastModified());
    lao.setModificationId(stateLao.getModificationId());
    PublicKey publicKey = context.getKeyManager().getMainPublicKey();
    if (lao.getOrganizer().equals(publicKey) || lao.getWitnesses().contains(publicKey)) {
        context.getMessageSender().subscribe(lao.getChannel().subChannel("consensus")).subscribe();
    }
    // Now we're going to remove all pending updates which came prior to this state lao
    long targetTime = stateLao.getLastModified();
    lao.getPendingUpdates().removeIf(pendingUpdate -> pendingUpdate.getModificationTime() <= targetTime);
    laoRepository.updateNodes(channel);
}
Also used : InvalidSignatureException(com.github.dedis.popstellar.utility.error.InvalidSignatureException) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) Channel(com.github.dedis.popstellar.model.objects.Channel) LAORepository(com.github.dedis.popstellar.repository.LAORepository) InvalidMessageIdException(com.github.dedis.popstellar.utility.error.InvalidMessageIdException) StateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao) CreateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao) Lao(com.github.dedis.popstellar.model.objects.Lao) UpdateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao) PublicKeySignaturePair(com.github.dedis.popstellar.model.network.method.message.PublicKeySignaturePair)

Aggregations

PublicKeySignaturePair (com.github.dedis.popstellar.model.network.method.message.PublicKeySignaturePair)1 CreateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao)1 StateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)1 UpdateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)1 Channel (com.github.dedis.popstellar.model.objects.Channel)1 Lao (com.github.dedis.popstellar.model.objects.Lao)1 PublicKey (com.github.dedis.popstellar.model.objects.security.PublicKey)1 LAORepository (com.github.dedis.popstellar.repository.LAORepository)1 InvalidMessageIdException (com.github.dedis.popstellar.utility.error.InvalidMessageIdException)1 InvalidSignatureException (com.github.dedis.popstellar.utility.error.InvalidSignatureException)1