mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 21:53:43 +00:00
Make signed prekey generation happen through the job queue.
This commit is contained in:
parent
b568ce70b2
commit
4cdc0a3e61
@ -29,6 +29,7 @@ import android.widget.ProgressBar;
|
|||||||
|
|
||||||
import org.thoughtcrime.securesms.crypto.DecryptingQueue;
|
import org.thoughtcrime.securesms.crypto.DecryptingQueue;
|
||||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
||||||
|
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
|
||||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
import org.whispersystems.textsecure.crypto.MasterSecret;
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||||
@ -47,12 +48,15 @@ public class DatabaseUpgradeActivity extends Activity {
|
|||||||
public static final int CURVE25519_VERSION = 63;
|
public static final int CURVE25519_VERSION = 63;
|
||||||
public static final int ASYMMETRIC_MASTER_SECRET_FIX_VERSION = 73;
|
public static final int ASYMMETRIC_MASTER_SECRET_FIX_VERSION = 73;
|
||||||
public static final int NO_V1_VERSION = 83;
|
public static final int NO_V1_VERSION = 83;
|
||||||
|
public static final int SIGNED_PREKEY_VERSION = 83;
|
||||||
|
|
||||||
private static final SortedSet<Integer> UPGRADE_VERSIONS = new TreeSet<Integer>() {{
|
private static final SortedSet<Integer> UPGRADE_VERSIONS = new TreeSet<Integer>() {{
|
||||||
add(NO_MORE_KEY_EXCHANGE_PREFIX_VERSION);
|
add(NO_MORE_KEY_EXCHANGE_PREFIX_VERSION);
|
||||||
add(TOFU_IDENTITIES_VERSION);
|
add(TOFU_IDENTITIES_VERSION);
|
||||||
add(CURVE25519_VERSION);
|
add(CURVE25519_VERSION);
|
||||||
add(ASYMMETRIC_MASTER_SECRET_FIX_VERSION);
|
add(ASYMMETRIC_MASTER_SECRET_FIX_VERSION);
|
||||||
|
add(NO_V1_VERSION);
|
||||||
|
add(SIGNED_PREKEY_VERSION);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
private MasterSecret masterSecret;
|
private MasterSecret masterSecret;
|
||||||
@ -155,6 +159,12 @@ public class DatabaseUpgradeActivity extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params[0] < SIGNED_PREKEY_VERSION) {
|
||||||
|
ApplicationContext.getInstance(getApplicationContext())
|
||||||
|
.getJobManager()
|
||||||
|
.add(new CreateSignedPreKeyJob(context, masterSecret));
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ public class RoutingActivity extends PassphraseRequiredSherlockActivity {
|
|||||||
private static final int STATE_CONVERSATION_OR_LIST = 3;
|
private static final int STATE_CONVERSATION_OR_LIST = 3;
|
||||||
private static final int STATE_UPGRADE_DATABASE = 4;
|
private static final int STATE_UPGRADE_DATABASE = 4;
|
||||||
private static final int STATE_PROMPT_PUSH_REGISTRATION = 5;
|
private static final int STATE_PROMPT_PUSH_REGISTRATION = 5;
|
||||||
private static final int STATE_CREATE_SIGNED_PREKEY = 6;
|
|
||||||
|
|
||||||
private MasterSecret masterSecret = null;
|
private MasterSecret masterSecret = null;
|
||||||
private boolean isVisible = false;
|
private boolean isVisible = false;
|
||||||
@ -169,21 +168,6 @@ public class RoutingActivity extends PassphraseRequiredSherlockActivity {
|
|||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
// private void scheduleRefreshActions() {
|
|
||||||
// if (TextSecurePreferences.isPushRegistered(this) &&
|
|
||||||
// TextSecurePreferences.getGcmRegistrationId(this) == null)
|
|
||||||
// {
|
|
||||||
// Intent intent = new Intent(this, GcmRegistrationService.class);
|
|
||||||
// startService(intent);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (TextSecurePreferences.isPushRegistered(this) &&
|
|
||||||
// !TextSecurePreferences.isSignedPreKeyRegistered(this))
|
|
||||||
// {
|
|
||||||
// PreKeyService.initiateCreateSigned(this, masterSecret);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private int getApplicationState() {
|
private int getApplicationState() {
|
||||||
if (!MasterSecretUtil.isPassphraseInitialized(this))
|
if (!MasterSecretUtil.isPassphraseInitialized(this))
|
||||||
return STATE_CREATE_PASSPHRASE;
|
return STATE_CREATE_PASSPHRASE;
|
||||||
|
@ -0,0 +1,66 @@
|
|||||||
|
package org.thoughtcrime.securesms.jobs;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
||||||
|
import org.thoughtcrime.securesms.push.PushServiceSocketFactory;
|
||||||
|
import org.thoughtcrime.securesms.util.ParcelUtil;
|
||||||
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
import org.whispersystems.jobqueue.EncryptionKeys;
|
||||||
|
import org.whispersystems.jobqueue.JobParameters;
|
||||||
|
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
||||||
|
import org.whispersystems.libaxolotl.IdentityKeyPair;
|
||||||
|
import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
|
||||||
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||||
|
import org.whispersystems.textsecure.crypto.PreKeyUtil;
|
||||||
|
import org.whispersystems.textsecure.push.PushServiceSocket;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class CreateSignedPreKeyJob extends ContextJob {
|
||||||
|
|
||||||
|
private static final String TAG = CreateSignedPreKeyJob.class.getSimpleName();
|
||||||
|
|
||||||
|
public CreateSignedPreKeyJob(Context context, MasterSecret masterSecret) {
|
||||||
|
super(context, JobParameters.newBuilder()
|
||||||
|
.withPersistence()
|
||||||
|
.withRequirement(new NetworkRequirement(context))
|
||||||
|
.withEncryption(new EncryptionKeys(ParcelUtil.serialize(masterSecret)))
|
||||||
|
.withGroupId(CreateSignedPreKeyJob.class.getSimpleName())
|
||||||
|
.create());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAdded() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRun() throws Throwable {
|
||||||
|
MasterSecret masterSecret = ParcelUtil.deserialize(getEncryptionKeys().getEncoded(), MasterSecret.CREATOR);
|
||||||
|
|
||||||
|
if (TextSecurePreferences.isSignedPreKeyRegistered(context)) {
|
||||||
|
Log.w(TAG, "Signed prekey already registered...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
IdentityKeyPair identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context, masterSecret);
|
||||||
|
SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, masterSecret, identityKeyPair);
|
||||||
|
PushServiceSocket socket = PushServiceSocketFactory.create(context);
|
||||||
|
|
||||||
|
socket.setCurrentSignedPreKey(signedPreKeyRecord);
|
||||||
|
TextSecurePreferences.setSignedPreKeyRegistered(context, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCanceled() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onShouldRetry(Throwable throwable) {
|
||||||
|
if (throwable instanceof IOException) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.w(TAG, throwable);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user