Merge branch 'hotfix/porsche-test'
This commit is contained in:
commit
c8c9fb21d6
|
@ -51,7 +51,7 @@ public class V2GCommunicationSessionHandlerEVCC implements Observer {
|
||||||
private Thread transportLayerThread;
|
private Thread transportLayerThread;
|
||||||
private StatefulTransportLayerClient transportLayerClient;
|
private StatefulTransportLayerClient transportLayerClient;
|
||||||
|
|
||||||
public V2GCommunicationSessionHandlerEVCC() {
|
public V2GCommunicationSessionHandlerEVCC() {
|
||||||
setMessageHandler(new MessageHandler());
|
setMessageHandler(new MessageHandler());
|
||||||
|
|
||||||
setSecurity(
|
setSecurity(
|
||||||
|
|
|
@ -20,6 +20,7 @@ import javax.net.ssl.SSLHandshakeException;
|
||||||
import javax.net.ssl.SSLSocket;
|
import javax.net.ssl.SSLSocket;
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
import org.eclipse.risev2g.shared.enumerations.GlobalValues;
|
import org.eclipse.risev2g.shared.enumerations.GlobalValues;
|
||||||
|
import org.eclipse.risev2g.shared.misc.TimeRestrictions;
|
||||||
import org.eclipse.risev2g.shared.misc.V2GTPMessage;
|
import org.eclipse.risev2g.shared.misc.V2GTPMessage;
|
||||||
import org.eclipse.risev2g.shared.utils.SecurityUtils;
|
import org.eclipse.risev2g.shared.utils.SecurityUtils;
|
||||||
|
|
||||||
|
@ -78,7 +79,9 @@ public class TLSClient extends StatefulTransportLayerClient {
|
||||||
GlobalValues.PASSPHRASE_FOR_CERTIFICATES_AND_KEYS.toString());
|
GlobalValues.PASSPHRASE_FOR_CERTIFICATES_AND_KEYS.toString());
|
||||||
|
|
||||||
SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
|
SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
|
||||||
|
getLogger().debug("Creating socket to TLS server ...");
|
||||||
setTlsSocketToServer((SSLSocket) sslSocketFactory.createSocket(host, port));
|
setTlsSocketToServer((SSLSocket) sslSocketFactory.createSocket(host, port));
|
||||||
|
getLogger().debug("TLS socket to server created");
|
||||||
setInStream(getTlsSocketToServer().getInputStream());
|
setInStream(getTlsSocketToServer().getInputStream());
|
||||||
setOutStream(getTlsSocketToServer().getOutputStream());
|
setOutStream(getTlsSocketToServer().getOutputStream());
|
||||||
|
|
||||||
|
@ -95,7 +98,17 @@ public class TLSClient extends StatefulTransportLayerClient {
|
||||||
String[] enabledProtocols = {"TLSv1.2"};
|
String[] enabledProtocols = {"TLSv1.2"};
|
||||||
getTlsSocketToServer().setEnabledProtocols(enabledProtocols);
|
getTlsSocketToServer().setEnabledProtocols(enabledProtocols);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The communication session setup timeout needs to be set here in case there is any problem with the
|
||||||
|
* TLS handshake.
|
||||||
|
* The timeout value will be overwritten with every new message being sent
|
||||||
|
*/
|
||||||
|
getTlsSocketToServer().setSoTimeout(TimeRestrictions.V2G_EVCC_COMMUNICATION_SETUP_TIMEOUT);
|
||||||
|
|
||||||
|
getLogger().debug("Starting TLS handshake ...");
|
||||||
getTlsSocketToServer().startHandshake();
|
getTlsSocketToServer().startHandshake();
|
||||||
|
getLogger().debug("TLS handshake finished");
|
||||||
|
|
||||||
Certificate[] seccCertificates = getTlsSocketToServer().getSession().getPeerCertificates();
|
Certificate[] seccCertificates = getTlsSocketToServer().getSession().getPeerCertificates();
|
||||||
X509Certificate seccLeafCertificate = (X509Certificate) seccCertificates[0];
|
X509Certificate seccLeafCertificate = (X509Certificate) seccCertificates[0];
|
||||||
|
|
||||||
|
@ -116,11 +129,13 @@ public class TLSClient extends StatefulTransportLayerClient {
|
||||||
getLogger().error("TLS client connection failed (UnknownHostException)!", e);
|
getLogger().error("TLS client connection failed (UnknownHostException)!", e);
|
||||||
} catch (SSLHandshakeException e) {
|
} catch (SSLHandshakeException e) {
|
||||||
getLogger().error("TLS client connection failed (SSLHandshakeException)", e);
|
getLogger().error("TLS client connection failed (SSLHandshakeException)", e);
|
||||||
|
} catch (SocketTimeoutException e) {
|
||||||
|
getLogger().fatal("TLS client connection failed (SocketTimeoutException) due to session setup timeout", e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
getLogger().error("TLS client connection failed (IOException)!", e);
|
getLogger().error("TLS client connection failed (IOException)!", e);
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
getLogger().fatal("NullPointerException while trying to set keystores, resource path to keystore/truststore might be incorrect");
|
getLogger().fatal("NullPointerException while trying to set keystores, resource path to keystore/truststore might be incorrect");
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,42 +123,46 @@ public class V2GCommunicationSessionHandlerSECC implements Observer {
|
||||||
private void processSECCDiscoveryReq(DatagramPacket udpClientPacket) {
|
private void processSECCDiscoveryReq(DatagramPacket udpClientPacket) {
|
||||||
setV2gTpMessage(new V2GTPMessage(udpClientPacket.getData()));
|
setV2gTpMessage(new V2GTPMessage(udpClientPacket.getData()));
|
||||||
|
|
||||||
if (getMessageHandler().isV2GTPMessageValid(getV2gTpMessage()) &&
|
try {
|
||||||
Arrays.equals(getV2gTpMessage().getPayloadType(), GlobalValues.V2GTP_PAYLOAD_TYPE_SDP_REQUEST_MESSAGE.getByteArrayValue())) {
|
if (getMessageHandler().isV2GTPMessageValid(getV2gTpMessage()) &&
|
||||||
|
Arrays.equals(getV2gTpMessage().getPayloadType(), GlobalValues.V2GTP_PAYLOAD_TYPE_SDP_REQUEST_MESSAGE.getByteArrayValue())) {
|
||||||
SECCDiscoveryReq seccDiscoveryReq = new SECCDiscoveryReq(getV2gTpMessage().getPayload());
|
|
||||||
setSecurity(seccDiscoveryReq.getSecurity());
|
SECCDiscoveryReq seccDiscoveryReq = new SECCDiscoveryReq(getV2gTpMessage().getPayload());
|
||||||
getLogger().debug("SECCDiscoveryReq received");
|
setSecurity(seccDiscoveryReq.getSecurity());
|
||||||
|
getLogger().debug("SECCDiscoveryReq received");
|
||||||
/*
|
|
||||||
* The TCP and TLS server ports are created upon initialization of the TCP/TLS server and will
|
/*
|
||||||
* remain the same for every connected EV. Only TCP or TLS are allowed as transport
|
* The TCP and TLS server ports are created upon initialization of the TCP/TLS server and will
|
||||||
* protocols for further communication beyond the SECCDiscoveryReq/-Res handshake (not UDP).
|
* remain the same for every connected EV. Only TCP or TLS are allowed as transport
|
||||||
*
|
* protocols for further communication beyond the SECCDiscoveryReq/-Res handshake (not UDP).
|
||||||
* One might implement further decision rules for dealing with the security level (TCP or TLS)
|
*
|
||||||
* requested by the EVCC (see also Table 3 and 4 of ISO/IEC 15118-2). For now, the requested
|
* One might implement further decision rules for dealing with the security level (TCP or TLS)
|
||||||
* security level of the EVCC will always be accepted.
|
* requested by the EVCC (see also Table 3 and 4 of ISO/IEC 15118-2). For now, the requested
|
||||||
*/
|
* security level of the EVCC will always be accepted.
|
||||||
byte[] seccAddress = (isSecureCommunication()) ? TLSServer.getInstance().getServerAddress().getAddress() : TCPServer.getInstance().getServerAddress().getAddress();
|
*/
|
||||||
int seccPort = (isSecureCommunication()) ? TLSServer.getInstance().getServerPort() : TCPServer.getInstance().getServerPort();
|
byte[] seccAddress = (isSecureCommunication()) ? TLSServer.getInstance().getServerAddress().getAddress() : TCPServer.getInstance().getServerAddress().getAddress();
|
||||||
|
int seccPort = (isSecureCommunication()) ? TLSServer.getInstance().getServerPort() : TCPServer.getInstance().getServerPort();
|
||||||
SECCDiscoveryRes seccDiscoveryRes = new SECCDiscoveryRes(
|
|
||||||
seccAddress,
|
SECCDiscoveryRes seccDiscoveryRes = new SECCDiscoveryRes(
|
||||||
ByteUtils.toByteArrayFromInt(seccPort, true),
|
seccAddress,
|
||||||
getSecurity(),
|
ByteUtils.toByteArrayFromInt(seccPort, true),
|
||||||
GlobalValues.V2G_TRANSPORT_PROTOCOL_TCP.getByteValue()
|
getSecurity(),
|
||||||
);
|
GlobalValues.V2G_TRANSPORT_PROTOCOL_TCP.getByteValue()
|
||||||
|
);
|
||||||
setV2gTpMessage(new V2GTPMessage(GlobalValues.V2GTP_VERSION_1_IS.getByteValue(),
|
|
||||||
GlobalValues.V2GTP_PAYLOAD_TYPE_SDP_RESPONSE_MESSAGE.getByteArrayValue(),
|
setV2gTpMessage(new V2GTPMessage(GlobalValues.V2GTP_VERSION_1_IS.getByteValue(),
|
||||||
seccDiscoveryRes.getPayload()));
|
GlobalValues.V2GTP_PAYLOAD_TYPE_SDP_RESPONSE_MESSAGE.getByteArrayValue(),
|
||||||
|
seccDiscoveryRes.getPayload()));
|
||||||
getLogger().debug("Preparing to send SECCDiscoveryRes ...");
|
|
||||||
|
getLogger().debug("Preparing to send SECCDiscoveryRes ...");
|
||||||
// The SECCDiscoveryRes must be sent via UDP before the requested TCP/TLS server can be used
|
|
||||||
UDPServer.getInstance().send(getV2gTpMessage(), (Inet6Address) udpClientPacket.getAddress(), udpClientPacket.getPort());
|
// The SECCDiscoveryRes must be sent via UDP before the requested TCP/TLS server can be used
|
||||||
} else {
|
UDPServer.getInstance().send(getV2gTpMessage(), (Inet6Address) udpClientPacket.getAddress(), udpClientPacket.getPort());
|
||||||
getLogger().warn("Incoming DatagramPacket could not be identified as a SECCDiscoveryReq");
|
} else {
|
||||||
|
getLogger().warn("Incoming DatagramPacket could not be identified as a SECCDiscoveryReq");
|
||||||
|
}
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
getLogger().error("NullPointerException occurred while processing SECCDiscoveryReq", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ public final class TCPServer extends StatefulTransportLayerServer {
|
||||||
|
|
||||||
public boolean initialize() {
|
public boolean initialize() {
|
||||||
super.initialize();
|
super.initialize();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setTcpServerSocket(new ServerSocket(getServerPort(), 50, getServerAddress()));
|
setTcpServerSocket(new ServerSocket(getServerPort(), 50, getServerAddress()));
|
||||||
getLogger().debug("TCP server initialized at link-local address " +
|
getLogger().debug("TCP server initialized at link-local address " +
|
||||||
|
|
|
@ -50,7 +50,7 @@ public final class TLSServer extends StatefulTransportLayerServer {
|
||||||
GlobalValues.SECC_KEYSTORE_FILEPATH.toString(),
|
GlobalValues.SECC_KEYSTORE_FILEPATH.toString(),
|
||||||
GlobalValues.SECC_TRUSTSTORE_FILEPATH.toString(),
|
GlobalValues.SECC_TRUSTSTORE_FILEPATH.toString(),
|
||||||
GlobalValues.PASSPHRASE_FOR_CERTIFICATES_AND_KEYS.toString());
|
GlobalValues.PASSPHRASE_FOR_CERTIFICATES_AND_KEYS.toString());
|
||||||
|
|
||||||
SSLServerSocketFactory tlsServerSocketFactory =
|
SSLServerSocketFactory tlsServerSocketFactory =
|
||||||
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
|
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
|
||||||
setTlsServerSocket((SSLServerSocket) tlsServerSocketFactory
|
setTlsServerSocket((SSLServerSocket) tlsServerSocketFactory
|
||||||
|
@ -94,7 +94,7 @@ public final class TLSServer extends StatefulTransportLayerServer {
|
||||||
getLogger().debug("TLS client connection with IP address " +
|
getLogger().debug("TLS client connection with IP address " +
|
||||||
getTlsClientSocket().getInetAddress().getHostAddress() + " and port " +
|
getTlsClientSocket().getInetAddress().getHostAddress() + " and port " +
|
||||||
getTlsClientSocket().getPort());
|
getTlsClientSocket().getPort());
|
||||||
|
|
||||||
ConnectionHandler connectionHandler = new ConnectionHandler(tlsClientSocket);
|
ConnectionHandler connectionHandler = new ConnectionHandler(tlsClientSocket);
|
||||||
|
|
||||||
// Notify the V2GCommunicationSessionHandlerSECC about a newly connected TCP client Socket
|
// Notify the V2GCommunicationSessionHandlerSECC about a newly connected TCP client Socket
|
||||||
|
|
|
@ -27,7 +27,7 @@ public enum GlobalValues {
|
||||||
*/
|
*/
|
||||||
PASSPHRASE_FOR_CERTIFICATES_AND_KEYS("123456"),
|
PASSPHRASE_FOR_CERTIFICATES_AND_KEYS("123456"),
|
||||||
|
|
||||||
// Aliases for contract certificate chain and OEM provisioning certficiate chain
|
// Aliases for contract certificate chain and OEM provisioning certificate chain
|
||||||
ALIAS_CONTRACT_CERTIFICATE("contract_cert"),
|
ALIAS_CONTRACT_CERTIFICATE("contract_cert"),
|
||||||
ALIAS_OEM_PROV_CERTIFICATE("oem_prov_cert"),
|
ALIAS_OEM_PROV_CERTIFICATE("oem_prov_cert"),
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue