summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--attic/world/README.md (renamed from world/README.md)0
-rwxr-xr-xattic/world/build.sh (renamed from world/build.sh)0
-rw-r--r--attic/world/earth-2016-01-13.bin (renamed from world/earth-2016-01-13.bin)bin634 -> 634 bytes
-rw-r--r--attic/world/mkworld.cpp (renamed from world/mkworld.cpp)22
-rw-r--r--attic/world/old/earth-2015-11-16.bin (renamed from world/old/earth-2015-11-16.bin)bin494 -> 494 bytes
-rw-r--r--attic/world/old/earth-2015-11-20.bin (renamed from world/old/earth-2015-11-20.bin)bin792 -> 792 bytes
-rw-r--r--attic/world/old/earth-2015-12-17.bin (renamed from world/old/earth-2015-12-17.bin)bin732 -> 732 bytes
-rw-r--r--node/World.hpp27
-rw-r--r--one.cpp87
9 files changed, 115 insertions, 21 deletions
diff --git a/world/README.md b/attic/world/README.md
index dda4920a..dda4920a 100644
--- a/world/README.md
+++ b/attic/world/README.md
diff --git a/world/build.sh b/attic/world/build.sh
index b783702c..b783702c 100755
--- a/world/build.sh
+++ b/attic/world/build.sh
diff --git a/world/earth-2016-01-13.bin b/attic/world/earth-2016-01-13.bin
index 5dea4d21..5dea4d21 100644
--- a/world/earth-2016-01-13.bin
+++ b/attic/world/earth-2016-01-13.bin
Binary files differ
diff --git a/world/mkworld.cpp b/attic/world/mkworld.cpp
index 2e9e621f..e0f477b3 100644
--- a/world/mkworld.cpp
+++ b/attic/world/mkworld.cpp
@@ -50,26 +50,6 @@
using namespace ZeroTier;
-class WorldMaker : public World
-{
-public:
- static inline World make(World::Type t,uint64_t id,uint64_t ts,const C25519::Public &sk,const std::vector<World::Root> &roots,const C25519::Pair &signWith)
- {
- WorldMaker w;
- w._id = id;
- w._ts = ts;
- w._type = t;
- w._updateSigningKey = sk;
- w._roots = roots;
-
- Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> tmp;
- w.serialize(tmp,true);
- w._signature = C25519::sign(signWith,tmp.data(),tmp.size());
-
- return w;
- }
-};
-
int main(int argc,char **argv)
{
std::string previous,current;
@@ -140,7 +120,7 @@ int main(int argc,char **argv)
fprintf(stderr,"INFO: generating and signing id==%llu ts==%llu"ZT_EOL_S,(unsigned long long)id,(unsigned long long)ts);
- World nw = WorldMaker::make(World::TYPE_PLANET,id,ts,currentKP.pub,roots,previousKP);
+ World nw = World::make(World::TYPE_PLANET,id,ts,currentKP.pub,roots,previousKP);
Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> outtmp;
nw.serialize(outtmp,false);
diff --git a/world/old/earth-2015-11-16.bin b/attic/world/old/earth-2015-11-16.bin
index 910ff144..910ff144 100644
--- a/world/old/earth-2015-11-16.bin
+++ b/attic/world/old/earth-2015-11-16.bin
Binary files differ
diff --git a/world/old/earth-2015-11-20.bin b/attic/world/old/earth-2015-11-20.bin
index 198682e5..198682e5 100644
--- a/world/old/earth-2015-11-20.bin
+++ b/attic/world/old/earth-2015-11-20.bin
Binary files differ
diff --git a/world/old/earth-2015-12-17.bin b/attic/world/old/earth-2015-12-17.bin
index 20fadb56..20fadb56 100644
--- a/world/old/earth-2015-12-17.bin
+++ b/attic/world/old/earth-2015-12-17.bin
Binary files differ
diff --git a/node/World.hpp b/node/World.hpp
index 06dcb981..8fe6dd2e 100644
--- a/node/World.hpp
+++ b/node/World.hpp
@@ -227,6 +227,33 @@ public:
inline bool operator<(const World &w) const { return (((int)_type < (int)w._type) ? true : ((_type == w._type) ? (_id < w._id) : false)); }
+ /**
+ * Create a World object signed with a key pair
+ *
+ * @param t World type
+ * @param id World ID
+ * @param ts World timestamp / revision
+ * @param sk Key that must be used to sign the next future update to this world
+ * @param roots Roots and their stable endpoints
+ * @param signWith Key to sign this World with (can have the same public as the next-update signing key, but doesn't have to)
+ * @return Signed World object
+ */
+ static inline World make(World::Type t,uint64_t id,uint64_t ts,const C25519::Public &sk,const std::vector<World::Root> &roots,const C25519::Pair &signWith)
+ {
+ World w;
+ w._id = id;
+ w._ts = ts;
+ w._type = t;
+ w._updatesMustBeSignedBy = sk;
+ w._roots = roots;
+
+ Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> tmp;
+ w.serialize(tmp,true);
+ w._signature = C25519::sign(signWith,tmp.data(),tmp.size());
+
+ return w;
+ }
+
protected:
uint64_t _id;
uint64_t _ts;
diff --git a/one.cpp b/one.cpp
index 016aab74..37ea13d3 100644
--- a/one.cpp
+++ b/one.cpp
@@ -62,6 +62,8 @@
#include "node/CertificateOfMembership.hpp"
#include "node/Utils.hpp"
#include "node/NetworkController.hpp"
+#include "node/Buffer.hpp"
+#include "node/World.hpp"
#include "osdep/OSUtils.hpp"
#include "osdep/Http.hpp"
@@ -545,6 +547,8 @@ static void idtoolPrintHelp(FILE *out,const char *pn)
fprintf(out," getpublic <identity.secret>" ZT_EOL_S);
fprintf(out," sign <identity.secret> <file>" ZT_EOL_S);
fprintf(out," verify <identity.secret/public> <file> <signature>" ZT_EOL_S);
+ fprintf(out," initmoon <identity.public of primary root>" ZT_EOL_S);
+ fprintf(out," genmoon <moon json>" ZT_EOL_S);
}
static Identity getIdFromArg(char *arg)
@@ -689,6 +693,89 @@ static int idtool(int argc,char **argv)
fprintf(stderr,"%s signature check FAILED" ZT_EOL_S,argv[3]);
return 1;
}
+ } else if (!strcmp(argv[1],"initmoon")) {
+ if (argc < 3) {
+ idtoolPrintHelp(stdout,argv[0]);
+ } else {
+ const Identity id = getIdFromArg(argv[2]);
+ if (!id) {
+ fprintf(stderr,"%s is not a valid identity" ZT_EOL_S,argv[2]);
+ return 1;
+ }
+
+ C25519::Pair kp(C25519::generate());
+
+ nlohmann::json mj;
+ 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");
+ nlohmann::json seedj;
+ seedj["identity"] = id.toString(false);
+ seedj["stableEndpoints"] = nlohmann::json::array();
+ (mj["roots"] = nlohmann::json::array()).push_back(seedj);
+ std::string mjd(OSUtils::jsonDump(mj));
+
+ printf("%s" ZT_EOL_S,mjd.c_str());
+ }
+ } else if (!strcmp(argv[1],"genmoon")) {
+ if (argc < 3) {
+ idtoolPrintHelp(stdout,argv[0]);
+ } else {
+ std::string buf;
+ if (!OSUtils::readFile(argv[2],buf)) {
+ fprintf(stderr,"cannot read %s" ZT_EOL_S,argv[2]);
+ return 1;
+ }
+ nlohmann::json mj(OSUtils::jsonParse(buf));
+
+ uint64_t id = Utils::hexStrToU64(OSUtils::jsonString(mj["id"],"").c_str());
+
+ World::Type t;
+ if (mj["worldType"] == "moon") {
+ t = World::TYPE_MOON;
+ } else if (mj["worldType"] == "planet") {
+ t = World::TYPE_PLANET;
+ } else {
+ fprintf(stderr,"invalid worldType" ZT_EOL_S);
+ return 1;
+ }
+
+ 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());
+
+ std::vector<World::Root> roots;
+ nlohmann::json &rootsj = mj["roots"];
+ if (rootsj.is_array()) {
+ for(unsigned long i=0;i<(unsigned long)rootsj.size();++i) {
+ nlohmann::json &r = rootsj[i];
+ if (r.is_object()) {
+ roots.push_back(World::Root());
+ roots.back().identity = Identity(OSUtils::jsonString(r["identity"],""));
+ nlohmann::json &stableEndpointsj = r["stableEndpoints"];
+ if (stableEndpointsj.is_array()) {
+ for(unsigned long k=0;k<(unsigned long)stableEndpointsj.size();++k)
+ roots.back().stableEndpoints.push_back(InetAddress(OSUtils::jsonString(stableEndpointsj[k],"")));
+ std::sort(roots.back().stableEndpoints.begin(),roots.back().stableEndpoints.end());
+ }
+ }
+ }
+ }
+ std::sort(roots.begin(),roots.end());
+
+ const uint64_t now = OSUtils::now();
+ World w(World::make(t,id,now,updatesMustBeSignedBy,roots,signingKey));
+ Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> wbuf;
+ w.serialize(wbuf);
+ char fn[128];
+ Utils::snprintf(fn,sizeof(fn),"%.16llx_%.16llx.moon",w.id(),now);
+ OSUtils::writeFile(fn,wbuf.data(),wbuf.size());
+ printf("wrote %s (signed world with timestamp %llu)" ZT_EOL_S,fn,now);
+ }
} else {
idtoolPrintHelp(stdout,argv[0]);
return 1;