Browse Source

s and i keys for all addresses

pull/1727/head
orignal 3 years ago
parent
commit
4211c733a2
  1. 4
      libi2pd/NTCP2.cpp
  2. 2
      libi2pd/RouterContext.cpp
  3. 18
      libi2pd/RouterInfo.cpp
  4. 10
      libi2pd/RouterInfo.h
  5. 3
      libi2pd/SSU2.cpp
  6. 18
      libi2pd/Tag.h

4
libi2pd/NTCP2.cpp

@ -339,8 +339,8 @@ namespace transport @@ -339,8 +339,8 @@ namespace transport
m_Establisher->m_RemoteIdentHash = GetRemoteIdentity ()->GetIdentHash ();
if (addr)
{
memcpy (m_Establisher->m_RemoteStaticKey, addr->ntcp2->staticKey, 32);
memcpy (m_Establisher->m_IV, addr->ntcp2->iv, 16);
memcpy (m_Establisher->m_RemoteStaticKey, addr->s, 32);
memcpy (m_Establisher->m_IV, addr->i, 16);
m_RemoteEndpoint = boost::asio::ip::tcp::endpoint (addr->host, addr->port);
}
else

2
libi2pd/RouterContext.cpp

@ -265,7 +265,7 @@ namespace i2p @@ -265,7 +265,7 @@ namespace i2p
}
if (port) address->port = port;
address->published = publish;
address->ntcp2->iv = m_NTCP2Keys->iv;
memcpy (address->i, m_NTCP2Keys->iv, 16);
updated = true;
}
}

18
libi2pd/RouterInfo.cpp

@ -220,10 +220,7 @@ namespace data @@ -220,10 +220,7 @@ namespace data
char transportStyle[6];
ReadString (transportStyle, 6, s);
if (!strncmp (transportStyle, "NTCP", 4)) // NTCP or NTCP2
{
address->transportStyle = eTransportNTCP;
address->ntcp2.reset (new NTCP2Ext ());
}
else if (!strcmp (transportStyle, "SSU"))
{
address->transportStyle = eTransportSSU;
@ -271,12 +268,12 @@ namespace data @@ -271,12 +268,12 @@ namespace data
address->caps = ExtractAddressCaps (value);
else if (!strcmp (key, "s")) // ntcp2 static key
{
Base64ToByteStream (value, strlen (value), address->ntcp2->staticKey, 32);
Base64ToByteStream (value, strlen (value), address->s, 32);
isStaticKey = true;
}
else if (!strcmp (key, "i")) // ntcp2 iv
{
Base64ToByteStream (value, strlen (value), address->ntcp2->iv, 16);
Base64ToByteStream (value, strlen (value), address->i, 16);
address->published = true; // presence if "i" means "published"
}
else if (key[0] == 'i')
@ -614,10 +611,9 @@ namespace data @@ -614,10 +611,9 @@ namespace data
addr->transportStyle = eTransportNTCP;
addr->caps = caps;
addr->date = 0;
addr->ntcp2.reset (new NTCP2Ext ());
if (port) addr->published = true;
memcpy (addr->ntcp2->staticKey, staticKey, 32);
memcpy (addr->ntcp2->iv, iv, 16);
memcpy (addr->s, staticKey, 32);
memcpy (addr->i, iv, 16);
if (addr->IsV4 ())
{
m_SupportedTransports |= eNTCP2V4;
@ -845,7 +841,7 @@ namespace data @@ -845,7 +841,7 @@ namespace data
return GetAddress (
[key](std::shared_ptr<const RouterInfo::Address> address)->bool
{
return address->IsNTCP2 () && !memcmp (address->ntcp2->staticKey, key, 32);
return address->IsNTCP2 () && !memcmp (address->s, key, 32);
});
}
@ -1197,7 +1193,7 @@ namespace data @@ -1197,7 +1193,7 @@ namespace data
{
// publish i for NTCP2
WriteString ("i", properties); properties << '=';
WriteString (address.ntcp2->iv.ToBase64 (), properties); properties << ';';
WriteString (address.i.ToBase64 (16), properties); properties << ';';
}
if (isPublished || address.ssu)
@ -1211,7 +1207,7 @@ namespace data @@ -1211,7 +1207,7 @@ namespace data
{
// publish s and v for NTCP2
WriteString ("s", properties); properties << '=';
WriteString (address.ntcp2->staticKey.ToBase64 (), properties); properties << ';';
WriteString (address.s.ToBase64 (), properties); properties << ';';
WriteString ("v", properties); properties << '=';
WriteString ("2", properties); properties << ';';
}

10
libi2pd/RouterInfo.h

@ -113,22 +113,16 @@ namespace data @@ -113,22 +113,16 @@ namespace data
std::vector<Introducer> introducers;
};
struct NTCP2Ext
{
Tag<32> staticKey;
Tag<16> iv;
};
struct Address
{
TransportStyle transportStyle;
boost::asio::ip::address host;
Tag<32> s, i; // keys, i is first 16 bytes for NTCP2
int port;
uint64_t date;
uint8_t caps;
bool published = false;
std::unique_ptr<SSUExt> ssu; // not null for SSU
std::unique_ptr<NTCP2Ext> ntcp2; // not null for NTCP2
bool IsCompatible (const boost::asio::ip::address& other) const
{
@ -147,7 +141,7 @@ namespace data @@ -147,7 +141,7 @@ namespace data
return !(*this == other);
}
bool IsNTCP2 () const { return (bool)ntcp2; };
bool IsNTCP2 () const { return transportStyle == eTransportNTCP; };
bool IsPublishedNTCP2 () const { return IsNTCP2 () && published; };
bool IsReachableSSU () const { return (bool)ssu && (published || !ssu->introducers.empty ()); };
bool UsesIntroducer () const { return (bool)ssu && !ssu->introducers.empty (); };

3
libi2pd/SSU2.cpp

@ -21,8 +21,7 @@ namespace transport @@ -21,8 +21,7 @@ namespace transport
if (in_RemoteRouter && addr)
{
// outgoing
if (addr->ntcp2) // TODO: should be SSU
InitNoiseXKState1 (*m_NoiseState, addr->ntcp2->staticKey);
InitNoiseXKState1 (*m_NoiseState, addr->s);
}
}

18
libi2pd/Tag.h

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2020, The PurpleI2P Project
* Copyright (c) 2013-2022, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
@ -9,14 +9,6 @@ @@ -9,14 +9,6 @@
#ifndef TAG_H__
#define TAG_H__
/*
* Copyright (c) 2013-2017, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
* See full license text in LICENSE file at top of project tree
*/
#include <boost/static_assert.hpp>
#include <string.h>
#include <openssl/rand.h>
@ -64,17 +56,17 @@ namespace data { @@ -64,17 +56,17 @@ namespace data {
RAND_bytes(m_Buf, sz);
}
std::string ToBase64 () const
std::string ToBase64 (size_t len = sz) const
{
char str[sz*2];
size_t l = i2p::data::ByteStreamToBase64 (m_Buf, sz, str, sz*2);
size_t l = i2p::data::ByteStreamToBase64 (m_Buf, len, str, sz*2);
return std::string (str, str + l);
}
std::string ToBase32 () const
std::string ToBase32 (size_t len = sz) const
{
char str[sz*2];
size_t l = i2p::data::ByteStreamToBase32 (m_Buf, sz, str, sz*2);
size_t l = i2p::data::ByteStreamToBase32 (m_Buf, len, str, sz*2);
return std::string (str, str + l);
}

Loading…
Cancel
Save