From 6634dded555ec73b19f0a2757f22518fd6cd1393 Mon Sep 17 00:00:00 2001 From: Dunith Dhanushka Date: Tue, 17 Jan 2017 15:09:05 +0530 Subject: [PATCH 01/18] Building the anchor text --- .../cdmf.unit.device.type.android.device-view/device-view.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js index c192718e8..4dcc25e5d 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js @@ -213,7 +213,6 @@ function onRequest(context) { deviceViewData["autoCompleteParams"] = autoCompleteParams; deviceViewData["portalUrl"] = devicemgtProps['portalURL']; - deviceViewData["deviceId"] = deviceId; - deviceViewData["deviceType"] = deviceType; + deviceViewData["anchor"] = encodeURI(JSON.stringify({ "device" : { "id" : deviceId, "type" : deviceType}})); return deviceViewData; } From 54b08f9b7a7d99ae9df74252c34abec41661737d Mon Sep 17 00:00:00 2001 From: Dunith Dhanushka Date: Tue, 17 Jan 2017 15:10:46 +0530 Subject: [PATCH 02/18] Adding the JSON formatted anchor text --- .../cdmf.unit.device.type.android.device-view/device-view.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.hbs index 38e3284f0..4a2461696 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.hbs @@ -339,7 +339,7 @@
+ href="{{portalUrl}}/portal/dashboards/geo-dashboard/?GLOBAL-STATE={{anchor}}"> From d4107747ab9f572580c1ac4100312d5d282ccc69 Mon Sep 17 00:00:00 2001 From: Dunith Dhanushka Date: Tue, 17 Jan 2017 15:35:59 +0530 Subject: [PATCH 03/18] Update device-view.js --- .../device-view.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.js b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.js index a3ef93ec7..e5ff0676c 100644 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.js +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.js @@ -35,11 +35,11 @@ function onRequest(context) { "autoCompleteParams": autoCompleteParams, "encodedFeaturePayloads": "", "portalUrl" : devicemgtProps['portalURL'], - "anchor" : JSON.stringify(anchor) + "anchor" : encodeURI(JSON.stringify(anchor)) }; } else { response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!"); exit(); } } -} \ No newline at end of file +} From bbbfff28d95ddf687a651b22070a0c9b7d03ebf1 Mon Sep 17 00:00:00 2001 From: Dunith Dhanushka Date: Tue, 17 Jan 2017 15:40:27 +0530 Subject: [PATCH 04/18] UI Improvements for Geo Fencing --- .../device-view.hbs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.hbs b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.hbs index e23f3c0c1..628f5fc11 100644 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.hbs +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android_sense.device-view/device-view.hbs @@ -44,7 +44,7 @@
  • Operations Log
  • Map
  • + aria-controls="geo_dashboard">Geo Fencing {{/zone}} {{#zone "device-view-tab-contents"}} @@ -77,18 +77,18 @@ {{/zone}} From e65b61bf95779cdc267c41fc134b3ad32aa653f4 Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Tue, 17 Jan 2017 16:05:42 +0530 Subject: [PATCH 05/18] Fix Message digest is weak security bug --- .../advanced/transport/CommunicationUtils.java | 14 +++++++------- .../agent/transport/CommunicationUtils.java | 14 +++++++------- .../impl/VirtualFirealarmSecurityManager.java | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/transport/CommunicationUtils.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/transport/CommunicationUtils.java index e6e16ba52..dfcc4268c 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/transport/CommunicationUtils.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/transport/CommunicationUtils.java @@ -43,7 +43,7 @@ public class CommunicationUtils { private static final Log log = LogFactory.getLog(TransportUtils.class); // The Signature Algorithm used. - private static final String SIGNATURE_ALG = "SHA1withRSA"; + private static final String SHA_512 = "SHA-512"; // The Encryption Algorithm and the Padding used. private static final String CIPHER_PADDING = "RSA/ECB/PKCS1Padding"; @@ -108,7 +108,7 @@ public class CommunicationUtils { String signedEncodedString; try { - signature = Signature.getInstance(SIGNATURE_ALG); + signature = Signature.getInstance(SHA_512); signature.initSign(signatureKey); signature.update(Base64.decodeBase64(message)); @@ -117,11 +117,11 @@ public class CommunicationUtils { } catch (NoSuchAlgorithmException e) { String errorMsg = - "Algorithm not found exception occurred for Signature instance of [" + SIGNATURE_ALG + "]"; + "Algorithm not found exception occurred for Signature instance of [" + SHA_512 + "]"; log.error(errorMsg); throw new TransportHandlerException(errorMsg, e); } catch (SignatureException e) { - String errorMsg = "Signature exception occurred for Signature instance of [" + SIGNATURE_ALG + "]"; + String errorMsg = "Signature exception occurred for Signature instance of [" + SHA_512 + "]"; log.error(errorMsg); throw new TransportHandlerException(errorMsg, e); } catch (InvalidKeyException e) { @@ -153,7 +153,7 @@ public class CommunicationUtils { boolean verified; try { - signature = Signature.getInstance(SIGNATURE_ALG); + signature = Signature.getInstance(SHA_512); signature.initVerify(verificationKey); signature.update(Base64.decodeBase64(data)); @@ -161,11 +161,11 @@ public class CommunicationUtils { } catch (NoSuchAlgorithmException e) { String errorMsg = - "Algorithm not found exception occurred for Signature instance of [" + SIGNATURE_ALG + "]"; + "Algorithm not found exception occurred for Signature instance of [" + SHA_512 + "]"; log.error(errorMsg); throw new TransportHandlerException(errorMsg, e); } catch (SignatureException e) { - String errorMsg = "Signature exception occurred for Signature instance of [" + SIGNATURE_ALG + "]"; + String errorMsg = "Signature exception occurred for Signature instance of [" + SHA_512 + "]"; log.error(errorMsg); throw new TransportHandlerException(errorMsg, e); } catch (InvalidKeyException e) { diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/transport/CommunicationUtils.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/transport/CommunicationUtils.java index bb445a3d9..46a43a0ba 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/transport/CommunicationUtils.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/transport/CommunicationUtils.java @@ -43,7 +43,7 @@ public class CommunicationUtils { private static final Log log = LogFactory.getLog(TransportUtils.class); // The Signature Algorithm used. - private static final String SIGNATURE_ALG = "SHA1withRSA"; + private static final String SHA_512 = "SHA-512"; // The Encryption Algorithm and the Padding used. private static final String CIPHER_PADDING = "RSA/ECB/PKCS1Padding"; @@ -107,7 +107,7 @@ public class CommunicationUtils { String signedEncodedString; try { - signature = Signature.getInstance(SIGNATURE_ALG); + signature = Signature.getInstance(SHA_512); signature.initSign(signatureKey); signature.update(Base64.decodeBase64(message)); @@ -116,11 +116,11 @@ public class CommunicationUtils { } catch (NoSuchAlgorithmException e) { String errorMsg = - "Algorithm not found exception occurred for Signature instance of [" + SIGNATURE_ALG + "]"; + "Algorithm not found exception occurred for Signature instance of [" + SHA_512 + "]"; log.error(errorMsg); throw new TransportHandlerException(errorMsg, e); } catch (SignatureException e) { - String errorMsg = "Signature exception occurred for Signature instance of [" + SIGNATURE_ALG + "]"; + String errorMsg = "Signature exception occurred for Signature instance of [" + SHA_512 + "]"; log.error(errorMsg); throw new TransportHandlerException(errorMsg, e); } catch (InvalidKeyException e) { @@ -152,7 +152,7 @@ public class CommunicationUtils { boolean verified; try { - signature = Signature.getInstance(SIGNATURE_ALG); + signature = Signature.getInstance(SHA_512); signature.initVerify(verificationKey); signature.update(Base64.decodeBase64(data)); @@ -160,11 +160,11 @@ public class CommunicationUtils { } catch (NoSuchAlgorithmException e) { String errorMsg = - "Algorithm not found exception occurred for Signature instance of [" + SIGNATURE_ALG + "]"; + "Algorithm not found exception occurred for Signature instance of [" + SHA_512 + "]"; log.error(errorMsg); throw new TransportHandlerException(errorMsg, e); } catch (SignatureException e) { - String errorMsg = "Signature exception occurred for Signature instance of [" + SIGNATURE_ALG + "]"; + String errorMsg = "Signature exception occurred for Signature instance of [" + SHA_512 + "]"; log.error(errorMsg); throw new TransportHandlerException(errorMsg, e); } catch (InvalidKeyException e) { diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/VirtualFirealarmSecurityManager.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/VirtualFirealarmSecurityManager.java index 9ff12424b..f7b19fdce 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/VirtualFirealarmSecurityManager.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/VirtualFirealarmSecurityManager.java @@ -51,7 +51,7 @@ public class VirtualFirealarmSecurityManager { private static final Log log = LogFactory.getLog(VirtualFirealarmSecurityManager.class); private static PrivateKey serverPrivateKey; - private static final String SIGNATURE_ALG = "SHA1withRSA"; + private static final String SHA_512 = "SHA-512"; private static final String CIPHER_PADDING = "RSA/ECB/PKCS1Padding"; private static CertificateKeystoreConfig certificateKeystoreConfig; private VirtualFirealarmSecurityManager() { @@ -162,7 +162,7 @@ public class VirtualFirealarmSecurityManager { String signedEncodedString; try { - signature = Signature.getInstance(SIGNATURE_ALG); + signature = Signature.getInstance(SHA_512); signature.initSign(signatureKey); signature.update(Base64.decodeBase64(encryptedData)); @@ -170,11 +170,11 @@ public class VirtualFirealarmSecurityManager { signedEncodedString = Base64.encodeBase64String(signatureBytes); } catch (NoSuchAlgorithmException e) { - String errorMsg = "Algorithm not found exception occurred for Signature instance of [" + SIGNATURE_ALG + "]"; + String errorMsg = "Algorithm not found exception occurred for Signature instance of [" + SHA_512 + "]"; log.error(errorMsg); throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e); } catch (SignatureException e) { - String errorMsg = "Signature exception occurred for Signature instance of [" + SIGNATURE_ALG + "]"; + String errorMsg = "Signature exception occurred for Signature instance of [" + SHA_512 + "]"; log.error(errorMsg); throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e); } catch (InvalidKeyException e) { @@ -193,18 +193,18 @@ public class VirtualFirealarmSecurityManager { boolean verified; try { - signature = Signature.getInstance(SIGNATURE_ALG); + signature = Signature.getInstance(SHA_512); signature.initVerify(verificationKey); signature.update(Base64.decodeBase64(data)); verified = signature.verify(Base64.decodeBase64(signedData)); } catch (NoSuchAlgorithmException e) { - String errorMsg = "Algorithm not found exception occurred for Signature instance of [" + SIGNATURE_ALG + "]"; + String errorMsg = "Algorithm not found exception occurred for Signature instance of [" + SHA_512 + "]"; log.error(errorMsg); throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e); } catch (SignatureException e) { - String errorMsg = "Signature exception occurred for Signature instance of [" + SIGNATURE_ALG + "]"; + String errorMsg = "Signature exception occurred for Signature instance of [" + SHA_512 + "]"; log.error(errorMsg); throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e); } catch (InvalidKeyException e) { From b06d86f87a237931295aa8374d035deabc68461f Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Tue, 17 Jan 2017 16:07:02 +0530 Subject: [PATCH 06/18] Fix Predictable pseudorandom number generator security issue --- .../advanced/transport/TransportUtils.java | 39 ++++++++++--------- .../virtual/VirtualHardwareManager.java | 11 ++++-- .../agent/transport/TransportUtils.java | 39 ++++++++++--------- .../agent/virtual/VirtualHardwareManager.java | 14 ++++--- 4 files changed, 56 insertions(+), 47 deletions(-) diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/transport/TransportUtils.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/transport/TransportUtils.java index 5045e4313..4fb1c5adb 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/transport/TransportUtils.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/transport/TransportUtils.java @@ -34,6 +34,8 @@ import java.net.ServerSocket; import java.net.SocketException; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; @@ -172,27 +174,26 @@ public class TransportUtils { */ public static synchronized int getAvailablePort(int randomAttempts) { ArrayList failedPorts = new ArrayList(randomAttempts); - - Random randomNum = new Random(); - int randomPort = MAX_PORT_NUMBER; - - while (randomAttempts > 0) { - randomPort = randomNum.nextInt(MAX_PORT_NUMBER - MIN_PORT_NUMBER) + MIN_PORT_NUMBER; - - if (checkIfPortAvailable(randomPort)) { - return randomPort; + try { + SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG"); + int randomPort = MAX_PORT_NUMBER; + while (randomAttempts > 0) { + randomPort = secureRandom.nextInt(MAX_PORT_NUMBER - MIN_PORT_NUMBER) + MIN_PORT_NUMBER; + if (checkIfPortAvailable(randomPort)) { + return randomPort; + } + failedPorts.add(randomPort); + randomAttempts--; } - failedPorts.add(randomPort); - randomAttempts--; - } - - randomPort = MAX_PORT_NUMBER; - - while (true) { - if (!failedPorts.contains(randomPort) && checkIfPortAvailable(randomPort)) { - return randomPort; + randomPort = MAX_PORT_NUMBER; + while (true) { + if (!failedPorts.contains(randomPort) && checkIfPortAvailable(randomPort)) { + return randomPort; + } + randomPort--; } - randomPort--; + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException("SHA1PRNG algorithm could not be found."); } } diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/virtual/VirtualHardwareManager.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/virtual/VirtualHardwareManager.java index 59a13bb87..1a676ed82 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/virtual/VirtualHardwareManager.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/virtual/VirtualHardwareManager.java @@ -33,6 +33,8 @@ import javax.sound.sampled.Clip; import javax.swing.*; import java.io.IOException; import java.io.InputStream; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; /** * This class use to emulate virtual hardware functionality @@ -188,9 +190,12 @@ public class VirtualHardwareManager { double mn = current - offset; min = (mn < min) ? min : (int) Math.round(mn); } - - double rnd = Math.random() * (max - min) + min; - return (int) Math.round(rnd); + try { + SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG"); + return secureRandom.nextInt(max - min) + min; + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException("SHA1PRNG algorithm could not be found."); + } } diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/transport/TransportUtils.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/transport/TransportUtils.java index 11ebc04bf..b55aee02d 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/transport/TransportUtils.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/transport/TransportUtils.java @@ -36,6 +36,8 @@ import java.net.ServerSocket; import java.net.SocketException; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; @@ -173,27 +175,26 @@ public class TransportUtils { */ public static synchronized int getAvailablePort(int randomAttempts) { ArrayList failedPorts = new ArrayList(randomAttempts); - - Random randomNum = new Random(); - int randomPort = MAX_PORT_NUMBER; - - while (randomAttempts > 0) { - randomPort = randomNum.nextInt(MAX_PORT_NUMBER - MIN_PORT_NUMBER) + MIN_PORT_NUMBER; - - if (checkIfPortAvailable(randomPort)) { - return randomPort; + try { + SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG"); + int randomPort = MAX_PORT_NUMBER; + while (randomAttempts > 0) { + randomPort = secureRandom.nextInt(MAX_PORT_NUMBER - MIN_PORT_NUMBER) + MIN_PORT_NUMBER; + if (checkIfPortAvailable(randomPort)) { + return randomPort; + } + failedPorts.add(randomPort); + randomAttempts--; } - failedPorts.add(randomPort); - randomAttempts--; - } - - randomPort = MAX_PORT_NUMBER; - - while (true) { - if (!failedPorts.contains(randomPort) && checkIfPortAvailable(randomPort)) { - return randomPort; + randomPort = MAX_PORT_NUMBER; + while (true) { + if (!failedPorts.contains(randomPort) && checkIfPortAvailable(randomPort)) { + return randomPort; + } + randomPort--; } - randomPort--; + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException("SHA1PRNG algorithm could not be found."); } } diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/virtual/VirtualHardwareManager.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/virtual/VirtualHardwareManager.java index 3b777cf75..61135c58a 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/virtual/VirtualHardwareManager.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/virtual/VirtualHardwareManager.java @@ -33,6 +33,8 @@ import javax.sound.sampled.Clip; import javax.swing.*; import java.io.IOException; import java.io.InputStream; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; /** * This class use to emulate virtual hardware functionality @@ -174,19 +176,19 @@ public class VirtualHardwareManager { } private int getRandom(int max, int min, int current, boolean isSmoothed, int svf) { - if (isSmoothed) { int offset = (max - min) * svf / 100; double mx = current + offset; max = (mx > max) ? max : (int) Math.round(mx); - double mn = current - offset; min = (mn < min) ? min : (int) Math.round(mn); } - - double rnd = Math.random() * (max - min) + min; - return (int) Math.round(rnd); - + try { + SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG"); + return secureRandom.nextInt(max - min) + min; + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException("SHA1PRNG algorithm could not be found."); + } } private void setAudioSequencer() { From cb9783a67fa38a99f6943db6bfec345651627b1c Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Tue, 17 Jan 2017 16:08:00 +0530 Subject: [PATCH 07/18] Fix Hard Coded Password security warning --- .../agent/enrollment/EnrollmentManager.java | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/enrollment/EnrollmentManager.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/enrollment/EnrollmentManager.java index deaa5ac24..26006620f 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/enrollment/EnrollmentManager.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/enrollment/EnrollmentManager.java @@ -129,11 +129,8 @@ public class EnrollmentManager { public void setEnrollmentStatus() { KeyStore keyStore; - try { keyStore = KeyStore.getInstance(AgentConstants.DEVICE_KEYSTORE_TYPE); - keyStore.load(new FileInputStream(AgentConstants.DEVICE_KEYSTORE), - AgentConstants.DEVICE_KEYSTORE_PASSWORD.toCharArray()); this.isEnrolled = (keyStore.containsAlias(AgentConstants.DEVICE_CERT_ALIAS) && keyStore.containsAlias(AgentConstants.DEVICE_PRIVATE_KEY_ALIAS) && @@ -146,21 +143,7 @@ public class EnrollmentManager { log.error(AgentConstants.LOG_APPENDER + e); log.warn(AgentConstants.LOG_APPENDER + "Device will be re-enrolled."); return; - } catch (CertificateException | NoSuchAlgorithmException e) { - log.error(AgentConstants.LOG_APPENDER + "An error occurred whilst trying to [load] the device KeyStore '" + - AgentConstants.DEVICE_KEYSTORE + "'."); - log.error(AgentConstants.LOG_APPENDER + e); - log.warn(AgentConstants.LOG_APPENDER + "Device will be re-enrolled."); - return; - } catch (IOException e) { - log.error(AgentConstants.LOG_APPENDER + - "An error occurred whilst trying to load input stream with the keystore file: " + - AgentConstants.DEVICE_KEYSTORE); - log.error(AgentConstants.LOG_APPENDER + e); - log.warn(AgentConstants.LOG_APPENDER + "Device will be re-enrolled."); - return; } - try { if (this.isEnrolled) { this.SCEPCertificate = (X509Certificate) keyStore.getCertificate(AgentConstants.DEVICE_CERT_ALIAS); @@ -262,9 +245,6 @@ public class EnrollmentManager { KeyStore keyStore; try { keyStore = KeyStore.getInstance(AgentConstants.DEVICE_KEYSTORE_TYPE); - keyStore.load(new FileInputStream(AgentConstants.DEVICE_KEYSTORE), - AgentConstants.DEVICE_KEYSTORE_PASSWORD.toCharArray()); - keyStore.setCertificateEntry(alias, certificate); keyStore.store(new FileOutputStream(AgentConstants.DEVICE_KEYSTORE), AgentConstants.DEVICE_KEYSTORE_PASSWORD.toCharArray()); @@ -285,9 +265,6 @@ public class EnrollmentManager { KeyStore keyStore; try { keyStore = KeyStore.getInstance(AgentConstants.DEVICE_KEYSTORE_TYPE); - keyStore.load(new FileInputStream(AgentConstants.DEVICE_KEYSTORE), - AgentConstants.DEVICE_KEYSTORE_PASSWORD.toCharArray()); - Certificate[] certChain = new Certificate[1]; certChain[0] = certInCertChain; From f699ba54b3d905e64415f6edd0e74f2e3243ec4d Mon Sep 17 00:00:00 2001 From: Menaka Jayawardena Date: Tue, 17 Jan 2017 16:14:49 +0530 Subject: [PATCH 08/18] Added Api annotation to AndroidSenseService --- .../mgt/iot/androidsense/service/impl/AndroidSenseService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java index b259eb6b5..aca23b632 100644 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java @@ -69,6 +69,8 @@ import javax.ws.rs.core.Response; ) } ) +@Api(value = "Android Sense Device Management", + description = "This carries all the resources related to the Android sense device management functionalities.") public interface AndroidSenseService { /** From 88b8901f75a6a43a302422f232e0b38ad037abe4 Mon Sep 17 00:00:00 2001 From: Menaka Jayawardena Date: Tue, 17 Jan 2017 16:15:23 +0530 Subject: [PATCH 09/18] Removed unused Test page from portal dashboard. --- .../android_sense_dashboard/android-iot.json | 152 ------------------ 1 file changed, 152 deletions(-) diff --git a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_dashboard/android-iot.json b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_dashboard/android-iot.json index 41eaafb20..58a1b2718 100644 --- a/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_dashboard/android-iot.json +++ b/components/device-types/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_dashboard/android-iot.json @@ -56,13 +56,6 @@ "ishidden": false, "subordinates": [], "title": "Communication" - }, - { - "id": "test", - "isanon": false, - "ishidden": false, - "title": "Test", - "subordinates": [] } ], "pages": [ @@ -1299,151 +1292,6 @@ "fluidLayout": false }, "title": "Communication" - }, - { - "id": "test", - "title": "Test", - "layout": { - "content": { - "loggedIn": { - "blocks": [ - { - "id": "49cada6f023f237c953761b597752212", - "x": 0, - "y": 1, - "width": 5, - "height": 1, - "banner": false - }, - { - "id": "a26d2f62dbb0011edf13371a2eb3cdd1", - "x": 0, - "y": 0, - "width": 3, - "height": 1, - "banner": false - } - ] - } - }, - "fluidLayout": false - }, - "isanon": false, - "content": { - "default": { - "49cada6f023f237c953761b597752212": [ - { - "id": "date-picker-widget-0", - "content": { - "id": "date-picker-widget", - "title": "Date Picker Widget", - "type": "widget", - "category": "Widgets", - "thumbnail": "fs://gadget/date-picker-widget/index.png", - "data": { - "url": "fs://gadget/date-picker-widget/index.xml" - }, - "options": {}, - "styles": { - "no_heading": true, - "hide_gadget": false, - "titlePosition": "left", - "title": "Date Picker Widget" - }, - "notify": { - "date-selected": { - "type": "message", - "description": "This notifies selected date" - } - }, - "locale_titles": { - "en-US": "Date Picker Widget" - }, - "settings": { - "priority": "5", - "timeoutInterval": "60000" - } - } - } - ], - "33faa57accead8af549c70f111face99": [ - { - "id": "EsbAnalytics-Gadget-Search_Box-0", - "content": { - "id": "EsbAnalytics-Gadget-Search_Box", - "title": "Search Box", - "type": "widget", - "category": "Widgets", - "thumbnail": "fs://gadget/usa-business-revenue/index.png", - "data": { - "url": "fs://gadget/EsbAnalytics-Gadget-Search_Box/index.xml" - }, - "styles": { - "no_heading": true, - "hide_gadget": false, - "titlePosition": "left", - "title": "Search Box" - }, - "toolbarButtons": { - "default": { - "maximize": false, - "configurations": false - }, - "custom": [], - "isDropdownView": false - }, - "options": {}, - "locale_titles": { - "en-US": "Search Box" - }, - "settings": { - "priority": "5", - "timeoutInterval": "60000" - } - } - } - ], - "be290fcc084ff118decc23588febc2ed": [], - "a26d2f62dbb0011edf13371a2eb3cdd1": [ - { - "id": "Android_Device_SearchBox-0", - "content": { - "id": "Android_Device_SearchBox", - "title": "Search Box", - "type": "gadget", - "category": "Gadgets", - "thumbnail": "fs://gadget/usa-business-revenue/index.png", - "data": { - "url": "fs://gadget/Android_Device_SearchBox/index.xml" - }, - "styles": { - "no_heading": true, - "hide_gadget": false, - "titlePosition": "left", - "title": "Search Box" - }, - "toolbarButtons": { - "default": { - "maximize": false, - "configurations": false - }, - "custom": [], - "isDropdownView": false - }, - "options": {}, - "locale_titles": { - "en-US": "Search Box" - }, - "settings": { - "priority": "5", - "timeoutInterval": "60000" - } - } - } - ] - }, - "anon": {} - } } ], "permissions": { From 62ba568e0541c86d6d8ade741c5e37f40ee94713 Mon Sep 17 00:00:00 2001 From: Imesh Chandrasiri Date: Tue, 17 Jan 2017 17:34:51 +0530 Subject: [PATCH 10/18] Fixed android type view notification pane message inconsistancy issue --- .../public/js/type-view.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/public/js/type-view.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/public/js/type-view.js index 5f33fdb5b..7d9c77921 100755 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/public/js/type-view.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/public/js/type-view.js @@ -131,7 +131,10 @@ function loadNewNotifications() { viewModel["appContext"] = context; $(messageSideBar).html(template(viewModel)); } else { - $(messageSideBar).html(''); + $(messageSideBar).html("

    No New Notifications

    " + + "
    " + + "Check this section for error notifications
    related to device operations" + + "
    "); } } else { $(messageSideBar).html("

    Unexpected error " + From dc840c389a006345d9f450c9ce4127acf3b445b7 Mon Sep 17 00:00:00 2001 From: Imesh Chandrasiri Date: Tue, 17 Jan 2017 17:48:12 +0530 Subject: [PATCH 11/18] Fix for inconsistant notification message --- .../public/js/type-view.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.type-view/public/js/type-view.js b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.type-view/public/js/type-view.js index cd364ebbd..9d6bcd266 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.type-view/public/js/type-view.js +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.type-view/public/js/type-view.js @@ -131,7 +131,10 @@ function loadNewNotifications() { viewModel["appContext"] = context; $(messageSideBar).html(template(viewModel)); } else { - $(messageSideBar).html(''); + $(messageSideBar).html("

    No New Notifications

    " + + "
    " + + "Check this section for error notifications
    related to device operations" + + "
    "); } } else { $(messageSideBar).html("

    Unexpected error " + From 444119790cbdabef41b90619769d13439b11f75a Mon Sep 17 00:00:00 2001 From: Megala Date: Wed, 18 Jan 2017 02:33:04 +0530 Subject: [PATCH 12/18] Fixing geo dashboard issues --- .../geo-dashboard/index.xml | 2 +- .../geo-dashboard/js/app.js | 89 +++++++++++++++--- .../geo-dashboard/js/websocket.js | 2 + .../public/asset/android-agent.apk | Bin 4250409 -> 4250280 bytes 4 files changed, 78 insertions(+), 15 deletions(-) diff --git a/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/src/main/resources/carbonapps/GadgetGeoDashboard_1.0.0/geo-dashboard/index.xml b/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/src/main/resources/carbonapps/GadgetGeoDashboard_1.0.0/geo-dashboard/index.xml index 4dbde58f8..ee92e8e65 100644 --- a/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/src/main/resources/carbonapps/GadgetGeoDashboard_1.0.0/geo-dashboard/index.xml +++ b/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/src/main/resources/carbonapps/GadgetGeoDashboard_1.0.0/geo-dashboard/index.xml @@ -432,7 +432,7 @@