mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-03 11:44:09 +00:00
Couple of small fixes, works again with new ID code.
This commit is contained in:
parent
2fa2796f2a
commit
430882327e
@ -90,26 +90,26 @@ static inline void _computeMemoryHardHash(const void *publicKey,unsigned int pub
|
|||||||
struct _Identity_generate_cond
|
struct _Identity_generate_cond
|
||||||
{
|
{
|
||||||
_Identity_generate_cond() throw() {}
|
_Identity_generate_cond() throw() {}
|
||||||
_Identity_generate_cond(unsigned char *sb,char *gm) throw() : sha512digest(sb),genmem(gm) {}
|
_Identity_generate_cond(unsigned char *sb,char *gm) throw() : digest(sb),genmem(gm) {}
|
||||||
inline bool operator()(const C25519::Pair &kp) const
|
inline bool operator()(const C25519::Pair &kp) const
|
||||||
throw()
|
throw()
|
||||||
{
|
{
|
||||||
_computeMemoryHardHash(kp.pub.data,kp.pub.size(),sha512digest,genmem);
|
_computeMemoryHardHash(kp.pub.data,kp.pub.size(),digest,genmem);
|
||||||
return (sha512digest[0] < ZT_IDENTITY_GEN_HASHCASH_FIRST_BYTE_LESS_THAN);
|
return (digest[0] < ZT_IDENTITY_GEN_HASHCASH_FIRST_BYTE_LESS_THAN);
|
||||||
}
|
}
|
||||||
unsigned char *sha512digest;
|
unsigned char *digest;
|
||||||
char *genmem;
|
char *genmem;
|
||||||
};
|
};
|
||||||
|
|
||||||
void Identity::generate()
|
void Identity::generate()
|
||||||
{
|
{
|
||||||
unsigned char sha512digest[64];
|
unsigned char digest[64];
|
||||||
char *genmem = new char[ZT_IDENTITY_GEN_MEMORY];
|
char *genmem = new char[ZT_IDENTITY_GEN_MEMORY];
|
||||||
|
|
||||||
C25519::Pair kp;
|
C25519::Pair kp;
|
||||||
do {
|
do {
|
||||||
kp = C25519::generateSatisfying(_Identity_generate_cond(sha512digest,genmem));
|
kp = C25519::generateSatisfying(_Identity_generate_cond(digest,genmem));
|
||||||
_address.setTo(sha512digest + 59,ZT_ADDRESS_LENGTH); // last 5 bytes are address
|
_address.setTo(digest + 59,ZT_ADDRESS_LENGTH); // last 5 bytes are address
|
||||||
} while (_address.isReserved());
|
} while (_address.isReserved());
|
||||||
|
|
||||||
_publicKey = kp.pub;
|
_publicKey = kp.pub;
|
||||||
@ -125,21 +125,21 @@ bool Identity::locallyValidate() const
|
|||||||
if (_address.isReserved())
|
if (_address.isReserved())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
unsigned char sha512digest[64];
|
unsigned char digest[64];
|
||||||
char *genmem = new char[ZT_IDENTITY_GEN_MEMORY];
|
char *genmem = new char[ZT_IDENTITY_GEN_MEMORY];
|
||||||
_computeMemoryHardHash(_publicKey.data,_publicKey.size(),sha512digest,genmem);
|
_computeMemoryHardHash(_publicKey.data,_publicKey.size(),digest,genmem);
|
||||||
delete [] genmem;
|
delete [] genmem;
|
||||||
|
|
||||||
unsigned char addrb[5];
|
unsigned char addrb[5];
|
||||||
_address.copyTo(addrb,5);
|
_address.copyTo(addrb,5);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(sha512digest[0] < ZT_IDENTITY_GEN_HASHCASH_FIRST_BYTE_LESS_THAN)&&
|
(digest[0] < ZT_IDENTITY_GEN_HASHCASH_FIRST_BYTE_LESS_THAN)&&
|
||||||
(sha512digest[59] == addrb[0])&&
|
(digest[59] == addrb[0])&&
|
||||||
(sha512digest[60] == addrb[1])&&
|
(digest[60] == addrb[1])&&
|
||||||
(sha512digest[61] == addrb[2])&&
|
(digest[61] == addrb[2])&&
|
||||||
(sha512digest[62] == addrb[3])&&
|
(digest[62] == addrb[3])&&
|
||||||
(sha512digest[63] == addrb[4]));
|
(digest[63] == addrb[4]));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Identity::toString(bool includePrivate) const
|
std::string Identity::toString(bool includePrivate) const
|
||||||
@ -176,7 +176,7 @@ bool Identity::fromString(const char *str)
|
|||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (f[0] != '0')
|
if ((f[0] != '0')||(f[1]))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -323,6 +323,8 @@ Node::ReasonForTermination Node::run()
|
|||||||
std::string idser;
|
std::string idser;
|
||||||
if (Utils::readFile(identitySecretPath.c_str(),idser))
|
if (Utils::readFile(identitySecretPath.c_str(),idser))
|
||||||
gotId = _r->identity.fromString(idser);
|
gotId = _r->identity.fromString(idser);
|
||||||
|
if ((gotId)&&(!_r->identity.locallyValidate()))
|
||||||
|
gotId = false;
|
||||||
if (gotId) {
|
if (gotId) {
|
||||||
// Make sure identity.public matches identity.secret
|
// Make sure identity.public matches identity.secret
|
||||||
idser = std::string();
|
idser = std::string();
|
||||||
@ -419,7 +421,7 @@ Node::ReasonForTermination Node::run()
|
|||||||
|
|
||||||
// Core I/O loop
|
// Core I/O loop
|
||||||
try {
|
try {
|
||||||
uint64_t lastNetworkAutoconfCheck = 0;
|
uint64_t lastNetworkAutoconfCheck = Utils::now() - 5000; // check autoconf again after 5s for startup
|
||||||
uint64_t lastPingCheck = 0;
|
uint64_t lastPingCheck = 0;
|
||||||
uint64_t lastClean = Utils::now(); // don't need to do this immediately
|
uint64_t lastClean = Utils::now(); // don't need to do this immediately
|
||||||
uint64_t lastNetworkFingerprintCheck = 0;
|
uint64_t lastNetworkFingerprintCheck = 0;
|
||||||
|
@ -78,13 +78,15 @@ NodeConfig::NodeConfig(const RuntimeEnvironment *renv,const char *authToken,unsi
|
|||||||
if (dot != std::string::npos) {
|
if (dot != std::string::npos) {
|
||||||
uint64_t nwid = strtoull(d->first.substr(0,dot).c_str(),(char **)0,16);
|
uint64_t nwid = strtoull(d->first.substr(0,dot).c_str(),(char **)0,16);
|
||||||
|
|
||||||
// TODO: remove legacy code -- this changes the network
|
// TODO: remove legacy code once out of beta
|
||||||
// ID for Earth if it's subscribed. Also deletes old
|
|
||||||
// config file. New one will be created.
|
|
||||||
if (nwid == 0x6c92786fee000001ULL) {
|
if (nwid == 0x6c92786fee000001ULL) {
|
||||||
nwid = 0xbc8f9a8ee3000001ULL;
|
nwid = 0xbc8f9a8ee3000001ULL;
|
||||||
Utils::rm((networksFolder + ZT_PATH_SEPARATOR_S + d->first).c_str());
|
Utils::rm((networksFolder + ZT_PATH_SEPARATOR_S + d->first).c_str());
|
||||||
}
|
}
|
||||||
|
if (nwid == 0xbc8f9a8ee3000001ULL) {
|
||||||
|
nwid = 0x8D93FBE886000001ULL;
|
||||||
|
Utils::rm((networksFolder + ZT_PATH_SEPARATOR_S + d->first).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
if (nwid > 0)
|
if (nwid > 0)
|
||||||
nwids.insert(nwid);
|
nwids.insert(nwid);
|
||||||
|
Loading…
Reference in New Issue
Block a user