Search in sources :

Example 6 with SignedPreKeyRecord

use of org.whispersystems.libsignal.state.SignedPreKeyRecord 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)

Example 7 with SignedPreKeyRecord

use of org.whispersystems.libsignal.state.SignedPreKeyRecord 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 8 with SignedPreKeyRecord

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

the class TextSecurePreKeyStore method migrateRecords.

public void migrateRecords() {
    synchronized (FILE_LOCK) {
        File preKeyRecords = getPreKeyDirectory();
        for (File preKeyRecord : preKeyRecords.listFiles()) {
            try {
                int preKeyId = Integer.parseInt(preKeyRecord.getName());
                PreKeyRecord record = loadPreKey(preKeyId);
                storePreKey(preKeyId, record);
            } catch (InvalidKeyIdException | NumberFormatException e) {
                Log.w(TAG, e);
            }
        }
        File signedPreKeyRecords = getSignedPreKeyDirectory();
        for (File signedPreKeyRecord : signedPreKeyRecords.listFiles()) {
            try {
                int signedPreKeyId = Integer.parseInt(signedPreKeyRecord.getName());
                SignedPreKeyRecord record = loadSignedPreKey(signedPreKeyId);
                storeSignedPreKey(signedPreKeyId, record);
            } catch (InvalidKeyIdException | NumberFormatException e) {
                Log.w(TAG, e);
            }
        }
    }
}
Also used : PreKeyRecord(org.whispersystems.libsignal.state.PreKeyRecord) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) InvalidKeyIdException(org.whispersystems.libsignal.InvalidKeyIdException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord)

Aggregations

SignedPreKeyRecord (org.whispersystems.libsignal.state.SignedPreKeyRecord)8 IdentityKeyPair (org.whispersystems.libsignal.IdentityKeyPair)4 PreKeyRecord (org.whispersystems.libsignal.state.PreKeyRecord)3 File (java.io.File)2 RandomAccessFile (java.io.RandomAccessFile)2 InvalidKeyIdException (org.whispersystems.libsignal.InvalidKeyIdException)2 SignedPreKeyStore (org.whispersystems.libsignal.state.SignedPreKeyStore)2 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 TextSecurePreKeyStore (org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)1 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)1 ECKeyPair (org.whispersystems.libsignal.ecc.ECKeyPair)1