private May <uint> processV2(SessionRecord sessionRecord, PreKeyWhisperMessage message) { if (!message.getPreKeyId().HasValue) { throw new InvalidKeyIdException("V2 message requires one time prekey id!"); } if (!preKeyStore.ContainsPreKey(message.getPreKeyId().ForceGetValue()) && sessionStore.ContainsSession(remoteAddress)) { //Log.w(TAG, "We've already processed the prekey part of this V2 session, letting bundled message fall through..."); return(May <uint> .NoValue); //May.absent(); } ECKeyPair ourPreKey = preKeyStore.LoadPreKey(message.getPreKeyId().ForceGetValue()).getKeyPair(); BobAxolotlParameters.Builder parameters = BobAxolotlParameters.newBuilder(); parameters.setOurIdentityKey(identityKeyStore.GetIdentityKeyPair()) .setOurSignedPreKey(ourPreKey) .setOurRatchetKey(ourPreKey) .setOurOneTimePreKey(May <ECKeyPair> .NoValue) //absent .setTheirIdentityKey(message.getIdentityKey()) .setTheirBaseKey(message.getBaseKey()); if (!sessionRecord.isFresh()) { sessionRecord.archiveCurrentState(); } RatchetingSession.initializeSession(sessionRecord.getSessionState(), message.getMessageVersion(), parameters.create()); sessionRecord.getSessionState().setLocalRegistrationId(identityKeyStore.GetLocalRegistrationId()); sessionRecord.getSessionState().setRemoteRegistrationId(message.getRegistrationId()); sessionRecord.getSessionState().setAliceBaseKey(message.getBaseKey().serialize()); if (message.getPreKeyId().ForceGetValue() != Medium.MAX_VALUE) { return(message.getPreKeyId()); } else { return(May <uint> .NoValue); // May.absent(); } }
private May <uint> ProcessV2(SessionRecord sessionRecord, PreKeyWhisperMessage message) { if (!message.GetPreKeyId().HasValue) { throw new InvalidKeyIdException("V2 message requires one time prekey id!"); } if (!preKeyStore.ContainsPreKey(message.GetPreKeyId().ForceGetValue()) && sessionStore.ContainsSession(remoteAddress)) { return(May <uint> .NoValue); } ECKeyPair ourPreKey = preKeyStore.LoadPreKey(message.GetPreKeyId().ForceGetValue()).GetKeyPair(); BobAxolotlParameters.Builder parameters = BobAxolotlParameters.NewBuilder(); parameters.SetOurIdentityKey(identityKeyStore.GetIdentityKeyPair()) .SetOurSignedPreKey(ourPreKey) .SetOurRatchetKey(ourPreKey) .SetOurOneTimePreKey(May <ECKeyPair> .NoValue) //absent .SetTheirIdentityKey(message.GetIdentityKey()) .SetTheirBaseKey(message.GetBaseKey()); if (!sessionRecord.IsFresh()) { sessionRecord.ArchiveCurrentState(); } RatchetingSession.InitializeSession(sessionRecord.GetSessionState(), message.GetMessageVersion(), parameters.Create()); sessionRecord.GetSessionState().SetLocalRegistrationId(identityKeyStore.GetLocalRegistrationId()); sessionRecord.GetSessionState().SetRemoteRegistrationId(message.GetRegistrationId()); sessionRecord.GetSessionState().SetAliceBaseKey(message.GetBaseKey().Serialize()); if (message.GetPreKeyId().ForceGetValue() != Medium.MAX_VALUE) { return(message.GetPreKeyId()); } else { return(May <uint> .NoValue); // May.absent(); } }
public bool ContainsPreKey(uint preKeyId) { return(preKeyStore.ContainsPreKey(preKeyId)); }