private byte[] decrypt(SignalServiceEnvelope envelope, byte[] ciphertext) { SignalProtocolAddress sourceAddress = new SignalProtocolAddress(envelope.getSource(), (uint)envelope.getSourceDevice()); SessionCipher sessionCipher = new SessionCipher(signalProtocolStore, sourceAddress); byte[] paddedMessage; if (envelope.isPreKeySignalMessage()) { paddedMessage = sessionCipher.decrypt(new PreKeySignalMessage(ciphertext)); } else if (envelope.isSignalMessage()) { paddedMessage = sessionCipher.decrypt(new SignalMessage(ciphertext)); } else { throw new InvalidMessageException("Unknown type: " + envelope.getType() + " from " + envelope.getSource()); } PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion()); return(transportDetails.getStrippedPaddingMessageBody(paddedMessage)); }
public void handle(SignalServiceEnvelope envelope, bool sendExplicitReceipt) { if (!isActiveNumber(envelope.getSource())) { TextSecureDirectory directory = DatabaseFactory.getDirectoryDatabase(); ContactTokenDetails contactTokenDetails = new ContactTokenDetails(); contactTokenDetails.setNumber(envelope.getSource()); directory.setNumber(contactTokenDetails, true); // TODO: evtl DirectoryRefresh } if (envelope.isReceipt()) { handleReceipt(envelope); } else if (envelope.isPreKeySignalMessage() || envelope.isSignalMessage()) { handleMessage(envelope, sendExplicitReceipt); } else { Log.Warn($"Received envelope of unknown type: {envelope.GetType()}"); } }
public void OnMessage(SignalServiceMessagePipeMessage message) { if (message is SignalServiceEnvelope) { SignalServiceEnvelope envelope = (SignalServiceEnvelope)message; List <SignalMessage> messages = new List <SignalMessage>(); if (envelope.isReceipt()) { SignalDBContext.IncreaseReceiptCountLocked(envelope, this); } else if (envelope.isPreKeySignalMessage() || envelope.isSignalMessage()) { HandleMessage(envelope); } else { Debug.WriteLine("received message of unknown type " + envelope.getType() + " from " + envelope.getSource()); } } }
private void handleMessage(SignalServiceEnvelope envelope, May <long> smsMessageId) { try { SignalProtocolStore axolotlStore = new TextSecureAxolotlStore(); SignalServiceAddress localAddress = new SignalServiceAddress(TextSecurePreferences.getLocalNumber()); SignalServiceCipher cipher = new SignalServiceCipher(localAddress, axolotlStore); SignalServiceContent content = cipher.decrypt(envelope); if (content.getDataMessage().HasValue) { SignalServiceDataMessage message = content.getDataMessage().ForceGetValue(); if (message.isEndSession()) { handleEndSessionMessage(envelope, message, smsMessageId); } else if (message.isGroupUpdate()) { handleGroupMessage(envelope, message, smsMessageId); } else if (message.getAttachments().HasValue) { handleMediaMessage(envelope, message, smsMessageId); } else { handleTextMessage(envelope, message, smsMessageId); } } /*else if (content.getSyncMessage().HasValue) TODO: SYNC enable * { * TextSecureSyncMessage syncMessage = content.getSyncMessage().ForceGetValue(); * * if (syncMessage.getSent().HasValue) handleSynchronizeSentMessage(masterSecret, syncMessage.getSent().ForceGetValue(), smsMessageId); * else if (syncMessage.getRequest().HasValue) handleSynchronizeRequestMessage(masterSecret, syncMessage.getRequest().ForceGetValue()); * }*/ if (envelope.isPreKeySignalMessage()) { App.Current.Worker.AddTaskActivities(new RefreshPreKeysTask()); //ApplicationContext.getInstance(context).getJobManager().add(new RefreshPreKeysJob(context)); } } catch (InvalidVersionException e) { Log.Warn(e); handleInvalidVersionMessage(envelope, smsMessageId); } catch (InvalidMessageException e) { Log.Warn(e); handleCorruptMessage(envelope, smsMessageId); } catch (InvalidKeyIdException e) { Log.Warn(e); handleCorruptMessage(envelope, smsMessageId); } catch (InvalidKeyException e) { Log.Warn(e); handleCorruptMessage(envelope, smsMessageId); } catch (NoSessionException e) { Log.Warn(e); handleNoSessionMessage(envelope, smsMessageId); } catch (LegacyMessageException e) { Log.Warn(e); handleLegacyMessage(envelope, smsMessageId); } catch (DuplicateMessageException e) { Log.Warn(e); handleDuplicateMessage(envelope, smsMessageId); } catch (libsignal.exceptions.UntrustedIdentityException e) { Log.Warn(e); handleUntrustedIdentityMessage(envelope, smsMessageId); } catch (Exception e) { Log.Warn($"Unexpected Exception"); } }