Search in sources :

Example 6 with InvalidInputException

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

the class ProfileKeySet method addMemberKey.

private void addMemberKey(@Nullable UUID changeSource, @NonNull ByteString memberUuidBytes, @NonNull ByteString profileKeyBytes) {
    UUID memberUuid = UuidUtil.fromByteString(memberUuidBytes);
    if (UuidUtil.UNKNOWN_UUID.equals(memberUuid)) {
        Log.w(TAG, "Seen unknown member UUID");
        return;
    }
    ProfileKey profileKey;
    try {
        profileKey = new ProfileKey(profileKeyBytes.toByteArray());
    } catch (InvalidInputException e) {
        Log.w(TAG, "Bad profile key in group");
        return;
    }
    if (memberUuid.equals(changeSource)) {
        authoritativeProfileKeys.put(ACI.from(memberUuid), profileKey);
        profileKeys.remove(ACI.from(memberUuid));
    } else {
        if (!authoritativeProfileKeys.containsKey(ACI.from(memberUuid))) {
            profileKeys.put(ACI.from(memberUuid), profileKey);
        }
    }
}
Also used : InvalidInputException(org.signal.zkgroup.InvalidInputException) UUID(java.util.UUID) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Example 7 with InvalidInputException

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

the class SubscriptionReceiptRequestResponseJob method generateRequestContext.

private static ReceiptCredentialRequestContext generateRequestContext() {
    Log.d(TAG, "Generating request credentials context for token redemption...", true);
    SecureRandom secureRandom = new SecureRandom();
    byte[] randomBytes = Util.getSecretBytes(ReceiptSerial.SIZE);
    try {
        ReceiptSerial receiptSerial = new ReceiptSerial(randomBytes);
        ClientZkReceiptOperations operations = ApplicationDependencies.getClientZkReceiptOperations();
        return operations.createReceiptCredentialRequestContext(secureRandom, receiptSerial);
    } catch (InvalidInputException | VerificationFailedException e) {
        Log.e(TAG, "Failed to create credential.", e);
        throw new AssertionError(e);
    }
}
Also used : InvalidInputException(org.signal.zkgroup.InvalidInputException) ReceiptSerial(org.signal.zkgroup.receipts.ReceiptSerial) ClientZkReceiptOperations(org.signal.zkgroup.receipts.ClientZkReceiptOperations) SecureRandom(java.security.SecureRandom) VerificationFailedException(org.signal.zkgroup.VerificationFailedException)

Example 8 with InvalidInputException

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

the class SignalCallManager method onSendCallMessageToGroup.

