summaryrefslogtreecommitdiff
path: root/controller/EmbeddedNetworkController.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2016-08-17 13:41:45 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2016-08-17 13:41:45 -0700
commitb72847d50404f4d751184d9977e7bba23050a797 (patch)
treea735b68d0e6038c30bc53aaabc40e52dff11078c /controller/EmbeddedNetworkController.cpp
parent168b86fdcd8f2a590ea59710dfbfb67c8d8c5cef (diff)
downloadinfinitytier-b72847d50404f4d751184d9977e7bba23050a797.tar.gz
infinitytier-b72847d50404f4d751184d9977e7bba23050a797.zip
Finally implement network join auth tokens, at least at the protocol level.
Diffstat (limited to 'controller/EmbeddedNetworkController.cpp')
-rw-r--r--controller/EmbeddedNetworkController.cpp53
1 files changed, 51 insertions, 2 deletions
diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp
index d3f44fb4..dfb93b01 100644
--- a/controller/EmbeddedNetworkController.cpp
+++ b/controller/EmbeddedNetworkController.cpp
@@ -658,11 +658,39 @@ NetworkController::ResultCode EmbeddedNetworkController::doNetworkConfigRequest(
// Stop if network is private and member is not authorized
if ( (network.value("private",true)) && (!member.value("authorized",false)) ) {
- _writeJson(memberJP,member);
- return NetworkController::NETCONF_QUERY_ACCESS_DENIED;
+ bool authenticatedViaToken = false;
+ char atok[256];
+ if (metaData.get(ZT_NETWORKCONFIG_REQUEST_METADATA_KEY_AUTH_TOKEN,atok,sizeof(atok)) > 0) {
+ atok[255] = (char)0; // not necessary but YDIFLO
+ if (strlen(atok) > 0) { // extra sanity check
+ auto authTokens = network["authTokens"];
+ if (authTokens.is_array()) {
+ for(unsigned long i=0;i<authTokens.size();++i) {
+ auto at = authTokens[i];
+ if (at.is_object()) {
+ const uint64_t expires = at.value("expires",0ULL);
+ std::string tok = at.value("token","");
+ if ( ((expires == 0ULL)||(expires > now)) && (tok.length() > 0) && (tok == atok) ) {
+ authenticatedViaToken = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (!authenticatedViaToken) {
+ _writeJson(memberJP,member);
+ return NetworkController::NETCONF_QUERY_ACCESS_DENIED;
+ }
}
// Else compose and send network config
+ // If we made it here for some reason other than authorized being true, such as this
+ // being a public network or via a bearer token, then we set this in the member config.
+ member["authorized"] = true;
+
nc.networkId = nwid;
nc.type = network.value("private",true) ? ZT_NETWORK_TYPE_PRIVATE : ZT_NETWORK_TYPE_PUBLIC;
nc.timestamp = now;
@@ -1308,6 +1336,26 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
network["rules"] = nrules;
}
}
+
+ if (b.count("authTokens")) {
+ auto authTokens = b["authTokens"];
+ if (authTokens.is_array()) {
+ json nat = json::array();
+ for(unsigned long i=0;i<authTokens.size();++i) {
+ auto token = authTokens[i];
+ if (token.is_object()) {
+ std::string tstr = token["token"];
+ if (tstr.length() > 0) {
+ json t = json::object();
+ t["token"] = tstr;
+ t["expires"] = token.value("expires",0ULL);
+ nat.push_back(t);
+ }
+ }
+ }
+ network["authTokens"] = nat;
+ }
+ }
} catch ( ... ) {
return 400;
}
@@ -1319,6 +1367,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
if (!network.count("v4AssignMode")) network["v4AssignMode"] = "{\"zt\":false}"_json;
if (!network.count("v6AssignMode")) network["v6AssignMode"] = "{\"rfc4193\":false,\"zt\":false,\"6plane\":false}"_json;
if (!network.count("activeBridges")) network["activeBridges"] = json::array();
+ if (!network.count("authTokens")) network["authTokens"] = json::array();
if (!network.count("rules")) {
// If unspecified, rules are set to allow anything and behave like a flat L2 segment