Search in sources :

Example 1 with InvalidInputException

use of org.signal.zkgroup.InvalidInputException in project Signal-Android by WhisperSystems.

the class ProtoTestUtils method randomProfileKey.

static ProfileKey randomProfileKey() {
    byte[] contents = new byte[32];
    new SecureRandom().nextBytes(contents);
    try {
        return new ProfileKey(contents);
    } catch (InvalidInputException e) {
        throw new AssertionError();
    }
}
Also used : InvalidInputException(org.signal.zkgroup.InvalidInputException) SecureRandom(java.security.SecureRandom) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Example 2 with InvalidInputException

use of org.signal.zkgroup.InvalidInputException in project Signal-Android by WhisperSystems.

the class GroupsV2AuthorizationSignalStoreCache method read.

@Override
@NonNull
public Map<Integer, AuthCredentialResponse> read() {
    byte[] credentialBlob = store.getBlob(KEY, null);
    if (credentialBlob == null) {
        Log.i(TAG, "No credentials responses are cached locally");
        return Collections.emptyMap();
    }
    try {
        TemporalAuthCredentialResponses temporalCredentials = TemporalAuthCredentialResponses.parseFrom(credentialBlob);
        HashMap<Integer, AuthCredentialResponse> result = new HashMap<>(temporalCredentials.getCredentialResponseCount());
        for (TemporalAuthCredentialResponse credential : temporalCredentials.getCredentialResponseList()) {
            result.put(credential.getDate(), new AuthCredentialResponse(credential.getAuthCredentialResponse().toByteArray()));
        }
        Log.i(TAG, String.format(Locale.US, "Loaded %d credentials from local storage", result.size()));
        return result;
    } catch (InvalidProtocolBufferException | InvalidInputException e) {
        throw new AssertionError(e);
    }
}
Also used : TemporalAuthCredentialResponse(org.thoughtcrime.securesms.database.model.databaseprotos.TemporalAuthCredentialResponse) InvalidInputException(org.signal.zkgroup.InvalidInputException) HashMap(java.util.HashMap) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) TemporalAuthCredentialResponses(org.thoughtcrime.securesms.database.model.databaseprotos.TemporalAuthCredentialResponses) AuthCredentialResponse(org.signal.zkgroup.auth.AuthCredentialResponse) TemporalAuthCredentialResponse(org.thoughtcrime.securesms.database.model.databaseprotos.TemporalAuthCredentialResponse) NonNull(androidx.annotation.NonNull)

Example 3 with InvalidInputException

use of org.signal.zkgroup.InvalidInputException in project Signal-Android by WhisperSystems.

the class ThreadDatabase method applyStorageSyncUpdate.

