/*private void handleGroupMessage(@NonNull MasterSecretUnion masterSecret, * @NonNull TextSecureEnvelope envelope, * @NonNull TextSecureDataMessage message, * @NonNull Optional<Long> smsMessageId) * { * GroupMessageProcessor.process(context, masterSecret, envelope, message); * * if (smsMessageId.isPresent()) * { * DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get()); * } * } * * private void handleSynchronizeSentMessage(@NonNull MasterSecretUnion masterSecret, * @NonNull SentTranscriptMessage message, * @NonNull Optional<Long> smsMessageId) * throws MmsException * { * if (message.getMessage().getAttachments().isPresent()) { * handleSynchronizeSentMediaMessage(masterSecret, message, smsMessageId); * } else { * handleSynchronizeSentTextMessage(masterSecret, message, smsMessageId); * } * } * * private void handleSynchronizeRequestMessage(@NonNull MasterSecretUnion masterSecret, * @NonNull RequestMessage message) * { * if (message.isContactsRequest()) * { * ApplicationContext.getInstance(context) * .getJobManager() * .add(new MultiDeviceContactUpdateJob(getContext())); * } * * if (message.isGroupsRequest()) * { * ApplicationContext.getInstance(context) * .getJobManager() * .add(new MultiDeviceGroupUpdateJob(getContext())); * } * } * * private void handleMediaMessage(@NonNull MasterSecretUnion masterSecret, * @NonNull TextSecureEnvelope envelope, * @NonNull TextSecureDataMessage message, * @NonNull Optional<Long> smsMessageId) * throws MmsException * { * MmsDatabase database = DatabaseFactory.getMmsDatabase(context); * String localNumber = TextSecurePreferences.getLocalNumber(context); * IncomingMediaMessage mediaMessage = new IncomingMediaMessage(masterSecret, envelope.getSource(), * localNumber, message.getTimestamp(), * Optional.fromNullable(envelope.getRelay()), * message.getBody(), * message.getGroupInfo(), * message.getAttachments()); * * Pair<Long, Long> messageAndThreadId = database.insertSecureDecryptedMessageInbox(masterSecret, mediaMessage, -1); * * ApplicationContext.getInstance(context) * .getJobManager() * .add(new AttachmentDownloadJob(context, messageAndThreadId.first)); * * if (smsMessageId.isPresent()) { * DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get()); * } * * MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), messageAndThreadId.second); * } * * private void handleSynchronizeSentMediaMessage(@NonNull MasterSecretUnion masterSecret, * @NonNull SentTranscriptMessage message, * @NonNull Optional<Long> smsMessageId) * throws MmsException * { * MmsDatabase database = DatabaseFactory.getMmsDatabase(context); * Recipients recipients = getSyncMessageDestination(message); * OutgoingMediaMessage mediaMessage = new OutgoingMediaMessage(context, masterSecret, recipients, * message.getMessage().getAttachments().get(), * message.getMessage().getBody().orNull()); * * mediaMessage = new OutgoingSecureMediaMessage(mediaMessage); * * long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients); * long messageId = database.insertMessageOutbox(masterSecret, mediaMessage, threadId, false, message.getTimestamp()); * * database.markAsSent(messageId, "push".getBytes(), 0); * database.markAsPush(messageId); * * ApplicationContext.getInstance(context) * .getJobManager() * .add(new AttachmentDownloadJob(context, messageId)); * * if (smsMessageId.isPresent()) * { * DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get()); * } * } */ private void handleTextMessage(/*@NonNull MasterSecretUnion masterSecret,*/ TextSecureEnvelope envelope, TextSecureDataMessage message /*, * @NonNull Optional<Long> smsMessageId*/) { MessageDatabase database = DatabaseFactory.getMessageDatabase(); String body = message.getBody().HasValue ? message.getBody().ForceGetValue() : ""; /*Pair<Long, Long> messageAndThreadId; * * if (smsMessageId.hasValue) * { * messageAndThreadId = database.updateBundleMessageBody(masterSecret, smsMessageId.get(), body); * } * else * {*/ IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), (long)message.getTimestamp(), body, message.getGroupInfo()); textMessage = new IncomingEncryptedMessage(textMessage, body); /*messageAndThreadId = */ database.insertMessageInbox(/*masterSecret, */ textMessage); /*} * * MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), messageAndThreadId.second);*/ }
private byte[] decrypt(TextSecureEnvelope envelope, byte[] ciphertext) { AxolotlAddress sourceAddress = new AxolotlAddress(envelope.getSource(), envelope.getSourceDevice()); SessionCipher sessionCipher = new SessionCipher(axolotlStore, sourceAddress); byte[] paddedMessage; if (envelope.isPreKeyWhisperMessage()) { paddedMessage = sessionCipher.decrypt(new PreKeyWhisperMessage(ciphertext)); } else if (envelope.isWhisperMessage()) { paddedMessage = sessionCipher.decrypt(new WhisperMessage(ciphertext)); } else { throw new InvalidMessageException("Unknown type: " + envelope.getType()); } PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion()); return(transportDetails.getStrippedPaddingMessageBody(paddedMessage)); }
public long Insert(TextSecureEnvelope envelope) { // TODO check if exists var push = new Push() { Type = envelope.getType(), Source = envelope.getSource(), DeviceId = envelope.getSourceDevice(), LegacyMessage = envelope.hasLegacyMessage() ? Base64.encodeBytes(envelope.getLegacyMessage()) : "", Content = envelope.hasContent() ? Base64.encodeBytes(envelope.getContent()) : "", Timestamp = TimeUtil.GetDateTime(envelope.getTimestamp()) }; try { conn.Insert(push); } catch (Exception e) { Debug.WriteLine(e.Message); } return(push.PushId); }