public SignalServiceEnvelope(int type, SignalServiceAddress sender, int senderDevice, long timestamp, byte[] legacyMessage, byte[] content, long serverTimestamp, string?uuid) { Envelope envelope = new Envelope { Type = (Envelope.Types.Type)type, SourceDevice = (uint)senderDevice, Timestamp = (ulong)timestamp, ServerTimestamp = (ulong)serverTimestamp }; if (sender.Uuid.HasValue) { envelope.SourceUuid = sender.Uuid.Value.ToString(); } if (sender.GetNumber() != null) { envelope.SourceE164 = sender.GetNumber(); } if (uuid != null) { envelope.ServerGuid = uuid; } if (legacyMessage != null) { envelope.LegacyMessage = ByteString.CopyFrom(legacyMessage); } if (content != null) { envelope.Content = ByteString.CopyFrom(content); } Envelope = envelope; }
private static SignalProtocolAddress GetPreferredProtocolAddress(SignalProtocolStore store, SignalServiceAddress address, int sourceDevice) { SignalProtocolAddress?uuidAddress = address.Uuid.HasValue ? new SignalProtocolAddress(address.Uuid.Value.ToString(), (uint)sourceDevice) : null; SignalProtocolAddress?e164Address = address.GetNumber() != null ? new SignalProtocolAddress(address.GetNumber(), (uint)sourceDevice) : null; if (uuidAddress != null && store.ContainsSession(uuidAddress)) { return(uuidAddress); } else if (e164Address != null && store.ContainsSession(e164Address)) { return(e164Address); } else { return(new SignalProtocolAddress(address.GetIdentifier(), (uint)sourceDevice)); } }
public static AddressProto ToProtobuf(SignalServiceAddress signalServiceAddress) { AddressProto builder = new AddressProto(); if (signalServiceAddress.GetNumber() != null) { builder.E164 = signalServiceAddress.E164; } if (signalServiceAddress.Uuid.HasValue) { builder.Uuid = ByteString.CopyFrom(UuidUtil.ToByteArray(signalServiceAddress.Uuid.Value)); } if (signalServiceAddress.Relay != null) { builder.Relay = signalServiceAddress.Relay; } return(builder); }
public OutgoingPushMessage Encrypt(SignalProtocolAddress destination, UnidentifiedAccess?unidentifiedAccess, byte[] unpaddedMessage) { if (unidentifiedAccess != null) { SealedSessionCipher sessionCipher = new SealedSessionCipher(signalProtocolStore, localAddress.Uuid, localAddress.GetNumber(), 1); PushTransportDetails transportDetails = new PushTransportDetails((uint)sessionCipher.GetSessionVersion(destination)); byte[] ciphertext = sessionCipher.Encrypt(destination, unidentifiedAccess.UnidentifiedCertificate, transportDetails.getPaddedMessageBody(unpaddedMessage)); string body = Base64.EncodeBytes(ciphertext); uint remoteRegistrationId = (uint)sessionCipher.GetRemoteRegistrationId(destination); return(new OutgoingPushMessage((uint)Envelope.Types.Type.UnidentifiedSender, destination.DeviceId, remoteRegistrationId, body)); } else { SessionCipher sessionCipher = new SessionCipher(signalProtocolStore, destination); PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion()); CiphertextMessage message = sessionCipher.encrypt(transportDetails.getPaddedMessageBody(unpaddedMessage)); uint remoteRegistrationId = sessionCipher.getRemoteRegistrationId(); string body = Base64.EncodeBytes(message.serialize()); var type = (message.getType()) switch { CiphertextMessage.PREKEY_TYPE => (uint)Envelope.Types.Type.PrekeyBundle, CiphertextMessage.WHISPER_TYPE => (uint)Envelope.Types.Type.Ciphertext, _ => throw new Exception("Bad type: " + message.getType()), }; return(new OutgoingPushMessage(type, destination.DeviceId, remoteRegistrationId, body)); } }