@Override
public void onSendCallMessageToGroup(@NonNull byte[] groupIdBytes, @NonNull byte[] message, @NonNull CallManager.CallMessageUrgency urgency) {
    Log.i(TAG, "onSendCallMessageToGroup():");
    networkExecutor.execute(() -> {
        try {
            GroupId groupId = GroupId.v2(new GroupIdentifier(groupIdBytes));
            List<Recipient> recipients = SignalDatabase.groups().getGroupMembers(groupId, GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF);
            recipients = RecipientUtil.getEligibleForSending((recipients.stream().map(Recipient::resolve).filter(r -> !r.isBlocked()).collect(Collectors.toList())));
            OpaqueMessage opaqueMessage = new OpaqueMessage(message, getUrgencyFromCallUrgency(urgency));
            SignalServiceCallMessage callMessage = SignalServiceCallMessage.forOutgoingGroupOpaque(groupId.getDecodedId(), System.currentTimeMillis(), opaqueMessage, true, null);
            RecipientAccessList accessList = new RecipientAccessList(recipients);
            List<SendMessageResult> results = GroupSendUtil.sendCallMessage(context, groupId.requireV2(), recipients, callMessage);
            Set<RecipientId> identifyFailureRecipientIds = results.stream().filter(result -> result.getIdentityFailure() != null).map(result -> accessList.requireIdByAddress(result.getAddress())).collect(Collectors.toSet());
            if (Util.hasItems(identifyFailureRecipientIds)) {
                process((s, p) -> p.handleGroupMessageSentError(s, identifyFailureRecipientIds, UNTRUSTED_IDENTITY));
                RetrieveProfileJob.enqueue(identifyFailureRecipientIds);
            }
        } catch (UntrustedIdentityException | IOException | InvalidInputException e) {
            Log.w(TAG, "onSendCallMessageToGroup failed", e);
        }
    });
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) SignalAudioManager(org.thoughtcrime.securesms.webrtc.audio.SignalAudioManager) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) NetworkRoute(org.signal.ringrtc.NetworkRoute) BubbleUtil(org.thoughtcrime.securesms.util.BubbleUtil) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) CallingResponse(org.whispersystems.signalservice.api.messages.calls.CallingResponse) TurnServerInfo(org.whispersystems.signalservice.api.messages.calls.TurnServerInfo) NonNull(androidx.annotation.NonNull) RecipientUtil(org.thoughtcrime.securesms.recipients.RecipientUtil) CallException(org.signal.ringrtc.CallException) WebRtcCallActivity(org.thoughtcrime.securesms.WebRtcCallActivity) CallManager(org.signal.ringrtc.CallManager) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) NetworkUtil(org.thoughtcrime.securesms.util.NetworkUtil) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IDLE(org.thoughtcrime.securesms.events.WebRtcViewModel.GroupCallState.IDLE) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) WebRtcUtil.getUrgencyFromCallUrgency(org.thoughtcrime.securesms.service.webrtc.WebRtcUtil.getUrgencyFromCallUrgency) GroupExternalCredential(org.signal.storageservice.protos.groups.GroupExternalCredential) ACI(org.whispersystems.signalservice.api.push.ACI) HttpHeader(org.signal.ringrtc.HttpHeader) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Collection(java.util.Collection) GroupCallUpdateSendJob(org.thoughtcrime.securesms.jobs.GroupCallUpdateSendJob) Set(java.util.Set) UnidentifiedAccessUtil(org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil) UUID(java.util.UUID) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) UNTRUSTED_IDENTITY(org.thoughtcrime.securesms.events.WebRtcViewModel.State.UNTRUSTED_IDENTITY) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) InvalidInputException(org.signal.zkgroup.InvalidInputException) GroupCall(org.signal.ringrtc.GroupCall) Log(org.signal.core.util.logging.Log) List(java.util.List) Nullable(androidx.annotation.Nullable) Application(android.app.Application) GroupId(org.thoughtcrime.securesms.groups.GroupId) CallId(org.signal.ringrtc.CallId) CameraEventListener(org.thoughtcrime.securesms.ringrtc.CameraEventListener) Context(android.content.Context) RecipientAccessList(org.thoughtcrime.securesms.util.RecipientAccessList) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) Stream(com.annimon.stream.Stream) Remote(org.signal.ringrtc.Remote) Util(org.thoughtcrime.securesms.util.Util) VerificationFailedException(org.signal.zkgroup.VerificationFailedException) Intent(android.content.Intent) AppForegroundObserver(org.thoughtcrime.securesms.util.AppForegroundObserver) RetrieveProfileJob(org.thoughtcrime.securesms.jobs.RetrieveProfileJob) NETWORK_FAILURE(org.thoughtcrime.securesms.events.WebRtcViewModel.State.NETWORK_FAILURE) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) LockManager(org.thoughtcrime.securesms.webrtc.locks.LockManager) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) OpaqueMessage(org.whispersystems.signalservice.api.messages.calls.OpaqueMessage) GroupManager(org.thoughtcrime.securesms.groups.GroupManager) CameraState(org.thoughtcrime.securesms.ringrtc.CameraState) Pair(org.whispersystems.libsignal.util.Pair) EventBus(org.greenrobot.eventbus.EventBus) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) Build(android.os.Build) LinkedList(java.util.LinkedList) GroupSendUtil(org.thoughtcrime.securesms.messages.GroupSendUtil) WebRtcServiceState(org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceState) ExecutorService(java.util.concurrent.ExecutorService) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) PeerConnection(org.webrtc.PeerConnection) Executor(java.util.concurrent.Executor) WebRtcViewModel(org.thoughtcrime.securesms.events.WebRtcViewModel) IOException(java.io.IOException) NO_SUCH_USER(org.thoughtcrime.securesms.events.WebRtcViewModel.State.NO_SUCH_USER) GroupCallPeekEvent(org.thoughtcrime.securesms.events.GroupCallPeekEvent) Optional(org.whispersystems.libsignal.util.guava.Optional) UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) GroupIdentifier(org.signal.zkgroup.groups.GroupIdentifier) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) CALL_INCOMING(org.thoughtcrime.securesms.events.WebRtcViewModel.State.CALL_INCOMING) ResultReceiver(android.os.ResultReceiver) Collections(java.util.Collections) InvalidInputException(org.signal.zkgroup.InvalidInputException) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IOException(java.io.IOException) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) GroupId(org.thoughtcrime.securesms.groups.GroupId) GroupIdentifier(org.signal.zkgroup.groups.GroupIdentifier) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) RecipientAccessList(org.thoughtcrime.securesms.util.RecipientAccessList) OpaqueMessage(org.whispersystems.signalservice.api.messages.calls.OpaqueMessage)

Example 9 with InvalidInputException

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

the class GroupsV2Api method parseCredentialResponse.

