use of com.ge.verdict.attackdefensecollector.adtree.ADOr 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.ADOr in project VERDICT by ge-high-assurance.
the class AttackDefenseCollector method perform.
/**
* Trace all cyber requirements, build attack-defense tree, and calculate probabilities for the
* loaded model.
*
* <p>The bulk of the work is actually done in SystemModel::trace and ConnectionModel::trace.
*/
public List<Result> perform() {
List<Result> output = new ArrayList<>();
// We are also ignoring whether or not the cyber requirement is in a mission
for (SystemModel system : sysNameToSystemModelMap.values()) {
for (CyberReq cyberReq : system.getCyberReqs()) {
Optional<ADTree> treeOpt = system.trace(cyberReq.getCondition());
// Crush the tree to remove redundant nodes
ADTree crushed = treeOpt.isPresent() ? treeOpt.get().crush() : new ADOr(Collections.emptyList(), true);
// not enabling this for now because it is potentially inefficient
// ADTree adtree = CutSetGenerator.generate(crushed);
ADTree adtree = crushed;
// Compute probability of attack
Prob computed = adtree.compute();
output.add(new Result(system, cyberReq, adtree, computed));
}
}
return output;
}
use of com.ge.verdict.attackdefensecollector.adtree.ADOr 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());
}
}
use of com.ge.verdict.attackdefensecollector.adtree.ADOr in project VERDICT by ge-high-assurance.
the class DTreeConstructorTest method testConstruct.
@Test
public void testConstruct() {
DLeaf.Factory factory = new DLeaf.Factory();
CostModel dummyCosts = new CostModel(new File(getClass().getResource("dummyCosts.xml").getPath()));
int dal = 5;
SystemModel system = new SystemModel("S1");
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.empty())));
ADTree adtree = new ADOr(new ADAnd(new ADNot(defense1), attack1));
Fraction[] costs = Util.fractionCosts(new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
DTree dtree = new DAnd(Collections.singletonList(new DOr(Collections.singletonList(new DOr(Collections.singletonList(new DAnd(Collections.singletonList(new DLeaf("S1", "D1", "A1", 0, dal, costs, factory)))))))));
Assertions.assertThat(DTreeConstructor.construct(adtree, dummyCosts, dal, false, false, factory).prettyPrint()).isEqualTo(dtree.prettyPrint());
}
use of com.ge.verdict.attackdefensecollector.adtree.ADOr in project VERDICT by ge-high-assurance.
the class DTreeConstructorTest method testUnmitigatedMixed.
@Test
public void testUnmitigatedMixed() {
DLeaf.Factory factory = new DLeaf.Factory();
CostModel dummyCosts = new CostModel(new File(getClass().getResource("dummyCosts.xml").getPath()));
int dal = 5;
SystemModel system = new SystemModel("S1");
Attack attack1 = new Attack(system.getAttackable(), "A1", "An attack", Prob.certain(), CIA.I);
Attack attack2 = new Attack(system.getAttackable(), "A2", "An attack", Prob.certain(), CIA.I);
Defense defense1 = new Defense(attack1);
defense1.addDefenseClause(Collections.singletonList(new Defense.DefenseLeaf("D1", Optional.empty())));
ADTree adtree = new ADOr(new ADNot(defense1), attack1, attack2);
Fraction[] costs = Util.fractionCosts(new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
DTree dtree = new DAnd(Arrays.asList(new DOr(Collections.singletonList(new DAnd(Collections.singletonList(new DLeaf("S1", "D1", "A1", 0, dal, costs, factory))))), new ALeaf(attack2)));
Assertions.assertThat(DTreeConstructor.construct(adtree, dummyCosts, dal, false, false, factory).prettyPrint()).isEqualTo(dtree.prettyPrint());
}
Aggregations