From 430edf9c6e6c4bc983e90e65bcbac5063f06c8e4 Mon Sep 17 00:00:00 2001 From: "DESKTOP-MARKXU\\xubia" Date: Wed, 10 Nov 2021 00:08:51 +0800 Subject: [PATCH] init --- .idea/.gitignore | 8 ++ .idea/docker-zerotier-planet.iml | 8 ++ .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 4 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + Dockerfile | 42 +++++++ mkworld.cpp | 119 ++++++++++++++++++ patch.json | 5 + patch.py | 51 ++++++++ run.sh | 3 + 11 files changed, 260 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/docker-zerotier-planet.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Dockerfile create mode 100644 mkworld.cpp create mode 100644 patch.json create mode 100644 patch.py create mode 100644 run.sh diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/docker-zerotier-planet.iml b/.idea/docker-zerotier-planet.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/docker-zerotier-planet.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d1e22ec --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..afea342 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..515489e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +FROM centos:7 + +WORKDIR /opt +COPY . /var/lib/zerotier-one/ +VOLUME ["/opt","/var/lib/zerotier-one"] +EXPOSE 9993 + +RUN curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo && \ + yum update -y && \ + yum install git make gcc gcc-c++ python3 wget -y && \ + yum install centos-release-scl -y &&\ + yum install devtoolset-8 -y &&\ + + # 编译服务 + cd /opt && \ + git clone https://github.com.cnpmjs.org/zerotier/ZeroTierOne.git && \ + cd ZeroTierOne && \ + make && \ + make install && \ + + # 配置moon + cd /var/lib/zerotier-one && \ + zerotier-idtool generate identity.public identity.secret &&\ + zerotier-idtool initmoon identity.public >> moon.json &&\ + + # 配置补丁 + cd /var/lib/zerotier-one && \ + python3 patch.py && \ + zerotier-idtool genmoon moon.json && \ + mkdir moons.d && cp ./*.moon ./moons.d &&\ + rm -rf planet &&\ + + # 编译新的plane + cd /opt/ZeroTierOne/attic/world/ && \ + sh build.sh &&\ + mv world.bin /var/lib/zerotier-one/planet + +CMD [ "bash","run.sh" ] + + + + diff --git a/mkworld.cpp b/mkworld.cpp new file mode 100644 index 0000000..49181a7 --- /dev/null +++ b/mkworld.cpp @@ -0,0 +1,119 @@ +/* + * ZeroTier One - Network Virtualization Everywhere + * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* + * This utility makes the World from the configuration specified below. + * It probably won't be much use to anyone outside ZeroTier, Inc. except + * for testing and experimentation purposes. + * + * If you want to make your own World you must edit this file. + * + * When run, it expects two files in the current directory: + * + * previous.c25519 - key pair to sign this world (key from previous world) + * current.c25519 - key pair whose public key should be embedded in this world + * + * If these files do not exist, they are both created with the same key pair + * and a self-signed initial World is born. + */ + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace ZeroTier; + +int main(int argc,char **argv) +{ + std::string previous,current; + if ((!OSUtils::readFile("previous.c25519",previous))||(!OSUtils::readFile("current.c25519",current))) { + C25519::Pair np(C25519::generate()); + previous = std::string(); + previous.append((const char *)np.pub.data,ZT_C25519_PUBLIC_KEY_LEN); + previous.append((const char *)np.priv.data,ZT_C25519_PRIVATE_KEY_LEN); + current = previous; + OSUtils::writeFile("previous.c25519",previous); + OSUtils::writeFile("current.c25519",current); + fprintf(stderr,"INFO: created initial world keys: previous.c25519 and current.c25519 (both initially the same)" ZT_EOL_S); + } + + if ((previous.length() != (ZT_C25519_PUBLIC_KEY_LEN + ZT_C25519_PRIVATE_KEY_LEN))||(current.length() != (ZT_C25519_PUBLIC_KEY_LEN + ZT_C25519_PRIVATE_KEY_LEN))) { + fprintf(stderr,"FATAL: previous.c25519 or current.c25519 empty or invalid" ZT_EOL_S); + return 1; + } + C25519::Pair previousKP; + memcpy(previousKP.pub.data,previous.data(),ZT_C25519_PUBLIC_KEY_LEN); + memcpy(previousKP.priv.data,previous.data() + ZT_C25519_PUBLIC_KEY_LEN,ZT_C25519_PRIVATE_KEY_LEN); + C25519::Pair currentKP; + memcpy(currentKP.pub.data,current.data(),ZT_C25519_PUBLIC_KEY_LEN); + memcpy(currentKP.priv.data,current.data() + ZT_C25519_PUBLIC_KEY_LEN,ZT_C25519_PRIVATE_KEY_LEN); + + // ========================================================================= + // EDIT BELOW HERE + + std::vector roots; + + const uint64_t id = ZT_WORLD_ID_EARTH; + const uint64_t ts = 1567191349589ULL; // August 30th, 2019 + + //__PATCH_REPLACE__ + + // END WORLD DEFINITION + // ========================================================================= + + fprintf(stderr,"INFO: generating and signing id==%llu ts==%llu" ZT_EOL_S,(unsigned long long)id,(unsigned long long)ts); + + World nw = World::make(World::TYPE_PLANET,id,ts,currentKP.pub,roots,previousKP); + + Buffer outtmp; + nw.serialize(outtmp,false); + World testw; + testw.deserialize(outtmp,0); + if (testw != nw) { + fprintf(stderr,"FATAL: serialization test failed!" ZT_EOL_S); + return 1; + } + + OSUtils::writeFile("world.bin",std::string((const char *)outtmp.data(),outtmp.size())); + fprintf(stderr,"INFO: world.bin written with %u bytes of binary world data." ZT_EOL_S,outtmp.size()); + + fprintf(stdout,ZT_EOL_S); + fprintf(stdout,"#define ZT_DEFAULT_WORLD_LENGTH %u" ZT_EOL_S,outtmp.size()); + fprintf(stdout,"static const unsigned char ZT_DEFAULT_WORLD[ZT_DEFAULT_WORLD_LENGTH] = {"); + for(unsigned int i=0;i 0) + fprintf(stdout,","); + fprintf(stdout,"0x%.2x",(unsigned int)d[i]); + } + fprintf(stdout,"};" ZT_EOL_S); + + return 0; +} \ No newline at end of file diff --git a/patch.json b/patch.json new file mode 100644 index 0000000..e8e3815 --- /dev/null +++ b/patch.json @@ -0,0 +1,5 @@ +{ + "stableEndpoints": [ + "81.70.255.9/9993" + ] +} \ No newline at end of file diff --git a/patch.py b/patch.py new file mode 100644 index 0000000..f171fb4 --- /dev/null +++ b/patch.py @@ -0,0 +1,51 @@ +import os +import json + + +def patch_moon(): + patch_data = dict() + with open("patch.json", "r") as f: + patch_data = json.load(f) + + moon = dict() + with open("moon.json", "r") as f: + moon = json.load(f) + + endpoint_patch = patch_data.get("stableEndpoints", []) + if len(endpoint_patch) == 0: + print("请配置endpoint!") + exit(1) + + moon["roots"][0]["stableEndpoints"] = endpoint_patch + + with open("moon.json", "w+") as f: + f.write(json.dumps(moon)) + + +def patch_world(): + moon = dict() + + file_moon = open("moon.json", "r") + moon = json.load(file_moon) + file_moon.close() + + middle = ''' + //China + roots.push_back(World::Root()); + roots.back().identity = Identity("{}");'''.format(moon["roots"][0]["identity"]) + + for i in moon["roots"][0]["stableEndpoints"]: + middle += '\n roots.back().stableEndpoints.push_back(InetAddress("{}"));'.format(i) + + with open("mkworld.cpp", "r") as cpp: + code = "".join(cpp.readlines()) + + with open("mknewworld.cpp", "w+") as cpp: + code = code.replace(" //__PATCH_REPLACE__", middle) + print(code) + cpp.write(code) + + +if __name__ == '__main__': + patch_moon() + patch_world() diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..4456f7c --- /dev/null +++ b/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash +zerotier-cli -d +cd /opt/ztncui/src && npm start \ No newline at end of file