use of org.opensmartgridplatform.oslp.Oslp.Message in project open-smart-grid-platform by OSGP.
the class OslpUtils method isOslpResponse.
public static boolean isOslpResponse(final OslpEnvelope envelope) {
final Message message = envelope.getPayloadMessage();
final boolean[] hasResponse = { message.hasRegisterDeviceResponse(), message.hasConfirmRegisterDeviceResponse(), message.hasStartSelfTestResponse(), message.hasStopSelfTestResponse(), message.hasUpdateFirmwareResponse(), message.hasSetLightResponse(), message.hasSetEventNotificationsResponse(), message.hasEventNotificationResponse(), message.hasSetScheduleResponse(), message.hasGetFirmwareVersionResponse(), message.hasGetStatusResponse(), message.hasResumeScheduleResponse(), message.hasSetRebootResponse(), message.hasSetTransitionResponse(), message.hasSetConfigurationResponse(), message.hasGetConfigurationResponse(), message.hasSwitchConfigurationResponse(), message.hasGetActualPowerUsageResponse(), message.hasGetPowerUsageHistoryResponse(), message.hasSwitchFirmwareResponse(), message.hasUpdateDeviceSslCertificationResponse(), message.hasSetDeviceVerificationKeyResponse() };
return BooleanUtils.or(hasResponse);
}
use of org.opensmartgridplatform.oslp.Oslp.Message in project open-smart-grid-platform by OSGP.
the class OslpEnvelopeEcDsaTest method buildOslpMessageIncorrectSignature.
/**
* Valid must fail when decryption fails using incorrect keys
*
* @throws IOException
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
* @throws NoSuchProviderException
*/
@Test()
public void buildOslpMessageIncorrectSignature() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException {
final byte[] deviceId = new byte[] { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
final byte[] sequenceNumber = new byte[] { 0, 1 };
final Message message = this.buildRegisterResponse();
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
new OslpEnvelope.Builder().withSignature("Incorrect").withProvider(this.provider()).withPrimaryKey(CertificateHelper.createPrivateKeyFromBase64(PRIVATE_KEY_BASE_64, KEY_TYPE, this.provider())).withDeviceId(deviceId).withSequenceNumber(sequenceNumber).withPayloadMessage(message).build();
});
}
use of org.opensmartgridplatform.oslp.Oslp.Message in project open-smart-grid-platform by OSGP.
the class OslpChannelHandler method handleRequest.
private Oslp.Message handleRequest(final OslpEnvelope message, final int sequenceNumber) throws DeviceSimulatorException {
final Oslp.Message request = message.getPayloadMessage();
// Create response message
final Oslp.Message response;
final String deviceIdString = Base64.encodeBase64String(message.getDeviceId());
LOGGER.info("request received, sequenceNumber: {}", sequenceNumber);
LOGGER.info("manufacturerId byte[0]: {} byte[1]: {}", message.getDeviceId()[0], message.getDeviceId()[1]);
LOGGER.info("deviceId as BASE 64 STRING: {}", deviceIdString);
// lookup correct device.
final Device device = this.deviceManagementService.findDevice(deviceIdString);
if (device == null) {
throw new DeviceSimulatorException("device with id: " + deviceIdString + " is unknown");
}
// Calculate expected sequence number
final int expectedSequenceNumber = device.doGetNextSequence();
// Check sequence number
if (Math.abs(expectedSequenceNumber - sequenceNumber) > this.sequenceNumberWindow) {
this.outOfSequenceList.add(new OutOfSequenceEvent(device.getId(), message.getPayloadMessage().toString(), DateTime.now()));
throw new DeviceSimulatorException("SequenceNumber incorrect for device: " + device.getDeviceIdentification() + " Expected: " + (expectedSequenceNumber == 0 ? this.sequenceNumberMaximum : expectedSequenceNumber - 1) + " Actual: " + (sequenceNumber == 0 ? this.sequenceNumberMaximum : sequenceNumber - 1) + " SequenceNumberWindow: " + this.sequenceNumberWindow + " Request: " + message.getPayloadMessage().toString());
}
// sleep for a little while
if (this.responseDelayTime != null) {
if (this.reponseDelayRandomRange == null) {
this.sleep(this.responseDelayTime);
} else {
final Long randomDelay = (long) (this.reponseDelayRandomRange * this.random.nextDouble());
this.sleep(this.responseDelayTime + randomDelay);
}
}
response = this.checkForRequest(request, device);
// Update device
device.setSequenceNumber(expectedSequenceNumber);
this.deviceManagementService.updateDevice(device);
// Write log entry for response
LOGGER.debug("Responding: {}", response);
return response;
}
Aggregations