def copyOutputLibrariesToMainLibraries(libraries): origin=Path(getPath("outFiles/libraries")) destination=str(Path(getPath("libraries"))) for library in libraries: originPath=origin / library os.system("cp %s %s" %(originPath, destination)) logger.info("INFO FILE: The file %s was copied from %s to %s." %(library, origin, destination))
def removeStandardsFromCountermeasures(libraries, standardNames): rootClass = supermod.libraryType() for lib in libraries: logger.info("Opened library %s" %lib) rootClass = supermod.parse(str(Path(getPath("libraries")) / lib), True) for standardName in standardNames: removeStandardFromLibrary(rootClass, convertToRef(standardName)) removeSupportedStandard(rootClass, convertToRef(standardName)) exportLib2XML(str(Path(getPath("outFiles/libraries/")) / lib), rootClass, False)
def applyStandardToLibraries(libraries, standardNames, dataExcel): for library in libraries: logger.info("Opened library %s" %library) rootClass = supermod.parse(str(Path(getPath("libraries")) / library), True) for standardName in standardNames: addStandardToLibrary(rootClass, dataExcel[dataExcel[standardName.replace("IoTSF ","")] == 'M'], convertToRef(standardName)) addSupportedStandard(rootClass, convertToRef(standardName), standardName) exportLib2XML(str(Path(getPath("outFiles/libraries/")) / library), rootClass, True)
def generateHTML(standardName, standards): code = "<!DOCTYPE html><html><head><title>Standard " + standardName + "</title><link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css\" integrity=\"sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm\" crossorigin=\"anonymous\">" code = code + "<script src=\"https://code.jquery.com/jquery-3.3.1.slim.min.js\" integrity=\"sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo\" crossorigin=\"anonymous\"></script>" code = code + "<script src=\"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js\" integrity=\"sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49\" crossorigin=\"anonymous\"></script>" code = code + "<script src=\"https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js\" integrity=\"sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy\" crossorigin=\"anonymous\"></script></head><body>" code += "<center><h2>Standard " + standardName + "</h2></center>" code += "<nav>" code += "<button class=\"btn btn-outline-success\" type=\"button\" data-toggle=\"collapse\" data-target=\"#collapseGroupExample1\" aria-expanded=\"false\" aria-controls=\"collapseGroupExample1\">Mapped with the standard</button>" code += " " code += "<button class=\"btn btn-outline-warning\" type=\"button\" data-toggle=\"collapse\" data-target=\"#collapseGroupExample2\" aria-expanded=\"false\" aria-controls=\"collapseGroupExample2\">Not mapped with the standard</button>" code += "</nav><br/>" code += "<div class=\"accordion\" id=\"root\">" code += "<div class=\"collapse\" id=\"collapseGroupExample1\" data-parent=\"#root\">" code += createTab(getAsvsRequirementsMappedWithStandard(standards), "Requirement ASVS", 'success') code += "</div>" code += "<div class=\"collapse\" id=\"collapseGroupExample2\" data-parent=\"#root\">" code += createTab(getAsvsRequirementsNotMappedWithStandard(standards), "Requirement ASVS (Not mapped)", 'warning') code += "</div>" code += "</div>" code += "</body></html>" fileHtml = open( getPath("outFiles") + "/" + standardName + "_otherVersion.html", "w") fileHtml.write(code) fileHtml.close()
def getDataFromExcelForIoT(stage): xls = pd.ExcelFile( Path(getPath("inputFiles/spreadSheetFiles/")) / 'Release Strategy for IoT Controls.xlsx') dfm = pd.read_excel(xls, header=2, sheet_name=stage + ' Controls') dfm_filtered = dfm.filter(items=[ 'Compliance Applicability', 'Requirement', 'Req. No', 'IR controls mapped', 'Mapped in IriusRisk', 'New IR control needed?', 'Class 0', 'Class 1', 'Class 2', 'Class 3', 'Class 4' ]) dfm_filtered = pd.DataFrame(dfm_filtered) return dfm_filtered
def selectLibraryToApplyStandard(): libraries = os.listdir(getPath("libraries")) # If there is not any selected library, we do the changes into all libraries. text = "In which library do you want to apply the IoT standards?\n" for library in libraries: if library.endswith(".xml"): text += "%i - %s\n" % (libraries.index(library), library) text += "%i - %s\n" % (len(libraries) + 1, "All libraries") valueText = int(input(text)) if valueText <= len(libraries): libraries = [libraries[valueText]] return libraries
def main(): if len(sys.argv) == 2: standardName = str(sys.argv[1]) standardNameFile = standardName standardNameFile = standardNameFile.replace(" ", "") standardNameFile = standardNameFile.replace(":", "_") standardNameFileStandard = "standard_" + standardNameFile standards = readCsvFile( getPath("inputFiles") + "/" + standardNameFileStandard + ".csv") standardsInfo = readCsvFile( getPath("inputFiles") + "/" + standardNameFileStandard + "_info.csv") asvsStandards = readCsvFile( getPath("inputFiles") + "/standard_ASVS_3.0.1.csv") newStandards = joinStandardListWithAsvs(standards, standardsInfo, asvsStandards) pathOutput = home generateHTML(standardName, newStandards) print("Html file for the standard " + standardName + " was generated.")
def createCsvInfoStandard(dataFrame, standardNames): for standardName in standardNames: standardName_replaced = standardName.replace(" ", "-") dfm_filtered = dataFrame[dataFrame[standardName.replace("IoTSF ", "")] == 'M'] dfm_filtered = dfm_filtered.filter( items=['Compliance Applicability', 'Req. No', 'Requirement']) dfm_filtered = dfm_filtered.assign(blank="", included="x") standards = dfm_filtered controls = sToC.getControlsData(standardName.lower().replace(" ", "-"), getPath("outFiles/libraries/")) sToC.generateHTML(standardName, standards, controls) logger.info("Html file for the standard " + standardName + " was generated.")
def getAsvsDataFromCsv(): asvsData = list() file = open(getPath("inputFiles") + "/standard_ASVS_3.0.1.csv", 'r') data = file.read() while (data.find("\n") != -1): arrayList = list() processData = data[0:data.find("\n")] data = data[data.find("\n") + 1:] while (processData.find("||") != -1): value = processData[0:processData.find("||")] processData = processData[processData.find("||") + 2:] arrayList.append(value) value = processData[0:processData.find("\\")] arrayList.append(value) asvsData.append(arrayList) return asvsData