mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-21 16:49:10 +01:00
extract and verify family from RouterInfo
This commit is contained in:
parent
7bfc3562af
commit
4eef9e780f
5 changed files with 24 additions and 7 deletions
|
@ -101,12 +101,12 @@ namespace data
|
||||||
LogPrint (eLogInfo, "Family: ", numCertificates, " certificates loaded");
|
LogPrint (eLogInfo, "Family: ", numCertificates, " certificates loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Families::VerifyFamily (const char * family, const IdentHash& ident,
|
bool Families::VerifyFamily (const std::string& family, const IdentHash& ident,
|
||||||
const char * signature, const char * key)
|
const char * signature, const char * key)
|
||||||
{
|
{
|
||||||
uint8_t buf[50], signatureBuf[64];
|
uint8_t buf[50], signatureBuf[64];
|
||||||
size_t len = strlen (family), signatureLen = strlen (signature);
|
size_t len = family.length (), signatureLen = strlen (signature);
|
||||||
memcpy (buf, family, len);
|
memcpy (buf, family.c_str (), len);
|
||||||
memcpy (buf + len, (const uint8_t *)ident, 32);
|
memcpy (buf + len, (const uint8_t *)ident, 32);
|
||||||
len += 32;
|
len += 32;
|
||||||
Base64ToByteStream (signature, signatureLen, signatureBuf, 64);
|
Base64ToByteStream (signature, signatureLen, signatureBuf, 64);
|
||||||
|
|
4
Family.h
4
Family.h
|
@ -18,8 +18,8 @@ namespace data
|
||||||
Families ();
|
Families ();
|
||||||
~Families ();
|
~Families ();
|
||||||
void LoadCertificates ();
|
void LoadCertificates ();
|
||||||
bool VerifyFamily (const char * family, const IdentHash& ident,
|
bool VerifyFamily (const std::string& family, const IdentHash& ident,
|
||||||
const char * signature, const char * key);
|
const char * signature, const char * key = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
1
NetDb.h
1
NetDb.h
|
@ -62,6 +62,7 @@ namespace data
|
||||||
void PostI2NPMsg (std::shared_ptr<const I2NPMessage> msg);
|
void PostI2NPMsg (std::shared_ptr<const I2NPMessage> msg);
|
||||||
|
|
||||||
void Reseed ();
|
void Reseed ();
|
||||||
|
Families& GetFamilies () { return m_Families; };
|
||||||
|
|
||||||
// for web interface
|
// for web interface
|
||||||
int GetNumRouters () const { return m_RouterInfos.size (); };
|
int GetNumRouters () const { return m_RouterInfos.size (); };
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
#include "Timestamp.h"
|
#include "Timestamp.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "NetDb.h"
|
||||||
#include "RouterInfo.h"
|
#include "RouterInfo.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
|
@ -262,11 +263,26 @@ namespace data
|
||||||
if (!strcmp (key, "caps"))
|
if (!strcmp (key, "caps"))
|
||||||
ExtractCaps (value);
|
ExtractCaps (value);
|
||||||
// check netId
|
// check netId
|
||||||
if (!strcmp (key, "netId") && atoi (value) != I2PD_NET_ID)
|
else if (!strcmp (key, "netId") && atoi (value) != I2PD_NET_ID)
|
||||||
{
|
{
|
||||||
LogPrint (eLogError, "Unexpected netid=", value);
|
LogPrint (eLogError, "Unexpected netid=", value);
|
||||||
m_IsUnreachable = true;
|
m_IsUnreachable = true;
|
||||||
}
|
}
|
||||||
|
// family
|
||||||
|
else if (!strcmp (key, "family"))
|
||||||
|
{
|
||||||
|
m_Family = value;
|
||||||
|
boost::to_lower (m_Family);
|
||||||
|
}
|
||||||
|
else if (!strcmp (key, "family.sig"))
|
||||||
|
{
|
||||||
|
if (!netdb.GetFamilies ().VerifyFamily (m_Family, GetIdentHash (), value))
|
||||||
|
{
|
||||||
|
LogPrint (eLogWarning, "RouterInfo: family signature verification failed");
|
||||||
|
m_Family.clear ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!s) return;
|
if (!s) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ namespace data
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string m_FullPath;
|
std::string m_FullPath, m_Family;
|
||||||
std::shared_ptr<const IdentityEx> m_RouterIdentity;
|
std::shared_ptr<const IdentityEx> m_RouterIdentity;
|
||||||
uint8_t * m_Buffer;
|
uint8_t * m_Buffer;
|
||||||
size_t m_BufferLen;
|
size_t m_BufferLen;
|
||||||
|
|
Loading…
Add table
Reference in a new issue