Пример #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);
            }
        }
        private May <uint> processV3(SessionRecord sessionRecord, PreKeySignalMessage message)
        {
            if (sessionRecord.hasSessionState(message.getMessageVersion(), message.getBaseKey().serialize()))
            {
                Debug.WriteLine("We've already setup a session for this V3 message, letting bundled message fall through...");
                return(May <uint> .NoValue);
            }

            ECKeyPair ourSignedPreKey = signedPreKeyStore.LoadSignedPreKey(message.getSignedPreKeyId()).getKeyPair();

            BobSignalProtocolParameters.Builder parameters = BobSignalProtocolParameters.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(), 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);
            }
        }
Пример #3
0
 public SignedPreKeyRecord LoadSignedPreKey(uint signedPreKeyId)
 {
     return(signedPreKeyStore.LoadSignedPreKey(signedPreKeyId));
 }