use of de.rwth.idsg.steve.utils.Helpers.getRandomString in project steve by RWTH-i5-IDSG.
the class Issue72 method attackInternal.
protected void attackInternal() throws Exception {
String idTag = __DatabasePreparer__.getRegisteredOcppTag();
String chargeBoxId = Helpers.getRandomString();
DateTime startDateTime = DateTime.now();
DateTime stopDateTime = startDateTime.plusHours(5);
int connectorId = 2;
int meterStart = 444;
int meterStop = 99999;
BootNotificationResponse boot = getForOcpp16(path).bootNotification(new BootNotificationRequest().withChargePointVendor(getRandomString()).withChargePointModel(getRandomString()), chargeBoxId);
Assertions.assertEquals(RegistrationStatus.ACCEPTED, boot.getStatus());
StartTransactionResponse start = getForOcpp16(path).startTransaction(new StartTransactionRequest().withConnectorId(connectorId).withIdTag(idTag).withTimestamp(startDateTime).withMeterStart(meterStart), chargeBoxId);
Assertions.assertNotNull(start);
int transactionId = start.getTransactionId();
StressTester.Runnable runnable = new StressTester.Runnable() {
private final ThreadLocal<CentralSystemService> threadLocalClient = new ThreadLocal<>();
@Override
public void beforeRepeat() {
threadLocalClient.set(getForOcpp16(path));
}
@Override
public void toRepeat() {
MeterValuesResponse mvr = threadLocalClient.get().meterValues(new MeterValuesRequest().withConnectorId(connectorId).withTransactionId(transactionId).withMeterValue(new MeterValue().withTimestamp(stopDateTime).withSampledValue(new SampledValue().withValue("555").withUnit(UnitOfMeasure.WH))), chargeBoxId);
Assertions.assertNotNull(mvr);
StopTransactionResponse stop = threadLocalClient.get().stopTransaction(new StopTransactionRequest().withTransactionId(transactionId).withTimestamp(stopDateTime).withIdTag(idTag).withMeterStop(meterStop), chargeBoxId);
Assertions.assertNotNull(stop);
}
@Override
public void afterRepeat() {
}
};
StressTester tester = new StressTester(THREAD_COUNT, REPEAT_COUNT_PER_THREAD);
tester.test(runnable);
tester.shutDown();
}
use of de.rwth.idsg.steve.utils.Helpers.getRandomString in project steve by RWTH-i5-IDSG.
the class Issue72LowLevelSoap method attackInternal.
protected void attackInternal() throws Exception {
String idTag = __DatabasePreparer__.getRegisteredOcppTag();
String chargeBoxId = Helpers.getRandomString();
DateTime startDateTime = DateTime.parse("2018-06-27T01:10:10Z");
DateTime stopDateTime = DateTime.parse("2018-06-27T04:10:10Z");
int connectorId = 2;
int meterStart = 444;
int meterStop = 99999;
BootNotificationResponse boot = getForOcpp16(path).bootNotification(new BootNotificationRequest().withChargePointVendor(getRandomString()).withChargePointModel(getRandomString()), chargeBoxId);
Assertions.assertEquals(RegistrationStatus.ACCEPTED, boot.getStatus());
StartTransactionResponse start = getForOcpp16(path).startTransaction(new StartTransactionRequest().withConnectorId(connectorId).withIdTag(idTag).withTimestamp(startDateTime).withMeterStart(meterStart), chargeBoxId);
Assertions.assertNotNull(start);
int transactionId = start.getTransactionId();
String body = buildRequest(chargeBoxId, transactionId, idTag, stopDateTime, meterStop);
ContentType contentType = ContentType.create(MediaType.SOAP_XML_UTF_8.type(), MediaType.SOAP_XML_UTF_8.charset().orNull());
HttpUriRequest req = RequestBuilder.post(path).addHeader("SOAPAction", "urn://Ocpp/Cs/2015/10/StopTransaction").setEntity(new StringEntity(body, contentType)).build();
CloseableHttpClient httpClient = HttpClients.createDefault();
StressTester.Runnable runnable = new StressTester.Runnable() {
private final ThreadLocal<CentralSystemService> threadLocalClient = new ThreadLocal<>();
@Override
public void beforeRepeat() {
threadLocalClient.set(getForOcpp16(path));
}
@Override
public void toRepeat() {
MeterValuesResponse mvr = threadLocalClient.get().meterValues(new MeterValuesRequest().withConnectorId(connectorId).withTransactionId(transactionId).withMeterValue(new MeterValue().withTimestamp(stopDateTime).withSampledValue(new SampledValue().withMeasurand(Measurand.ENERGY_ACTIVE_IMPORT_REGISTER).withValue("555").withUnit(UnitOfMeasure.WH))), chargeBoxId);
Assertions.assertNotNull(mvr);
try {
httpClient.execute(req, httpResponse -> {
if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
throw new RuntimeException("Not OK");
}
return null;
});
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void afterRepeat() {
}
};
try {
StressTester tester = new StressTester(100, 100);
tester.test(runnable);
tester.shutDown();
} finally {
httpClient.close();
}
}
use of de.rwth.idsg.steve.utils.Helpers.getRandomString in project EVSUPERVISION by EnergyTIC.
the class Issue72LowLevelSoap method attackInternal.
protected void attackInternal() throws Exception {
String idTag = __DatabasePreparer__.getRegisteredOcppTag();
String chargeBoxId = Helpers.getRandomString();
DateTime startDateTime = DateTime.parse("2018-06-27T01:10:10Z");
DateTime stopDateTime = DateTime.parse("2018-06-27T04:10:10Z");
int connectorId = 2;
int meterStart = 444;
int meterStop = 99999;
BootNotificationResponse boot = getForOcpp16(path).bootNotification(new BootNotificationRequest().withChargePointVendor(getRandomString()).withChargePointModel(getRandomString()), chargeBoxId);
Assertions.assertEquals(RegistrationStatus.ACCEPTED, boot.getStatus());
StartTransactionResponse start = getForOcpp16(path).startTransaction(new StartTransactionRequest().withConnectorId(connectorId).withIdTag(idTag).withTimestamp(startDateTime).withMeterStart(meterStart), chargeBoxId);
Assertions.assertNotNull(start);
int transactionId = start.getTransactionId();
String body = buildRequest(chargeBoxId, transactionId, idTag, stopDateTime, meterStop);
ContentType contentType = ContentType.create(MediaType.SOAP_XML_UTF_8.type(), MediaType.SOAP_XML_UTF_8.charset().orNull());
HttpUriRequest req = RequestBuilder.post(path).addHeader("SOAPAction", "urn://Ocpp/Cs/2015/10/StopTransaction").setEntity(new StringEntity(body, contentType)).build();
CloseableHttpClient httpClient = HttpClients.createDefault();
StressTester.Runnable runnable = new StressTester.Runnable() {
private final ThreadLocal<CentralSystemService> threadLocalClient = new ThreadLocal<>();
@Override
public void beforeRepeat() {
threadLocalClient.set(getForOcpp16(path));
}
@Override
public void toRepeat() {
MeterValuesResponse mvr = threadLocalClient.get().meterValues(new MeterValuesRequest().withConnectorId(connectorId).withTransactionId(transactionId).withMeterValue(new MeterValue().withTimestamp(stopDateTime).withSampledValue(new SampledValue().withMeasurand(Measurand.ENERGY_ACTIVE_IMPORT_REGISTER).withValue("555").withUnit(UnitOfMeasure.WH))), chargeBoxId);
Assertions.assertNotNull(mvr);
try {
httpClient.execute(req, httpResponse -> {
if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
throw new RuntimeException("Not OK");
}
return null;
});
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void afterRepeat() {
}
};
try {
StressTester tester = new StressTester(100, 100);
tester.test(runnable);
tester.shutDown();
} finally {
httpClient.close();
}
}
use of de.rwth.idsg.steve.utils.Helpers.getRandomString in project EVSUPERVISION by EnergyTIC.
the class Issue72 method attackInternal.
protected void attackInternal() throws Exception {
String idTag = __DatabasePreparer__.getRegisteredOcppTag();
String chargeBoxId = Helpers.getRandomString();
DateTime startDateTime = DateTime.now();
DateTime stopDateTime = startDateTime.plusHours(5);
int connectorId = 2;
int meterStart = 444;
int meterStop = 99999;
BootNotificationResponse boot = getForOcpp16(path).bootNotification(new BootNotificationRequest().withChargePointVendor(getRandomString()).withChargePointModel(getRandomString()), chargeBoxId);
Assertions.assertEquals(RegistrationStatus.ACCEPTED, boot.getStatus());
StartTransactionResponse start = getForOcpp16(path).startTransaction(new StartTransactionRequest().withConnectorId(connectorId).withIdTag(idTag).withTimestamp(startDateTime).withMeterStart(meterStart), chargeBoxId);
Assertions.assertNotNull(start);
int transactionId = start.getTransactionId();
StressTester.Runnable runnable = new StressTester.Runnable() {
private final ThreadLocal<CentralSystemService> threadLocalClient = new ThreadLocal<>();
@Override
public void beforeRepeat() {
threadLocalClient.set(getForOcpp16(path));
}
@Override
public void toRepeat() {
MeterValuesResponse mvr = threadLocalClient.get().meterValues(new MeterValuesRequest().withConnectorId(connectorId).withTransactionId(transactionId).withMeterValue(new MeterValue().withTimestamp(stopDateTime).withSampledValue(new SampledValue().withValue("555").withUnit(UnitOfMeasure.WH))), chargeBoxId);
Assertions.assertNotNull(mvr);
StopTransactionResponse stop = threadLocalClient.get().stopTransaction(new StopTransactionRequest().withTransactionId(transactionId).withTimestamp(stopDateTime).withIdTag(idTag).withMeterStop(meterStop), chargeBoxId);
Assertions.assertNotNull(stop);
}
@Override
public void afterRepeat() {
}
};
StressTester tester = new StressTester(THREAD_COUNT, REPEAT_COUNT_PER_THREAD);
tester.test(runnable);
tester.shutDown();
}
Aggregations