Java Code Examples for org.whispersystems.signalservice.api.push.SignalServiceAddress#DEFAULT_DEVICE_ID

The following examples show how to use org.whispersystems.signalservice.api.push.SignalServiceAddress#DEFAULT_DEVICE_ID . 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: SessionDatabase.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public @NonNull List<Integer> getSubDevices(@NonNull RecipientId recipientId) {
  SQLiteDatabase database = databaseHelper.getReadableDatabase();
  List<Integer>  results  = new LinkedList<>();

  try (Cursor cursor = database.query(TABLE_NAME, new String[] {DEVICE},
                                      RECIPIENT_ID + " = ?",
                                      new String[] {recipientId.serialize()},
                                      null, null, null))
  {
    while (cursor != null && cursor.moveToNext()) {
      int device = cursor.getInt(cursor.getColumnIndexOrThrow(DEVICE));

      if (device != SignalServiceAddress.DEFAULT_DEVICE_ID) {
        results.add(device);
      }
    }
  }

  return results;
}
 
Example 2
Source File: IncomingTextMessage.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public IncomingTextMessage(@NonNull RecipientId sender, @NonNull SmsMessage message, int subscriptionId) {
  this.message               = message.getDisplayMessageBody();
  this.sender                = sender;
  this.senderDeviceId        = SignalServiceAddress.DEFAULT_DEVICE_ID;
  this.protocol              = message.getProtocolIdentifier();
  this.serviceCenterAddress  = message.getServiceCenterAddress();
  this.replyPathPresent      = message.isReplyPathPresent();
  this.pseudoSubject         = message.getPseudoSubject();
  this.sentTimestampMillis   = message.getTimestampMillis();
  this.serverTimestampMillis = -1;
  this.subscriptionId        = subscriptionId;
  this.expiresInMillis       = 0;
  this.groupId               = null;
  this.push                  = false;
  this.unidentified          = false;
}
 
Example 3
Source File: IncomingTextMessage.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
protected IncomingTextMessage(@NonNull RecipientId sender, @Nullable GroupId groupId)
{
  this.message               = "";
  this.sender                = sender;
  this.senderDeviceId        = SignalServiceAddress.DEFAULT_DEVICE_ID;
  this.protocol              = 31338;
  this.serviceCenterAddress  = "Outgoing";
  this.replyPathPresent      = true;
  this.pseudoSubject         = "";
  this.sentTimestampMillis   = System.currentTimeMillis();
  this.serverTimestampMillis = sentTimestampMillis;
  this.groupId               = groupId;
  this.push                  = true;
  this.subscriptionId        = -1;
  this.expiresInMillis       = 0;
  this.unidentified          = false;
}
 
Example 4
Source File: IncomingTextMessage.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public IncomingTextMessage(@NonNull AccountContext accountContext,
                           @NonNull SmsMessage message,
                           int subscriptionId) {
    this.message = message.getDisplayMessageBody();
    this.payloadType = parseBodyPayloadType(this.message);
    this.sender = Address.from(accountContext, message.getDisplayOriginatingAddress());
    this.senderDeviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
    this.protocol = message.getProtocolIdentifier();
    this.serviceCenterAddress = message.getServiceCenterAddress();
    this.replyPathPresent = message.isReplyPathPresent();
    this.pseudoSubject = message.getPseudoSubject();
    this.sentTimestampMillis = message.getTimestampMillis();
    this.subscriptionId = subscriptionId;
    this.expiresInMillis = 0;
    this.groupId = null;
    this.push = false;
}
 
Example 5
Source File: TextSecureSessionStore.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private @Nullable
SignalProtocolAddress getAddressName(File sessionFile) {
    try {
        String[] parts = sessionFile.getName().split("[.]");

        int deviceId;

        if (parts.length > 1) deviceId = Integer.parseInt(parts[1]);
        else deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;

        return new SignalProtocolAddress(parts[0], deviceId);
    } catch (NumberFormatException e) {
        Log.w(TAG, e);
        return null;
    }
}
 
Example 6
Source File: IncomingTextMessage.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
protected IncomingTextMessage(@NonNull Address sender, @Nullable Address groupId) {
    this.message = "";
    this.sender = sender;
    this.senderDeviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
    this.protocol = 31338;
    this.serviceCenterAddress = "Outgoing";
    this.replyPathPresent = true;
    this.pseudoSubject = "";
    this.sentTimestampMillis = System.currentTimeMillis();
    this.groupId = groupId;
    this.push = true;
    this.subscriptionId = -1;
    this.expiresInMillis = 0;
}
 
