コード例 #1
0
        public static void initializeSession(SessionState sessionState,
                                             uint sessionVersion,
                                             AliceAxolotlParameters parameters)

        {
            try
            {
                sessionState.setSessionVersion(sessionVersion);
                sessionState.setRemoteIdentityKey(parameters.getTheirIdentityKey());
                sessionState.setLocalIdentityKey(parameters.getOurIdentityKey().getPublicKey());

                ECKeyPair    sendingRatchetKey = Curve.generateKeyPair();
                MemoryStream secrets           = new MemoryStream();

                if (sessionVersion >= 3)
                {
                    byte[] discontinuityBytes = getDiscontinuityBytes();
                    secrets.Write(discontinuityBytes, 0, discontinuityBytes.Length);
                }

                byte[] agree1 = Curve.calculateAgreement(parameters.getTheirSignedPreKey(),
                                                         parameters.getOurIdentityKey().getPrivateKey());
                byte[] agree2 = Curve.calculateAgreement(parameters.getTheirIdentityKey().getPublicKey(),
                                                         parameters.getOurBaseKey().getPrivateKey());
                byte[] agree3 = Curve.calculateAgreement(parameters.getTheirSignedPreKey(),
                                                         parameters.getOurBaseKey().getPrivateKey());

                secrets.Write(agree1, 0, agree1.Length);
                secrets.Write(agree2, 0, agree2.Length);
                secrets.Write(agree3, 0, agree3.Length);


                if (sessionVersion >= 3 && parameters.getTheirOneTimePreKey().HasValue)
                {
                    byte[] agree4 = Curve.calculateAgreement(parameters.getTheirOneTimePreKey().ForceGetValue(),
                                                             parameters.getOurBaseKey().getPrivateKey());
                    secrets.Write(agree4, 0, agree4.Length);
                }

                DerivedKeys derivedKeys = calculateDerivedKeys(sessionVersion, secrets.ToArray());
                Pair <RootKey, ChainKey> sendingChain = derivedKeys.getRootKey().createChain(parameters.getTheirRatchetKey(), sendingRatchetKey);

                sessionState.addReceiverChain(parameters.getTheirRatchetKey(), derivedKeys.getChainKey());
                sessionState.setSenderChain(sendingRatchetKey, sendingChain.second());
                sessionState.setRootKey(sendingChain.first());
            }
            catch (IOException e)
            {
                throw new Exception(e.Message);
            }
        }
コード例 #2
0
        public static void InitializeSession(SessionState sessionState, AliceSignalProtocolParameters parameters)

        {
            try
            {
                sessionState.SetSessionVersion(CiphertextMessage.CurrentVersion);
                sessionState.SetRemoteIdentityKey(parameters.GetTheirIdentityKey());
                sessionState.SetLocalIdentityKey(parameters.GetOurIdentityKey().GetPublicKey());

                EcKeyPair    sendingRatchetKey = Curve.GenerateKeyPair();
                MemoryStream secrets           = new MemoryStream();

                byte[] discontinuityBytes = GetDiscontinuityBytes();
                secrets.Write(discontinuityBytes, 0, discontinuityBytes.Length);

                byte[] agree1 = Curve.CalculateAgreement(parameters.GetTheirSignedPreKey(),
                                                         parameters.GetOurIdentityKey().GetPrivateKey());
                byte[] agree2 = Curve.CalculateAgreement(parameters.GetTheirIdentityKey().GetPublicKey(),
                                                         parameters.GetOurBaseKey().GetPrivateKey());
                byte[] agree3 = Curve.CalculateAgreement(parameters.GetTheirSignedPreKey(),
                                                         parameters.GetOurBaseKey().GetPrivateKey());

                secrets.Write(agree1, 0, agree1.Length);
                secrets.Write(agree2, 0, agree2.Length);
                secrets.Write(agree3, 0, agree3.Length);


                if (parameters.GetTheirOneTimePreKey().HasValue)
                {
                    byte[] otAgree = Curve.CalculateAgreement(parameters.GetTheirOneTimePreKey().ForceGetValue(),
                                                              parameters.GetOurBaseKey().GetPrivateKey());
                    secrets.Write(otAgree, 0, otAgree.Length);
                }

                DerivedKeys derivedKeys = CalculateDerivedKeys(secrets.ToArray());
                Pair <RootKey, ChainKey> sendingChain = derivedKeys.GetRootKey().CreateChain(parameters.GetTheirRatchetKey(), sendingRatchetKey);

                sessionState.AddReceiverChain(parameters.GetTheirRatchetKey(), derivedKeys.GetChainKey());
                sessionState.SetSenderChain(sendingRatchetKey, sendingChain.Second());
                sessionState.SetRootKey(sendingChain.First());
            }
            catch (IOException e)
            {
                throw new Exception(e.Message);
            }
        }
