use of com.alliander.osgp.oslp.Oslp.Message in project Protocol-Adapter-OSLP by OSGP.
the class OslpEnvelopeRsaTest method buildOslpMessageIncorrectSignature.
/**
* Valid must fail when decryption fails using incorrect keys
*
* @throws IOException
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
* @throws NoSuchProviderException
*/
@Test(expected = IllegalArgumentException.class)
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();
new OslpEnvelope.Builder().withSignature("Incorrect").withProvider(PROVIDER).withPrimaryKey(CertificateHelper.createPrivateKeyFromBase64(PRIVATE_KEY_BASE_64, KEY_TYPE, PROVIDER)).withDeviceId(deviceId).withSequenceNumber(sequenceNumber).withPayloadMessage(message).build();
}
use of com.alliander.osgp.oslp.Oslp.Message in project Protocol-Adapter-OSLP by OSGP.
the class OslpEnvelopeRsaTest method buildOslpMessageIncorrectProvider.
/**
* Valid must fail when decryption fails using incorrect keys
*
* @throws IOException
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
* @throws NoSuchProviderException
*/
@Test(expected = IllegalArgumentException.class)
public void buildOslpMessageIncorrectProvider() 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();
new OslpEnvelope.Builder().withSignature(SIGNATURE).withProvider("Incorrect").withPrimaryKey(CertificateHelper.createPrivateKeyFromBase64(PRIVATE_KEY_BASE_64, KEY_TYPE, PROVIDER)).withDeviceId(deviceId).withSequenceNumber(sequenceNumber).withPayloadMessage(message).build();
}
use of com.alliander.osgp.oslp.Oslp.Message in project Protocol-Adapter-OSLP by OSGP.
the class OslpChannelHandlerServer method messageReceived.
@Override
public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent e) throws Exception {
final OslpEnvelope message = (OslpEnvelope) e.getMessage();
this.logMessage(message, true);
final Integer channelId = e.getChannel().getId();
if (message.isValid()) {
if (this.isOslpResponse(message)) {
LOGGER.warn("{} Received OSLP Response, which is not expected: {}", channelId, message.getPayloadMessage());
} else {
LOGGER.info("{} Received OSLP Request: {}", channelId, message.getPayloadMessage());
// Response pay-load to send to device.
Message payload = null;
// Check which request the device has sent and handle it.
if (message.getPayloadMessage().hasRegisterDeviceRequest()) {
payload = this.handleRegisterDeviceRequest(message.getDeviceId(), message.getSequenceNumber(), message.getPayloadMessage().getRegisterDeviceRequest());
} else if (message.getPayloadMessage().hasConfirmRegisterDeviceRequest()) {
payload = this.handleConfirmRegisterDeviceRequest(message.getDeviceId(), message.getSequenceNumber(), message.getPayloadMessage().getConfirmRegisterDeviceRequest());
} else if (message.getPayloadMessage().hasEventNotificationRequest()) {
payload = this.handleEventNotificationRequest(message.getDeviceId(), message.getSequenceNumber(), message.getPayloadMessage().getEventNotificationRequest());
} else {
LOGGER.warn("{} Received unknown payload. Received: {}.", channelId, message.getPayloadMessage().toString());
// Optional extra: return error code to device.
return;
}
// Cache the channel so we can write the response to it later.
this.cacheChannel(channelId, e.getChannel());
// Send message to signing server to get our response signed.
this.oslpSigningService.buildAndSignEnvelope(message.getDeviceId(), message.getSequenceNumber(), payload, channelId, this);
}
} else {
LOGGER.warn("{} Received message wasn't properly secured.", channelId);
}
}
use of com.alliander.osgp.oslp.Oslp.Message in project Protocol-Adapter-OSLP by OSGP.
the class OslpEnvelopeEcDsaTest method buildOslpMessageIncorrectProvider.
/**
* Valid must fail when decryption fails using incorrect keys
*
* @throws IOException
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
* @throws NoSuchProviderException
*/
@Test(expected = IllegalArgumentException.class)
public void buildOslpMessageIncorrectProvider() 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();
new OslpEnvelope.Builder().withSignature(SIGNATURE).withProvider("Incorrect").withPrimaryKey(CertificateHelper.createPrivateKeyFromBase64(PRIVATE_KEY_BASE_64, KEY_TYPE, this.provider())).withDeviceId(deviceId).withSequenceNumber(sequenceNumber).withPayloadMessage(message).build();
}
use of com.alliander.osgp.oslp.Oslp.Message in project Protocol-Adapter-OSLP 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(expected = IllegalArgumentException.class)
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();
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();
}
Aggregations