예제 #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 {
     };
 }