Search in sources :

Example 1 with IdentityKeyPair

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

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

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

the class IdentityKeyUtil method getIdentityKeyPair.

@NonNull
public static IdentityKeyPair getIdentityKeyPair(@NonNull Context context) {
    if (!hasIdentityKey(context))
        throw new AssertionError("There isn't one!");
    try {
        IdentityKey publicKey = getIdentityKey(context);
        ECPrivateKey privateKey = Curve.decodePrivatePoint(Base64.decode(retrieve(context, IDENTITY_PRIVATE_KEY_PREF)));
        return new IdentityKeyPair(publicKey, privateKey);
    } catch (IOException 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) NonNull(android.support.annotation.NonNull)

Example 3 with IdentityKeyPair

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

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

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

the class IdentityKeyUtil method getIdentityKeyPair.

@NonNull
public static IdentityKeyPair getIdentityKeyPair(@NonNull Context context) {
    if (!hasIdentityKey(context))
        throw new AssertionError("There isn't one!");
    try {
        IdentityKey publicKey = getIdentityKey(context);
        ECPrivateKey privateKey = Curve.decodePrivatePoint(Base64.decode(retrieve(context, IDENTITY_PRIVATE_KEY_PREF)));
        return new IdentityKeyPair(publicKey, privateKey);
    } catch (IOException 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) NonNull(android.support.annotation.NonNull)

Example 5 with IdentityKeyPair

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

the class RegistrationActivity method verifyAccount.

private void verifyAccount(@NonNull String code, @Nullable String pin) throws IOException {
    int registrationId = KeyHelper.generateRegistrationId(false);
    TextSecurePreferences.setLocalRegistrationId(RegistrationActivity.this, registrationId);
    SessionUtil.archiveAllSessions(RegistrationActivity.this);
    String signalingKey = Util.getSecret(52);
    accountManager.verifyAccountWithCode(code, signalingKey, registrationId, !registrationState.gcmToken.isPresent(), pin);
    IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(RegistrationActivity.this);
    List<PreKeyRecord> records = PreKeyUtil.generatePreKeys(RegistrationActivity.this);
    SignedPreKeyRecord signedPreKey = PreKeyUtil.generateSignedPreKey(RegistrationActivity.this, identityKey, true);
    accountManager.setPreKeys(identityKey.getPublicKey(), signedPreKey, records);
    if (registrationState.gcmToken.isPresent()) {
        accountManager.setGcmId(registrationState.gcmToken);
    }
    TextSecurePreferences.setGcmRegistrationId(RegistrationActivity.this, registrationState.gcmToken.orNull());
    TextSecurePreferences.setGcmDisabled(RegistrationActivity.this, !registrationState.gcmToken.isPresent());
    TextSecurePreferences.setWebsocketRegistered(RegistrationActivity.this, true);
    DatabaseFactory.getIdentityDatabase(RegistrationActivity.this).saveIdentity(Address.fromSerialized(registrationState.e164number), identityKey.getPublicKey(), IdentityDatabase.VerifiedStatus.VERIFIED, true, System.currentTimeMillis(), true);
    TextSecurePreferences.setVerifying(RegistrationActivity.this, false);
    TextSecurePreferences.setPushRegistered(RegistrationActivity.this, true);
    TextSecurePreferences.setLocalNumber(RegistrationActivity.this, registrationState.e164number);
    TextSecurePreferences.setPushServerPassword(RegistrationActivity.this, registrationState.password);
    TextSecurePreferences.setSignalingKey(RegistrationActivity.this, signalingKey);
    TextSecurePreferences.setSignedPreKeyRegistered(RegistrationActivity.this, true);
    TextSecurePreferences.setPromptedPushRegistration(RegistrationActivity.this, true);
    TextSecurePreferences.setUnauthorizedReceived(RegistrationActivity.this, false);
}
Also used : SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) PreKeyRecord(org.whispersystems.libsignal.state.PreKeyRecord) SpannableString(android.text.SpannableString) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint)

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