mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
removed scep impl from virtual fire alarm
This commit is contained in:
parent
2025179df0
commit
37969ba0a0
@ -208,7 +208,10 @@ public class FireAlarmMQTTCommunicator extends MQTTTransportHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
int currentTemperature = agentManager.getTemperature();
|
int currentTemperature = agentManager.getTemperature();
|
||||||
String message = "PUBLISHER:" + AgentConstants.TEMPERATURE_CONTROL + ":" + currentTemperature;
|
String message = "{\"event\": {\"metaData\": {\"owner\": \"" + AgentManager
|
||||||
|
.getInstance().getAgentConfigs().getDeviceOwner() + "\",\"deviceId\": \"" + AgentManager
|
||||||
|
.getInstance().getAgentConfigs().getDeviceId() + "\",\"time\": " +
|
||||||
|
"0},\"payloadData\": { \"temperature\": " + currentTemperature + "} }}";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String payLoad = AgentUtilOperations.prepareSecurePayLoad(message);
|
String payLoad = AgentUtilOperations.prepareSecurePayLoad(message);
|
||||||
|
|||||||
@ -189,8 +189,10 @@ public class FireAlarmXMPPCommunicator extends XMPPTransportHandler {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
int currentTemperature = agentManager.getTemperature();
|
int currentTemperature = agentManager.getTemperature();
|
||||||
|
String message = "{\"event\": {\"metaData\": {\"owner\": \"" + AgentManager
|
||||||
String message = AgentConstants.TEMPERATURE_CONTROL + ":" + currentTemperature;
|
.getInstance().getAgentConfigs().getDeviceOwner() + "\",\"deviceId\": \"" + AgentManager
|
||||||
|
.getInstance().getAgentConfigs().getDeviceId() + "\",\"time\": " +
|
||||||
|
"0},\"payloadData\": { \"temperature\": " + currentTemperature + "} }}";
|
||||||
String payLoad = AgentUtilOperations.prepareSecurePayLoad(message);
|
String payLoad = AgentUtilOperations.prepareSecurePayLoad(message);
|
||||||
|
|
||||||
xmppMessage.setTo(xmppAdminJID);
|
xmppMessage.setTo(xmppAdminJID);
|
||||||
|
|||||||
@ -62,7 +62,7 @@ public class AgentConstants {
|
|||||||
public static final int DEFAULT_MQTT_RECONNECTION_INTERVAL = 2; // time in seconds
|
public static final int DEFAULT_MQTT_RECONNECTION_INTERVAL = 2; // time in seconds
|
||||||
public static final int DEFAULT_MQTT_QUALITY_OF_SERVICE = 0;
|
public static final int DEFAULT_MQTT_QUALITY_OF_SERVICE = 0;
|
||||||
public static final String MQTT_SUBSCRIBE_TOPIC = "%s/" + DEVICE_TYPE + "/%s";
|
public static final String MQTT_SUBSCRIBE_TOPIC = "%s/" + DEVICE_TYPE + "/%s";
|
||||||
public static final String MQTT_PUBLISH_TOPIC = "%s/" + DEVICE_TYPE + "/%s/publisher";
|
public static final String MQTT_PUBLISH_TOPIC = "%s/" + DEVICE_TYPE + "/%s/temperature";
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------
|
/* ---------------------------------------------------------------------------------------
|
||||||
Device/Agent specific properties to be read from the 'deviceConfig.properties' file
|
Device/Agent specific properties to be read from the 'deviceConfig.properties' file
|
||||||
|
|||||||
@ -153,15 +153,15 @@ public class AgentManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
if (!EnrollmentManager.getInstance().isEnrolled()) {
|
// if (!EnrollmentManager.getInstance().isEnrolled()) {
|
||||||
EnrollmentManager.getInstance().beginEnrollmentFlow();
|
// EnrollmentManager.getInstance().beginEnrollmentFlow();
|
||||||
}
|
// }
|
||||||
} catch (AgentCoreOperationException e) {
|
// } catch (AgentCoreOperationException e) {
|
||||||
log.error("Device Enrollment Failed:\n");
|
// log.error("Device Enrollment Failed:\n");
|
||||||
log.error(e);
|
// log.error(e);
|
||||||
System.exit(0);
|
// System.exit(0);
|
||||||
}
|
// }
|
||||||
|
|
||||||
//Start agent communication
|
//Start agent communication
|
||||||
agentCommunicator.get(protocol).connect();
|
agentCommunicator.get(protocol).connect();
|
||||||
|
|||||||
@ -250,57 +250,65 @@ public class AgentUtilOperations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String prepareSecurePayLoad(String message) throws AgentCoreOperationException {
|
public static String prepareSecurePayLoad(String message) throws AgentCoreOperationException {
|
||||||
PrivateKey devicePrivateKey = EnrollmentManager.getInstance().getPrivateKey();
|
if (EnrollmentManager.getInstance().isEnrolled()) {
|
||||||
String encodedMessage = Base64.encodeBase64String(message.getBytes());
|
PrivateKey devicePrivateKey = EnrollmentManager.getInstance().getPrivateKey();
|
||||||
String signedPayload;
|
String encodedMessage = Base64.encodeBase64String(message.getBytes());
|
||||||
try {
|
String signedPayload;
|
||||||
signedPayload = CommunicationUtils.signMessage(encodedMessage, devicePrivateKey);
|
|
||||||
} catch (TransportHandlerException e) {
|
|
||||||
String errorMsg = "Error occurred whilst trying to sign encrypted message of: [" + message + "]";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new AgentCoreOperationException(errorMsg, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject jsonPayload = new JSONObject();
|
|
||||||
jsonPayload.put(JSON_MESSAGE_KEY, encodedMessage);
|
|
||||||
jsonPayload.put(JSON_SIGNATURE_KEY, signedPayload);
|
|
||||||
//below statements are temporary fix.
|
|
||||||
jsonPayload.put(JSON_SERIAL_KEY, EnrollmentManager.getInstance().getSCEPCertificate().getSerialNumber());
|
|
||||||
return jsonPayload.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String extractMessageFromPayload(String message) throws AgentCoreOperationException {
|
|
||||||
String actualMessage;
|
|
||||||
|
|
||||||
PublicKey serverPublicKey = EnrollmentManager.getInstance().getServerPublicKey();
|
|
||||||
JSONObject jsonPayload = new JSONObject(message);
|
|
||||||
Object encodedMessage = jsonPayload.get(JSON_MESSAGE_KEY);
|
|
||||||
Object signedPayload = jsonPayload.get(JSON_SIGNATURE_KEY);
|
|
||||||
boolean verification;
|
|
||||||
|
|
||||||
if (encodedMessage != null && signedPayload != null) {
|
|
||||||
try {
|
try {
|
||||||
verification = CommunicationUtils.verifySignature(
|
signedPayload = CommunicationUtils.signMessage(encodedMessage, devicePrivateKey);
|
||||||
encodedMessage.toString(), signedPayload.toString(), serverPublicKey);
|
|
||||||
} catch (TransportHandlerException e) {
|
} catch (TransportHandlerException e) {
|
||||||
String errorMsg =
|
String errorMsg = "Error occurred whilst trying to sign encrypted message of: [" + message + "]";
|
||||||
"Error occurred whilst trying to verify signature on received message: [" + message + "]";
|
|
||||||
log.error(errorMsg);
|
log.error(errorMsg);
|
||||||
throw new AgentCoreOperationException(errorMsg, e);
|
throw new AgentCoreOperationException(errorMsg, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSONObject jsonPayload = new JSONObject();
|
||||||
|
jsonPayload.put(JSON_MESSAGE_KEY, encodedMessage);
|
||||||
|
jsonPayload.put(JSON_SIGNATURE_KEY, signedPayload);
|
||||||
|
//below statements are temporary fix.
|
||||||
|
jsonPayload.put(JSON_SERIAL_KEY, EnrollmentManager.getInstance().getSCEPCertificate().getSerialNumber());
|
||||||
|
return jsonPayload.toString();
|
||||||
} else {
|
} else {
|
||||||
String errorMsg = "The received message is in an INVALID format. " +
|
return message;
|
||||||
"Need to be JSON - {\"Msg\":\"<ENCRYPTED_MSG>\", \"Sig\":\"<SIGNED_MSG>\"}.";
|
|
||||||
throw new AgentCoreOperationException(errorMsg);
|
|
||||||
}
|
}
|
||||||
if (verification) {
|
}
|
||||||
actualMessage = new String(Base64.decodeBase64(encodedMessage.toString()), StandardCharsets.UTF_8);
|
|
||||||
|
public static String extractMessageFromPayload(String message) throws AgentCoreOperationException {
|
||||||
|
if (EnrollmentManager.getInstance().isEnrolled()) {
|
||||||
|
String actualMessage;
|
||||||
|
|
||||||
|
PublicKey serverPublicKey = EnrollmentManager.getInstance().getServerPublicKey();
|
||||||
|
JSONObject jsonPayload = new JSONObject(message);
|
||||||
|
Object encodedMessage = jsonPayload.get(JSON_MESSAGE_KEY);
|
||||||
|
Object signedPayload = jsonPayload.get(JSON_SIGNATURE_KEY);
|
||||||
|
boolean verification;
|
||||||
|
|
||||||
|
if (encodedMessage != null && signedPayload != null) {
|
||||||
|
try {
|
||||||
|
verification = CommunicationUtils.verifySignature(
|
||||||
|
encodedMessage.toString(), signedPayload.toString(), serverPublicKey);
|
||||||
|
} catch (TransportHandlerException e) {
|
||||||
|
String errorMsg =
|
||||||
|
"Error occurred whilst trying to verify signature on received message: [" + message + "]";
|
||||||
|
log.error(errorMsg);
|
||||||
|
throw new AgentCoreOperationException(errorMsg, e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String errorMsg = "The received message is in an INVALID format. " +
|
||||||
|
"Need to be JSON - {\"Msg\":\"<ENCRYPTED_MSG>\", \"Sig\":\"<SIGNED_MSG>\"}.";
|
||||||
|
throw new AgentCoreOperationException(errorMsg);
|
||||||
|
}
|
||||||
|
if (verification) {
|
||||||
|
actualMessage = new String(Base64.decodeBase64(encodedMessage.toString()), StandardCharsets.UTF_8);
|
||||||
|
} else {
|
||||||
|
String errorMsg = "Could not verify payload signature. The message was not signed by a valid client";
|
||||||
|
log.error(errorMsg);
|
||||||
|
throw new AgentCoreOperationException(errorMsg);
|
||||||
|
}
|
||||||
|
return actualMessage;
|
||||||
} else {
|
} else {
|
||||||
String errorMsg = "Could not verify payload signature. The message was not signed by a valid client";
|
return message;
|
||||||
log.error(errorMsg);
|
|
||||||
throw new AgentCoreOperationException(errorMsg);
|
|
||||||
}
|
}
|
||||||
return actualMessage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getAuthenticationMethod() {
|
public static String getAuthenticationMethod() {
|
||||||
|
|||||||
@ -111,7 +111,7 @@ public class EnrollmentManager {
|
|||||||
*/
|
*/
|
||||||
private EnrollmentManager() {
|
private EnrollmentManager() {
|
||||||
this.SCEPUrl = AgentManager.getInstance().getEnrollmentEP();
|
this.SCEPUrl = AgentManager.getInstance().getEnrollmentEP();
|
||||||
setEnrollmentStatus();
|
//setEnrollmentStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user