use of com.ge.verdict.attackdefensecollector.adtree.Attack in project VERDICT by ge-high-assurance.
the class VerdictSynthesisTest method partialSolutionTest.
@Test
public void partialSolutionTest() {
CostModel costModel = new CostModel(new File(getClass().getResource("partialCosts.xml").getPath()));
int dal = 2;
SystemModel system = new SystemModel("C1");
Attack attack1 = new Attack(system.getAttackable(), "A1", "An attack", Prob.certain(), CIA.I);
Defense defense1 = new Defense(attack1);
defense1.addDefenseClause(Collections.singletonList(new Defense.DefenseLeaf("D1", Optional.of(new com.ge.verdict.attackdefensecollector.Pair<>("D1", 1)))));
ADTree adtree = new ADOr(new ADAnd(new ADNot(defense1), attack1));
for (Approach approach : Approach.values()) {
{
DLeaf.Factory factoryPartial = new DLeaf.Factory();
Optional<Pair<Set<ComponentDefense>, Double>> resultPartial = VerdictSynthesis.performSynthesisSingle(DTreeConstructor.construct(adtree, costModel, dal, true, false, factoryPartial), dal, factoryPartial, approach);
Assertions.assertThat(resultPartial.isPresent());
Assertions.assertThat(resultPartial.get().right).isEqualTo(1);
}
{
DLeaf.Factory factoryTotal = new DLeaf.Factory();
Optional<Pair<Set<ComponentDefense>, Double>> resultTotal = VerdictSynthesis.performSynthesisSingle(DTreeConstructor.construct(adtree, costModel, dal, false, false, factoryTotal), dal, factoryTotal, approach);
Assertions.assertThat(resultTotal.isPresent());
Assertions.assertThat(resultTotal.get().right).isEqualTo(2);
}
}
}
use of com.ge.verdict.attackdefensecollector.adtree.Attack in project VERDICT by ge-high-assurance.
the class VerdictSynthesisTest method unmitigatedMixedTest.
@Test
public void unmitigatedMixedTest() {
DLeaf.Factory factory = new DLeaf.Factory();
SystemModel system = new SystemModel("S1");
int targetDal = 1;
Fraction[] costs = Util.fractionCosts(new double[] { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 });
DLeaf dleaf = new DLeaf("S1", "D1", "A2", 0, targetDal, costs, factory);
DTree dtree = new DOr(new ALeaf(new Attack(system.getAttackable(), "A1", "An attack", Prob.certain(), CIA.I)), dleaf);
for (Approach approach : Approach.values()) {
Optional<Pair<Set<ComponentDefense>, Double>> result = VerdictSynthesis.performSynthesisSingle(dtree, targetDal, factory, approach);
Assertions.assertThat(result.isPresent());
Assertions.assertThat(result.get().left).hasSize(1);
Assertions.assertThat(result.get().left).contains(dleaf.componentDefense);
Assertions.assertThat(result.get().right).isEqualTo(5);
}
}
use of com.ge.verdict.attackdefensecollector.adtree.Attack in project VERDICT by ge-high-assurance.
the class VerdictSynthesisTest method unmitigatedTest.
@Test
public void unmitigatedTest() {
DLeaf.Factory factory = new DLeaf.Factory();
SystemModel system = new SystemModel("S1");
DTree dtree = new ALeaf(new Attack(system.getAttackable(), "A1", "An attack", Prob.certain(), CIA.I));
for (Approach approach : Approach.values()) {
Assertions.assertThat(VerdictSynthesis.performSynthesisSingle(dtree, 1, factory, approach)).isEmpty();
}
}
use of com.ge.verdict.attackdefensecollector.adtree.Attack in project VERDICT by ge-high-assurance.
the class AttackDefenseCollector method loadAttacksDefensesFromCsv.
/**
* Load the attacks and defenses from CAPEC.csv and Defenses.csv, respectively.
*
* <p>This is factored out because it is used by both the CSV and VDM approaches.
*
* @param inputDir the STEM output directory
* @param connectionNameMap the map from connection names in the CSV files to the actual
* connection names
* @throws CSVFile.MalformedInputException
* @throws IOException
*/
private void loadAttacksDefensesFromCsv(String inputDir, Map<String, String> connectionNameMap) throws CSVFile.MalformedInputException, IOException {
// Load all the files as CSV
CSVFile capecCsv = new CSVFile(new File(inputDir, "CAPEC.csv"), true, "CompType", "CompInst", "CAPEC", "CAPECDescription", "Confidentiality", "Integrity", "Availability", "LikelihoodOfSuccess");
CSVFile defensesCsv = new CSVFile(new File(inputDir, "Defenses.csv"), true, "CompType", "CompInst", "CAPEC", "Confidentiality", "Integrity", "Availability", "ApplicableDefenseProperties", "ImplProperties", "DAL");
// Load attacks
for (CSVFile.RowData row : capecCsv.getRowDatas()) {
String systemTypeName = row.getCell("CompType");
String systemInstName = row.getCell("CompInst");
String attackName = row.getCell("CAPEC");
String attackDesc = row.getCell("CAPECDescription");
Prob likelihood = Prob.certain();
// Look at all three columns to figure out which one is being used
CIA cia = CIA.fromStrings(row.getCell("Confidentiality"), row.getCell("Integrity"), row.getCell("Availability"));
if ("Connection".equals(systemTypeName)) {
String connectionName = connectionNameMap.get(systemInstName);
for (ConnectionModel connection : connNameToConnectionModelMap.get(connectionName)) {
connection.getAttackable().addAttack(new Attack(connection.getAttackable(), attackName, attackDesc, likelihood, cia));
}
} else {
SystemModel system = getSystem(systemInstName);
system.getAttackable().addAttack(new Attack(system.getAttackable(), attackName, attackDesc, likelihood, cia));
}
}
// Note we don't use implemented property column in csv files if we vdm as input
for (CSVFile.RowData row : defensesCsv.getRowDatas()) {
String systemTypeName = row.getCell("CompType");
String systemInstName = row.getCell("CompInst");
String attackName = row.getCell("CAPEC");
CIA cia = CIA.fromStrings(row.getCell("Confidentiality"), row.getCell("Integrity"), row.getCell("Availability"));
List<String> defenseNames = Arrays.asList(row.getCell("ApplicableDefenseProperties").split(";")).stream().map(name -> name.length() > 0 ? Character.toString(name.charAt(0)).toLowerCase() + name.substring(1) : "").collect(Collectors.toList());
List<String> implProps = Arrays.asList(row.getCell("ImplProperties").split(";"));
List<String> likelihoodStrings = Arrays.asList(row.getCell("DAL").split(";"));
if (defenseNames.size() != implProps.size() || defenseNames.size() != likelihoodStrings.size()) {
throw new RuntimeException("ApplicableDefenseProperties, ImplProperties, and DAL must have same cardinality");
}
List<Defense> defenses = new ArrayList<>();
List<Defense.DefenseLeaf> clause = new ArrayList<>();
if ("Connection".equals(systemTypeName)) {
String connectionName = connectionNameMap.get(systemInstName);
for (ConnectionModel connection : connNameToConnectionModelMap.get(connectionName)) {
Defense defense = connection.getAttackable().getDefenseByAttackAndCia(attackName, cia);
if (defense == null) {
Attack attack = connection.getAttackable().getAttackByNameAndCia(attackName, cia);
if (attack == null) {
throw new RuntimeException("could not find attack: " + attackName + ", " + cia);
}
defense = new Defense(attack);
connection.getAttackable().addDefense(defense);
}
defenses.add(defense);
}
} else {
SystemModel system = getSystem(systemInstName);
Defense defense = system.getAttackable().getDefenseByAttackAndCia(attackName, cia);
if (defense == null) {
Attack attack = system.getAttackable().getAttackByNameAndCia(attackName, cia);
if (attack == null) {
throw new RuntimeException("could not find attack: " + attackName + ", " + cia);
}
defense = new Defense(attack);
system.getAttackable().addDefense(defense);
}
defenses.add(defense);
}
// TODO get defense descriptions from Defenses2NIST?
// Need to get correct name if connection
String entityName = "Connection".equals(systemTypeName) ? connectionNameMap.get(systemInstName) : systemInstName;
for (int i = 0; i < defenseNames.size(); i++) {
if (!"null".equals(defenseNames.get(i))) {
int dal = -1;
// it will be null if we are not loading from VDM
if (compDefenseToImplDal != null) {
// load DAL from VDM if available
Pair<String, String> pair = new Pair<>(entityName, defenseNames.get(i));
if (compDefenseToImplDal.containsKey(pair)) {
dal = compDefenseToImplDal.get(pair);
} else {
// if there is no binding present, then it is not implemented
dal = 0;
}
}
// this code treats applicable defense and impl defense as separate things
// but we have changed the capitalization so that they should be the same
Optional<Pair<String, Integer>> impl;
if (dal == -1) {
impl = "null".equals(implProps.get(i)) ? Optional.empty() : Optional.of(new Pair<>(implProps.get(i), Integer.parseInt(likelihoodStrings.get(i))));
} else {
impl = dal == 0 ? Optional.empty() : Optional.of(new Pair<>(defenseNames.get(i), dal));
}
clause.add(new Defense.DefenseLeaf(defenseNames.get(i), impl));
}
}
// And there are potentially multiple such rows, forming a DNF
for (Defense defense : defenses) {
defense.addDefenseClause(clause);
}
}
}
use of com.ge.verdict.attackdefensecollector.adtree.Attack in project VERDICT by ge-high-assurance.
the class DTreeConstructor method constructInternal.
/**
* Inductively-defined function over attack-defense trees.
*
* <p>The mapping from attack-defense tree to defense tree is pretty straightforward. One of the
* most important things to note is that AND and OR nodes are transposed in the transformation
* because they mean opposite things in a defense tree compared to an attack-defense tree. (An
* attack-defense tree is "how to attack", whereas a defense tree is "how to defend".)
*
* @param adtree
* @return
*/
private Optional<DTree> constructInternal(ADTree adtree) {
if (adtree instanceof Attack) {
Attack attack = (Attack) adtree;
ALeaf aleaf = new ALeaf(attack);
// keep track of all attack leaves
if (!attackALeafMap.containsKey(attack)) {
attackALeafMap.put(attack, new LinkedHashSet<>());
}
attackALeafMap.get(attack).add(aleaf);
return Optional.of(aleaf);
} else if (adtree instanceof Defense) {
Defense defense = (Defense) adtree;
defenses.add(defense);
return Optional.of(new DNot(constructDefenseTree(defense)));
} else if (adtree instanceof ADAnd) {
ADAnd adand = (ADAnd) adtree;
// Transpose and/or
return Optional.of(new DOr(adand.children().stream().map(this::constructInternal).flatMap(elem -> elem.isPresent() ? Stream.of(elem.get()) : Stream.empty()).collect(Collectors.toList())));
} else if (adtree instanceof ADOr) {
ADOr ador = (ADOr) adtree;
// Transpose and/or
return Optional.of(new DAnd(ador.children().stream().map(this::constructInternal).flatMap(elem -> elem.isPresent() ? Stream.of(elem.get()) : Stream.empty()).collect(Collectors.toList())));
} else if (adtree instanceof ADNot) {
ADNot adnot = (ADNot) adtree;
return constructInternal(adnot.child()).map(DNot::new);
} else if (adtree instanceof DefenseCondition) {
DCondition dcond = new DCondition((DefenseCondition) adtree);
dconditions.add(dcond);
return Optional.of(dcond);
} else {
throw new RuntimeException("got invalid adtree type: " + adtree.getClass().getCanonicalName());
}
}
Aggregations