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