diff --git a/src/main/java/tmltranslator/SecurityPattern.java b/src/main/java/tmltranslator/SecurityPattern.java index 81911a2f5896d4e667cb7a384929ec2f2f35c2cb..70e19d35bd021198bf799b2622718b08b874e58b 100644 --- a/src/main/java/tmltranslator/SecurityPattern.java +++ b/src/main/java/tmltranslator/SecurityPattern.java @@ -50,6 +50,12 @@ import java.util.Objects; public class SecurityPattern { public final static int ENCRYPTION_PROCESS = 1; public final static int DECRYPTION_PROCESS = 2; + public final static String SYMMETRIC_ENC_PATTERN = "Symmetric Encryption"; + public final static String ASYMMETRIC_ENC_PATTERN = "Asymmetric Encryption"; + public final static String MAC_PATTERN = "MAC"; + public final static String HASH_PATTERN = "Hash"; + public final static String NONCE_PATTERN = "Nonce"; + public final static String ADVANCED_PATTERN = "Advanced"; public String name = ""; public String type = ""; @@ -167,10 +173,10 @@ public class SecurityPattern { if (type == null) { return false; } - return type.toLowerCase(Locale.ROOT).equals("nonce"); + return type.equals(SecurityPattern.NONCE_PATTERN); } - public void setProcess(int _process){ + public void setProcess(int _process) { this.process = _process; } diff --git a/src/main/java/tmltranslator/TMLModeling.java b/src/main/java/tmltranslator/TMLModeling.java index 3b5a0543f9bc37bbaf7ca0a3afe97a58c20dc885..f405036b5278afcabb86efbbef530c1c396d3bc0 100755 --- a/src/main/java/tmltranslator/TMLModeling.java +++ b/src/main/java/tmltranslator/TMLModeling.java @@ -959,8 +959,8 @@ public class TMLModeling<E> { signalName = s.split("__decrypt")[0]; - /*for (TMLTask t: getTasks()){ - if (signalName.contains(t.getName())){ + /*for (TMLTask t: getTasks()) { + if (signalName.contains(t.getName())) { signalName = signalName.replace(t.getName()+"__",""); } }*/ @@ -1076,8 +1076,8 @@ public class TMLModeling<E> { } signalName = s.toString().split("__decrypt")[0]; - /*for (TMLTask t: getTasks()){ - if (signalName.contains(t.getName())){ + /*for (TMLTask t: getTasks()) { + if (signalName.contains(t.getName())) { signalName = signalName.replace(t.getName()+"__",""); } }*/ @@ -1668,7 +1668,7 @@ public class TMLModeling<E> { //TraceManager.addDev("Getting usage"); name = attr.getName(); if (!(name.startsWith("arg")) && (name.endsWith("__req"))) { - //if ((name.compareTo("arg1__req") != 0) && (name.compareTo("arg2__req") != 0) && (name.compareTo("arg3__req") != 0)){ + //if ((name.compareTo("arg1__req") != 0) && (name.compareTo("arg2__req") != 0) && (name.compareTo("arg3__req") != 0)) { usage = getUsageOfAttribute(task, activity, attr); //TraceManager.addDev("End getting usage"); if (usage == 0) { diff --git a/src/main/java/tmltranslator/TMLTextSpecification.java b/src/main/java/tmltranslator/TMLTextSpecification.java index 6b0f4870bea6439c056cbff3efbeb3b62b0a678c..7a08f37cebba07dfd3eebf0092ca2002427d1cd0 100755 --- a/src/main/java/tmltranslator/TMLTextSpecification.java +++ b/src/main/java/tmltranslator/TMLTextSpecification.java @@ -419,17 +419,17 @@ public class TMLTextSpecification<E> { code = "EXECC" + SP + modifyString(((TMLExecC) elt).getAction()) + CR; } else { String type = ""; - if (elt.securityPattern.type.equals("Asymmetric Encryption")) { + if (elt.securityPattern.type.equals(SecurityPattern.ASYMMETRIC_ENC_PATTERN)) { type = AENCRYPT; - } else if (elt.securityPattern.type.equals("Symmetric Encryption")) { + } else if (elt.securityPattern.type.equals(SecurityPattern.SYMMETRIC_ENC_PATTERN)) { type = SENCRYPT; - } else if (elt.securityPattern.type.equals("MAC")) { + } else if (elt.securityPattern.type.equals(SecurityPattern.MAC_PATTERN)) { type = MAC; - } else if (elt.securityPattern.type.equals("Nonce")) { + } else if (elt.securityPattern.type.equals(SecurityPattern.NONCE_PATTERN)) { type = NONCE; - } else if (elt.securityPattern.type.equals("Hash")) { + } else if (elt.securityPattern.type.equals(SecurityPattern.HASH_PATTERN)) { type = HASH; - } else { + } else if (elt.securityPattern.type.equals(SecurityPattern.ADVANCED_PATTERN)) { type = ADV; } @@ -782,17 +782,17 @@ public class TMLTextSpecification<E> { int process; if (type.equals(AENCRYPT)) { - stringType = "Symmetric Encryption"; + stringType = SecurityPattern.ASYMMETRIC_ENC_PATTERN; } else if (type.equals(SENCRYPT)) { - stringType = "Symmetric Encryption"; + stringType = SecurityPattern.SYMMETRIC_ENC_PATTERN; } else if (type.equals(HASH)) { - stringType = "Hash"; + stringType = SecurityPattern.HASH_PATTERN; } else if (type.equals(MAC)) { - stringType = "MAC"; + stringType = SecurityPattern.MAC_PATTERN; } else if (type.equals(NONCE)) { - stringType = "Nonce"; + stringType = SecurityPattern.NONCE_PATTERN; } else if (type.equals(ADV)) { - stringType = "Advanced"; + stringType = SecurityPattern.ADVANCED_PATTERN; } if (stringType.length() > 0) { diff --git a/src/main/java/tmltranslator/toavatar/FullTML2Avatar.java b/src/main/java/tmltranslator/toavatar/FullTML2Avatar.java index 1093b1af13b24f47a5e64500a4adbd55224116da..211650c34ab7b209865213b99ab2c97a59e09ec6 100644 --- a/src/main/java/tmltranslator/toavatar/FullTML2Avatar.java +++ b/src/main/java/tmltranslator/toavatar/FullTML2Avatar.java @@ -1170,10 +1170,10 @@ public class FullTML2Avatar { //If encryption if (ae.securityPattern != null && ae.securityPattern.process == SecurityPattern.ENCRYPTION_PROCESS) { secPatterns.add(ae.securityPattern); - if (ae.securityPattern.type.equals("Advanced")) { + if (ae.securityPattern.type.equals(SecurityPattern.ADVANCED_PATTERN)) { //Type Advanced tran.addAction(ae.securityPattern.formula); - } else if (ae.securityPattern.type.equals("Symmetric Encryption")) { + } else if (ae.securityPattern.type.equals(SecurityPattern.SYMMETRIC_ENC_PATTERN)) { //Type Symmetric Encryption if (!ae.securityPattern.nonce.isEmpty()) { //Concatenate nonce to data @@ -1230,7 +1230,7 @@ public class FullTML2Avatar { //Set as origin for authenticity ae.securityPattern.originTask = block.getName(); ae.securityPattern.state1 = as; - } else if (ae.securityPattern.type.equals("Asymmetric Encryption")) { + } else if (ae.securityPattern.type.equals(SecurityPattern.ASYMMETRIC_ENC_PATTERN)) { if (!ae.securityPattern.nonce.isEmpty()) { //Concatenating a nonce //Add concat2 method @@ -1277,7 +1277,7 @@ public class FullTML2Avatar { //Set as origin state for authenticity ae.securityPattern.originTask = block.getName(); ae.securityPattern.state1 = as; - } else if (ae.securityPattern.type.equals("Nonce")) { + } else if (ae.securityPattern.type.equals(SecurityPattern.NONCE_PATTERN)) { //Do nothing except occupy time to forge nonce @@ -1291,14 +1291,14 @@ public class FullTML2Avatar { arandom.addNext(tran); elementList.add(tran); block.addAttribute(new AvatarAttribute(ae.securityPattern.name, AvatarType.INTEGER, block, null));*/ - } else if (ae.securityPattern.type.equals("Hash")) { + } else if (ae.securityPattern.type.equals(SecurityPattern.HASH_PATTERN)) { AvatarMethod hash = new AvatarMethod("hash", ae); hash.addParameter(block.getAvatarAttributeWithName(ae.securityPattern.name)); if (block.getAvatarAttributeWithName(ae.securityPattern.name) != null) { block.addMethod(hash); } tran.addAction(ae.securityPattern.name + "_encrypted = hash(" + ae.securityPattern.name + ")"); - } else if (ae.securityPattern.type.equals("MAC")) { + } else if (ae.securityPattern.type.equals(SecurityPattern.MAC_PATTERN)) { block.addAttribute(new AvatarAttribute(ae.securityPattern.name, AvatarType.INTEGER, block, null)); block.addAttribute(new AvatarAttribute("key_" + ae.securityPattern.name, AvatarType.INTEGER, block, null)); block.addAttribute(new AvatarAttribute(ae.securityPattern.name + "_encrypted", AvatarType.INTEGER, block, null)); //msg + mac(msg) @@ -1356,7 +1356,7 @@ public class FullTML2Avatar { //Decryption action //block.addAttribute(new AvatarAttribute(ae.securityPattern.name, AvatarType.INTEGER, block, null)); //block.addAttribute(new AvatarAttribute(ae.securityPattern.name+"_encrypted", AvatarType.INTEGER, block, null)); - if (ae.securityPattern.type.equals("Symmetric Encryption")) { + if (ae.securityPattern.type.equals(SecurityPattern.SYMMETRIC_ENC_PATTERN)) { if (!ae.securityPattern.key.isEmpty()) { //Decrypting a key //Add sdecrypt method @@ -1423,7 +1423,7 @@ public class FullTML2Avatar { AvatarAttributeState authDest = new AvatarAttributeState(block.getName() + "." + dummy.getName() + "." + ae.securityPattern.name, ae.getReferenceObject(), block.getAvatarAttributeWithName(ae.securityPattern.name), dummy); signalAuthDestMap.put(ae.securityPattern.name, authDest); } - } else if (ae.securityPattern.type.equals("Asymmetric Encryption")) { + } else if (ae.securityPattern.type.equals(SecurityPattern.ASYMMETRIC_ENC_PATTERN)) { AvatarMethod adecrypt = new AvatarMethod("adecrypt", ae); if (!ae.securityPattern.key.isEmpty()) { @@ -1490,7 +1490,7 @@ public class FullTML2Avatar { ae.securityPattern.name, ae.getReferenceObject(), block.getAvatarAttributeWithName(ae.securityPattern.name), dummy); signalAuthDestMap.put(ae.securityPattern.name, authDest); } - } else if (ae.securityPattern.type.equals("MAC")) { + } else if (ae.securityPattern.type.equals(SecurityPattern.MAC_PATTERN)) { //Separate MAC from MSG //Add get2 method diff --git a/src/main/java/tmltranslator/toavatarsec/TML2Avatar.java b/src/main/java/tmltranslator/toavatarsec/TML2Avatar.java index a82338ad9ba97bcc97d99d7a5304e0133609a56e..0dc02ffdc1d1a65cce517e8346a19c00023ca974 100644 --- a/src/main/java/tmltranslator/toavatarsec/TML2Avatar.java +++ b/src/main/java/tmltranslator/toavatarsec/TML2Avatar.java @@ -679,10 +679,10 @@ public class TML2Avatar { //If encryption if (ae.securityPattern != null && ae.securityPattern.process == SecurityPattern.ENCRYPTION_PROCESS) { secPatterns.add(ae.securityPattern); - if (ae.securityPattern.type.equals("Advanced")) { + if (ae.securityPattern.type.equals(SecurityPattern.ADVANCED_PATTERN)) { //Type Advanced tran.addAction(ae.securityPattern.formula); - } else if (ae.securityPattern.type.equals("Symmetric Encryption")) { + } else if (ae.securityPattern.type.equals(SecurityPattern.SYMMETRIC_ENC_PATTERN)) { //Type Symmetric Encryption if (!ae.securityPattern.nonce.isEmpty()) { //Concatenate nonce to data @@ -739,7 +739,7 @@ public class TML2Avatar { //Set as origin for authenticity ae.securityPattern.originTask = block.getName(); ae.securityPattern.state1 = as; - } else if (ae.securityPattern.type.equals("Asymmetric Encryption")) { + } else if (ae.securityPattern.type.equals(SecurityPattern.ASYMMETRIC_ENC_PATTERN)) { if (!ae.securityPattern.nonce.isEmpty()) { //Concatenating a nonce //Add concat2 method @@ -786,7 +786,7 @@ public class TML2Avatar { //Set as origin state for authenticity ae.securityPattern.originTask = block.getName(); ae.securityPattern.state1 = as; - } else if (ae.securityPattern.type.equals("Nonce")) { + } else if (ae.securityPattern.type.equals(SecurityPattern.NONCE_PATTERN)) { //Do nothing except occupy time to forge nonce @@ -800,14 +800,14 @@ public class TML2Avatar { arandom.addNext(tran); elementList.add(tran); block.addAttribute(new AvatarAttribute(ae.securityPattern.name, AvatarType.INTEGER, block, null));*/ - } else if (ae.securityPattern.type.equals("Hash")) { + } else if (ae.securityPattern.type.equals(SecurityPattern.HASH_PATTERN)) { AvatarMethod hash = new AvatarMethod("hash", ae); hash.addParameter(block.getAvatarAttributeWithName(ae.securityPattern.name)); if (block.getAvatarAttributeWithName(ae.securityPattern.name) != null) { block.addMethod(hash); } tran.addAction(ae.securityPattern.name + "_encrypted = hash(" + ae.securityPattern.name + ")"); - } else if (ae.securityPattern.type.equals("MAC")) { + } else if (ae.securityPattern.type.equals(SecurityPattern.MAC_PATTERN)) { block.addAttribute(new AvatarAttribute(ae.securityPattern.name, AvatarType.INTEGER, block, null)); block.addAttribute(new AvatarAttribute("key_" + ae.securityPattern.name, AvatarType.INTEGER, block, null)); block.addAttribute(new AvatarAttribute(ae.securityPattern.name + "_encrypted", AvatarType.INTEGER, block, null)); //msg + mac(msg) @@ -867,7 +867,7 @@ public class TML2Avatar { //Decryption action //block.addAttribute(new AvatarAttribute(ae.securityPattern.name, AvatarType.INTEGER, block, null)); //block.addAttribute(new AvatarAttribute(ae.securityPattern.name+"_encrypted", AvatarType.INTEGER, block, null)); - if (ae.securityPattern.type.equals("Symmetric Encryption")) { + if (ae.securityPattern.type.equals(SecurityPattern.SYMMETRIC_ENC_PATTERN)) { if (!ae.securityPattern.key.isEmpty()) { //Decrypting a key //Add sdecrypt method @@ -937,7 +937,7 @@ public class TML2Avatar { ae.securityPattern.name, ae.getReferenceObject(), block.getAvatarAttributeWithName(ae.securityPattern.name), dummy); signalAuthDestMap.put(ae.securityPattern.name, authDest); } - } else if (ae.securityPattern.type.equals("Asymmetric Encryption")) { + } else if (ae.securityPattern.type.equals(SecurityPattern.ASYMMETRIC_ENC_PATTERN)) { AvatarMethod adecrypt = new AvatarMethod("adecrypt", ae); if (!ae.securityPattern.key.isEmpty()) { @@ -1003,7 +1003,7 @@ public class TML2Avatar { AvatarAttributeState authDest = new AvatarAttributeState(block.getName() + "." + dummy.getName() + "." + ae.securityPattern.name, ae.getReferenceObject(), block.getAvatarAttributeWithName(ae.securityPattern.name), dummy); signalAuthDestMap.put(ae.securityPattern.name, authDest); } - } else if (ae.securityPattern.type.equals("MAC")) { + } else if (ae.securityPattern.type.equals(SecurityPattern.MAC_PATTERN)) { //Separate MAC from MSG //Add get2 method @@ -1132,7 +1132,7 @@ public class TML2Avatar { if (ae.securityPattern != null) { //If nonce - if (ae.securityPattern.type.equals("Nonce")) { + if (ae.securityPattern.type.equals(SecurityPattern.NONCE_PATTERN)) { block.addAttribute(new AvatarAttribute(ae.securityPattern.name, AvatarType.INTEGER, block, null)); as.addValue(ae.securityPattern.name); } @@ -1266,7 +1266,7 @@ public class TML2Avatar { if (ae.securityPattern != null) { //send nonce - if (ae.securityPattern.type.equals("Nonce")) { + if (ae.securityPattern.type.equals(SecurityPattern.NONCE_PATTERN)) { block.addAttribute(new AvatarAttribute(ae.securityPattern.name, AvatarType.INTEGER, block, null)); as.addValue(ae.securityPattern.name); } @@ -2332,7 +2332,7 @@ public class TML2Avatar { for (TMLTask t : accessKeys.keySet()) { AvatarBlock b = taskBlockMap.get(t); for (SecurityPattern sp : accessKeys.get(t)) { - if (sp.type.equals("Symmetric Encryption") || sp.type.equals("MAC")) { + if (sp.type.equals(SecurityPattern.SYMMETRIC_ENC_PATTERN) || sp.type.equals(SecurityPattern.MAC_PATTERN)) { AvatarAttribute key = new AvatarAttribute("key_" + sp.name, AvatarType.INTEGER, b, null); if (symKeys.containsKey(sp)) { symKeys.get(sp).add(key); @@ -2342,7 +2342,7 @@ public class TML2Avatar { symKeys.put(sp, tmp); } b.addAttribute(key); - } else if (sp.type.equals("Asymmetric Encryption")) { + } else if (sp.type.equals(SecurityPattern.ASYMMETRIC_ENC_PATTERN)) { AvatarAttribute pubkey = new AvatarAttribute("pubKey_" + sp.name, AvatarType.INTEGER, b, null); b.addAttribute(pubkey); diff --git a/src/main/java/ui/GTURTLEModeling.java b/src/main/java/ui/GTURTLEModeling.java index 8691671805da6d6457af4d4620ac1382cd9ea126..bc48e0da90f6052c2bc10b1c0a88641967d92ee2 100644 --- a/src/main/java/ui/GTURTLEModeling.java +++ b/src/main/java/ui/GTURTLEModeling.java @@ -1514,7 +1514,7 @@ public class GTURTLEModeling { - for (TMLADWriteChannel wr: wrChans){ + for (TMLADWriteChannel wr: wrChans) { String chanName = wr.getChannelName(); @@ -1813,12 +1813,12 @@ public class GTURTLEModeling { return; } for (SecurityPattern sp : tmlm.securityTaskMap.keySet()) { - if (sp.type.contains("Symmetric Encryption") || sp.type.equals("MAC") || sp.type.equals("Asymmetric Encryption")) { + if (sp.type.equals(SecurityPattern.SYMMETRIC_ENC_PATTERN) || sp.type.equals(SecurityPattern.MAC_PATTERN) || sp.type.equals(SecurityPattern.ASYMMETRIC_ENC_PATTERN)) { for (TMLTask t : tmlm.securityTaskMap.get(sp)) { HwExecutionNode node1 = tmap.getHwNodeOf(t); boolean taskMappedToCPU = false; - if (node1!=null){ - if (node1 instanceof HwCPU){ + if (node1!=null) { + if (node1 instanceof HwCPU) { HwCPU cpuNode = (HwCPU) node1; taskMappedToCPU = true; boolean keyMappedtoMem = false; @@ -1868,7 +1868,7 @@ public class GTURTLEModeling { links.add(newLink);*/ //Connect Bus and Memory - TDiagramPanel archPanel = busNode.tdp; + TDiagramPanel archPanel = busNode.tdp; TMLArchiConnectorNode connect = new TMLArchiConnectorNode(memNodeToMap.getX() + 100, archPanel.getMaxY() - 300, archPanel.getMinX(), archPanel.getMaxX(), archPanel.getMinY(), archPanel.getMaxY(), true, null, archPanel, null, null, new Vector<Point>()); TGConnectingPoint p1 = busNode.findFirstFreeTGConnectingPoint(true, true); p1.setFree(false); @@ -1892,7 +1892,7 @@ public class GTURTLEModeling { } } if (!keyMappedtoMem) { - if (lastLink!=null){ + if (lastLink != null) { TMLArchiBUSNode lastBusNode = (TMLArchiBUSNode) listE.getTG(lastLink.bus); TMLArchiCPUNode cpuArchiNode = (TMLArchiCPUNode) listE.getTG(cpuNode); @@ -1963,8 +1963,8 @@ public class GTURTLEModeling { //Disconnect Public Bus and CPU lastBusNode.tdp.getConnectorConnectedTo(p2); - for (TGConnector connector: lastBusNode.tdp.getConnectors()){ - if ((connector.getTGComponent1() == cpuArchiNode && connector.getTGComponent2() == lastBusNode) || (connector.getTGComponent1() == lastBusNode && connector.getTGComponent2() == cpuArchiNode)){ + for (TGConnector connector: lastBusNode.tdp.getConnectors()) { + if ((connector.getTGComponent1() == cpuArchiNode && connector.getTGComponent2() == lastBusNode) || (connector.getTGComponent1() == lastBusNode && connector.getTGComponent2() == cpuArchiNode)) { TraceManager.addDev("Disconnect :" + connector.getTGComponent1().getName() + " and " + connector.getTGComponent2().getName()); lastBusNode.tdp.removeComponent(connector); } @@ -1973,7 +1973,7 @@ public class GTURTLEModeling { } } } - if (!taskMappedToCPU){ + if (!taskMappedToCPU) { TraceManager.addDev(t.getTaskName() + " has to be mapped to a CPU!"); } } @@ -3313,7 +3313,7 @@ public class GTURTLEModeling { Point p1 = savedPanels.elementAt(size - 1); // panels are saved under the form of a point -> x = analysis/design, y = panel if (p == null) p = p1; - /*if ((p1.x != p.x) || (p1.y != p.y)){ + /*if ((p1.x != p.x) || (p1.y != p.y)) { savedOperations.add(savedOperations.elementAt(size - 1)); savedPanels.add(p); if (savedOperations.size() > nbMaxSavedOperations) { @@ -3524,7 +3524,7 @@ public class GTURTLEModeling { checkingErrors = tmc.syntaxAnalysisChecking(); warnings.addAll(tmc.getWarnings()); - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + if ((checkingErrors != null) && (checkingErrors.size() > 0)) { analyzeErrors(); return false; } else { @@ -7595,7 +7595,7 @@ public class GTURTLEModeling { tdp.addBuiltComponent(tgc); list.add(tgc); - /*if ((zoomV != 1) && (tgc instanceof TGScalableComponent)){ + /*if ((zoomV != 1) && (tgc instanceof TGScalableComponent)) { ((TGScalableComponent)tgc).forceScale(zoomV); TraceManager.addDev("myX after =" + tgc.getX()); }*/ @@ -7797,7 +7797,7 @@ public class GTURTLEModeling { // Do the scaling here? - /*if ((zoomV != 1) && (tgc instanceof TGScalableComponent)){ + /*if ((zoomV != 1) && (tgc instanceof TGScalableComponent)) { ((TGScalableComponent)tgc).forceScale(zoomV); TraceManager.addDev("myX after =" + tgc.getX()); }*/ @@ -7826,7 +7826,7 @@ public class GTURTLEModeling { if (father instanceof SwallowTGComponent) { //TraceManager.addDev("1 Must add the component to its father:"); tgc = TGComponentManager.addComponent(myX, myY, myType, tdp); - /*if ((zoomV != 1) && (tgc instanceof TGScalableComponent)){ + /*if ((zoomV != 1) && (tgc instanceof TGScalableComponent)) { ((TGScalableComponent)tgc).forceScale(zoomV); TraceManager.addDev("myX after =" + tgc.getX()); }*/ @@ -7852,7 +7852,7 @@ public class GTURTLEModeling { } } else { tgc = TGComponentManager.addComponent(myX, myY, myType, tdp); - /*if ((zoomV != 1) && (tgc instanceof TGScalableComponent)){ + /*if ((zoomV != 1) && (tgc instanceof TGScalableComponent)) { ((TGScalableComponent)tgc).forceScale(zoomV); TraceManager.addDev("myX after =" + tgc.getX()); }*/ @@ -8888,7 +8888,7 @@ public class GTURTLEModeling { // checkingErrors = gtmlm.getCheckingErrors(); // avatarspec = gtmlm.avspec; - // if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + // if ((checkingErrors != null) && (checkingErrors.size() > 0)) { // analyzeErrors(); // warnings = gtmlm.getCheckingWarnings(); // return false; @@ -9238,13 +9238,13 @@ public class GTURTLEModeling { if (asme instanceof AvatarState) { //check if empty checker state - /* if (asme.getName().contains("signalstate_")){ + /* if (asme.getName().contains("signalstate_")) { //don't add the state, ignore next transition, - if (asme.getNexts().size()==1){ + if (asme.getNexts().size()==1) { AvatarStateMachineElement next = asme.getNext(0).getNext(0); //Reroute transition - for (AvatarTransition at: tranDestMap.keySet()){ - if (tranDestMap.get(at) == asme){ + for (AvatarTransition at: tranDestMap.keySet()) { + if (tranDestMap.get(at) == asme) { tranDestMap.put(at, next); } } @@ -9791,9 +9791,9 @@ public class GTURTLEModeling { conn.updateAllSignals(); } - /*for (ui.AvatarSignal sig:blockMap.get(bl1).getSignalList()){ - for (ui.AvatarSignal sig2: blockMap.get(bl2).getSignalList()){ - if (sig.getId().equals(sig2.getId())){ + /*for (ui.AvatarSignal sig:blockMap.get(bl1).getSignalList()) { + for (ui.AvatarSignal sig2: blockMap.get(bl2).getSignalList()) { + if (sig.getId().equals(sig2.getId())) { conn.addSignal("in "+sig.getId(), true, true); conn.addSignal("out "+sig.getId(), false, false); } diff --git a/src/main/java/ui/HSMGeneration.java b/src/main/java/ui/HSMGeneration.java index 3d7bee5aa7fba5cc98a9ba4a05e07af051fed0d8..4bbcb686f05018849f7e5fb72662468a227b53ad 100644 --- a/src/main/java/ui/HSMGeneration.java +++ b/src/main/java/ui/HSMGeneration.java @@ -54,7 +54,7 @@ public class HSMGeneration implements Runnable { ProVerifSpec proverif; TMLMapping<TGComponent> tmap; - public HSMGeneration(MainGUI gui, Map<String, List<String>> selectedCpuTasks, TMLMapping<TGComponent> tmap){ + public HSMGeneration(MainGUI gui, Map<String, List<String>> selectedCpuTasks, TMLMapping<TGComponent> tmap) { this.gui = gui; this.selectedCpuTasks = selectedCpuTasks; this.tmap = tmap; @@ -90,7 +90,7 @@ public class HSMGeneration implements Runnable { ProVerifOutputAnalyzer pvoa = avatar2proverif.getOutputAnalyzer(); pvoa.analyzeOutput(data, true); - if (pvoa.getResults().size() ==0){ + if (pvoa.getResults().size() ==0) { TraceManager.addDev("ERROR: No security results"); } @@ -122,19 +122,19 @@ public class HSMGeneration implements Runnable { } - public void startThread(){ + public void startThread() { Thread t = new Thread(this); t.start(); try { t.join(); } - catch (Exception e){ + catch (Exception e) { TraceManager.addDev("Error in HSM Generation Thread"); } return; } - public void run(){ + public void run() { Map<String, Integer> channelIndexMap = new HashMap<String, Integer>(); int channelIndex=0; TraceManager.addDev("Adding HSM"); @@ -244,7 +244,7 @@ public class HSMGeneration implements Runnable { if (type != -1) { compChannels.put(writeChannel.getChannelName(), ch); channelInstances.add(tg); - if (!channelIndexMap.containsKey(writeChannel.getChannelName())){ + if (!channelIndexMap.containsKey(writeChannel.getChannelName())) { channelIndexMap.put(writeChannel.getChannelName(),channelIndex); channelIndex++; } @@ -257,19 +257,19 @@ public class HSMGeneration implements Runnable { channelInstances.add(tg); SecurityPattern sp = tmap.getSecurityPatternByName(writeChannel.getSecurityContext()); int type = -1; - if (sp.type.equals("Symmetric Encryption")) { + if (sp.type.equals(SecurityPattern.SYMMETRIC_ENC_PATTERN)) { type = HSMChannel.SENC; - } else if (sp.type.equals("Asymmetric Encryption")) { + } else if (sp.type.equals(SecurityPattern.ASYMMETRIC_ENC_PATTERN)) { type = HSMChannel.AENC; - } else if (sp.type.equals("MAC")) { + } else if (sp.type.equals(SecurityPattern.MAC_PATTERN)) { type = HSMChannel.MAC; - } else if (sp.type.equals("Nonce")) { + } else if (sp.type.equals(SecurityPattern.NONCE_PATTERN)) { type = HSMChannel.NONCE; } HSMChannel ch = new HSMChannel(writeChannel.getChannelName(), compName, type); ch.securityContext = writeChannel.getSecurityContext(); compChannels.put(writeChannel.getChannelName(), ch); - if (!channelIndexMap.containsKey(writeChannel.getChannelName())){ + if (!channelIndexMap.containsKey(writeChannel.getChannelName())) { channelIndexMap.put(writeChannel.getChannelName(),channelIndex); channelIndex++; } @@ -287,7 +287,7 @@ public class HSMGeneration implements Runnable { HSMChannel ch = new HSMChannel(readChannel.getChannelName(), compName, HSMChannel.DEC); ch.securityContext = "hsmSec_" + readChannel.getChannelName(); compChannels.put(readChannel.getChannelName(), ch); - if (!channelIndexMap.containsKey(readChannel.getChannelName())){ + if (!channelIndexMap.containsKey(readChannel.getChannelName())) { channelIndexMap.put(readChannel.getChannelName(),channelIndex); channelIndex++; } @@ -303,7 +303,7 @@ public class HSMGeneration implements Runnable { HSMChannel ch = new HSMChannel(readChannel.getChannelName(), compName, HSMChannel.DEC); ch.securityContext = readChannel.getSecurityContext(); compChannels.put(readChannel.getChannelName(), ch); - if (!channelIndexMap.containsKey(readChannel.getChannelName())){ + if (!channelIndexMap.containsKey(readChannel.getChannelName())) { channelIndexMap.put(readChannel.getChannelName(),channelIndex); channelIndex++; } @@ -631,13 +631,13 @@ public class HSMGeneration implements Runnable { TMLADEncrypt enc = new TMLADEncrypt(xc, 500, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); enc.securityContext = ch.securityContext; if (hsmChannels.get(chan).secType == HSMChannel.SENC) { - enc.type = "Symmetric Encryption"; + enc.type = SecurityPattern.SYMMETRIC_ENC_PATTERN; } else if (hsmChannels.get(chan).secType == HSMChannel.AENC) { - enc.type = "Asymmetric Encryption"; + enc.type = SecurityPattern.ASYMMETRIC_ENC_PATTERN; } else if (hsmChannels.get(chan).secType == HSMChannel.MAC) { - enc.type = "MAC"; + enc.type = SecurityPattern.MAC_PATTERN; } else if (hsmChannels.get(chan).secType == HSMChannel.NONCE) { - enc.type = "Nonce"; + enc.type = SecurityPattern.NONCE_PATTERN; } enc.message_overhead = overhead; @@ -734,13 +734,13 @@ public class HSMGeneration implements Runnable { TMLADEncrypt enc = new TMLADEncrypt(xc, 500, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); enc.securityContext = ch.securityContext; if (hsmChannels.get(chan).secType == HSMChannel.SENC) { - enc.type = "Symmetric Encryption"; + enc.type = SecurityPattern.SYMMETRIC_ENC_PATTERN; } else if (hsmChannels.get(chan).secType == HSMChannel.AENC) { - enc.type = "Asymmetric Encryption"; + enc.type = SecurityPattern.ASYMMETRIC_ENC_PATTERN; } else if (hsmChannels.get(chan).secType == HSMChannel.MAC) { - enc.type = "MAC"; + enc.type = SecurityPattern.MAC_PATTERN; } else if (hsmChannels.get(chan).secType == HSMChannel.NONCE) { - enc.type = "Nonce"; + enc.type = SecurityPattern.NONCE_PATTERN; } enc.message_overhead = overhead; @@ -871,7 +871,7 @@ public class HSMGeneration implements Runnable { TMLADEncrypt enc = new TMLADEncrypt(xpos, ypos, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); tad.addComponent(enc, xpos, ypos, false, true); enc.securityContext = ch.securityContext; - enc.type = "Symmetric Encryption"; + enc.type = SecurityPattern.SYMMETRIC_ENC_PATTERN; enc.message_overhead = overhead; enc.encTime = encComp; enc.decTime = decComp; diff --git a/src/main/java/ui/SecurityGeneration.java b/src/main/java/ui/SecurityGeneration.java index 017c0c5400696530f062bc86c7abba46eaff7e4b..72e364a9a4d23e86d1cb131f50aab90ec3e091d1 100644 --- a/src/main/java/ui/SecurityGeneration.java +++ b/src/main/java/ui/SecurityGeneration.java @@ -495,7 +495,7 @@ public class SecurityGeneration implements Runnable { if (chan.checkConf && autoConf && nonConf) { toSecure.get(orig).add(dest); /*if (chan.checkAuth && autoStrongAuth) { - if (!toSecureRev.get(dest).contains(orig)){ + if (!toSecureRev.get(dest).contains(orig)) { toSecureRev.get(dest).add(orig); } }*/ @@ -543,8 +543,8 @@ public class SecurityGeneration implements Runnable { } else if (chan.checkAuth && autoWeakAuth && nonAuth) { toSecure.get(orig).add(dest); /* if (autoStrongAuth) { - /* if (chan.getOriginTask().getReferenceObject() instanceof TMLCPrimitiveComponent && chan.getDestinationTask().getReferenceObject() instanceof TMLCPrimitiveComponent){*/ - /*if (!toSecureRev.get(dest).contains(orig)){ + /* if (chan.getOriginTask().getReferenceObject() instanceof TMLCPrimitiveComponent && chan.getDestinationTask().getReferenceObject() instanceof TMLCPrimitiveComponent) {*/ + /*if (!toSecureRev.get(dest).contains(orig)) { toSecureRev.get(dest).add(orig); }*/ /*} @@ -834,8 +834,8 @@ public class SecurityGeneration implements Runnable { for (TMLChannel chan : chans2) { if (chan.isCheckAuthChannel()) { if (chan.getName().split("__")[1].equals(channelAtif.getCommunicationName())) { - count_chans +=1; - if (count_chans==1) { + count_chans += 1; + if (count_chans == 1) { compMemToPutChannel = compMem; newChannelInMem = new TMLArchiCommunicationArtifact(compMem.getX(), (int)(compMem.getY()+compMem.getHeight()*(0.3+Math.random()/2)), compMem.getCurrentMinX(), compMem.getCurrentMaxX(), compMem.getCurrentMinY(), compMem.getCurrentMaxY(), true, comp, newarch.tmlap); newChannelInMem.setCommunicationName(destPort.commName); @@ -848,7 +848,7 @@ public class SecurityGeneration implements Runnable { } } } - if (count_chans>0){ + if (count_chans > 0) { compMemToPutChannel.addInternalComponent(newChannelInMem, compMemToPutChannel.getNbInternalTGComponent()); } } @@ -935,7 +935,7 @@ public class SecurityGeneration implements Runnable { } enc.securityContext = channelSecMap.get(channel); - enc.type = "Symmetric Encryption"; + enc.type = SecurityPattern.SYMMETRIC_ENC_PATTERN; enc.message_overhead = overhead; enc.encTime = encComp; enc.decTime = decComp; @@ -1032,7 +1032,7 @@ public class SecurityGeneration implements Runnable { //Add encryption operator enc.securityContext = channelSecMap.get(channel); - enc.type = "MAC"; + enc.type = SecurityPattern.MAC_PATTERN; enc.message_overhead = overhead; enc.encTime = encComp; enc.decTime = decComp; @@ -1295,7 +1295,7 @@ public class SecurityGeneration implements Runnable { yShift += 60; nonce = new TMLADEncrypt(xpos, ypos + yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); nonce.securityContext = "nonce_" + tmlc.getDestinationTask().getName().split("__")[1] + "_" + tmlc.getOriginTask().getName().split("__")[1]; - nonce.type = "Nonce"; + nonce.type = SecurityPattern.NONCE_PATTERN; nonce.message_overhead = overhead; nonce.encTime = encComp; nonce.decTime = decComp; @@ -1432,7 +1432,7 @@ public class SecurityGeneration implements Runnable { //Create a nonce operator and a write channel operator TMLADEncrypt nonce = new TMLADEncrypt(xpos, ypos + yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); nonce.securityContext = "nonce_" + tmlc.getDestinationTask().getName().split("__")[1] + "_" + tmlc.getOriginTask().getName().split("__")[1]; - nonce.type = "Nonce"; + nonce.type = SecurityPattern.NONCE_PATTERN; nonce.message_overhead = overhead; nonce.encTime = encComp; nonce.decTime = decComp; @@ -1548,7 +1548,7 @@ public class SecurityGeneration implements Runnable { //Create a nonce operator and a write channel operator nonce = new TMLADEncrypt(xpos, ypos + yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); nonce.securityContext = "nonce_" + tmlc.getDestinationTask().getName().split("__")[1] + "_" + tmlc.getOriginTask().getName().split("__")[1]; - nonce.type = "Nonce"; + nonce.type = SecurityPattern.NONCE_PATTERN; nonce.message_overhead = overhead; nonce.encTime = encComp; nonce.decTime = decComp; @@ -1630,7 +1630,7 @@ public class SecurityGeneration implements Runnable { // GTMLModeling gtm = new GTMLModeling(newarch, false); // map = gtm.translateToTMLMapping(); -//if (gtm.getCheckingErrors().size() > 0){ +//if (gtm.getCheckingErrors().size() > 0) { //System.out.println("@$()(#"); //map= null; // } @@ -1765,13 +1765,13 @@ public class SecurityGeneration implements Runnable { TMLADEncrypt enc = new TMLADEncrypt(xc, 500, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); enc.securityContext = channelSecMap.get(ch.name); if (ch.secType == HSMChannel.SENC) { - enc.type = "Symmetric Encryption"; + enc.type = SecurityPattern.SYMMETRIC_ENC_PATTERN; } else if (ch.secType == HSMChannel.AENC) { - enc.type = "Asymmetric Encryption"; + enc.type = SecurityPattern.ASYMMETRIC_ENC_PATTERN; } else if (ch.secType == HSMChannel.MAC) { - enc.type = "MAC"; + enc.type = SecurityPattern.MAC_PATTERN; } else if (ch.secType == HSMChannel.NONCE) { - enc.type = "Nonce"; + enc.type = SecurityPattern.NONCE_PATTERN; } enc.message_overhead = overhead; @@ -1904,13 +1904,13 @@ public class SecurityGeneration implements Runnable { TMLADEncrypt enc = new TMLADEncrypt(xc, 500, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); enc.securityContext = channelSecMap.get(ch.name); if (ch.secType == HSMChannel.SENC) { - enc.type = "Symmetric Encryption"; + enc.type = SecurityPattern.SYMMETRIC_ENC_PATTERN; } else if (ch.secType == HSMChannel.AENC) { - enc.type = "Asymmetric Encryption"; + enc.type = SecurityPattern.ASYMMETRIC_ENC_PATTERN; } else if (ch.secType == HSMChannel.MAC) { - enc.type = "MAC"; + enc.type = SecurityPattern.MAC_PATTERN; } else if (ch.secType == HSMChannel.NONCE) { - enc.type = "Nonce"; + enc.type = SecurityPattern.NONCE_PATTERN; } enc.message_overhead = overhead; diff --git a/src/main/java/ui/tmlad/TMLADEncrypt.java b/src/main/java/ui/tmlad/TMLADEncrypt.java index 4057349b4b25e687cb96d27d9ad01ad7eebc6cb5..81007715610bd4c55ad3c713e43afcaae194fde5 100755 --- a/src/main/java/ui/tmlad/TMLADEncrypt.java +++ b/src/main/java/ui/tmlad/TMLADEncrypt.java @@ -48,6 +48,7 @@ import ui.*; import ui.ad.TADComponentWithoutSubcomponents; import ui.util.IconManager; import ui.window.JDialogCryptographicConfiguration; +import tmltranslator.*; import javax.swing.*; import java.awt.*; @@ -156,7 +157,7 @@ public class TMLADEncrypt extends TADComponentWithoutSubcomponents/* Issue #69 T final int scaledSymbolHeight = scale( ENC_SYMBOL_HEIGHT ); final int scaledSymbolMargin = scale( ENC_SYMBOL_MARGIN ); - if (type.equals("Symmetric Encryption")) { + if (type.equals(SecurityPattern.SYMMETRIC_ENC_PATTERN)) { //S g.drawLine(x + scaledMargin, y + (height - scaledSymbolHeight) / 4, x + width - scaledMargin, y + (height - scaledSymbolHeight) / 4); g.drawLine(x + scaledMargin, y + (height - scaledSymbolHeight) / 4 + scaledSymbolHeight, x + width - scaledMargin, y + (height - scaledSymbolHeight) / 4 + scaledSymbolHeight); @@ -168,7 +169,7 @@ public class TMLADEncrypt extends TADComponentWithoutSubcomponents/* Issue #69 T g.drawLine(x + scaledMargin, y + (height - scaledSymbolHeight) / 4 + scaledSymbolHeight + height / 2 - scaledMargin / 2, x + width - scaledMargin, y + (height - scaledSymbolHeight) / 4 + scaledSymbolHeight + height / 2 - scaledMargin / 2); g.drawLine(x + scaledMargin, y + (height - scaledSymbolHeight) / 4 + scaledSymbolHeight / 2 + height / 2 - scaledMargin / 2, x + width - scaledMargin, y + (height - scaledSymbolHeight) / 4 + scaledSymbolHeight / 2 + height / 2 - scaledMargin / 2); g.drawLine(x + scaledMargin, y + (height - scaledSymbolHeight) / 4 + height / 2 - scaledMargin / 2, x + scaledMargin, y + (height - scaledSymbolHeight) / 4 + scaledSymbolHeight + height / 2 - scaledMargin / 2); - } else if (type.equals("Asymmetric Encryption")) { + } else if (type.equals(SecurityPattern.ASYMMETRIC_ENC_PATTERN)) { //A g.drawLine(x + (width / 2), y + (height - scaledSymbolHeight) / 4, x + scaledMargin, y + (height - scaledSymbolHeight) / 4 + scaledSymbolHeight); g.drawLine(x + (width / 2), y + (height - scaledSymbolHeight) / 4, x + (width) - scaledMargin, y + (height - scaledSymbolHeight) / 4 + scaledSymbolHeight); @@ -178,23 +179,23 @@ public class TMLADEncrypt extends TADComponentWithoutSubcomponents/* Issue #69 T g.drawLine(x + scaledMargin, y + (height - scaledSymbolHeight) / 4 + scaledSymbolHeight + height / 2 - scaledMargin / 2, x + width - scaledMargin, y + (height - scaledSymbolHeight) / 4 + scaledSymbolHeight + height / 2 - scaledMargin / 2); g.drawLine(x + scaledMargin, y + (height - scaledSymbolHeight) / 4 + scaledSymbolHeight / 2 + height / 2 - scaledMargin / 2, x + width - scaledMargin, y + (height - scaledSymbolHeight) / 4 + scaledSymbolHeight / 2 + height / 2 - scaledMargin / 2); g.drawLine(x + scaledMargin, y + (height - scaledSymbolHeight) / 4 + height / 2 - scaledMargin / 2, x + scaledMargin, y + (height - scaledSymbolHeight) / 4 + scaledSymbolHeight + height / 2 - scaledMargin / 2); - } else if (type.equals("Nonce")) { + } else if (type.equals(SecurityPattern.NONCE_PATTERN)) { //N g.drawLine(x + (width / 2) - scaledSymbolMargin, y + (height - scaledSymbolHeight) / 2, x + (width / 2) - scaledSymbolMargin, y + (height - scaledSymbolHeight) / 2 + scaledSymbolHeight); g.drawLine(x + (width / 2) + scaledSymbolMargin, y + (height - scaledSymbolHeight) / 2, x + (width / 2) + scaledSymbolMargin, y + (height - scaledSymbolHeight) / 2 + scaledSymbolHeight); g.drawLine(x + (width / 2) - scaledSymbolMargin, y + (height - scaledSymbolHeight) / 2, x + (width / 2) + scaledSymbolMargin, y + (height - scaledSymbolHeight) / 2 + scaledSymbolHeight); - } else if (type.equals("MAC")) { + } else if (type.equals(SecurityPattern.MAC_PATTERN)) { //M g.drawLine(x + scaledMargin / 2 + 1, y + (height - scaledSymbolHeight) / 2, x + scaledMargin / 2 + 1, y + (height - scaledSymbolHeight) / 2 + scaledSymbolHeight); g.drawLine(x + width - scaledMargin / 2 - 1, y + (height - scaledSymbolHeight) / 2, x + width - scaledMargin / 2 - 1, y + (height - scaledSymbolHeight) / 2 + scaledSymbolHeight); g.drawLine(x + scaledMargin / 2 + 1, y + (height - scaledSymbolHeight) / 2, x + width / 2, y + (height - scaledSymbolHeight) / 2 + scaledSymbolHeight); g.drawLine(x + width - scaledMargin / 2 - 1, y + (height - scaledSymbolHeight) / 2, x + width / 2, y + (height - scaledSymbolHeight) / 2 + scaledSymbolHeight); - } else if (type.equals("Hash")) { + } else if (type.equals(SecurityPattern.HASH_PATTERN)) { //H g.drawLine(x + (width / 2) - scaledSymbolMargin, y + (height - scaledSymbolHeight) / 2, x + (width / 2) - scaledSymbolMargin, y + (height - scaledSymbolHeight) / 2 + scaledSymbolHeight); g.drawLine(x + (width / 2) + scaledSymbolMargin, y + (height - scaledSymbolHeight) / 2, x + (width / 2) + scaledSymbolMargin, y + (height - scaledSymbolHeight) / 2 + scaledSymbolHeight); g.drawLine(x + (width / 2) - scaledSymbolMargin, y + (height - scaledSymbolHeight) / 2 + scaledSymbolHeight / 2, x + (width / 2) + scaledSymbolMargin, y + (height - scaledSymbolHeight) / 2 + scaledSymbolHeight / 2); - } else if (type.equals("Advanced")) { + } else if (type.equals(SecurityPattern.ADVANCED_PATTERN)) { //A g.drawLine(x + (width / 2), y + (height - scaledSymbolHeight) / 2, x + scaledMargin, y + (height - scaledSymbolHeight) / 2 + scaledSymbolHeight); g.drawLine(x + (width / 2), y + (height - scaledSymbolHeight) / 2, x + (width) - scaledMargin, y + (height - scaledSymbolHeight) / 2 + scaledSymbolHeight); diff --git a/src/main/java/ui/tmlad/TMLActivityDiagramPanel.java b/src/main/java/ui/tmlad/TMLActivityDiagramPanel.java index eefd2c04916eafe0ca3989f392e05f7868882cc9..9b054eae4746f19f0dead9c86d958b4d12f5c36b 100755 --- a/src/main/java/ui/tmlad/TMLActivityDiagramPanel.java +++ b/src/main/java/ui/tmlad/TMLActivityDiagramPanel.java @@ -42,7 +42,7 @@ package ui.tmlad; //import java.awt.*; - +import tmltranslator.*; import ui.*; import java.util.ArrayList; @@ -128,7 +128,7 @@ public class TMLActivityDiagramPanel extends TDiagramPanel { while(iterator.hasNext()) { o = iterator.next(); - if (o instanceof TMLADStartState){ + if (o instanceof TMLADStartState) { enhance(v, o); } } @@ -178,15 +178,15 @@ public class TMLActivityDiagramPanel extends TDiagramPanel { return true; } - public List<String> getAllCryptoConfig(){ + public List<String> getAllCryptoConfig() { List<String> cc = new ArrayList<String>(); List<TGComponent> comps = getAllComponentList(); - for (TGComponent c: comps){ - if (c instanceof TMLADEncrypt){ + for (TGComponent c: comps) { + if (c instanceof TMLADEncrypt) { TMLADEncrypt en= (TMLADEncrypt) c; - if (!en.securityContext.isEmpty()){ + if (!en.securityContext.isEmpty()) { cc.add(en.securityContext); } } @@ -195,14 +195,14 @@ public class TMLActivityDiagramPanel extends TDiagramPanel { return cc; } - public List<String> getAllNonce(){ + public List<String> getAllNonce() { List<String> ns=new ArrayList<String>(); List<TGComponent> comps= getAllComponentList(); - for (TGComponent c: comps){ - if (c instanceof TMLADEncrypt){ + for (TGComponent c: comps) { + if (c instanceof TMLADEncrypt) { TMLADEncrypt en= (TMLADEncrypt) c; - if (!en.securityContext.isEmpty() && en.type.equals("Nonce")){ + if (!en.securityContext.isEmpty() && en.type.equals(SecurityPattern.NONCE_PATTERN)) { ns.add(en.securityContext); } } @@ -211,18 +211,18 @@ public class TMLActivityDiagramPanel extends TDiagramPanel { return ns; } - public List<String> getAllKeys(){ + public List<String> getAllKeys() { List<String> ns=new ArrayList<String>(); List<TGComponent> comps= getAllComponentList(); - for (TGComponent c: comps){ - if (c instanceof TMLADEncrypt){ + for (TGComponent c: comps) { + if (c instanceof TMLADEncrypt) { TMLADEncrypt en= (TMLADEncrypt) c; - if (!en.securityContext.isEmpty()){ - if ((en.type.equals("Symmetric Encryption") || en.type.equals("MAC"))){ + if (!en.securityContext.isEmpty()) { + if ((en.type.equals(SecurityPattern.SYMMETRIC_ENC_PATTERN) || en.type.equals(SecurityPattern.MAC_PATTERN))) { ns.add(en.securityContext); } - else if (en.type.equals("Asymmetric Encryption")) { + else if (en.type.equals(SecurityPattern.ASYMMETRIC_ENC_PATTERN)) { ns.add(en.securityContext); //ns.add("pubKey" + en.securityContext); } diff --git a/src/main/java/ui/tmldd/TMLArchiCommunicationArtifact.java b/src/main/java/ui/tmldd/TMLArchiCommunicationArtifact.java index 5d21063c9b673ee913abbea91ee14d334ccab28e..3c9a79ed1ec242c53f39b2afeb7c4a46392c483d 100755 --- a/src/main/java/ui/tmldd/TMLArchiCommunicationArtifact.java +++ b/src/main/java/ui/tmldd/TMLArchiCommunicationArtifact.java @@ -387,8 +387,8 @@ public class TMLArchiCommunicationArtifact extends TGCWithoutInternalComponent i } public void addNewOtherCommunicationNames(ArrayList<String> _mappedElements) { - for(String mappedElem: _mappedElements){ - if (!mappedElements.contains(mappedElem)){ + for(String mappedElem: _mappedElements) { + if (!mappedElements.contains(mappedElem)) { mappedElements.add(mappedElem); } } diff --git a/src/main/java/ui/window/JDialogCryptographicConfiguration.java b/src/main/java/ui/window/JDialogCryptographicConfiguration.java index 46293afd204ec072dac422e7f78b7269e30688bc..ce6732370b437bec2403a4bc4cee3fbb26cc02f8 100644 --- a/src/main/java/ui/window/JDialogCryptographicConfiguration.java +++ b/src/main/java/ui/window/JDialogCryptographicConfiguration.java @@ -60,6 +60,7 @@ import javax.swing.JPanel; import javax.swing.JTextField; import myutil.TraceManager; +import tmltranslator.*; /** * Class JDialogCryptographicConfiguration @@ -120,19 +121,19 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac //http://www.cs.wustl.edu/~jain/cse567-06/ftp/encryption_perf/index.html //https://automationrhapsody.com/md5-sha-1-sha-256-sha-512-speed-performance/ //Add list of sample security algorithms - secAlgs.add(new SecurityAlgorithm("AES", "0","100","100","128","Symmetric Encryption")); - secAlgs.add(new SecurityAlgorithm("Triple-DES", "0","200","200","128","Symmetric Encryption")); + secAlgs.add(new SecurityAlgorithm("AES", "0","100","100","128", SecurityPattern.SYMMETRIC_ENC_PATTERN)); + secAlgs.add(new SecurityAlgorithm("Triple-DES", "0","200","200","128", SecurityPattern.SYMMETRIC_ENC_PATTERN)); - secAlgs.add(new SecurityAlgorithm("RSA", "0","250","150","128","Asymmetric Encryption")); - secAlgs.add(new SecurityAlgorithm("ECC", "0","315","310","128","Asymmetric Encryption")); + secAlgs.add(new SecurityAlgorithm("RSA", "0","250","150","128", SecurityPattern.ASYMMETRIC_ENC_PATTERN)); + secAlgs.add(new SecurityAlgorithm("ECC", "0","315","310","128", SecurityPattern.ASYMMETRIC_ENC_PATTERN)); - secAlgs.add(new SecurityAlgorithm("SHA-256", "0","370","370","128","Hash")); - secAlgs.add(new SecurityAlgorithm("Whirlpool", "0","550","550","128","Hash")); + secAlgs.add(new SecurityAlgorithm("SHA-256", "0","370","370","128", SecurityPattern.HASH_PATTERN)); + secAlgs.add(new SecurityAlgorithm("Whirlpool", "0","550","550","128", SecurityPattern.HASH_PATTERN)); - secAlgs.add(new SecurityAlgorithm("Poly-1305", "0","400","400","128","MAC")); - secAlgs.add(new SecurityAlgorithm("HMAC", "0","800","800","128","MAC")); + secAlgs.add(new SecurityAlgorithm("Poly-1305", "0","400","400","128", SecurityPattern.MAC_PATTERN)); + secAlgs.add(new SecurityAlgorithm("HMAC", "0","800","800","128", SecurityPattern.MAC_PATTERN)); - for (SecurityAlgorithm secAlg: secAlgs){ + for (SecurityAlgorithm secAlg: secAlgs) { algNames.add(secAlg.name); } inserts = new JButton[nbString]; @@ -145,7 +146,7 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - if (values[1].contains("Encryption") || values[1].equals("MAC") || values[1].isEmpty()){ + if (values[1].contains("Encryption") || values[1].equals("MAC") || values[1].isEmpty()) { panel1= new EncryptPanel(this); } else { @@ -185,7 +186,7 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac if (evt.getSource() == inserts[0]) { texts[1].setText(helps.get(1).getSelectedItem().toString()); boolean repanel = false; - if (helps.get(1).getSelectedIndex()==5 && !(panel1 instanceof AdvPanel)){ + if (helps.get(1).getSelectedIndex()==5 && !(panel1 instanceof AdvPanel)) { values[1]=helps.get(1).getSelectedItem().toString(); values[0]=texts[0].getText(); values[3]=texts[3].getText(); @@ -197,7 +198,7 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac c.removeAll(); panel1= new AdvPanel(this); } - else if ((helps.get(1).getSelectedIndex() >2) && !(panel1 instanceof FuncPanel)){ + else if ((helps.get(1).getSelectedIndex() >2) && !(panel1 instanceof FuncPanel)) { values[1]=helps.get(1).getSelectedItem().toString(); values[0]=texts[0].getText(); values[3]=texts[3].getText(); @@ -209,7 +210,7 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac c.removeAll(); panel1= new FuncPanel(this); } - else if ((helps.get(1).getSelectedIndex() <3) && !(panel1 instanceof EncryptPanel)){ + else if ((helps.get(1).getSelectedIndex() <3) && !(panel1 instanceof EncryptPanel)) { values[1]=helps.get(1).getSelectedItem().toString(); values[0]=texts[0].getText(); values[3]=texts[3].getText(); @@ -222,7 +223,7 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac } - if (repanel){ + if (repanel) { /*c0.gridwidth = 1; c0.gridheight = 10; c0.weighty = 1.0; @@ -252,21 +253,21 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac } } if (evt.getSource() == inserts[5]) { - if (helps.get(5).getSelectedItem()!=null){ + if (helps.get(5).getSelectedItem()!=null) { texts[5].setText(helps.get(5).getSelectedItem().toString()); } } if (evt.getSource() == inserts[8]) { - if (helps.get(8).getSelectedItem()!=null){ + if (helps.get(8).getSelectedItem()!=null) { texts[8].setText(helps.get(8).getSelectedItem().toString()); } } //Using preset algorithm if (evt.getSource() == inserts[9]) { - if (helps.get(9).getSelectedItem()!=null){ + if (helps.get(9).getSelectedItem()!=null) { texts[9].setText(helps.get(9).getSelectedItem().toString()); - for (SecurityAlgorithm secAlg: secAlgs){ - if (secAlg.name.equals(texts[9].getText())){ + for (SecurityAlgorithm secAlg: secAlgs) { + if (secAlg.name.equals(texts[9].getText())) { //Set algorithm times + overhead texts[1].setText(secAlg.type); texts[2].setText(secAlg.overhead); @@ -292,7 +293,7 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac add(new JLabel(" "), gc); } - EncryptPanel(JDialogCryptographicConfiguration j){ + EncryptPanel(JDialogCryptographicConfiguration j) { GridBagConstraints c1 = new GridBagConstraints(); GridBagLayout gridbag1 = new GridBagLayout(); @@ -309,7 +310,7 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac c1.weightx = 1.0; c1.fill = GridBagConstraints.HORIZONTAL; c1.anchor = GridBagConstraints.CENTER; - String[] vals = new String[]{"Symmetric Encryption", "Asymmetric Encryption","MAC", "Hash", "Nonce", "Advanced"}; + String[] vals = new String[]{SecurityPattern.SYMMETRIC_ENC_PATTERN, SecurityPattern.ASYMMETRIC_ENC_PATTERN, SecurityPattern.MAC_PATTERN, SecurityPattern.HASH_PATTERN, SecurityPattern.NONCE_PATTERN, SecurityPattern.ADVANCED_PATTERN}; addEmptyLine(c1); @@ -360,7 +361,7 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac c1.gridwidth = 1; add(new JLabel("Nonce"),c1); helps.put(5, new JComboBox<>(nonces)); - if (helps.get(5).getItemCount() > 0){ + if (helps.get(5).getItemCount() > 0) { helps.get(5).setSelectedItem(values[5]); } add(helps.get(5),c1); @@ -376,7 +377,7 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac c1.gridwidth = 1; add(new JLabel("Encrypted Key"),c1); helps.put(8, new JComboBox<>(keys)); - if (helps.get(8).getItemCount() > 0){ + if (helps.get(8).getItemCount() > 0) { helps.get(8).setSelectedItem(values[8]); } add(helps.get(8),c1); @@ -414,7 +415,7 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac add(new JLabel(" "), gc); } - FuncPanel(JDialogCryptographicConfiguration j){ + FuncPanel(JDialogCryptographicConfiguration j) { GridBagConstraints c1 = new GridBagConstraints(); GridBagLayout gridbag1 = new GridBagLayout(); @@ -439,7 +440,7 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac c1.anchor = GridBagConstraints.CENTER; c1.fill = GridBagConstraints.HORIZONTAL; c1.anchor = GridBagConstraints.CENTER; - String[] vals = new String[]{"Symmetric Encryption", "Asymmetric Encryption","MAC", "Hash", "Nonce", "Advanced"}; + String[] vals = new String[]{SecurityPattern.SYMMETRIC_ENC_PATTERN, SecurityPattern.ASYMMETRIC_ENC_PATTERN, SecurityPattern.MAC_PATTERN, SecurityPattern.HASH_PATTERN, SecurityPattern.NONCE_PATTERN, SecurityPattern.ADVANCED_PATTERN}; // String1 addEmptyLine(c1); @@ -504,7 +505,7 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac add(new JLabel(" "), gc); } - AdvPanel(JDialogCryptographicConfiguration j){ + AdvPanel(JDialogCryptographicConfiguration j) { GridBagConstraints c1 = new GridBagConstraints(); GridBagLayout gridbag1 = new GridBagLayout(); @@ -529,7 +530,7 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac c1.anchor = GridBagConstraints.CENTER; c1.fill = GridBagConstraints.HORIZONTAL; c1.anchor = GridBagConstraints.CENTER; - String[] vals = new String[]{"Symmetric Encryption", "Asymmetric Encryption","MAC", "Hash", "Nonce", "Advanced"}; + String[] vals = new String[]{SecurityPattern.SYMMETRIC_ENC_PATTERN, SecurityPattern.ASYMMETRIC_ENC_PATTERN, SecurityPattern.MAC_PATTERN, SecurityPattern.HASH_PATTERN, SecurityPattern.NONCE_PATTERN, SecurityPattern.ADVANCED_PATTERN}; addEmptyLine(c1); @@ -584,7 +585,7 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac } public String getString(int i) { - if (texts[i]!=null){ + if (texts[i]!=null) { return texts[i].getText(); } return ""; @@ -610,7 +611,7 @@ public class JDialogCryptographicConfiguration extends JDialogBase implements Ac String decryptCC; String keysize; String type; - public SecurityAlgorithm(String name, String overhead, String encryptCC, String decryptCC, String keysize, String type){ + public SecurityAlgorithm(String name, String overhead, String encryptCC, String decryptCC, String keysize, String type) { this.name=name; this.overhead=overhead; this.encryptCC = encryptCC;