Search in sources :

Example 16 with PublicKey

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

the class LaoHandler method updateLaoWitnessesWitnessMessage.

public static WitnessMessage updateLaoWitnessesWitnessMessage(MessageID messageId, UpdateLao updateLao, Lao lao) {
    WitnessMessage message = new WitnessMessage(messageId);
    List<PublicKey> tempList = new ArrayList<>(updateLao.getWitnesses());
    message.setTitle("Update Lao Witnesses");
    message.setDescription("Lao Name : " + lao.getName() + "\n" + "Message ID : " + messageId + "\n" + "New Witness ID : " + tempList.get(tempList.size() - 1));
    return message;
}
Also used : PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) ArrayList(java.util.ArrayList) WitnessMessage(com.github.dedis.popstellar.model.objects.WitnessMessage)

Example 17 with PublicKey

use of com.github.dedis.popstellar.model.objects.security.PublicKey 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);
}
Also used : KeyPair(com.github.dedis.popstellar.model.objects.security.KeyPair) PrivateKey(com.github.dedis.popstellar.model.objects.security.PrivateKey) ProtectedPrivateKey(com.github.dedis.popstellar.model.objects.security.privatekey.ProtectedPrivateKey) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) ProtectedPrivateKey(com.github.dedis.popstellar.model.objects.security.privatekey.ProtectedPrivateKey) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 18 with PublicKey

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

the class ElectInstanceTest method acceptorsResponsesTest.

@Test
public void acceptorsResponsesTest() {
    MessageID messageId1 = generateMessageID();
    MessageID messageId2 = generateMessageID();
    String instanceId = electInstance.getInstanceId();
    ConsensusElectAccept electAccept = new ConsensusElectAccept(instanceId, electMessageId, true);
    ConsensusElectAccept electReject = new ConsensusElectAccept(instanceId, electMessageId, false);
    electInstance.addElectAccept(node2, messageId1, electAccept);
    electInstance.addElectAccept(node2, messageId2, electReject);
    Map<PublicKey, MessageID> messageIds = electInstance.getAcceptorsToMessageId();
    assertEquals(1, messageIds.size());
    assertEquals(messageId1, messageIds.get(node2));
}
Also used : ConsensusElectAccept(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept) Base64DataUtils.generatePublicKey(com.github.dedis.popstellar.testutils.Base64DataUtils.generatePublicKey) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID) Base64DataUtils.generateMessageID(com.github.dedis.popstellar.testutils.Base64DataUtils.generateMessageID) Test(org.junit.Test)

Example 19 with PublicKey

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

the class ChirpListAdapter method getView.

@Override
public View getView(int position, View chirpView, ViewGroup viewGroup) {
    if (chirpView == null) {
        chirpView = layoutInflater.inflate(R.layout.chirp_card, null);
    }
    Chirp chirp = getItem(position);
    if (chirp == null) {
        throw new IllegalArgumentException("The chirp does not exist");
    }
    PublicKey publicKey = chirp.getSender();
    long timestamp = chirp.getTimestamp();
    String text;
    TextView itemUsername = chirpView.findViewById(R.id.social_media_username);
    TextView itemTime = chirpView.findViewById(R.id.social_media_time);
    TextView itemText = chirpView.findViewById(R.id.social_media_text);
    if (socialMediaViewModel.isOwner(publicKey.getEncoded())) {
        ImageButton deleteChirp = chirpView.findViewById(R.id.delete_chirp_button);
        deleteChirp.setVisibility(View.VISIBLE);
        deleteChirp.setOnClickListener(v -> socialMediaViewModel.deleteChirpEvent(chirp.getId()));
    }
    if (chirp.getIsDeleted()) {
        text = "Chirp is deleted.";
        ImageButton deleteChirp = chirpView.findViewById(R.id.delete_chirp_button);
        deleteChirp.setVisibility(View.GONE);
        itemText.setTextColor(Color.GRAY);
    } else {
        text = chirp.getText();
    }
    itemUsername.setText(publicKey.getEncoded());
    itemTime.setText(getRelativeTimeSpanString(timestamp * 1000));
    itemText.setText(text);
    return chirpView;
}
Also used : ImageButton(android.widget.ImageButton) Chirp(com.github.dedis.popstellar.model.objects.Chirp) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) TextView(android.widget.TextView) DateUtils.getRelativeTimeSpanString(android.text.format.DateUtils.getRelativeTimeSpanString)

Example 20 with PublicKey

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

the class ChirpHandler method handleChirpAdd.

/**
 * Process an AddChirp message.
 *
 * @param context the HandlerContext of the message
 * @param addChirp the data of the message that was received
 */
public static void handleChirpAdd(HandlerContext context, AddChirp addChirp) {
    LAORepository laoRepository = context.getLaoRepository();
    Channel channel = context.getChannel();
    MessageID messageId = context.getMessageId();
    PublicKey senderPk = context.getSenderPk();
    Lao lao = laoRepository.getLaoByChannel(channel);
    Chirp chirp = new Chirp(messageId);
    chirp.setChannel(channel);
    chirp.setSender(senderPk);
    chirp.setText(addChirp.getText());
    chirp.setTimestamp(addChirp.getTimestamp());
    chirp.setParentId(addChirp.getParentId().orElse(new MessageID("")));
    lao.updateAllChirps(messageId, chirp);
}
Also used : DeleteChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.DeleteChirp) AddChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.AddChirp) Chirp(com.github.dedis.popstellar.model.objects.Chirp) 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)

Aggregations

PublicKey (com.github.dedis.popstellar.model.objects.security.PublicKey)21 MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)8 Channel (com.github.dedis.popstellar.model.objects.Channel)6 Lao (com.github.dedis.popstellar.model.objects.Lao)6 LAORepository (com.github.dedis.popstellar.repository.LAORepository)6 Test (org.junit.Test)4 ElectInstance (com.github.dedis.popstellar.model.objects.ElectInstance)3 Base64DataUtils.generatePublicKey (com.github.dedis.popstellar.testutils.Base64DataUtils.generatePublicKey)3 ConsensusElectAccept (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept)2 CreateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao)2 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 Chirp (com.github.dedis.popstellar.model.objects.Chirp)2 KeyPair (com.github.dedis.popstellar.model.objects.security.KeyPair)2 InvalidMessageIdException (com.github.dedis.popstellar.utility.error.InvalidMessageIdException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 DateUtils.getRelativeTimeSpanString (android.text.format.DateUtils.getRelativeTimeSpanString)1 ImageButton (android.widget.ImageButton)1