コード例 #3
0
        public static void InitializeSession(SessionState sessionState,
                                             uint sessionVersion,
                                             BobAxolotlParameters parameters)
        {
            try
            {
                sessionState.SetSessionVersion(sessionVersion);
                sessionState.SetRemoteIdentityKey(parameters.GetTheirIdentityKey());
                sessionState.SetLocalIdentityKey(parameters.GetOurIdentityKey().GetPublicKey());

                MemoryStream secrets = new MemoryStream();

                if (sessionVersion >= 3)
                {
                    byte[] discontinuityBytes = GetDiscontinuityBytes();
                    secrets.Write(discontinuityBytes, 0, discontinuityBytes.Length);
                }

                byte[] agree1 = Curve.CalculateAgreement(parameters.GetTheirIdentityKey().GetPublicKey(),
                                                         parameters.GetOurSignedPreKey().GetPrivateKey());
                byte[] agree2 = Curve.CalculateAgreement(parameters.GetTheirBaseKey(),
                                                         parameters.GetOurIdentityKey().GetPrivateKey());
                byte[] agree3 = Curve.CalculateAgreement(parameters.GetTheirBaseKey(),
                                                         parameters.GetOurSignedPreKey().GetPrivateKey());
                secrets.Write(agree1, 0, agree1.Length);
                secrets.Write(agree2, 0, agree2.Length);
                secrets.Write(agree3, 0, agree3.Length);

                if (sessionVersion >= 3 && parameters.GetOurOneTimePreKey().HasValue)
                {
                    byte[] agree4 = Curve.CalculateAgreement(parameters.GetTheirBaseKey(),
                                                             parameters.GetOurOneTimePreKey().ForceGetValue().GetPrivateKey());
                    secrets.Write(agree4, 0, agree4.Length);
                }

                DerivedKeys derivedKeys = CalculateDerivedKeys(sessionVersion, secrets.ToArray());

                sessionState.SetSenderChain(parameters.GetOurRatchetKey(), derivedKeys.GetChainKey());
                sessionState.SetRootKey(derivedKeys.GetRootKey());
            }
            catch (IOException e)
            {
                throw new Exception(e.Message);
            }
        }
コード例 #4
0
        public static void initializeSession(SessionState sessionState,
                                             BobSignalProtocolParameters parameters)
        {
            try
            {
                sessionState.setSessionVersion(CiphertextMessage.CURRENT_VERSION);
                sessionState.setRemoteIdentityKey(parameters.getTheirIdentityKey());
                sessionState.setLocalIdentityKey(parameters.getOurIdentityKey().getPublicKey());

                MemoryStream secrets = new MemoryStream();

                byte[] discontinuityBytes = getDiscontinuityBytes();
                secrets.Write(discontinuityBytes, 0, discontinuityBytes.Length);

                byte[] agree1 = Curve.calculateAgreement(parameters.getTheirIdentityKey().getPublicKey(),
                                                         parameters.getOurSignedPreKey().getPrivateKey());
                byte[] agree2 = Curve.calculateAgreement(parameters.getTheirBaseKey(),
                                                         parameters.getOurIdentityKey().getPrivateKey());
                byte[] agree3 = Curve.calculateAgreement(parameters.getTheirBaseKey(),
                                                         parameters.getOurSignedPreKey().getPrivateKey());
                secrets.Write(agree1, 0, agree1.Length);
                secrets.Write(agree2, 0, agree2.Length);
                secrets.Write(agree3, 0, agree3.Length);

                if (parameters.getOurOneTimePreKey().HasValue)
                {
                    byte[] otAgree = Curve.calculateAgreement(parameters.getTheirBaseKey(),
                                                              parameters.getOurOneTimePreKey().ForceGetValue().getPrivateKey());
                    secrets.Write(otAgree, 0, otAgree.Length);
                }

                DerivedKeys derivedKeys = calculateDerivedKeys(secrets.ToArray());

                sessionState.setSenderChain(parameters.getOurRatchetKey(), derivedKeys.getChainKey());
                sessionState.setRootKey(derivedKeys.getRootKey());
            }
            catch (IOException e)
            {
                throw new Exception(e.Message);
            }
        }