Search in sources :

Example 16 with IdentityKeyPair

use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.

the class MobileCoinPublicAddressProfileUtilTest method can_not_verify_a_tampered_signature.

@Test
public void can_not_verify_a_tampered_signature() {
    IdentityKeyPair identityKeyPair = IdentityKeyUtil.generateIdentityKeyPair();
    byte[] address = Util.getSecretBytes(100);
    SignalServiceProtos.PaymentAddress signedPaymentAddress = MobileCoinPublicAddressProfileUtil.signPaymentsAddress(address, identityKeyPair);
    byte[] signature = signedPaymentAddress.getMobileCoinAddress().getSignature().toByteArray();
    signature[0] = (byte) (signature[0] ^ 0x01);
    SignalServiceProtos.PaymentAddress tamperedSignature = signedPaymentAddress.toBuilder().setMobileCoinAddress(signedPaymentAddress.getMobileCoinAddress().toBuilder().setSignature(ByteString.copyFrom(signature))).build();
    assertThatThrownBy(() -> MobileCoinPublicAddressProfileUtil.verifyPaymentsAddress(tamperedSignature, identityKeyPair.getPublicKey())).isInstanceOf(PaymentsAddressException.class).hasMessage("Invalid MobileCoin address signature on payments address proto");
}
Also used : SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) Test(org.junit.Test)

Example 17 with IdentityKeyPair

use of org.whispersystems.libsignal.IdentityKeyPair in project Smack by igniterealtime.

the class LegacySignalOmemoKeyUtilTest method generateOmemoSignedPreKeyTest.

@Test
public void generateOmemoSignedPreKeyTest() {
    IdentityKeyPair ikp = keyUtil.generateOmemoIdentityKeyPair();
    try {
        SignedPreKeyRecord spk = keyUtil.generateOmemoSignedPreKey(ikp, 1);
        assertNotNull("SignedPreKey must not be null.", spk);
        assertEquals("SignedPreKeyId must match.", 1, spk.getId());
        assertEquals("singedPreKeyId must match here also.", 1, keyUtil.signedPreKeyIdFromKey(spk));
    } catch (CorruptedOmemoKeyException e) {
        fail("Caught an exception while generating signedPreKey (" + e + "): " + e.getMessage());
    }
}
Also used : IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) CorruptedOmemoKeyException(org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException) Test(org.junit.Test)

Example 18 with IdentityKeyPair

use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.

the class CreateSignedPreKeyJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) throws IOException {
    if (TextSecurePreferences.isSignedPreKeyRegistered(context)) {
        Log.w(TAG, "Signed prekey already registered...");
        return;
    }
    if (!TextSecurePreferences.isPushRegistered(context)) {
        Log.w(TAG, "Not yet registered...");
        return;
    }
    IdentityKeyPair identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context);
    SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, identityKeyPair, true);
    accountManager.setSignedPreKey(signedPreKeyRecord);
    TextSecurePreferences.setSignedPreKeyRegistered(context, true);
}
Also used : IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord)

Example 19 with IdentityKeyPair

use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.

the class RefreshPreKeysJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) throws IOException {
    if (!TextSecurePreferences.isPushRegistered(context))
        return;
    int availableKeys = accountManager.getPreKeysCount();
    if (availableKeys >= PREKEY_MINIMUM && TextSecurePreferences.isSignedPreKeyRegistered(context)) {
        Log.w(TAG, "Available keys sufficient: " + availableKeys);
        return;
    }
    List<PreKeyRecord> preKeyRecords = PreKeyUtil.generatePreKeys(context);
    PreKeyRecord lastResortKeyRecord = PreKeyUtil.generateLastResortKey(context);
    IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context);
    SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, identityKey, false);
    Log.w(TAG, "Registering new prekeys...");
    accountManager.setPreKeys(identityKey.getPublicKey(), lastResortKeyRecord, signedPreKeyRecord, preKeyRecords);
    PreKeyUtil.setActiveSignedPreKeyId(context, signedPreKeyRecord.getId());
    TextSecurePreferences.setSignedPreKeyRegistered(context, true);
    ApplicationContext.getInstance(context).getJobManager().add(new CleanPreKeysJob(context));
}
Also used : PreKeyRecord(org.whispersystems.libsignal.state.PreKeyRecord) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord)

Example 20 with IdentityKeyPair

use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.

the class RotateSignedPreKeyJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) throws Exception {
    Log.w(TAG, "Rotating signed prekey...");
    IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context);
    SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, identityKey, false);
    accountManager.setSignedPreKey(signedPreKeyRecord);
    PreKeyUtil.setActiveSignedPreKeyId(context, signedPreKeyRecord.getId());
    TextSecurePreferences.setSignedPreKeyRegistered(context, true);
    TextSecurePreferences.setSignedPreKeyFailureCount(context, 0);
    ApplicationContext.getInstance(context).getJobManager().add(new CleanPreKeysJob(context));
}
Also used : IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord)

Aggregations

IdentityKeyPair (org.whispersystems.libsignal.IdentityKeyPair)40 SignedPreKeyRecord (org.whispersystems.libsignal.state.SignedPreKeyRecord)12 Test (org.junit.Test)9 IdentityKey (org.whispersystems.libsignal.IdentityKey)9 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)8 PreKeyRecord (org.whispersystems.libsignal.state.PreKeyRecord)7 IOException (java.io.IOException)6 SignalServiceProtos (org.whispersystems.signalservice.internal.push.SignalServiceProtos)6 ECPrivateKey (org.whispersystems.libsignal.ecc.ECPrivateKey)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 SuppressLint (android.annotation.SuppressLint)3 ECKeyPair (org.whispersystems.libsignal.ecc.ECKeyPair)3 SignalServiceAccountManager (org.whispersystems.signalservice.api.SignalServiceAccountManager)3 ContentValues (android.content.ContentValues)2 Context (android.content.Context)2 Cursor (android.database.Cursor)2 NonNull (android.support.annotation.NonNull)2 Account (de.pixart.messenger.entities.Account)2 Account (eu.siacs.conversations.entities.Account)2