Search in sources :

Example 6 with PublicKey

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

the class ConsensusHandlerTest method handleConsensusElectAcceptTest.

// handle an electAccept from node3 for the elect of node2
// This test need be run after the elect message was handled, else the messageId would be invalid
private void handleConsensusElectAcceptTest() throws DataHandlingException {
    ConsensusElectAccept electAccept = new ConsensusElectAccept(INSTANCE_ID, messageId, true);
    MessageGeneral electAcceptMsg = getMsg(NODE_3_KEY, electAccept);
    messageHandler.handleMessage(laoRepository, messageSender, CONSENSUS_CHANNEL, electAcceptMsg);
    Optional<ElectInstance> electInstanceOpt = lao.getElectInstance(electMsg.getMessageId());
    assertTrue(electInstanceOpt.isPresent());
    ElectInstance electInstance = electInstanceOpt.get();
    Map<PublicKey, MessageID> acceptorsToMessageId = electInstance.getAcceptorsToMessageId();
    assertEquals(1, acceptorsToMessageId.size());
    assertEquals(electAcceptMsg.getMessageId(), acceptorsToMessageId.get(NODE_3));
    assertEquals(3, lao.getNodes().size());
    ConsensusNode organizer = lao.getNode(ORGANIZER);
    ConsensusNode node2 = lao.getNode(NODE_2);
    ConsensusNode node3 = lao.getNode(NODE_3);
    assertNotNull(organizer);
    assertNotNull(node2);
    assertNotNull(node3);
    Set<MessageID> organizerAcceptedMsg = organizer.getAcceptedMessageIds();
    Set<MessageID> node2AcceptedMsg = node2.getAcceptedMessageIds();
    Set<MessageID> node3AcceptedMsg = node3.getAcceptedMessageIds();
    assertTrue(organizerAcceptedMsg.isEmpty());
    assertTrue(node2AcceptedMsg.isEmpty());
    assertEquals(Sets.newSet(electMsg.getMessageId()), node3AcceptedMsg);
}
Also used : ConsensusElectAccept(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept) ElectInstance(com.github.dedis.popstellar.model.objects.ElectInstance) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) ConsensusNode(com.github.dedis.popstellar.model.objects.ConsensusNode) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Example 7 with PublicKey

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

the class ChirpTest method setAndGetSenderTest.

@Test
public void setAndGetSenderTest() {
    PublicKey sender = generatePublicKey();
    CHIRP.setSender(sender);
    assertEquals(sender, CHIRP.getSender());
}
Also used : Base64DataUtils.generatePublicKey(com.github.dedis.popstellar.testutils.Base64DataUtils.generatePublicKey) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) Test(org.junit.Test)

Example 8 with PublicKey

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

the class LaoDetailViewModel method onQRCodeDetected.

@Override
public void onQRCodeDetected(Barcode barcode) {
    Log.d(TAG, "Detected barcode with value: " + barcode.rawValue);
    PublicKey attendee;
    try {
        attendee = new PublicKey(barcode.rawValue);
    } catch (IllegalArgumentException e) {
        mScanWarningEvent.postValue(new SingleEvent<>("Invalid QR code. Please try again."));
        return;
    }
    if (attendees.contains(attendee) || Objects.requireNonNull(mWitnesses.getValue()).contains(attendee)) {
        mScanWarningEvent.postValue(new SingleEvent<>("This QR code has already been scanned. Please try again."));
        return;
    }
    if (scanningAction == (ScanningAction.ADD_ROLL_CALL_ATTENDEE)) {
        attendees.add(attendee);
        mAttendeeScanConfirmEvent.postValue(new SingleEvent<>("Attendee has been added."));
        mNbAttendeesEvent.postValue(new SingleEvent<>(attendees.size()));
    } else if (scanningAction == (ScanningAction.ADD_WITNESS)) {
        witnesses.add(attendee);
        mWitnessScanConfirmEvent.postValue(new SingleEvent<>(true));
        updateLaoWitnesses();
    }
}
Also used : PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) SingleEvent(com.github.dedis.popstellar.SingleEvent)

Example 9 with PublicKey

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

the class LaoDetailActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lao_detail_activity);
    mViewModel = obtainViewModel(this);
    mViewModel.subscribeToLao((String) Objects.requireNonNull(getIntent().getExtras()).get("LAO_ID"));
    if (getIntent().getExtras().get("FRAGMENT_TO_OPEN").equals("LaoDetail")) {
        setupLaoFragment();
    } else {
        setupLaoWalletFragment();
    }
    setupHomeButton();
    setupIdentityButton();
    setupSocialMediaButton();
    // Subscribe to "open lao detail event"
    mViewModel.getOpenLaoDetailEvent().observe(this, booleanEvent -> {
        Boolean event = booleanEvent.getContentIfNotHandled();
        if (event != null) {
            setupLaoFragment();
        }
    });
    // Subscribe to "open home" event
    setupHomeActivity();
    // Subscribe to "open identity" event
    setupIdentityFragment();
    // Subscribe to " open social media " event
    setupSocialMediaActivity();
    // Subscribe to " open witness message" event
    setupWitnessMessageFragment();
    // Subscribe to "add witness" event
    setupAddWitness();
    // Subscribe to "new lao event" event
    handleNewEvent();
    // Subscribe to "open roll call" event
    mViewModel.getOpenRollCallEvent().observe(this, stringEvent -> {
        HomeViewModel.HomeViewAction action = stringEvent.getContentIfNotHandled();
        if (action != null) {
            openScanning(action);
        }
    });
    mViewModel.getCloseRollCallEvent().observe(this, integerEvent -> {
        Integer nextFragment = integerEvent.getContentIfNotHandled();
        if (nextFragment != null) {
            if (nextFragment.equals(R.id.fragment_lao_detail)) {
                mViewModel.openLaoDetail();
            } else if (nextFragment.equals(R.id.fragment_home)) {
                mViewModel.openHome();
            } else if (nextFragment.equals(R.id.fragment_identity)) {
                mViewModel.openIdentity();
            }
        }
    });
    mViewModel.getPkRollCallEvent().observe(this, stringEvent -> {
        PublicKey pk = stringEvent.getContentIfNotHandled();
        if (pk != null) {
            setupRollCallDetailFragment(pk);
        }
    });
    subscribeWalletEvents();
    // Subscribe to "open cast votes event" event
    setupCastVotesFragment();
    // Subscribe to "open election display" event
    setupElectionResultsFragment();
    // Subscribe to "open manage election" event
    setupManageElectionFragment();
    // Subscribe to "open start election" event
    setupElectionStartFragment();
}
Also used : PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) HomeViewModel(com.github.dedis.popstellar.ui.home.HomeViewModel)

Example 10 with PublicKey

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

the class LaoDetailViewModel method enterRollCall.

public void enterRollCall(String id) {
    if (!wallet.isSetUp()) {
        mWalletMessageEvent.setValue(new SingleEvent<>(true));
        return;
    }
    String firstLaoId = getCurrentLaoValue().getId();
    String errorMessage = "failed to retrieve public key from wallet";
    try {
        PublicKey publicKey = wallet.generatePoPToken(firstLaoId, id).getPublicKey();
        mPkRollCallEvent.postValue(new SingleEvent<>(publicKey));
    } catch (Exception e) {
        Log.d(TAG, errorMessage, e);
    }
}
Also used : PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) GeneralSecurityException(java.security.GeneralSecurityException) KeyGenerationException(com.github.dedis.popstellar.utility.error.keys.KeyGenerationException) KeyException(com.github.dedis.popstellar.utility.error.keys.KeyException) UninitializedWalletException(com.github.dedis.popstellar.utility.error.keys.UninitializedWalletException)

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