Search in sources :

Example 11 with SignalStorageManifest

use of org.whispersystems.signalservice.api.storage.SignalStorageManifest in project Signal-Android by WhisperSystems.

the class SignalServiceAccountManager method getStorageManifestIfDifferentVersion.

public Optional<SignalStorageManifest> getStorageManifestIfDifferentVersion(StorageKey storageKey, long manifestVersion) throws IOException, InvalidKeyException {
    try {
        String authToken = this.pushServiceSocket.getStorageAuth();
        StorageManifest storageManifest = this.pushServiceSocket.getStorageManifestIfDifferentVersion(authToken, manifestVersion);
        if (storageManifest.getValue().isEmpty()) {
            Log.w(TAG, "Got an empty storage manifest!");
            return Optional.absent();
        }
        return Optional.of(SignalStorageModels.remoteToLocalStorageManifest(storageManifest, storageKey));
    } catch (NoContentException e) {
        return Optional.absent();
    }
}
Also used : ByteString(com.google.protobuf.ByteString) NoContentException(org.whispersystems.signalservice.api.push.exceptions.NoContentException) StorageManifest(org.whispersystems.signalservice.internal.storage.protos.StorageManifest) SignalStorageManifest(org.whispersystems.signalservice.api.storage.SignalStorageManifest)

Example 12 with SignalStorageManifest

use of org.whispersystems.signalservice.api.storage.SignalStorageManifest in project Signal-Android by signalapp.

the class SignalServiceAccountManager method getStorageManifest.

public Optional<SignalStorageManifest> getStorageManifest(StorageKey storageKey) throws IOException {
    try {
        String authToken = this.pushServiceSocket.getStorageAuth();
        StorageManifest storageManifest = this.pushServiceSocket.getStorageManifest(authToken);
        return Optional.of(SignalStorageModels.remoteToLocalStorageManifest(storageManifest, storageKey));
    } catch (InvalidKeyException | NotFoundException e) {
        Log.w(TAG, "Error while fetching manifest.", e);
        return Optional.absent();
    }
}
Also used : NotFoundException(org.whispersystems.signalservice.api.push.exceptions.NotFoundException) ByteString(com.google.protobuf.ByteString) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) StorageManifest(org.whispersystems.signalservice.internal.storage.protos.StorageManifest) SignalStorageManifest(org.whispersystems.signalservice.api.storage.SignalStorageManifest)

Example 13 with SignalStorageManifest

use of org.whispersystems.signalservice.api.storage.SignalStorageManifest in project Signal-Android by signalapp.

the class SignalServiceAccountManager method getStorageManifestIfDifferentVersion.

public Optional<SignalStorageManifest> getStorageManifestIfDifferentVersion(StorageKey storageKey, long manifestVersion) throws IOException, InvalidKeyException {
    try {
        String authToken = this.pushServiceSocket.getStorageAuth();
        StorageManifest storageManifest = this.pushServiceSocket.getStorageManifestIfDifferentVersion(authToken, manifestVersion);
        if (storageManifest.getValue().isEmpty()) {
            Log.w(TAG, "Got an empty storage manifest!");
            return Optional.absent();
        }
        return Optional.of(SignalStorageModels.remoteToLocalStorageManifest(storageManifest, storageKey));
    } catch (NoContentException e) {
        return Optional.absent();
    }
}
Also used : ByteString(com.google.protobuf.ByteString) NoContentException(org.whispersystems.signalservice.api.push.exceptions.NoContentException) StorageManifest(org.whispersystems.signalservice.internal.storage.protos.StorageManifest) SignalStorageManifest(org.whispersystems.signalservice.api.storage.SignalStorageManifest)

Example 14 with SignalStorageManifest

use of org.whispersystems.signalservice.api.storage.SignalStorageManifest in project Signal-Android by signalapp.

the class StorageSyncValidations method validateManifestAndInserts.

