NetworkConfig.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /*
  2. * Copyright (c)2019 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2025-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. #include <stdint.h>
  14. #include <algorithm>
  15. #include "NetworkConfig.hpp"
  16. namespace ZeroTier {
  17. bool NetworkConfig::toDictionary(Dictionary<ZT_NETWORKCONFIG_DICT_CAPACITY> &d,bool includeLegacy) const
  18. {
  19. Buffer<ZT_NETWORKCONFIG_DICT_CAPACITY> *tmp = new Buffer<ZT_NETWORKCONFIG_DICT_CAPACITY>();
  20. char tmp2[128] = {0};
  21. try {
  22. d.clear();
  23. // Try to put the more human-readable fields first
  24. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_VERSION,(uint64_t)ZT_NETWORKCONFIG_VERSION)) return false;
  25. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_NETWORK_ID,this->networkId)) return false;
  26. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_TIMESTAMP,this->timestamp)) return false;
  27. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_CREDENTIAL_TIME_MAX_DELTA,this->credentialTimeMaxDelta)) return false;
  28. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_REVISION,this->revision)) return false;
  29. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_ISSUED_TO,this->issuedTo.toString(tmp2))) return false;
  30. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_REMOTE_TRACE_TARGET,this->remoteTraceTarget.toString(tmp2))) return false;
  31. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_REMOTE_TRACE_LEVEL,(uint64_t)this->remoteTraceLevel)) return false;
  32. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_FLAGS,this->flags)) return false;
  33. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_LIMIT,(uint64_t)this->multicastLimit)) return false;
  34. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_TYPE,(uint64_t)this->type)) return false;
  35. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_NAME,this->name)) return false;
  36. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_MTU,(uint64_t)this->mtu)) return false;
  37. #ifdef ZT_SUPPORT_OLD_STYLE_NETCONF
  38. if (includeLegacy) {
  39. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_ENABLE_BROADCAST_OLD,this->enableBroadcast())) return false;
  40. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_PRIVATE_OLD,this->isPrivate())) return false;
  41. std::string v4s;
  42. for(unsigned int i=0;i<staticIpCount;++i) {
  43. if (this->staticIps[i].ss_family == AF_INET) {
  44. if (v4s.length() > 0)
  45. v4s.push_back(',');
  46. char buf[64];
  47. v4s.append(this->staticIps[i].toString(buf));
  48. }
  49. }
  50. if (v4s.length() > 0) {
  51. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_IPV4_STATIC_OLD,v4s.c_str())) return false;
  52. }
  53. std::string v6s;
  54. for(unsigned int i=0;i<staticIpCount;++i) {
  55. if (this->staticIps[i].ss_family == AF_INET6) {
  56. if (v6s.length() > 0)
  57. v6s.push_back(',');
  58. char buf[64];
  59. v6s.append(this->staticIps[i].toString(buf));
  60. }
  61. }
  62. if (v6s.length() > 0) {
  63. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_IPV6_STATIC_OLD,v6s.c_str())) return false;
  64. }
  65. std::string ets;
  66. unsigned int et = 0;
  67. ZT_VirtualNetworkRuleType lastrt = ZT_NETWORK_RULE_ACTION_ACCEPT;
  68. for(unsigned int i=0;i<ruleCount;++i) {
  69. ZT_VirtualNetworkRuleType rt = (ZT_VirtualNetworkRuleType)(rules[i].t & 0x7f);
  70. if (rt == ZT_NETWORK_RULE_MATCH_ETHERTYPE) {
  71. et = rules[i].v.etherType;
  72. } else if (rt == ZT_NETWORK_RULE_ACTION_ACCEPT) {
  73. if (((int)lastrt < 32)||(lastrt == ZT_NETWORK_RULE_MATCH_ETHERTYPE)) {
  74. if (ets.length() > 0)
  75. ets.push_back(',');
  76. char tmp2[16] = {0};
  77. ets.append(Utils::hex((uint16_t)et,tmp2));
  78. }
  79. et = 0;
  80. }
  81. lastrt = rt;
  82. }
  83. if (ets.length() > 0) {
  84. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_ALLOWED_ETHERNET_TYPES_OLD,ets.c_str())) return false;
  85. }
  86. if (this->com) {
  87. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_CERTIFICATE_OF_MEMBERSHIP_OLD,this->com.toString().c_str())) return false;
  88. }
  89. std::string ab;
  90. for(unsigned int i=0;i<this->specialistCount;++i) {
  91. if ((this->specialists[i] & ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE) != 0) {
  92. if (ab.length() > 0)
  93. ab.push_back(',');
  94. char tmp2[16] = {0};
  95. ab.append(Address(this->specialists[i]).toString(tmp2));
  96. }
  97. }
  98. if (ab.length() > 0) {
  99. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_ACTIVE_BRIDGES_OLD,ab.c_str())) return false;
  100. }
  101. }
  102. #endif // ZT_SUPPORT_OLD_STYLE_NETCONF
  103. // Then add binary blobs
  104. if (this->com) {
  105. tmp->clear();
  106. this->com.serialize(*tmp);
  107. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_COM,*tmp)) return false;
  108. }
  109. tmp->clear();
  110. for(unsigned int i=0;i<this->capabilityCount;++i)
  111. this->capabilities[i].serialize(*tmp);
  112. if (tmp->size()) {
  113. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_CAPABILITIES,*tmp)) return false;
  114. }
  115. tmp->clear();
  116. for(unsigned int i=0;i<this->tagCount;++i)
  117. this->tags[i].serialize(*tmp);
  118. if (tmp->size()) {
  119. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_TAGS,*tmp)) return false;
  120. }
  121. tmp->clear();
  122. for(unsigned int i=0;i<this->certificateOfOwnershipCount;++i)
  123. this->certificatesOfOwnership[i].serialize(*tmp);
  124. if (tmp->size()) {
  125. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_CERTIFICATES_OF_OWNERSHIP,*tmp)) return false;
  126. }
  127. tmp->clear();
  128. for(unsigned int i=0;i<this->specialistCount;++i)
  129. tmp->append((uint64_t)this->specialists[i]);
  130. if (tmp->size()) {
  131. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_SPECIALISTS,*tmp)) return false;
  132. }
  133. tmp->clear();
  134. for(unsigned int i=0;i<this->routeCount;++i) {
  135. reinterpret_cast<const InetAddress *>(&(this->routes[i].target))->serialize(*tmp);
  136. reinterpret_cast<const InetAddress *>(&(this->routes[i].via))->serialize(*tmp);
  137. tmp->append((uint16_t)this->routes[i].flags);
  138. tmp->append((uint16_t)this->routes[i].metric);
  139. }
  140. if (tmp->size()) {
  141. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_ROUTES,*tmp)) return false;
  142. }
  143. tmp->clear();
  144. for(unsigned int i=0;i<this->staticIpCount;++i)
  145. this->staticIps[i].serialize(*tmp);
  146. if (tmp->size()) {
  147. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_STATIC_IPS,*tmp)) return false;
  148. }
  149. if (this->ruleCount) {
  150. tmp->clear();
  151. Capability::serializeRules(*tmp,rules,ruleCount);
  152. if (tmp->size()) {
  153. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_RULES,*tmp)) return false;
  154. }
  155. }
  156. tmp->clear();
  157. DNS::serializeDNS(*tmp, &dns);
  158. if (tmp->size()) {
  159. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_DNS,*tmp)) return false;
  160. }
  161. if (this->ssoVersion == 0) {
  162. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_SSO_VERSION, this->ssoVersion)) return false;
  163. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_SSO_ENABLED, this->ssoEnabled)) return false;
  164. if (this->ssoEnabled) {
  165. if (this->authenticationURL[0]) {
  166. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_AUTHENTICATION_URL, this->authenticationURL)) return false;
  167. }
  168. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_AUTHENTICATION_EXPIRY_TIME, this->authenticationExpiryTime)) return false;
  169. }
  170. } else if(this->ssoVersion == 1) {
  171. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_SSO_VERSION, this->ssoVersion)) return false;
  172. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_SSO_ENABLED, this->ssoEnabled)) return false;
  173. //if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_AUTHENTICATION_URL, this->authenticationURL)) return false;
  174. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_ISSUER_URL, this->issuerURL)) return false;
  175. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_CENTRAL_ENDPOINT_URL, this->centralAuthURL)) return false;
  176. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_NONCE, this->ssoNonce)) return false;
  177. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_STATE, this->ssoState)) return false;
  178. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_CLIENT_ID, this->ssoClientID)) return false;
  179. if (!d.add(ZT_NETWORKCONFIG_DICT_KEY_SSO_PROVIDER, this->ssoProvider)) return false;
  180. }
  181. delete tmp;
  182. } catch ( ... ) {
  183. delete tmp;
  184. throw;
  185. }
  186. return true;
  187. }
  188. bool NetworkConfig::fromDictionary(const Dictionary<ZT_NETWORKCONFIG_DICT_CAPACITY> &d)
  189. {
  190. static const NetworkConfig NIL_NC;
  191. Buffer<ZT_NETWORKCONFIG_DICT_CAPACITY> *tmp = new Buffer<ZT_NETWORKCONFIG_DICT_CAPACITY>();
  192. try {
  193. *this = NIL_NC;
  194. // Fields that are always present, new or old
  195. this->networkId = d.getUI(ZT_NETWORKCONFIG_DICT_KEY_NETWORK_ID,0);
  196. if (!this->networkId) {
  197. delete tmp;
  198. return false;
  199. }
  200. this->timestamp = d.getUI(ZT_NETWORKCONFIG_DICT_KEY_TIMESTAMP,0);
  201. this->credentialTimeMaxDelta = d.getUI(ZT_NETWORKCONFIG_DICT_KEY_CREDENTIAL_TIME_MAX_DELTA,0);
  202. this->revision = d.getUI(ZT_NETWORKCONFIG_DICT_KEY_REVISION,0);
  203. this->issuedTo = d.getUI(ZT_NETWORKCONFIG_DICT_KEY_ISSUED_TO,0);
  204. if (!this->issuedTo) {
  205. delete tmp;
  206. return false;
  207. }
  208. this->remoteTraceTarget = d.getUI(ZT_NETWORKCONFIG_DICT_KEY_REMOTE_TRACE_TARGET);
  209. this->remoteTraceLevel = (Trace::Level)d.getUI(ZT_NETWORKCONFIG_DICT_KEY_REMOTE_TRACE_LEVEL);
  210. this->multicastLimit = (unsigned int)d.getUI(ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_LIMIT,0);
  211. d.get(ZT_NETWORKCONFIG_DICT_KEY_NAME,this->name,sizeof(this->name));
  212. this->mtu = (unsigned int)d.getUI(ZT_NETWORKCONFIG_DICT_KEY_MTU,ZT_DEFAULT_MTU);
  213. if (this->mtu < 1280)
  214. this->mtu = 1280; // minimum MTU allowed by IPv6 standard and others
  215. else if (this->mtu > ZT_MAX_MTU)
  216. this->mtu = ZT_MAX_MTU;
  217. if (d.getUI(ZT_NETWORKCONFIG_DICT_KEY_VERSION,0) < 6) {
  218. #ifdef ZT_SUPPORT_OLD_STYLE_NETCONF
  219. char tmp2[1024] = {0};
  220. // Decode legacy fields if version is old
  221. if (d.getB(ZT_NETWORKCONFIG_DICT_KEY_ENABLE_BROADCAST_OLD))
  222. this->flags |= ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST;
  223. this->flags |= ZT_NETWORKCONFIG_FLAG_ENABLE_IPV6_NDP_EMULATION; // always enable for old-style netconf
  224. this->type = (d.getB(ZT_NETWORKCONFIG_DICT_KEY_PRIVATE_OLD,true)) ? ZT_NETWORK_TYPE_PRIVATE : ZT_NETWORK_TYPE_PUBLIC;
  225. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_IPV4_STATIC_OLD,tmp2,sizeof(tmp2)) > 0) {
  226. char *saveptr = (char *)0;
  227. for(char *f=Utils::stok(tmp2,",",&saveptr);(f);f=Utils::stok((char *)0,",",&saveptr)) {
  228. if (this->staticIpCount >= ZT_MAX_ZT_ASSIGNED_ADDRESSES) break;
  229. InetAddress ip(f);
  230. if (!ip.isNetwork())
  231. this->staticIps[this->staticIpCount++] = ip;
  232. }
  233. }
  234. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_IPV6_STATIC_OLD,tmp2,sizeof(tmp2)) > 0) {
  235. char *saveptr = (char *)0;
  236. for(char *f=Utils::stok(tmp2,",",&saveptr);(f);f=Utils::stok((char *)0,",",&saveptr)) {
  237. if (this->staticIpCount >= ZT_MAX_ZT_ASSIGNED_ADDRESSES) break;
  238. InetAddress ip(f);
  239. if (!ip.isNetwork())
  240. this->staticIps[this->staticIpCount++] = ip;
  241. }
  242. }
  243. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_CERTIFICATE_OF_MEMBERSHIP_OLD,tmp2,sizeof(tmp2)) > 0) {
  244. this->com.fromString(tmp2);
  245. }
  246. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_ALLOWED_ETHERNET_TYPES_OLD,tmp2,sizeof(tmp2)) > 0) {
  247. char *saveptr = (char *)0;
  248. for(char *f=Utils::stok(tmp2,",",&saveptr);(f);f=Utils::stok((char *)0,",",&saveptr)) {
  249. unsigned int et = Utils::hexStrToUInt(f) & 0xffff;
  250. if ((this->ruleCount + 2) > ZT_MAX_NETWORK_RULES) break;
  251. if (et > 0) {
  252. this->rules[this->ruleCount].t = (uint8_t)ZT_NETWORK_RULE_MATCH_ETHERTYPE;
  253. this->rules[this->ruleCount].v.etherType = (uint16_t)et;
  254. ++this->ruleCount;
  255. }
  256. this->rules[this->ruleCount++].t = (uint8_t)ZT_NETWORK_RULE_ACTION_ACCEPT;
  257. }
  258. } else {
  259. this->rules[0].t = ZT_NETWORK_RULE_ACTION_ACCEPT;
  260. this->ruleCount = 1;
  261. }
  262. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_ACTIVE_BRIDGES_OLD,tmp2,sizeof(tmp2)) > 0) {
  263. char *saveptr = (char *)0;
  264. for(char *f=Utils::stok(tmp2,",",&saveptr);(f);f=Utils::stok((char *)0,",",&saveptr)) {
  265. this->addSpecialist(Address(Utils::hexStrToU64(f)),ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE);
  266. }
  267. }
  268. #else
  269. delete tmp;
  270. return false;
  271. #endif // ZT_SUPPORT_OLD_STYLE_NETCONF
  272. } else {
  273. // Otherwise we can use the new fields
  274. this->flags = d.getUI(ZT_NETWORKCONFIG_DICT_KEY_FLAGS,0);
  275. this->type = (ZT_VirtualNetworkType)d.getUI(ZT_NETWORKCONFIG_DICT_KEY_TYPE,(uint64_t)ZT_NETWORK_TYPE_PRIVATE);
  276. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_COM,*tmp))
  277. this->com.deserialize(*tmp,0);
  278. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_CAPABILITIES,*tmp)) {
  279. try {
  280. unsigned int p = 0;
  281. while (p < tmp->size()) {
  282. Capability cap;
  283. p += cap.deserialize(*tmp,p);
  284. this->capabilities[this->capabilityCount++] = cap;
  285. }
  286. } catch ( ... ) {}
  287. std::sort(&(this->capabilities[0]),&(this->capabilities[this->capabilityCount]));
  288. }
  289. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_TAGS,*tmp)) {
  290. try {
  291. unsigned int p = 0;
  292. while (p < tmp->size()) {
  293. Tag tag;
  294. p += tag.deserialize(*tmp,p);
  295. this->tags[this->tagCount++] = tag;
  296. }
  297. } catch ( ... ) {}
  298. std::sort(&(this->tags[0]),&(this->tags[this->tagCount]));
  299. }
  300. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_CERTIFICATES_OF_OWNERSHIP,*tmp)) {
  301. unsigned int p = 0;
  302. while (p < tmp->size()) {
  303. if (certificateOfOwnershipCount < ZT_MAX_CERTIFICATES_OF_OWNERSHIP)
  304. p += certificatesOfOwnership[certificateOfOwnershipCount++].deserialize(*tmp,p);
  305. else {
  306. CertificateOfOwnership foo;
  307. p += foo.deserialize(*tmp,p);
  308. }
  309. }
  310. }
  311. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_SPECIALISTS,*tmp)) {
  312. unsigned int p = 0;
  313. while ((p + 8) <= tmp->size()) {
  314. if (specialistCount < ZT_MAX_NETWORK_SPECIALISTS)
  315. this->specialists[this->specialistCount++] = tmp->at<uint64_t>(p);
  316. p += 8;
  317. }
  318. }
  319. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_ROUTES,*tmp)) {
  320. unsigned int p = 0;
  321. while ((p < tmp->size())&&(routeCount < ZT_MAX_NETWORK_ROUTES)) {
  322. p += reinterpret_cast<InetAddress *>(&(this->routes[this->routeCount].target))->deserialize(*tmp,p);
  323. p += reinterpret_cast<InetAddress *>(&(this->routes[this->routeCount].via))->deserialize(*tmp,p);
  324. this->routes[this->routeCount].flags = tmp->at<uint16_t>(p); p += 2;
  325. this->routes[this->routeCount].metric = tmp->at<uint16_t>(p); p += 2;
  326. ++this->routeCount;
  327. }
  328. }
  329. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_STATIC_IPS,*tmp)) {
  330. unsigned int p = 0;
  331. while ((p < tmp->size())&&(staticIpCount < ZT_MAX_ZT_ASSIGNED_ADDRESSES)) {
  332. p += this->staticIps[this->staticIpCount++].deserialize(*tmp,p);
  333. }
  334. }
  335. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_RULES,*tmp)) {
  336. this->ruleCount = 0;
  337. unsigned int p = 0;
  338. Capability::deserializeRules(*tmp,p,this->rules,this->ruleCount,ZT_MAX_NETWORK_RULES);
  339. }
  340. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_DNS, *tmp)) {
  341. unsigned int p = 0;
  342. DNS::deserializeDNS(*tmp, p, &dns);
  343. }
  344. this->ssoVersion = d.getUI(ZT_NETWORKCONFIG_DICT_KEY_SSO_VERSION, 0ULL);
  345. this->ssoEnabled = d.getB(ZT_NETWORKCONFIG_DICT_KEY_SSO_ENABLED, false);
  346. if (this->ssoVersion == 0) {
  347. // implicit flow
  348. if (this->ssoEnabled) {
  349. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_AUTHENTICATION_URL, this->authenticationURL, (unsigned int)sizeof(this->authenticationURL)) > 0) {
  350. this->authenticationURL[sizeof(this->authenticationURL) - 1] = 0; // ensure null terminated
  351. } else {
  352. this->authenticationURL[0] = 0;
  353. }
  354. this->authenticationExpiryTime = d.getI(ZT_NETWORKCONFIG_DICT_KEY_AUTHENTICATION_EXPIRY_TIME, 0);
  355. } else {
  356. this->authenticationURL[0] = 0;
  357. this->authenticationExpiryTime = 0;
  358. }
  359. } else if (this->ssoVersion == 1) {
  360. // full flow
  361. if (this->ssoEnabled) {
  362. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_AUTHENTICATION_URL, this->authenticationURL, (unsigned int)sizeof(this->authenticationURL)) > 0) {
  363. this->authenticationURL[sizeof(this->authenticationURL) - 1] = 0;
  364. }
  365. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_ISSUER_URL, this->issuerURL, (unsigned int)sizeof(this->issuerURL)) > 0) {
  366. this->issuerURL[sizeof(this->issuerURL) - 1] = 0;
  367. }
  368. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_CENTRAL_ENDPOINT_URL, this->centralAuthURL, (unsigned int)sizeof(this->centralAuthURL)) > 0) {
  369. this->centralAuthURL[sizeof(this->centralAuthURL) - 1] = 0;
  370. }
  371. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_NONCE, this->ssoNonce, (unsigned int)sizeof(this->ssoNonce)) > 0) {
  372. this->ssoNonce[sizeof(this->ssoNonce) - 1] = 0;
  373. }
  374. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_STATE, this->ssoState, (unsigned int)sizeof(this->ssoState)) > 0) {
  375. this->ssoState[sizeof(this->ssoState) - 1] = 0;
  376. }
  377. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_CLIENT_ID, this->ssoClientID, (unsigned int)sizeof(this->ssoClientID)) > 0) {
  378. this->ssoClientID[sizeof(this->ssoClientID) - 1] = 0;
  379. }
  380. if (d.get(ZT_NETWORKCONFIG_DICT_KEY_SSO_PROVIDER, this->ssoProvider, (unsigned int)(sizeof(this->ssoProvider))) > 0) {
  381. this->ssoProvider[sizeof(this->ssoProvider) - 1] = 0;
  382. } else {
  383. strncpy(this->ssoProvider, "default", sizeof(this->ssoProvider));
  384. this->ssoProvider[sizeof(this->ssoProvider) - 1] = 0;
  385. }
  386. } else {
  387. this->authenticationURL[0] = 0;
  388. this->authenticationExpiryTime = 0;
  389. this->centralAuthURL[0] = 0;
  390. this->ssoNonce[0] = 0;
  391. this->ssoState[0] = 0;
  392. this->ssoClientID[0] = 0;
  393. this->issuerURL[0] = 0;
  394. this->ssoProvider[0] = 0;
  395. }
  396. }
  397. }
  398. //printf("~~~\n%s\n~~~\n",d.data());
  399. //dump();
  400. //printf("~~~\n");
  401. delete tmp;
  402. return true;
  403. } catch ( ... ) {
  404. delete tmp;
  405. return false;
  406. }
  407. }
  408. } // namespace ZeroTier