Search in sources :

Example 1 with VerdictStem

use of com.ge.verdict.stem.VerdictStem in project VERDICT by ge-high-assurance.

the class App method runMbas.

/**
 * Run MBAS with CSV input files
 *
 * @param modelName Name of model
 * @param stemDir output directory for STEM input files
 * @param soteriaDir output directory for Soteria++ input files
 * @throws VerdictRunException
 */
public static void runMbas(String modelName, String stemProjectDir, String debugDir, String soteriaPpBin, boolean cyberInference, boolean safetyInference) throws VerdictRunException {
    String stemCsvDir = (new File(stemProjectDir, "CSVData")).getAbsolutePath();
    String stemOutputDir = (new File(stemProjectDir, "Output")).getAbsolutePath();
    String stemGraphsDir = (new File(stemProjectDir, "Graphs")).getAbsolutePath();
    String stemSadlFile = (new File(stemProjectDir, "Run.sadl")).getAbsolutePath();
    File soteriaOutputDir = new File(stemOutputDir, "Soteria_Output");
    soteriaOutputDir.mkdirs();
    String soteriaPpOutputDir = soteriaOutputDir.getAbsolutePath();
    checkFile(stemCsvDir, true, true, true, false, null);
    checkFile(stemOutputDir, true, true, true, false, null);
    checkFile(stemGraphsDir, true, true, true, false, null);
    checkFile(stemSadlFile, true, false, false, false, null);
    checkFile(soteriaPpOutputDir, true, true, true, false, null);
    checkFile(soteriaPpBin, true, false, false, true, null);
    deleteDirectoryContents(stemGraphsDir);
    deleteDirectoryContents(soteriaPpOutputDir);
    if (debugDir != null) {
        logHeader("DEBUGGING XML OUTPUT");
    }
    try {
        // Copy Soteria++ pngs
        for (String soteria_png : soteria_pngs) {
            Binary.copyResource("soteria_pngs/" + soteria_png + ".png", new File(soteriaPpOutputDir, soteria_png + ".png"), false);
        }
    } catch (Binary.ExecutionException e) {
        throw new VerdictRunException("Failed to copy Soteria++ pngs", e);
    }
    logHeader("STEM");
    log("STEM project directory: " + stemProjectDir);
    log("STEM output directory: " + stemOutputDir);
    log("STEM graphs directory: " + stemGraphsDir);
    log("STEM is running. Please be patient...");
    VerdictStem stemRunner = new VerdictStem();
    Metrics.timer("Timer.mbas.stem", "model", modelName).record(() -> stemRunner.runStem(new File(stemProjectDir), new File(stemOutputDir), new File(stemGraphsDir)));
    log("STEM finished!");
    logHeader("Soteria++");
    log("Soteria++ input directory: " + stemOutputDir);
    log("Soteria++ output directory: " + soteriaPpOutputDir);
    log("Soteria++ is running. Please be patient...");
    // Soteria has optional arguments, so need to add all args to this list
    List<String> args = new ArrayList<>();
    args.add("-o");
    args.add(soteriaPpOutputDir);
    args.add(stemOutputDir);
    if (cyberInference) {
        args.add("-c");
    }
    if (safetyInference) {
        args.add("-s");
    }
    try {
        Timer.Sample sample = Timer.start(Metrics.globalRegistry);
        Binary.invokeBin(soteriaPpBin, soteriaPpOutputDir, new PumpStreamHandler(), args.toArray(new String[args.size()]));
        sample.stop(Metrics.timer("Timer.mbas.soteria_pp", "model", modelName));
    } catch (Binary.ExecutionException e) {
        throw new VerdictRunException("Failed to execute soteria_pp", e);
    }
    logHeader("Finished");
}
Also used : PumpStreamHandler(org.apache.tools.ant.taskdefs.PumpStreamHandler) Timer(io.micrometer.core.instrument.Timer) VerdictStem(com.ge.verdict.stem.VerdictStem) ArrayList(java.util.ArrayList) File(java.io.File)

Example 2 with VerdictStem

use of com.ge.verdict.stem.VerdictStem in project VERDICT by ge-high-assurance.

the class App method runMbasSynthesis.

/**
 * Run MBAS Synthesis with CSV input files
 *
 * @param vdmPath VDM input file for synthesis
 * @param modelName Name of model
 * @param stemDir output directory for STEM input files
 * @param soteriaDir output directory for Soteria++ input files
 * @throws VerdictRunException
 */