private static void validateManifestAndInserts(@NonNull SignalStorageManifest manifest, @NonNull List<SignalStorageRecord> inserts, @NonNull Recipient self) {
    Set<StorageId> allSet = new HashSet<>(manifest.getStorageIds());
    Set<StorageId> insertSet = new HashSet<>(Stream.of(inserts).map(SignalStorageRecord::getId).toList());
    Set<ByteBuffer> rawIdSet = Stream.of(allSet).map(id -> ByteBuffer.wrap(id.getRaw())).collect(Collectors.toSet());
    if (allSet.size() != manifest.getStorageIds().size()) {
        throw new DuplicateStorageIdError();
    }
    if (rawIdSet.size() != allSet.size()) {
        throw new DuplicateRawIdError();
    }
    if (inserts.size() > insertSet.size()) {
        throw new DuplicateInsertInWriteError();
    }
    int accountCount = 0;
    for (StorageId id : manifest.getStorageIds()) {
        accountCount += id.getType() == ManifestRecord.Identifier.Type.ACCOUNT_VALUE ? 1 : 0;
    }
    if (accountCount > 1) {
        throw new MultipleAccountError();
    }
    if (accountCount == 0) {
        throw new MissingAccountError();
    }
    for (SignalStorageRecord insert : inserts) {
        if (!allSet.contains(insert.getId())) {
            throw new InsertNotPresentInFullIdSetError();
        }
        if (insert.isUnknown()) {
            throw new UnknownInsertError();
        }
        if (insert.getContact().isPresent()) {
            SignalServiceAddress address = insert.getContact().get().getAddress();
            if (self.requireE164().equals(address.getNumber().or("")) || self.requireServiceId().equals(address.getServiceId())) {
                throw new SelfAddedAsContactError();
            }
        }
    }
}
Also used : Collectors(com.annimon.stream.Collectors) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) Base64(org.thoughtcrime.securesms.util.Base64) ManifestRecord(org.whispersystems.signalservice.internal.storage.protos.ManifestRecord) Set(java.util.Set) SetUtil(org.thoughtcrime.securesms.util.SetUtil) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) ByteBuffer(java.nio.ByteBuffer) HashSet(java.util.HashSet) Log(org.signal.core.util.logging.Log) List(java.util.List) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalStorageRecord(org.whispersystems.signalservice.api.storage.SignalStorageRecord) SignalStorageManifest(org.whispersystems.signalservice.api.storage.SignalStorageManifest) StorageId(org.whispersystems.signalservice.api.storage.StorageId) SignalStorageRecord(org.whispersystems.signalservice.api.storage.SignalStorageRecord) StorageId(org.whispersystems.signalservice.api.storage.StorageId) ByteBuffer(java.nio.ByteBuffer) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) HashSet(java.util.HashSet)

Aggregations

SignalStorageManifest (org.whispersystems.signalservice.api.storage.SignalStorageManifest)14 SignalStorageRecord (org.whispersystems.signalservice.api.storage.SignalStorageRecord)10 StorageId (org.whispersystems.signalservice.api.storage.StorageId)10 ByteString (com.google.protobuf.ByteString)6 Recipient (org.thoughtcrime.securesms.recipients.Recipient)6 SignalServiceAccountManager (org.whispersystems.signalservice.api.SignalServiceAccountManager)6 StorageKey (org.whispersystems.signalservice.api.storage.StorageKey)6 StorageManifest (org.whispersystems.signalservice.internal.storage.protos.StorageManifest)6 NonNull (androidx.annotation.NonNull)4 Stream (com.annimon.stream.Stream)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Log (org.signal.core.util.logging.Log)4 UnknownStorageIdDatabase (org.thoughtcrime.securesms.database.UnknownStorageIdDatabase)4 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)4 RetryLaterException (org.thoughtcrime.securesms.transport.RetryLaterException)3 SignalAccountRecord (org.whispersystems.signalservice.api.storage.SignalAccountRecord)3 ManifestRecord (org.whispersystems.signalservice.internal.storage.protos.ManifestRecord)3 Collectors (com.annimon.stream.Collectors)2 IOException (java.io.IOException)2