Search in sources :

Example 11 with PoPToken

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

the class KeyManagerTest method popTokenRetrievingFailsWhenWalletFails.

@Test
public void popTokenRetrievingFailsWhenWalletFails() throws KeyException {
    PoPToken token = Base64DataUtils.generatePoPToken();
    // create LAO and RollCall
    Lao lao = new Lao("lao", Base64DataUtils.generatePublicKey(), 54213424);
    RollCall rollCall = new RollCall(lao.getId(), 5421364, "rollcall");
    lao.updateRollCall(rollCall.getId(), rollCall);
    KeyManager manager = new KeyManager(androidKeysetManager, wallet);
    // Test with every possible errors
    when(wallet.recoverKey(any(), any(), any())).thenThrow(new KeyGenerationException(new GeneralSecurityException()));
    assertThrows(KeyGenerationException.class, () -> manager.getValidPoPToken(lao));
    verify(wallet, times(1)).recoverKey(eq(lao.getId()), eq(rollCall.getId()), any());
    reset(wallet);
    when(wallet.recoverKey(any(), any(), any())).thenThrow(new UninitializedWalletException());
    assertThrows(UninitializedWalletException.class, () -> manager.getValidPoPToken(lao));
    verify(wallet, times(1)).recoverKey(eq(lao.getId()), eq(rollCall.getId()), any());
    reset(wallet);
    when(wallet.recoverKey(any(), any(), any())).thenThrow(new InvalidPoPTokenException(token));
    assertThrows(InvalidPoPTokenException.class, () -> manager.getValidPoPToken(lao));
    verify(wallet, times(1)).recoverKey(eq(lao.getId()), eq(rollCall.getId()), any());
}
Also used : PoPToken(com.github.dedis.popstellar.model.objects.security.PoPToken) InvalidPoPTokenException(com.github.dedis.popstellar.utility.error.keys.InvalidPoPTokenException) GeneralSecurityException(java.security.GeneralSecurityException) RollCall(com.github.dedis.popstellar.model.objects.RollCall) KeyGenerationException(com.github.dedis.popstellar.utility.error.keys.KeyGenerationException) Lao(com.github.dedis.popstellar.model.objects.Lao) UninitializedWalletException(com.github.dedis.popstellar.utility.error.keys.UninitializedWalletException) Test(org.junit.Test) HiltAndroidTest(dagger.hilt.android.testing.HiltAndroidTest)

Example 12 with PoPToken

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

the class WalletTest method crossValidationWithFe1Web.

@Test
public void crossValidationWithFe1Web() throws GeneralSecurityException, KeyException {
    String Lao_ID = "T8grJq7LR9KGjE7741gXMqPny8xsLvsyBiwIFwoF7rg=";
    String Roll_Call_ID = "T8grJq7LR9KGjE7741gXMqPny8xsLvsyBiwIFwoF7rg=";
    Wallet hdw = new Wallet(TestKeysetModule.provideWalletKeysetManager());
    hdw.importSeed("garbage effort river orphan negative kind outside quit hat camera approve first");
    PoPToken res = hdw.generatePoPToken(Lao_ID, Roll_Call_ID);
    assertEquals("9e8ca414e088b2276d140bb69302269ccede242197e1f1751c45ec40b01678a0", Utils.bytesToHex(res.getPrivateKey().getData()));
    assertEquals("7147759d146897111bcf74f60a1948b1d3a22c9199a6b88c236eb7326adc2efc", Utils.bytesToHex(res.getPublicKey().getData()));
}
Also used : PoPToken(com.github.dedis.popstellar.model.objects.security.PoPToken) Wallet(com.github.dedis.popstellar.model.objects.Wallet) Test(org.junit.Test) HiltAndroidTest(dagger.hilt.android.testing.HiltAndroidTest)

Aggregations

PoPToken (com.github.dedis.popstellar.model.objects.security.PoPToken)12 Lao (com.github.dedis.popstellar.model.objects.Lao)7 KeyException (com.github.dedis.popstellar.utility.error.keys.KeyException)6 Channel (com.github.dedis.popstellar.model.objects.Channel)4 RollCall (com.github.dedis.popstellar.model.objects.RollCall)4 HiltAndroidTest (dagger.hilt.android.testing.HiltAndroidTest)4 Test (org.junit.Test)4 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)3 Disposable (io.reactivex.disposables.Disposable)3 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)2 Wallet (com.github.dedis.popstellar.model.objects.Wallet)2 InvalidPoPTokenException (com.github.dedis.popstellar.utility.error.keys.InvalidPoPTokenException)2 KeyGenerationException (com.github.dedis.popstellar.utility.error.keys.KeyGenerationException)2 UninitializedWalletException (com.github.dedis.popstellar.utility.error.keys.UninitializedWalletException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 Ed25519PrivateKeyParameters (org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters)2 Ed25519PublicKeyParameters (org.bouncycastle.crypto.params.Ed25519PublicKeyParameters)2 Bitmap (android.graphics.Bitmap)1 Nullable (androidx.annotation.Nullable)1 CastVote (com.github.dedis.popstellar.model.network.method.message.data.election.CastVote)1