mirror of
				https://github.com/PurpleI2P/i2pd.git
				synced 2025-11-04 08:30:46 +00:00 
			
		
		
		
	correct encryption key type for LS2
This commit is contained in:
		
							parent
							
								
									9cf43dea1a
								
							
						
					
					
						commit
						b89cf73ae2
					
				
					 2 changed files with 12 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -777,20 +777,20 @@ namespace client
 | 
			
		|||
		m_DatagramDestination (nullptr), m_RefCounter (0),
 | 
			
		||||
		m_ReadyChecker(GetService())
 | 
			
		||||
	{
 | 
			
		||||
		i2p::data::CryptoKeyType keyType = GetIdentity ()->GetCryptoKeyType ();
 | 
			
		||||
		m_EncryptionKeyType = GetIdentity ()->GetCryptoKeyType ();
 | 
			
		||||
		// extract encryption type params for LS2
 | 
			
		||||
		if (GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2 && params)
 | 
			
		||||
		{
 | 
			
		||||
			auto it = params->find (I2CP_PARAM_LEASESET_ENCRYPTION_TYPE);
 | 
			
		||||
			if (it != params->end ())
 | 
			
		||||
				keyType = std::stoi(it->second);
 | 
			
		||||
				m_EncryptionKeyType = std::stoi(it->second);
 | 
			
		||||
		}		
 | 
			
		||||
	
 | 
			
		||||
		if (isPublic)
 | 
			
		||||
			PersistTemporaryKeys (keyType);
 | 
			
		||||
		if (isPublic && m_EncryptionKeyType == GetIdentity ()->GetCryptoKeyType ()) // TODO: presist key type
 | 
			
		||||
			PersistTemporaryKeys ();
 | 
			
		||||
		else
 | 
			
		||||
			i2p::data::PrivateKeys::GenerateCryptoKeyPair (keyType, m_EncryptionPrivateKey, m_EncryptionPublicKey);
 | 
			
		||||
		m_Decryptor = i2p::data::PrivateKeys::CreateDecryptor (keyType, m_EncryptionPrivateKey);
 | 
			
		||||
			i2p::data::PrivateKeys::GenerateCryptoKeyPair (m_EncryptionKeyType, m_EncryptionPrivateKey, m_EncryptionPublicKey);
 | 
			
		||||
		m_Decryptor = i2p::data::PrivateKeys::CreateDecryptor (m_EncryptionKeyType, m_EncryptionPrivateKey);
 | 
			
		||||
		if (isPublic)
 | 
			
		||||
			LogPrint (eLogInfo, "Destination: Local address ", GetIdentHash().ToBase32 (), " created");
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1008,7 +1008,7 @@ namespace client
 | 
			
		|||
		return ret;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void ClientDestination::PersistTemporaryKeys (i2p::data::CryptoKeyType keyType)
 | 
			
		||||
	void ClientDestination::PersistTemporaryKeys ()
 | 
			
		||||
	{
 | 
			
		||||
		std::string ident = GetIdentHash().ToBase32();
 | 
			
		||||
		std::string path  = i2p::fs::DataDirPath("destinations", (ident + ".dat"));
 | 
			
		||||
| 
						 | 
				
			
			@ -1020,10 +1020,10 @@ namespace client
 | 
			
		|||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		LogPrint (eLogInfo, "Destination: Creating new temporary keys of type ", (int)keyType, " for address ", ident, ".b32.i2p");
 | 
			
		||||
		LogPrint (eLogInfo, "Destination: Creating new temporary keys of type for address ", ident, ".b32.i2p");
 | 
			
		||||
		memset (m_EncryptionPrivateKey, 0, 256);
 | 
			
		||||
		memset (m_EncryptionPublicKey, 0, 256);	
 | 
			
		||||
		i2p::data::PrivateKeys::GenerateCryptoKeyPair (keyType, m_EncryptionPrivateKey, m_EncryptionPublicKey);
 | 
			
		||||
		i2p::data::PrivateKeys::GenerateCryptoKeyPair (GetIdentity ()->GetCryptoKeyType (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
 | 
			
		||||
 | 
			
		||||
		std::ofstream f1 (path, std::ofstream::binary | std::ofstream::out);
 | 
			
		||||
		if (f1) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1048,7 +1048,7 @@ namespace client
 | 
			
		|||
			// standard LS2 (type 3) assumed for now. TODO: implement others
 | 
			
		||||
			auto keyLen = m_Decryptor ? m_Decryptor->GetPublicKeyLen () : 256;
 | 
			
		||||
			leaseSet = new i2p::data::LocalLeaseSet2 (i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2,
 | 
			
		||||
				GetIdentity (), GetIdentity ()->GetCryptoKeyType (), keyLen, m_EncryptionPublicKey, tunnels);
 | 
			
		||||
				GetIdentity (), m_EncryptionKeyType, keyLen, m_EncryptionPublicKey, tunnels);
 | 
			
		||||
			// sign
 | 
			
		||||
			Sign (leaseSet->GetBuffer () - 1, leaseSet->GetBufferLen () - leaseSet->GetSignatureLen () + 1, leaseSet->GetSignature ()); // + leading store type
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -234,7 +234,7 @@ namespace client
 | 
			
		|||
 | 
			
		||||
			std::shared_ptr<ClientDestination> GetSharedFromThis ()
 | 
			
		||||
			{ return std::static_pointer_cast<ClientDestination>(shared_from_this ()); }
 | 
			
		||||
			void PersistTemporaryKeys (i2p::data::CryptoKeyType keyType);
 | 
			
		||||
			void PersistTemporaryKeys ();
 | 
			
		||||
#ifdef I2LUA
 | 
			
		||||
			void ScheduleCheckForReady(ReadyPromise * p);
 | 
			
		||||
			void HandleCheckForReady(const boost::system::error_code & ecode, ReadyPromise * p);
 | 
			
		||||
| 
						 | 
				
			
			@ -243,6 +243,7 @@ namespace client
 | 
			
		|||
 | 
			
		||||
			i2p::data::PrivateKeys m_Keys;
 | 
			
		||||
			uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256];
 | 
			
		||||
			i2p::data::CryptoKeyType m_EncryptionKeyType;
 | 
			
		||||
			std::shared_ptr<i2p::crypto::CryptoKeyDecryptor> m_Decryptor;
 | 
			
		||||
 | 
			
		||||
			int m_StreamingAckDelay;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue