mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-25 02:55:23 +00:00
67 lines
2.4 KiB
Java
67 lines
2.4 KiB
Java
|
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;
|
||
|
}
|
||
|
}
|