Esempio n. 1
0
        private May <uint> ProcessV3(SessionRecord sessionRecord, PreKeyWhisperMessage message)
        {
            if (sessionRecord.HasSessionState(message.GetMessageVersion(), message.GetBaseKey().Serialize()))
            {
                return(May <uint> .NoValue);
            }

            SignedPreKeyRecord signedPreKeyRecord = signedPreKeyStore.LoadSignedPreKey(message.GetSignedPreKeyId());
            ECKeyPair          ourSignedPreKey    = signedPreKeyRecord.GetKeyPair();

            BobAxolotlParameters.Builder parameters = BobAxolotlParameters.NewBuilder();

            parameters.SetTheirBaseKey(message.GetBaseKey())
            .SetTheirIdentityKey(message.GetIdentityKey())
            .SetOurIdentityKey(identityKeyStore.GetIdentityKeyPair())
            .SetOurSignedPreKey(ourSignedPreKey)
            .SetOurRatchetKey(ourSignedPreKey);

            if (message.GetPreKeyId().HasValue)
            {
                parameters.SetOurOneTimePreKey(new May <ECKeyPair>(preKeyStore.LoadPreKey(message.GetPreKeyId().ForceGetValue()).GetKeyPair()));
            }
            else
            {
                parameters.SetOurOneTimePreKey(May <ECKeyPair> .NoValue);
            }

            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().HasValue&& message.GetPreKeyId().ForceGetValue() != Medium.MAX_VALUE)
            {
                return(message.GetPreKeyId());
            }
            else
            {
                return(May <uint> .NoValue);
            }
        }
Esempio n. 2
0
        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();
            }
        }