mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 15:14:14 +00:00
s and i keys for all addresses
This commit is contained in:
parent
450266818a
commit
4211c733a2
@ -339,8 +339,8 @@ namespace transport
|
|||||||
m_Establisher->m_RemoteIdentHash = GetRemoteIdentity ()->GetIdentHash ();
|
m_Establisher->m_RemoteIdentHash = GetRemoteIdentity ()->GetIdentHash ();
|
||||||
if (addr)
|
if (addr)
|
||||||
{
|
{
|
||||||
memcpy (m_Establisher->m_RemoteStaticKey, addr->ntcp2->staticKey, 32);
|
memcpy (m_Establisher->m_RemoteStaticKey, addr->s, 32);
|
||||||
memcpy (m_Establisher->m_IV, addr->ntcp2->iv, 16);
|
memcpy (m_Establisher->m_IV, addr->i, 16);
|
||||||
m_RemoteEndpoint = boost::asio::ip::tcp::endpoint (addr->host, addr->port);
|
m_RemoteEndpoint = boost::asio::ip::tcp::endpoint (addr->host, addr->port);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -265,7 +265,7 @@ namespace i2p
|
|||||||
}
|
}
|
||||||
if (port) address->port = port;
|
if (port) address->port = port;
|
||||||
address->published = publish;
|
address->published = publish;
|
||||||
address->ntcp2->iv = m_NTCP2Keys->iv;
|
memcpy (address->i, m_NTCP2Keys->iv, 16);
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,10 +220,7 @@ namespace data
|
|||||||
char transportStyle[6];
|
char transportStyle[6];
|
||||||
ReadString (transportStyle, 6, s);
|
ReadString (transportStyle, 6, s);
|
||||||
if (!strncmp (transportStyle, "NTCP", 4)) // NTCP or NTCP2
|
if (!strncmp (transportStyle, "NTCP", 4)) // NTCP or NTCP2
|
||||||
{
|
|
||||||
address->transportStyle = eTransportNTCP;
|
address->transportStyle = eTransportNTCP;
|
||||||
address->ntcp2.reset (new NTCP2Ext ());
|
|
||||||
}
|
|
||||||
else if (!strcmp (transportStyle, "SSU"))
|
else if (!strcmp (transportStyle, "SSU"))
|
||||||
{
|
{
|
||||||
address->transportStyle = eTransportSSU;
|
address->transportStyle = eTransportSSU;
|
||||||
@ -271,12 +268,12 @@ namespace data
|
|||||||
address->caps = ExtractAddressCaps (value);
|
address->caps = ExtractAddressCaps (value);
|
||||||
else if (!strcmp (key, "s")) // ntcp2 static key
|
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;
|
isStaticKey = true;
|
||||||
}
|
}
|
||||||
else if (!strcmp (key, "i")) // ntcp2 iv
|
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"
|
address->published = true; // presence if "i" means "published"
|
||||||
}
|
}
|
||||||
else if (key[0] == 'i')
|
else if (key[0] == 'i')
|
||||||
@ -614,10 +611,9 @@ namespace data
|
|||||||
addr->transportStyle = eTransportNTCP;
|
addr->transportStyle = eTransportNTCP;
|
||||||
addr->caps = caps;
|
addr->caps = caps;
|
||||||
addr->date = 0;
|
addr->date = 0;
|
||||||
addr->ntcp2.reset (new NTCP2Ext ());
|
|
||||||
if (port) addr->published = true;
|
if (port) addr->published = true;
|
||||||
memcpy (addr->ntcp2->staticKey, staticKey, 32);
|
memcpy (addr->s, staticKey, 32);
|
||||||
memcpy (addr->ntcp2->iv, iv, 16);
|
memcpy (addr->i, iv, 16);
|
||||||
if (addr->IsV4 ())
|
if (addr->IsV4 ())
|
||||||
{
|
{
|
||||||
m_SupportedTransports |= eNTCP2V4;
|
m_SupportedTransports |= eNTCP2V4;
|
||||||
@ -845,7 +841,7 @@ namespace data
|
|||||||
return GetAddress (
|
return GetAddress (
|
||||||
[key](std::shared_ptr<const RouterInfo::Address> address)->bool
|
[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
|
|||||||
{
|
{
|
||||||
// publish i for NTCP2
|
// publish i for NTCP2
|
||||||
WriteString ("i", properties); properties << '=';
|
WriteString ("i", properties); properties << '=';
|
||||||
WriteString (address.ntcp2->iv.ToBase64 (), properties); properties << ';';
|
WriteString (address.i.ToBase64 (16), properties); properties << ';';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPublished || address.ssu)
|
if (isPublished || address.ssu)
|
||||||
@ -1211,7 +1207,7 @@ namespace data
|
|||||||
{
|
{
|
||||||
// publish s and v for NTCP2
|
// publish s and v for NTCP2
|
||||||
WriteString ("s", properties); properties << '=';
|
WriteString ("s", properties); properties << '=';
|
||||||
WriteString (address.ntcp2->staticKey.ToBase64 (), properties); properties << ';';
|
WriteString (address.s.ToBase64 (), properties); properties << ';';
|
||||||
WriteString ("v", properties); properties << '=';
|
WriteString ("v", properties); properties << '=';
|
||||||
WriteString ("2", properties); properties << ';';
|
WriteString ("2", properties); properties << ';';
|
||||||
}
|
}
|
||||||
|
@ -113,22 +113,16 @@ namespace data
|
|||||||
std::vector<Introducer> introducers;
|
std::vector<Introducer> introducers;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NTCP2Ext
|
|
||||||
{
|
|
||||||
Tag<32> staticKey;
|
|
||||||
Tag<16> iv;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Address
|
struct Address
|
||||||
{
|
{
|
||||||
TransportStyle transportStyle;
|
TransportStyle transportStyle;
|
||||||
boost::asio::ip::address host;
|
boost::asio::ip::address host;
|
||||||
|
Tag<32> s, i; // keys, i is first 16 bytes for NTCP2
|
||||||
int port;
|
int port;
|
||||||
uint64_t date;
|
uint64_t date;
|
||||||
uint8_t caps;
|
uint8_t caps;
|
||||||
bool published = false;
|
bool published = false;
|
||||||
std::unique_ptr<SSUExt> ssu; // not null for SSU
|
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
|
bool IsCompatible (const boost::asio::ip::address& other) const
|
||||||
{
|
{
|
||||||
@ -147,7 +141,7 @@ namespace data
|
|||||||
return !(*this == other);
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsNTCP2 () const { return (bool)ntcp2; };
|
bool IsNTCP2 () const { return transportStyle == eTransportNTCP; };
|
||||||
bool IsPublishedNTCP2 () const { return IsNTCP2 () && published; };
|
bool IsPublishedNTCP2 () const { return IsNTCP2 () && published; };
|
||||||
bool IsReachableSSU () const { return (bool)ssu && (published || !ssu->introducers.empty ()); };
|
bool IsReachableSSU () const { return (bool)ssu && (published || !ssu->introducers.empty ()); };
|
||||||
bool UsesIntroducer () const { return (bool)ssu && !ssu->introducers.empty (); };
|
bool UsesIntroducer () const { return (bool)ssu && !ssu->introducers.empty (); };
|
||||||
|
@ -21,8 +21,7 @@ namespace transport
|
|||||||
if (in_RemoteRouter && addr)
|
if (in_RemoteRouter && addr)
|
||||||
{
|
{
|
||||||
// outgoing
|
// outgoing
|
||||||
if (addr->ntcp2) // TODO: should be SSU
|
InitNoiseXKState1 (*m_NoiseState, addr->s);
|
||||||
InitNoiseXKState1 (*m_NoiseState, addr->ntcp2->staticKey);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@ -9,14 +9,6 @@
|
|||||||
#ifndef TAG_H__
|
#ifndef TAG_H__
|
||||||
#define 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 <boost/static_assert.hpp>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <openssl/rand.h>
|
#include <openssl/rand.h>
|
||||||
@ -64,17 +56,17 @@ namespace data {
|
|||||||
RAND_bytes(m_Buf, sz);
|
RAND_bytes(m_Buf, sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ToBase64 () const
|
std::string ToBase64 (size_t len = sz) const
|
||||||
{
|
{
|
||||||
char str[sz*2];
|
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);
|
return std::string (str, str + l);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ToBase32 () const
|
std::string ToBase32 (size_t len = sz) const
|
||||||
{
|
{
|
||||||
char str[sz*2];
|
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);
|
return std::string (str, str + l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user