From 01f5ff7c865213405774325cc085d2736374b52b Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 28 Jan 2020 12:27:12 +1100 Subject: [PATCH] Fix up build gradle. --- .../crypto/UnidentifiedAccessUtil.java | 19 +++++++++++++++-- .../securesms/jobs/PushSendJob.java | 21 +------------------ 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/org/thoughtcrime/securesms/crypto/UnidentifiedAccessUtil.java b/src/org/thoughtcrime/securesms/crypto/UnidentifiedAccessUtil.java index 141ec67de5..6f8f5e9e65 100644 --- a/src/org/thoughtcrime/securesms/crypto/UnidentifiedAccessUtil.java +++ b/src/org/thoughtcrime/securesms/crypto/UnidentifiedAccessUtil.java @@ -6,6 +6,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.WorkerThread; +import org.signal.libsignal.metadata.SignalProtos; import org.signal.libsignal.metadata.certificate.CertificateValidator; import org.signal.libsignal.metadata.certificate.InvalidCertificateException; import network.loki.messenger.BuildConfig; @@ -20,6 +21,7 @@ import org.whispersystems.libsignal.ecc.ECPublicKey; import org.whispersystems.libsignal.util.guava.Optional; import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess; import org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair; +import org.whispersystems.signalservice.api.push.SignalServiceAddress; import java.io.IOException; @@ -48,7 +50,7 @@ public class UnidentifiedAccessUtil { try { byte[] theirUnidentifiedAccessKey = getTargetUnidentifiedAccessKey(recipient); byte[] ourUnidentifiedAccessKey = getSelfUnidentifiedAccessKey(context); - byte[] ourUnidentifiedAccessCertificate = TextSecurePreferences.getUnidentifiedAccessCertificate(context); + byte[] ourUnidentifiedAccessCertificate = getUnidentifiedAccessCertificate(context); if (TextSecurePreferences.isUniversalUnidentifiedAccess(context)) { ourUnidentifiedAccessKey = Util.getSecretBytes(16); @@ -83,7 +85,7 @@ public class UnidentifiedAccessUtil { try { byte[] ourUnidentifiedAccessKey = getSelfUnidentifiedAccessKey(context); - byte[] ourUnidentifiedAccessCertificate = TextSecurePreferences.getUnidentifiedAccessCertificate(context); + byte[] ourUnidentifiedAccessCertificate = getUnidentifiedAccessCertificate(context); if (TextSecurePreferences.isUniversalUnidentifiedAccess(context)) { ourUnidentifiedAccessKey = Util.getSecretBytes(16); @@ -125,4 +127,17 @@ public class UnidentifiedAccessUtil { throw new AssertionError("Unknown mode: " + recipient.getUnidentifiedAccessMode().getMode()); } } + + private static @Nullable byte[] getUnidentifiedAccessCertificate(Context context) { + String ourNumber = TextSecurePreferences.getLocalNumber(context); + if (ourNumber != null) { + SignalProtos.SenderCertificate certificate = SignalProtos.SenderCertificate.newBuilder() + .setSender(ourNumber) + .setSenderDevice(SignalServiceAddress.DEFAULT_DEVICE_ID) + .build(); + return certificate.toByteArray(); + } + + return null; + } } diff --git a/src/org/thoughtcrime/securesms/jobs/PushSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushSendJob.java index 526264ef67..591e3f43f8 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushSendJob.java @@ -280,26 +280,7 @@ public abstract class PushSendJob extends SendJob { } protected void rotateSenderCertificateIfNecessary() throws IOException { - try { - byte[] certificateBytes = TextSecurePreferences.getUnidentifiedAccessCertificate(context); - - if (certificateBytes == null) { - throw new InvalidCertificateException("No certificate was present."); - } - - SenderCertificate certificate = new SenderCertificate(certificateBytes); - - if (System.currentTimeMillis() > (certificate.getExpiration() - CERTIFICATE_EXPIRATION_BUFFER)) { - throw new InvalidCertificateException("Certificate is expired, or close to it. Expires on: " + certificate.getExpiration() + ", currently: " + System.currentTimeMillis()); - } - - Log.d(TAG, "Certificate is valid."); - } catch (InvalidCertificateException e) { - Log.w(TAG, "Certificate was invalid at send time. Fetching a new one.", e); - RotateCertificateJob certificateJob = new RotateCertificateJob(context); - ApplicationContext.getInstance(context).injectDependencies(certificateJob); - certificateJob.onRun(); - } + // Loki - We don't need verification on sender certificates } protected SignalServiceSyncMessage buildSelfSendSyncMessage(@NonNull Context context, @NonNull SignalServiceDataMessage message, Optional syncAccess) {