From 04f140ee0972465124b300265caf5fbddd49afeb Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Mon, 22 Feb 2021 09:31:29 +1100 Subject: [PATCH] WIP: clean up signal service protos --- app/src/main/AndroidManifest.xml | 3 - .../securesms/ApplicationContext.java | 12 +- .../SignalCommunicationModule.java | 22 +- .../jobs/PushNotificationReceiveJob.java | 90 - .../service/IncomingMessageObserver.java | 210 -- .../utilities/TextSecurePreferences.kt | 12 - .../service/api/SignalServiceMessagePipe.java | 275 --- .../api/SignalServiceMessageReceiver.java | 166 -- .../api/SignalServiceMessageSender.java | 16 +- .../service/api/push/ContactTokenDetails.java | 69 - .../service/api/push/SignedPreKeyEntity.java | 57 - .../AuthorizationFailedException.java | 15 - .../exceptions/CaptchaRequiredException.java | 6 - .../exceptions/EncapsulatedExceptions.java | 49 - .../ExpectationFailedException.java | 11 - .../exceptions/NetworkFailureException.java | 21 - .../NonSuccessfulResponseCodeException.java | 4 - .../push/exceptions/NotFoundException.java | 13 - .../push/exceptions/RateLimitException.java | 15 - ...teAttestationResponseExpiredException.java | 13 - .../internal/push/AccountAttributes.java | 81 - .../push/AttachmentUploadAttributes.java | 78 - .../push/ContactDiscoveryCredentials.java | 28 - .../push/ContactDiscoveryFailureReason.java | 13 - .../push/ContactTokenDetailsList.java | 25 - .../internal/push/ContactTokenList.java | 24 - .../service/internal/push/DeviceCode.java | 13 - .../service/internal/push/DeviceLimit.java | 20 - .../push/DeviceLimitExceededException.java | 20 - .../internal/push/LockedException.java | 23 - .../internal/push/MismatchedDevices.java | 27 - .../service/internal/push/PreKeyEntity.java | 68 - .../service/internal/push/PreKeyResponse.java | 37 - .../internal/push/PreKeyResponseItem.java | 43 - .../service/internal/push/PreKeyState.java | 33 - .../service/internal/push/PreKeyStatus.java | 21 - .../push/ProfileAvatarUploadAttributes.java | 64 - .../internal/push/ProvisioningMessage.java | 14 - .../internal/push/ProvisioningProtos.java | 1698 ----------------- .../internal/push/PushServiceSocket.java | 669 ------- .../internal/push/SendMessageResponse.java | 16 - .../internal/push/SenderCertificate.java | 45 - .../push/SignalServiceEnvelopeEntity.java | 57 - .../push/SignalServiceEnvelopeEntityList.java | 14 - .../service/internal/push/StaleDevices.java | 21 - .../MismatchedDevicesException.java | 23 - .../exceptions/StaleDevicesException.java | 23 - 47 files changed, 4 insertions(+), 4273 deletions(-) delete mode 100644 app/src/main/java/org/thoughtcrime/securesms/jobs/PushNotificationReceiveJob.java delete mode 100644 app/src/main/java/org/thoughtcrime/securesms/service/IncomingMessageObserver.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/api/SignalServiceMessagePipe.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/api/push/ContactTokenDetails.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/api/push/SignedPreKeyEntity.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/AuthorizationFailedException.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/CaptchaRequiredException.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/EncapsulatedExceptions.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/ExpectationFailedException.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/NetworkFailureException.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/NotFoundException.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/RateLimitException.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/RemoteAttestationResponseExpiredException.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/AccountAttributes.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/AttachmentUploadAttributes.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/ContactDiscoveryCredentials.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/ContactDiscoveryFailureReason.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/ContactTokenDetailsList.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/ContactTokenList.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/DeviceCode.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/DeviceLimit.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/DeviceLimitExceededException.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/LockedException.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/MismatchedDevices.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyEntity.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyResponse.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyResponseItem.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyState.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyStatus.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/ProfileAvatarUploadAttributes.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/ProvisioningMessage.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/ProvisioningProtos.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/PushServiceSocket.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/SendMessageResponse.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/SenderCertificate.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/SignalServiceEnvelopeEntity.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/SignalServiceEnvelopeEntityList.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/StaleDevices.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/exceptions/MismatchedDevicesException.java delete mode 100644 libsignal/src/main/java/org/session/libsignal/service/internal/push/exceptions/StaleDevicesException.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ccced9814e..13e143ebe6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -382,9 +382,6 @@ android:name="org.thoughtcrime.securesms.service.KeyCachingService" android:enabled="true" android:exported="false" /> - diff --git a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java index 1e27dd7822..c9dd0ce359 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java +++ b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java @@ -84,7 +84,6 @@ import org.thoughtcrime.securesms.notifications.OptimizedMessageNotifier; import org.thoughtcrime.securesms.providers.BlobProvider; import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess; import org.thoughtcrime.securesms.service.ExpiringMessageManager; -import org.thoughtcrime.securesms.service.IncomingMessageObserver; import org.thoughtcrime.securesms.service.KeyCachingService; import org.thoughtcrime.securesms.service.LocalBackupListener; import org.thoughtcrime.securesms.service.UpdateApkRefreshListener; @@ -206,7 +205,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc initializeProfileManager(); initializePeriodicTasks(); initializeWebRtc(); - initializePendingMessages(); initializeBlobProvider(); SSKEnvironment.Companion.configure(getTypingStatusRepository(), getReadReceiptManager(), getProfileManager(), messageNotifier, getExpiringMessageManager()); } @@ -340,7 +338,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc } private void initializeDependencyInjection() { - communicationModule = new SignalCommunicationModule(this, new SignalServiceNetworkAccess(this)); + communicationModule = new SignalCommunicationModule(this); this.objectGraph = ObjectGraph.create(communicationModule); } @@ -409,14 +407,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc } } - private void initializePendingMessages() { - if (TextSecurePreferences.getNeedsMessagePull(this)) { - Log.i(TAG, "Scheduling a message fetch."); - ApplicationContext.getInstance(this).getJobManager().add(new PushNotificationReceiveJob(this)); - TextSecurePreferences.setNeedsMessagePull(this, false); - } - } - private void initializeBlobProvider() { AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> { BlobProvider.getInstance().onSessionStart(this); diff --git a/app/src/main/java/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java b/app/src/main/java/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java index 2d0fe001ba..1e2aab477f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java +++ b/app/src/main/java/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java @@ -19,7 +19,6 @@ import org.thoughtcrime.securesms.jobs.PushDecryptJob; import org.thoughtcrime.securesms.jobs.PushGroupSendJob; import org.thoughtcrime.securesms.jobs.PushGroupUpdateJob; import org.thoughtcrime.securesms.jobs.PushMediaSendJob; -import org.thoughtcrime.securesms.jobs.PushNotificationReceiveJob; import org.thoughtcrime.securesms.jobs.PushTextSendJob; import org.thoughtcrime.securesms.jobs.RequestGroupInfoJob; import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob; @@ -32,9 +31,7 @@ import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository; import org.session.libsignal.utilities.logging.Log; import org.thoughtcrime.securesms.loki.api.SessionProtocolImpl; import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment; -import org.thoughtcrime.securesms.push.MessageSenderEventListener; import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess; -import org.thoughtcrime.securesms.service.IncomingMessageObserver; import org.thoughtcrime.securesms.stickers.StickerPackPreviewRepository; import org.thoughtcrime.securesms.stickers.StickerRemoteUriLoader; import org.thoughtcrime.securesms.util.RealtimeSleepTimer; @@ -48,8 +45,6 @@ import network.loki.messenger.BuildConfig; PushTextSendJob.class, PushMediaSendJob.class, AttachmentDownloadJob.class, - IncomingMessageObserver.class, - PushNotificationReceiveJob.class, RequestGroupInfoJob.class, PushGroupUpdateJob.class, AvatarDownloadJob.class, @@ -71,15 +66,12 @@ public class SignalCommunicationModule { private static final String TAG = SignalCommunicationModule.class.getSimpleName(); private final Context context; - private final SignalServiceNetworkAccess networkAccess; private SignalServiceMessageSender messageSender; private SignalServiceMessageReceiver messageReceiver; - public SignalCommunicationModule(Context context, SignalServiceNetworkAccess networkAccess) { + public SignalCommunicationModule(Context context) { this.context = context; - this.networkAccess = networkAccess; - } @Provides @@ -87,8 +79,6 @@ public class SignalCommunicationModule { if (this.messageSender == null) { this.messageSender = new SignalServiceMessageSender(new DynamicCredentialsProvider(context), new SignalProtocolStoreImpl(context), - Optional.fromNullable(IncomingMessageObserver.getPipe()), - Optional.fromNullable(IncomingMessageObserver.getUnidentifiedPipe()), TextSecurePreferences.getLocalNumber(context), DatabaseFactory.getLokiAPIDatabase(context), DatabaseFactory.getLokiThreadDatabase(context), @@ -97,8 +87,6 @@ public class SignalCommunicationModule { DatabaseFactory.getLokiUserDatabase(context), DatabaseFactory.getGroupDatabase(context), ((ApplicationContext)context.getApplicationContext()).broadcaster); - } else { - this.messageSender.setMessagePipe(IncomingMessageObserver.getPipe(), IncomingMessageObserver.getUnidentifiedPipe()); } return this.messageSender; @@ -109,8 +97,7 @@ public class SignalCommunicationModule { if (this.messageReceiver == null) { SleepTimer sleepTimer = TextSecurePreferences.isFcmDisabled(context) ? new RealtimeSleepTimer(context) : new UptimeSleepTimer(); - this.messageReceiver = new SignalServiceMessageReceiver(networkAccess.getConfiguration(context), - new DynamicCredentialsProvider(context), + this.messageReceiver = new SignalServiceMessageReceiver(new DynamicCredentialsProvider(context), BuildConfig.USER_AGENT, new PipeConnectivityListener(), sleepTimer); @@ -119,11 +106,6 @@ public class SignalCommunicationModule { return this.messageReceiver; } - @Provides - synchronized SignalServiceNetworkAccess provideSignalServiceNetworkAccess() { - return networkAccess; - } - private static class DynamicCredentialsProvider implements CredentialsProvider { private final Context context; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushNotificationReceiveJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushNotificationReceiveJob.java deleted file mode 100644 index 2ab93d174c..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushNotificationReceiveJob.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.thoughtcrime.securesms.jobs; - -import android.content.Context; -import androidx.annotation.NonNull; - -import org.session.libsession.messaging.jobs.Data; -import org.thoughtcrime.securesms.dependencies.InjectableType; -import org.thoughtcrime.securesms.jobmanager.Job; -import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; -import org.session.libsignal.utilities.logging.Log; -import org.session.libsignal.service.api.SignalServiceMessageReceiver; -import org.session.libsignal.service.api.push.exceptions.PushNetworkException; - -import org.session.libsession.utilities.TextSecurePreferences; - -import java.io.IOException; - -import javax.inject.Inject; - -public class PushNotificationReceiveJob extends PushReceivedJob implements InjectableType { - - public static final String KEY = "PushNotificationReceiveJob"; - - private static final String TAG = PushNotificationReceiveJob.class.getSimpleName(); - - @Inject SignalServiceMessageReceiver receiver; - - public PushNotificationReceiveJob(Context context) { - this(new Job.Parameters.Builder() - .addConstraint(NetworkConstraint.KEY) - .setQueue("__notification_received") - .setMaxAttempts(3) - .setMaxInstances(1) - .build()); - setContext(context); - } - - private PushNotificationReceiveJob(@NonNull Job.Parameters parameters) { - super(parameters); - } - - @Override - public @NonNull - Data serialize() { - return Data.EMPTY; - } - - @Override - public @NonNull String getFactoryKey() { - return KEY; - } - - @Override - public void onRun() throws IOException { - pullAndProcessMessages(receiver, TAG, System.currentTimeMillis()); - } - - public void pullAndProcessMessages(SignalServiceMessageReceiver receiver, String tag, long startTime) throws IOException { - synchronized (PushReceivedJob.RECEIVE_LOCK) { - receiver.retrieveMessages(envelope -> { - Log.i(tag, "Retrieved an envelope." + timeSuffix(startTime)); - processEnvelope(envelope, false); - Log.i(tag, "Successfully processed an envelope." + timeSuffix(startTime)); - }); - TextSecurePreferences.setNeedsMessagePull(context, false); - } - } - @Override - public boolean onShouldRetry(@NonNull Exception e) { - Log.w(TAG, e); - return e instanceof PushNetworkException; - } - - @Override - public void onCanceled() { - Log.w(TAG, "***** Failed to download pending message!"); -// MessageNotifier.notifyMessagesPending(getContext()); - } - - private static String timeSuffix(long startTime) { - return " (" + (System.currentTimeMillis() - startTime) + " ms elapsed)"; - } - - public static final class Factory implements Job.Factory { - @Override - public @NonNull PushNotificationReceiveJob create(@NonNull Parameters parameters, @NonNull Data data) { - return new PushNotificationReceiveJob(parameters); - } - } -} diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/IncomingMessageObserver.java b/app/src/main/java/org/thoughtcrime/securesms/service/IncomingMessageObserver.java deleted file mode 100644 index f95f024305..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/service/IncomingMessageObserver.java +++ /dev/null @@ -1,210 +0,0 @@ -package org.thoughtcrime.securesms.service; - -import android.app.Service; -import androidx.lifecycle.DefaultLifecycleObserver; -import androidx.lifecycle.LifecycleOwner; -import androidx.lifecycle.ProcessLifecycleOwner; -import android.content.Context; -import android.content.Intent; -import android.os.IBinder; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.core.app.NotificationCompat; -import androidx.core.content.ContextCompat; - -import org.thoughtcrime.securesms.ApplicationContext; -import org.thoughtcrime.securesms.dependencies.InjectableType; -import org.thoughtcrime.securesms.jobmanager.ConstraintObserver; -import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; -import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraintObserver; -import org.thoughtcrime.securesms.jobs.PushContentReceiveJob; -import org.session.libsignal.utilities.logging.Log; -import org.thoughtcrime.securesms.notifications.NotificationChannels; -import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess; -import org.session.libsession.utilities.TextSecurePreferences; -import org.session.libsignal.libsignal.InvalidVersionException; -import org.session.libsignal.service.api.SignalServiceMessagePipe; -import org.session.libsignal.service.api.SignalServiceMessageReceiver; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import javax.inject.Inject; - -import network.loki.messenger.R; - -public class IncomingMessageObserver implements InjectableType, ConstraintObserver.Notifier { - - private static final String TAG = IncomingMessageObserver.class.getSimpleName(); - - public static final int FOREGROUND_ID = 313399; - private static final long REQUEST_TIMEOUT_MINUTES = 1; - - private static SignalServiceMessagePipe pipe = null; - private static SignalServiceMessagePipe unidentifiedPipe = null; - - private final Context context; - private final NetworkConstraint networkConstraint; - - private boolean appVisible; - - @Inject SignalServiceMessageReceiver receiver; - @Inject SignalServiceNetworkAccess networkAccess; - - public IncomingMessageObserver(@NonNull Context context) { - ApplicationContext.getInstance(context).injectDependencies(this); - - this.context = context; - this.networkConstraint = new NetworkConstraint.Factory(ApplicationContext.getInstance(context)).create(); - - new NetworkConstraintObserver(ApplicationContext.getInstance(context)).register(this); - new MessageRetrievalThread().start(); - - if (TextSecurePreferences.isFcmDisabled(context)) { - ContextCompat.startForegroundService(context, new Intent(context, ForegroundService.class)); - } - - ProcessLifecycleOwner.get().getLifecycle().addObserver(new DefaultLifecycleObserver() { - @Override - public void onStart(@NonNull LifecycleOwner owner) { - onAppForegrounded(); - } - - @Override - public void onStop(@NonNull LifecycleOwner owner) { - onAppBackgrounded(); - } - }); - } - - @Override - public void onConstraintMet(@NonNull String reason) { - synchronized (this) { - notifyAll(); - } - } - - private synchronized void onAppForegrounded() { - appVisible = true; - notifyAll(); - } - - private synchronized void onAppBackgrounded() { - appVisible = false; - notifyAll(); - } - - private synchronized boolean isConnectionNecessary() { - boolean isGcmDisabled = TextSecurePreferences.isFcmDisabled(context); - - Log.d(TAG, String.format("Network requirement: %s, app visible: %s, gcm disabled: %b", - networkConstraint.isMet(), appVisible, isGcmDisabled)); - - return TextSecurePreferences.isPushRegistered(context) && - TextSecurePreferences.isWebsocketRegistered(context) && - (appVisible || isGcmDisabled) && - networkConstraint.isMet() && - !networkAccess.isCensored(context); - } - - private synchronized void waitForConnectionNecessary() { - try { - while (!isConnectionNecessary()) wait(); - } catch (InterruptedException e) { - throw new AssertionError(e); - } - } - - private void shutdown(SignalServiceMessagePipe pipe, SignalServiceMessagePipe unidentifiedPipe) { - try { - pipe.shutdown(); - unidentifiedPipe.shutdown(); - } catch (Throwable t) { - Log.w(TAG, t); - } - } - - public static @Nullable SignalServiceMessagePipe getPipe() { - return pipe; - } - - public static @Nullable SignalServiceMessagePipe getUnidentifiedPipe() { - return unidentifiedPipe; - } - - private class MessageRetrievalThread extends Thread implements Thread.UncaughtExceptionHandler { - - MessageRetrievalThread() { - super("MessageRetrievalService"); - setUncaughtExceptionHandler(this); - } - - @Override - public void run() { - while (true) { - Log.i(TAG, "Waiting for websocket state change...."); - waitForConnectionNecessary(); - - Log.i(TAG, "Making websocket connection...."); - pipe = receiver.createMessagePipe(); - unidentifiedPipe = receiver.createUnidentifiedMessagePipe(); - - SignalServiceMessagePipe localPipe = pipe; - SignalServiceMessagePipe unidentifiedLocalPipe = unidentifiedPipe; - - try { - while (isConnectionNecessary()) { - try { - Log.i(TAG, "Reading message..."); - localPipe.read(REQUEST_TIMEOUT_MINUTES, TimeUnit.MINUTES, - envelope -> { - Log.i(TAG, "Retrieved envelope! " + String.valueOf(envelope.getSource())); - new PushContentReceiveJob(context).processEnvelope(envelope, false); - }); - } catch (TimeoutException e) { - Log.w(TAG, "Application level read timeout..."); - } catch (InvalidVersionException e) { - Log.w(TAG, e); - } - } - } catch (Throwable e) { - Log.w(TAG, e); - } finally { - Log.w(TAG, "Shutting down pipe..."); - shutdown(localPipe, unidentifiedLocalPipe); - } - - Log.i(TAG, "Looping..."); - } - } - - @Override - public void uncaughtException(Thread t, Throwable e) { - Log.w(TAG, "*** Uncaught exception!"); - Log.w(TAG, e); - } - } - - public static class ForegroundService extends Service { - - @Override - public @Nullable IBinder onBind(Intent intent) { - return null; - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - super.onStartCommand(intent, flags, startId); - - NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), NotificationChannels.OTHER); - builder.setContentTitle(getApplicationContext().getString(R.string.MessageRetrievalService_signal)); - builder.setContentText(getApplicationContext().getString(R.string.MessageRetrievalService_background_connection_enabled)); - builder.setPriority(NotificationCompat.PRIORITY_MIN); - builder.setWhen(0); - builder.setSmallIcon(R.drawable.ic_notification); - startForeground(FOREGROUND_ID, builder.build()); - - return Service.START_STICKY; - } - } -} diff --git a/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt b/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt index 1b5f817864..e1c1eda085 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt @@ -108,8 +108,6 @@ object TextSecurePreferences { private const val NOTIFICATION_CHANNEL_VERSION = "pref_notification_channel_version" private const val NOTIFICATION_MESSAGES_CHANNEL_VERSION = "pref_notification_messages_channel_version" - private const val NEEDS_MESSAGE_PULL = "pref_needs_message_pull" - const val UNIVERSAL_UNIDENTIFIED_ACCESS = "pref_universal_unidentified_access" const val TYPING_INDICATORS = "pref_typing_indicators" @@ -766,16 +764,6 @@ object TextSecurePreferences { setIntegerPrefrence(context, NOTIFICATION_MESSAGES_CHANNEL_VERSION, version) } - @JvmStatic - fun getNeedsMessagePull(context: Context): Boolean { - return getBooleanPreference(context, NEEDS_MESSAGE_PULL, false) - } - - @JvmStatic - fun setNeedsMessagePull(context: Context, needsMessagePull: Boolean) { - setBooleanPreference(context, NEEDS_MESSAGE_PULL, needsMessagePull) - } - @JvmStatic fun hasSeenStickerIntroTooltip(context: Context): Boolean { return getBooleanPreference(context, SEEN_STICKER_INTRO_TOOLTIP, false) diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/SignalServiceMessagePipe.java b/libsignal/src/main/java/org/session/libsignal/service/api/SignalServiceMessagePipe.java deleted file mode 100644 index 022c04bac1..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/api/SignalServiceMessagePipe.java +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.api; - -import com.google.protobuf.ByteString; - -import org.session.libsignal.libsignal.InvalidVersionException; -import org.session.libsignal.libsignal.util.Pair; -import org.session.libsignal.libsignal.util.guava.Optional; -import org.session.libsignal.service.api.crypto.UnidentifiedAccess; -import org.session.libsignal.service.api.messages.SignalServiceEnvelope; -import org.session.libsignal.service.api.profiles.SignalServiceProfile; -import org.session.libsignal.service.api.push.SignalServiceAddress; -import org.session.libsignal.service.api.util.CredentialsProvider; -import org.session.libsignal.service.internal.push.AttachmentUploadAttributes; -import org.session.libsignal.service.internal.push.OutgoingPushMessageList; -import org.session.libsignal.service.internal.push.SendMessageResponse; -import org.session.libsignal.utilities.Base64; -import org.session.libsignal.utilities.JsonUtil; -import org.session.libsignal.service.internal.util.Util; -import org.session.libsignal.service.internal.websocket.WebSocketConnection; - -import java.io.IOException; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import static org.session.libsignal.service.internal.websocket.WebSocketProtos.WebSocketRequestMessage; -import static org.session.libsignal.service.internal.websocket.WebSocketProtos.WebSocketResponseMessage; - -/** - * A SignalServiceMessagePipe represents a dedicated connection - * to the Signal Service, which the server can push messages - * down through. - */ -public class SignalServiceMessagePipe { - - private static final String TAG = SignalServiceMessagePipe.class.getName(); - - private final WebSocketConnection websocket; - private final Optional credentialsProvider; - - SignalServiceMessagePipe(WebSocketConnection websocket, Optional credentialsProvider) { - this.websocket = websocket; - this.credentialsProvider = credentialsProvider; - - this.websocket.connect(); - } - - /** - * A blocking call that reads a message off the pipe. When this - * call returns, the message has been acknowledged and will not - * be retransmitted. - * - * @param timeout The timeout to wait for. - * @param unit The timeout time unit. - * @return A new message. - * - * @throws InvalidVersionException - * @throws IOException - * @throws TimeoutException - */ - public SignalServiceEnvelope read(long timeout, TimeUnit unit) - throws InvalidVersionException, IOException, TimeoutException - { - return read(timeout, unit, new NullMessagePipeCallback()); - } - - /** - * A blocking call that reads a message off the pipe (see {@link #read(long, TimeUnit)} - * - * Unlike {@link #read(long, TimeUnit)}, this method allows you - * to specify a callback that will be called before the received message is acknowledged. - * This allows you to write the received message to durable storage before acknowledging - * receipt of it to the server. - * - * @param timeout The timeout to wait for. - * @param unit The timeout time unit. - * @param callback A callback that will be called before the message receipt is - * acknowledged to the server. - * @return The message read (same as the message sent through the callback). - * @throws TimeoutException - * @throws IOException - * @throws InvalidVersionException - */ - public SignalServiceEnvelope read(long timeout, TimeUnit unit, MessagePipeCallback callback) - throws TimeoutException, IOException, InvalidVersionException - { - if (!credentialsProvider.isPresent()) { - throw new IllegalArgumentException("You can't read messages if you haven't specified credentials"); - } - - while (true) { - WebSocketRequestMessage request = websocket.readRequest(unit.toMillis(timeout)); - WebSocketResponseMessage response = createWebSocketResponse(request); - boolean signalKeyEncrypted = isSignalKeyEncrypted(request); - - try { - if (isSignalServiceEnvelope(request)) { - SignalServiceEnvelope envelope = new SignalServiceEnvelope(request.getBody().toByteArray(), - credentialsProvider.get().getSignalingKey(), - signalKeyEncrypted); - - callback.onMessage(envelope); - return envelope; - } - } finally { - websocket.sendResponse(response); - } - } - } - - public SendMessageResponse send(OutgoingPushMessageList list, Optional unidentifiedAccess) throws IOException { - try { - List headers = new LinkedList() {{ - add("content-type:application/json"); - }}; - - if (unidentifiedAccess.isPresent()) { - headers.add("Unidentified-Access-Key:" + Base64.encodeBytes(unidentifiedAccess.get().getUnidentifiedAccessKey())); - } - - WebSocketRequestMessage requestMessage = WebSocketRequestMessage.newBuilder() - .setId(SecureRandom.getInstance("SHA1PRNG").nextLong()) - .setVerb("PUT") - .setPath(String.format("/v1/messages/%s", list.getDestination())) - .addAllHeaders(headers) - .setBody(ByteString.copyFrom(JsonUtil.toJson(list).getBytes())) - .build(); - - Pair response = websocket.sendRequest(requestMessage).get(10, TimeUnit.SECONDS); - - if (response.first() < 200 || response.first() >= 300) { - throw new IOException("Non-successful response: " + response.first()); - } - - if (Util.isEmpty(response.second())) return new SendMessageResponse(false); - else return JsonUtil.fromJson(response.second(), SendMessageResponse.class); - } catch (NoSuchAlgorithmException e) { - throw new AssertionError(e); - } catch (InterruptedException e) { - throw new IOException(e); - } catch (ExecutionException e) { - throw new IOException(e); - } catch (TimeoutException e) { - throw new IOException(e); - } - } - - public SignalServiceProfile getProfile(SignalServiceAddress address, Optional unidentifiedAccess) throws IOException { - try { - List headers = new LinkedList(); - - if (unidentifiedAccess.isPresent()) { - headers.add("Unidentified-Access-Key:" + Base64.encodeBytes(unidentifiedAccess.get().getUnidentifiedAccessKey())); - } - - WebSocketRequestMessage requestMessage = WebSocketRequestMessage.newBuilder() - .setId(SecureRandom.getInstance("SHA1PRNG").nextLong()) - .setVerb("GET") - .setPath(String.format("/v1/profile/%s", address.getNumber())) - .addAllHeaders(headers) - .build(); - - Pair response = websocket.sendRequest(requestMessage).get(10, TimeUnit.SECONDS); - - if (response.first() < 200 || response.first() >= 300) { - throw new IOException("Non-successful response: " + response.first()); - } - - return JsonUtil.fromJson(response.second(), SignalServiceProfile.class); - } catch (NoSuchAlgorithmException nsae) { - throw new AssertionError(nsae); - } catch (InterruptedException e) { - throw new IOException(e); - } catch (ExecutionException e) { - throw new IOException(e); - } catch (TimeoutException e) { - throw new IOException(e); - } - } - - public AttachmentUploadAttributes getAttachmentUploadAttributes() throws IOException { - try { - WebSocketRequestMessage requestMessage = WebSocketRequestMessage.newBuilder() - .setId(new SecureRandom().nextLong()) - .setVerb("GET") - .setPath("/v2/attachments/form/upload") - .build(); - - Pair response = websocket.sendRequest(requestMessage).get(10, TimeUnit.SECONDS); - - if (response.first() < 200 || response.first() >= 300) { - throw new IOException("Non-successful response: " + response.first()); - } - - return JsonUtil.fromJson(response.second(), AttachmentUploadAttributes.class); - } catch (InterruptedException e) { - throw new IOException(e); - } catch (ExecutionException e) { - throw new IOException(e); - } catch (TimeoutException e) { - throw new IOException(e); - } - } - - /** - * Close this connection to the server. - */ - public void shutdown() { - websocket.disconnect(); - } - - private boolean isSignalServiceEnvelope(WebSocketRequestMessage message) { - return "PUT".equals(message.getVerb()) && "/api/v1/message".equals(message.getPath()); - } - - private boolean isSignalKeyEncrypted(WebSocketRequestMessage message) { - List headers = message.getHeadersList(); - - if (headers == null || headers.isEmpty()) { - return true; - } - - for (String header : headers) { - String[] parts = header.split(":"); - - if (parts.length == 2 && parts[0] != null && parts[0].trim().equalsIgnoreCase("X-Signal-Key")) { - if (parts[1] != null && parts[1].trim().equalsIgnoreCase("false")) { - return false; - } - } - } - - return true; - } - - private WebSocketResponseMessage createWebSocketResponse(WebSocketRequestMessage request) { - if (isSignalServiceEnvelope(request)) { - return WebSocketResponseMessage.newBuilder() - .setId(request.getId()) - .setStatus(200) - .setMessage("OK") - .build(); - } else { - return WebSocketResponseMessage.newBuilder() - .setId(request.getId()) - .setStatus(400) - .setMessage("Unknown") - .build(); - } - } - - /** - * For receiving a callback when a new message has been - * received. - */ - public static interface MessagePipeCallback { - public void onMessage(SignalServiceEnvelope envelope); - } - - private static class NullMessagePipeCallback implements MessagePipeCallback { - @Override - public void onMessage(SignalServiceEnvelope envelope) {} - } - -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/SignalServiceMessageReceiver.java b/libsignal/src/main/java/org/session/libsignal/service/api/SignalServiceMessageReceiver.java index e41e66fa94..8effb24b34 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/api/SignalServiceMessageReceiver.java +++ b/libsignal/src/main/java/org/session/libsignal/service/api/SignalServiceMessageReceiver.java @@ -7,37 +7,17 @@ package org.session.libsignal.service.api; import org.session.libsignal.libsignal.InvalidMessageException; -import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsignal.service.api.crypto.AttachmentCipherInputStream; import org.session.libsignal.service.api.crypto.ProfileCipherInputStream; -import org.session.libsignal.service.api.crypto.UnidentifiedAccess; import org.session.libsignal.service.api.messages.SignalServiceAttachment.ProgressListener; import org.session.libsignal.service.api.messages.SignalServiceAttachmentPointer; import org.session.libsignal.service.api.messages.SignalServiceDataMessage; -import org.session.libsignal.service.api.messages.SignalServiceEnvelope; -import org.session.libsignal.service.api.messages.SignalServiceStickerManifest; -import org.session.libsignal.service.api.profiles.SignalServiceProfile; -import org.session.libsignal.service.api.push.SignalServiceAddress; -import org.session.libsignal.service.api.util.CredentialsProvider; -import org.session.libsignal.service.api.util.SleepTimer; -import org.session.libsignal.service.api.websocket.ConnectivityListener; -import org.session.libsignal.service.internal.configuration.SignalServiceConfiguration; -import org.session.libsignal.service.internal.push.PushServiceSocket; -import org.session.libsignal.service.internal.push.SignalServiceEnvelopeEntity; -import org.session.libsignal.service.internal.sticker.StickerProtos; -import org.session.libsignal.service.internal.util.StaticCredentialsProvider; -import org.session.libsignal.service.internal.util.Util; -import org.session.libsignal.service.internal.websocket.WebSocketConnection; import org.session.libsignal.service.loki.utilities.DownloadUtilities; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; /** * The primary interface for receiving Signal Service messages. @@ -46,51 +26,6 @@ import java.util.List; */ @SuppressWarnings("OptionalUsedAsFieldOrParameterType") public class SignalServiceMessageReceiver { - - private final PushServiceSocket socket; - private final SignalServiceConfiguration urls; - private final CredentialsProvider credentialsProvider; - private final String userAgent; - private final ConnectivityListener connectivityListener; - private final SleepTimer sleepTimer; - - /** - * Construct a SignalServiceMessageReceiver. - * - * @param urls The URL of the Signal Service. - * @param user The Signal Service username (eg. phone number). - * @param password The Signal Service user password. - * @param signalingKey The 52 byte signaling key assigned to this user at registration. - */ - public SignalServiceMessageReceiver(SignalServiceConfiguration urls, - String user, String password, - String signalingKey, String userAgent, - ConnectivityListener listener, - SleepTimer timer) - { - this(urls, new StaticCredentialsProvider(user, password, signalingKey), userAgent, listener, timer); - } - - /** - * Construct a SignalServiceMessageReceiver. - * - * @param urls The URL of the Signal Service. - * @param credentials The Signal Service user's credentials. - */ - public SignalServiceMessageReceiver(SignalServiceConfiguration urls, - CredentialsProvider credentials, - String userAgent, - ConnectivityListener listener, - SleepTimer timer) - { - this.urls = urls; - this.credentialsProvider = credentials; - this.socket = new PushServiceSocket(urls, credentials, userAgent); - this.userAgent = userAgent; - this.connectivityListener = listener; - this.sleepTimer = timer; - } - /** * Retrieves a SignalServiceAttachment. * @@ -139,105 +74,4 @@ public class SignalServiceMessageReceiver { return AttachmentCipherInputStream.createForAttachment(destination, pointer.getSize().or(0), pointer.getKey(), pointer.getDigest().get()); } - - public InputStream retrieveSticker(byte[] packId, byte[] packKey, int stickerId) - throws IOException, InvalidMessageException - { - byte[] data = socket.retrieveSticker(packId, stickerId); - return AttachmentCipherInputStream.createForStickerData(data, packKey); - } - - /** - * Retrieves a {@link SignalServiceStickerManifest}. - * - * @param packId The 16-byte packId that identifies the sticker pack. - * @param packKey The 32-byte packKey that decrypts the sticker pack. - * @return The {@link SignalServiceStickerManifest} representing the sticker pack. - * @throws IOException - * @throws InvalidMessageException - */ - public SignalServiceStickerManifest retrieveStickerManifest(byte[] packId, byte[] packKey) - throws IOException, InvalidMessageException - { - byte[] manifestBytes = socket.retrieveStickerManifest(packId); - - InputStream cipherStream = AttachmentCipherInputStream.createForStickerData(manifestBytes, packKey); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - - Util.copy(cipherStream, outputStream); - - StickerProtos.Pack pack = StickerProtos.Pack.parseFrom(outputStream.toByteArray()); - List stickers = new ArrayList(pack.getStickersCount()); - SignalServiceStickerManifest.StickerInfo cover = pack.hasCover() ? new SignalServiceStickerManifest.StickerInfo(pack.getCover().getId(), pack.getCover().getEmoji()) - : null; - - for (StickerProtos.Pack.Sticker sticker : pack.getStickersList()) { - stickers.add(new SignalServiceStickerManifest.StickerInfo(sticker.getId(), sticker.getEmoji())); - } - - return new SignalServiceStickerManifest(pack.getTitle(), pack.getAuthor(), cover, stickers); - } - - /** - * Creates a pipe for receiving SignalService messages. - * - * Callers must call {@link SignalServiceMessagePipe#shutdown()} when finished with the pipe. - * - * @return A SignalServiceMessagePipe for receiving Signal Service messages. - */ - public SignalServiceMessagePipe createMessagePipe() { - WebSocketConnection webSocket = new WebSocketConnection(urls.getSignalServiceUrls()[0].getUrl(), - urls.getSignalServiceUrls()[0].getTrustStore(), - Optional.of(credentialsProvider), userAgent, connectivityListener, - sleepTimer); - - return new SignalServiceMessagePipe(webSocket, Optional.of(credentialsProvider)); - } - - public SignalServiceMessagePipe createUnidentifiedMessagePipe() { - WebSocketConnection webSocket = new WebSocketConnection(urls.getSignalServiceUrls()[0].getUrl(), - urls.getSignalServiceUrls()[0].getTrustStore(), - Optional.absent(), userAgent, connectivityListener, - sleepTimer); - - return new SignalServiceMessagePipe(webSocket, Optional.of(credentialsProvider)); - } - - public List retrieveMessages(MessageReceivedCallback callback) - throws IOException - { - List results = new LinkedList(); - List entities = socket.getMessages(); - - for (SignalServiceEnvelopeEntity entity : entities) { - SignalServiceEnvelope envelope; - - if (entity.getSource() != null && entity.getSourceDevice() > 0) { - envelope = new SignalServiceEnvelope(entity.getType(), entity.getSource(), - entity.getSourceDevice(), entity.getTimestamp(), - entity.getContent(), entity.getServerTimestamp()); - } else { - envelope = new SignalServiceEnvelope(entity.getType(), entity.getTimestamp(), - entity.getContent(), entity.getServerTimestamp()); - } - - callback.onMessage(envelope); - results.add(envelope); - - socket.acknowledgeMessage(entity.getSource(), entity.getTimestamp()); - } - - return results; - } - - - public interface MessageReceivedCallback { - public void onMessage(SignalServiceEnvelope envelope); - } - - public static class NullMessageReceivedCallback implements MessageReceivedCallback { - @Override - public void onMessage(SignalServiceEnvelope envelope) {} - } - } diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/SignalServiceMessageSender.java b/libsignal/src/main/java/org/session/libsignal/service/api/SignalServiceMessageSender.java index 6190023c97..16cac09520 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/api/SignalServiceMessageSender.java +++ b/libsignal/src/main/java/org/session/libsignal/service/api/SignalServiceMessageSender.java @@ -93,9 +93,6 @@ public class SignalServiceMessageSender { private final IdentityKeyStore store; private final SignalServiceAddress localAddress; - private final AtomicReference> pipe; - private final AtomicReference> unidentifiedPipe; - // Loki private final String userPublicKey; private final LokiAPIDatabaseProtocol apiDatabase; @@ -115,8 +112,6 @@ public class SignalServiceMessageSender { */ public SignalServiceMessageSender(String user, String password, IdentityKeyStore store, - Optional pipe, - Optional unidentifiedPipe, String userPublicKey, LokiAPIDatabaseProtocol apiDatabase, LokiThreadDatabaseProtocol threadDatabase, @@ -126,13 +121,11 @@ public class SignalServiceMessageSender { LokiOpenGroupDatabaseProtocol openGroupDatabase, Broadcaster broadcaster) { - this(new StaticCredentialsProvider(user, password, null), store, pipe, unidentifiedPipe, userPublicKey, apiDatabase, threadDatabase, messageDatabase, sessionProtocolImpl, userDatabase, openGroupDatabase, broadcaster); + this(new StaticCredentialsProvider(user, password, null), store, userPublicKey, apiDatabase, threadDatabase, messageDatabase, sessionProtocolImpl, userDatabase, openGroupDatabase, broadcaster); } public SignalServiceMessageSender(CredentialsProvider credentialsProvider, IdentityKeyStore store, - Optional pipe, - Optional unidentifiedPipe, String userPublicKey, LokiAPIDatabaseProtocol apiDatabase, LokiThreadDatabaseProtocol threadDatabase, @@ -144,8 +137,6 @@ public class SignalServiceMessageSender { { this.store = store; this.localAddress = new SignalServiceAddress(credentialsProvider.getUser()); - this.pipe = new AtomicReference<>(pipe); - this.unidentifiedPipe = new AtomicReference<>(unidentifiedPipe); this.userPublicKey = userPublicKey; this.apiDatabase = apiDatabase; this.threadDatabase = threadDatabase; @@ -223,11 +214,6 @@ public class SignalServiceMessageSender { return sendMessage(messageID, recipients, unidentifiedAccess, timestamp, content, false, message.getTTL(), isClosedGroup, message.hasVisibleContent()); } - public void setMessagePipe(SignalServiceMessagePipe pipe, SignalServiceMessagePipe unidentifiedPipe) { - this.pipe.set(Optional.fromNullable(pipe)); - this.unidentifiedPipe.set(Optional.fromNullable(unidentifiedPipe)); - } - public SignalServiceAttachmentPointer uploadAttachment(SignalServiceAttachmentStream attachment, boolean usePadding, @Nullable SignalServiceAddress recipient) throws IOException { diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/push/ContactTokenDetails.java b/libsignal/src/main/java/org/session/libsignal/service/api/push/ContactTokenDetails.java deleted file mode 100644 index 30ec1a3d16..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/api/push/ContactTokenDetails.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.api.push; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * A class that represents a contact's registration state. - */ -public class ContactTokenDetails { - - @JsonProperty - private String token; - - @JsonProperty - private String relay; - - @JsonProperty - private String number; - - @JsonProperty - private boolean voice; - - @JsonProperty - private boolean video; - - public ContactTokenDetails() {} - - /** - * @return The "anonymized" token (truncated hash) that's transmitted to the server. - */ - public String getToken() { - return token; - } - - /** - * @return The federated server this contact is registered with, or null if on your server. - */ - public String getRelay() { - return relay; - } - - /** - * @return Whether this contact supports secure voice calls. - */ - public boolean isVoice() { - return voice; - } - - public boolean isVideo() { - return video; - } - - public void setNumber(String number) { - this.number = number; - } - - /** - * @return This contact's username (e164 formatted number). - */ - public String getNumber() { - return number; - } - -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/push/SignedPreKeyEntity.java b/libsignal/src/main/java/org/session/libsignal/service/api/push/SignedPreKeyEntity.java deleted file mode 100644 index 07db5e80a2..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/api/push/SignedPreKeyEntity.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.api.push; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -import org.session.libsignal.libsignal.ecc.ECPublicKey; -import org.session.libsignal.service.internal.push.PreKeyEntity; -import org.session.libsignal.utilities.Base64; - -import java.io.IOException; - -public class SignedPreKeyEntity extends PreKeyEntity { - - @JsonProperty - @JsonSerialize(using = ByteArraySerializer.class) - @JsonDeserialize(using = ByteArrayDeserializer.class) - private byte[] signature; - - public SignedPreKeyEntity() {} - - public SignedPreKeyEntity(int keyId, ECPublicKey publicKey, byte[] signature) { - super(keyId, publicKey); - this.signature = signature; - } - - public byte[] getSignature() { - return signature; - } - - private static class ByteArraySerializer extends JsonSerializer { - @Override - public void serialize(byte[] value, JsonGenerator gen, SerializerProvider serializers) throws IOException { - gen.writeString(Base64.encodeBytesWithoutPadding(value)); - } - } - - private static class ByteArrayDeserializer extends JsonDeserializer { - - @Override - public byte[] deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { - return Base64.decodeWithoutPadding(p.getValueAsString()); - } - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/AuthorizationFailedException.java b/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/AuthorizationFailedException.java deleted file mode 100644 index 8709b22c37..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/AuthorizationFailedException.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.api.push.exceptions; - -import org.session.libsignal.service.api.push.exceptions.NonSuccessfulResponseCodeException; - -public class AuthorizationFailedException extends NonSuccessfulResponseCodeException { - public AuthorizationFailedException(String s) { - super(s); - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/CaptchaRequiredException.java b/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/CaptchaRequiredException.java deleted file mode 100644 index abeb5db5ad..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/CaptchaRequiredException.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.session.libsignal.service.api.push.exceptions; - -import org.session.libsignal.service.api.push.exceptions.NonSuccessfulResponseCodeException; - -public class CaptchaRequiredException extends NonSuccessfulResponseCodeException { -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/EncapsulatedExceptions.java b/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/EncapsulatedExceptions.java deleted file mode 100644 index e23a5ab13f..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/EncapsulatedExceptions.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ -package org.session.libsignal.service.api.push.exceptions; - -import org.session.libsignal.service.api.crypto.UntrustedIdentityException; -import org.session.libsignal.service.api.push.exceptions.NetworkFailureException; -import org.session.libsignal.service.api.push.exceptions.UnregisteredUserException; - -import java.util.LinkedList; -import java.util.List; - -public class EncapsulatedExceptions extends Throwable { - - private final List untrustedIdentityExceptions; - private final List unregisteredUserExceptions; - private final List networkExceptions; - - public EncapsulatedExceptions(List untrustedIdentities, - List unregisteredUsers, - List networkExceptions) - { - this.untrustedIdentityExceptions = untrustedIdentities; - this.unregisteredUserExceptions = unregisteredUsers; - this.networkExceptions = networkExceptions; - } - - public EncapsulatedExceptions(UntrustedIdentityException e) { - this.untrustedIdentityExceptions = new LinkedList(); - this.unregisteredUserExceptions = new LinkedList(); - this.networkExceptions = new LinkedList(); - - this.untrustedIdentityExceptions.add(e); - } - - public List getUntrustedIdentityExceptions() { - return untrustedIdentityExceptions; - } - - public List getUnregisteredUserExceptions() { - return unregisteredUserExceptions; - } - - public List getNetworkExceptions() { - return networkExceptions; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/ExpectationFailedException.java b/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/ExpectationFailedException.java deleted file mode 100644 index 5ce5b15b3f..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/ExpectationFailedException.java +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ -package org.session.libsignal.service.api.push.exceptions; - -import org.session.libsignal.service.api.push.exceptions.NonSuccessfulResponseCodeException; - -public class ExpectationFailedException extends NonSuccessfulResponseCodeException { -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/NetworkFailureException.java b/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/NetworkFailureException.java deleted file mode 100644 index 4e37bcfc1b..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/NetworkFailureException.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.api.push.exceptions; - -public class NetworkFailureException extends Exception { - - private final String e164number; - - public NetworkFailureException(String e164number, Exception nested) { - super(nested); - this.e164number = e164number; - } - - public String getE164number() { - return e164number; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/NonSuccessfulResponseCodeException.java b/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/NonSuccessfulResponseCodeException.java index 363d577621..40a00e0a2c 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/NonSuccessfulResponseCodeException.java +++ b/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/NonSuccessfulResponseCodeException.java @@ -10,10 +10,6 @@ import java.io.IOException; public class NonSuccessfulResponseCodeException extends IOException { - public NonSuccessfulResponseCodeException() { - super(); - } - public NonSuccessfulResponseCodeException(String s) { super(s); } diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/NotFoundException.java b/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/NotFoundException.java deleted file mode 100644 index 29e4f24aaf..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/NotFoundException.java +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.api.push.exceptions; - -public class NotFoundException extends NonSuccessfulResponseCodeException { - public NotFoundException(String s) { - super(s); - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/RateLimitException.java b/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/RateLimitException.java deleted file mode 100644 index f1a248b3cc..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/RateLimitException.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.api.push.exceptions; - -import org.session.libsignal.service.api.push.exceptions.NonSuccessfulResponseCodeException; - -public class RateLimitException extends NonSuccessfulResponseCodeException { - public RateLimitException(String s) { - super(s); - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/RemoteAttestationResponseExpiredException.java b/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/RemoteAttestationResponseExpiredException.java deleted file mode 100644 index c5e5eaa76f..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/api/push/exceptions/RemoteAttestationResponseExpiredException.java +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (C) 2019 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.api.push.exceptions; - -public class RemoteAttestationResponseExpiredException extends NonSuccessfulResponseCodeException { - public RemoteAttestationResponseExpiredException(String message) { - super(message); - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/AccountAttributes.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/AccountAttributes.java deleted file mode 100644 index a7c1157cb0..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/AccountAttributes.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.internal.push; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class AccountAttributes { - - @JsonProperty - private String signalingKey; - - @JsonProperty - private int registrationId; - - @JsonProperty - private boolean voice; - - @JsonProperty - private boolean video; - - @JsonProperty - private boolean fetchesMessages; - - @JsonProperty - private String pin; - - @JsonProperty - private byte[] unidentifiedAccessKey; - - @JsonProperty - private boolean unrestrictedUnidentifiedAccess; - - public AccountAttributes(String signalingKey, int registrationId, boolean fetchesMessages, String pin, byte[] unidentifiedAccessKey, boolean unrestrictedUnidentifiedAccess) { - this.signalingKey = signalingKey; - this.registrationId = registrationId; - this.voice = true; - this.video = true; - this.fetchesMessages = fetchesMessages; - this.pin = pin; - this.unidentifiedAccessKey = unidentifiedAccessKey; - this.unrestrictedUnidentifiedAccess = unrestrictedUnidentifiedAccess; - } - - public AccountAttributes() {} - - public String getSignalingKey() { - return signalingKey; - } - - public int getRegistrationId() { - return registrationId; - } - - public boolean isVoice() { - return voice; - } - - public boolean isVideo() { - return video; - } - - public boolean isFetchesMessages() { - return fetchesMessages; - } - - public String getPin() { - return pin; - } - - public byte[] getUnidentifiedAccessKey() { - return unidentifiedAccessKey; - } - - public boolean isUnrestrictedUnidentifiedAccess() { - return unrestrictedUnidentifiedAccess; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/AttachmentUploadAttributes.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/AttachmentUploadAttributes.java deleted file mode 100644 index 65bed7ec28..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/AttachmentUploadAttributes.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.session.libsignal.service.internal.push; - - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class AttachmentUploadAttributes { - @JsonProperty - private String url; - - @JsonProperty - private String key; - - @JsonProperty - private String credential; - - @JsonProperty - private String acl; - - @JsonProperty - private String algorithm; - - @JsonProperty - private String date; - - @JsonProperty - private String policy; - - @JsonProperty - private String signature; - - @JsonProperty - private String attachmentId; - - @JsonProperty - private String attachmentIdString; - - public AttachmentUploadAttributes() {} - - public String getUrl() { - return url; - } - - public String getKey() { - return key; - } - - public String getCredential() { - return credential; - } - - public String getAcl() { - return acl; - } - - public String getAlgorithm() { - return algorithm; - } - - public String getDate() { - return date; - } - - public String getPolicy() { - return policy; - } - - public String getSignature() { - return signature; - } - - public String getAttachmentId() { - return attachmentId; - } - - public String getAttachmentIdString() { - return attachmentIdString; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/ContactDiscoveryCredentials.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/ContactDiscoveryCredentials.java deleted file mode 100644 index 3018150ad7..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/ContactDiscoveryCredentials.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.session.libsignal.service.internal.push; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class ContactDiscoveryCredentials { - - @JsonProperty - private String username; - - @JsonProperty - private String password; - - public void setUsername(String username) { - this.username = username; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getUsername() { - return username; - } - - public String getPassword() { - return password; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/ContactDiscoveryFailureReason.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/ContactDiscoveryFailureReason.java deleted file mode 100644 index da59b0764e..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/ContactDiscoveryFailureReason.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.session.libsignal.service.internal.push; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class ContactDiscoveryFailureReason { - - @JsonProperty - private final String reason; - - public ContactDiscoveryFailureReason(String reason) { - this.reason = reason == null ? "" : reason; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/ContactTokenDetailsList.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/ContactTokenDetailsList.java deleted file mode 100644 index 7e644bef4b..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/ContactTokenDetailsList.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.internal.push; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import org.session.libsignal.service.api.push.ContactTokenDetails; - -import java.util.List; - -public class ContactTokenDetailsList { - - @JsonProperty - private List contacts; - - public ContactTokenDetailsList() {} - - public List getContacts() { - return contacts; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/ContactTokenList.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/ContactTokenList.java deleted file mode 100644 index 530bcce852..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/ContactTokenList.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.internal.push; - -import java.util.List; - -public class ContactTokenList { - - private List contacts; - - public ContactTokenList(List contacts) { - this.contacts = contacts; - } - - public ContactTokenList() {} - - public List getContacts() { - return contacts; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/DeviceCode.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/DeviceCode.java deleted file mode 100644 index e92ee7fce8..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/DeviceCode.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.session.libsignal.service.internal.push; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class DeviceCode { - - @JsonProperty - private String verificationCode; - - public String getVerificationCode() { - return verificationCode; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/DeviceLimit.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/DeviceLimit.java deleted file mode 100644 index cf22e8eca2..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/DeviceLimit.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.session.libsignal.service.internal.push; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class DeviceLimit { - - @JsonProperty - private int current; - - @JsonProperty - private int max; - - public int getCurrent() { - return current; - } - - public int getMax() { - return max; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/DeviceLimitExceededException.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/DeviceLimitExceededException.java deleted file mode 100644 index ca00a33c34..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/DeviceLimitExceededException.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.session.libsignal.service.internal.push; - -import org.session.libsignal.service.api.push.exceptions.NonSuccessfulResponseCodeException; - -public class DeviceLimitExceededException extends NonSuccessfulResponseCodeException { - - private final DeviceLimit deviceLimit; - - public DeviceLimitExceededException(DeviceLimit deviceLimit) { - this.deviceLimit = deviceLimit; - } - - public int getCurrent() { - return deviceLimit.getCurrent(); - } - - public int getMax() { - return deviceLimit.getMax(); - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/LockedException.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/LockedException.java deleted file mode 100644 index ed7e3285b3..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/LockedException.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.session.libsignal.service.internal.push; - - -import org.session.libsignal.service.api.push.exceptions.NonSuccessfulResponseCodeException; - -public class LockedException extends NonSuccessfulResponseCodeException { - - private int length; - private long timeRemaining; - - LockedException(int length, long timeRemaining) { - this.length = length; - this.timeRemaining = timeRemaining; - } - - public int getLength() { - return length; - } - - public long getTimeRemaining() { - return timeRemaining; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/MismatchedDevices.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/MismatchedDevices.java deleted file mode 100644 index bf9f6f90e9..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/MismatchedDevices.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.internal.push; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.List; - -public class MismatchedDevices { - @JsonProperty - private List missingDevices; - - @JsonProperty - private List extraDevices; - - public List getMissingDevices() { - return missingDevices; - } - - public List getExtraDevices() { - return extraDevices; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyEntity.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyEntity.java deleted file mode 100644 index f59258441a..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyEntity.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.internal.push; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -import org.session.libsignal.libsignal.InvalidKeyException; -import org.session.libsignal.libsignal.ecc.Curve; -import org.session.libsignal.libsignal.ecc.ECPublicKey; -import org.session.libsignal.utilities.Base64; - -import java.io.IOException; - -public class PreKeyEntity { - - @JsonProperty - private int keyId; - - @JsonProperty - @JsonSerialize(using = ECPublicKeySerializer.class) - @JsonDeserialize(using = ECPublicKeyDeserializer.class) - private ECPublicKey publicKey; - - public PreKeyEntity() {} - - public PreKeyEntity(int keyId, ECPublicKey publicKey) { - this.keyId = keyId; - this.publicKey = publicKey; - } - - public int getKeyId() { - return keyId; - } - - public ECPublicKey getPublicKey() { - return publicKey; - } - - private static class ECPublicKeySerializer extends JsonSerializer { - @Override - public void serialize(ECPublicKey value, JsonGenerator gen, SerializerProvider serializers) throws IOException { - gen.writeString(Base64.encodeBytesWithoutPadding(value.serialize())); - } - } - - private static class ECPublicKeyDeserializer extends JsonDeserializer { - @Override - public ECPublicKey deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { - try { - return Curve.decodePoint(Base64.decodeWithoutPadding(p.getValueAsString()), 0); - } catch (InvalidKeyException e) { - throw new IOException(e); - } - } - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyResponse.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyResponse.java deleted file mode 100644 index 8474809f28..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyResponse.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.internal.push; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -import org.session.libsignal.libsignal.IdentityKey; -import org.session.libsignal.utilities.JsonUtil; - -import java.util.List; - -public class PreKeyResponse { - - @JsonProperty - @JsonSerialize(using = JsonUtil.IdentityKeySerializer.class) - @JsonDeserialize(using = JsonUtil.IdentityKeyDeserializer.class) - private IdentityKey identityKey; - - @JsonProperty - private List devices; - - public IdentityKey getIdentityKey() { - return identityKey; - } - - public List getDevices() { - return devices; - } - - -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyResponseItem.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyResponseItem.java deleted file mode 100644 index 86d34020ab..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyResponseItem.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.internal.push; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import org.session.libsignal.service.api.push.SignedPreKeyEntity; - -public class PreKeyResponseItem { - - @JsonProperty - private int deviceId; - - @JsonProperty - private int registrationId; - - @JsonProperty - private SignedPreKeyEntity signedPreKey; - - @JsonProperty - private PreKeyEntity preKey; - - public int getDeviceId() { - return deviceId; - } - - public int getRegistrationId() { - return registrationId; - } - - public SignedPreKeyEntity getSignedPreKey() { - return signedPreKey; - } - - public PreKeyEntity getPreKey() { - return preKey; - } - -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyState.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyState.java deleted file mode 100644 index 13091f89a2..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyState.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.session.libsignal.service.internal.push; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -import org.session.libsignal.libsignal.IdentityKey; -import org.session.libsignal.service.api.push.SignedPreKeyEntity; -import org.session.libsignal.utilities.JsonUtil; - -import java.util.List; - -public class PreKeyState { - - @JsonProperty - @JsonSerialize(using = JsonUtil.IdentityKeySerializer.class) - @JsonDeserialize(using = JsonUtil.IdentityKeyDeserializer.class) - private IdentityKey identityKey; - - @JsonProperty - private List preKeys; - - @JsonProperty - private SignedPreKeyEntity signedPreKey; - - - public PreKeyState(List preKeys, SignedPreKeyEntity signedPreKey, IdentityKey identityKey) { - this.preKeys = preKeys; - this.signedPreKey = signedPreKey; - this.identityKey = identityKey; - } - -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyStatus.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyStatus.java deleted file mode 100644 index f119667a67..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/PreKeyStatus.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.internal.push; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class PreKeyStatus { - - @JsonProperty - private int count; - - public PreKeyStatus() {} - - public int getCount() { - return count; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/ProfileAvatarUploadAttributes.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/ProfileAvatarUploadAttributes.java deleted file mode 100644 index c6bfa619a5..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/ProfileAvatarUploadAttributes.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.session.libsignal.service.internal.push; - - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class ProfileAvatarUploadAttributes { - @JsonProperty - private String url; - - @JsonProperty - private String key; - - @JsonProperty - private String credential; - - @JsonProperty - private String acl; - - @JsonProperty - private String algorithm; - - @JsonProperty - private String date; - - @JsonProperty - private String policy; - - @JsonProperty - private String signature; - - public ProfileAvatarUploadAttributes() {} - - public String getUrl() { - return url; - } - - public String getKey() { - return key; - } - - public String getCredential() { - return credential; - } - - public String getAcl() { - return acl; - } - - public String getAlgorithm() { - return algorithm; - } - - public String getDate() { - return date; - } - - public String getPolicy() { - return policy; - } - - public String getSignature() { - return signature; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/ProvisioningMessage.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/ProvisioningMessage.java deleted file mode 100644 index 727f5ff8ff..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/ProvisioningMessage.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.session.libsignal.service.internal.push; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class ProvisioningMessage { - - @JsonProperty - private String body; - - public ProvisioningMessage(String body) { - this.body = body; - } - -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/ProvisioningProtos.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/ProvisioningProtos.java deleted file mode 100644 index 15bf1a02a6..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/ProvisioningProtos.java +++ /dev/null @@ -1,1698 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: Provisioning.proto - -package org.session.libsignal.service.internal.push; - -public final class ProvisioningProtos { - private ProvisioningProtos() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - } - public interface ProvisionEnvelopeOrBuilder - extends com.google.protobuf.MessageOrBuilder { - - // optional bytes publicKey = 1; - /** - * optional bytes publicKey = 1; - */ - boolean hasPublicKey(); - /** - * optional bytes publicKey = 1; - */ - com.google.protobuf.ByteString getPublicKey(); - - // optional bytes body = 2; - /** - * optional bytes body = 2; - * - *
-     * Encrypted ProvisionMessage
-     * 
- */ - boolean hasBody(); - /** - * optional bytes body = 2; - * - *
-     * Encrypted ProvisionMessage
-     * 
- */ - com.google.protobuf.ByteString getBody(); - } - /** - * Protobuf type {@code signalservice.ProvisionEnvelope} - */ - public static final class ProvisionEnvelope extends - com.google.protobuf.GeneratedMessage - implements ProvisionEnvelopeOrBuilder { - // Use ProvisionEnvelope.newBuilder() to construct. - private ProvisionEnvelope(com.google.protobuf.GeneratedMessage.Builder builder) { - super(builder); - this.unknownFields = builder.getUnknownFields(); - } - private ProvisionEnvelope(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } - - private static final ProvisionEnvelope defaultInstance; - public static ProvisionEnvelope getDefaultInstance() { - return defaultInstance; - } - - public ProvisionEnvelope getDefaultInstanceForType() { - return defaultInstance; - } - - private final com.google.protobuf.UnknownFieldSet unknownFields; - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private ProvisionEnvelope( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - initFields(); - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownField(input, unknownFields, - extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - bitField0_ |= 0x00000001; - publicKey_ = input.readBytes(); - break; - } - case 18: { - bitField0_ |= 0x00000002; - body_ = input.readBytes(); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e.getMessage()).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return org.session.libsignal.service.internal.push.ProvisioningProtos.internal_static_signalservice_ProvisionEnvelope_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return org.session.libsignal.service.internal.push.ProvisioningProtos.internal_static_signalservice_ProvisionEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope.class, org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope.Builder.class); - } - - public static com.google.protobuf.Parser PARSER = - new com.google.protobuf.AbstractParser() { - public ProvisionEnvelope parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new ProvisionEnvelope(input, extensionRegistry); - } - }; - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - private int bitField0_; - // optional bytes publicKey = 1; - public static final int PUBLICKEY_FIELD_NUMBER = 1; - private com.google.protobuf.ByteString publicKey_; - /** - * optional bytes publicKey = 1; - */ - public boolean hasPublicKey() { - return ((bitField0_ & 0x00000001) == 0x00000001); - } - /** - * optional bytes publicKey = 1; - */ - public com.google.protobuf.ByteString getPublicKey() { - return publicKey_; - } - - // optional bytes body = 2; - public static final int BODY_FIELD_NUMBER = 2; - private com.google.protobuf.ByteString body_; - /** - * optional bytes body = 2; - * - *
-     * Encrypted ProvisionMessage
-     * 
- */ - public boolean hasBody() { - return ((bitField0_ & 0x00000002) == 0x00000002); - } - /** - * optional bytes body = 2; - * - *
-     * Encrypted ProvisionMessage
-     * 
- */ - public com.google.protobuf.ByteString getBody() { - return body_; - } - - private void initFields() { - publicKey_ = com.google.protobuf.ByteString.EMPTY; - body_ = com.google.protobuf.ByteString.EMPTY; - } - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized != -1) return isInitialized == 1; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - getSerializedSize(); - if (((bitField0_ & 0x00000001) == 0x00000001)) { - output.writeBytes(1, publicKey_); - } - if (((bitField0_ & 0x00000002) == 0x00000002)) { - output.writeBytes(2, body_); - } - getUnknownFields().writeTo(output); - } - - private int memoizedSerializedSize = -1; - public int getSerializedSize() { - int size = memoizedSerializedSize; - if (size != -1) return size; - - size = 0; - if (((bitField0_ & 0x00000001) == 0x00000001)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(1, publicKey_); - } - if (((bitField0_ & 0x00000002) == 0x00000002)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(2, body_); - } - size += getUnknownFields().getSerializedSize(); - memoizedSerializedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - @java.lang.Override - protected java.lang.Object writeReplace() - throws java.io.ObjectStreamException { - return super.writeReplace(); - } - - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope parseFrom(java.io.InputStream input) - throws java.io.IOException { - return PARSER.parseFrom(input); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return PARSER.parseDelimitedFrom(input); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseDelimitedFrom(input, extensionRegistry); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return PARSER.parseFrom(input); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); - } - - public static Builder newBuilder() { return Builder.create(); } - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder(org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope prototype) { - return newBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { return newBuilder(this); } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code signalservice.ProvisionEnvelope} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder - implements org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelopeOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return org.session.libsignal.service.internal.push.ProvisioningProtos.internal_static_signalservice_ProvisionEnvelope_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return org.session.libsignal.service.internal.push.ProvisioningProtos.internal_static_signalservice_ProvisionEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope.class, org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope.Builder.class); - } - - // Construct using org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - } - } - private static Builder create() { - return new Builder(); - } - - public Builder clear() { - super.clear(); - publicKey_ = com.google.protobuf.ByteString.EMPTY; - bitField0_ = (bitField0_ & ~0x00000001); - body_ = com.google.protobuf.ByteString.EMPTY; - bitField0_ = (bitField0_ & ~0x00000002); - return this; - } - - public Builder clone() { - return create().mergeFrom(buildPartial()); - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return org.session.libsignal.service.internal.push.ProvisioningProtos.internal_static_signalservice_ProvisionEnvelope_descriptor; - } - - public org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope getDefaultInstanceForType() { - return org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope.getDefaultInstance(); - } - - public org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope build() { - org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope buildPartial() { - org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope result = new org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope(this); - int from_bitField0_ = bitField0_; - int to_bitField0_ = 0; - if (((from_bitField0_ & 0x00000001) == 0x00000001)) { - to_bitField0_ |= 0x00000001; - } - result.publicKey_ = publicKey_; - if (((from_bitField0_ & 0x00000002) == 0x00000002)) { - to_bitField0_ |= 0x00000002; - } - result.body_ = body_; - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; - } - - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope) { - return mergeFrom((org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope other) { - if (other == org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope.getDefaultInstance()) return this; - if (other.hasPublicKey()) { - setPublicKey(other.getPublicKey()); - } - if (other.hasBody()) { - setBody(other.getBody()); - } - this.mergeUnknownFields(other.getUnknownFields()); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionEnvelope) e.getUnfinishedMessage(); - throw e; - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - // optional bytes publicKey = 1; - private com.google.protobuf.ByteString publicKey_ = com.google.protobuf.ByteString.EMPTY; - /** - * optional bytes publicKey = 1; - */ - public boolean hasPublicKey() { - return ((bitField0_ & 0x00000001) == 0x00000001); - } - /** - * optional bytes publicKey = 1; - */ - public com.google.protobuf.ByteString getPublicKey() { - return publicKey_; - } - /** - * optional bytes publicKey = 1; - */ - public Builder setPublicKey(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000001; - publicKey_ = value; - onChanged(); - return this; - } - /** - * optional bytes publicKey = 1; - */ - public Builder clearPublicKey() { - bitField0_ = (bitField0_ & ~0x00000001); - publicKey_ = getDefaultInstance().getPublicKey(); - onChanged(); - return this; - } - - // optional bytes body = 2; - private com.google.protobuf.ByteString body_ = com.google.protobuf.ByteString.EMPTY; - /** - * optional bytes body = 2; - * - *
-       * Encrypted ProvisionMessage
-       * 
- */ - public boolean hasBody() { - return ((bitField0_ & 0x00000002) == 0x00000002); - } - /** - * optional bytes body = 2; - * - *
-       * Encrypted ProvisionMessage
-       * 
- */ - public com.google.protobuf.ByteString getBody() { - return body_; - } - /** - * optional bytes body = 2; - * - *
-       * Encrypted ProvisionMessage
-       * 
- */ - public Builder setBody(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000002; - body_ = value; - onChanged(); - return this; - } - /** - * optional bytes body = 2; - * - *
-       * Encrypted ProvisionMessage
-       * 
- */ - public Builder clearBody() { - bitField0_ = (bitField0_ & ~0x00000002); - body_ = getDefaultInstance().getBody(); - onChanged(); - return this; - } - - // @@protoc_insertion_point(builder_scope:signalservice.ProvisionEnvelope) - } - - static { - defaultInstance = new ProvisionEnvelope(true); - defaultInstance.initFields(); - } - - // @@protoc_insertion_point(class_scope:signalservice.ProvisionEnvelope) - } - - public interface ProvisionMessageOrBuilder - extends com.google.protobuf.MessageOrBuilder { - - // optional bytes identityKeyPublic = 1; - /** - * optional bytes identityKeyPublic = 1; - */ - boolean hasIdentityKeyPublic(); - /** - * optional bytes identityKeyPublic = 1; - */ - com.google.protobuf.ByteString getIdentityKeyPublic(); - - // optional bytes identityKeyPrivate = 2; - /** - * optional bytes identityKeyPrivate = 2; - */ - boolean hasIdentityKeyPrivate(); - /** - * optional bytes identityKeyPrivate = 2; - */ - com.google.protobuf.ByteString getIdentityKeyPrivate(); - - // optional string number = 3; - /** - * optional string number = 3; - */ - boolean hasNumber(); - /** - * optional string number = 3; - */ - java.lang.String getNumber(); - /** - * optional string number = 3; - */ - com.google.protobuf.ByteString - getNumberBytes(); - - // optional string provisioningCode = 4; - /** - * optional string provisioningCode = 4; - */ - boolean hasProvisioningCode(); - /** - * optional string provisioningCode = 4; - */ - java.lang.String getProvisioningCode(); - /** - * optional string provisioningCode = 4; - */ - com.google.protobuf.ByteString - getProvisioningCodeBytes(); - - // optional string userAgent = 5; - /** - * optional string userAgent = 5; - */ - boolean hasUserAgent(); - /** - * optional string userAgent = 5; - */ - java.lang.String getUserAgent(); - /** - * optional string userAgent = 5; - */ - com.google.protobuf.ByteString - getUserAgentBytes(); - - // optional bytes profileKey = 6; - /** - * optional bytes profileKey = 6; - */ - boolean hasProfileKey(); - /** - * optional bytes profileKey = 6; - */ - com.google.protobuf.ByteString getProfileKey(); - - // optional bool readReceipts = 7; - /** - * optional bool readReceipts = 7; - */ - boolean hasReadReceipts(); - /** - * optional bool readReceipts = 7; - */ - boolean getReadReceipts(); - } - /** - * Protobuf type {@code signalservice.ProvisionMessage} - */ - public static final class ProvisionMessage extends - com.google.protobuf.GeneratedMessage - implements ProvisionMessageOrBuilder { - // Use ProvisionMessage.newBuilder() to construct. - private ProvisionMessage(com.google.protobuf.GeneratedMessage.Builder builder) { - super(builder); - this.unknownFields = builder.getUnknownFields(); - } - private ProvisionMessage(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } - - private static final ProvisionMessage defaultInstance; - public static ProvisionMessage getDefaultInstance() { - return defaultInstance; - } - - public ProvisionMessage getDefaultInstanceForType() { - return defaultInstance; - } - - private final com.google.protobuf.UnknownFieldSet unknownFields; - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private ProvisionMessage( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - initFields(); - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownField(input, unknownFields, - extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - bitField0_ |= 0x00000001; - identityKeyPublic_ = input.readBytes(); - break; - } - case 18: { - bitField0_ |= 0x00000002; - identityKeyPrivate_ = input.readBytes(); - break; - } - case 26: { - bitField0_ |= 0x00000004; - number_ = input.readBytes(); - break; - } - case 34: { - bitField0_ |= 0x00000008; - provisioningCode_ = input.readBytes(); - break; - } - case 42: { - bitField0_ |= 0x00000010; - userAgent_ = input.readBytes(); - break; - } - case 50: { - bitField0_ |= 0x00000020; - profileKey_ = input.readBytes(); - break; - } - case 56: { - bitField0_ |= 0x00000040; - readReceipts_ = input.readBool(); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e.getMessage()).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return org.session.libsignal.service.internal.push.ProvisioningProtos.internal_static_signalservice_ProvisionMessage_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return org.session.libsignal.service.internal.push.ProvisioningProtos.internal_static_signalservice_ProvisionMessage_fieldAccessorTable - .ensureFieldAccessorsInitialized( - org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage.class, org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage.Builder.class); - } - - public static com.google.protobuf.Parser PARSER = - new com.google.protobuf.AbstractParser() { - public ProvisionMessage parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new ProvisionMessage(input, extensionRegistry); - } - }; - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - private int bitField0_; - // optional bytes identityKeyPublic = 1; - public static final int IDENTITYKEYPUBLIC_FIELD_NUMBER = 1; - private com.google.protobuf.ByteString identityKeyPublic_; - /** - * optional bytes identityKeyPublic = 1; - */ - public boolean hasIdentityKeyPublic() { - return ((bitField0_ & 0x00000001) == 0x00000001); - } - /** - * optional bytes identityKeyPublic = 1; - */ - public com.google.protobuf.ByteString getIdentityKeyPublic() { - return identityKeyPublic_; - } - - // optional bytes identityKeyPrivate = 2; - public static final int IDENTITYKEYPRIVATE_FIELD_NUMBER = 2; - private com.google.protobuf.ByteString identityKeyPrivate_; - /** - * optional bytes identityKeyPrivate = 2; - */ - public boolean hasIdentityKeyPrivate() { - return ((bitField0_ & 0x00000002) == 0x00000002); - } - /** - * optional bytes identityKeyPrivate = 2; - */ - public com.google.protobuf.ByteString getIdentityKeyPrivate() { - return identityKeyPrivate_; - } - - // optional string number = 3; - public static final int NUMBER_FIELD_NUMBER = 3; - private java.lang.Object number_; - /** - * optional string number = 3; - */ - public boolean hasNumber() { - return ((bitField0_ & 0x00000004) == 0x00000004); - } - /** - * optional string number = 3; - */ - public java.lang.String getNumber() { - java.lang.Object ref = number_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - if (bs.isValidUtf8()) { - number_ = s; - } - return s; - } - } - /** - * optional string number = 3; - */ - public com.google.protobuf.ByteString - getNumberBytes() { - java.lang.Object ref = number_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - number_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - // optional string provisioningCode = 4; - public static final int PROVISIONINGCODE_FIELD_NUMBER = 4; - private java.lang.Object provisioningCode_; - /** - * optional string provisioningCode = 4; - */ - public boolean hasProvisioningCode() { - return ((bitField0_ & 0x00000008) == 0x00000008); - } - /** - * optional string provisioningCode = 4; - */ - public java.lang.String getProvisioningCode() { - java.lang.Object ref = provisioningCode_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - if (bs.isValidUtf8()) { - provisioningCode_ = s; - } - return s; - } - } - /** - * optional string provisioningCode = 4; - */ - public com.google.protobuf.ByteString - getProvisioningCodeBytes() { - java.lang.Object ref = provisioningCode_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - provisioningCode_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - // optional string userAgent = 5; - public static final int USERAGENT_FIELD_NUMBER = 5; - private java.lang.Object userAgent_; - /** - * optional string userAgent = 5; - */ - public boolean hasUserAgent() { - return ((bitField0_ & 0x00000010) == 0x00000010); - } - /** - * optional string userAgent = 5; - */ - public java.lang.String getUserAgent() { - java.lang.Object ref = userAgent_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - if (bs.isValidUtf8()) { - userAgent_ = s; - } - return s; - } - } - /** - * optional string userAgent = 5; - */ - public com.google.protobuf.ByteString - getUserAgentBytes() { - java.lang.Object ref = userAgent_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - userAgent_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - // optional bytes profileKey = 6; - public static final int PROFILEKEY_FIELD_NUMBER = 6; - private com.google.protobuf.ByteString profileKey_; - /** - * optional bytes profileKey = 6; - */ - public boolean hasProfileKey() { - return ((bitField0_ & 0x00000020) == 0x00000020); - } - /** - * optional bytes profileKey = 6; - */ - public com.google.protobuf.ByteString getProfileKey() { - return profileKey_; - } - - // optional bool readReceipts = 7; - public static final int READRECEIPTS_FIELD_NUMBER = 7; - private boolean readReceipts_; - /** - * optional bool readReceipts = 7; - */ - public boolean hasReadReceipts() { - return ((bitField0_ & 0x00000040) == 0x00000040); - } - /** - * optional bool readReceipts = 7; - */ - public boolean getReadReceipts() { - return readReceipts_; - } - - private void initFields() { - identityKeyPublic_ = com.google.protobuf.ByteString.EMPTY; - identityKeyPrivate_ = com.google.protobuf.ByteString.EMPTY; - number_ = ""; - provisioningCode_ = ""; - userAgent_ = ""; - profileKey_ = com.google.protobuf.ByteString.EMPTY; - readReceipts_ = false; - } - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized != -1) return isInitialized == 1; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - getSerializedSize(); - if (((bitField0_ & 0x00000001) == 0x00000001)) { - output.writeBytes(1, identityKeyPublic_); - } - if (((bitField0_ & 0x00000002) == 0x00000002)) { - output.writeBytes(2, identityKeyPrivate_); - } - if (((bitField0_ & 0x00000004) == 0x00000004)) { - output.writeBytes(3, getNumberBytes()); - } - if (((bitField0_ & 0x00000008) == 0x00000008)) { - output.writeBytes(4, getProvisioningCodeBytes()); - } - if (((bitField0_ & 0x00000010) == 0x00000010)) { - output.writeBytes(5, getUserAgentBytes()); - } - if (((bitField0_ & 0x00000020) == 0x00000020)) { - output.writeBytes(6, profileKey_); - } - if (((bitField0_ & 0x00000040) == 0x00000040)) { - output.writeBool(7, readReceipts_); - } - getUnknownFields().writeTo(output); - } - - private int memoizedSerializedSize = -1; - public int getSerializedSize() { - int size = memoizedSerializedSize; - if (size != -1) return size; - - size = 0; - if (((bitField0_ & 0x00000001) == 0x00000001)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(1, identityKeyPublic_); - } - if (((bitField0_ & 0x00000002) == 0x00000002)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(2, identityKeyPrivate_); - } - if (((bitField0_ & 0x00000004) == 0x00000004)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(3, getNumberBytes()); - } - if (((bitField0_ & 0x00000008) == 0x00000008)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(4, getProvisioningCodeBytes()); - } - if (((bitField0_ & 0x00000010) == 0x00000010)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(5, getUserAgentBytes()); - } - if (((bitField0_ & 0x00000020) == 0x00000020)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(6, profileKey_); - } - if (((bitField0_ & 0x00000040) == 0x00000040)) { - size += com.google.protobuf.CodedOutputStream - .computeBoolSize(7, readReceipts_); - } - size += getUnknownFields().getSerializedSize(); - memoizedSerializedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - @java.lang.Override - protected java.lang.Object writeReplace() - throws java.io.ObjectStreamException { - return super.writeReplace(); - } - - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage parseFrom(java.io.InputStream input) - throws java.io.IOException { - return PARSER.parseFrom(input); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return PARSER.parseDelimitedFrom(input); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseDelimitedFrom(input, extensionRegistry); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return PARSER.parseFrom(input); - } - public static org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); - } - - public static Builder newBuilder() { return Builder.create(); } - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder(org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage prototype) { - return newBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { return newBuilder(this); } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code signalservice.ProvisionMessage} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder - implements org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessageOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return org.session.libsignal.service.internal.push.ProvisioningProtos.internal_static_signalservice_ProvisionMessage_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return org.session.libsignal.service.internal.push.ProvisioningProtos.internal_static_signalservice_ProvisionMessage_fieldAccessorTable - .ensureFieldAccessorsInitialized( - org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage.class, org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage.Builder.class); - } - - // Construct using org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - } - } - private static Builder create() { - return new Builder(); - } - - public Builder clear() { - super.clear(); - identityKeyPublic_ = com.google.protobuf.ByteString.EMPTY; - bitField0_ = (bitField0_ & ~0x00000001); - identityKeyPrivate_ = com.google.protobuf.ByteString.EMPTY; - bitField0_ = (bitField0_ & ~0x00000002); - number_ = ""; - bitField0_ = (bitField0_ & ~0x00000004); - provisioningCode_ = ""; - bitField0_ = (bitField0_ & ~0x00000008); - userAgent_ = ""; - bitField0_ = (bitField0_ & ~0x00000010); - profileKey_ = com.google.protobuf.ByteString.EMPTY; - bitField0_ = (bitField0_ & ~0x00000020); - readReceipts_ = false; - bitField0_ = (bitField0_ & ~0x00000040); - return this; - } - - public Builder clone() { - return create().mergeFrom(buildPartial()); - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return org.session.libsignal.service.internal.push.ProvisioningProtos.internal_static_signalservice_ProvisionMessage_descriptor; - } - - public org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage getDefaultInstanceForType() { - return org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage.getDefaultInstance(); - } - - public org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage build() { - org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage buildPartial() { - org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage result = new org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage(this); - int from_bitField0_ = bitField0_; - int to_bitField0_ = 0; - if (((from_bitField0_ & 0x00000001) == 0x00000001)) { - to_bitField0_ |= 0x00000001; - } - result.identityKeyPublic_ = identityKeyPublic_; - if (((from_bitField0_ & 0x00000002) == 0x00000002)) { - to_bitField0_ |= 0x00000002; - } - result.identityKeyPrivate_ = identityKeyPrivate_; - if (((from_bitField0_ & 0x00000004) == 0x00000004)) { - to_bitField0_ |= 0x00000004; - } - result.number_ = number_; - if (((from_bitField0_ & 0x00000008) == 0x00000008)) { - to_bitField0_ |= 0x00000008; - } - result.provisioningCode_ = provisioningCode_; - if (((from_bitField0_ & 0x00000010) == 0x00000010)) { - to_bitField0_ |= 0x00000010; - } - result.userAgent_ = userAgent_; - if (((from_bitField0_ & 0x00000020) == 0x00000020)) { - to_bitField0_ |= 0x00000020; - } - result.profileKey_ = profileKey_; - if (((from_bitField0_ & 0x00000040) == 0x00000040)) { - to_bitField0_ |= 0x00000040; - } - result.readReceipts_ = readReceipts_; - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; - } - - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage) { - return mergeFrom((org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage other) { - if (other == org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage.getDefaultInstance()) return this; - if (other.hasIdentityKeyPublic()) { - setIdentityKeyPublic(other.getIdentityKeyPublic()); - } - if (other.hasIdentityKeyPrivate()) { - setIdentityKeyPrivate(other.getIdentityKeyPrivate()); - } - if (other.hasNumber()) { - bitField0_ |= 0x00000004; - number_ = other.number_; - onChanged(); - } - if (other.hasProvisioningCode()) { - bitField0_ |= 0x00000008; - provisioningCode_ = other.provisioningCode_; - onChanged(); - } - if (other.hasUserAgent()) { - bitField0_ |= 0x00000010; - userAgent_ = other.userAgent_; - onChanged(); - } - if (other.hasProfileKey()) { - setProfileKey(other.getProfileKey()); - } - if (other.hasReadReceipts()) { - setReadReceipts(other.getReadReceipts()); - } - this.mergeUnknownFields(other.getUnknownFields()); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (org.session.libsignal.service.internal.push.ProvisioningProtos.ProvisionMessage) e.getUnfinishedMessage(); - throw e; - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - // optional bytes identityKeyPublic = 1; - private com.google.protobuf.ByteString identityKeyPublic_ = com.google.protobuf.ByteString.EMPTY; - /** - * optional bytes identityKeyPublic = 1; - */ - public boolean hasIdentityKeyPublic() { - return ((bitField0_ & 0x00000001) == 0x00000001); - } - /** - * optional bytes identityKeyPublic = 1; - */ - public com.google.protobuf.ByteString getIdentityKeyPublic() { - return identityKeyPublic_; - } - /** - * optional bytes identityKeyPublic = 1; - */ - public Builder setIdentityKeyPublic(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000001; - identityKeyPublic_ = value; - onChanged(); - return this; - } - /** - * optional bytes identityKeyPublic = 1; - */ - public Builder clearIdentityKeyPublic() { - bitField0_ = (bitField0_ & ~0x00000001); - identityKeyPublic_ = getDefaultInstance().getIdentityKeyPublic(); - onChanged(); - return this; - } - - // optional bytes identityKeyPrivate = 2; - private com.google.protobuf.ByteString identityKeyPrivate_ = com.google.protobuf.ByteString.EMPTY; - /** - * optional bytes identityKeyPrivate = 2; - */ - public boolean hasIdentityKeyPrivate() { - return ((bitField0_ & 0x00000002) == 0x00000002); - } - /** - * optional bytes identityKeyPrivate = 2; - */ - public com.google.protobuf.ByteString getIdentityKeyPrivate() { - return identityKeyPrivate_; - } - /** - * optional bytes identityKeyPrivate = 2; - */ - public Builder setIdentityKeyPrivate(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000002; - identityKeyPrivate_ = value; - onChanged(); - return this; - } - /** - * optional bytes identityKeyPrivate = 2; - */ - public Builder clearIdentityKeyPrivate() { - bitField0_ = (bitField0_ & ~0x00000002); - identityKeyPrivate_ = getDefaultInstance().getIdentityKeyPrivate(); - onChanged(); - return this; - } - - // optional string number = 3; - private java.lang.Object number_ = ""; - /** - * optional string number = 3; - */ - public boolean hasNumber() { - return ((bitField0_ & 0x00000004) == 0x00000004); - } - /** - * optional string number = 3; - */ - public java.lang.String getNumber() { - java.lang.Object ref = number_; - if (!(ref instanceof java.lang.String)) { - java.lang.String s = ((com.google.protobuf.ByteString) ref) - .toStringUtf8(); - number_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * optional string number = 3; - */ - public com.google.protobuf.ByteString - getNumberBytes() { - java.lang.Object ref = number_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - number_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * optional string number = 3; - */ - public Builder setNumber( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000004; - number_ = value; - onChanged(); - return this; - } - /** - * optional string number = 3; - */ - public Builder clearNumber() { - bitField0_ = (bitField0_ & ~0x00000004); - number_ = getDefaultInstance().getNumber(); - onChanged(); - return this; - } - /** - * optional string number = 3; - */ - public Builder setNumberBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000004; - number_ = value; - onChanged(); - return this; - } - - // optional string provisioningCode = 4; - private java.lang.Object provisioningCode_ = ""; - /** - * optional string provisioningCode = 4; - */ - public boolean hasProvisioningCode() { - return ((bitField0_ & 0x00000008) == 0x00000008); - } - /** - * optional string provisioningCode = 4; - */ - public java.lang.String getProvisioningCode() { - java.lang.Object ref = provisioningCode_; - if (!(ref instanceof java.lang.String)) { - java.lang.String s = ((com.google.protobuf.ByteString) ref) - .toStringUtf8(); - provisioningCode_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * optional string provisioningCode = 4; - */ - public com.google.protobuf.ByteString - getProvisioningCodeBytes() { - java.lang.Object ref = provisioningCode_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - provisioningCode_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * optional string provisioningCode = 4; - */ - public Builder setProvisioningCode( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000008; - provisioningCode_ = value; - onChanged(); - return this; - } - /** - * optional string provisioningCode = 4; - */ - public Builder clearProvisioningCode() { - bitField0_ = (bitField0_ & ~0x00000008); - provisioningCode_ = getDefaultInstance().getProvisioningCode(); - onChanged(); - return this; - } - /** - * optional string provisioningCode = 4; - */ - public Builder setProvisioningCodeBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000008; - provisioningCode_ = value; - onChanged(); - return this; - } - - // optional string userAgent = 5; - private java.lang.Object userAgent_ = ""; - /** - * optional string userAgent = 5; - */ - public boolean hasUserAgent() { - return ((bitField0_ & 0x00000010) == 0x00000010); - } - /** - * optional string userAgent = 5; - */ - public java.lang.String getUserAgent() { - java.lang.Object ref = userAgent_; - if (!(ref instanceof java.lang.String)) { - java.lang.String s = ((com.google.protobuf.ByteString) ref) - .toStringUtf8(); - userAgent_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * optional string userAgent = 5; - */ - public com.google.protobuf.ByteString - getUserAgentBytes() { - java.lang.Object ref = userAgent_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - userAgent_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * optional string userAgent = 5; - */ - public Builder setUserAgent( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000010; - userAgent_ = value; - onChanged(); - return this; - } - /** - * optional string userAgent = 5; - */ - public Builder clearUserAgent() { - bitField0_ = (bitField0_ & ~0x00000010); - userAgent_ = getDefaultInstance().getUserAgent(); - onChanged(); - return this; - } - /** - * optional string userAgent = 5; - */ - public Builder setUserAgentBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000010; - userAgent_ = value; - onChanged(); - return this; - } - - // optional bytes profileKey = 6; - private com.google.protobuf.ByteString profileKey_ = com.google.protobuf.ByteString.EMPTY; - /** - * optional bytes profileKey = 6; - */ - public boolean hasProfileKey() { - return ((bitField0_ & 0x00000020) == 0x00000020); - } - /** - * optional bytes profileKey = 6; - */ - public com.google.protobuf.ByteString getProfileKey() { - return profileKey_; - } - /** - * optional bytes profileKey = 6; - */ - public Builder setProfileKey(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000020; - profileKey_ = value; - onChanged(); - return this; - } - /** - * optional bytes profileKey = 6; - */ - public Builder clearProfileKey() { - bitField0_ = (bitField0_ & ~0x00000020); - profileKey_ = getDefaultInstance().getProfileKey(); - onChanged(); - return this; - } - - // optional bool readReceipts = 7; - private boolean readReceipts_ ; - /** - * optional bool readReceipts = 7; - */ - public boolean hasReadReceipts() { - return ((bitField0_ & 0x00000040) == 0x00000040); - } - /** - * optional bool readReceipts = 7; - */ - public boolean getReadReceipts() { - return readReceipts_; - } - /** - * optional bool readReceipts = 7; - */ - public Builder setReadReceipts(boolean value) { - bitField0_ |= 0x00000040; - readReceipts_ = value; - onChanged(); - return this; - } - /** - * optional bool readReceipts = 7; - */ - public Builder clearReadReceipts() { - bitField0_ = (bitField0_ & ~0x00000040); - readReceipts_ = false; - onChanged(); - return this; - } - - // @@protoc_insertion_point(builder_scope:signalservice.ProvisionMessage) - } - - static { - defaultInstance = new ProvisionMessage(true); - defaultInstance.initFields(); - } - - // @@protoc_insertion_point(class_scope:signalservice.ProvisionMessage) - } - - private static com.google.protobuf.Descriptors.Descriptor - internal_static_signalservice_ProvisionEnvelope_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_signalservice_ProvisionEnvelope_fieldAccessorTable; - private static com.google.protobuf.Descriptors.Descriptor - internal_static_signalservice_ProvisionMessage_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_signalservice_ProvisionMessage_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n\022Provisioning.proto\022\rsignalservice\"4\n\021P" + - "rovisionEnvelope\022\021\n\tpublicKey\030\001 \001(\014\022\014\n\004b" + - "ody\030\002 \001(\014\"\260\001\n\020ProvisionMessage\022\031\n\021identi" + - "tyKeyPublic\030\001 \001(\014\022\032\n\022identityKeyPrivate\030" + - "\002 \001(\014\022\016\n\006number\030\003 \001(\t\022\030\n\020provisioningCod" + - "e\030\004 \001(\t\022\021\n\tuserAgent\030\005 \001(\t\022\022\n\nprofileKey" + - "\030\006 \001(\014\022\024\n\014readReceipts\030\007 \001(\010BA\n+org.sess" + - "ion.libsignal.service.internal.pushB\022Pro" + - "visioningProtos" - }; - com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = - new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { - public com.google.protobuf.ExtensionRegistry assignDescriptors( - com.google.protobuf.Descriptors.FileDescriptor root) { - descriptor = root; - internal_static_signalservice_ProvisionEnvelope_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_signalservice_ProvisionEnvelope_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_signalservice_ProvisionEnvelope_descriptor, - new java.lang.String[] { "PublicKey", "Body", }); - internal_static_signalservice_ProvisionMessage_descriptor = - getDescriptor().getMessageTypes().get(1); - internal_static_signalservice_ProvisionMessage_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_signalservice_ProvisionMessage_descriptor, - new java.lang.String[] { "IdentityKeyPublic", "IdentityKeyPrivate", "Number", "ProvisioningCode", "UserAgent", "ProfileKey", "ReadReceipts", }); - return null; - } - }; - com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - }, assigner); - } - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/PushServiceSocket.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/PushServiceSocket.java deleted file mode 100644 index 3d5272fe12..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/PushServiceSocket.java +++ /dev/null @@ -1,669 +0,0 @@ -/* - * Copyright (C) 2014-2017 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.internal.push; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonProcessingException; - -import org.session.libsignal.libsignal.IdentityKey; -import org.session.libsignal.libsignal.ecc.ECPublicKey; -import org.session.libsignal.utilities.logging.Log; -import org.session.libsignal.libsignal.util.Pair; -import org.session.libsignal.libsignal.util.guava.Optional; -import org.session.libsignal.service.api.crypto.UnidentifiedAccess; -import org.session.libsignal.service.api.messages.SignalServiceAttachment.ProgressListener; -import org.session.libsignal.service.api.profiles.SignalServiceProfile; -import org.session.libsignal.service.api.push.ContactTokenDetails; -import org.session.libsignal.service.api.push.SignalServiceAddress; -import org.session.libsignal.service.api.push.SignedPreKeyEntity; -import org.session.libsignal.service.api.push.exceptions.AuthorizationFailedException; -import org.session.libsignal.service.api.push.exceptions.CaptchaRequiredException; -import org.session.libsignal.service.api.push.exceptions.ExpectationFailedException; -import org.session.libsignal.service.api.push.exceptions.NonSuccessfulResponseCodeException; -import org.session.libsignal.service.api.push.exceptions.NotFoundException; -import org.session.libsignal.service.api.push.exceptions.PushNetworkException; -import org.session.libsignal.service.api.push.exceptions.RateLimitException; -import org.session.libsignal.service.api.push.exceptions.RemoteAttestationResponseExpiredException; -import org.session.libsignal.service.api.push.exceptions.UnregisteredUserException; -import org.session.libsignal.service.api.util.CredentialsProvider; -import org.session.libsignal.service.api.util.Tls12SocketFactory; -import org.session.libsignal.service.internal.configuration.SignalServiceConfiguration; -import org.session.libsignal.service.internal.configuration.SignalUrl; -import org.session.libsignal.service.internal.contacts.entities.DiscoveryRequest; -import org.session.libsignal.service.internal.contacts.entities.DiscoveryResponse; -import org.session.libsignal.service.internal.contacts.entities.RemoteAttestationRequest; -import org.session.libsignal.service.internal.contacts.entities.RemoteAttestationResponse; -import org.session.libsignal.service.internal.push.exceptions.MismatchedDevicesException; -import org.session.libsignal.service.internal.push.exceptions.StaleDevicesException; -import org.session.libsignal.service.internal.push.http.DigestingRequestBody; -import org.session.libsignal.service.internal.push.http.OutputStreamFactory; -import org.session.libsignal.utilities.Base64; -import org.session.libsignal.service.internal.util.BlacklistingTrustManager; -import org.session.libsignal.utilities.Hex; -import org.session.libsignal.utilities.JsonUtil; -import org.session.libsignal.service.internal.util.Util; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.security.KeyManagementException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManager; -import javax.net.ssl.TrustManagerFactory; -import javax.net.ssl.X509TrustManager; - -import okhttp3.Call; -import okhttp3.ConnectionSpec; -import okhttp3.Credentials; -import okhttp3.MediaType; -import okhttp3.MultipartBody; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; -import okhttp3.ResponseBody; - -/** - * @author Moxie Marlinspike - */ -public class PushServiceSocket { - - private static final String TAG = PushServiceSocket.class.getSimpleName(); - - private static final String CREATE_ACCOUNT_SMS_PATH = "/v1/accounts/sms/code/%s?client=%s"; - private static final String CREATE_ACCOUNT_VOICE_PATH = "/v1/accounts/voice/code/%s"; - private static final String VERIFY_ACCOUNT_CODE_PATH = "/v1/accounts/code/%s"; - private static final String REGISTER_GCM_PATH = "/v1/accounts/gcm/"; - private static final String TURN_SERVER_INFO = "/v1/accounts/turn"; - private static final String SET_ACCOUNT_ATTRIBUTES = "/v1/accounts/attributes/"; - private static final String PIN_PATH = "/v1/accounts/pin/"; - - private static final String PREKEY_METADATA_PATH = "/v2/keys/"; - private static final String PREKEY_PATH = "/v2/keys/%s"; - private static final String PREKEY_DEVICE_PATH = "/v2/keys/%s/%s"; - private static final String SIGNED_PREKEY_PATH = "/v2/keys/signed"; - - private static final String PROVISIONING_CODE_PATH = "/v1/devices/provisioning/code"; - private static final String PROVISIONING_MESSAGE_PATH = "/v1/provisioning/%s"; - private static final String DEVICE_PATH = "/v1/devices/%s"; - - private static final String DIRECTORY_TOKENS_PATH = "/v1/directory/tokens"; - private static final String DIRECTORY_VERIFY_PATH = "/v1/directory/%s"; - private static final String DIRECTORY_AUTH_PATH = "/v1/directory/auth"; - private static final String DIRECTORY_FEEDBACK_PATH = "/v1/directory/feedback-v3/%s"; - private static final String MESSAGE_PATH = "/v1/messages/%s"; - private static final String SENDER_ACK_MESSAGE_PATH = "/v1/messages/%s/%d"; - private static final String UUID_ACK_MESSAGE_PATH = "/v1/messages/uuid/%s"; - private static final String ATTACHMENT_PATH = "/v2/attachments/form/upload"; - - private static final String PROFILE_PATH = "/v1/profile/%s"; - - private static final String SENDER_CERTIFICATE_PATH = "/v1/certificate/delivery"; - - private static final String ATTACHMENT_DOWNLOAD_PATH = "attachments/%d"; - private static final String ATTACHMENT_UPLOAD_PATH = "attachments/"; - - private static final String STICKER_MANIFEST_PATH = "stickers/%s/manifest.proto"; - private static final String STICKER_PATH = "stickers/%s/full/%d"; - - private static final Map NO_HEADERS = Collections.emptyMap(); - private static final ResponseCodeHandler NO_HANDLER = new EmptyResponseCodeHandler(); - - private long soTimeoutMillis = TimeUnit.SECONDS.toMillis(30); - private final Set connections = new HashSet(); - - private final ServiceConnectionHolder[] serviceClients; - private final ConnectionHolder[] cdnClients; - private final ConnectionHolder[] contactDiscoveryClients; - private final OkHttpClient attachmentClient; - - private final CredentialsProvider credentialsProvider; - private final String userAgent; - private final SecureRandom random; - - public PushServiceSocket(SignalServiceConfiguration signalServiceConfiguration, CredentialsProvider credentialsProvider, String userAgent) { - this.credentialsProvider = credentialsProvider; - this.userAgent = userAgent; - this.serviceClients = createServiceConnectionHolders(signalServiceConfiguration.getSignalServiceUrls()); - this.cdnClients = createConnectionHolders(signalServiceConfiguration.getSignalCdnUrls()); - this.contactDiscoveryClients = createConnectionHolders(signalServiceConfiguration.getSignalContactDiscoveryUrls()); - this.attachmentClient = createAttachmentClient(); - this.random = new SecureRandom(); - } - - public List getMessages() throws IOException { - String responseText = makeServiceRequest(String.format(MESSAGE_PATH, ""), "GET", null); - return JsonUtil.fromJson(responseText, SignalServiceEnvelopeEntityList.class).getMessages(); - } - - public void acknowledgeMessage(String sender, long timestamp) throws IOException { - makeServiceRequest(String.format(SENDER_ACK_MESSAGE_PATH, sender, timestamp), "DELETE", null); - } - - public byte[] retrieveSticker(byte[] packId, int stickerId) - throws NonSuccessfulResponseCodeException, PushNetworkException - { - String hexPackId = Hex.toStringCondensed(packId); - ByteArrayOutputStream output = new ByteArrayOutputStream(); - - downloadFromCdn(output, String.format(STICKER_PATH, hexPackId, stickerId), 1024 * 1024, null); - - return output.toByteArray(); - } - - public byte[] retrieveStickerManifest(byte[] packId) - throws NonSuccessfulResponseCodeException, PushNetworkException - { - String hexPackId = Hex.toStringCondensed(packId); - ByteArrayOutputStream output = new ByteArrayOutputStream(); - - downloadFromCdn(output, String.format(STICKER_MANIFEST_PATH, hexPackId), 1024 * 1024, null); - - return output.toByteArray(); - } - - public SignalServiceProfile retrieveProfile(SignalServiceAddress target, Optional unidentifiedAccess) - throws NonSuccessfulResponseCodeException, PushNetworkException - { - try { - String response = makeServiceRequest(String.format(PROFILE_PATH, target.getNumber()), "GET", null, NO_HEADERS, unidentifiedAccess); - return JsonUtil.fromJson(response, SignalServiceProfile.class); - } catch (IOException e) { - Log.w(TAG, e); - throw new NonSuccessfulResponseCodeException("Unable to parse entity"); - } - } - - private void downloadFromCdn(OutputStream outputStream, String path, int maxSizeBytes, ProgressListener listener) - throws PushNetworkException, NonSuccessfulResponseCodeException - { - ConnectionHolder connectionHolder = getRandom(cdnClients, random); - OkHttpClient okHttpClient = connectionHolder.getClient() - .newBuilder() - .connectTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS) - .readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS) - .build(); - - Request.Builder request = new Request.Builder().url(connectionHolder.getUrl() + "/" + path).get(); - - if (connectionHolder.getHostHeader().isPresent()) { - request.addHeader("Host", connectionHolder.getHostHeader().get()); - } - - Call call = okHttpClient.newCall(request.build()); - - synchronized (connections) { - connections.add(call); - } - - Response response; - - try { - response = call.execute(); - - if (response.isSuccessful()) { - ResponseBody body = response.body(); - - if (body == null) throw new PushNetworkException("No response body!"); - if (body.contentLength() > maxSizeBytes) throw new PushNetworkException("Response exceeds max size!"); - - InputStream in = body.byteStream(); - byte[] buffer = new byte[32768]; - - int read, totalRead = 0; - - while ((read = in.read(buffer, 0, buffer.length)) != -1) { - outputStream.write(buffer, 0, read); - if ((totalRead += read) > maxSizeBytes) throw new PushNetworkException("Response exceeded max size!"); - - if (listener != null) { - listener.onAttachmentProgress(body.contentLength(), totalRead); - } - } - - return; - } - } catch (IOException e) { - throw new PushNetworkException(e); - } finally { - synchronized (connections) { - connections.remove(call); - } - } - - throw new NonSuccessfulResponseCodeException("Response: " + response); - } - - private String makeServiceRequest(String urlFragment, String method, String body) - throws NonSuccessfulResponseCodeException, PushNetworkException - { - return makeServiceRequest(urlFragment, method, body, NO_HEADERS, NO_HANDLER, Optional.absent()); - } - - private String makeServiceRequest(String urlFragment, String method, String body, Map headers) - throws NonSuccessfulResponseCodeException, PushNetworkException - { - return makeServiceRequest(urlFragment, method, body, headers, NO_HANDLER, Optional.absent()); - } - - private String makeServiceRequest(String urlFragment, String method, String body, Map headers, ResponseCodeHandler responseCodeHandler) - throws NonSuccessfulResponseCodeException, PushNetworkException - { - return makeServiceRequest(urlFragment, method, body, headers, responseCodeHandler, Optional.absent()); - } - - private String makeServiceRequest(String urlFragment, String method, String body, Map headers, Optional unidentifiedAccessKey) - throws NonSuccessfulResponseCodeException, PushNetworkException - { - return makeServiceRequest(urlFragment, method, body, headers, NO_HANDLER, unidentifiedAccessKey); - } - - private String makeServiceRequest(String urlFragment, String method, String body, Map headers, ResponseCodeHandler responseCodeHandler, Optional unidentifiedAccessKey) - throws NonSuccessfulResponseCodeException, PushNetworkException - { - Response response = getServiceConnection(urlFragment, method, body, headers, unidentifiedAccessKey); - - int responseCode; - String responseMessage; - String responseBody; - - try { - responseCode = response.code(); - responseMessage = response.message(); - responseBody = response.body().string(); - } catch (IOException ioe) { - throw new PushNetworkException(ioe); - } - - responseCodeHandler.handle(responseCode); - - switch (responseCode) { - case 413: - throw new RateLimitException("Rate limit exceeded: " + responseCode); - case 401: - case 403: - throw new AuthorizationFailedException("Authorization failed!"); - case 404: - throw new NotFoundException("Not found"); - case 409: - MismatchedDevices mismatchedDevices; - - try { - mismatchedDevices = JsonUtil.fromJson(responseBody, MismatchedDevices.class); - } catch (JsonProcessingException e) { - Log.w(TAG, e); - throw new NonSuccessfulResponseCodeException("Bad response: " + responseCode + " " + responseMessage); - } catch (IOException e) { - throw new PushNetworkException(e); - } - - throw new MismatchedDevicesException(mismatchedDevices); - case 410: - StaleDevices staleDevices; - - try { - staleDevices = JsonUtil.fromJson(responseBody, StaleDevices.class); - } catch (JsonProcessingException e) { - throw new NonSuccessfulResponseCodeException("Bad response: " + responseCode + " " + responseMessage); - } catch (IOException e) { - throw new PushNetworkException(e); - } - - throw new StaleDevicesException(staleDevices); - case 411: - DeviceLimit deviceLimit; - - try { - deviceLimit = JsonUtil.fromJson(responseBody, DeviceLimit.class); - } catch (JsonProcessingException e) { - throw new NonSuccessfulResponseCodeException("Bad response: " + responseCode + " " + responseMessage); - } catch (IOException e) { - throw new PushNetworkException(e); - } - - throw new DeviceLimitExceededException(deviceLimit); - case 417: - throw new ExpectationFailedException(); - case 423: - RegistrationLockFailure accountLockFailure; - - try { - accountLockFailure = JsonUtil.fromJson(responseBody, RegistrationLockFailure.class); - } catch (JsonProcessingException e) { - Log.w(TAG, e); - throw new NonSuccessfulResponseCodeException("Bad response: " + responseCode + " " + responseMessage); - } catch (IOException e) { - throw new PushNetworkException(e); - } - - throw new LockedException(accountLockFailure.length, accountLockFailure.timeRemaining); - } - - if (responseCode != 200 && responseCode != 204) { - throw new NonSuccessfulResponseCodeException("Bad response: " + responseCode + " " + - responseMessage); - } - - return responseBody; - } - - private Response getServiceConnection(String urlFragment, String method, String body, Map headers, Optional unidentifiedAccess) - throws PushNetworkException - { - try { - ServiceConnectionHolder connectionHolder = (ServiceConnectionHolder) getRandom(serviceClients, random); - OkHttpClient baseClient = unidentifiedAccess.isPresent() ? connectionHolder.getUnidentifiedClient() : connectionHolder.getClient(); - OkHttpClient okHttpClient = baseClient.newBuilder() - .connectTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS) - .readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS) - .build(); - - Log.w(TAG, "Push service URL: " + connectionHolder.getUrl()); - Log.w(TAG, "Opening URL: " + String.format("%s%s", connectionHolder.getUrl(), urlFragment)); - - Request.Builder request = new Request.Builder(); - request.url(String.format("%s%s", connectionHolder.getUrl(), urlFragment)); - - if (body != null) { - request.method(method, RequestBody.create(MediaType.parse("application/json"), body)); - } else { - request.method(method, null); - } - - for (Map.Entry header : headers.entrySet()) { - request.addHeader(header.getKey(), header.getValue()); - } - - if (unidentifiedAccess.isPresent()) { - request.addHeader("Unidentified-Access-Key", Base64.encodeBytes(unidentifiedAccess.get().getUnidentifiedAccessKey())); - } else if (credentialsProvider.getPassword() != null) { - request.addHeader("Authorization", getAuthorizationHeader(credentialsProvider)); - } - - if (userAgent != null) { - request.addHeader("X-Signal-Agent", userAgent); - } - - if (connectionHolder.getHostHeader().isPresent()) { - request.addHeader("Host", connectionHolder.getHostHeader().get()); - } - - Call call = okHttpClient.newCall(request.build()); - - synchronized (connections) { - connections.add(call); - } - - try { - return call.execute(); - } finally { - synchronized (connections) { - connections.remove(call); - } - } - } catch (IOException e) { - throw new PushNetworkException(e); - } - } - - private Response makeContactDiscoveryRequest(String authorization, List cookies, String path, String method, String body) - throws PushNetworkException, NonSuccessfulResponseCodeException - { - ConnectionHolder connectionHolder = getRandom(contactDiscoveryClients, random); - OkHttpClient okHttpClient = connectionHolder.getClient() - .newBuilder() - .connectTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS) - .readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS) - .build(); - - Request.Builder request = new Request.Builder().url(connectionHolder.getUrl() + path); - - if (body != null) { - request.method(method, RequestBody.create(MediaType.parse("application/json"), body)); - } else { - request.method(method, null); - } - - if (connectionHolder.getHostHeader().isPresent()) { - request.addHeader("Host", connectionHolder.getHostHeader().get()); - } - - if (authorization != null) { - request.addHeader("Authorization", authorization); - } - - if (cookies != null && !cookies.isEmpty()) { - request.addHeader("Cookie", Util.join(cookies, "; ")); - } - - Call call = okHttpClient.newCall(request.build()); - - synchronized (connections) { - connections.add(call); - } - - Response response; - - try { - response = call.execute(); - - if (response.isSuccessful()) { - return response; - } - } catch (IOException e) { - throw new PushNetworkException(e); - } finally { - synchronized (connections) { - connections.remove(call); - } - } - - switch (response.code()) { - case 401: - case 403: - throw new AuthorizationFailedException("Authorization failed!"); - case 409: - throw new RemoteAttestationResponseExpiredException("Remote attestation response expired"); - case 429: - throw new RateLimitException("Rate limit exceeded: " + response.code()); - } - - throw new NonSuccessfulResponseCodeException("Response: " + response); - } - - private ServiceConnectionHolder[] createServiceConnectionHolders(SignalUrl[] urls) { - List serviceConnectionHolders = new LinkedList(); - - for (SignalUrl url : urls) { - serviceConnectionHolders.add(new ServiceConnectionHolder(createConnectionClient(url), - createConnectionClient(url), - url.getUrl(), url.getHostHeader())); - } - - return serviceConnectionHolders.toArray(new ServiceConnectionHolder[0]); - } - - private ConnectionHolder[] createConnectionHolders(SignalUrl[] urls) { - List connectionHolders = new LinkedList(); - - for (SignalUrl url : urls) { - connectionHolders.add(new ConnectionHolder(createConnectionClient(url), url.getUrl(), url.getHostHeader())); - } - - return connectionHolders.toArray(new ConnectionHolder[0]); - } - - private OkHttpClient createConnectionClient(SignalUrl url) { - try { - TrustManager[] trustManagers = BlacklistingTrustManager.createFor(url.getTrustStore()); - - SSLContext context = SSLContext.getInstance("TLS"); - context.init(null, trustManagers, null); - - return new OkHttpClient.Builder() - .sslSocketFactory(new Tls12SocketFactory(context.getSocketFactory()), (X509TrustManager)trustManagers[0]) - .connectionSpecs(url.getConnectionSpecs().or(Util.immutableList(ConnectionSpec.RESTRICTED_TLS))) - .build(); - } catch (NoSuchAlgorithmException e) { - throw new AssertionError(e); - } catch (KeyManagementException e) { - throw new AssertionError(e); - } - } - - private OkHttpClient createAttachmentClient() { - try { - SSLContext context = SSLContext.getInstance("TLS"); - context.init(null, null, null); - - TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); - trustManagerFactory.init((KeyStore)null); - - return new OkHttpClient.Builder() - .sslSocketFactory(new Tls12SocketFactory(context.getSocketFactory()), - (X509TrustManager)trustManagerFactory.getTrustManagers()[0]) - .connectionSpecs(Util.immutableList(ConnectionSpec.RESTRICTED_TLS)) - .build(); - } catch (NoSuchAlgorithmException e) { - throw new AssertionError(e); - } catch (KeyManagementException e) { - throw new AssertionError(e); - } catch (KeyStoreException e) { - throw new AssertionError(e); - } - } - - private String getAuthorizationHeader(CredentialsProvider credentialsProvider) { - try { - return "Basic " + Base64.encodeBytes((credentialsProvider.getUser() + ":" + credentialsProvider.getPassword()).getBytes("UTF-8")); - } catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } - } - - private ConnectionHolder getRandom(ConnectionHolder[] connections, SecureRandom random) { - return connections[random.nextInt(connections.length)]; - } - - private static class GcmRegistrationId { - - @JsonProperty - private String gcmRegistrationId; - - @JsonProperty - private boolean webSocketChannel; - - public GcmRegistrationId() {} - - public GcmRegistrationId(String gcmRegistrationId, boolean webSocketChannel) { - this.gcmRegistrationId = gcmRegistrationId; - this.webSocketChannel = webSocketChannel; - } - } - - private static class RegistrationLock { - @JsonProperty - private String pin; - - public RegistrationLock() {} - - public RegistrationLock(String pin) { - this.pin = pin; - } - } - - private static class RegistrationLockFailure { - @JsonProperty - private int length; - - @JsonProperty - private long timeRemaining; - } - - private static class AttachmentDescriptor { - @JsonProperty - private long id; - - @JsonProperty - private String location; - - public long getId() { - return id; - } - - public String getLocation() { - return location; - } - } - - - private static class ConnectionHolder { - - private final OkHttpClient client; - private final String url; - private final Optional hostHeader; - - private ConnectionHolder(OkHttpClient client, String url, Optional hostHeader) { - this.client = client; - this.url = url; - this.hostHeader = hostHeader; - } - - OkHttpClient getClient() { - return client; - } - - public String getUrl() { - return url; - } - - Optional getHostHeader() { - return hostHeader; - } - } - - private static class ServiceConnectionHolder extends ConnectionHolder { - - private final OkHttpClient unidentifiedClient; - - private ServiceConnectionHolder(OkHttpClient identifiedClient, OkHttpClient unidentifiedClient, String url, Optional hostHeader) { - super(identifiedClient, url, hostHeader); - this.unidentifiedClient = unidentifiedClient; - } - - OkHttpClient getUnidentifiedClient() { - return unidentifiedClient; - } - } - - private interface ResponseCodeHandler { - void handle(int responseCode) throws NonSuccessfulResponseCodeException, PushNetworkException; - } - - private static class EmptyResponseCodeHandler implements ResponseCodeHandler { - @Override - public void handle(int responseCode) { } - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/SendMessageResponse.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/SendMessageResponse.java deleted file mode 100644 index b7ff39de67..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/SendMessageResponse.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.session.libsignal.service.internal.push; - -public class SendMessageResponse { - - private boolean needsSync; - - public SendMessageResponse() {} - - public SendMessageResponse(boolean needsSync) { - this.needsSync = needsSync; - } - - public boolean getNeedsSync() { - return needsSync; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/SenderCertificate.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/SenderCertificate.java deleted file mode 100644 index 3765ac9893..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/SenderCertificate.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.session.libsignal.service.internal.push; - - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -import org.session.libsignal.utilities.Base64; - -import java.io.IOException; - -public class SenderCertificate { - - @JsonProperty - @JsonDeserialize(using = ByteArrayDesieralizer.class) - @JsonSerialize(using = ByteArraySerializer.class) - private byte[] certificate; - - public SenderCertificate() {} - - public byte[] getCertificate() { - return certificate; - } - - public static class ByteArraySerializer extends JsonSerializer { - @Override - public void serialize(byte[] value, JsonGenerator gen, SerializerProvider serializers) throws IOException { - gen.writeString(Base64.encodeBytes(value)); - } - } - - public static class ByteArrayDesieralizer extends JsonDeserializer { - - @Override - public byte[] deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { - return Base64.decode(p.getValueAsString()); - } - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/SignalServiceEnvelopeEntity.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/SignalServiceEnvelopeEntity.java deleted file mode 100644 index 4c0424d92e..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/SignalServiceEnvelopeEntity.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.session.libsignal.service.internal.push; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class SignalServiceEnvelopeEntity { - - @JsonProperty - private int type; - - @JsonProperty - private String relay; - - @JsonProperty - private long timestamp; - - @JsonProperty - private String source; - - @JsonProperty - private int sourceDevice; - - @JsonProperty - private byte[] content; - - @JsonProperty - private long serverTimestamp; - - public SignalServiceEnvelopeEntity() {} - - public int getType() { - return type; - } - - public String getRelay() { - return relay; - } - - public long getTimestamp() { - return timestamp; - } - - public String getSource() { - return source; - } - - public int getSourceDevice() { - return sourceDevice; - } - - public byte[] getContent() { - return content; - } - - public long getServerTimestamp() { - return serverTimestamp; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/SignalServiceEnvelopeEntityList.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/SignalServiceEnvelopeEntityList.java deleted file mode 100644 index 52b49d02e1..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/SignalServiceEnvelopeEntityList.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.session.libsignal.service.internal.push; - -import java.util.List; - -public class SignalServiceEnvelopeEntityList { - - private List messages; - - public SignalServiceEnvelopeEntityList() {} - - public List getMessages() { - return messages; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/StaleDevices.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/StaleDevices.java deleted file mode 100644 index bcce154c43..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/StaleDevices.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.internal.push; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.List; - -public class StaleDevices { - - @JsonProperty - private List staleDevices; - - public List getStaleDevices() { - return staleDevices; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/exceptions/MismatchedDevicesException.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/exceptions/MismatchedDevicesException.java deleted file mode 100644 index 31a06266d2..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/exceptions/MismatchedDevicesException.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.internal.push.exceptions; - -import org.session.libsignal.service.api.push.exceptions.NonSuccessfulResponseCodeException; -import org.session.libsignal.service.internal.push.MismatchedDevices; - -public class MismatchedDevicesException extends NonSuccessfulResponseCodeException { - - private final MismatchedDevices mismatchedDevices; - - public MismatchedDevicesException(MismatchedDevices mismatchedDevices) { - this.mismatchedDevices = mismatchedDevices; - } - - public MismatchedDevices getMismatchedDevices() { - return mismatchedDevices; - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/service/internal/push/exceptions/StaleDevicesException.java b/libsignal/src/main/java/org/session/libsignal/service/internal/push/exceptions/StaleDevicesException.java deleted file mode 100644 index ea1c9efdc2..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/service/internal/push/exceptions/StaleDevicesException.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (C) 2014-2016 Open Whisper Systems - * - * Licensed according to the LICENSE file in this repository. - */ - -package org.session.libsignal.service.internal.push.exceptions; - -import org.session.libsignal.service.api.push.exceptions.NonSuccessfulResponseCodeException; -import org.session.libsignal.service.internal.push.StaleDevices; - -public class StaleDevicesException extends NonSuccessfulResponseCodeException { - - private final StaleDevices staleDevices; - - public StaleDevicesException(StaleDevices staleDevices) { - this.staleDevices = staleDevices; - } - - public StaleDevices getStaleDevices() { - return staleDevices; - } -}