signalapp / libsignal-protocol-java

GNU General Public License v3.0
1.83k stars 432 forks source link

DH Ratchet never skips keys while documentation does #54

Closed OughtToPrevail closed 5 years ago

OughtToPrevail commented 5 years ago

I was reading about the Double Ratchet Algorithm and in

def RatchetDecrypt(state, header, ciphertext, AD): 

there is the specified line

    if header.dh != state.DHr:                 
        SkipMessageKeys(state, header.pn)

which doesn't exist in the Java Implementation in the Java implementation message keys are skipped only in getOrCreateMessageKeys where they are skipped only for the current ratchet key this is specified in the documentation at

    SkipMessageKeys(state, header.n)      

In getOrCreateChainKey message keys aren't skipped while they should be, which if I am correct will result in message keys not being saved after a DH ratchet step causing a DuplicateMessageException if a message was received from before the DH ratchet step.

Thanks, OughtToPrevail

Edited from: Signal users community forum where I first asked it as a question when now I understand this is actually an issue.