Archive sessions and generate new registration id on re-register

Fixes #6703
// FREEBIE
fork-5.53.8
Moxie Marlinspike 2017-07-05 13:12:59 -07:00
rodzic 39b95ca4ed
commit 2c4c0f1349
9 zmienionych plików z 39 dodań i 52 usunięć

Wyświetl plik

@ -61,7 +61,7 @@ dependencies {
compile 'org.whispersystems:jobmanager:1.0.2'
compile 'org.whispersystems:libpastelog:1.0.7'
compile 'org.whispersystems:signal-service-android:2.5.14'
compile 'org.whispersystems:signal-service-android:2.5.15'
compile 'org.whispersystems:webrtc-android:M59-S1'
compile "me.leolin:ShortcutBadger:1.1.16"
@ -135,7 +135,7 @@ dependencyVerification {
'com.google.android.exoplayer:exoplayer:955085aa611a8f7cf6c61b88ae03d1a392f4ad94c9bfbc153f3dedb9ffb14718',
'org.whispersystems:jobmanager:506f679fc2fcf7bb6d10f00f41d6f6ea0abf75c70dc95b913398661ad538a181',
'org.whispersystems:libpastelog:bb331d9a98240fc139101128ba836c1edec3c40e000597cdbb29ebf4cbf34d88',
'org.whispersystems:signal-service-android:85d7140c540f6ae03a493ba648cb6fbe8bff093e1ffafde6c6454aa021aeefb3',
'org.whispersystems:signal-service-android:335ba8dbe4253b4676a6a629d82cb39de8a646457290d9296939a0afd0bf6131',
'org.whispersystems:webrtc-android:de647643afbbea45a26a4f24db75aa10bc8de45426e8eb0d9d563cc10af4f582',
'me.leolin:ShortcutBadger:e3cb3e7625892129b0c92dd5e4bc649faffdd526d5af26d9c45ee31ff8851774',
'se.emilsjolander:stickylistheaders:a08ca948aa6b220f09d82f16bbbac395f6b78897e9eeac6a9f0b0ba755928eeb',
@ -169,7 +169,7 @@ dependencyVerification {
'com.google.android.gms:play-services-base:0ca636a8fc9a5af45e607cdcd61783bf5d561cbbb0f862021ce69606eee5ad49',
'com.google.android.gms:play-services-basement:95dd882c5ffba15b9a99de3fefb05d3a01946623af67454ca00055d222f85a8d',
'com.google.android.gms:play-services-iid:54e919f9957b8b7820da7ee9b83471d00d0cac1cf08ddea8b5b41aea80bb1a70',
'org.whispersystems:signal-service-java:837ce100e454f3fc09871204c66a9689d8287b7d7ae871fc7566fc3097d2cd20',
'org.whispersystems:signal-service-java:fc5e54216e85ad2d3b7d389d54d0945545e0c406078d409806e22ae8a7fe7105',
'org.whispersystems:signal-protocol-android:b05cd9570d2e262afeb6610b70f473a936c54dd23a7c967d76e8f288766731fd',
'com.nineoldandroids:library:68025a14e3e7673d6ad2f95e4b46d78d7d068343aa99256b686fe59de1b3163a',
'javax.inject:javax.inject:91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff',
@ -193,7 +193,6 @@ dependencyVerification {
]
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.0'

Wyświetl plik

@ -30,7 +30,6 @@ import org.thoughtcrime.securesms.dependencies.InjectableType;
import org.thoughtcrime.securesms.dependencies.SignalCommunicationModule;
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
import org.thoughtcrime.securesms.jobs.GcmRefreshJob;
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
import org.thoughtcrime.securesms.jobs.persistence.EncryptingJobSerializer;
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirementProvider;
import org.thoughtcrime.securesms.jobs.requirements.MediaNetworkRequirementProvider;
@ -90,7 +89,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
initializeSignedPreKeyCheck();
initializePeriodicTasks();
initializeCircumvention();
initializeSetVideoCapable();
initializeWebRtc();
}
@ -168,15 +166,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
}
}
private void initializeSetVideoCapable() {
if (TextSecurePreferences.isPushRegistered(this) &&
!TextSecurePreferences.isWebrtcCallingEnabled(this))
{
TextSecurePreferences.setWebrtcCallingEnabled(this, true);
jobManager.add(new RefreshAttributesJob(this));
}
}
private void initializeWebRtc() {
Set<String> HARDWARE_AEC_BLACKLIST = new HashSet<String>() {{
add("Pixel");

Wyświetl plik

@ -31,11 +31,13 @@ import android.widget.TextView;
import android.widget.Toast;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.SessionUtil;
import org.thoughtcrime.securesms.push.AccountManagerFactory;
import org.thoughtcrime.securesms.service.RegistrationService;
import org.thoughtcrime.securesms.util.Dialogs;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.libsignal.util.KeyHelper;
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
import org.whispersystems.signalservice.api.push.exceptions.ExpectationFailedException;
import org.whispersystems.signalservice.api.push.exceptions.RateLimitException;
@ -530,10 +532,12 @@ public class RegistrationProgressActivity extends BaseActionBarActivity {
protected Integer doInBackground(Void... params) {
try {
SignalServiceAccountManager accountManager = AccountManagerFactory.createManager(context, e164number, password);
int registrationId = TextSecurePreferences.getLocalRegistrationId(context);
boolean video = TextSecurePreferences.isWebrtcCallingEnabled(context);
int registrationId = KeyHelper.generateRegistrationId(false);
accountManager.verifyAccountWithCode(code, signalingKey, registrationId, true, video, !gcmSupported);
TextSecurePreferences.setLocalRegistrationId(context, registrationId);
SessionUtil.archiveAllSessions(context);
accountManager.verifyAccountWithCode(code, signalingKey, registrationId, !gcmSupported);
return SUCCESS;
} catch (ExpectationFailedException e) {

Wyświetl plik

@ -91,26 +91,6 @@ public class PreKeyUtil {
}
}
public static PreKeyRecord generateLastResortKey(Context context) {
PreKeyStore preKeyStore = new TextSecurePreKeyStore(context);
if (preKeyStore.containsPreKey(Medium.MAX_VALUE)) {
try {
return preKeyStore.loadPreKey(Medium.MAX_VALUE);
} catch (InvalidKeyIdException e) {
Log.w("PreKeyUtil", e);
preKeyStore.removePreKey(Medium.MAX_VALUE);
}
}
ECKeyPair keyPair = Curve.generateKeyPair();
PreKeyRecord record = new PreKeyRecord(Medium.MAX_VALUE, keyPair);
preKeyStore.storePreKey(Medium.MAX_VALUE, record);
return record;
}
private static synchronized void setNextPreKeyId(Context context, int id) {
try {
File nextFile = new File(getPreKeysDirectory(context), PreKeyIndex.FILE_NAME);

Wyświetl plik

@ -41,6 +41,9 @@ public class SessionUtil {
}
}
}
}
public static void archiveAllSessions(Context context) {
new TextSecureSessionStore(context).archiveAllSessions();
}
}

Wyświetl plik

@ -175,6 +175,24 @@ public class TextSecureSessionStore implements SessionStore {
}
}
public void archiveAllSessions() {
synchronized (FILE_LOCK) {
File directory = getSessionDirectory();
for (File session : directory.listFiles()) {
if (session.isFile()) {
SignalProtocolAddress address = getAddressName(session);
if (address != null) {
SessionRecord sessionRecord = loadSession(address);
sessionRecord.archiveCurrentState();
storeSession(address, sessionRecord);
}
}
}
}
}
private File getSessionFile(SignalProtocolAddress address) {
return new File(getSessionDirectory(), getSessionName(address));
}

Wyświetl plik

@ -39,10 +39,9 @@ public class RefreshAttributesJob extends ContextJob implements InjectableType {
public void onRun() throws IOException {
String signalingKey = TextSecurePreferences.getSignalingKey(context);
int registrationId = TextSecurePreferences.getLocalRegistrationId(context);
boolean video = TextSecurePreferences.isWebrtcCallingEnabled(context);
boolean fetchesMessages = TextSecurePreferences.isGcmDisabled(context);
signalAccountManager.setAccountAttributes(signalingKey, registrationId, true, video || fetchesMessages, fetchesMessages);
signalAccountManager.setAccountAttributes(signalingKey, registrationId, fetchesMessages);
}
@Override

Wyświetl plik

@ -58,13 +58,12 @@ public class RefreshPreKeysJob extends MasterSecretJob implements InjectableType
}
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);
accountManager.setPreKeys(identityKey.getPublicKey(), signedPreKeyRecord, preKeyRecords);
PreKeyUtil.setActiveSignedPreKeyId(context, signedPreKeyRecord.getId());
TextSecurePreferences.setSignedPreKeyRegistered(context, true);

Wyświetl plik

@ -15,6 +15,7 @@ import com.google.android.gms.gcm.GoogleCloudMessaging;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
import org.thoughtcrime.securesms.crypto.PreKeyUtil;
import org.thoughtcrime.securesms.crypto.SessionUtil;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.IdentityDatabase;
import org.thoughtcrime.securesms.jobs.GcmRefreshJob;
@ -188,13 +189,9 @@ public class RegistrationService extends Service {
String number = intent.getStringExtra(NUMBER_EXTRA);
boolean supportsGcm = intent.getBooleanExtra(GCM_SUPPORTED_EXTRA, true);
int registrationId = TextSecurePreferences.getLocalRegistrationId(this);
boolean supportsVideo = TextSecurePreferences.isWebrtcCallingEnabled(this) || !supportsGcm;
if (registrationId == 0) {
registrationId = KeyHelper.generateRegistrationId(false);
TextSecurePreferences.setLocalRegistrationId(this, registrationId);
}
int registrationId = KeyHelper.generateRegistrationId(false);
TextSecurePreferences.setLocalRegistrationId(this, registrationId);
SessionUtil.archiveAllSessions(this);
try {
String password = Util.getSecret(18);
@ -208,7 +205,7 @@ public class RegistrationService extends Service {
setState(new RegistrationState(RegistrationState.STATE_VERIFYING, number));
String challenge = waitForChallenge();
accountManager.verifyAccountWithCode(challenge, signalingKey, registrationId, true, supportsVideo, !supportsGcm);
accountManager.verifyAccountWithCode(challenge, signalingKey, registrationId, !supportsGcm);
handleCommonRegistration(accountManager, number, password, signalingKey, supportsGcm);
markAsVerified(number, password, signalingKey);
@ -243,9 +240,8 @@ public class RegistrationService extends Service {
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);
accountManager.setPreKeys(identityKey.getPublicKey(), signedPreKey, records);
setState(new RegistrationState(RegistrationState.STATE_GCM_REGISTERING, number));