Java Code Examples for org.whispersystems.signalservice.api.push.SignalServiceAddress#getIdentifier()

The following examples show how to use org.whispersystems.signalservice.api.push.SignalServiceAddress#getIdentifier() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private OutgoingPushMessageList getEncryptedMessages(PushServiceSocket            socket,
                                                     SignalServiceAddress         recipient,
                                                     Optional<UnidentifiedAccess> unidentifiedAccess,
                                                     long                         timestamp,
                                                     byte[]                       plaintext,
                                                     boolean                      online)
    throws IOException, InvalidKeyException, UntrustedIdentityException
{
  List<OutgoingPushMessage> messages = new LinkedList<>();

  if (!recipient.matches(localAddress) || unidentifiedAccess.isPresent()) {
    messages.add(getEncryptedMessage(socket, recipient, unidentifiedAccess, SignalServiceAddress.DEFAULT_DEVICE_ID, plaintext));
  }

  for (int deviceId : store.getSubDeviceSessions(recipient.getIdentifier())) {
    if (store.containsSession(new SignalProtocolAddress(recipient.getIdentifier(), deviceId))) {
      messages.add(getEncryptedMessage(socket, recipient, unidentifiedAccess, deviceId, plaintext));
    }
  }

  return new OutgoingPushMessageList(recipient.getIdentifier(), timestamp, messages, online);
}
 
Example 2
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
private OutgoingPushMessageList getEncryptedMessages(PushServiceSocket            socket,
                                                     SignalServiceAddress         recipient,
                                                     Optional<UnidentifiedAccess> unidentifiedAccess,
                                                     long                         timestamp,
                                                     byte[]                       plaintext,
                                                     boolean                      online)
    throws IOException, InvalidKeyException, UntrustedIdentityException
{
  List<OutgoingPushMessage> messages = new LinkedList<>();

  if (!recipient.matches(localAddress) || unidentifiedAccess.isPresent()) {
    messages.add(getEncryptedMessage(socket, recipient, unidentifiedAccess, SignalServiceAddress.DEFAULT_DEVICE_ID, plaintext));
  }

  for (int deviceId : store.getSubDeviceSessions(recipient.getIdentifier())) {
    if (store.containsSession(new SignalProtocolAddress(recipient.getIdentifier(), deviceId))) {
      messages.add(getEncryptedMessage(socket, recipient, unidentifiedAccess, deviceId, plaintext));
    }
  }

  return new OutgoingPushMessageList(recipient.getIdentifier(), timestamp, messages, online);
}
 
Example 3
Source File: PushServiceSocket.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public PreKeyBundle getPreKey(SignalServiceAddress destination, int deviceId) throws IOException {
  try {
    String path = String.format(PREKEY_DEVICE_PATH, destination.getIdentifier(), String.valueOf(deviceId));

    if (destination.getRelay().isPresent()) {
      path = path + "?relay=" + destination.getRelay().get();
    }

    String         responseText = makeServiceRequest(path, "GET", null);
    PreKeyResponse response     = JsonUtil.fromJson(responseText, PreKeyResponse.class);

    if (response.getDevices() == null || response.getDevices().size() < 1)
      throw new IOException("Empty prekey list");

    PreKeyResponseItem device                = response.getDevices().get(0);
    ECPublicKey        preKey                = null;
    ECPublicKey        signedPreKey          = null;
    byte[]             signedPreKeySignature = null;
    int                preKeyId              = -1;
    int                signedPreKeyId        = -1;

    if (device.getPreKey() != null) {
      preKeyId = device.getPreKey().getKeyId();
      preKey   = device.getPreKey().getPublicKey();
    }

    if (device.getSignedPreKey() != null) {
      signedPreKeyId        = device.getSignedPreKey().getKeyId();
      signedPreKey          = device.getSignedPreKey().getPublicKey();
      signedPreKeySignature = device.getSignedPreKey().getSignature();
    }

    return new PreKeyBundle(device.getRegistrationId(), device.getDeviceId(), preKeyId, preKey,
                            signedPreKeyId, signedPreKey, signedPreKeySignature, response.getIdentityKey());
  } catch (NotFoundException nfe) {
    throw new UnregisteredUserException(destination.getIdentifier(), nfe);
  }
}
 
Example 4
Source File: SignalServiceCipher.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
private static SignalProtocolAddress getPreferredProtocolAddress(SignalProtocolStore store, SignalServiceAddress address, int sourceDevice) {
  SignalProtocolAddress uuidAddress = address.getUuid().isPresent() ? new SignalProtocolAddress(address.getUuid().get().toString(), sourceDevice) : null;
  SignalProtocolAddress e164Address = address.getNumber().isPresent() ? new SignalProtocolAddress(address.getNumber().get(), sourceDevice) : null;

  if (uuidAddress != null && store.containsSession(uuidAddress)) {
    return uuidAddress;
  } else if (e164Address != null && store.containsSession(e164Address)) {
    return e164Address;
  } else {
    return new SignalProtocolAddress(address.getIdentifier(), sourceDevice);
  }
}
 
