Search in sources :

Example 11 with SignalServiceAddress

use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by WhisperSystems.

the class ProfileService method getProfile.

public Single<ServiceResponse<ProfileAndCredential>> getProfile(SignalServiceAddress address, Optional<ProfileKey> profileKey, Optional<UnidentifiedAccess> unidentifiedAccess, SignalServiceProfile.RequestType requestType, Locale locale) {
    ServiceId serviceId = address.getServiceId();
    SecureRandom random = new SecureRandom();
    ProfileKeyCredentialRequestContext requestContext = null;
    WebSocketProtos.WebSocketRequestMessage.Builder builder = WebSocketProtos.WebSocketRequestMessage.newBuilder().setId(random.nextLong()).setVerb("GET");
    if (profileKey.isPresent()) {
        ProfileKeyVersion profileKeyIdentifier = profileKey.get().getProfileKeyVersion(serviceId.uuid());
        String version = profileKeyIdentifier.serialize();
        if (requestType == SignalServiceProfile.RequestType.PROFILE_AND_CREDENTIAL) {
            requestContext = clientZkProfileOperations.createProfileKeyCredentialRequestContext(random, serviceId.uuid(), profileKey.get());
            ProfileKeyCredentialRequest request = requestContext.getRequest();
            String credentialRequest = Hex.toStringCondensed(request.serialize());
            builder.setPath(String.format("/v1/profile/%s/%s/%s", serviceId, version, credentialRequest));
        } else {
            builder.setPath(String.format("/v1/profile/%s/%s", serviceId, version));
        }
    } else {
        builder.setPath(String.format("/v1/profile/%s", address.getIdentifier()));
    }
    builder.addHeaders(AcceptLanguagesUtil.getAcceptLanguageHeader(locale));
    WebSocketProtos.WebSocketRequestMessage requestMessage = builder.build();
    ResponseMapper<ProfileAndCredential> responseMapper = DefaultResponseMapper.extend(ProfileAndCredential.class).withResponseMapper(new ProfileResponseMapper(requestType, requestContext)).build();
    return signalWebSocket.request(requestMessage, unidentifiedAccess).map(responseMapper::map).onErrorResumeNext(t -> restFallback(address, profileKey, unidentifiedAccess, requestType, locale)).onErrorReturn(ServiceResponse::forUnknownError);
}
Also used : Single(io.reactivex.rxjava3.core.Single) AcceptLanguagesUtil(org.whispersystems.signalservice.internal.push.http.AcceptLanguagesUtil) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException) SignalServiceMessageReceiver(org.whispersystems.signalservice.api.SignalServiceMessageReceiver) VerificationFailedException(org.signal.zkgroup.VerificationFailedException) SignalWebSocket(org.whispersystems.signalservice.api.SignalWebSocket) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) SignalServiceProfile(org.whispersystems.signalservice.api.profiles.SignalServiceProfile) SecureRandom(java.security.SecureRandom) UnidentifiedAccess(org.whispersystems.signalservice.api.crypto.UnidentifiedAccess) Pair(org.whispersystems.libsignal.util.Pair) ProfileAndCredential(org.whispersystems.signalservice.api.profiles.ProfileAndCredential) ProfileKeyCredentialRequest(org.signal.zkgroup.profiles.ProfileKeyCredentialRequest) Locale(java.util.Locale) Hex(org.whispersystems.signalservice.internal.util.Hex) DefaultResponseMapper(org.whispersystems.signalservice.internal.websocket.DefaultResponseMapper) ClientZkProfileOperations(org.signal.zkgroup.profiles.ClientZkProfileOperations) ProfileKeyCredential(org.signal.zkgroup.profiles.ProfileKeyCredential) ACI(org.whispersystems.signalservice.api.push.ACI) WebSocketProtos(org.whispersystems.signalservice.internal.websocket.WebSocketProtos) ProfileKeyVersion(org.signal.zkgroup.profiles.ProfileKeyVersion) Function(org.whispersystems.libsignal.util.guava.Function) ServiceResponse(org.whispersystems.signalservice.internal.ServiceResponse) JsonUtil(org.whispersystems.signalservice.internal.util.JsonUtil) Optional(org.whispersystems.libsignal.util.guava.Optional) TimeUnit(java.util.concurrent.TimeUnit) ProfileKeyCredentialRequestContext(org.signal.zkgroup.profiles.ProfileKeyCredentialRequestContext) ResponseMapper(org.whispersystems.signalservice.internal.websocket.ResponseMapper) ServiceResponseProcessor(org.whispersystems.signalservice.internal.ServiceResponseProcessor) ServiceId(org.whispersystems.signalservice.api.push.ServiceId) SecureRandom(java.security.SecureRandom) ProfileAndCredential(org.whispersystems.signalservice.api.profiles.ProfileAndCredential) ProfileKeyCredentialRequestContext(org.signal.zkgroup.profiles.ProfileKeyCredentialRequestContext) ServiceId(org.whispersystems.signalservice.api.push.ServiceId) ServiceResponse(org.whispersystems.signalservice.internal.ServiceResponse) ProfileKeyCredentialRequest(org.signal.zkgroup.profiles.ProfileKeyCredentialRequest) ProfileKeyVersion(org.signal.zkgroup.profiles.ProfileKeyVersion) WebSocketProtos(org.whispersystems.signalservice.internal.websocket.WebSocketProtos)

