Search in sources :

Example 21 with IdentityKeyPair

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

the class RegistrationService method handleCommonRegistration.

private void handleCommonRegistration(SignalServiceAccountManager accountManager, String number, String password, String signalingKey, boolean supportsGcm) throws IOException {
    setState(new RegistrationState(RegistrationState.STATE_GENERATING_KEYS, number));
    Recipient self = RecipientFactory.getRecipientsFromString(this, number, false).getPrimaryRecipient();
    IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(this);
    List<PreKeyRecord> records = PreKeyUtil.generatePreKeys(this);
    PreKeyRecord lastResort = PreKeyUtil.generateLastResortKey(this);
    SignedPreKeyRecord signedPreKey = PreKeyUtil.generateSignedPreKey(this, identityKey, true);
    accountManager.setPreKeys(identityKey.getPublicKey(), lastResort, signedPreKey, records);
    setState(new RegistrationState(RegistrationState.STATE_GCM_REGISTERING, number));
    if (supportsGcm) {
        String gcmRegistrationId = GoogleCloudMessaging.getInstance(this).register(GcmRefreshJob.REGISTRATION_ID);
        accountManager.setGcmId(Optional.of(gcmRegistrationId));
        TextSecurePreferences.setGcmRegistrationId(this, gcmRegistrationId);
        TextSecurePreferences.setGcmDisabled(this, false);
    } else {
        TextSecurePreferences.setGcmDisabled(this, true);
    }
    TextSecurePreferences.setWebsocketRegistered(this, true);
    DatabaseFactory.getIdentityDatabase(this).saveIdentity(self.getRecipientId(), identityKey.getPublicKey());
    DirectoryHelper.refreshDirectory(this, accountManager, number);
    DirectoryRefreshListener.schedule(this);
    RotateSignedPreKeyListener.schedule(this);
}
Also used : PreKeyRecord(org.whispersystems.libsignal.state.PreKeyRecord) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord)

Example 22 with IdentityKeyPair

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

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 23 with IdentityKeyPair

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

the class IdentityKeyUtil method getLegacyIdentityKeyPair.

private static IdentityKeyPair getLegacyIdentityKeyPair(@NonNull Context context, @NonNull MasterSecret masterSecret) {
    try {
        MasterCipher masterCipher = new MasterCipher(masterSecret);
        byte[] publicKeyBytes = Base64.decode(retrieve(context, IDENTITY_PUBLIC_KEY_CIPHERTEXT_LEGACY_PREF));
        IdentityKey identityKey = new IdentityKey(publicKeyBytes, 0);
        ECPrivateKey privateKey = masterCipher.decryptKey(Base64.decode(retrieve(context, IDENTITY_PRIVATE_KEY_CIPHERTEXT_LEGACY_PREF)));
        return new IdentityKeyPair(identityKey, privateKey);
    } catch (IOException | InvalidKeyException e) {
        throw new AssertionError(e);
    }
}
Also used : ECPrivateKey(org.whispersystems.libsignal.ecc.ECPrivateKey) IdentityKey(org.whispersystems.libsignal.IdentityKey) IOException(java.io.IOException) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException)

Example 24 with IdentityKeyPair

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

the class IdentityKeyUtil method migrateIdentityKeys.

public static void migrateIdentityKeys(@NonNull Context context, @NonNull MasterSecret masterSecret) {
    if (!hasIdentityKey(context)) {
        if (hasLegacyIdentityKeys(context)) {
            IdentityKeyPair legacyPair = getLegacyIdentityKeyPair(context, masterSecret);
            save(context, IDENTITY_PUBLIC_KEY_PREF, Base64.encodeBytes(legacyPair.getPublicKey().serialize()));
            save(context, IDENTITY_PRIVATE_KEY_PREF, Base64.encodeBytes(legacyPair.getPrivateKey().serialize()));
            delete(context, IDENTITY_PUBLIC_KEY_CIPHERTEXT_LEGACY_PREF);
            delete(context, IDENTITY_PRIVATE_KEY_CIPHERTEXT_LEGACY_PREF);
        } else {
            generateIdentityKeys(context);
        }
    }
}
Also used : IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair)

Example 25 with IdentityKeyPair

use of org.whispersystems.libsignal.IdentityKeyPair in project toshi-android-client by toshiapp.

the class ProtocolStore method generateIdentityKeyPair.

private IdentityKeyPair generateIdentityKeyPair() {
    final IdentityKeyPair ikp = KeyHelper.generateIdentityKeyPair();
    SignalPreferences.setSerializedIdentityKeyPair(ikp.serialize());
    return ikp;
}
Also used : IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair)

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