Example 7
Source File: ProvisioningManager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
public ProvisioningManager(String settingsPath, SignalServiceConfiguration serviceConfiguration, String userAgent) {
    this.pathConfig = PathConfig.createDefault(settingsPath);
    this.serviceConfiguration = serviceConfiguration;
    this.userAgent = userAgent;

    identityKey = KeyHelper.generateIdentityKeyPair();
    registrationId = KeyHelper.generateRegistrationId(false);
    password = KeyUtils.createPassword();
    final SleepTimer timer = new UptimeSleepTimer();
    accountManager = new SignalServiceAccountManager(serviceConfiguration, null, null, password, SignalServiceAddress.DEFAULT_DEVICE_ID, userAgent, timer);
}
 
Example 8
Source File: SessionUtil.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public static boolean hasSession(@NonNull Context context, @NonNull RecipientId id) {
  SessionStore          sessionStore   = new TextSecureSessionStore(context);
  SignalProtocolAddress axolotlAddress = new SignalProtocolAddress(Recipient.resolved(id).requireServiceId(), SignalServiceAddress.DEFAULT_DEVICE_ID);

  return sessionStore.containsSession(axolotlAddress);
}
 
Example 9
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
private void handleCorruptMessage(@NonNull MasterSecretUnion masterSecret,
                                  @NonNull SignalServiceProtos.Envelope envelope) {
    ALog.i(TAG, "handleCorruptMessage");

    ThreadRepo threadRepo = repository.getThreadRepo();
    String dataJson = threadRepo.getDecryptFailData(envelope.getSource());
    DecryptFailData data;
    if (dataJson != null && !dataJson.isEmpty()) {
        data = GsonUtils.INSTANCE.fromJson(dataJson, DecryptFailData.class);
    } else {
        data = new DecryptFailData();
    }
    if (data.getLastDeleteSessionTime() + 50000 < System.currentTimeMillis()) {
        ALog.i(TAG, "Last delete session time is 5s ago. Delete Session.");
        SignalProtocolStore store = new SignalProtocolStoreImpl(context, accountContext);
        SignalProtocolAddress address = new SignalProtocolAddress(envelope.getSource(), SignalServiceAddress.DEFAULT_DEVICE_ID);
        if (store.containsSession(address)) {
            store.deleteSession(address);
        }
        try {
            Optional<String> relay = Optional.absent();
            if (envelope.hasRelay()) {
                relay = Optional.of(envelope.getRelay());
            }
            List<PreKeyBundle> preKeyBundles = ChatHttp.INSTANCE.get(accountContext).getPreKeys(new SignalServiceAddress(envelope.getSource(), relay), SignalServiceAddress.DEFAULT_DEVICE_ID);
            for (PreKeyBundle preKey : preKeyBundles) {

                String identityKeyString = new String(EncryptUtils.base64Encode(preKey.getIdentityKey().serialize()));
                if (!AddressUtil.INSTANCE.isValid(envelope.getSource(), identityKeyString)) {
                    ALog.e(TAG, "getPreKeys error identity key got");
                    continue;
                }

                SessionBuilder sessionBuilder = new SessionBuilder(store, new SignalProtocolAddress(envelope.getSource(), SignalServiceAddress.DEFAULT_DEVICE_ID));
                sessionBuilder.process(preKey);

            }
        } catch (Throwable ex) {
            ALog.w(TAG, "Untrusted identity key from handleMismatchedDevices");
        }
        data.setLastDeleteSessionTime(System.currentTimeMillis());
        threadRepo.setDecryptFailData(envelope.getSource(), data.toJson());
    }

    //If the decryption fails, do not insert the library, and send a new receipt directly
    long messageId = envelope.getTimestamp();
    Recipient recipient = Recipient.from(accountContext, envelope.getSource(), false);
    String message = new AmeGroupMessage<>(AmeGroupMessage.RECEIPT, new AmeGroupMessage.ReceiptContent(messageId)).toString();
    OutgoingLocationMessage outgoingLocationMessage = new OutgoingLocationMessage(recipient, message, 0);
    if (masterSecret.getMasterSecret().isPresent()) {
        long threadId = threadRepo.getThreadIdIfExist(recipient);
        MessageSender.sendHideMessage(AppContextHolder.APP_CONTEXT, threadId, accountContext, AmeGroupMessage.RECEIPT, outgoingLocationMessage);
    }
}
 
Example 10
Source File: SessionUtil.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
public static boolean hasSession(Context context, MasterSecret masterSecret, @NonNull Address address) {
    SessionStore sessionStore = new TextSecureSessionStore(context, address.context(), masterSecret);
    SignalProtocolAddress axolotlAddress = new SignalProtocolAddress(address.serialize(), SignalServiceAddress.DEFAULT_DEVICE_ID);

    return sessionStore.containsSession(axolotlAddress);
}
 
Example 11
Source File: TextSecureSessionStore.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
private String getSessionName(SignalProtocolAddress address) {
    int deviceId = address.getDeviceId();
    return address.getName() + (deviceId == SignalServiceAddress.DEFAULT_DEVICE_ID ? "" : "." + deviceId);
}