Skip to content

Commit

Permalink
Changelog commit 15.9.17
Browse files Browse the repository at this point in the history
- Added copyNewCertsAndKeys.bat and generateCertificates.bat to RISE-V2G-Certificates in order to port the already existing Unix shell scripts to Windows systems
- Corrected an error in V2GCommunicationSessionHandlerEVCC.java which ensures that the SDP procedure continues to work correctly even if there is a false SDP response coming from the SECC
- Changed the signature of the method generateDigest() (in SecurityUtils.java) to have more logging information about the ID of the element for which the digest is generated
- Made sure that the PreCharge timeout and CableCheck timeout are triggered exactly (there was a possible delay of 2s)
- Changed logging level of TCP server and client from debug to info
- Added debugging logging functionality with new EVCC and SECC property HexAndBase64RepresentationOfMessages which will log the hexadecimal and Base64 encoding of each message being sent
- Small change in log4j2.xml files enabling highlighting of logging level (you need to have ANSI Console installed in Eclipse IDE for this change to take effect)
- Shifted the process of reading the MO Sub-CA 2 private key from the keystore from the method getMOSubCA2PrivateKey to the constructor of DummyBackendInterface.java in order to avoid timeouts when processing the ChargeParameterDiscoveryReq on embedded devices
- Updated the EXIficient_V2G_CI_MsgDef.java (serialized version of the XSD grammar) as there was an bug before that caused an incomplete deserialization of an EXI byte stream to an XML message
- Updated log4j from 2.1 to 2.9
  • Loading branch information
Marc Mültin committed Sep 15, 2017
1 parent 75cb9ed commit d8c9fc7
Show file tree
Hide file tree
Showing 38 changed files with 3,206 additions and 4,972 deletions.
12 changes: 12 additions & 0 deletions RISE-V2G-Certificates/copyNewCertsAndKeys.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@echo off
REM This is a useful small shell script to automatically copy the Java Keystores (.jks files), .p12 containers and the DER encoded Mobility Operator Sub-CA private key to the places in the RISE V2G project where they belong. Execute this script after you executed the generateCertificates.sh script.

copy keystores\evccKeystore.jks ..\RISE-V2G-EVCC
copy keystores\evccTruststore.jks ..\RISE-V2G-EVCC
copy keystores\seccKeystore.jks ..\RISE-V2G-SECC
copy keystores\seccTruststore.jks ..\RISE-V2G-SECC

copy certs\cpsCertChain.p12 ..\RISE-V2G-SECC
copy certs\moCertChain.p12 ..\RISE-V2G-SECC

copy privateKeys\moSubCA2.pkcs8.der ..\RISE-V2G-SECC
223 changes: 223 additions & 0 deletions RISE-V2G-Certificates/generateCertificates.bat

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion RISE-V2G-EVCC/EVCCConfig.properties
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ RequestedEnergyTransferMode = AC_three_phase_core
XMLRepresentationOfMessages = true


# Hexadecimal and Base64 representation of messages
#--------------------------------------------------
#
# Possible values:
# - true
# - false
# If this value is set to 'true', the EXICodec will print each message's hexadecimal and Base64 representation (for debugging purposes)
# If no correct value is provided here, 'false' will be chosen
HexAndBase64RepresentationOfMessages = true


