public void setSenderChainKey(ChainKey nextChainKey) { Chain.Types.ChainKey chainKey = Chain.Types.ChainKey.CreateBuilder() .SetKey(ByteString.CopyFrom(nextChainKey.getKey())) .SetIndex(nextChainKey.getIndex()) .Build(); Chain chain = sessionStructure.SenderChain.ToBuilder() .SetChainKey(chainKey).Build(); this.sessionStructure = this.sessionStructure.ToBuilder().SetSenderChain(chain).Build(); }
public void setUnacknowledgedPreKeyMessage(May <uint> preKeyId, uint signedPreKeyId, ECPublicKey baseKey) { PendingPreKey.Builder pending = PendingPreKey.CreateBuilder() .SetSignedPreKeyId(signedPreKeyId) .SetBaseKey(ByteString.CopyFrom(baseKey.serialize())); if (preKeyId.HasValue) { pending.SetPreKeyId(preKeyId.ForceGetValue()); } this.sessionStructure = this.sessionStructure.ToBuilder() .SetPendingPreKey(pending.Build()) .Build(); }
public void setSenderChain(ECKeyPair senderRatchetKeyPair, ChainKey chainKey) { Chain.Types.ChainKey chainKeyStructure = Chain.Types.ChainKey.CreateBuilder() .SetKey(ByteString.CopyFrom(chainKey.getKey())) .SetIndex(chainKey.getIndex()) .Build(); Chain senderChain = Chain.CreateBuilder() .SetSenderRatchetKey(ByteString.CopyFrom(senderRatchetKeyPair.getPublicKey().serialize())) .SetSenderRatchetKeyPrivate(ByteString.CopyFrom(senderRatchetKeyPair.getPrivateKey().serialize())) .SetChainKey(chainKeyStructure) .Build(); this.sessionStructure = this.sessionStructure.ToBuilder().SetSenderChain(senderChain).Build(); }
public void setReceiverChainKey(ECPublicKey senderEphemeral, ChainKey chainKey) { Pair <Chain, uint> chainAndIndex = getReceiverChain(senderEphemeral); Chain chain = chainAndIndex.first(); Chain.Types.ChainKey chainKeyStructure = Chain.Types.ChainKey.CreateBuilder() .SetKey(ByteString.CopyFrom(chainKey.getKey())) .SetIndex(chainKey.getIndex()) .Build(); Chain updatedChain = chain.ToBuilder().SetChainKey(chainKeyStructure).Build(); this.sessionStructure = this.sessionStructure.ToBuilder() .SetReceiverChains((int)chainAndIndex.second(), updatedChain) // TODO: conv .Build(); }
public void addReceiverChain(ECPublicKey senderRatchetKey, ChainKey chainKey) { Chain.Types.ChainKey chainKeyStructure = Chain.Types.ChainKey.CreateBuilder() .SetKey(ByteString.CopyFrom(chainKey.getKey())) .SetIndex(chainKey.getIndex()) .Build(); Chain chain = Chain.CreateBuilder() .SetChainKey(chainKeyStructure) .SetSenderRatchetKey(ByteString.CopyFrom(senderRatchetKey.serialize())) .Build(); sessionStructure = sessionStructure.ToBuilder().AddReceiverChains(chain).Build(); if (sessionStructure.ReceiverChainsList.Count > 5) { sessionStructure = sessionStructure.ToBuilder().Build(); } }
public void addReceiverChain(ECPublicKey senderRatchetKey, ChainKey chainKey) { Chain.Types.ChainKey chainKeyStructure = Chain.Types.ChainKey.CreateBuilder() .SetKey(ByteString.CopyFrom(chainKey.getKey())) .SetIndex(chainKey.getIndex()) .Build(); Chain chain = Chain.CreateBuilder() .SetChainKey(chainKeyStructure) .SetSenderRatchetKey(ByteString.CopyFrom(senderRatchetKey.serialize())) .Build(); this.sessionStructure = this.sessionStructure.ToBuilder().AddReceiverChains(chain).Build(); if (this.sessionStructure.ReceiverChainsList.Count > 5) { this.sessionStructure = this.sessionStructure.ToBuilder() /*.ClearReceiverChains()*/.Build(); //RemoveReceiverChains(0) TODO: why does it work without } }
public void setMessageKeys(ECPublicKey senderEphemeral, MessageKeys messageKeys) { Pair <Chain, uint> chainAndIndex = getReceiverChain(senderEphemeral); Chain chain = chainAndIndex.first(); Chain.Types.MessageKey messageKeyStructure = Chain.Types.MessageKey.CreateBuilder() .SetCipherKey(ByteString.CopyFrom(messageKeys.getCipherKey() /*.getEncoded()*/)) .SetMacKey(ByteString.CopyFrom(messageKeys.getMacKey() /*.getEncoded()*/)) .SetIndex(messageKeys.getCounter()) .SetIv(ByteString.CopyFrom(messageKeys.getIv() /*.getIV()*/)) .Build(); Chain updatedChain = chain.ToBuilder() .AddMessageKeys(messageKeyStructure) .Build(); this.sessionStructure = this.sessionStructure.ToBuilder() .SetReceiverChains((int)chainAndIndex.second(), updatedChain) // TODO: conv .Build(); }
public void setPendingKeyExchange(uint sequence, ECKeyPair ourBaseKey, ECKeyPair ourRatchetKey, IdentityKeyPair ourIdentityKey) { PendingKeyExchange structure = PendingKeyExchange.CreateBuilder() .SetSequence(sequence) .SetLocalBaseKey(ByteString.CopyFrom(ourBaseKey.getPublicKey().serialize())) .SetLocalBaseKeyPrivate(ByteString.CopyFrom(ourBaseKey.getPrivateKey().serialize())) .SetLocalRatchetKey(ByteString.CopyFrom(ourRatchetKey.getPublicKey().serialize())) .SetLocalRatchetKeyPrivate(ByteString.CopyFrom(ourRatchetKey.getPrivateKey().serialize())) .SetLocalIdentityKey(ByteString.CopyFrom(ourIdentityKey.getPublicKey().serialize())) .SetLocalIdentityKeyPrivate(ByteString.CopyFrom(ourIdentityKey.getPrivateKey().serialize())) .Build(); this.sessionStructure = this.sessionStructure.ToBuilder() .SetPendingKeyExchange(structure) .Build(); }
public MessageKeys removeMessageKeys(ECPublicKey senderEphemeral, uint counter) { Pair <Chain, uint> chainAndIndex = getReceiverChain(senderEphemeral); Chain chain = chainAndIndex.first(); if (chain == null) { return(null); } List <Chain.Types.MessageKey> messageKeyList = new List <Chain.Types.MessageKey>(chain.MessageKeysList); IEnumerator <Chain.Types.MessageKey> messageKeyIterator = messageKeyList.GetEnumerator(); MessageKeys result = null; while (messageKeyIterator.MoveNext()) //hasNext() { Chain.Types.MessageKey messageKey = messageKeyIterator.Current; // next() if (messageKey.Index == counter) { result = new MessageKeys(messageKey.CipherKey.ToByteArray(), messageKey.MacKey.ToByteArray(), messageKey.Iv.ToByteArray(), messageKey.Index); messageKeyList.Remove(messageKey); //messageKeyIterator.remove(); break; } } Chain updatedChain = chain.ToBuilder().ClearMessageKeys() .AddRangeMessageKeys(messageKeyList) // AddAllMessageKeys .Build(); this.sessionStructure = this.sessionStructure.ToBuilder() .SetReceiverChains((int)chainAndIndex.second(), updatedChain) // TODO: conv .Build(); return(result); }
public void setMessageKeys(ECPublicKey senderEphemeral, MessageKeys messageKeys) { Pair <Chain, uint> chainAndIndex = getReceiverChain(senderEphemeral); Chain chain = chainAndIndex.first(); Chain.Types.MessageKey messageKeyStructure = Chain.Types.MessageKey.CreateBuilder() .SetCipherKey(ByteString.CopyFrom(messageKeys.getCipherKey())) .SetMacKey(ByteString.CopyFrom(messageKeys.getMacKey())) .SetIndex(messageKeys.getCounter()) .SetIv(ByteString.CopyFrom(messageKeys.getIv())) .Build(); Chain.Builder updatedChain = chain.ToBuilder().AddMessageKeys(messageKeyStructure); if (updatedChain.MessageKeysList.Count > MAX_MESSAGE_KEYS) { updatedChain.MessageKeysList.RemoveAt(0); } sessionStructure = sessionStructure.ToBuilder() .SetReceiverChains((int)chainAndIndex.second(), updatedChain.Build()) .Build(); }
public void setPreviousCounter(uint previousCounter) { this.sessionStructure = this.sessionStructure.ToBuilder() .SetPreviousCounter(previousCounter) .Build(); }
public void setUnacknowledgedPreKeyMessage(May<uint> preKeyId, uint signedPreKeyId, ECPublicKey baseKey) { PendingPreKey.Builder pending = PendingPreKey.CreateBuilder() .SetSignedPreKeyId(signedPreKeyId) .SetBaseKey(ByteString.CopyFrom(baseKey.serialize())); if (preKeyId.HasValue) { pending.SetPreKeyId(preKeyId.ForceGetValue()); } this.sessionStructure = this.sessionStructure.ToBuilder() .SetPendingPreKey(pending.Build()) .Build(); }
public SessionState(SessionState copy) { this.sessionStructure = copy.sessionStructure.ToBuilder().Build(); }
public SessionState(SessionStructure sessionStructure) { _sessionStructure = sessionStructure; }
public SessionState() { _sessionStructure = new SessionStructure { }; }
public SessionState() { this.sessionStructure = SessionStructure.CreateBuilder().Build(); }
public SessionState(SessionStructure sessionStructure) { this.sessionStructure = sessionStructure; }
public void setRemoteRegistrationId(uint registrationId) { sessionStructure = sessionStructure.ToBuilder() .SetRemoteRegistrationId(registrationId) .Build(); }
public void setReceiverChainKey(ECPublicKey senderEphemeral, ChainKey chainKey) { Pair<Chain, uint> chainAndIndex = getReceiverChain(senderEphemeral); Chain chain = chainAndIndex.first(); Chain.Types.ChainKey chainKeyStructure = Chain.Types.ChainKey.CreateBuilder() .SetKey(ByteString.CopyFrom(chainKey.getKey())) .SetIndex(chainKey.getIndex()) .Build(); Chain updatedChain = chain.ToBuilder().SetChainKey(chainKeyStructure).Build(); this.sessionStructure = this.sessionStructure.ToBuilder() .SetReceiverChains((int)chainAndIndex.second(), updatedChain) // TODO: conv .Build(); }
public void setMessageKeys(ECPublicKey senderEphemeral, MessageKeys messageKeys) { Pair<Chain, uint> chainAndIndex = getReceiverChain(senderEphemeral); Chain chain = chainAndIndex.first(); Chain.Types.MessageKey messageKeyStructure = Chain.Types.MessageKey.CreateBuilder() .SetCipherKey(ByteString.CopyFrom(messageKeys.getCipherKey()/*.getEncoded()*/)) .SetMacKey(ByteString.CopyFrom(messageKeys.getMacKey()/*.getEncoded()*/)) .SetIndex(messageKeys.getCounter()) .SetIv(ByteString.CopyFrom(messageKeys.getIv()/*.getIV()*/)) .Build(); Chain.Builder updatedChain = chain.ToBuilder().AddMessageKeys(messageKeyStructure); if (updatedChain.MessageKeysList.Count > MAX_MESSAGE_KEYS) { updatedChain.MessageKeysList.RemoveAt(0); } this.sessionStructure = this.sessionStructure.ToBuilder() .SetReceiverChains((int)chainAndIndex.second(), updatedChain.Build()) // TODO: conv .Build(); }
public MessageKeys removeMessageKeys(ECPublicKey senderEphemeral, uint counter) { Pair<Chain, uint> chainAndIndex = getReceiverChain(senderEphemeral); Chain chain = chainAndIndex.first(); if (chain == null) { return null; } List<Chain.Types.MessageKey> messageKeyList = new List<Chain.Types.MessageKey>(chain.MessageKeysList); IEnumerator<Chain.Types.MessageKey> messageKeyIterator = messageKeyList.GetEnumerator(); MessageKeys result = null; while (messageKeyIterator.MoveNext()) //hasNext() { Chain.Types.MessageKey messageKey = messageKeyIterator.Current; // next() if (messageKey.Index == counter) { result = new MessageKeys(messageKey.CipherKey.ToByteArray(), messageKey.MacKey.ToByteArray(), messageKey.Iv.ToByteArray(), messageKey.Index); messageKeyList.Remove(messageKey); //messageKeyIterator.remove(); break; } } Chain updatedChain = chain.ToBuilder().ClearMessageKeys() .AddRangeMessageKeys(messageKeyList) // AddAllMessageKeys .Build(); this.sessionStructure = this.sessionStructure.ToBuilder() .SetReceiverChains((int)chainAndIndex.second(), updatedChain) // TODO: conv .Build(); return result; }
public void setRemoteIdentityKey(IdentityKey identityKey) { sessionStructure = sessionStructure.ToBuilder() .SetRemoteIdentityPublic(ByteString.CopyFrom(identityKey.serialize())) .Build(); }
public void setRootKey(RootKey rootKey) { this.sessionStructure = this.sessionStructure.ToBuilder() .SetRootKey(ByteString.CopyFrom(rootKey.getKeyBytes())) .Build(); }
public void addReceiverChain(ECPublicKey senderRatchetKey, ChainKey chainKey) { Chain.Types.ChainKey chainKeyStructure = Chain.Types.ChainKey.CreateBuilder() .SetKey(ByteString.CopyFrom(chainKey.getKey())) .SetIndex(chainKey.getIndex()) .Build(); Chain chain = Chain.CreateBuilder() .SetChainKey(chainKeyStructure) .SetSenderRatchetKey(ByteString.CopyFrom(senderRatchetKey.serialize())) .Build(); this.sessionStructure = this.sessionStructure.ToBuilder().AddReceiverChains(chain).Build(); if (this.sessionStructure.ReceiverChainsList.Count > 5) { this.sessionStructure = this.sessionStructure.ToBuilder()/*.ClearReceiverChains()*/.Build(); //RemoveReceiverChains(0) TODO: why does it work without } }
public SessionState(SessionState copy) { _sessionStructure = new SessionStructure(copy._sessionStructure); }
public void clearUnacknowledgedPreKeyMessage() { this.sessionStructure = this.sessionStructure.ToBuilder() .ClearPendingPreKey() .Build(); }
public void setSessionVersion(uint version) { this.sessionStructure = this.sessionStructure.ToBuilder() .SetSessionVersion(version) .Build(); }
public SessionState(SessionState copy) { this.sessionStructure = new SessionStructure(copy.sessionStructure); }
public void setLocalRegistrationId(uint registrationId) { this.sessionStructure = this.sessionStructure.ToBuilder() .SetLocalRegistrationId(registrationId) .Build(); }
public void setAliceBaseKey(byte[] aliceBaseKey) { this.sessionStructure = this.sessionStructure.ToBuilder() .SetAliceBaseKey(ByteString.CopyFrom(aliceBaseKey)) .Build(); }
public void setLocalIdentityKey(IdentityKey identityKey) { this.sessionStructure = this.sessionStructure.ToBuilder() .SetLocalIdentityPublic(ByteString.CopyFrom(identityKey.serialize())) .Build(); }
public SessionState() { this.sessionStructure = new SessionStructure { }; }