use of com.github.dedis.popstellar.model.network.method.message.data.message.WitnessMessageSignature in project popstellar by dedis.
the class LaoDetailViewModel method signMessage.
public void signMessage(WitnessMessage witnessMessage) {
Log.d(TAG, "signing message with ID " + witnessMessage.getMessageId());
Lao lao = getCurrentLaoValue();
if (lao == null) {
Log.d(TAG, LAO_FAILURE_MESSAGE);
return;
}
Channel channel = lao.getChannel();
try {
KeyPair mainKey = keyManager.getMainKeyPair();
// generate the signature of the message
Signature signature = mainKey.sign(witnessMessage.getMessageId());
Log.d(TAG, PUBLISH_MESSAGE);
WitnessMessageSignature signatureMessage = new WitnessMessageSignature(witnessMessage.getMessageId(), signature);
disposables.add(networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), channel, signatureMessage).subscribe(() -> Log.d(TAG, "Verifying the signature of message with id: " + witnessMessage.getMessageId()), error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_sign_message)));
} catch (GeneralSecurityException e) {
Log.d(TAG, PK_FAILURE_MESSAGE, e);
}
}
use of com.github.dedis.popstellar.model.network.method.message.data.message.WitnessMessageSignature 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;
}
}
use of com.github.dedis.popstellar.model.network.method.message.data.message.WitnessMessageSignature in project popstellar by dedis.
the class MessageHandler method notifyLaoUpdate.
/**
* Keep the UI up to date by notifying all observers the updated LAO state.
*
* <p>The LAO is updated if the channel of the message is a LAO channel and the message is not a
* WitnessSignatureMessage.
*
* <p>If a LAO has been created or modified then the LAO lists in the LAORepository are updated.
*
* @param laoRepository the repository to access the LAO lists
* @param data the data received
* @param channel the channel of the message received
*/
private void notifyLaoUpdate(LAORepository laoRepository, Data data, Channel channel) {
if (!(data instanceof WitnessMessageSignature) && channel.isLaoChannel()) {
LAOState laoState = laoRepository.getLaoById().get(channel.extractLaoId());
// Trigger an onNext
laoState.publish();
if (data instanceof StateLao || data instanceof CreateLao) {
laoRepository.setAllLaoSubject();
}
}
}
Aggregations