Search in sources :

Example 41 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.

the class SenderKeyDistributionSendJob method onRun.

@Override
protected void onRun() throws Exception {
    GroupDatabase groupDatabase = SignalDatabase.groups();
    if (!groupDatabase.isCurrentMember(groupId, recipientId)) {
        Log.w(TAG, recipientId + " is no longer a member of " + groupId + "! Not sending.");
        return;
    }
    Recipient recipient = Recipient.resolved(recipientId);
    if (recipient.getSenderKeyCapability() != Recipient.Capability.SUPPORTED) {
        Log.w(TAG, recipientId + " does not support sender key! Not sending.");
        return;
    }
    if (recipient.isUnregistered()) {
        Log.w(TAG, recipient.getId() + " not registered!");
        return;
    }
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    List<SignalServiceAddress> address = Collections.singletonList(RecipientUtil.toSignalServiceAddress(context, recipient));
    DistributionId distributionId = groupDatabase.getOrCreateDistributionId(groupId);
    SenderKeyDistributionMessage message = messageSender.getOrCreateNewGroupSession(distributionId);
    List<Optional<UnidentifiedAccessPair>> access = UnidentifiedAccessUtil.getAccessFor(context, Collections.singletonList(recipient));
    SendMessageResult result = messageSender.sendSenderKeyDistributionMessage(distributionId, address, access, message, groupId.getDecodedId()).get(0);
    if (result.isSuccess()) {
        List<SignalProtocolAddress> addresses = result.getSuccess().getDevices().stream().map(device -> recipient.requireServiceId().toProtocolAddress(device)).collect(Collectors.toList());
        ApplicationDependencies.getProtocolStore().aci().markSenderKeySharedWith(distributionId, addresses);
    }
}
Also used : SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) NonNull(androidx.annotation.NonNull) Data(org.thoughtcrime.securesms.jobmanager.Data) RecipientUtil(org.thoughtcrime.securesms.recipients.RecipientUtil) 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) 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) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) Collectors(java.util.stream.Collectors) Optional(org.whispersystems.libsignal.util.guava.Optional) TimeUnit(java.util.concurrent.TimeUnit) Log(org.signal.core.util.logging.Log) List(java.util.List) GroupId(org.thoughtcrime.securesms.groups.GroupId) Job(org.thoughtcrime.securesms.jobmanager.Job) Collections(java.util.Collections) Optional(org.whispersystems.libsignal.util.guava.Optional) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) Recipient(org.thoughtcrime.securesms.recipients.Recipient) DistributionId(org.whispersystems.signalservice.api.push.DistributionId) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) SenderKeyDistributionMessage(org.whispersystems.libsignal.protocol.SenderKeyDistributionMessage) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 42 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.

the class DirectoryHelper method hasSession.

public static boolean hasSession(@NonNull RecipientId id) {
    Recipient recipient = Recipient.resolved(id);
    if (!recipient.hasServiceId()) {
        return false;
    }
    SignalProtocolAddress protocolAddress = Recipient.resolved(id).requireServiceId().toProtocolAddress(SignalServiceAddress.DEFAULT_DEVICE_ID);
    return ApplicationDependencies.getProtocolStore().aci().containsSession(protocolAddress) || ApplicationDependencies.getProtocolStore().pni().containsSession(protocolAddress);
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 43 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.

the class PushDecryptMessageJob method handleSenderKeyDistributionMessage.

private void handleSenderKeyDistributionMessage(@NonNull SignalServiceAddress address, int deviceId, @NonNull SenderKeyDistributionMessage message) {
    Log.i(TAG, "Processing SenderKeyDistributionMessage.");
    SignalServiceMessageSender sender = ApplicationDependencies.getSignalServiceMessageSender();
    sender.processSenderKeyDistributionMessage(new SignalProtocolAddress(address.getIdentifier(), deviceId), message);
}
Also used : SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 44 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.

the class SenderKeySharedDatabase method getSharedWith.

/**
 * Get the set of recipientIds that know about the distributionId in question.
 */
@NonNull
public Set<SignalProtocolAddress> getSharedWith(@NonNull DistributionId distributionId) {
    SQLiteDatabase db = databaseHelper.getSignalReadableDatabase();
    String query = DISTRIBUTION_ID + " = ?";
    String[] args = SqlUtil.buildArgs(distributionId);
    Set<SignalProtocolAddress> addresses = new HashSet<>();
    try (Cursor cursor = db.query(TABLE_NAME, new String[] { ADDRESS, DEVICE }, query, args, null, null, null)) {
        while (cursor.moveToNext()) {
            String address = CursorUtil.requireString(cursor, ADDRESS);
            int device = CursorUtil.requireInt(cursor, DEVICE);
            addresses.add(new SignalProtocolAddress(address, device));
        }
    }
    return addresses;
}
Also used : Cursor(android.database.Cursor) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) HashSet(java.util.HashSet) NonNull(androidx.annotation.NonNull)

Example 45 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.

the class SenderKeySharedDatabase method delete.

/**
 * Clear the shared statuses for all provided addresses.
 */
public void delete(@NonNull DistributionId distributionId, @NonNull Collection<SignalProtocolAddress> addresses) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    String query = DISTRIBUTION_ID + " = ? AND " + ADDRESS + " = ? AND " + DEVICE + " = ?";
    db.beginTransaction();
    try {
        for (SignalProtocolAddress address : addresses) {
            db.delete(TABLE_NAME, query, SqlUtil.buildArgs(distributionId, address.getName(), address.getDeviceId()));
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}
Also used : SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Aggregations

SignalProtocolAddress (org.whispersystems.libsignal.SignalProtocolAddress)77 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)14 PreKeyBundle (org.whispersystems.libsignal.state.PreKeyBundle)11 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)11 ArrayList (java.util.ArrayList)10 Recipient (org.thoughtcrime.securesms.recipients.Recipient)10 IOException (java.io.IOException)9 SessionBuilder (org.whispersystems.libsignal.SessionBuilder)9 Optional (org.whispersystems.libsignal.util.guava.Optional)9 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 List (java.util.List)8 ContentHint (org.whispersystems.signalservice.api.crypto.ContentHint)8 DistributionId (org.whispersystems.signalservice.api.push.DistributionId)8 NonNull (androidx.annotation.NonNull)6 LinkedList (java.util.LinkedList)6 Collectors (java.util.stream.Collectors)6 SenderKeyDistributionMessage (org.whispersystems.libsignal.protocol.SenderKeyDistributionMessage)6 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)6