public void applyStorageSyncUpdate(@NonNull RecipientId recipientId, @NonNull SignalAccountRecord record) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    db.beginTransaction();
    try {
        applyStorageSyncUpdate(recipientId, record.isNoteToSelfArchived(), record.isNoteToSelfForcedUnread());
        ContentValues clearPinnedValues = new ContentValues();
        clearPinnedValues.put(PINNED, 0);
        db.update(TABLE_NAME, clearPinnedValues, null, null);
        int pinnedPosition = 1;
        for (SignalAccountRecord.PinnedConversation pinned : record.getPinnedConversations()) {
            ContentValues pinnedValues = new ContentValues();
            pinnedValues.put(PINNED, pinnedPosition);
            Recipient pinnedRecipient;
            if (pinned.getContact().isPresent()) {
                pinnedRecipient = Recipient.externalPush(pinned.getContact().get());
            } else if (pinned.getGroupV1Id().isPresent()) {
                try {
                    pinnedRecipient = Recipient.externalGroupExact(context, GroupId.v1(pinned.getGroupV1Id().get()));
                } catch (BadGroupIdException e) {
                    Log.w(TAG, "Failed to parse pinned groupV1 ID!", e);
                    pinnedRecipient = null;
                }
            } else if (pinned.getGroupV2MasterKey().isPresent()) {
                try {
                    pinnedRecipient = Recipient.externalGroupExact(context, GroupId.v2(new GroupMasterKey(pinned.getGroupV2MasterKey().get())));
                } catch (InvalidInputException e) {
                    Log.w(TAG, "Failed to parse pinned groupV2 master key!", e);
                    pinnedRecipient = null;
                }
            } else {
                Log.w(TAG, "Empty pinned conversation on the AccountRecord?");
                pinnedRecipient = null;
            }
            if (pinnedRecipient != null) {
                db.update(TABLE_NAME, pinnedValues, RECIPIENT_ID + " = ?", SqlUtil.buildArgs(pinnedRecipient.getId()));
            }
            pinnedPosition++;
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    notifyConversationListListeners();
}
Also used : ContentValues(android.content.ContentValues) InvalidInputException(org.signal.zkgroup.InvalidInputException) SignalAccountRecord(org.whispersystems.signalservice.api.storage.SignalAccountRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey) BadGroupIdException(org.thoughtcrime.securesms.groups.BadGroupIdException)

Example 4 with InvalidInputException

use of org.signal.zkgroup.InvalidInputException in project Signal-Android by WhisperSystems.

the class ProfileUtil method getProfileKey.

private static ProfileKey getProfileKey(@NonNull Recipient recipient) throws IOException {
    byte[] profileKeyBytes = recipient.getProfileKey();
    if (profileKeyBytes == null) {
        Log.w(TAG, "Profile key unknown for " + recipient.getId());
        throw new IOException("No profile key");
    }
    ProfileKey profileKey;
    try {
        profileKey = new ProfileKey(profileKeyBytes);
    } catch (InvalidInputException e) {
        Log.w(TAG, "Profile key invalid for " + recipient.getId());
        throw new IOException("Invalid profile key");
    }
    return profileKey;
}
Also used : InvalidInputException(org.signal.zkgroup.InvalidInputException) IOException(java.io.IOException) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Example 5 with InvalidInputException

use of org.signal.zkgroup.InvalidInputException in project Signal-Android by WhisperSystems.

the class SignalCallManager method onGroupCallRingUpdate.

@Override
public void onGroupCallRingUpdate(@NonNull byte[] groupIdBytes, long ringId, @NonNull UUID uuid, @NonNull CallManager.RingUpdate ringUpdate) {
    try {
        GroupId.V2 groupId = GroupId.v2(new GroupIdentifier(groupIdBytes));
        Optional<GroupDatabase.GroupRecord> group = SignalDatabase.groups().getGroup(groupId);
        if (group.isPresent()) {
            process((s, p) -> p.handleGroupCallRingUpdate(s, new RemotePeer(group.get().getRecipientId()), groupId, ringId, uuid, ringUpdate));
        } else {
            Log.w(TAG, "Unable to ring unknown group.");
        }
    } catch (InvalidInputException e) {
        Log.w(TAG, "Unable to ring group due to invalid group id", e);
    }
}
Also used : InvalidInputException(org.signal.zkgroup.InvalidInputException) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) GroupId(org.thoughtcrime.securesms.groups.GroupId) GroupIdentifier(org.signal.zkgroup.groups.GroupIdentifier)

Aggregations

InvalidInputException (org.signal.zkgroup.InvalidInputException)14 IOException (java.io.IOException)5 GroupMasterKey (org.signal.zkgroup.groups.GroupMasterKey)4 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)3 Recipient (org.thoughtcrime.securesms.recipients.Recipient)3 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 ByteString (com.google.protobuf.ByteString)2 SecureRandom (java.security.SecureRandom)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 VerificationFailedException (org.signal.zkgroup.VerificationFailedException)2 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)2 SignalServiceProtos (org.whispersystems.signalservice.internal.push.SignalServiceProtos)2 Application (android.app.Application)1 ContentValues (android.content.ContentValues)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Build (android.os.Build)1 ResultReceiver (android.os.ResultReceiver)1