Example 12 with SignalServiceAddress

use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by WhisperSystems.

the class DeviceGroupsOutputStream method writeGroupDetails.

private void writeGroupDetails(DeviceGroup group) throws IOException {
    GroupDetails.Builder groupDetails = GroupDetails.newBuilder();
    groupDetails.setId(ByteString.copyFrom(group.getId()));
    if (group.getName().isPresent()) {
        groupDetails.setName(group.getName().get());
    }
    if (group.getAvatar().isPresent()) {
        GroupDetails.Avatar.Builder avatarBuilder = GroupDetails.Avatar.newBuilder();
        avatarBuilder.setContentType(group.getAvatar().get().getContentType());
        avatarBuilder.setLength((int) group.getAvatar().get().getLength());
        groupDetails.setAvatar(avatarBuilder);
    }
    if (group.getExpirationTimer().isPresent()) {
        groupDetails.setExpireTimer(group.getExpirationTimer().get());
    }
    if (group.getColor().isPresent()) {
        groupDetails.setColor(group.getColor().get());
    }
    List<GroupDetails.Member> members = new ArrayList<>(group.getMembers().size());
    List<String> membersE164 = new ArrayList<>(group.getMembers().size());
    for (SignalServiceAddress address : group.getMembers()) {
        if (address.getNumber().isPresent()) {
            membersE164.add(address.getNumber().get());
            GroupDetails.Member.Builder builder = GroupDetails.Member.newBuilder();
            builder.setE164(address.getNumber().get());
            members.add(builder.build());
        }
    }
    groupDetails.addAllMembers(members);
    groupDetails.addAllMembersE164(membersE164);
    groupDetails.setActive(group.isActive());
    groupDetails.setBlocked(group.isBlocked());
    groupDetails.setArchived(group.isArchived());
    if (group.getInboxPosition().isPresent()) {
        groupDetails.setInboxPosition(group.getInboxPosition().get());
    }
    byte[] serializedContactDetails = groupDetails.build().toByteArray();
    writeVarint32(serializedContactDetails.length);
    out.write(serializedContactDetails);
}
Also used : GroupDetails(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupDetails) ArrayList(java.util.ArrayList) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) ByteString(com.google.protobuf.ByteString)

Example 13 with SignalServiceAddress

use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by WhisperSystems.

the class MultiDeviceBlockedUpdateJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    if (!TextSecurePreferences.isMultiDevice(context)) {
        Log.i(TAG, "Not multi device, aborting...");
        return;
    }
    RecipientDatabase database = SignalDatabase.recipients();
    try (RecipientReader reader = database.readerForBlocked(database.getBlocked())) {
        List<SignalServiceAddress> blockedIndividuals = new LinkedList<>();
        List<byte[]> blockedGroups = new LinkedList<>();
        Recipient recipient;
        while ((recipient = reader.getNext()) != null) {
            if (recipient.isPushGroup()) {
                blockedGroups.add(recipient.requireGroupId().getDecodedId());
            } else if (recipient.isMaybeRegistered() && (recipient.hasServiceId() || recipient.hasE164())) {
                blockedIndividuals.add(RecipientUtil.toSignalServiceAddress(context, recipient));
            }
        }
        SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
        messageSender.sendSyncMessage(SignalServiceSyncMessage.forBlocked(new BlockedListMessage(blockedIndividuals, blockedGroups)), UnidentifiedAccessUtil.getAccessForSync(context));
    }
}
Also used : RecipientReader(org.thoughtcrime.securesms.database.RecipientDatabase.RecipientReader) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) Recipient(org.thoughtcrime.securesms.recipients.Recipient) BlockedListMessage(org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage) LinkedList(java.util.LinkedList)

Example 14 with SignalServiceAddress

use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by WhisperSystems.

the class ResendMessageJob method onRun.

@Override
protected void onRun() throws Exception {
    if (SignalStore.internalValues().delayResends()) {
        Log.w(TAG, "Delaying resend by 10 sec because of an internal preference.");
        ThreadUtil.sleep(10000);
    }
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    Recipient recipient = Recipient.resolved(recipientId);
    if (recipient.isUnregistered()) {
        Log.w(TAG, recipient.getId() + " is unregistered!");
        return;
    }
    SignalServiceAddress address = RecipientUtil.toSignalServiceAddress(context, recipient);
    Optional<UnidentifiedAccessPair> access = UnidentifiedAccessUtil.getAccessFor(context, recipient);
    Content contentToSend = content;
    if (distributionId != null) {
        Optional<GroupRecord> groupRecord = SignalDatabase.groups().getGroupByDistributionId(distributionId);
        if (!groupRecord.isPresent()) {
            Log.w(TAG, "Could not find a matching group for the distributionId! Skipping message send.");
            return;
        } else if (!groupRecord.get().getMembers().contains(recipientId)) {
            Log.w(TAG, "The target user is no longer in the group! Skipping message send.");
            return;
        }
        SenderKeyDistributionMessage senderKeyDistributionMessage = messageSender.getOrCreateNewGroupSession(distributionId);
        ByteString distributionBytes = ByteString.copyFrom(senderKeyDistributionMessage.serialize());
        contentToSend = contentToSend.toBuilder().setSenderKeyDistributionMessage(distributionBytes).build();
    }
    SendMessageResult result = messageSender.resendContent(address, access, sentTimestamp, contentToSend, contentHint, Optional.fromNullable(groupId).transform(GroupId::getDecodedId));
    if (result.isSuccess() && distributionId != null) {
        List<SignalProtocolAddress> addresses = result.getSuccess().getDevices().stream().map(device -> recipient.requireServiceId().toProtocolAddress(device)).collect(Collectors.toList());
        ApplicationDependencies.getProtocolStore().aci().markSenderKeySharedWith(distributionId, addresses);
    }
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) ContentHint(org.whispersystems.signalservice.api.crypto.ContentHint) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) NonNull(androidx.annotation.NonNull) Data(org.thoughtcrime.securesms.jobmanager.Data) RecipientUtil(org.thoughtcrime.securesms.recipients.RecipientUtil) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) UnidentifiedAccessPair(org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) Recipient(org.thoughtcrime.securesms.recipients.Recipient) DistributionId(org.whispersystems.signalservice.api.push.DistributionId) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) SenderKeyDistributionMessage(org.whispersystems.libsignal.protocol.SenderKeyDistributionMessage) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) UnidentifiedAccessUtil(org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil) ThreadUtil(org.signal.core.util.ThreadUtil) Collectors(java.util.stream.Collectors) Optional(org.whispersystems.libsignal.util.guava.Optional) ByteString(com.google.protobuf.ByteString) TimeUnit(java.util.concurrent.TimeUnit) Log(org.signal.core.util.logging.Log) List(java.util.List) Nullable(androidx.annotation.Nullable) GroupId(org.thoughtcrime.securesms.groups.GroupId) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) Job(org.thoughtcrime.securesms.jobmanager.Job) ByteString(com.google.protobuf.ByteString) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) Recipient(org.thoughtcrime.securesms.recipients.Recipient) UnidentifiedAccessPair(org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) SenderKeyDistributionMessage(org.whispersystems.libsignal.protocol.SenderKeyDistributionMessage) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 15 with SignalServiceAddress