public static void runMbasSynthesis(String vdmPath, String modelName, String stemProjectDir, String debugDir, String soteriaPpBin, boolean cyberInference, boolean safetyInference, boolean partialSolution, String costModelPath, String outputPath) throws VerdictRunException {
    String stemCsvDir = (new File(stemProjectDir, "CSVData")).getAbsolutePath();
    String stemOutputDir = (new File(stemProjectDir, "Output")).getAbsolutePath();
    String stemGraphsDir = (new File(stemProjectDir, "Graphs")).getAbsolutePath();
    String stemSadlFile = (new File(stemProjectDir, "Run.sadl")).getAbsolutePath();
    File soteriaOutputDir = new File(stemOutputDir, "Soteria_Output");
    soteriaOutputDir.mkdirs();
    String soteriaPpOutputDir = soteriaOutputDir.getAbsolutePath();
    checkFile(stemCsvDir, true, true, true, false, null);
    checkFile(stemOutputDir, true, true, true, false, null);
    checkFile(stemGraphsDir, true, true, true, false, null);
    checkFile(stemSadlFile, true, false, false, false, null);
    checkFile(soteriaPpOutputDir, true, true, true, false, null);
    checkFile(soteriaPpBin, true, false, false, true, null);
    checkFile(vdmPath, true, false, false, false, "xml");
    checkFile(costModelPath, true, false, false, false, "xml");
    checkFile(outputPath, false, false, true, false, "xml");
    deleteDirectoryContents(stemGraphsDir);
    deleteDirectoryContents(soteriaPpOutputDir);
    if (debugDir != null) {
        logHeader("DEBUGGING XML OUTPUT");
    }
    try {
        // Copy Soteria++ pngs
        for (String soteria_png : soteria_pngs) {
            Binary.copyResource("soteria_pngs/" + soteria_png + ".png", new File(soteriaPpOutputDir, soteria_png + ".png"), false);
        }
    } catch (Binary.ExecutionException e) {
        throw new VerdictRunException("Failed to copy Soteria++ pngs", e);
    }
    logHeader("STEM");
    log("STEM project directory: " + stemProjectDir);
    log("STEM output directory: " + stemOutputDir);
    log("STEM graphs directory: " + stemGraphsDir);
    log("STEM is running. Please be patient...");
    VerdictStem stemRunner = new VerdictStem();
    Metrics.timer("Timer.mbas.stem", "model", modelName).record(() -> stemRunner.runStem(new File(stemProjectDir), new File(stemOutputDir), new File(stemGraphsDir)));
    log("STEM finished!");
    logHeader("Synthesis");
    try {
        Timer.Sample sample = Timer.start(Metrics.globalRegistry);
        CostModel costModel = new CostModel(new File(costModelPath));
        AttackDefenseCollector collector = new AttackDefenseCollector(new File(vdmPath), new File(stemOutputDir), cyberInference);
        List<AttackDefenseCollector.Result> results = collector.perform();
        boolean sat = results.stream().allMatch(result -> Prob.lte(result.prob, result.cyberReq.getSeverity()));
        boolean performMeritAssignment = partialSolution && sat;
        DLeaf.Factory factory = new DLeaf.Factory();
        DTree dtree = DTreeConstructor.construct(results, costModel, partialSolution, performMeritAssignment, factory);
        Optional<ResultsInstance> selected = VerdictSynthesis.performSynthesisMultiple(dtree, factory, costModel, partialSolution, sat, performMeritAssignment, false);
        if (selected.isPresent()) {
            if (performMeritAssignment) {
                ResultsInstance withExtraDefProps = VerdictSynthesis.addExtraImplDefenses(selected.get(), collector.getImplDal(), costModel);
                withExtraDefProps.toFileXml(new File(outputPath));
            } else {
                selected.get().toFileXml(new File(outputPath));
            }
            log("Synthesis results output to " + outputPath);
        } else {
            logError("Synthesis failed");
        }
        sample.stop(Metrics.timer("Timer.mbas.synthesis", "model", modelName));
    } catch (IOException | MalformedInputException e) {
        throw new VerdictRunException("Failed to execute synthesis", e);
    }
    logHeader("Finished");
}
Also used : DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) DTree(com.ge.verdict.synthesis.dtree.DTree) VerdictStem(com.ge.verdict.stem.VerdictStem) CostModel(com.ge.verdict.synthesis.CostModel) AttackDefenseCollector(com.ge.verdict.attackdefensecollector.AttackDefenseCollector) IOException(java.io.IOException) ResultsInstance(com.ge.verdict.vdm.synthesis.ResultsInstance) Timer(io.micrometer.core.instrument.Timer) MalformedInputException(com.ge.verdict.attackdefensecollector.CSVFile.MalformedInputException) File(java.io.File)

Aggregations

VerdictStem (com.ge.verdict.stem.VerdictStem)2 Timer (io.micrometer.core.instrument.Timer)2 File (java.io.File)2 AttackDefenseCollector (com.ge.verdict.attackdefensecollector.AttackDefenseCollector)1 MalformedInputException (com.ge.verdict.attackdefensecollector.CSVFile.MalformedInputException)1 CostModel (com.ge.verdict.synthesis.CostModel)1 DLeaf (com.ge.verdict.synthesis.dtree.DLeaf)1 DTree (com.ge.verdict.synthesis.dtree.DTree)1 ResultsInstance (com.ge.verdict.vdm.synthesis.ResultsInstance)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 PumpStreamHandler (org.apache.tools.ant.taskdefs.PumpStreamHandler)1