Commit d5496f70 authored by Paff's avatar Paff
Browse files

analysis bug fixes,

transform workflow for trustlevel -1
parent 0845d8a3
......@@ -3,6 +3,8 @@
* http://www.monticore.de/ - http://www.se-rwth.de/ */
package secarc;
import java.util.List;
import com.google.inject.Inject;
import interfaces2.language.ILanguage;
......@@ -19,6 +21,7 @@ import secarc.ets.check.MontiSecArcAnalysisCreator;
import secarc.ets.check.MontiSecArcAnalysisVisitor;
import secarc.ets.check.MontiSecArcAnalysisWorkflow;
import secarc.ets.transform.PreCoCoCheckMontiSecArcTransformationWorkflow;
import secarc.ets.transform.trustlevel.PreAnalysisTrustlevelTransformationWorkflow;
/**
* As subclass of {@link ModelingLanguage}, this class configures the technical
......@@ -36,17 +39,17 @@ public final class MontiSecArcAnalysis extends MontiSecArc {
public static final Class<? extends MontiSecArcRoot> LANGUAGE_ROOT = MontiSecArcRoot.class;
/**
* Factory method for {@link MontiSecArcAnalysis}.
* Factory method for {@link MontiSecArcAnalysis}.l
*/
public static MontiSecArcAnalysis newLanguage(ILanguage component) {
return new MontiSecArcAnalysis(component);
public static MontiSecArcAnalysis newLanguage(ILanguage component, List<String> analysisParameter, boolean critical) {
return new MontiSecArcAnalysis(component, analysisParameter, critical);
}
/**
* Constructor for secarc.MontiSecArcAnalysis
*/
@Inject
public MontiSecArcAnalysis(final ILanguage component) {
public MontiSecArcAnalysis(final ILanguage component, List<String> analysisParameter, boolean critical) {
super(component);
// PARSING-SETUP
......@@ -79,9 +82,45 @@ public final class MontiSecArcAnalysis extends MontiSecArc {
//AnalysisConfiguratin
analysisWorkflow.setAnalysisConfiguration(MontiSecArcAnalysisCreator.createConfig());
//Visitor for Analysis
analysisWorkflow.setClient(new MontiSecArcAnalysisVisitor());
//Add Workflow for Analysis
addExecutionUnit("secAnalysis", analysisWorkflow);
MontiSecArcAnalysisVisitor analysisVisitor = new MontiSecArcAnalysisVisitor();
analysisVisitor.setAdvanced(false);
analysisVisitor.setAnalysisParameter(analysisParameter);
analysisVisitor.setCiritical(critical);
analysisWorkflow.setClient(analysisVisitor);
//Add Workflow for Analysis for beginners
addExecutionUnit(MontiSecArcConstants.ANALYSIS_WORKFLOW_BEGINNERS, analysisWorkflow);
//Add Workflow for Analysis for advanced users
analysisVisitor.setAdvanced(true);
analysisWorkflow.setClient(analysisVisitor);
addExecutionUnit(MontiSecArcConstants.ANALYSIS_WORKFLOW_ADVANCED, analysisWorkflow);
PreAnalysisTrustlevelTransformationWorkflow<MontiSecArcRoot> trustlevelTransformationWorkflow = new PreAnalysisTrustlevelTransformationWorkflow<MontiSecArcRoot>(MontiSecArcRoot.class);
trustlevelTransformationWorkflow.setAnalysisParameter(analysisParameter);
addExecutionUnit("transformTrustlevel", trustlevelTransformationWorkflow);
//Workflow for Analysis
MontiSecArcAnalysisWorkflow<MontiSecArcRoot> analysisTransformWorkflow = new MontiSecArcAnalysisWorkflow<MontiSecArcRoot>(LANGUAGE_ROOT);
//AnalysisCreator
analysisTransformWorkflow.setAnalysis(MontiSecArcAnalysisCreator.createAnalysis());
//AnalysisConfiguratin
analysisTransformWorkflow.setAnalysisConfiguration(MontiSecArcAnalysisCreator.createConfig());
//Visitor for Analysis
MontiSecArcAnalysisVisitor analysisTransfromVisitor = new MontiSecArcAnalysisVisitor();
analysisTransfromVisitor.setAdvanced(false);
analysisTransfromVisitor.setAnalysisParameter(analysisParameter);
analysisTransfromVisitor.setCiritical(critical);
analysisTransformWorkflow.setClient(analysisTransfromVisitor);
//Add Workflow for Analysis for beginners: what if
addExecutionUnit(MontiSecArcConstants.ANALYSIS_WORKFLOW_BEGINNERS_WHAT_IF, analysisTransformWorkflow);
//Add Workflow for Analysis for advanced users
analysisTransfromVisitor.setAdvanced(true);
analysisTransformWorkflow.setClient(analysisVisitor);
//Add Workflow for Analysis for advanced users: what if
addExecutionUnit(MontiSecArcConstants.ANALYSIS_WORKFLOW_ADVANCED_WHAT_IF, analysisTransformWorkflow);
}
......
package secarc;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.google.inject.Guice;
......@@ -30,27 +32,107 @@ public class MontiSecArcAnalysisTool extends ETSTool {
*/
public static void main(String[] arguments) {
MCG.initMonticoreGlobals();
MontiSecArcAnalysisTool tool = new MontiSecArcAnalysisTool(arguments);
List<String> analysisParameter = getAnalysisParameter(arguments);
boolean critical = isAnalysisCritical(arguments);
MontiSecArcAnalysisTool tool = new MontiSecArcAnalysisTool(cleanArgumentList(arguments), analysisParameter, critical);
tool.init();
tool.run();
}
/**
* Checks if the analysis shall be used for critical ports
*
* @param arguments
* @return true if analysis parameter -crictical is used
*/
protected static boolean isAnalysisCritical(String[] arguments) {
for(String argument : arguments) {
if(argument.equals(MontiSecArcConstants.ANALYSIS_CIRITICAL_PORTS)) {
return true;
}
}
return false;
}
/**
* Searches for analysis parameters
*
* @param arguments
* @return List with parameters for analysis
*/
protected static List<String> getAnalysisParameter(String[] arguments) {
boolean isAnalysisParameter = false;
List<String> analysisParameter = new ArrayList<String>();
for(String argument : arguments) {
//Search for beginning of parameters
if(argument.equals(MontiSecArcConstants.ANALYSIS_WORKFLOW_BEGINNERS) || argument.equals(MontiSecArcConstants.ANALYSIS_WORKFLOW_ADVANCED)) {
isAnalysisParameter = true;
continue;
}
if(isAnalysisParameter) {
//New parameter
if(argument.contains("-") || argument.contains("/")) {
break;
}
analysisParameter.add(argument);
}
}
return analysisParameter;
}
/**
* Cleans argument list form analysis parameters
*
* @param arguments
* @return cleaned list
*/
protected static String[] cleanArgumentList(String[] arguments) {
List<String> cleanedArguments = new ArrayList<String>();
boolean isAnalysisParameter = false;
for(String argument : arguments) {
if(argument.equals(MontiSecArcConstants.ANALYSIS_CIRITICAL_PORTS)) {
continue;
}
if(argument.equals(MontiSecArcConstants.ANALYSIS_WORKFLOW_BEGINNERS) || argument.equals(MontiSecArcConstants.ANALYSIS_WORKFLOW_ADVANCED)) {
isAnalysisParameter = true;
cleanedArguments.add(argument);
continue;
}
if(isAnalysisParameter) {
//New parameter
if(argument.contains("-") || argument.contains("/")) {
isAnalysisParameter = false;
cleanedArguments.add(argument);
}
continue;
}
cleanedArguments.add(argument);
}
return cleanedArguments.toArray(new String[cleanedArguments.size()]);
}
/**
* Constructor for secarc.MontiSecArcAnalysisTool
*
* @param arguments
*/
public MontiSecArcAnalysisTool(String[] arguments) {
public MontiSecArcAnalysisTool(String[] arguments, List<String> analysisParameter, boolean critical) {
super(arguments);
Injector injector = Guice.createInjector(new MontiSecArcDefaultModule());
InjectorProvider.setInjector(injector);
LanguageFamily languageFamily = new LanguageFamily();
languageFamily.addLanguage(MontiSecArcAnalysis.newLanguage(injector.getInstance(MontiSecArcComponent.class)));
languageFamily.addLanguage(MontiSecArcAnalysis.newLanguage(injector.getInstance(MontiSecArcComponent.class), analysisParameter, critical));
setLanguages(languageFamily);
// set default CoCos
......
......@@ -145,4 +145,14 @@ public enum MontiSecArcAnalysisErrorCodes implements IErrorCode {
* For a trustlevel relation should exist trustlevels
*/
TrustlevelForTrustlevelrelation,
/**
* If an identity link is defined, the target should define roles
*/
IdentityWithoutRoles,
/**
* The referenced component for the what if analysis does not exist
*/
ReferencedComponentWhatIfDoNotExist,
}
......@@ -25,6 +25,6 @@ public interface ISecAnalysisComponentChecker {
* @param entry
* @throws AmbigousException
*/
void check(ASTArcComponent node, SecComponentEntry entry) throws AmbigousException;
void check(ASTArcComponent node, SecComponentEntry entry, boolean advanced) throws AmbigousException;
}
......@@ -23,6 +23,6 @@ public interface ISecAnalysisConfigurationChecker {
* @param node
* @param entry
*/
void check(ASTSecArcConfiguration node, ConfigurationEntry entry);
void check(ASTSecArcConfiguration node, ConfigurationEntry entry, boolean advanced);
}
......@@ -27,7 +27,7 @@ public interface ISecAnalysisConnectorChecker {
* @param entry
* @throws AmbigousException
*/
void check(ASTArcConnector node, SecConnectorEntry entry, ArchitectureGraph graph) throws AmbigousException;
void check(ASTArcConnector node, SecConnectorEntry entry, ArchitectureGraph graph, boolean advanced) throws AmbigousException;
/**
*
......@@ -35,6 +35,6 @@ public interface ISecAnalysisConnectorChecker {
* @param entry entry related connector entry to be checked
* @throws AmbigousException
*/
void check(ASTArcSimpleConnector node, SecConnectorEntry entry, ArchitectureGraph graph) throws AmbigousException;
void check(ASTArcSimpleConnector node, SecConnectorEntry entry, ArchitectureGraph graph, boolean advanced) throws AmbigousException;
}
......@@ -27,6 +27,6 @@ public interface ISecAnalysisFilterChecker {
* @param graph
* @throws AmbigousException
*/
void check(ASTSecArcFilter node, FilterEntry entry, ArchitectureGraph graph) throws AmbigousException;;
void check(ASTSecArcFilter node, FilterEntry entry, ArchitectureGraph graph, boolean advanced) throws AmbigousException;;
}
......@@ -27,6 +27,6 @@ public interface ISecAnalysisIdentityChecker {
* @param graph
* @throws AmbigousException
*/
void check(ASTSecArcIdentity node, IdentityEntry entry, ArchitectureGraph graph) throws AmbigousException;
void check(ASTSecArcIdentity node, IdentityEntry entry, ArchitectureGraph graphConnectorEdges, ArchitectureGraph graphIdentityEdges, boolean advanced) throws AmbigousException;
}
package secarc.ets.analysis.checker;
import interfaces2.resolvers.AmbigousException;
import mc.umlp.arcd._ast.ASTMCCompilationUnit;
/**
* Analysis checker interface for checking parameter
* related analysis
*
* <br>
* <br>
* Copyright (c) 2011 RWTH Aachen. All rights reserved
*
* @author (last commit) $Author$
* @version $Date$<br>
* $Revision$
*
*/
public interface ISecAnalysisParameterChecker {
/**
*
* @param parameter
*/
void check(ASTMCCompilationUnit node, String parameter) throws AmbigousException;
}
......@@ -27,6 +27,6 @@ public interface ISecAnalysisPortChecker {
* @param graph
* @throws AmbigousException
*/
void check(ASTArcPort node, SecPortEntry entry, ArchitectureGraph graph) throws AmbigousException;
void check(ASTArcPort node, SecPortEntry entry, ArchitectureGraph graph, boolean advanced) throws AmbigousException;
}
......@@ -27,6 +27,6 @@ public interface ISecAnalysisRoleChecker {
* @param graph
* @throws AmbigousException
*/
void check(ASTSecArcRole node, RoleEntry entry, ArchitectureGraph graph) throws AmbigousException;
void check(ASTSecArcRole node, RoleEntry entry, ArchitectureGraph graph, boolean advanced) throws AmbigousException;
}
......@@ -26,6 +26,6 @@ public interface ISecAnalysisTrustlevelRelationChecker {
* @param graph
* @throws AmbigousException
*/
void check(ASTSecArcTrustlevelRelation node, TrustlevelRelationEntry entry) throws AmbigousException;
void check(ASTSecArcTrustlevelRelation node, TrustlevelRelationEntry entry, boolean advanced) throws AmbigousException;
}
......@@ -34,7 +34,7 @@ public class ListThirdPartyComponents extends Analysis implements
* @see secarc.ets.analysis.checker.ISecAnalysisComponentChecker#check(mc.umlp.arcd._ast.ASTArcComponent, secarc.ets.entries.SecComponentEntry)
*/
@Override
public void check(ASTArcComponent node, SecComponentEntry entry)
public void check(ASTArcComponent node, SecComponentEntry entry, boolean advanced)
throws AmbigousException {
if(entry.getConfiguration() != null && entry.getVersion() != null) {
addReport("The third party component " + NameHelper.getSimplenameFromComplexname(entry.getName()) + " has the version " + entry.getVersion().getVersion() + " and configuration " + entry.getConfiguration().getName() + ".", node.get_SourcePositionStart());
......
......@@ -36,7 +36,7 @@ public class ReviewedConfiguration extends Analysis implements
* (non-Javadoc)
* @see secarc.ets.analysis.checker.ISecConfigurationChecker#check(secarc._ast.ASTSecArcConfiguration, secarc.ets.entries.ConfigurationEntry)
*/
public void check(ASTSecArcConfiguration node, ConfigurationEntry entry) {
public void check(ASTSecArcConfiguration node, ConfigurationEntry entry, boolean advanced) {
String name = entry.getName();
if(!name.endsWith("_reviewed")) {
addReport("The configuration " + name + " is not reviewed, yet. After the configuration is reviewed, a \"_reviewed\" must be added to the configuration's name.", node.get_SourcePositionStart());
......
......@@ -20,6 +20,19 @@ import secarc.ets.graph.ArchitectureGraph;
import secarc.ets.graph.Edge;
import secarc.ets.graph.Vertex;
/**
* Checks if an encrypted path continues unencrypted.
* Then the message is readable for the following components
*
* <br>
* <br>
* Copyright (c) 2011 RWTH Aachen. All rights reserved
*
* @author (last commit) $Author$
* @version $Date$<br>
* $Revision$
*
*/
public class EncryptedPathContinuesUnencrypted extends Analysis implements
ISecAnalysisPortChecker {
......@@ -29,7 +42,7 @@ public class EncryptedPathContinuesUnencrypted extends Analysis implements
@Override
public void check(ASTArcPort node, SecPortEntry entry,
ArchitectureGraph graph) throws AmbigousException {
ArchitectureGraph graph, boolean advanced) throws AmbigousException {
//Checks if the port is a target of an encrypted connection
ConnectorEntry connectorEntry = AnalysisHelper.isPortBenningOfPath(entry, graph);
......@@ -66,7 +79,7 @@ public class EncryptedPathContinuesUnencrypted extends Analysis implements
element = iterator.next().getArchitectureElement();
//Next path
if(element.equals(entry) || !iterator.hasNext()) {
if(element.equals(entry)) {
unencryptedEnds = false;
sbuilder.append(", ");
count = 0;
......
......@@ -48,7 +48,7 @@ public class EncryptedPathWithUnencryptedPart extends Analysis
* (non-Javadoc)
* @see secarc.ets.cocos.checkers.ISecPortChecker#check(mc.umlp.arcd._ast.ASTArcPort, secarc.ets.entries.SecPortEntry)
*/
public void check(ASTArcPort node, SecPortEntry entry, ArchitectureGraph graph) throws AmbigousException{
public void check(ASTArcPort node, SecPortEntry entry, ArchitectureGraph graph, boolean advanced) throws AmbigousException{
//Checks if the path starts with this port
if(AnalysisHelper.isPortBenningOfPath(entry, graph) != null) {
......@@ -96,7 +96,7 @@ public class EncryptedPathWithUnencryptedPart extends Analysis
}
//New path starts
if((element instanceof PortEntry && ((PortEntry) element).getName().equals(entry.getName())) ||
if((element instanceof PortEntry && element.equals(entry)) ||
!iterator.hasNext()) {
//Check if info is needed
if(!path.isEmpty()) {
......
......@@ -9,8 +9,8 @@ import mc.umlp.arcd.ets.entries.ComponentEntry;
import mc.umlp.arcd.ets.entries.SubComponentEntry;
import interfaces2.resolvers.AmbigousException;
import secarc.error.MontiSecArcAnalysisErrorCodes;
import secarc.ets.analysis.checker.Analysis;
import secarc.ets.analysis.checker.ISecAnalysisConnectorChecker;
import secarc.ets.analysis.trustlevel.DerivedTrustlevel;
import secarc.ets.check.CoCoHelper;
import secarc.ets.check.MontiSecArcAnalysisConstants;
import secarc.ets.entries.SecComponentEntry;
......@@ -32,19 +32,29 @@ import secarc.ets.graph.ArchitectureGraph;
* $Revision$
*
*/
public class UnencryptedConnectorThroughLowTurstlevel extends Analysis
public class UnencryptedConnectorThroughLowTurstlevel extends DerivedTrustlevel
implements ISecAnalysisConnectorChecker {
public UnencryptedConnectorThroughLowTurstlevel() {
super(MontiSecArcAnalysisConstants.UNENCRYPTED_CONNECTOR_THROUGH_LOW_TRUSTLEVEL);
}
/*
* (non-Javadoc)
* @see secarc.ets.analysis.checker.ISecAnalysisComponentChecker#check(mc.umlp.arcd._ast.ASTArcComponent, secarc.ets.entries.SecComponentEntry)
*/
@Override
public void check(ASTArcComponent node, SecComponentEntry entry, boolean advanced)
throws AmbigousException {
}
/*
* (non-Javadoc)
* @see secarc.ets.analysis.checker.ISecAnalysisConnectorChecker#check(cc.clarc.lang.architecture._ast.ASTArcConnector, secarc.ets.entries.SecConnectorEntry)
*/
@Override
public void check(ASTArcConnector node, SecConnectorEntry entry, ArchitectureGraph graph)
public void check(ASTArcConnector node, SecConnectorEntry entry, ArchitectureGraph graph, boolean advanced)
throws AmbigousException {
innerCheck(node, entry, node.getMainParent());
}
......@@ -54,7 +64,7 @@ public class UnencryptedConnectorThroughLowTurstlevel extends Analysis
* @see secarc.ets.analysis.checker.ISecAnalysisConnectorChecker#check(mc.umlp.arcd._ast.ASTArcSimpleConnector, secarc.ets.entries.SecConnectorEntry)
*/
@Override
public void check(ASTArcSimpleConnector node, SecConnectorEntry entry, ArchitectureGraph graph)
public void check(ASTArcSimpleConnector node, SecConnectorEntry entry, ArchitectureGraph graph, boolean advanced)
throws AmbigousException {
innerCheck(node, entry, node.getMainParent());
}
......@@ -116,8 +126,8 @@ public class UnencryptedConnectorThroughLowTurstlevel extends Analysis
parentTrustlevel = CoCoHelper.getTrustlevelAsString(parentComp);
parentTrustlevelCompare = CoCoHelper.getTrustlevelAsInteger(parentComp);
} else {
parentTrustlevel = CoCoHelper.getTrustlevelAsString(getTrustlevel(nodeParent));
parentTrustlevelCompare = CoCoHelper.getTrustlevelAsInteger(getTrustlevel(nodeParent));
parentTrustlevel = CoCoHelper.getTrustlevelAsString(getDerivedTrustlevel(nodeParent));
parentTrustlevelCompare = CoCoHelper.getTrustlevelAsInteger(getDerivedTrustlevel(nodeParent));
}
int sourceTrustlevelCompare = -1;
......@@ -145,26 +155,6 @@ public class UnencryptedConnectorThroughLowTurstlevel extends Analysis
}
}
/**
* Search for trustlevel in super components
* @param node
* @return trustlevel
* @throws AmbigousException
*/
private SecComponentEntry getTrustlevel(ASTArcComponent node) throws AmbigousException {
ASTArcComponent parent = node.getMainParent();
if(parent != null) {
SecComponentEntry componentParent = (SecComponentEntry) resolver.resolve(parent.getName(), ComponentEntry.KIND, getNameSpaceFor(parent));
if(componentParent.getTrustlevel().isPresent()) {
return componentParent;
} else {
return getTrustlevel(parent);
}
} else {
return null;
}
}
/*
* (non-Javadoc)
......
......@@ -11,6 +11,18 @@ import secarc.ets.check.MontiSecArcAnalysisConstants;
import secarc.ets.entries.SecPortEntry;
import secarc.ets.graph.ArchitectureGraph;
/**
* String is a very unspecific input type. Therfore, it should be avoided
*
* <br>
* <br>
* Copyright (c) 2011 RWTH Aachen. All rights reserved
*
* @author (last commit) $Author$
* @version $Date$<br>
* $Revision$
*
*/
public class AvoidInputString extends Analysis implements
ISecAnalysisPortChecker {
......@@ -18,9 +30,13 @@ public class AvoidInputString extends Analysis implements
super(MontiSecArcAnalysisConstants.AVOID_INPUT_STRING);
}
/*
* (non-Javadoc)
* @see secarc.ets.analysis.checker.ISecAnalysisPortChecker#check(mc.umlp.arcd._ast.ASTArcPort, secarc.ets.entries.SecPortEntry, secarc.ets.graph.ArchitectureGraph)
*/
@Override
public void check(ASTArcPort node, SecPortEntry entry,
ArchitectureGraph graph) throws AmbigousException {
ArchitectureGraph graph, boolean advanced) throws AmbigousException {
if(AnalysisHelper.isPortBenningOfPath(entry, graph) != null
&& entry.getTypeReference().getExtendedName().equals("java.lang.String")) {
addReport("The input port " + entry.getName() + " has the type " + entry.getTypeReference() + ". This type is not specific enough.", node.get_SourcePositionStart());
......@@ -28,6 +44,10 @@ public class AvoidInputString extends Analysis implements
}
/*
* (non-Javadoc)
* @see interfaces2.coco.ContextCondition#getErrorCode()
*/
@Override
public IErrorCode getErrorCode() {
return MontiSecArcAnalysisErrorCodes.AvoidInputString;
......
......@@ -12,14 +12,13 @@ import mc.IErrorCode;
import mc.ast.ASTNode;
import mc.umlp.arcd._ast.ASTArcComponent;
import mc.umlp.arcd._ast.ASTArcPort;
import mc.umlp.arcd.ets.entries.ComponentEntry;
import mc.umlp.arcd.ets.entries.PortEntry;
import interfaces2.STEntry;
import interfaces2.resolvers.AmbigousException;
import secarc.error.MontiSecArcAnalysisErrorCodes;
import secarc.ets.analysis.checker.Analysis;
import secarc.ets.analysis.checker.AnalysisHelper;
import secarc.ets.analysis.checker.ISecAnalysisPortChecker;
import secarc.ets.analysis.trustlevel.DerivedTrustlevel;
import secarc.ets.check.CoCoHelper;
import secarc.ets.check.MontiSecArcAnalysisConstants;
import secarc.ets.entries.SecComponentEntry;
......@@ -34,8 +33,6 @@ import secarc.ets.graph.Vertex;
*
* - SSL/TLS Testing
*
* TODO SimpleConnector
*
* <br>
* <br>
* Copyright (c) 2011 RWTH Aachen. All rights reserved
......@@ -45,12 +42,21 @@ import secarc.ets.graph.Vertex;
* $Revision$
*