Example 5
Source File: PushServiceSocket.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public PreKeyBundle getPreKey(SignalServiceAddress destination, int deviceId) throws IOException {
  try {
    String path = String.format(PREKEY_DEVICE_PATH, destination.getIdentifier(),
                                String.valueOf(deviceId));

    if (destination.getRelay().isPresent()) {
      path = path + "?relay=" + destination.getRelay().get();
    }

    String         responseText = makeServiceRequest(path, "GET", null);
    PreKeyResponse response     = JsonUtil.fromJson(responseText, PreKeyResponse.class);

    if (response.getDevices() == null || response.getDevices().size() < 1)
      throw new IOException("Empty prekey list");

    PreKeyResponseItem device                = response.getDevices().get(0);
    ECPublicKey        preKey                = null;
    ECPublicKey        signedPreKey          = null;
    byte[]             signedPreKeySignature = null;
    int                preKeyId              = -1;
    int                signedPreKeyId        = -1;

    if (device.getPreKey() != null) {
      preKeyId = device.getPreKey().getKeyId();
      preKey   = device.getPreKey().getPublicKey();
    }

    if (device.getSignedPreKey() != null) {
      signedPreKeyId        = device.getSignedPreKey().getKeyId();
      signedPreKey          = device.getSignedPreKey().getPublicKey();
      signedPreKeySignature = device.getSignedPreKey().getSignature();
    }

    return new PreKeyBundle(device.getRegistrationId(), device.getDeviceId(), preKeyId, preKey,
                            signedPreKeyId, signedPreKey, signedPreKeySignature, response.getIdentityKey());
  } catch (NotFoundException nfe) {
    throw new UnregisteredUserException(destination.getIdentifier(), nfe);
  }
}
 
Example 6
Source File: PushServiceSocket.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public List<PreKeyBundle> getPreKeys(SignalServiceAddress destination,
                                     Optional<UnidentifiedAccess> unidentifiedAccess,
                                     int deviceIdInteger)
    throws IOException
{
  try {
    String deviceId = String.valueOf(deviceIdInteger);

    if (deviceId.equals("1"))
      deviceId = "*";

    String path = String.format(PREKEY_DEVICE_PATH, destination.getIdentifier(), deviceId);

    if (destination.getRelay().isPresent()) {
      path = path + "?relay=" + destination.getRelay().get();
    }

    String             responseText = makeServiceRequest(path, "GET", null, NO_HEADERS, unidentifiedAccess);
    PreKeyResponse     response     = JsonUtil.fromJson(responseText, PreKeyResponse.class);
    List<PreKeyBundle> bundles      = new LinkedList<>();

    for (PreKeyResponseItem device : response.getDevices()) {
      ECPublicKey preKey                = null;
      ECPublicKey signedPreKey          = null;
      byte[]      signedPreKeySignature = null;
      int         preKeyId              = -1;
      int         signedPreKeyId        = -1;

      if (device.getSignedPreKey() != null) {
        signedPreKey          = device.getSignedPreKey().getPublicKey();
        signedPreKeyId        = device.getSignedPreKey().getKeyId();
        signedPreKeySignature = device.getSignedPreKey().getSignature();
      }

      if (device.getPreKey() != null) {
        preKeyId = device.getPreKey().getKeyId();
        preKey   = device.getPreKey().getPublicKey();
      }

      bundles.add(new PreKeyBundle(device.getRegistrationId(), device.getDeviceId(), preKeyId,
                                   preKey, signedPreKeyId, signedPreKey, signedPreKeySignature,
                                   response.getIdentityKey()));
    }

    return bundles;
  } catch (NotFoundException nfe) {
    throw new UnregisteredUserException(destination.getIdentifier(), nfe);
  }
}
 
Example 7
Source File: PushServiceSocket.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
public List<PreKeyBundle> getPreKeys(SignalServiceAddress destination,
                                     Optional<UnidentifiedAccess> unidentifiedAccess,
                                     int deviceIdInteger)
    throws IOException
{
  try {
    String deviceId = String.valueOf(deviceIdInteger);

    if (deviceId.equals("1"))
      deviceId = "*";

    String path = String.format(PREKEY_DEVICE_PATH, destination.getIdentifier(), deviceId);

    if (destination.getRelay().isPresent()) {
      path = path + "?relay=" + destination.getRelay().get();
    }

    String             responseText = makeServiceRequest(path, "GET", null, NO_HEADERS, unidentifiedAccess);
    PreKeyResponse     response     = JsonUtil.fromJson(responseText, PreKeyResponse.class);
    List<PreKeyBundle> bundles      = new LinkedList<>();

    for (PreKeyResponseItem device : response.getDevices()) {
      ECPublicKey preKey                = null;
      ECPublicKey signedPreKey          = null;
      byte[]      signedPreKeySignature = null;
      int         preKeyId              = -1;
      int         signedPreKeyId        = -1;

      if (device.getSignedPreKey() != null) {
        signedPreKey          = device.getSignedPreKey().getPublicKey();
        signedPreKeyId        = device.getSignedPreKey().getKeyId();
        signedPreKeySignature = device.getSignedPreKey().getSignature();
      }

      if (device.getPreKey() != null) {
        preKeyId = device.getPreKey().getKeyId();
        preKey   = device.getPreKey().getPublicKey();
      }

      bundles.add(new PreKeyBundle(device.getRegistrationId(), device.getDeviceId(), preKeyId,
                                   preKey, signedPreKeyId, signedPreKey, signedPreKeySignature,
                                   response.getIdentityKey()));
    }

    return bundles;
  } catch (NotFoundException nfe) {
    throw new UnregisteredUserException(destination.getIdentifier(), nfe);
  }
}