use of com.github.dedis.popstellar.model.objects.security.KeyPair in project popstellar by dedis.
the class LaoDetailViewModel method updateLaoName.
/**
* Method to update the name of a Lao by sending an updateLao msg and a stateLao msg to the
* backend
*/
public void updateLaoName() {
Log.d(TAG, "Updating lao name to " + mLaoName.getValue());
Lao lao = getCurrentLaoValue();
Channel channel = lao.getChannel();
KeyPair mainKey = keyManager.getMainKeyPair();
long now = Instant.now().getEpochSecond();
UpdateLao updateLao = new UpdateLao(mainKey.getPublicKey(), lao.getCreation(), mLaoName.getValue(), now, lao.getWitnesses());
MessageGeneral msg = new MessageGeneral(mainKey, updateLao, gson);
Disposable disposable = networkManager.getMessageSender().publish(channel, msg).subscribe(() -> {
Log.d(TAG, "updated lao name");
dispatchLaoUpdate("lao name", updateLao, lao, channel, msg);
}, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_update_lao));
disposables.add(disposable);
}
use of com.github.dedis.popstellar.model.objects.security.KeyPair 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.objects.security.KeyPair in project popstellar by dedis.
the class LaoDetailViewModel method updateLaoWitnesses.
/**
* Method to update the list of witnesses of a Lao by sending an updateLao msg and a stateLao msg
* to the backend
*/
public void updateLaoWitnesses() {
Log.d(TAG, "Updating lao witnesses ");
Lao lao = getCurrentLaoValue();
if (lao == null) {
Log.d(TAG, LAO_FAILURE_MESSAGE);
return;
}
Channel channel = lao.getChannel();
KeyPair mainKey = keyManager.getMainKeyPair();
long now = Instant.now().getEpochSecond();
UpdateLao updateLao = new UpdateLao(mainKey.getPublicKey(), lao.getCreation(), lao.getName(), now, witnesses);
MessageGeneral msg = new MessageGeneral(mainKey, updateLao, gson);
Disposable disposable = networkManager.getMessageSender().publish(channel, msg).subscribe(() -> {
Log.d(TAG, "updated lao witnesses");
dispatchLaoUpdate("lao state with new witnesses", updateLao, lao, channel, msg);
}, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_update_lao));
disposables.add(disposable);
}
use of com.github.dedis.popstellar.model.objects.security.KeyPair in project popstellar by dedis.
the class KeyManager method getKeyPair.
@VisibleForTesting
public KeyPair getKeyPair(KeysetHandle keysetHandle) throws GeneralSecurityException, IOException {
PrivateKey privateKey = new ProtectedPrivateKey(keysetHandle);
PublicKey publicKey = getPublicKey(keysetHandle);
return new KeyPair(privateKey, publicKey);
}
use of com.github.dedis.popstellar.model.objects.security.KeyPair in project popstellar by dedis.
the class KeyManagerTest method keyPairIsRight.
@Test
public void keyPairIsRight() throws GeneralSecurityException {
KeyManager keyManager = new KeyManager(androidKeysetManager, wallet);
KeyPair mainKeyPair = keyManager.getMainKeyPair();
PublicKey mainKey = keyManager.getMainPublicKey();
assertEquals(mainKey, mainKeyPair.getPublicKey());
// We cannot extract the public key from the keyset handle
// But we can make sure both signatures are equals and the key manager keypair can verify it
PublicKeySign signer = androidKeysetManager.getKeysetHandle().getPrimitive(PublicKeySign.class);
// Generate any data, here a message id
Base64URLData data = Base64DataUtils.generateMessageID();
Signature signature = mainKeyPair.sign(data);
assertArrayEquals(signer.sign(data.getData()), signature.getData());
assertTrue(mainKey.verify(signature, data));
}
Aggregations