Example #1
0
        public void SetSenderChainKey(ChainKey nextChainKey)
        {
            StorageProtos.SessionStructure.Types.Chain.Types.ChainKey chainKey = StorageProtos.SessionStructure.Types.Chain.Types.ChainKey.CreateBuilder()
                                                                                 .SetKey(ByteString.CopyFrom(nextChainKey.GetKey()))
                                                                                 .SetIndex(nextChainKey.GetIndex())
                                                                                 .Build();

            StorageProtos.SessionStructure.Types.Chain chain = _sessionStructure.SenderChain.ToBuilder()
                                                               .SetChainKey(chainKey).Build();

            _sessionStructure = _sessionStructure.ToBuilder().SetSenderChain(chain).Build();
        }
Example #2
0
        public void SetSenderChain(EcKeyPair senderRatchetKeyPair, ChainKey chainKey)
        {
            StorageProtos.SessionStructure.Types.Chain.Types.ChainKey chainKeyStructure = StorageProtos.SessionStructure.Types.Chain.Types.ChainKey.CreateBuilder()
                                                                                          .SetKey(ByteString.CopyFrom(chainKey.GetKey()))
                                                                                          .SetIndex(chainKey.GetIndex())
                                                                                          .Build();

            StorageProtos.SessionStructure.Types.Chain senderChain = StorageProtos.SessionStructure.Types.Chain.CreateBuilder()
                                                                     .SetSenderRatchetKey(ByteString.CopyFrom(senderRatchetKeyPair.GetPublicKey().Serialize()))
                                                                     .SetSenderRatchetKeyPrivate(ByteString.CopyFrom(senderRatchetKeyPair.GetPrivateKey().Serialize()))
                                                                     .SetChainKey(chainKeyStructure)
                                                                     .Build();

            _sessionStructure = _sessionStructure.ToBuilder().SetSenderChain(senderChain).Build();
        }
Example #3
0
        public void SetReceiverChainKey(IEcPublicKey senderEphemeral, ChainKey chainKey)
        {
            Pair <StorageProtos.SessionStructure.Types.Chain, uint> chainAndIndex = GetReceiverChain(senderEphemeral);

            StorageProtos.SessionStructure.Types.Chain chain = chainAndIndex.First();

            StorageProtos.SessionStructure.Types.Chain.Types.ChainKey chainKeyStructure = StorageProtos.SessionStructure.Types.Chain.Types.ChainKey.CreateBuilder()
                                                                                          .SetKey(ByteString.CopyFrom(chainKey.GetKey()))
                                                                                          .SetIndex(chainKey.GetIndex())
                                                                                          .Build();

            StorageProtos.SessionStructure.Types.Chain updatedChain = chain.ToBuilder().SetChainKey(chainKeyStructure).Build();

            _sessionStructure = _sessionStructure.ToBuilder()
                                .SetReceiverChains((int)chainAndIndex.Second(), updatedChain)                                                                                  // TODO: conv
                                .Build();
        }
Example #4
0
        public void AddReceiverChain(IEcPublicKey senderRatchetKey, ChainKey chainKey)
        {
            StorageProtos.SessionStructure.Types.Chain.Types.ChainKey chainKeyStructure = StorageProtos.SessionStructure.Types.Chain.Types.ChainKey.CreateBuilder()
                                                                                          .SetKey(ByteString.CopyFrom(chainKey.GetKey()))
                                                                                          .SetIndex(chainKey.GetIndex())
                                                                                          .Build();

            StorageProtos.SessionStructure.Types.Chain chain = StorageProtos.SessionStructure.Types.Chain.CreateBuilder()
                                                               .SetChainKey(chainKeyStructure)
                                                               .SetSenderRatchetKey(ByteString.CopyFrom(senderRatchetKey.Serialize()))
                                                               .Build();

            _sessionStructure = _sessionStructure.ToBuilder().AddReceiverChains(chain).Build();

            if (_sessionStructure.ReceiverChainsList.Count > 5)
            {
                _sessionStructure = _sessionStructure.ToBuilder() /*.ClearReceiverChains()*/.Build();                //RemoveReceiverChains(0) TODO: why does it work without
            }
        }
Example #5
0
 public ChainKey GetSenderChainKey()
 {
     StorageProtos.SessionStructure.Types.Chain.Types.ChainKey chainKeyStructure = _sessionStructure.SenderChain.ChainKey;
     return(new ChainKey(Hkdf.CreateFor(GetSessionVersion()),
                         chainKeyStructure.Key.ToByteArray(), chainKeyStructure.Index));
 }