# Extended logging of signature verification
#-------------------------------------------
#
Expand All @@ -114,4 +125,4 @@ SignatureVerificationLog = true
# - exificient
# - open_exi
# If no correct value is provided here, 'exificient' will be used
EXICodec = exificient
EXICodec = open_exi
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ private boolean initialize() {
setSessionRetryCounter(getSeccDiscoveryRequestCounter() + 1);

// Create SECCDiscoveryReq and check response
while (udpResponse == null &&
getSeccDiscoveryRequestCounter() < TimeRestrictions.SDP_REQUEST_MAX_COUNTER) {
while (getSeccDiscoveryRequestCounter() < TimeRestrictions.SDP_REQUEST_MAX_COUNTER) {
udpResponse = sendSECCDiscoveryReq(getSecurity());

if (udpResponse == null) {
Expand All @@ -99,7 +98,9 @@ private boolean initialize() {

if (getMessageHandler().isV2GTPMessageValid(getV2gTpMessage())) {
seccDiscoveryRes = new SECCDiscoveryRes(getV2gTpMessage().getPayload());
break;
break; // if everything is OK and a valid SDP response is received, the while loop is stopped here
} else {
continue;
}
}
}
Expand Down Expand Up @@ -307,11 +308,11 @@ private void sendSupportedAppProtocolReq() {
if (isSecureCommunication()) {
TLSClient.getInstance().send(
getV2gTpMessage(),
TimeRestrictions.getV2G_EVCC_Msg_Timeout(V2GMessages.SUPPORTED_APP_PROTOCOL_RES));
TimeRestrictions.getV2gEvccMsgTimeout(V2GMessages.SUPPORTED_APP_PROTOCOL_RES));
} else {
TCPClient.getInstance().send(
getV2gTpMessage(),
TimeRestrictions.getV2G_EVCC_Msg_Timeout(V2GMessages.SUPPORTED_APP_PROTOCOL_RES));
TimeRestrictions.getV2gEvccMsgTimeout(V2GMessages.SUPPORTED_APP_PROTOCOL_RES));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public ReactionToIncomingMessage processIncomingMessage(Object message) {
AuthorizationResType authorizationRes =
(AuthorizationResType) v2gMessageRes.getBody().getBodyElement().getValue();

if (authorizationRes.getEVSEProcessing() == null)
return new TerminateSession("EVSEProcessing parameter of AuthorizationRes is null. Parameter is mandatory.");

if (authorizationRes.getEVSEProcessing().equals(EVSEProcessingType.FINISHED)) {
getLogger().debug("EVSEProcessing was set to FINISHED");

Expand All @@ -70,9 +73,11 @@ public ReactionToIncomingMessage processIncomingMessage(Object message) {
} else {
getLogger().debug("EVSEProcessing was set to ONGOING");

long elapsedTimeInMs = 0;

if (getCommSessionContext().isOngoingTimerActive()) {
long elapsedTime = System.nanoTime() - getCommSessionContext().getOngoingTimer();
long elapsedTimeInMs = TimeUnit.MILLISECONDS.convert(elapsedTime, TimeUnit.NANOSECONDS);
elapsedTimeInMs = TimeUnit.MILLISECONDS.convert(elapsedTime, TimeUnit.NANOSECONDS);

if (elapsedTimeInMs > TimeRestrictions.V2G_EVCC_ONGOING_TIMEOUT)
return new TerminateSession("Ongoing timer timed out for AuthorizationReq");
Expand All @@ -90,7 +95,9 @@ public ReactionToIncomingMessage processIncomingMessage(Object message) {
// Set xml reference element
getXMLSignatureRefElements().put(
authorizationReq.getId(),
SecurityUtils.generateDigest(getMessageHandler().getJaxbElement(authorizationReq)));
SecurityUtils.generateDigest(
authorizationReq.getId(),
getMessageHandler().getJaxbElement(authorizationReq)));

// Set signing private key
setSignaturePrivateKey(SecurityUtils.getPrivateKey(
Expand All @@ -103,7 +110,7 @@ public ReactionToIncomingMessage processIncomingMessage(Object message) {
authorizationReq = getAuthorizationReq(null);
}

return getSendMessage(authorizationReq, V2GMessages.AUTHORIZATION_RES);
return getSendMessage(authorizationReq, V2GMessages.AUTHORIZATION_RES, Math.min((TimeRestrictions.V2G_EVCC_ONGOING_TIMEOUT - (int) elapsedTimeInMs), TimeRestrictions.getV2gEvccMsgTimeout(V2GMessages.AUTHORIZATION_RES)));
}
} else {
return new TerminateSession("Incoming message raised an error");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ public ReactionToIncomingMessage processIncomingMessage(Object message) {
} else {
getLogger().debug("EVSEProcessing was set to ONGOING");

long elapsedTimeInMs = 0;

if (getCommSessionContext().isOngoingTimerActive()) {
long elapsedTime = System.nanoTime() - getCommSessionContext().getOngoingTimer();
long elapsedTimeInMs = TimeUnit.MILLISECONDS.convert(elapsedTime, TimeUnit.NANOSECONDS);
elapsedTimeInMs = TimeUnit.MILLISECONDS.convert(elapsedTime, TimeUnit.NANOSECONDS);

if (elapsedTimeInMs > TimeRestrictions.V2G_EVCC_CABLE_CHECK_TIMEOUT)
return new TerminateSession("CableCheck timer timed out for CableCheckReq");
Expand All @@ -77,7 +79,7 @@ public ReactionToIncomingMessage processIncomingMessage(Object message) {
getCommSessionContext().setOngoingTimerActive(true);
}

return getSendMessage(getCableCheckReq(), V2GMessages.CABLE_CHECK_RES);
return getSendMessage(getCableCheckReq(), V2GMessages.CABLE_CHECK_RES, Math.min((TimeRestrictions.V2G_EVCC_CABLE_CHECK_TIMEOUT - (int) elapsedTimeInMs), TimeRestrictions.getV2gEvccMsgTimeout(V2GMessages.CABLE_CHECK_RES)));
}
} else {
return new TerminateSession("Incoming message raised an error");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,24 @@ private boolean verifySignature(CertificateInstallationResType certificateInstal
HashMap<String, byte[]> verifyXMLSigRefElements = new HashMap<String, byte[]>();
verifyXMLSigRefElements.put(
certificateInstallationRes.getContractSignatureCertChain().getId(),
SecurityUtils.generateDigest(getMessageHandler().getJaxbElement(certificateInstallationRes.getContractSignatureCertChain())));
SecurityUtils.generateDigest(
certificateInstallationRes.getContractSignatureCertChain().getId(),
getMessageHandler().getJaxbElement(certificateInstallationRes.getContractSignatureCertChain())));
verifyXMLSigRefElements.put(
certificateInstallationRes.getContractSignatureEncryptedPrivateKey().getId(),
SecurityUtils.generateDigest(getMessageHandler().getJaxbElement(certificateInstallationRes.getContractSignatureEncryptedPrivateKey())));
SecurityUtils.generateDigest(
certificateInstallationRes.getContractSignatureEncryptedPrivateKey().getId(),
getMessageHandler().getJaxbElement(certificateInstallationRes.getContractSignatureEncryptedPrivateKey())));
verifyXMLSigRefElements.put(
certificateInstallationRes.getDHpublickey().getId(),
SecurityUtils.generateDigest(getMessageHandler().getJaxbElement(certificateInstallationRes.getDHpublickey())));
SecurityUtils.generateDigest(
certificateInstallationRes.getDHpublickey().getId(),
getMessageHandler().getJaxbElement(certificateInstallationRes.getDHpublickey())));
verifyXMLSigRefElements.put(
certificateInstallationRes.getEMAID().getId(),
SecurityUtils.generateDigest(getMessageHandler().getJaxbElement(certificateInstallationRes.getEMAID())));
SecurityUtils.generateDigest(
certificateInstallationRes.getEMAID().getId(),
getMessageHandler().getJaxbElement(certificateInstallationRes.getEMAID())));

if (!SecurityUtils.verifySignature(
signature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,24 @@ private boolean verifySignature(CertificateUpdateResType certificateUpdateRes, S
HashMap<String, byte[]> verifyXMLSigRefElements = new HashMap<String, byte[]>();
verifyXMLSigRefElements.put(
certificateUpdateRes.getContractSignatureCertChain().getId(),
SecurityUtils.generateDigest(getMessageHandler().getJaxbElement(certificateUpdateRes.getContractSignatureCertChain())));
SecurityUtils.generateDigest(
certificateUpdateRes.getContractSignatureCertChain().getId(),
getMessageHandler().getJaxbElement(certificateUpdateRes.getContractSignatureCertChain())));
verifyXMLSigRefElements.put(
certificateUpdateRes.getContractSignatureEncryptedPrivateKey().getId(),
SecurityUtils.generateDigest(getMessageHandler().getJaxbElement(certificateUpdateRes.getContractSignatureEncryptedPrivateKey())));
SecurityUtils.generateDigest(
certificateUpdateRes.getContractSignatureEncryptedPrivateKey().getId(),
getMessageHandler().getJaxbElement(certificateUpdateRes.getContractSignatureEncryptedPrivateKey())));
verifyXMLSigRefElements.put(
certificateUpdateRes.getDHpublickey().getId(),
SecurityUtils.generateDigest(getMessageHandler().getJaxbElement(certificateUpdateRes.getDHpublickey())));
SecurityUtils.generateDigest(
certificateUpdateRes.getDHpublickey().getId(),
getMessageHandler().getJaxbElement(certificateUpdateRes.getDHpublickey())));
verifyXMLSigRefElements.put(
certificateUpdateRes.getEMAID().getId(),
SecurityUtils.generateDigest(getMessageHandler().getJaxbElement(certificateUpdateRes.getEMAID())));
SecurityUtils.generateDigest(
certificateUpdateRes.getEMAID().getId(),
getMessageHandler().getJaxbElement(certificateUpdateRes.getEMAID())));

if (!SecurityUtils.verifySignature(
signature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,17 @@ public ReactionToIncomingMessage processIncomingMessage(Object message) {
ChargeParameterDiscoveryResType chargeParameterDiscoveryRes =
(ChargeParameterDiscoveryResType) v2gMessageRes.getBody().getBodyElement().getValue();

if (chargeParameterDiscoveryRes.getEVSEProcessing() == null)
return new TerminateSession("EVSEProcessing parameter of ChargeParameterDiscoveryRes is null. Parameter is mandatory.");

if (chargeParameterDiscoveryRes.getEVSEProcessing().equals(EVSEProcessingType.ONGOING)) {
getLogger().debug("EVSEProcessing was set to ONGOING");

long elapsedTimeInMs = 0;

if (getCommSessionContext().isOngoingTimerActive()) {
long elapsedTime = System.nanoTime() - getCommSessionContext().getOngoingTimer();
long elapsedTimeInMs = TimeUnit.MILLISECONDS.convert(elapsedTime, TimeUnit.NANOSECONDS);
elapsedTimeInMs = TimeUnit.MILLISECONDS.convert(elapsedTime, TimeUnit.NANOSECONDS);

if (elapsedTimeInMs > TimeRestrictions.V2G_EVCC_ONGOING_TIMEOUT)
return new TerminateSession("Ongoing timer timed out for ChargeParameterDiscoveryReq");
Expand All @@ -74,7 +79,7 @@ public ReactionToIncomingMessage processIncomingMessage(Object message) {
getCommSessionContext().setOngoingTimerActive(true);
}

return getSendMessage(getCommSessionContext().getChargeParameterDiscoveryReq(), V2GMessages.CHARGE_PARAMETER_DISCOVERY_RES);
return getSendMessage(getCommSessionContext().getChargeParameterDiscoveryReq(), V2GMessages.CHARGE_PARAMETER_DISCOVERY_RES, Math.min((TimeRestrictions.V2G_EVCC_ONGOING_TIMEOUT - (int) elapsedTimeInMs), TimeRestrictions.getV2gEvccMsgTimeout(V2GMessages.CHARGE_PARAMETER_DISCOVERY_RES)));
} else {
getLogger().debug("EVSEProcessing was set to FINISHED");

Expand Down Expand Up @@ -200,7 +205,9 @@ private boolean verifySalesTariffs(SAScheduleListType saSchedules, SignatureType

verifyXMLSigRefElements.put(
saScheduleTuple.getSalesTariff().getId(),
SecurityUtils.generateDigest(getMessageHandler().getJaxbElement(saScheduleTuple.getSalesTariff())));
SecurityUtils.generateDigest(
saScheduleTuple.getSalesTariff().getId(),
getMessageHandler().getJaxbElement(saScheduleTuple.getSalesTariff())));
}

if (salesTariffCounter > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public ReactionToIncomingMessage processIncomingMessage(Object message) {
// Set xml reference element
getXMLSignatureRefElements().put(
meteringReceiptReq.getId(),
SecurityUtils.generateDigest(getMessageHandler().getJaxbElement(meteringReceiptReq)));
SecurityUtils.generateDigest(
meteringReceiptReq.getId(),
getMessageHandler().getJaxbElement(meteringReceiptReq)));

// Set signing private key
setSignaturePrivateKey(SecurityUtils.getPrivateKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public ReactionToIncomingMessage processIncomingMessage(Object message) {
// Set xml reference element
getXMLSignatureRefElements().put(
meteringReceiptReq.getId(),
SecurityUtils.generateDigest(getMessageHandler().getJaxbElement(meteringReceiptReq)));
SecurityUtils.generateDigest(
meteringReceiptReq.getId(),
getMessageHandler().getJaxbElement(meteringReceiptReq)));

// Set signing private key
setSignaturePrivateKey(SecurityUtils.getPrivateKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public ReactionToIncomingMessage processIncomingMessage(Object message) {
// Set xml reference element
getXMLSignatureRefElements().put(
authorizationReq.getId(),
SecurityUtils.generateDigest(getMessageHandler().getJaxbElement(authorizationReq)));
SecurityUtils.generateDigest(
authorizationReq.getId(),
getMessageHandler().getJaxbElement(authorizationReq)));

// Set signing private key
setSignaturePrivateKey(SecurityUtils.getPrivateKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ private CertificateInstallationReqType getCertificateInstallationReq() {
// Set xml reference element
getXMLSignatureRefElements().put(
certInstallationReq.getId(),
SecurityUtils.generateDigest(getMessageHandler().getJaxbElement(certInstallationReq)));
SecurityUtils.generateDigest(
certInstallationReq.getId(),
getMessageHandler().getJaxbElement(certInstallationReq)));

// Set signing private key
setSignaturePrivateKey(SecurityUtils.getPrivateKey(
Expand Down Expand Up @@ -142,7 +144,9 @@ private CertificateUpdateReqType getCertificateUpdateReq() {
// Set xml reference element
getXMLSignatureRefElements().put(
certificateUpdateReq.getId(),
SecurityUtils.generateDigest(getMessageHandler().getJaxbElement(certificateUpdateReq)));
SecurityUtils.generateDigest(
certificateUpdateReq.getId(),
getMessageHandler().getJaxbElement(certificateUpdateReq)));

// Set signing private key
setSignaturePrivateKey(SecurityUtils.getPrivateKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public ReactionToIncomingMessage processIncomingMessage(Object message) {
preChargeReq.setEVTargetCurrent(dcEvController.getTargetCurrent());
preChargeReq.setEVTargetVoltage(dcEvController.getTargetVoltage());

return getSendMessage(preChargeReq, V2GMessages.PRE_CHARGE_RES);
return getSendMessage(preChargeReq, V2GMessages.PRE_CHARGE_RES, Math.min((TimeRestrictions.V2G_EVCC_PRE_CHARGE_TIMEOUT - (int) elapsedTimeInMs), TimeRestrictions.getV2gEvccMsgTimeout(V2GMessages.PRE_CHARGE_RES)));
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public ReactionToIncomingMessage processIncomingMessage(Object message) {
long elapsedTimeInMs = TimeUnit.MILLISECONDS.convert(elapsedTime, TimeUnit.NANOSECONDS);

return getSendMessage(sessionSetupReq, V2GMessages.SESSION_SETUP_RES, (int) Math.min(
TimeRestrictions.getV2G_EVCC_Msg_Timeout(V2GMessages.SESSION_SETUP_RES),
TimeRestrictions.getV2gEvccMsgTimeout(V2GMessages.SESSION_SETUP_RES),
TimeRestrictions.V2G_EVCC_COMMUNICATION_SETUP_TIMEOUT - elapsedTimeInMs
));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public boolean initialize(Inet6Address host, int port) {
setInStream(getTcpSocketToServer().getInputStream());
setOutStream(getTcpSocketToServer().getOutputStream());

getLogger().debug("TCP client connection established \n\t from link-local address " +
getLogger().info("TCP client connection established \n\t from link-local address " +
getClientAddress() + " and port " + getClientPort() +
"\n\t to host " + host.getHostAddress() + " and port " + port);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public boolean initialize(Inet6Address host, int port) {
return false;
}

getLogger().debug("TLS client connection established \n\t from link-local address " +
getLogger().info("TLS client connection established \n\t from link-local address " +
getClientAddress() + " and port " + getClientPort() +
"\n\t to host " + host.getHostAddress() + " and port " + port);

Expand Down
32 changes: 12 additions & 20 deletions RISE-V2G-EVCC/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appenders>
<console name="Console" target="SYSTEM_OUT">
<patternLayout pattern="%d{ISO8601} %-5p [%t] %c: %m%n" />
</console>
<!-- <param name="threshold" value="debug" />
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p [%t] %c: %m%n" />
</layout>-->
</appenders>

<loggers>
<root level="debug">
<appender-ref ref="Console" />
</root>
</loggers>

</log4j:configuration>
<Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{ISO8601} %highlight{%level}{FATAL=bg_red, ERROR=red, WARN=yellow, INFO=green, DEBUG=blue} [%t] %c: %m%n" />
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
<!-- see http://logging.apache.org/log4j/2.x/manual/configuration.html -->
13 changes: 12 additions & 1 deletion RISE-V2G-SECC/SECCConfig.properties
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ PrivateEnvironment = false
XMLRepresentationOfMessages = true


# Hexadecimal and Base64 representation of messages
#--------------------------------------------------
#
# Possible values:
# - true
# - false
# If this value is set to 'true', the EXICodec will print each message's hexadecimal and Base64 representation (for debugging purposes)
# If no correct value is provided here, 'false' will be chosen
HexAndBase64RepresentationOfMessages = true


# Extended logging of signature verification
#-------------------------------------------
#
Expand All @@ -107,4 +118,4 @@ SignatureVerificationLog = true
# - exificient
# - open_exi
# If no correct value is provided here, 'exificient' will be used
EXICodec = exificient
EXICodec = open_exi
Loading

0 comments on commit d8c9fc7

Please sign in to comment.