use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by WhisperSystems.

the class MultiDeviceOutgoingPaymentSyncJob method onRun.

@Override
protected void onRun() throws Exception {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    if (!TextSecurePreferences.isMultiDevice(context)) {
        Log.i(TAG, "Not multi device, aborting...");
        return;
    }
    PaymentDatabase.PaymentTransaction payment = SignalDatabase.payments().getPayment(uuid);
    if (payment == null) {
        Log.w(TAG, "Payment not found " + uuid);
        return;
    }
    PaymentMetaData.MobileCoinTxoIdentification txoIdentification = payment.getPaymentMetaData().getMobileCoinTxoIdentification();
    boolean defrag = payment.isDefrag();
    Optional<SignalServiceAddress> uuid;
    if (!defrag && payment.getPayee().hasRecipientId()) {
        uuid = Optional.of(new SignalServiceAddress(Recipient.resolved(payment.getPayee().requireRecipientId()).requireServiceId()));
    } else {
        uuid = Optional.absent();
    }
    byte[] receipt = payment.getReceipt();
    if (receipt == null) {
        throw new AssertionError("Trying to sync payment before sent?");
    }
    OutgoingPaymentMessage outgoingPaymentMessage = new OutgoingPaymentMessage(uuid, payment.getAmount().requireMobileCoin(), payment.getFee().requireMobileCoin(), ByteString.copyFrom(receipt), payment.getBlockIndex(), payment.getTimestamp(), defrag ? Optional.absent() : Optional.of(payment.getPayee().requirePublicAddress().serialize()), defrag ? Optional.absent() : Optional.of(payment.getNote()), txoIdentification.getPublicKeyList(), txoIdentification.getKeyImagesList());
    ApplicationDependencies.getSignalServiceMessageSender().sendSyncMessage(SignalServiceSyncMessage.forOutgoingPayment(outgoingPaymentMessage), UnidentifiedAccessUtil.getAccessForSync(context));
}
Also used : PaymentMetaData(org.thoughtcrime.securesms.payments.proto.PaymentMetaData) OutgoingPaymentMessage(org.whispersystems.signalservice.api.messages.multidevice.OutgoingPaymentMessage) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) PaymentDatabase(org.thoughtcrime.securesms.database.PaymentDatabase)

Aggregations

SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)113 Recipient (org.thoughtcrime.securesms.recipients.Recipient)44 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)32 SendMessageResult (org.whispersystems.signalservice.api.messages.SendMessageResult)28 LinkedList (java.util.LinkedList)27 Optional (org.whispersystems.libsignal.util.guava.Optional)23 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)21 NotPushRegisteredException (org.thoughtcrime.securesms.net.NotPushRegisteredException)20 UnidentifiedAccessPair (org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair)20 NonNull (androidx.annotation.NonNull)18 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)18 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)16 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)15 List (java.util.List)14 ByteString (com.google.protobuf.ByteString)13 Nullable (androidx.annotation.Nullable)12 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)12 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)10