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 5f1ee08f75ff1b852e990c9eac1a5741954a1c86..f405036b5278afcabb86efbbef530c1c396d3bc0 100755 --- a/src/main/java/tmltranslator/TMLModeling.java +++ b/src/main/java/tmltranslator/TMLModeling.java @@ -900,22 +900,21 @@ public class TMLModeling<E> { + "__" + pragma.getAttrA().getAttribute().getName() + "__" + pragma.getAttrA().getState().getName(); - TraceManager.addDev("\n\n **Backtracing Authenticity s=" + s + " **"); - if (result.isProved() && !result.isSatisfied()) { - TraceManager.addDev("Backtracing Authenticity proved but not satisfied"); - String signalName = s.toString().split("_chData")[0]; - signalName = signalName.split("__")[signalName.split("__").length - 1]; - - TMLChannel channel = getChannelByShortName(signalName); - - if (channel == null) { - channel = getChannelByDestinationPortName(signalName); + TraceManager.addDev("\n\n **Backtracing Authenticity s=" + s + " **"); + if (result.isProved() && result.isSatisfied()) { + TraceManager.addDev("Backtracing Authenticity proved and satisfied" ); + String signalName = s.split("_chData")[0]; + for (TMLTask t : getTasks()) { + if (signalName.contains(t.getName())) { + signalName = signalName.replace(t.getName() + "__", ""); + } } + signalName = signalName.split("__")[1]; + TMLChannel channel = getChannelByShortName(signalName); if (channel != null) { for (TMLPortWithSecurityInformation port : channel.ports) { if (port.getCheckAuth()) { - TraceManager.addDev("Backtracing Authenticity proved but not satisfied / Found port with checkAuth"); - port.setStrongAuthStatus(3); + port.setStrongAuthStatus(2); port.setMappingName(mappingName); ProVerifResultTrace trace = pvoa.getResults().get(pragma).getTrace(); if (trace != null && !port.isOrigin()) { @@ -924,10 +923,8 @@ public class TMLModeling<E> { } } } - } else { - TraceManager.addDev("Backtracing Authenticity proved but not satisfied / NULL channel"); } - signalName = s.toString().split("_reqData")[0]; + signalName = s.split("_reqData")[0]; for (TMLTask t : getTasks()) { if (signalName.contains(t.getName())) { signalName = signalName.replace(t.getName() + "__", ""); @@ -937,12 +934,12 @@ public class TMLModeling<E> { if (req != null) { for (TMLPortWithSecurityInformation port : req.ports) { if (port.getCheckAuth()) { - port.setStrongAuthStatus(3); + port.setStrongAuthStatus(2); port.setMappingName(mappingName); } } } - signalName = s.toString().split("_eventData")[0]; + signalName = s.split("_eventData")[0]; for (TMLTask t : getTasks()) { if (signalName.contains(t.getName())) { signalName = signalName.replace(t.getName() + "__", ""); @@ -951,26 +948,34 @@ public class TMLModeling<E> { TMLEvent ev = getEventByName(signalName); if (ev != null) { if (ev.port.checkAuth) { - ev.port.checkStrongAuthStatus = 3; + ev.port.checkStrongAuthStatus = 2; ev.port2.mappingName = mappingName; } if (ev.port2.checkAuth) { - ev.port2.checkStrongAuthStatus = 3; + ev.port2.checkStrongAuthStatus = 2; ev.port2.mappingName = mappingName; } } signalName = s.split("__decrypt")[0]; + + /*for (TMLTask t: getTasks()) { + if (signalName.contains(t.getName())) { + signalName = signalName.replace(t.getName()+"__",""); + } + }*/ + signalName = signalName.split("__")[1]; + // TraceManager.addDev("secpattern " + signalName); List<String> channels = secChannelMap.get(signalName); + // TraceManager.addDev("secpattern channels " + channels); if (channels != null) { for (String channelName : channels) { channel = getChannelByShortName(channelName); if (channel != null) { - TraceManager.addDev("Security ports: " + channel.getSecurityPorts()); for (TMLPortWithSecurityInformation port : channel.ports) { - if (port.getCheckAuth() && port.getCheckStrongAuthStatus() == 1) { - port.setStrongAuthStatus(3); - TraceManager.addDev("Backtracing Authenticity not verified " + signalName); + // TraceManager.addDev("adding to port " + channelName); + if (port.getCheckAuth()) { + port.setStrongAuthStatus(2); port.setSecName(signalName); ProVerifResultTrace trace = pvoa.getResults().get(pragma).getTrace(); if (trace != null && !port.isOrigin()) { @@ -1001,7 +1006,7 @@ public class TMLModeling<E> { if (channel != null) { for (TMLPortWithSecurityInformation port : channel.ports) { if (port.getCheckAuth()) { - port.setWeakAuthStatus(3); + port.setStrongAuthStatus(2); port.setSecName(signalName); ProVerifResultTrace trace = pvoa.getResults().get(pragma).getTrace(); if (trace != null && !port.isOrigin()) { @@ -1014,9 +1019,7 @@ public class TMLModeling<E> { } } } - } - - if (result.isWeakProved() && result.isWeakSatisfied()) { + } else if (result.isWeakProved() && result.isWeakSatisfied()) { TraceManager.addDev("Backtracing Authenticity weak proved and weak satisfied"); String signalName = s.split("_chData")[0]; signalName = signalName.split("__")[1]; @@ -1073,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()+"__",""); } }*/ @@ -1090,6 +1093,7 @@ public class TMLModeling<E> { TraceManager.addDev("Security ports (2): " + channel.getSecurityPorts()); for (TMLPortWithSecurityInformation port : channel.ports) { if (port.getCheckAuth()) { + port.setStrongAuthStatus(3); port.setWeakAuthStatus(2); port.setSecName(signalName); ProVerifResultTrace trace = pvoa.getResults().get(pragma).getTrace(); @@ -1136,22 +1140,21 @@ public class TMLModeling<E> { } } } - } + } else if (result.isProved() && !result.isSatisfied()) { + TraceManager.addDev("Backtracing Authenticity proved but not satisfied"); + String signalName = s.toString().split("_chData")[0]; + signalName = signalName.split("__")[signalName.split("__").length - 1]; - if (result.isProved() && result.isSatisfied()) { - TraceManager.addDev("Backtracing Authenticity proved and satisfied" ); - String signalName = s.split("_chData")[0]; - for (TMLTask t : getTasks()) { - if (signalName.contains(t.getName())) { - signalName = signalName.replace(t.getName() + "__", ""); - } - } - signalName = signalName.split("__")[1]; TMLChannel channel = getChannelByShortName(signalName); + + if (channel == null) { + channel = getChannelByDestinationPortName(signalName); + } if (channel != null) { for (TMLPortWithSecurityInformation port : channel.ports) { if (port.getCheckAuth()) { - port.setStrongAuthStatus(2); + TraceManager.addDev("Backtracing Authenticity proved but not satisfied / Found port with checkAuth"); + port.setStrongAuthStatus(3); port.setMappingName(mappingName); ProVerifResultTrace trace = pvoa.getResults().get(pragma).getTrace(); if (trace != null && !port.isOrigin()) { @@ -1160,8 +1163,10 @@ public class TMLModeling<E> { } } } + } else { + TraceManager.addDev("Backtracing Authenticity proved but not satisfied / NULL channel"); } - signalName = s.split("_reqData")[0]; + signalName = s.toString().split("_reqData")[0]; for (TMLTask t : getTasks()) { if (signalName.contains(t.getName())) { signalName = signalName.replace(t.getName() + "__", ""); @@ -1171,12 +1176,12 @@ public class TMLModeling<E> { if (req != null) { for (TMLPortWithSecurityInformation port : req.ports) { if (port.getCheckAuth()) { - port.setStrongAuthStatus(2); + port.setStrongAuthStatus(3); port.setMappingName(mappingName); } } } - signalName = s.split("_eventData")[0]; + signalName = s.toString().split("_eventData")[0]; for (TMLTask t : getTasks()) { if (signalName.contains(t.getName())) { signalName = signalName.replace(t.getName() + "__", ""); @@ -1185,33 +1190,30 @@ public class TMLModeling<E> { TMLEvent ev = getEventByName(signalName); if (ev != null) { if (ev.port.checkAuth) { - ev.port.checkStrongAuthStatus = 2; + ev.port.checkStrongAuthStatus = 3; ev.port2.mappingName = mappingName; } if (ev.port2.checkAuth) { - ev.port2.checkStrongAuthStatus = 2; + ev.port2.checkStrongAuthStatus = 3; ev.port2.mappingName = mappingName; } } signalName = s.split("__decrypt")[0]; - /*for (TMLTask t: getTasks()){ - if (signalName.contains(t.getName())){ - signalName = signalName.replace(t.getName()+"__",""); - } - }*/ signalName = signalName.split("__")[1]; - // TraceManager.addDev("secpattern " + signalName); List<String> channels = secChannelMap.get(signalName); - // TraceManager.addDev("secpattern channels " + channels); + for (Map.Entry<String, List<String>> entry : secChannelMap.entrySet()) { + System.out.println(entry.getKey() + ":" + entry.getValue()); + } + if (channels != null) { for (String channelName : channels) { channel = getChannelByShortName(channelName); if (channel != null) { for (TMLPortWithSecurityInformation port : channel.ports) { - // TraceManager.addDev("adding to port " + channelName); if (port.getCheckAuth()) { - port.setStrongAuthStatus(2); + port.setStrongAuthStatus(3); + TraceManager.addDev("Backtracing Authenticity not verified " + signalName); port.setSecName(signalName); ProVerifResultTrace trace = pvoa.getResults().get(pragma).getTrace(); if (trace != null && !port.isOrigin()) { @@ -1221,7 +1223,6 @@ public class TMLModeling<E> { } } } - } } @@ -1243,7 +1244,7 @@ public class TMLModeling<E> { if (channel != null) { for (TMLPortWithSecurityInformation port : channel.ports) { if (port.getCheckAuth()) { - port.setStrongAuthStatus(2); + port.setWeakAuthStatus(3); port.setSecName(signalName); ProVerifResultTrace trace = pvoa.getResults().get(pragma).getTrace(); if (trace != null && !port.isOrigin()) { @@ -1257,7 +1258,6 @@ public class TMLModeling<E> { } } } - } } @@ -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 ffb204dd30a100fe50d963779cf879a585b8bbec..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); } @@ -1183,7 +1183,7 @@ public class TML2Avatar { afterSignalState.addNext(tran); elementList.add(afterSignalState); elementList.add(tran); - if (autoAuthChans) { + if (autoAuthChans || ae.securityPattern == null) { if (block.getAvatarAttributeWithName(getName(ch.getName()) + "_chData") == null) { AvatarAttribute channelData = new AvatarAttribute(getName(ch.getName()) + "_chData", AvatarType.INTEGER, block, null); block.addAttribute(channelData); @@ -1250,7 +1250,7 @@ public class TML2Avatar { // To be removed in case another authenticity pragma is used on the channel // Also, to be duplicated for each send / receive if (ch.checkAuth) { - if (autoAuthChans) { + if (autoAuthChans || ae.securityPattern == null) { if (block.getAvatarAttributeWithName(getName(ch.getName()) + "_chData") == null) { AvatarAttribute channelData = new AvatarAttribute(getName(ch.getName()) + "_chData", AvatarType.INTEGER, block, null); block.addAttribute(channelData); @@ -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 55786a00d62cf63abb85b48695315fd1459b2942..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(); @@ -1812,7 +1812,175 @@ public class GTURTLEModeling { if (tmlm.securityTaskMap == null) { return; } + for (SecurityPattern sp : tmlm.securityTaskMap.keySet()) { + 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) { + HwCPU cpuNode = (HwCPU) node1; + taskMappedToCPU = true; + boolean keyMappedtoMem = false; + HwLink lastLink = null; + for (HwLink link : links) { + if (!keyMappedtoMem && link.hwnode == node1) { + lastLink = link; + if (link.bus.privacy == 1) { + HwBus curBus = link.bus; + boolean keyFound = false; + TMLArchiMemoryNode memNodeToMap = null; + outer: + for (HwLink linkBus : links) { + if (linkBus.bus == curBus) { + if (linkBus.hwnode instanceof HwMemory) { + memNodeToMap = (TMLArchiMemoryNode) listE.getTG(linkBus.hwnode); + List<TMLArchiKey> keys = memNodeToMap.getKeyList(); + for (TMLArchiKey key : keys) { + if (key.getValue().equals(sp.name)) { + keyFound = true; + keyMappedtoMem = true; + break outer; + } + } + } + } + } + if (!keyFound) { + if (memNodeToMap != null) { + TMLArchiKey key = new TMLArchiKey(memNodeToMap.x, (int)(memNodeToMap.y+memNodeToMap.getHeight()*(0.3+Math.random()/2)), memNodeToMap.tdp.getMinX(), memNodeToMap.tdp.getMaxX(), memNodeToMap.tdp.getMinY(), memNodeToMap.tdp.getMaxY(), false, memNodeToMap, memNodeToMap.tdp); + key.setReferenceKey(sp.name); + key.makeFullValue(); + TraceManager.addDev("Adding " + sp.name + " key to " + memNodeToMap.getName()); + memNodeToMap.tdp.addComponent(key, memNodeToMap.x, memNodeToMap.y, true, true); + memNodeToMap.tdp.repaint(); + keyMappedtoMem = true; + } else { + TMLArchiBUSNode busNode = (TMLArchiBUSNode) listE.getTG(curBus); + memNodeToMap = new TMLArchiMemoryNode(busNode.getX(), (int) (busNode.getY() + busNode.getHeight()*(1+Math.random())), busNode.tdp.getMinX(), busNode.tdp.getMaxX(), busNode.tdp.getMinY(), busNode.tdp.getMaxY(), false, busNode.getFather(), busNode.tdp); + memNodeToMap.setName(t.getTaskName() + "KeysMemory"); + busNode.tdp.addComponent(memNodeToMap); + + /*HwLink newLink = new HwLink("Link_"+curBus.getName() + "_" + memNodeToMap.getName()); + HwMemory newHwMemory = new HwMemory("HwMemory_" + memNodeToMap.getName()); + listE.addCor(newHwMemory, memNodeToMap); + newLink.setNodes(curBus, listE.getHwNode(memNodeToMap)); + links.add(newLink);*/ + + //Connect Bus and Memory + 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); + connect.setP2(p1); + + TGConnectingPoint p2 = memNodeToMap.findFirstFreeTGConnectingPoint(true, true); + p2.setFree(false); + connect.setP1(p2); + archPanel.addComponent(connect, memNodeToMap.getX() + 100, memNodeToMap.getY() + 100, false, true); + + TMLArchiKey key = new TMLArchiKey(memNodeToMap.x, (int)(memNodeToMap.y+memNodeToMap.getHeight()*(0.3+Math.random()/2)), memNodeToMap.tdp.getMinX(), memNodeToMap.tdp.getMaxX(), memNodeToMap.tdp.getMinY(), memNodeToMap.tdp.getMaxY(), false, memNodeToMap, memNodeToMap.tdp); + key.setReferenceKey(sp.name); + key.makeFullValue(); + TraceManager.addDev("Adding " + sp.name + " key to " + memNodeToMap.getName()); + memNodeToMap.tdp.addComponent(key, memNodeToMap.x, memNodeToMap.y, true, true); + memNodeToMap.tdp.repaint(); + keyMappedtoMem = true; + } + } + } + } + } + if (!keyMappedtoMem) { + if (lastLink != null) { + TMLArchiBUSNode lastBusNode = (TMLArchiBUSNode) listE.getTG(lastLink.bus); + TMLArchiCPUNode cpuArchiNode = (TMLArchiCPUNode) listE.getTG(cpuNode); + + TMLArchiBridgeNode newBrigde = new TMLArchiBridgeNode(lastBusNode.getX(), (int) (lastBusNode.getY() + lastBusNode.getHeight()*(1+Math.random())), lastBusNode.tdp.getMinX(), lastBusNode.tdp.getMaxX(), lastBusNode.tdp.getMinY(), lastBusNode.tdp.getMaxY(), false, lastBusNode.getFather(), lastBusNode.tdp); + newBrigde.setName(t.getTaskName() + "KeysBrigde"); + lastBusNode.tdp.addComponent(newBrigde); + + TMLArchiBUSNode newPrivateBus = new TMLArchiBUSNode(newBrigde.getX(), (int) (newBrigde.getY() + newBrigde.getHeight()*(1+Math.random())), newBrigde.tdp.getMinX(), newBrigde.tdp.getMaxX(), newBrigde.tdp.getMinY(), newBrigde.tdp.getMaxY(), false, lastBusNode.getFather(), lastBusNode.tdp); + newPrivateBus.setPrivacy(1); + newPrivateBus.setName(t.getTaskName() + "KeysPrivateBus"); + lastBusNode.tdp.addComponent(newPrivateBus); + + TMLArchiMemoryNode memNodeToMap = new TMLArchiMemoryNode(newPrivateBus.getX(), (int) (newPrivateBus.getY() + newPrivateBus.getHeight()*(1+Math.random())), newPrivateBus.tdp.getMinX(), newPrivateBus.tdp.getMaxX(), newPrivateBus.tdp.getMinY(), newPrivateBus.tdp.getMaxY(), false, lastBusNode.getFather(), lastBusNode.tdp); + memNodeToMap.setName(t.getTaskName() + "KeysMemory"); + lastBusNode.tdp.addComponent(memNodeToMap); + + TMLArchiKey key = new TMLArchiKey(memNodeToMap.x, (int)(memNodeToMap.y+memNodeToMap.getHeight()*(0.3+Math.random()/2)), memNodeToMap.tdp.getMinX(), memNodeToMap.tdp.getMaxX(), memNodeToMap.tdp.getMinY(), memNodeToMap.tdp.getMaxY(), false, memNodeToMap, memNodeToMap.tdp); + key.setReferenceKey(sp.name); + key.makeFullValue(); + TraceManager.addDev("Adding " + sp.name + " key to " + memNodeToMap.getName()); + memNodeToMap.tdp.addComponent(key, memNodeToMap.x, memNodeToMap.y, true, true); + memNodeToMap.tdp.repaint(); + keyMappedtoMem = true; + + //Connect Bus and Memory + TMLArchiConnectorNode connectbusMem = new TMLArchiConnectorNode(memNodeToMap.getX() + 100, lastBusNode.tdp.getMaxY() - 300, lastBusNode.tdp.getMinX(), lastBusNode.tdp.getMaxX(), lastBusNode.tdp.getMinY(), lastBusNode.tdp.getMaxY(), true, null, lastBusNode.tdp, null, null, new Vector<Point>()); + TGConnectingPoint p1 = newPrivateBus.findFirstFreeTGConnectingPoint(true, true); + p1.setFree(false); + connectbusMem.setP2(p1); + + TGConnectingPoint p2 = memNodeToMap.findFirstFreeTGConnectingPoint(true, true); + p2.setFree(false); + connectbusMem.setP1(p2); + lastBusNode.tdp.addComponent(connectbusMem, memNodeToMap.getX() + 100, memNodeToMap.getY() + 100, false, true); + + //Connect new Private Bus and Bridge + TMLArchiConnectorNode connectPrivatebusBridge = new TMLArchiConnectorNode(newBrigde.getX() + 100, lastBusNode.tdp.getMaxY() - 300, lastBusNode.tdp.getMinX(), lastBusNode.tdp.getMaxX(), lastBusNode.tdp.getMinY(), lastBusNode.tdp.getMaxY(), true, null, lastBusNode.tdp, null, null, new Vector<Point>()); + p1 = newPrivateBus.findFirstFreeTGConnectingPoint(true, true); + p1.setFree(false); + connectPrivatebusBridge.setP2(p1); + + p2 = newBrigde.findFirstFreeTGConnectingPoint(true, true); + p2.setFree(false); + connectPrivatebusBridge.setP1(p2); + lastBusNode.tdp.addComponent(connectPrivatebusBridge, newBrigde.getX() + 100, newBrigde.getY() + 100, false, true); + + //Connect Public Bus and Bridge + TMLArchiConnectorNode connectPublicbusBridge = new TMLArchiConnectorNode(newBrigde.getX() + 100, lastBusNode.tdp.getMaxY() - 300, lastBusNode.tdp.getMinX(), lastBusNode.tdp.getMaxX(), lastBusNode.tdp.getMinY(), lastBusNode.tdp.getMaxY(), true, null, lastBusNode.tdp, null, null, new Vector<Point>()); + p1 = lastBusNode.findFirstFreeTGConnectingPoint(true, true); + p1.setFree(false); + connectPublicbusBridge.setP2(p1); + + p2 = newBrigde.findFirstFreeTGConnectingPoint(true, true); + p2.setFree(false); + connectPublicbusBridge.setP1(p2); + lastBusNode.tdp.addComponent(connectPublicbusBridge, newBrigde.getX() + 100, newBrigde.getY() + 100, false, true); + + //Connect new Private Bus and CPU + TMLArchiConnectorNode connectPrivatebusCPU = new TMLArchiConnectorNode(cpuArchiNode.getX() + 100, lastBusNode.tdp.getMaxY() - 300, lastBusNode.tdp.getMinX(), lastBusNode.tdp.getMaxX(), lastBusNode.tdp.getMinY(), lastBusNode.tdp.getMaxY(), true, null, lastBusNode.tdp, null, null, new Vector<Point>()); + p1 = newPrivateBus.findFirstFreeTGConnectingPoint(true, true); + p1.setFree(false); + connectPrivatebusCPU.setP2(p1); + + p2 = cpuArchiNode.findFirstFreeTGConnectingPoint(true, true); + p2.setFree(false); + connectPrivatebusCPU.setP1(p2); + lastBusNode.tdp.addComponent(connectPrivatebusCPU, cpuArchiNode.getX() + 100, cpuArchiNode.getY() + 100, false, true); + + //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)) { + TraceManager.addDev("Disconnect :" + connector.getTGComponent1().getName() + " and " + connector.getTGComponent2().getName()); + lastBusNode.tdp.removeComponent(connector); + } + } + } + } + } + } + if (!taskMappedToCPU) { + TraceManager.addDev(t.getTaskName() + " has to be mapped to a CPU!"); + } + } + } + } // + /* for (SecurityPattern sp : tmlm.securityTaskMap.keySet()) { if (sp.type.contains("Symmetric Encryption") || sp.type.equals("MAC")) { @@ -1952,7 +2120,7 @@ public class GTURTLEModeling { } } } - } + }*/ TraceManager.addDev("Mapping finished"); } @@ -3145,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) { @@ -3356,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 { @@ -7427,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()); }*/ @@ -7629,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()); }*/ @@ -7658,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()); }*/ @@ -7684,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()); }*/ @@ -8720,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; @@ -9070,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); } } @@ -9623,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 600f3cb93c48f85ec99b47a397ab709772075b4f..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); }*/ /*} @@ -824,22 +824,33 @@ public class SecurityGeneration implements Runnable { tcdp.addComponent(conn, 0, 0, false, true); List<TMLChannel> chans2 = tmlmodel.getChannelsFromMe(task2); - for (TGComponent comps : newarch.tmlap.getComponentList()) { - if (comps instanceof TMLArchiMemoryNode) { - TMLArchiMemoryNode compMem = (TMLArchiMemoryNode) comps; + int count_chans = 0; + TMLArchiCommunicationArtifact newChannelInMem = null; + TMLArchiMemoryNode compMemToPutChannel = null; + for (TGComponent comp : newarch.tmlap.getComponentList()) { + if (comp instanceof TMLArchiMemoryNode) { + TMLArchiMemoryNode compMem = (TMLArchiMemoryNode) comp; for (TMLArchiCommunicationArtifact channelAtif : compMem.getChannelArtifactList()) { for (TMLChannel chan : chans2) { - if (chan.getName().split("__")[1].equals(channelAtif.getCommunicationName())) { - TMLArchiCommunicationArtifact newChannelInMem = new TMLArchiCommunicationArtifact(compMem.getX(), (int)(compMem.getY()+compMem.getHeight()*(0.3+Math.random()/2)), compMem.getCurrentMinX(), compMem.getCurrentMaxX(), compMem.getCurrentMinY(), compMem.getCurrentMaxY(), true, comps, newarch.tmlap); - newChannelInMem.setReferenceCommunicationName(channelAtif.getReferenceCommunicationName()); - newChannelInMem.setCommunicationName(destPort.commName); - newChannelInMem.setOtherCommunicationNames(channelAtif.getOtherCommunicationNames()); - compMem.addInternalComponent(newChannelInMem, compMem.getNbInternalTGComponent()); + if (chan.isCheckAuthChannel()) { + if (chan.getName().split("__")[1].equals(channelAtif.getCommunicationName())) { + 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); + newChannelInMem.setReferenceCommunicationName(channelAtif.getReferenceCommunicationName()); + } + newChannelInMem.addNewOtherCommunicationNames(channelAtif.getOtherCommunicationNames()); + } } } } } } + if (count_chans > 0) { + compMemToPutChannel.addInternalComponent(newChannelInMem, compMemToPutChannel.getNbInternalTGComponent()); + } } } } @@ -924,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; @@ -1021,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; @@ -1284,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; @@ -1421,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; @@ -1537,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; @@ -1619,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; // } @@ -1754,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; @@ -1893,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 ea036c374bb44f649e4bfc395688a6d6b90d97d2..3c9a79ed1ec242c53f39b2afeb7c4a46392c483d 100755 --- a/src/main/java/ui/tmldd/TMLArchiCommunicationArtifact.java +++ b/src/main/java/ui/tmldd/TMLArchiCommunicationArtifact.java @@ -386,8 +386,12 @@ public class TMLArchiCommunicationArtifact extends TGCWithoutInternalComponent i return mappedElements; } - public void setOtherCommunicationNames(ArrayList<String> _mappedElements) { - mappedElements = _mappedElements; + public void addNewOtherCommunicationNames(ArrayList<String> _mappedElements) { + for(String mappedElem: _mappedElements) { + if (!mappedElements.contains(mappedElem)) { + mappedElements.add(mappedElem); + } + } makeFullValue(); } 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;