Пример #1
0
        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();
        }
Пример #2
0
        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();
        }
Пример #3
0
        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();
        }
Пример #4
0
        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();
            }
        }
Пример #6
0
        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
            }
        }
Пример #7
0
        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();
        }
Пример #8
0
        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();
        }
Пример #9
0
        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();
        }
Пример #11
0
		public void setPreviousCounter(uint previousCounter)
		{
			this.sessionStructure = this.sessionStructure.ToBuilder()
														 .SetPreviousCounter(previousCounter)
														 .Build();
		}
Пример #12
0
		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();
		}
Пример #13
0
 public SessionState(SessionState copy)
 {
     this.sessionStructure = copy.sessionStructure.ToBuilder().Build();
 }
Пример #14
0
		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 SessionState(SessionStructure sessionStructure)
 {
     _sessionStructure = sessionStructure;
 }
 public SessionState()
 {
     _sessionStructure = new SessionStructure {
     };
 }
Пример #17
0
 public void setPreviousCounter(uint previousCounter)
 {
     this.sessionStructure = this.sessionStructure.ToBuilder()
                             .SetPreviousCounter(previousCounter)
                             .Build();
 }
Пример #18
0
 public SessionState()
 {
     this.sessionStructure = SessionStructure.CreateBuilder().Build();
 }
Пример #19
0
		public SessionState(SessionStructure sessionStructure)
		{
			this.sessionStructure = sessionStructure;
		}
 public void setRemoteRegistrationId(uint registrationId)
 {
     sessionStructure = sessionStructure.ToBuilder()
                        .SetRemoteRegistrationId(registrationId)
                        .Build();
 }
Пример #21
0
		public SessionState()
		{
			this.sessionStructure = SessionStructure.CreateBuilder().Build();
		}
Пример #22
0
		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();
		}
Пример #23
0
		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();
		}
Пример #24
0
		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();
		}
Пример #25
0
		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();
 }
Пример #27
0
		public SessionState(SessionState copy)
		{
			this.sessionStructure = copy.sessionStructure.ToBuilder().Build();
		}
Пример #28
0
 public void setRootKey(RootKey rootKey)
 {
     this.sessionStructure = this.sessionStructure.ToBuilder()
                             .SetRootKey(ByteString.CopyFrom(rootKey.getKeyBytes()))
                             .Build();
 }
Пример #29
0
		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);
 }
Пример #31
0
		public void setRootKey(RootKey rootKey)
		{
			this.sessionStructure = this.sessionStructure.ToBuilder()
														 .SetRootKey(ByteString.CopyFrom(rootKey.getKeyBytes()))
														 .Build();
		}
Пример #32
0
 public SessionState(SessionStructure sessionStructure)
 {
     this.sessionStructure = sessionStructure;
 }
Пример #33
0
 public void clearUnacknowledgedPreKeyMessage()
 {
     this.sessionStructure = this.sessionStructure.ToBuilder()
                             .ClearPendingPreKey()
                             .Build();
 }
Пример #34
0
 public void setSessionVersion(uint version)
 {
     this.sessionStructure = this.sessionStructure.ToBuilder()
                             .SetSessionVersion(version)
                             .Build();
 }
 public SessionState(SessionState copy)
 {
     this.sessionStructure = new SessionStructure(copy.sessionStructure);
 }
Пример #36
0
		public void clearUnacknowledgedPreKeyMessage()
		{
			this.sessionStructure = this.sessionStructure.ToBuilder()
														 .ClearPendingPreKey()
														 .Build();
		}
Пример #37
0
		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();
		}
Пример #38
0
		public void setLocalRegistrationId(uint registrationId)
		{
			this.sessionStructure = this.sessionStructure.ToBuilder()
														 .SetLocalRegistrationId(registrationId)
														 .Build();
		}
Пример #39
0
		public void setAliceBaseKey(byte[] aliceBaseKey)
		{
			this.sessionStructure = this.sessionStructure.ToBuilder()
														 .SetAliceBaseKey(ByteString.CopyFrom(aliceBaseKey))
														 .Build();
		}
Пример #40
0
 public void setAliceBaseKey(byte[] aliceBaseKey)
 {
     this.sessionStructure = this.sessionStructure.ToBuilder()
                             .SetAliceBaseKey(ByteString.CopyFrom(aliceBaseKey))
                             .Build();
 }
Пример #41
0
		public void setSessionVersion(uint version)
		{
			this.sessionStructure = this.sessionStructure.ToBuilder()
														 .SetSessionVersion(version)
														 .Build();
		}
Пример #42
0
 public void setLocalRegistrationId(uint registrationId)
 {
     this.sessionStructure = this.sessionStructure.ToBuilder()
                             .SetLocalRegistrationId(registrationId)
                             .Build();
 }
Пример #43
0
		public void setLocalIdentityKey(IdentityKey identityKey)
		{
			this.sessionStructure = this.sessionStructure.ToBuilder()
														 .SetLocalIdentityPublic(ByteString.CopyFrom(identityKey.serialize()))
														 .Build();
		}
Пример #44
0
 public void setLocalIdentityKey(IdentityKey identityKey)
 {
     this.sessionStructure = this.sessionStructure.ToBuilder()
                             .SetLocalIdentityPublic(ByteString.CopyFrom(identityKey.serialize()))
                             .Build();
 }
 public SessionState()
 {
     this.sessionStructure = new SessionStructure {
     };
 }