def timeout(p): if p.poll() == None: try: p.kill() logE('process taking too much time to perform --terminating!') except: pass
def get_value_as_string(section, option): value = "" try: value = config.get(section, option) except ConfigParser.NoOptionError: logE("Specified option [" + option + "] was not found.") return value
def set_value(section, option, value): try: config.set(section, option, value) return True except ConfigParser.NoSectionError: logE("Specified section [" + section + "] does not exist.") except ConfigParser.TypeError: logE("value type is not valid. Value must be of type: str") return False
def get_value_as_boolean(section, option): try: value = config.getboolean(section, option) return value except ConfigParser.NoOptionError: logE("Specified option [" + option + "] was not found.") except ConfigParser.ValueError: value = config.get(section, option) logE("Specified option [" + option + "] could not be interpreted as an boolean. Value: " + value)
def write_to_file(path_to_file): logI("Writing configuration to file...") try: fp = open(path_to_file, 'w') except IOError: logE("Specifed file was not found: " + path_to_file) return False config.write(fp) fp.close() return True
def verify_secure_components(componentsToCheck): missing = [] ret = True for uuid in componentsToCheck.viewkeys(): if str(uuid) not in str(SystemTAs.keys()) and str(uuid) not in str( SPTAs.keys()): missing.append(str(componentsToCheck[uuid]) + ':' + str(uuid)) if missing: ret = False for item in missing: logE("Unable to find presence of Secure Components: " + item) return ret
def verify_normal_world(): list = [] for k, v in NormalWorld.iteritems(): if 'false' in v: list.append(k) logW( "BUG: teed may not be detected even though it is valid, you may ignore this error" ) if not list: return True else: logE("Normal World misses libraries/bins or bad permissions: " + str(list)) if SELinux['available'] == 'true' and SELinux['enforcing'] == 'true': logI("SELinux is activated, and enforcing") return False
def read_file(path_to_file): # reset the contents of the parser #logD("Resetting parser content...") sections = config.sections() for section in sections: config.remove_section(section) #logD("Attempting to parse configuration file: " + path_to_file) try: fp = open(path_to_file, 'r') except IOError: logE("Specifed file was not found.") return False try: config.readfp(fp) fp.close() return config except ConfigParser.Error as e: logE("Specifed file is badly formatted. Parsing failed.") logE(e) return False
def verify_integration(workingDirectory, dumpFilePath, secureComponents): logI( "+--------------------------------------------------------------------------" ) logI("| Verify tkcore bsp integration...") logI( "+--------------------------------------------------------------------------" ) if lib_adb.is_file_exist(dumpFilePath): lib_adb.cmd("rm " + dumpFilePath, check_result=False) if not lib_adb.start_activity( "com.trustkernel.teeotaverifier/.MainActivity"): logE("Could not start tee verifier app") logI( "+--------------------------------------------------------------------------" ) return False, teeIntegrationCheck time.sleep(5) # give time for checks to happen # broadcast intent lib_adb.broadcast_intent( "com.trustkernel.teeotaverifier.DUMP --es filename " + dumpFilePath) lib_adb.stop_activity("com.trustkernel.teeotaverifier") # retrieve and parse dump file lib_adb.pull(dumpFilePath, workingDirectory) #read config file dump_file = os.path.join(workingDirectory, os.path.basename(dumpFilePath)) if not lib_config_file.read_file(dump_file): logE("Could not read tee verifier dump") logI( "+--------------------------------------------------------------------------" ) return False, teeIntegrationCheck # test get_section_list sections = lib_config_file.get_section_list() dictionary = {} for section in sections: if section == "android": dictionary = SystemInfo elif section == "global": dictionary = Global elif section == "TEE": dictionary = teeIntegrationCheck elif section == "system ta": dictionary = SystemTAs elif section == "SP ta": dictionary = SPTAs elif section == "normal_world" or section == "files_permissions": dictionary = NormalWorld elif section.startswith("selinux"): dictionary = SELinux elif section == "connectivity": dictionary = Connectivity for option in lib_config_file.get_all_options(section): dictionary[option[0]] = option[1] logI("Global Info:") for k, v in Global.iteritems(): logI(k + ':' + v) logI("tee Info: <version could not be detected yet>") teeIntegrationCheck['result'] = "SUCCESS" if not verify_normal_world(): teeIntegrationCheck['result'] = "ERROR" if not verify_secure_components(secureComponents): teeIntegrationCheck['result'] = "ERROR" logI( "---------------------------------------------------------------------------" ) logI(" Global verification result: " + teeIntegrationCheck['result']) logI( "---------------------------------------------------------------------------" ) return True, teeIntegrationCheck