I'm using libsignal-protocol-java according to Signal's Documentation to implement end-to-end encryption in a messaging app.
Let's say Alice sends Bob a (pairwise) serialized ciphertext message. How does Bob know how to deserialize it? Doesn't he first need to know the type of the ciphertext message? My understanding is that a pairwise ciphertext message could either be a signal message (WHISPER_TYPE) or a pre key signal message (PREKEY_TYPE). So how does Bob know which type it is?
Is Alice supposed to also send Bob the type (as plaintext) of the ciphertext message?
Or is there another way that Bob could detect the type? For example, is Bob supposed to try to deserialize it as if it's a signal message, and if that fails, then try to deserialize it as if it's a pre key signal message?
After reviewing the source code of Signal Android, I think Alice is supposed to also send Bob the type (as plaintext) of the ciphertext message.
In the class
SignalServiceCipher:The instance method
encrypt(SignalProtocolAddress, Optional<UnidentifiedAccess>, byte[])returns an instance ofOutgoingPushMessagewith itstypeproperty set to that of the ciphertext message and itsbodyproperty set to the Base64 encoded serialized ciphertext message.The instance method
decrypt(SignalServiceEnvelope, byte[])gets the type of the ciphertext message from its first argument, which is an instance of SignalServiceEnvelope.