private static HashMap<Integer, AuthCredentialResponse> parseCredentialResponse(CredentialResponse credentialResponse) throws IOException {
    HashMap<Integer, AuthCredentialResponse> credentials = new HashMap<>();
    for (TemporalCredential credential : credentialResponse.getCredentials()) {
        AuthCredentialResponse authCredentialResponse;
        try {
            authCredentialResponse = new AuthCredentialResponse(credential.getCredential());
        } catch (InvalidInputException e) {
            throw new IOException(e);
        }
        credentials.put(credential.getRedemptionTime(), authCredentialResponse);
    }
    return credentials;
}
Also used : InvalidInputException(org.signal.zkgroup.InvalidInputException) HashMap(java.util.HashMap) IOException(java.io.IOException) AuthCredentialResponse(org.signal.zkgroup.auth.AuthCredentialResponse)

Example 10 with InvalidInputException

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

the class DeviceContactsInputStream method read.

public DeviceContact read() throws IOException {
    int detailsLength = (int) readRawVarint32();
    if (detailsLength == -1) {
        return null;
    }
    byte[] detailsSerialized = new byte[(int) detailsLength];
    Util.readFully(in, detailsSerialized);
    SignalServiceProtos.ContactDetails details = SignalServiceProtos.ContactDetails.parseFrom(detailsSerialized);
    if (!SignalServiceAddress.isValidAddress(details.getUuid(), details.getNumber())) {
        throw new IOException("Missing contact address!");
    }
    SignalServiceAddress address = new SignalServiceAddress(ACI.parseOrThrow(details.getUuid()), details.getNumber());
    Optional<String> name = Optional.fromNullable(details.getName());
    Optional<SignalServiceAttachmentStream> avatar = Optional.absent();
    Optional<String> color = details.hasColor() ? Optional.of(details.getColor()) : Optional.<String>absent();
    Optional<VerifiedMessage> verified = Optional.absent();
    Optional<ProfileKey> profileKey = Optional.absent();
    boolean blocked = false;
    Optional<Integer> expireTimer = Optional.absent();
    Optional<Integer> inboxPosition = Optional.absent();
    boolean archived = false;
    if (details.hasAvatar()) {
        long avatarLength = details.getAvatar().getLength();
        InputStream avatarStream = new LimitedInputStream(in, avatarLength);
        String avatarContentType = details.getAvatar().getContentType();
        avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, Optional.<String>absent(), false, false, false, null, null));
    }
    if (details.hasVerified()) {
        try {
            if (!SignalServiceAddress.isValidAddress(details.getVerified().getDestinationUuid(), details.getVerified().getDestinationE164())) {
                throw new InvalidMessageException("Missing Verified address!");
            }
            IdentityKey identityKey = new IdentityKey(details.getVerified().getIdentityKey().toByteArray(), 0);
            SignalServiceAddress destination = new SignalServiceAddress(ACI.parseOrThrow(details.getVerified().getDestinationUuid()), details.getVerified().getDestinationE164());
            VerifiedMessage.VerifiedState state;
            switch(details.getVerified().getState()) {
                case VERIFIED:
                    state = VerifiedMessage.VerifiedState.VERIFIED;
                    break;
                case UNVERIFIED:
                    state = VerifiedMessage.VerifiedState.UNVERIFIED;
                    break;
                case DEFAULT:
                    state = VerifiedMessage.VerifiedState.DEFAULT;
                    break;
                default:
                    throw new InvalidMessageException("Unknown state: " + details.getVerified().getState());
            }
            verified = Optional.of(new VerifiedMessage(destination, identityKey, state, System.currentTimeMillis()));
        } catch (InvalidKeyException | InvalidMessageException e) {
            Log.w(TAG, e);
            verified = Optional.absent();
        }
    }
    if (details.hasProfileKey()) {
        try {
            profileKey = Optional.fromNullable(new ProfileKey(details.getProfileKey().toByteArray()));
        } catch (InvalidInputException e) {
            Log.w(TAG, "Invalid profile key ignored", e);
        }
    }
    if (details.hasExpireTimer() && details.getExpireTimer() > 0) {
        expireTimer = Optional.of(details.getExpireTimer());
    }
    if (details.hasInboxPosition()) {
        inboxPosition = Optional.of(details.getInboxPosition());
    }
    blocked = details.getBlocked();
    archived = details.getArchived();
    return new DeviceContact(address, name, avatar, color, verified, profileKey, blocked, expireTimer, inboxPosition, archived);
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) SignalServiceAttachmentStream(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) InvalidInputException(org.signal.zkgroup.InvalidInputException) IdentityKey(org.whispersystems.libsignal.IdentityKey) InputStream(java.io.InputStream) IOException(java.io.IOException) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos)

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