From c95bae2d7389fdaff84e6c518f7f0ebbd1b46230 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 13 Feb 2017 10:05:00 -0800 Subject: [PATCH] Small fixes to moon-management code in CLI. --- one.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/one.cpp b/one.cpp index d903f62c0..c4dd6268e 100644 --- a/one.cpp +++ b/one.cpp @@ -547,7 +547,7 @@ static void idtoolPrintHelp(FILE *out,const char *pn) fprintf(out," getpublic " ZT_EOL_S); fprintf(out," sign " ZT_EOL_S); fprintf(out," verify " ZT_EOL_S); - fprintf(out," initmoon " ZT_EOL_S); + fprintf(out," initmoon " ZT_EOL_S); fprintf(out," genmoon " ZT_EOL_S); } @@ -709,8 +709,8 @@ static int idtool(int argc,char **argv) mj["objtype"] = "world"; mj["worldType"] = "moon"; mj["updatesMustBeSignedBy"] = mj["signingKey"] = Utils::hex(kp.pub.data,(unsigned int)kp.pub.size()); - mj["signingKeySECRET"] = Utils::hex(kp.priv.data,(unsigned int)kp.priv.size()); - mj["id"] = (id.address().toString() + "000000"); + mj["updatesMustBeSignedBy_SECRET"] = Utils::hex(kp.priv.data,(unsigned int)kp.priv.size()); + mj["id"] = id.address().toInt(); nlohmann::json seedj; seedj["identity"] = id.toString(false); seedj["stableEndpoints"] = nlohmann::json::array(); @@ -730,7 +730,11 @@ static int idtool(int argc,char **argv) } nlohmann::json mj(OSUtils::jsonParse(buf)); - uint64_t id = Utils::hexStrToU64(OSUtils::jsonString(mj["id"],"").c_str()); + const uint64_t id = OSUtils::jsonInt(mj["id"],0); + if (!id) { + fprintf(stderr,"ID in %s is invalid" ZT_EOL_S,argv[2]); + return 1; + } World::Type t; if (mj["worldType"] == "moon") { @@ -743,10 +747,8 @@ static int idtool(int argc,char **argv) } C25519::Pair signingKey; - C25519::Public updatesMustBeSignedBy; - Utils::unhex(OSUtils::jsonString(mj["singingKey"],""),signingKey.pub.data,(unsigned int)signingKey.pub.size()); - Utils::unhex(OSUtils::jsonString(mj["singingKeySECRET"],""),signingKey.priv.data,(unsigned int)signingKey.priv.size()); - Utils::unhex(OSUtils::jsonString(mj["updatesMustBeSignedBy"],""),updatesMustBeSignedBy.data,(unsigned int)updatesMustBeSignedBy.size()); + Utils::unhex(OSUtils::jsonString(mj["updatesMustBeSignedBy"],""),signingKey.pub.data,(unsigned int)signingKey.pub.size()); + Utils::unhex(OSUtils::jsonString(mj["updatesMustBeSignedBy_SECRET"],""),signingKey.priv.data,(unsigned int)signingKey.priv.size()); std::vector roots; nlohmann::json &rootsj = mj["roots"]; @@ -768,7 +770,7 @@ static int idtool(int argc,char **argv) std::sort(roots.begin(),roots.end()); const uint64_t now = OSUtils::now(); - World w(World::make(t,id,now,updatesMustBeSignedBy,roots,signingKey)); + World w(World::make(t,id,now,signingKey.pub,roots,signingKey)); Buffer wbuf; w.serialize(wbuf); char fn[128];