Search in sources :

Example 11 with MessageID

use of com.github.dedis.popstellar.model.objects.security.MessageID in project popstellar by dedis.

the class MessageGeneral method verify.

public boolean verify() {
    if (!this.sender.verify(this.signature, this.dataBuf))
        return false;
    if (this.data instanceof WitnessMessageSignature) {
        WitnessMessageSignature witness = (WitnessMessageSignature) this.data;
        Signature witnessSignature = witness.getSignature();
        MessageID messageID = witness.getMessageId();
        return this.sender.verify(witnessSignature, messageID);
    } else {
        return true;
    }
}
Also used : WitnessMessageSignature(com.github.dedis.popstellar.model.network.method.message.data.message.WitnessMessageSignature) Signature(com.github.dedis.popstellar.model.objects.security.Signature) WitnessMessageSignature(com.github.dedis.popstellar.model.network.method.message.data.message.WitnessMessageSignature) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Example 12 with MessageID

use of com.github.dedis.popstellar.model.objects.security.MessageID in project popstellar by dedis.

the class ConsensusHandler method handleElect.

/**
 * Process an Elect message.
 *
 * @param context the HandlerContext of the message
 * @param consensusElect the data of the message that was received
 */
public static void handleElect(HandlerContext context, ConsensusElect consensusElect) {
    LAORepository laoRepository = context.getLaoRepository();
    Channel channel = context.getChannel();
    MessageID messageId = context.getMessageId();
    PublicKey senderPk = context.getSenderPk();
    Lao lao = laoRepository.getLaoByChannel(channel);
    Set<PublicKey> nodes = new HashSet<>(lao.getWitnesses());
    nodes.add(lao.getOrganizer());
    ElectInstance electInstance = new ElectInstance(messageId, channel, senderPk, nodes, consensusElect);
    lao.updateElectInstance(electInstance);
    laoRepository.updateNodes(lao.getChannel());
}
Also used : ElectInstance(com.github.dedis.popstellar.model.objects.ElectInstance) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) Channel(com.github.dedis.popstellar.model.objects.Channel) LAORepository(com.github.dedis.popstellar.repository.LAORepository) Lao(com.github.dedis.popstellar.model.objects.Lao) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID) HashSet(java.util.HashSet)

Example 13 with MessageID

use of com.github.dedis.popstellar.model.objects.security.MessageID in project popstellar by dedis.

the class LaoHandler method handleUpdateLao.

/**
 * Process an UpdateLao message.
 *
 * @param context the HandlerContext of the message
 * @param updateLao the message that was received
 */
public static void handleUpdateLao(HandlerContext context, UpdateLao updateLao) throws DataHandlingException {
    LAORepository laoRepository = context.getLaoRepository();
    Channel channel = context.getChannel();
    MessageID messageId = context.getMessageId();
    Log.d(TAG, " Receive Update Lao Broadcast msg=" + updateLao);
    Lao lao = laoRepository.getLaoByChannel(channel);
    if (lao.getLastModified() > updateLao.getLastModified()) {
        // the current state we have is more up to date
        throw new DataHandlingException(updateLao, "The current Lao is more up to date than the update lao message");
    }
    WitnessMessage message;
    if (!updateLao.getName().equals(lao.getName())) {
        message = updateLaoNameWitnessMessage(messageId, updateLao, lao);
    } else if (!updateLao.getWitnesses().equals(lao.getWitnesses())) {
        message = updateLaoWitnessesWitnessMessage(messageId, updateLao, lao);
    } else {
        Log.d(TAG, "Cannot set the witness message title to update lao");
        throw new DataHandlingException(updateLao, "Cannot set the witness message title to update lao");
    }
    lao.updateWitnessMessage(messageId, message);
    if (!lao.getWitnesses().isEmpty()) {
        // We send a pending update only if there are already some witness that need to sign this
        // UpdateLao
        lao.getPendingUpdates().add(new PendingUpdate(updateLao.getLastModified(), messageId));
    }
    laoRepository.updateNodes(channel);
}
Also used : Channel(com.github.dedis.popstellar.model.objects.Channel) PendingUpdate(com.github.dedis.popstellar.model.objects.PendingUpdate) LAORepository(com.github.dedis.popstellar.repository.LAORepository) 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) DataHandlingException(com.github.dedis.popstellar.utility.error.DataHandlingException) WitnessMessage(com.github.dedis.popstellar.model.objects.WitnessMessage) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Example 14 with MessageID

use of com.github.dedis.popstellar.model.objects.security.MessageID in project popstellar by dedis.

the class RollCallHandler method handleCloseRollCall.

/**
 * Process a CloseRollCall message.
 *
 * @param context the HandlerContext of the message
 * @param closeRollCall the message that was received
 */
