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));
        }
Esempio n. 2
0
        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()}");
            }
        }
Esempio n. 3
0
 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());
         }
     }
 }