Refactored the VirtualFirealarm Controller Impl classes

Shabirmean 9 years ago
parent 68beecafc4
commit bd924c530f

@ -29,7 +29,7 @@ import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.exception.VirtualFireAlarmException;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VerificationManager;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.SecurityManager;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VirtualFireAlarmServiceUtils;
import java.io.File;
@ -99,7 +99,7 @@ public class VirtualFireAlarmMQTTConnector extends MQTTTransportHandler {
try {
PublicKey clientPublicKey = VirtualFireAlarmServiceUtils.getDevicePublicKey(deviceId);
PrivateKey serverPrivateKey = VerificationManager.getServerPrivateKey();
PrivateKey serverPrivateKey = SecurityManager.getServerPrivateKey();
actualMessage = VirtualFireAlarmServiceUtils.extractMessageFromPayload(mqttMessage.toString(),
serverPrivateKey, clientPublicKey);
if (log.isDebugEnabled()) {
@ -151,7 +151,7 @@ public class VirtualFireAlarmMQTTConnector extends MQTTTransportHandler {
try {
PublicKey devicePublicKey = VirtualFireAlarmServiceUtils.getDevicePublicKey(deviceId);
PrivateKey serverPrivateKey = VerificationManager.getServerPrivateKey();
PrivateKey serverPrivateKey = SecurityManager.getServerPrivateKey();
String actualMessage = resource + ":" + state;
String encryptedMsg = VirtualFireAlarmServiceUtils.prepareSecurePayLoad(actualMessage,

@ -20,7 +20,6 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.jivesoftware.smack.packet.Message;
import org.wso2.carbon.device.mgt.iot.config.server.DeviceManagementConfigurationManager;
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppAccount;
@ -32,11 +31,10 @@ import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
import org.wso2.carbon.device.mgt.iot.transport.xmpp.XMPPTransportHandler;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.exception.VirtualFireAlarmException;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VerificationManager;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.SecurityManager;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VirtualFireAlarmServiceUtils;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Calendar;
@ -161,7 +159,7 @@ public class VirtualFireAlarmXMPPConnector extends XMPPTransportHandler {
try {
PublicKey clientPublicKey = VirtualFireAlarmServiceUtils.getDevicePublicKey(deviceId);
PrivateKey serverPrivateKey = VerificationManager.getServerPrivateKey();
PrivateKey serverPrivateKey = SecurityManager.getServerPrivateKey();
String actualMessage = VirtualFireAlarmServiceUtils.extractMessageFromPayload(message, serverPrivateKey,
clientPublicKey);
if (log.isDebugEnabled()) {
@ -223,7 +221,7 @@ public class VirtualFireAlarmXMPPConnector extends XMPPTransportHandler {
try {
PublicKey devicePublicKey = VirtualFireAlarmServiceUtils.getDevicePublicKey(deviceId);
PrivateKey serverPrivateKey = VerificationManager.getServerPrivateKey();
PrivateKey serverPrivateKey = SecurityManager.getServerPrivateKey();
String actualMessage = resource + ":" + state;
String encryptedMsg = VirtualFireAlarmServiceUtils.prepareSecurePayLoad(actualMessage,

@ -47,14 +47,14 @@ import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
public class VerificationManager {
private static final Log log = LogFactory.getLog(VerificationManager.class);
public class SecurityManager {
private static final Log log = LogFactory.getLog(SecurityManager.class);
private static PrivateKey serverPrivateKey;
private static final String SIGNATURE_ALG = "SHA1withRSA";
private static final String CIPHER_PADDING = "RSA/ECB/PKCS1Padding";
private VerificationManager() {
private SecurityManager() {
}

@ -246,8 +246,8 @@ public class VirtualFireAlarmServiceUtils {
public static String prepareSecurePayLoad(String message, Key encryptionKey, PrivateKey signatureKey)
throws VirtualFireAlarmException {
String encryptedMsg = VerificationManager.encryptMessage(message, encryptionKey);
String signedPayload = VerificationManager.signMessage(encryptedMsg, signatureKey);
String encryptedMsg = SecurityManager.encryptMessage(message, encryptionKey);
String signedPayload = SecurityManager.signMessage(encryptedMsg, signatureKey);
JSONObject jsonPayload = new JSONObject();
jsonPayload.put(JSON_MESSAGE_KEY, encryptedMsg);
@ -266,9 +266,9 @@ public class VirtualFireAlarmServiceUtils {
Object signedPayload = jsonPayload.get(JSON_SIGNATURE_KEY);
if (encryptedMessage != null && signedPayload != null) {
if (VerificationManager.verifySignature(
if (SecurityManager.verifySignature(
encryptedMessage.toString(), signedPayload.toString(), verifySignatureKey)) {
actualMessage = VerificationManager.decryptMessage(encryptedMessage.toString(), decryptionKey);
actualMessage = SecurityManager.decryptMessage(encryptedMessage.toString(), decryptionKey);
} else {
String errorMsg = "The message was not signed by a valid client. Could not verify signature on payload";
throw new VirtualFireAlarmException(errorMsg);

@ -28,7 +28,7 @@
<jaxrs:serviceBeans>
<bean id="VirtualFireAlarmService"
class="org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.VirtualFireAlarmService">
<property name="verificationManager" ref="verificationManagerBean"/>
<property name="securityManager" ref="securityManagerBean"/>
<property name="virtualFireAlarmMQTTConnector" ref="mqttConnectorBean"/>
<property name="virtualFireAlarmXMPPConnector" ref="xmppConnectorBean"/>
</bean>
@ -38,8 +38,8 @@
</jaxrs:providers>
</jaxrs:server>
<bean id="verificationManagerBean"
class="org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VerificationManager">
<bean id="securityManagerBean"
class="org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.SecurityManager">
</bean>
<bean id="mqttConnectorBean"
class="org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport.VirtualFireAlarmMQTTConnector">

Loading…
Cancel
Save