private static String STR_SKEL_CLASS_SUFFIX;
private static String STR_STUB_CLASS_SUFFIX;
private static String STR_ACTIVATE_SANDBOXING;
+ private static String STR_POLICY_ON;
+ private static String STR_MAC_TO_IP_TRANSLATION;
private static boolean BOOL_VERBOSE;
/**
private static final String STR_SHELL_HEADER = "#!/bin/sh";
private static final String STR_JAVA_PATH = "/usr/bin/java";
private static final String STR_MAC_POL_PATH = "tomoyo/";
+ private static final String STR_TMP = "tmp";
+ private static final String STR_ARP = "arp";
private static int INT_SIZE = 4; // send length in the size of integer (4 bytes)
private static final int INT_DNS_PORT = 53;
STR_JVM_MAX_HEAP_SIZE = null;
STR_LANGUAGE_CONTROLLER = null;
STR_ACTIVATE_SANDBOXING = null;
+ STR_POLICY_ON = null;
+ STR_MAC_TO_IP_TRANSLATION = null;
BOOL_VERBOSE = false;
}
lbIoT = new LoadBalancer(BOOL_VERBOSE);
lbIoT.setupLoadBalancer();
routerConfig = new RouterConfig();
- routerConfig.getAddressList(STR_ROUTER_ADD);
+ // Get MAC to IP translation either from /tmp/dhcp.leases or arp command
+ if (STR_MAC_TO_IP_TRANSLATION.equals(STR_TMP))
+ routerConfig.getAddressListTmp(STR_ROUTER_ADD);
+ else if (STR_MAC_TO_IP_TRANSLATION.equals(STR_ARP))
+ routerConfig.getAddressListArp(STR_ROUTER_ADD);
+ else
+ throw new Error("IoTMaster: Unknown value for STR_MAC_TO_IP_TRANSLATION: " + STR_MAC_TO_IP_TRANSLATION);
processJailConfig = new ProcessJailConfig();
//processJailConfig.setAddressListObject(routerConfig.getAddressListObject());
objInitHand = new ObjectInitHandler(BOOL_VERBOSE);
STR_SKEL_CLASS_SUFFIX = prop.getProperty("SKEL_CLASS_SUFFIX");
STR_STUB_CLASS_SUFFIX = prop.getProperty("STUB_CLASS_SUFFIX");
STR_ACTIVATE_SANDBOXING = prop.getProperty("ACTIVATE_SANDBOXING");
+ STR_POLICY_ON = prop.getProperty("POLICY_ON");
+ STR_MAC_TO_IP_TRANSLATION = prop.getProperty("MAC_TO_IP_TRANSLATION");
if(prop.getProperty("VERBOSE").equals(STR_YES)) {
BOOL_VERBOSE = true;
}
RuntimeOutput.print("STR_SKEL_CLASS_SUFFIX=" + STR_SKEL_CLASS_SUFFIX, BOOL_VERBOSE);
RuntimeOutput.print("STR_STUB_CLASS_SUFFIX=" + STR_STUB_CLASS_SUFFIX, BOOL_VERBOSE);
RuntimeOutput.print("STR_ACTIVATE_SANDBOXING=" + STR_ACTIVATE_SANDBOXING, BOOL_VERBOSE);
+ RuntimeOutput.print("STR_POLICY_ON=" + STR_POLICY_ON, BOOL_VERBOSE);
+ RuntimeOutput.print("STR_MAC_TO_IP_TRANSLATION=" + STR_MAC_TO_IP_TRANSLATION, BOOL_VERBOSE);
RuntimeOutput.print("BOOL_VERBOSE=" + BOOL_VERBOSE, BOOL_VERBOSE);
RuntimeOutput.print("IoTMaster: Information extracted successfully!", BOOL_VERBOSE);
}
// Deploy the policy
setAddresses = new HashSet<String>(commHan.getHosts());
setAddresses.add(strIoTMasterHostAdd);
- createPolicyThreads(STR_ROUTER_ADD, setAddresses);
+ // See if firewall policy is configured to be "on" or "off"
+ if (STR_POLICY_ON.equals(STR_YES))
+ createPolicyThreads(STR_ROUTER_ADD, setAddresses);
// PROFILING
result = System.currentTimeMillis()-start;
* RouterConfig constants
*/
private static final String STR_SSH_USERNAME_ROUTER = "root";
+ private static final String STR_SSH_USERNAME_RASPBERRYPI = "pi";
private static final String STR_SSH_USERNAME_HOST = "iotuser";
private static final String STR_POLICY_FILE_ALL = "_all";
private static final String STR_POLICY_FILE_EXT = ".policy";
+ private static final String STR_INCOMPLETE = "(incomplete)";
/**
* RouterConfig properties
}
/**
- * getAddressList() method gets list of IP addresses
+ * getAddressListTmp() method gets list of IP addresses from /tmp/dhcp.leases
* <p>
* This method sends an inquiry to the router to look for
* the list of DHCP leased addresses and their mapping to MAC
*
* @param strRouterAddress String that contains address of router
*/
- public void getAddressList(String strRouterAddress) {
+ public void getAddressListTmp(String strRouterAddress) {
//HashMap<String,String> hmMACToIPAdd = new HashMap<String,String>();
try {
}
}
+ /**
+ * getAddressListArp() method gets list of IP addresses from arp command
+ * <p>
+ * This method sends an inquiry to the router to look for
+ * the list of DHCP leased addresses and their mapping to MAC
+ * addresses
+ *
+ * @param strRouterAddress String that contains address of router
+ */
+ public void getAddressListArp(String strRouterAddress) {
+
+ //HashMap<String,String> hmMACToIPAdd = new HashMap<String,String>();
+ try {
+ // We replace with "cat /usr/sbin/arp"
+ String cmd = "ssh " + STR_SSH_USERNAME_RASPBERRYPI + "@" + strRouterAddress +
+ " /usr/sbin/arp";
+ Runtime runtime = Runtime.getRuntime();
+ Process process = runtime.exec(cmd);
+
+ InputStream inStream = process.getInputStream();
+ InputStreamReader isReader = new InputStreamReader(inStream);
+ BufferedReader bReader = new BufferedReader(isReader);
+ String strRead = null;
+ while((strRead = bReader.readLine()) != null){
+ String[] str = strRead.split("\\s+");
+ // Skip if "(incomplete)" is seen!
+ if (str[1].equals(STR_INCOMPLETE))
+ continue;
+ mapMACtoIPAdd.put(str[2], str[0]);
+ }
+ } catch (IOException ex) {
+ System.out.println("RouterConfig: IOException: " + ex.getMessage());
+ ex.printStackTrace();
+ }
+ }
+
/**
* getIPFromMACAddress() method gets IP from MAC address
*