OSUtils.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  4. *
  5. * (c) ZeroTier, Inc.
  6. * https://www.zerotier.com/
  7. */
  8. #include "../node/Constants.hpp"
  9. #include "../node/Utils.hpp"
  10. #include <cstddef>
  11. #include <inttypes.h>
  12. #include <stdarg.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <sys/stat.h>
  17. #ifdef __UNIX_LIKE__
  18. #include <dirent.h>
  19. #include <errno.h>
  20. #include <fcntl.h>
  21. #include <netdb.h>
  22. #include <sys/socket.h>
  23. #include <sys/stat.h>
  24. #include <sys/types.h>
  25. #include <sys/uio.h>
  26. #include <unistd.h>
  27. #endif
  28. #ifdef __WINDOWS__
  29. #include <iphlpapi.h>
  30. #include <netioapi.h>
  31. #include <shlobj.h>
  32. #include <wincrypt.h>
  33. #include <windows.h>
  34. #endif
  35. #include "OSUtils.hpp"
  36. #ifdef __GCC__
  37. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  38. #endif
  39. namespace ZeroTier {
  40. unsigned int OSUtils::ztsnprintf(char* buf, unsigned int len, const char* fmt, ...)
  41. {
  42. va_list ap;
  43. va_start(ap, fmt);
  44. int n = (int)vsnprintf(buf, len, fmt, ap);
  45. va_end(ap);
  46. if ((n >= (int)len) || (n < 0)) {
  47. if (len)
  48. buf[len - 1] = (char)0;
  49. throw std::length_error("buf[] overflow");
  50. }
  51. return (unsigned int)n;
  52. }
  53. std::string OSUtils::networkIDStr(const uint64_t nwid)
  54. {
  55. char tmp[32] = {};
  56. ztsnprintf(tmp, sizeof(tmp), "%.16" PRIx64, nwid);
  57. return std::string(tmp);
  58. }
  59. std::string OSUtils::nodeIDStr(const uint64_t nid)
  60. {
  61. char tmp[32] = {};
  62. ztsnprintf(tmp, sizeof(tmp), "%.10" PRIx64, nid);
  63. return std::string(tmp);
  64. }
  65. #ifdef __UNIX_LIKE__
  66. bool OSUtils::redirectUnixOutputs(const char* stdoutPath, const char* stderrPath) throw()
  67. {
  68. int fdout = ::open(stdoutPath, O_WRONLY | O_CREAT, 0600);
  69. if (fdout > 0) {
  70. int fderr;
  71. if (stderrPath) {
  72. fderr = ::open(stderrPath, O_WRONLY | O_CREAT, 0600);
  73. if (fderr <= 0) {
  74. ::close(fdout);
  75. return false;
  76. }
  77. }
  78. else
  79. fderr = fdout;
  80. ::close(STDOUT_FILENO);
  81. ::close(STDERR_FILENO);
  82. ::dup2(fdout, STDOUT_FILENO);
  83. ::dup2(fderr, STDERR_FILENO);
  84. return true;
  85. }
  86. return false;
  87. }
  88. #endif // __UNIX_LIKE__
  89. std::vector<std::string> OSUtils::listDirectory(const char* path, bool includeDirectories)
  90. {
  91. std::vector<std::string> r;
  92. #ifdef __WINDOWS__
  93. HANDLE hFind;
  94. WIN32_FIND_DATAA ffd;
  95. if ((hFind = FindFirstFileA((std::string(path) + "\\*").c_str(), &ffd)) != INVALID_HANDLE_VALUE) {
  96. do {
  97. if ((strcmp(ffd.cFileName, ".")) && (strcmp(ffd.cFileName, ".."))
  98. && (((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
  99. || (((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) && (includeDirectories))))
  100. r.push_back(std::string(ffd.cFileName));
  101. } while (FindNextFileA(hFind, &ffd));
  102. FindClose(hFind);
  103. }
  104. #else
  105. struct dirent de;
  106. struct dirent* dptr;
  107. DIR* d = opendir(path);
  108. if (! d)
  109. return r;
  110. dptr = (struct dirent*)0;
  111. for (;;) {
  112. if (readdir_r(d, &de, &dptr))
  113. break;
  114. if (dptr) {
  115. if ((strcmp(dptr->d_name, ".")) && (strcmp(dptr->d_name, ".."))
  116. && ((dptr->d_type != DT_DIR) || (includeDirectories)))
  117. r.push_back(std::string(dptr->d_name));
  118. }
  119. else
  120. break;
  121. }
  122. closedir(d);
  123. #endif
  124. return r;
  125. }
  126. long OSUtils::cleanDirectory(const char* path, const int64_t olderThan)
  127. {
  128. long cleaned = 0;
  129. #ifdef __WINDOWS__
  130. HANDLE hFind;
  131. WIN32_FIND_DATAA ffd;
  132. LARGE_INTEGER date, adjust;
  133. adjust.QuadPart = 11644473600000 * 10000;
  134. char tmp[4096];
  135. if ((hFind = FindFirstFileA((std::string(path) + "\\*").c_str(), &ffd)) != INVALID_HANDLE_VALUE) {
  136. do {
  137. if ((strcmp(ffd.cFileName, ".")) && (strcmp(ffd.cFileName, ".."))
  138. && ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)) {
  139. date.HighPart = ffd.ftLastWriteTime.dwHighDateTime;
  140. date.LowPart = ffd.ftLastWriteTime.dwLowDateTime;
  141. if (date.QuadPart > 0) {
  142. date.QuadPart -= adjust.QuadPart;
  143. if ((int64_t)((date.QuadPart / 10000000) * 1000) < olderThan) {
  144. ztsnprintf(tmp, sizeof(tmp), "%s\\%s", path, ffd.cFileName);
  145. if (DeleteFileA(tmp))
  146. ++cleaned;
  147. }
  148. }
  149. }
  150. } while (FindNextFileA(hFind, &ffd));
  151. FindClose(hFind);
  152. }
  153. #else
  154. struct dirent de;
  155. struct dirent* dptr;
  156. struct stat st;
  157. char tmp[4096];
  158. DIR* d = opendir(path);
  159. if (! d)
  160. return -1;
  161. dptr = (struct dirent*)0;
  162. for (;;) {
  163. if (readdir_r(d, &de, &dptr))
  164. break;
  165. if (dptr) {
  166. if ((strcmp(dptr->d_name, ".")) && (strcmp(dptr->d_name, "..")) && (dptr->d_type == DT_REG)) {
  167. ztsnprintf(tmp, sizeof(tmp), "%s/%s", path, dptr->d_name);
  168. if (stat(tmp, &st) == 0) {
  169. int64_t mt = (int64_t)(st.st_mtime);
  170. if ((mt > 0) && ((mt * 1000) < olderThan)) {
  171. if (unlink(tmp) == 0)
  172. ++cleaned;
  173. }
  174. }
  175. }
  176. }
  177. else
  178. break;
  179. }
  180. closedir(d);
  181. #endif
  182. return cleaned;
  183. }
  184. bool OSUtils::rmDashRf(const char* path)
  185. {
  186. #ifdef __WINDOWS__
  187. HANDLE hFind;
  188. WIN32_FIND_DATAA ffd;
  189. if ((hFind = FindFirstFileA((std::string(path) + "\\*").c_str(), &ffd)) != INVALID_HANDLE_VALUE) {
  190. do {
  191. if ((strcmp(ffd.cFileName, ".") != 0) && (strcmp(ffd.cFileName, "..") != 0)) {
  192. if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
  193. if (DeleteFileA((std::string(path) + ZT_PATH_SEPARATOR_S + ffd.cFileName).c_str()) == FALSE)
  194. return false;
  195. }
  196. else {
  197. if (! rmDashRf((std::string(path) + ZT_PATH_SEPARATOR_S + ffd.cFileName).c_str()))
  198. return false;
  199. }
  200. }
  201. } while (FindNextFileA(hFind, &ffd));
  202. FindClose(hFind);
  203. }
  204. return (RemoveDirectoryA(path) != FALSE);
  205. #else
  206. struct dirent de;
  207. struct dirent* dptr;
  208. DIR* d = opendir(path);
  209. if (! d)
  210. return true;
  211. dptr = (struct dirent*)0;
  212. for (;;) {
  213. if (readdir_r(d, &de, &dptr) != 0)
  214. break;
  215. if (! dptr)
  216. break;
  217. if ((strcmp(dptr->d_name, ".") != 0) && (strcmp(dptr->d_name, "..") != 0) && (strlen(dptr->d_name) > 0)) {
  218. std::string p(path);
  219. p.push_back(ZT_PATH_SEPARATOR);
  220. p.append(dptr->d_name);
  221. if (unlink(p.c_str()) != 0) { // unlink first will remove symlinks instead of recursing them
  222. if (! rmDashRf(p.c_str()))
  223. return false;
  224. }
  225. }
  226. }
  227. closedir(d);
  228. return (rmdir(path) == 0);
  229. #endif
  230. }
  231. void OSUtils::lockDownFile(const char* path, bool isDir)
  232. {
  233. #ifdef __UNIX_LIKE__
  234. chmod(path, isDir ? 0700 : 0600);
  235. #else
  236. #ifdef __WINDOWS__
  237. {
  238. STARTUPINFOA startupInfo;
  239. PROCESS_INFORMATION processInfo;
  240. startupInfo.cb = sizeof(startupInfo);
  241. memset(&startupInfo, 0, sizeof(STARTUPINFOA));
  242. memset(&processInfo, 0, sizeof(PROCESS_INFORMATION));
  243. if (CreateProcessA(
  244. NULL,
  245. (LPSTR)(std::string("C:\\Windows\\System32\\icacls.exe \"") + path + "\" /inheritance:d /Q").c_str(),
  246. NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &startupInfo, &processInfo)) {
  247. WaitForSingleObject(processInfo.hProcess, INFINITE);
  248. CloseHandle(processInfo.hProcess);
  249. CloseHandle(processInfo.hThread);
  250. }
  251. startupInfo.cb = sizeof(startupInfo);
  252. memset(&startupInfo, 0, sizeof(STARTUPINFOA));
  253. memset(&processInfo, 0, sizeof(PROCESS_INFORMATION));
  254. if (CreateProcessA(
  255. NULL,
  256. (LPSTR)(std::string("C:\\Windows\\System32\\icacls.exe \"") + path + "\" /remove *S-1-5-32-545 /Q")
  257. .c_str(),
  258. NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &startupInfo, &processInfo)) {
  259. WaitForSingleObject(processInfo.hProcess, INFINITE);
  260. CloseHandle(processInfo.hProcess);
  261. CloseHandle(processInfo.hThread);
  262. }
  263. // Remove 'Everyone' group from R/RX access
  264. startupInfo.cb = sizeof(startupInfo);
  265. memset(&startupInfo, 0, sizeof(STARTUPINFOA));
  266. memset(&processInfo, 0, sizeof(PROCESS_INFORMATION));
  267. if (CreateProcessA(
  268. NULL,
  269. (LPSTR)(std::string("C:\\Windows\\System32\\icacls.exe \"") + path + "\" /remove:g Everyone /t /c /Q")
  270. .c_str(),
  271. NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &startupInfo, &processInfo)) {
  272. WaitForSingleObject(processInfo.hProcess, INFINITE);
  273. CloseHandle(processInfo.hProcess);
  274. CloseHandle(processInfo.hThread);
  275. }
  276. }
  277. #endif
  278. #endif
  279. }
  280. uint64_t OSUtils::getLastModified(const char* path)
  281. {
  282. struct stat s;
  283. if (stat(path, &s))
  284. return 0;
  285. return (((uint64_t)s.st_mtime) * 1000ULL);
  286. }
  287. bool OSUtils::fileExists(const char* path, bool followLinks)
  288. {
  289. struct stat s;
  290. #ifdef __UNIX_LIKE__
  291. if (! followLinks)
  292. return (lstat(path, &s) == 0);
  293. #endif
  294. return (stat(path, &s) == 0);
  295. }
  296. int64_t OSUtils::getFileSize(const char* path)
  297. {
  298. struct stat s;
  299. if (stat(path, &s))
  300. return -1;
  301. #ifdef __WINDOWS__
  302. return s.st_size;
  303. #else
  304. if (S_ISREG(s.st_mode))
  305. return s.st_size;
  306. #endif
  307. return -1;
  308. }
  309. bool OSUtils::readFile(const char* path, std::string& buf)
  310. {
  311. char tmp[16384];
  312. FILE* f = fopen(path, "rb");
  313. if (f) {
  314. for (;;) {
  315. long n = (long)fread(tmp, 1, sizeof(tmp), f);
  316. if (n > 0)
  317. buf.append(tmp, n);
  318. else
  319. break;
  320. }
  321. fclose(f);
  322. return true;
  323. }
  324. return false;
  325. }
  326. bool OSUtils::writeFile(const char* path, const void* buf, unsigned int len)
  327. {
  328. FILE* f = fopen(path, "wb");
  329. if (f) {
  330. if ((long)fwrite(buf, 1, len, f) != (long)len) {
  331. fclose(f);
  332. return false;
  333. }
  334. else {
  335. fclose(f);
  336. return true;
  337. }
  338. }
  339. return false;
  340. }
  341. std::vector<std::string> OSUtils::split(const char* s, const char* const sep, const char* esc, const char* quot)
  342. {
  343. std::vector<std::string> fields;
  344. std::string buf;
  345. if (! esc)
  346. esc = "";
  347. if (! quot)
  348. quot = "";
  349. bool escapeState = false;
  350. char quoteState = 0;
  351. while (*s) {
  352. if (escapeState) {
  353. escapeState = false;
  354. buf.push_back(*s);
  355. }
  356. else if (quoteState) {
  357. if (*s == quoteState) {
  358. quoteState = 0;
  359. fields.push_back(buf);
  360. buf.clear();
  361. }
  362. else
  363. buf.push_back(*s);
  364. }
  365. else {
  366. const char* quotTmp;
  367. if (strchr(esc, *s))
  368. escapeState = true;
  369. else if ((buf.size() <= 0) && ((quotTmp = strchr(quot, *s))))
  370. quoteState = *quotTmp;
  371. else if (strchr(sep, *s)) {
  372. if (! buf.empty()) {
  373. fields.push_back(buf);
  374. buf.clear();
  375. } // else skip runs of separators
  376. }
  377. else
  378. buf.push_back(*s);
  379. }
  380. ++s;
  381. }
  382. if (buf.size())
  383. fields.push_back(buf);
  384. return fields;
  385. }
  386. std::string OSUtils::platformDefaultHomePath()
  387. {
  388. #ifdef __QNAP__
  389. char* cmd = "/sbin/getcfg zerotier Install_Path -f /etc/config/qpkg.conf";
  390. char buf[128];
  391. FILE* fp;
  392. if ((fp = popen(cmd, "r")) == NULL) {
  393. printf("Error opening pipe!\n");
  394. return NULL;
  395. }
  396. while (fgets(buf, 128, fp) != NULL) {}
  397. if (pclose(fp)) {
  398. printf("Command not found or exited with error status\n");
  399. return NULL;
  400. }
  401. std::string homeDir = std::string(buf);
  402. homeDir.erase(std::remove(homeDir.begin(), homeDir.end(), '\n'), homeDir.end());
  403. return homeDir;
  404. #endif
  405. #ifdef __UBIQUITI__
  406. // Only persistent location after firmware upgrades
  407. return std::string("/config/zerotier-one");
  408. #endif
  409. // Check for user-defined environment variable before using defaults
  410. #ifdef __WINDOWS__
  411. DWORD bufferSize = 65535;
  412. std::string userDefinedPath;
  413. bufferSize = GetEnvironmentVariable("ZEROTIER_HOME", &userDefinedPath[0], bufferSize);
  414. if (bufferSize) {
  415. return userDefinedPath;
  416. }
  417. #else
  418. if (const char* userDefinedPath = getenv("ZEROTIER_HOME")) {
  419. return std::string(userDefinedPath);
  420. }
  421. #endif
  422. // Finally, resort to using default paths if no user-defined path was provided
  423. #ifdef __UNIX_LIKE__
  424. #ifdef __APPLE__
  425. // /Library/... on Apple
  426. return std::string("/Library/Application Support/ZeroTier/One");
  427. #else
  428. #ifdef __BSD__
  429. // BSD likes /var/db instead of /var/lib
  430. return std::string("/var/db/zerotier-one");
  431. #else
  432. // Use /var/lib for Linux and other *nix
  433. return std::string("/var/lib/zerotier-one");
  434. #endif
  435. #endif
  436. #else // not __UNIX_LIKE__
  437. #ifdef __WINDOWS__
  438. // Look up app data folder on Windows, e.g. C:\ProgramData\...
  439. char buf[16384];
  440. if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_COMMON_APPDATA, NULL, 0, buf)))
  441. return (std::string(buf) + "\\ZeroTier\\One");
  442. else
  443. return std::string("C:\\ZeroTier\\One");
  444. #else
  445. return (std::string(ZT_PATH_SEPARATOR_S) + "ZeroTier" + ZT_PATH_SEPARATOR_S + "One"); // UNKNOWN PLATFORM
  446. #endif
  447. #endif // __UNIX_LIKE__ or not...
  448. }
  449. #ifndef OMIT_JSON_SUPPORT
  450. // Inline these massive JSON operations in one place only to reduce binary footprint and compile time
  451. nlohmann::json OSUtils::jsonParse(const std::string& buf)
  452. {
  453. return nlohmann::json::parse(buf.c_str());
  454. }
  455. std::string OSUtils::jsonDump(const nlohmann::json& j, int indentation)
  456. {
  457. return j.dump(indentation);
  458. }
  459. uint64_t OSUtils::jsonInt(const nlohmann::json& jv, const uint64_t dfl)
  460. {
  461. try {
  462. if (jv.is_number()) {
  463. return (uint64_t)jv;
  464. }
  465. else if (jv.is_string()) {
  466. std::string s = jv;
  467. return Utils::strToU64(s.c_str());
  468. }
  469. else if (jv.is_boolean()) {
  470. return ((bool)jv ? 1ULL : 0ULL);
  471. }
  472. }
  473. catch (...) {
  474. }
  475. return dfl;
  476. }
  477. int64_t OSUtils::jsonUInt(const nlohmann::json& jv, const int64_t dfl)
  478. {
  479. try {
  480. if (jv.is_number()) {
  481. return (int64_t)jv;
  482. }
  483. else if (jv.is_string()) {
  484. std::string s = jv;
  485. return Utils::strTo64(s.c_str());
  486. }
  487. else if (jv.is_boolean()) {
  488. return ((bool)jv ? 1LL : 0LL);
  489. }
  490. }
  491. catch (...) {
  492. }
  493. return dfl;
  494. }
  495. double OSUtils::jsonDouble(const nlohmann::json& jv, const double dfl)
  496. {
  497. try {
  498. if (jv.is_number()) {
  499. return (double)jv;
  500. }
  501. else if (jv.is_string()) {
  502. std::string s = jv;
  503. return Utils::strToDouble(s.c_str());
  504. }
  505. else if (jv.is_boolean()) {
  506. return (double)jv;
  507. }
  508. }
  509. catch (...) {
  510. }
  511. return dfl;
  512. }
  513. uint64_t OSUtils::jsonIntHex(const nlohmann::json& jv, const uint64_t dfl)
  514. {
  515. try {
  516. if (jv.is_number()) {
  517. return (uint64_t)jv;
  518. }
  519. else if (jv.is_string()) {
  520. std::string s = jv;
  521. return Utils::hexStrToU64(s.c_str());
  522. }
  523. else if (jv.is_boolean()) {
  524. return ((bool)jv ? 1ULL : 0ULL);
  525. }
  526. }
  527. catch (...) {
  528. }
  529. return dfl;
  530. }
  531. bool OSUtils::jsonBool(const nlohmann::json& jv, const bool dfl)
  532. {
  533. try {
  534. if (jv.is_boolean()) {
  535. return (bool)jv;
  536. }
  537. else if (jv.is_number()) {
  538. return ((uint64_t)jv > 0ULL);
  539. }
  540. else if (jv.is_string()) {
  541. std::string s = jv;
  542. if (s.length() > 0) {
  543. switch (s[0]) {
  544. case 't':
  545. case 'T':
  546. case '1':
  547. return true;
  548. }
  549. }
  550. return false;
  551. }
  552. }
  553. catch (...) {
  554. }
  555. return dfl;
  556. }
  557. std::string OSUtils::jsonString(const nlohmann::json& jv, const char* dfl)
  558. {
  559. try {
  560. if (jv.is_string()) {
  561. return jv;
  562. }
  563. else if (jv.is_number()) {
  564. char tmp[64];
  565. ztsnprintf(tmp, sizeof(tmp), "%llu", (uint64_t)jv);
  566. return tmp;
  567. }
  568. else if (jv.is_boolean()) {
  569. return ((bool)jv ? std::string("1") : std::string("0"));
  570. }
  571. }
  572. catch (...) {
  573. }
  574. return std::string((dfl) ? dfl : "");
  575. }
  576. std::string OSUtils::jsonBinFromHex(const nlohmann::json& jv)
  577. {
  578. std::string s(jsonString(jv, ""));
  579. if (s.length() > 0) {
  580. unsigned int buflen = (unsigned int)((s.length() / 2) + 1);
  581. char* buf = new char[buflen];
  582. try {
  583. unsigned int l = Utils::unhex(s.c_str(), buf, buflen);
  584. std::string b(buf, l);
  585. delete[] buf;
  586. return b;
  587. }
  588. catch (...) {
  589. delete[] buf;
  590. }
  591. }
  592. return std::string();
  593. }
  594. #endif // OMIT_JSON_SUPPORT
  595. // Used to convert HTTP header names to ASCII lower case
  596. const unsigned char OSUtils::TOLOWER_TABLE[256] = {
  597. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
  598. 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, ' ', '!', '"', '#', '$', '%',
  599. '&', 0x27, '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8',
  600. '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
  601. 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~',
  602. '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  603. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84,
  604. 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  605. 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa,
  606. 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd,
  607. 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0,
  608. 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
  609. 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6,
  610. 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
  611. };
  612. } // namespace ZeroTier