Skip to content
Snippets Groups Projects
Commit 9b401249 authored by apvrille's avatar apvrille
Browse files

Adding attack name checking

parent 009d8f8a
No related branches found
No related tags found
No related merge requests found
......@@ -38,7 +38,7 @@
<property name="caretWidth" class="java.lang.Integer" />
</properties>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="false" project-jdk-name="1.7" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
......@@ -37,8 +37,6 @@
*/
package attacktrees;
import java.util.ArrayList;
......@@ -47,59 +45,54 @@ import java.util.ArrayList;
/**
* Class Attack
* Creation: 10/04/2015
* @version 1.0 10/04/2015
*
* @author Ludovic APVRILLE
* @version 1.0 10/04/2015
*/
public class Attack {
public class Attack extends AttackElement {
private AttackNode originNode; // If no origin node -> leaf attack
private ArrayList<AttackNode> destinationNodes;
private String name;
private Object referenceObject;
private boolean isRoot;
private boolean isEnabled = true;
public Attack(String _name, Object _referenceObject) {
name = _name;
referenceObject = _referenceObject;
destinationNodes = new ArrayList<AttackNode>();
super(_name, _referenceObject);
destinationNodes = new ArrayList<AttackNode>();
}
public boolean isRoot() {
return isRoot;
return isRoot;
}
public void setRoot(boolean _root) {
isRoot = _root;
isRoot = _root;
}
public boolean isEnabled() {
return isEnabled;
return isEnabled;
}
public void setEnabled(boolean _enabled) {
isEnabled = _enabled;
isEnabled = _enabled;
}
public void setOriginNode(AttackNode _node) {
originNode = _node;
originNode = _node;
}
public void addDestinationNode(AttackNode _node) {
destinationNodes.add(_node);
destinationNodes.add(_node);
}
public String getName() {
return name;
}
public boolean isLeaf() {
return (originNode == null);
return (originNode == null);
}
public boolean isFinal() {
return destinationNodes.size() == 0;
}
}
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
* ludovic.apvrille AT enst.fr
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package attacktrees;
import java.util.ArrayList;
/**
* Class AttackElement
* Creation: 31/01/2018
*
* @author Ludovic APVRILLE
* @version 1.0 31/01/2018
*/
public abstract class AttackElement {
protected String name;
protected Object referenceObject;
public AttackElement(String _name, Object _referenceObject) {
name = _name;
referenceObject = _referenceObject;
}
public String getName() {
return name;
}
public Object getReferenceObject() { return referenceObject; }
}
......@@ -37,8 +37,6 @@
*/
package attacktrees;
import java.util.ArrayList;
......@@ -48,87 +46,84 @@ import java.util.Collections;
/**
* Class AttackNode
* Creation: 10/04/2015
* @version 1.0 10/04/2015
*
* @author Ludovic APVRILLE
* @version 1.0 10/04/2015
*/
public abstract class AttackNode {
public abstract class AttackNode extends AttackElement {
private Attack resultingAttack; // If no resulting attack -> error!
private ArrayList<Attack> inputAttacks;
private ArrayList<Integer> inputValues;
private String name;
protected String type = "";
protected Object referenceObject;
public AttackNode(String _name, Object _referenceObject) {
name = _name;
referenceObject = _referenceObject;
inputAttacks = new ArrayList<Attack>();
inputValues = new ArrayList<Integer>();
super(_name, _referenceObject);
inputAttacks = new ArrayList<Attack>();
inputValues = new ArrayList<Integer>();
}
// At least one input and one output
public boolean isWellFormed() {
if (resultingAttack == null) {
return false;
}
if (resultingAttack == null) {
return false;
}
return inputAttacks.size() >= 1;
}
public String getName() { return name;}
public void setResultingAttack(Attack _attack) {
resultingAttack = _attack;
resultingAttack = _attack;
}
public Attack getResultingAttack() {
return resultingAttack;
return resultingAttack;
}
public ArrayList<Attack> getInputAttacks() {
return inputAttacks;
return inputAttacks;
}
public void addInputAttack(Attack _attack, Integer _val) {
inputAttacks.add(_attack);
inputValues.add(_val);
inputAttacks.add(_attack);
inputValues.add(_val);
}
public String toString() {
String ret = name + "/" + type + " Incoming attacks: ";
for (Attack att: inputAttacks) {
ret += att.getName() + " ";
}
if (resultingAttack == null) {
ret += " No resulting attack";
} else {
ret += " Resulting attack:" + resultingAttack.getName();
}
return ret;
String ret = name + "/" + type + " Incoming attacks: ";
for (Attack att : inputAttacks) {
ret += att.getName() + " ";
}
if (resultingAttack == null) {
ret += " No resulting attack";
} else {
ret += " Resulting attack:" + resultingAttack.getName();
}
return ret;
}
// Order attacks according to the Integer value
public void orderAttacks() {
ArrayList<Attack> newAttacks = new ArrayList<Attack>();
ArrayList<Integer> newInputValues = new ArrayList<Integer>();
ArrayList<Attack> newAttacks = new ArrayList<Attack>();
ArrayList<Integer> newInputValues = new ArrayList<Integer>();
for(Integer i: inputValues) {
newInputValues.add(i);
}
for (Integer i : inputValues) {
newInputValues.add(i);
}
// sort newInputValues
Collections.sort(newInputValues);
// sort newInputValues
Collections.sort(newInputValues);
for(Integer i: newInputValues) {
int index = inputValues.indexOf(i);
newAttacks.add(inputAttacks.get(index));
}
for (Integer i : newInputValues) {
int index = inputValues.indexOf(i);
newAttacks.add(inputAttacks.get(index));
}
inputAttacks = newAttacks;
inputValues = newInputValues;
inputAttacks = newAttacks;
inputValues = newInputValues;
}
}
......@@ -37,8 +37,6 @@
*/
package attacktrees;
import java.util.ArrayList;
......@@ -47,47 +45,48 @@ import java.util.ArrayList;
/**
* Class AttackTree
* Creation: 10/04/2015
* @version 1.0 10/04/2015
*
* @author Ludovic APVRILLE
* @version 1.0 10/04/2015
*/
public class AttackTree {
public class AttackTree extends AttackElement {
private ArrayList<AttackNode> nodes;
private ArrayList<Attack> attacks;
private String name;
Object reference;
public AttackElement faultyElement;
public String errorOfFaultyElement;
public AttackTree(String _name, Object _reference) {
name = _name;
reference = _reference;
nodes = new ArrayList<AttackNode>();
attacks = new ArrayList<Attack>();
super(_name, _reference);
nodes = new ArrayList<AttackNode>();
attacks = new ArrayList<Attack>();
}
public void addNode(AttackNode _node) {
nodes.add(_node);
nodes.add(_node);
}
public void addAttack(Attack _attack) {
attacks.add(_attack);
attacks.add(_attack);
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("List of nodes:");
for(AttackNode an: nodes) {
sb.append(" " + an.toString() + "\n");
}
return sb.toString();
StringBuffer sb = new StringBuffer();
sb.append("List of nodes:");
for (AttackNode an : nodes) {
sb.append(" " + an.toString() + "\n");
}
return sb.toString();
}
public ArrayList<Attack> getAttacks() {
return attacks;
return attacks;
}
public ArrayList<AttackNode> getAttackNodes() {
return nodes;
return nodes;
}
// Checks:
......@@ -96,7 +95,22 @@ public class AttackTree {
// Attack name is unique
// Node name is unique
public boolean checkSyntax() {
return true;
// Attack name is unique
for(int i=0; i<attacks.size()-1; i++) {
Attack atti = attacks.get(i);
for(int j=i+1; j<attacks.size(); j++) {
//myutil.TraceManager.addDev("i=" + i + " j=" + j + " size=" + attacks.size());
Attack attj = attacks.get(j);
//myutil.TraceManager.addDev("i=" + atti.getName() + " j=" + attj.getName() + " size=" + attacks.size());
if (atti.getName().compareTo(attj.getName()) == 0) {
faultyElement = atti;
errorOfFaultyElement = "Duplicate name for attack: " + atti.getName();
return false;
}
}
}
return true;
}
}
......@@ -37,47 +37,46 @@
*/
package translator;
/**
* Class JKeyword
* Creation: 03/03/2005
* @version 1.1 03/03/2005
*
* @author Ludovic APVRILLE
* @version 1.1 03/03/2005
*/
public class JKeyword {
private final static String [] words = {"abstract", "default", "goto", "package", "synchronized", "boolean", "do", "if", "private", "this", "break", "double", "implements",
"protected", "throw", "byte", "else", "import", "public", "throws", "case", "enum", "instanceof", "return", "transient", "catch", "extends", "int", "short", "try", "char", "final",
"interface", "static", "void", "class", "finally", "long", "strictfp", "volatile", "const", "float", "native", "super", "while", "continue", "for", "new", "switch", "select"};
private final static String[] words = {"abstract", "default", "goto", "package", "synchronized", "boolean", "do", "if", "private", "this", "break", "double", "implements",
"protected", "throw", "byte", "else", "import", "public", "throws", "case", "enum", "instanceof", "return", "transient", "catch", "extends", "int", "short", "try", "char", "final",
"interface", "static", "void", "class", "finally", "long", "strictfp", "volatile", "const", "float", "native", "super", "while", "continue", "for", "new", "switch", "select"};
public final static String INDENT = " ";
public final static String END_OP = ";";
public final static String END_OP_N = ";\n";
public final static String ATTRIBUTE_SEP = ",";
public final static String ATTRIBUTE_AFFECT = "=";
public final static String START_CODE = "{";
public final static String START_CODE_N = "{\n";
public final static String STOP_CODE = "}";
public final static String STOP_CODE_N = "}\n";
public static final String PRIVATE = "private";
public static final String PUBLIC = "public";
public static final String PROTECTED = "protected";
public static final String INTEGER = "int";
public static final String LONG = "long";
public static final String BOOLEAN = "boolean";
public static final String STATIC = "static";
public static final String VOID = "void";
public final static String INDENT = " ";
public final static String END_OP = ";";
public final static String END_OP_N = ";\n";
public final static String ATTRIBUTE_SEP = ",";
public final static String ATTRIBUTE_AFFECT = "=";
public final static String START_CODE = "{";
public final static String START_CODE_N = "{\n";
public final static String STOP_CODE = "}";
public final static String STOP_CODE_N = "}\n";
public static final String PRIVATE = "private" ;
public static final String PUBLIC = "public" ;
public static final String PROTECTED = "protected" ;
public static final String INTEGER = "int" ;
public static final String LONG = "long" ;
public static final String BOOLEAN = "boolean" ;
public static final String STATIC = "static" ;
public static final String VOID = "void" ;
public static boolean isAKeyword(String s) {
for(int i=0; i<words.length; i++) {
for (int i = 0; i < words.length; i++) {
if (words[i].equals(s)) {
return true;
}
}
return false;
}
}
}
\ No newline at end of file
......@@ -95,6 +95,14 @@ public class AttackTreePanelTranslator {
for (TDiagramPanel panel : atp.panels) {
if (panel instanceof AttackTreeDiagramPanel) {
translate((AttackTreeDiagramPanel) panel);
boolean b = at.checkSyntax();
if (!b) {
UICheckingError ce = new UICheckingError(CheckingError.STRUCTURE_ERROR, at.errorOfFaultyElement);
ce.setTGComponent((TGComponent) (at.faultyElement.getReferenceObject()));
ce.setTDiagramPanel(panel);
addCheckingError(ce);
}
return at;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment