RISE-V2G/RISE-V2G-SECC/src/main/java/com/v2gclarity/risev2g/secc/states/WaitForSupportedAppProtocol...

144 lines
6.5 KiB
Java
Raw Normal View History

2015-06-01 08:19:09 -07:00
/*******************************************************************************
* The MIT License (MIT)
2015-06-01 08:19:09 -07:00
*
* Copyright (c) 2015-207 V2G Clarity (Dr.-Ing. Marc Mültin)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
2015-06-01 08:19:09 -07:00
*******************************************************************************/
package com.v2gclarity.risev2g.secc.states;
2015-06-01 08:19:09 -07:00
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.v2gclarity.risev2g.secc.session.V2GCommunicationSessionSECC;
import com.v2gclarity.risev2g.shared.enumerations.GlobalValues;
import com.v2gclarity.risev2g.shared.enumerations.V2GMessages;
import com.v2gclarity.risev2g.shared.messageHandling.ChangeProcessingState;
import com.v2gclarity.risev2g.shared.messageHandling.ReactionToIncomingMessage;
import com.v2gclarity.risev2g.shared.v2gMessages.SECCDiscoveryReq;
import com.v2gclarity.risev2g.shared.v2gMessages.appProtocol.AppProtocolType;
import com.v2gclarity.risev2g.shared.v2gMessages.appProtocol.ResponseCodeType;
import com.v2gclarity.risev2g.shared.v2gMessages.appProtocol.SupportedAppProtocolReq;
import com.v2gclarity.risev2g.shared.v2gMessages.appProtocol.SupportedAppProtocolRes;
import com.v2gclarity.risev2g.shared.v2gMessages.msgDef.BodyBaseType;
2015-06-01 08:19:09 -07:00
public class WaitForSupportedAppProtocolReq extends ServerState {
private SupportedAppProtocolRes supportedAppProtocolRes;
public WaitForSupportedAppProtocolReq(V2GCommunicationSessionSECC commSessionContext) {
super(commSessionContext);
}
@Override
public ReactionToIncomingMessage processIncomingMessage(Object message) {
supportedAppProtocolRes = new SupportedAppProtocolRes();
if (message instanceof SupportedAppProtocolReq) {
getLogger().debug("SupportedAppProtocolReq received");
boolean match = false;
ResponseCodeType responseCode = ResponseCodeType.FAILED_NO_NEGOTIATION;
SupportedAppProtocolReq supportedAppProtocolReq = (SupportedAppProtocolReq) message;
// The provided appProtocols might not be sorted by priority
Collections.sort(supportedAppProtocolReq.getAppProtocol(), (appProtocol1, appProtocol2) ->
Short.compare(appProtocol1.getPriority(), appProtocol2.getPriority()));
/*
* If protocol and major version matches with more than one supported protocol,
* choose the one with highest priority
*/
for (AppProtocolType evccAppProtocol : supportedAppProtocolReq.getAppProtocol()) {
/*
* A getSupportedAppProtocols().contains(evccAppProtocol) does not work here since
* priority and schemaID are not provided in getSupportedAppProtocols()
*/
for (AppProtocolType seccAppProtocol : getSupportedAppProtocols()) {
if (evccAppProtocol.getProtocolNamespace().equals(seccAppProtocol.getProtocolNamespace()) &&
evccAppProtocol.getVersionNumberMajor() == seccAppProtocol.getVersionNumberMajor()) {
if (evccAppProtocol.getVersionNumberMinor() == seccAppProtocol.getVersionNumberMinor()) {
responseCode = ResponseCodeType.OK_SUCCESSFUL_NEGOTIATION;
} else {
responseCode = ResponseCodeType.OK_SUCCESSFUL_NEGOTIATION_WITH_MINOR_DEVIATION;
}
match = true;
supportedAppProtocolRes.setSchemaID(evccAppProtocol.getSchemaID());
break;
}
}
if (match) break;
}
supportedAppProtocolRes.setResponseCode(responseCode);
} else if (message instanceof SECCDiscoveryReq) {
getLogger().debug("Another SECCDiscoveryReq was received, changing to state WaitForSECCDiscoveryReq");
return new ChangeProcessingState(message, getCommSessionContext().getStates().get(V2GMessages.SECC_DISCOVERY_REQ));
} else if (message != null) {
/*
* This check has been introduced to make sure the application can deal with incoming messages which rely
* on the DINSPEC 70121 XSD schema (which is different from the ISO 15118-2 schema. Without this check,
* the message.getClass() would throw a NullPointerException and the application would die.
*/
2015-06-01 08:19:09 -07:00
getLogger().error("Invalid message (" + message.getClass().getSimpleName() +
") at this state (" + this.getClass().getSimpleName() + ")");
supportedAppProtocolRes.setResponseCode(ResponseCodeType.FAILED_NO_NEGOTIATION);
} else {
getLogger().error("Invalid message at this state, message seems to be null. Check if same XSD schema is used on EVCC side.");
supportedAppProtocolRes.setResponseCode(ResponseCodeType.FAILED_NO_NEGOTIATION);
2015-06-01 08:19:09 -07:00
}
return getSendMessage(supportedAppProtocolRes,
(supportedAppProtocolRes.getResponseCode().toString().startsWith("OK") ?
- Replaced System.currentTimeMillis() by System.nanoTime() for timing tasks. - Changed the way how JAXBElements are created due to particularities with the creation of the XML Reference elements for the CertificateInstallationRes and CertificateUpdateRes messages. The JAXBContext is now set exactly for the message or field that is to be marshaled into XML. As a result, the JAXBContext is no more set in the EXI codec, but in the MessageHandler - SecurityUtils.java has been partly rewritten with regards to the verification of certificate chains. See also verifyCertificateChain(…) method. - Requirement [V2G2-812] is not implemented. - When the EVCC sends a message out of the correct order which would induce a FAILED_SequenceError message, the SECC now sends the response message corresponding to the request message sent by the EVCC instead of the response message corresponding to the message the SECC would expect. As a result, ServerState.java has partly been rewritten and all SECC states have been adapted to it. - Charge parameter provided by ChargeParameterDisoveryReq message are now thoroughly checked by the SECC. See also verifyChargeParameter(…) method. - Charging profile provided by PowerDeliveryReq message is now thoroughly checked by SECC. See also isChargingProfileValid(…) method. - New enum class PKI is added to shared.enumerations package. Needed for certificate chain checks in SecurityUtils.java. - Some bugfixes in V2GTPMessage so that headers are not checked correctly.
2017-08-20 14:26:22 -07:00
V2GMessages.SESSION_SETUP_REQ : V2GMessages.NONE),
supportedAppProtocolRes.getResponseCode()
2015-06-01 08:19:09 -07:00
);
}
/**
* All supported versions of the ISO/IEC 15118-2 protocol are listed here.
* Currently, only IS version of April 2014 is supported (see [V2G2-098]), more could be provided here.
* The values for priority and schema ID do not need to be set since these values are provided by
* the EVCC.
*
* @return A list of supported of AppProtocol entries
*/
private List<AppProtocolType> getSupportedAppProtocols() {
List<AppProtocolType> supportedAppProtocols = new ArrayList<AppProtocolType>();
AppProtocolType appProtocol1 = new AppProtocolType();
appProtocol1.setProtocolNamespace(GlobalValues.V2G_CI_MSG_DEF_NAMESPACE.toString());
appProtocol1.setVersionNumberMajor(2);
appProtocol1.setVersionNumberMinor(0);
supportedAppProtocols.add(appProtocol1);
return supportedAppProtocols;
}
- Replaced System.currentTimeMillis() by System.nanoTime() for timing tasks. - Changed the way how JAXBElements are created due to particularities with the creation of the XML Reference elements for the CertificateInstallationRes and CertificateUpdateRes messages. The JAXBContext is now set exactly for the message or field that is to be marshaled into XML. As a result, the JAXBContext is no more set in the EXI codec, but in the MessageHandler - SecurityUtils.java has been partly rewritten with regards to the verification of certificate chains. See also verifyCertificateChain(…) method. - Requirement [V2G2-812] is not implemented. - When the EVCC sends a message out of the correct order which would induce a FAILED_SequenceError message, the SECC now sends the response message corresponding to the request message sent by the EVCC instead of the response message corresponding to the message the SECC would expect. As a result, ServerState.java has partly been rewritten and all SECC states have been adapted to it. - Charge parameter provided by ChargeParameterDisoveryReq message are now thoroughly checked by the SECC. See also verifyChargeParameter(…) method. - Charging profile provided by PowerDeliveryReq message is now thoroughly checked by SECC. See also isChargingProfileValid(…) method. - New enum class PKI is added to shared.enumerations package. Needed for certificate chain checks in SecurityUtils.java. - Some bugfixes in V2GTPMessage so that headers are not checked correctly.
2017-08-20 14:26:22 -07:00
Commit-Nachricht für RISE V2G - Signature creation and verification has been fixed and works now properly. Has been tested against various industry OEMs and suppliers.
SecurityUtils.java class was substantially revised as part of fixing the signature creation and verification process and extended signature logging - Introduced a new abstract method setMandatoryFieldsForFailedRes() in ServerState which makes sure that for each response the mandatory fields are set properly according to the standard in case a FAILED response code is sent - Introduced a fix in WaitForAuthorizationReq which makes sure that a possible challenge is only checked for if the chosen payment option is „Contract“ (and TLS is used) - Saves now the payment option selected by the EVCC (in state WaitForPaymentServiceSelectionReq) in the SECCs communication session for later reference - To avoid possible race conditions, the transport layer threads needed to be started AFTER the SECC session handler has been initialized. Otherwise the situation might occur that the UDPServer is receiving a UDP client packet and tries to access the MessageHandler object before this object has been created by the SECC session handler. - generateCertificates.sh Shell-Script now includes variables to ease the setting of certificates’ validity periods. Renaming of some certificates (e.g. provLeaf.cert -> cpsLeaf.cert) and keys. All certificates are now also generated in DER encoded form. MOSubCA2 private key is now also created as a PKCS#8 DER encoded file as RISE V2G needs this format to read the private key from file and sign SalesTariffs. - EVCCConfig.properties and SECCConfig.properties have additional property „SignatureVerificationLog“ which enables extended logging information to debug signature creation and verification processes - Catched a (theoretically) possible ClassCastException in WaitForChargeParameterDiscoveryRes in case the EVCC signalizes an EnergyTransferMode (AC or DC) which does not fit to the EVSEChargeParameter sent by the SECC later on - Made sure that by default the sum of the individual time intervals described in the PMaxSchedule and SalesTariff provided in the ChargeParameterDiscoveryRes message are equal to 24 hours as demanded by a requirement. - Renaming of some methods in IBackendInterface for clarity and consistency - Provided a correctly formatted EVSE-ID in DummyACEVSEController and DummyDCEVSEController - Corrected the service name of CertificateUpdate service and CertificateInstallation service to „Service“ according to the standard - Edited GlobalValues so that the string value returned for each global value only needs to be edited once in this file (less error prone)
2017-07-20 06:50:43 -07:00
@Override
- Replaced System.currentTimeMillis() by System.nanoTime() for timing tasks. - Changed the way how JAXBElements are created due to particularities with the creation of the XML Reference elements for the CertificateInstallationRes and CertificateUpdateRes messages. The JAXBContext is now set exactly for the message or field that is to be marshaled into XML. As a result, the JAXBContext is no more set in the EXI codec, but in the MessageHandler - SecurityUtils.java has been partly rewritten with regards to the verification of certificate chains. See also verifyCertificateChain(…) method. - Requirement [V2G2-812] is not implemented. - When the EVCC sends a message out of the correct order which would induce a FAILED_SequenceError message, the SECC now sends the response message corresponding to the request message sent by the EVCC instead of the response message corresponding to the message the SECC would expect. As a result, ServerState.java has partly been rewritten and all SECC states have been adapted to it. - Charge parameter provided by ChargeParameterDisoveryReq message are now thoroughly checked by the SECC. See also verifyChargeParameter(…) method. - Charging profile provided by PowerDeliveryReq message is now thoroughly checked by SECC. See also isChargingProfileValid(…) method. - New enum class PKI is added to shared.enumerations package. Needed for certificate chain checks in SecurityUtils.java. - Some bugfixes in V2GTPMessage so that headers are not checked correctly.
2017-08-20 14:26:22 -07:00
public BodyBaseType getResponseMessage() {
return null;
Commit-Nachricht für RISE V2G - Signature creation and verification has been fixed and works now properly. Has been tested against various industry OEMs and suppliers.
SecurityUtils.java class was substantially revised as part of fixing the signature creation and verification process and extended signature logging - Introduced a new abstract method setMandatoryFieldsForFailedRes() in ServerState which makes sure that for each response the mandatory fields are set properly according to the standard in case a FAILED response code is sent - Introduced a fix in WaitForAuthorizationReq which makes sure that a possible challenge is only checked for if the chosen payment option is „Contract“ (and TLS is used) - Saves now the payment option selected by the EVCC (in state WaitForPaymentServiceSelectionReq) in the SECCs communication session for later reference - To avoid possible race conditions, the transport layer threads needed to be started AFTER the SECC session handler has been initialized. Otherwise the situation might occur that the UDPServer is receiving a UDP client packet and tries to access the MessageHandler object before this object has been created by the SECC session handler. - generateCertificates.sh Shell-Script now includes variables to ease the setting of certificates’ validity periods. Renaming of some certificates (e.g. provLeaf.cert -> cpsLeaf.cert) and keys. All certificates are now also generated in DER encoded form. MOSubCA2 private key is now also created as a PKCS#8 DER encoded file as RISE V2G needs this format to read the private key from file and sign SalesTariffs. - EVCCConfig.properties and SECCConfig.properties have additional property „SignatureVerificationLog“ which enables extended logging information to debug signature creation and verification processes - Catched a (theoretically) possible ClassCastException in WaitForChargeParameterDiscoveryRes in case the EVCC signalizes an EnergyTransferMode (AC or DC) which does not fit to the EVSEChargeParameter sent by the SECC later on - Made sure that by default the sum of the individual time intervals described in the PMaxSchedule and SalesTariff provided in the ChargeParameterDiscoveryRes message are equal to 24 hours as demanded by a requirement. - Renaming of some methods in IBackendInterface for clarity and consistency - Provided a correctly formatted EVSE-ID in DummyACEVSEController and DummyDCEVSEController - Corrected the service name of CertificateUpdate service and CertificateInstallation service to „Service“ according to the standard - Edited GlobalValues so that the string value returned for each global value only needs to be edited once in this file (less error prone)
2017-07-20 06:50:43 -07:00
}
2015-06-01 08:19:09 -07:00
}