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 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()); } } }
public long Insert(SignalServiceEnvelope 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); }