public static void handleCloseRollCall(HandlerContext context, CloseRollCall closeRollCall) throws DataHandlingException {
    LAORepository laoRepository = context.getLaoRepository();
    Channel channel = context.getChannel();
    MessageID messageId = context.getMessageId();
    Lao lao = laoRepository.getLaoByChannel(channel);
    Log.d(TAG, "handleCloseRollCall: " + channel);
    String updateId = closeRollCall.getUpdateId();
    String closes = closeRollCall.getCloses();
    Optional<RollCall> rollCallOptional = lao.getRollCall(closes);
    if (!rollCallOptional.isPresent()) {
        Log.w(TAG, "Cannot find roll call to close : " + closes);
        throw new InvalidDataException(closeRollCall, "close id", closes);
    }
    RollCall rollCall = rollCallOptional.get();
    rollCall.setEnd(closeRollCall.getClosedAt());
    rollCall.setId(updateId);
    rollCall.getAttendees().addAll(closeRollCall.getAttendees());
    rollCall.setState(EventState.CLOSED);
    lao.updateRollCall(closes, rollCall);
    lao.updateWitnessMessage(messageId, closeRollCallWitnessMessage(messageId, rollCall));
    // Subscribe to the social media channels
    try {
        PoPToken token = context.getKeyManager().getValidPoPToken(lao, rollCall);
        context.getMessageSender().subscribe(channel.subChannel("social").subChannel(token.getPublicKey().getEncoded())).subscribe();
    } catch (InvalidPoPTokenException e) {
        Log.i(TAG, "Received a close roll-call that you did not attend");
    } catch (KeyException e) {
        Log.e(TAG, "Could not retrieve your PoP Token to subscribe you to your social media channel", e);
    }
}
Also used : PoPToken(com.github.dedis.popstellar.model.objects.security.PoPToken) InvalidPoPTokenException(com.github.dedis.popstellar.utility.error.keys.InvalidPoPTokenException) Channel(com.github.dedis.popstellar.model.objects.Channel) LAORepository(com.github.dedis.popstellar.repository.LAORepository) InvalidDataException(com.github.dedis.popstellar.utility.error.InvalidDataException) CreateRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall) OpenRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall) RollCall(com.github.dedis.popstellar.model.objects.RollCall) CloseRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall) Lao(com.github.dedis.popstellar.model.objects.Lao) KeyException(com.github.dedis.popstellar.utility.error.keys.KeyException) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Example 15 with MessageID

use of com.github.dedis.popstellar.model.objects.security.MessageID in project popstellar by dedis.

the class RollCallHandler method handleCreateRollCall.

/**
 * Process a CreateRollCall message.
 *
 * @param context the HandlerContext of the message
 * @param createRollCall the message that was received
 */
public static void handleCreateRollCall(HandlerContext context, CreateRollCall createRollCall) {
    LAORepository laoRepository = context.getLaoRepository();
    Channel channel = context.getChannel();
    MessageID messageId = context.getMessageId();
    Lao lao = laoRepository.getLaoByChannel(channel);
    Log.d(TAG, "handleCreateRollCall: " + channel + " name " + createRollCall.getName());
    RollCall rollCall = new RollCall(createRollCall.getId());
    rollCall.setCreation(createRollCall.getCreation());
    rollCall.setState(EventState.CREATED);
    rollCall.setStart(createRollCall.getProposedStart());
    rollCall.setEnd(createRollCall.getProposedEnd());
    rollCall.setName(createRollCall.getName());
    rollCall.setLocation(createRollCall.getLocation());
    rollCall.setLocation(createRollCall.getLocation());
    rollCall.setDescription(createRollCall.getDescription().orElse(""));
    lao.updateRollCall(rollCall.getId(), rollCall);
    lao.updateWitnessMessage(messageId, createRollCallWitnessMessage(messageId, rollCall));
}
Also used : Channel(com.github.dedis.popstellar.model.objects.Channel) LAORepository(com.github.dedis.popstellar.repository.LAORepository) CreateRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall) OpenRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall) RollCall(com.github.dedis.popstellar.model.objects.RollCall) CloseRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall) Lao(com.github.dedis.popstellar.model.objects.Lao) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Aggregations

MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)23 Channel (com.github.dedis.popstellar.model.objects.Channel)10 Lao (com.github.dedis.popstellar.model.objects.Lao)10 LAORepository (com.github.dedis.popstellar.repository.LAORepository)10 PublicKey (com.github.dedis.popstellar.model.objects.security.PublicKey)8 Test (org.junit.Test)7 Base64DataUtils.generateMessageID (com.github.dedis.popstellar.testutils.Base64DataUtils.generateMessageID)6 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)4 ElectInstance (com.github.dedis.popstellar.model.objects.ElectInstance)4 ConsensusElectAccept (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept)3 CloseRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall)3 CreateRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall)3 OpenRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall)3 AddChirp (com.github.dedis.popstellar.model.network.method.message.data.socialmedia.AddChirp)3 DeleteChirp (com.github.dedis.popstellar.model.network.method.message.data.socialmedia.DeleteChirp)3 Chirp (com.github.dedis.popstellar.model.objects.Chirp)3 RollCall (com.github.dedis.popstellar.model.objects.RollCall)3 StateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)2 UpdateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)2 ConsensusNode (com.github.dedis.popstellar.model.objects.ConsensusNode)2