Adding a new feature that makes process jailing rules more fine-grained - we can...
[iot2.git] / iotjava / iotruntime / master / IoTMaster.java
index 2d5b44f799ff6e01856df452d81fc59e37acf2a2..454ca306e2cfd6aa4ea03f886a23cc2a1525b81b 100644 (file)
@@ -127,6 +127,7 @@ public final class IoTMaster {
        private static final String STR_INT_STUB_CLS_CFG = "INTERFACE_STUB_CLASS";
        private static final String STR_FILE_TRF_CFG = "ADDITIONAL_ZIP_FILE";
        private static final String STR_LANGUAGE = "LANGUAGE";
+       private static final String STR_ADD_MAC_POL = "ADDITIONAL_MAC_POLICY";
        private static final String STR_YES = "Yes";
        private static final String STR_NO = "No";
        private static final String STR_JAVA = "Java";
@@ -645,6 +646,12 @@ public final class IoTMaster {
                                processJailConfig.configureProcessJailDeviceDriverPolicies(strIoTSlaveObjectHostAdd, strObjName, strObjClassName,
                                        strFileName, strIoTMasterHostAdd, commHan.getComPort(strObjName), commHan.getRMIRegPort(strObjName), 
                                        commHan.getRMIStubPort(strObjName));
+                   // Check for additional MAC policy
+                   String strMACConfigPath = STR_IOT_CODE_PATH + strObjClassName + "/";
+                   String strCfgFile = strMACConfigPath + strObjClassName + STR_CFG_FILE_EXT;
+                       String strAddMACPolicy = parseConfigFile(strCfgFile, STR_ADD_MAC_POL);
+                   if (strAddMACPolicy != null && strAddMACPolicy.equals("Yes"))
+                       processJailConfig.combineAdditionalMACPolicy(strMACConfigPath, strObjClassName, strIoTSlaveObjectHostAdd);
                                processJailConfig.configureProcessJailContRMIPolicies(strObjControllerName, strIoTSlaveObjectHostAdd, 
                                        commHan.getRMIRegPort(strObjName), commHan.getRMIStubPort(strObjName));
                        }
@@ -1996,6 +2003,7 @@ public final class IoTMaster {
                        strIoTMasterHostAdd = routerConfig.getIPFromMACAddress(STR_MASTER_MAC_ADD);
                    // Assign a new list of PrintWriter objects
            routerConfig.renewPrintWriter();
+           HashSet<String> setAddresses = null;
                        // Loop as we can still find controller/device classes
                        for(int i=0; i<strObjectNames.length; i++) {
                                // PROFILING
@@ -2081,6 +2089,12 @@ public final class IoTMaster {
                                        String strFileName = STR_MAC_POL_PATH + STR_JAVA + STR_MAC_POLICY_EXT;
                                        processJailConfig.configureProcessJailControllerPolicies(strObjControllerName, strFileName, 
                                                strIoTMasterHostAdd, commHan.getComPort(strObjControllerName));
+                               // Whether or not we need additional Tomoyo policy?
+                                   String strAddMACPolicy = parseConfigFile(strControllerCfg, STR_ADD_MAC_POL);
+                                   if (strAddMACPolicy != null && strAddMACPolicy.equals("Yes")) {
+                                   String strContMACCfg = STR_CONT_PATH + strObjControllerName + "/";
+                                       processJailConfig.combineAdditionalMACPolicy(strContMACCfg, strObjControllerName, strObjControllerName);
+                                   }
                                }
                                // PROFILING
                                result = System.currentTimeMillis()-start;
@@ -2146,7 +2160,7 @@ public final class IoTMaster {
                                // Combine controller MAC policies with the main policy file for the host
                                String strTempFileName = "./" + strObjControllerName + STR_MAC_POLICY_EXT;
                                processJailConfig.combineControllerMACPolicies(strIoTSlaveControllerHostAdd, strObjControllerName, strTempFileName);
-                               processJailConfig.close();
+                               processJailConfig.flush();
 
                                // PROFILING
                                result = System.currentTimeMillis()-start;
@@ -2165,7 +2179,7 @@ public final class IoTMaster {
                                setRouterBasicPolicies(STR_ROUTER_ADD);
                                routerConfig.closeMain();
                                // Deploy the policy
-                               HashSet<String> setAddresses = new HashSet<String>(commHan.getHosts());
+                               setAddresses = new HashSet<String>(commHan.getHosts());
                                setAddresses.add(strIoTMasterHostAdd);
                                createPolicyThreads(STR_ROUTER_ADD, setAddresses);
 
@@ -2214,11 +2228,12 @@ public final class IoTMaster {
                                commHan.printLists();
                                commHan.clearCommunicationHandler();
                                lbIoT.printHostInfo();
-                               if (STR_ACTIVATE_SANDBOXING.equals("Yes"))
-                                       createMACPolicyThreads(setAddresses);
                        }
                        // Close access to policy files and deploy policies
                        routerConfig.close();
+                       processJailConfig.close();
+                       if (STR_ACTIVATE_SANDBOXING.equals("Yes"))
+                               createMACPolicyThreads(setAddresses);
 
                } catch (IOException          |
                                 InterruptedException |