From 6355a2077b2e8d78500d3ba1c52352ec66459142 Mon Sep 17 00:00:00 2001 From: Mathias Oben Date: Thu, 9 Jun 2022 16:41:28 +0200 Subject: [PATCH 1/9] Initial implementation of models for 'Improved security for OCPP 1.6-J' --- .../CertificateSignedConfirmation.java | 95 +++++++++ .../securityext/CertificateSignedRequest.java | 101 +++++++++ .../DeleteCertificateConfirmation.java | 95 +++++++++ .../securityext/DeleteCertificateRequest.java | 95 +++++++++ .../ExtendedTriggerMessageConfirmation.java | 95 +++++++++ .../ExtendedTriggerMessageRequest.java | 117 +++++++++++ ...etInstalledCertificateIdsConfirmation.java | 118 +++++++++++ .../GetInstalledCertificateIdsRequest.java | 95 +++++++++ .../model/securityext/GetLogConfirmation.java | 124 +++++++++++ .../ocpp/model/securityext/GetLogRequest.java | 194 ++++++++++++++++++ .../InstallCertificateConfirmation.java | 95 +++++++++ .../InstallCertificateRequest.java | 122 +++++++++++ .../LogStatusNotificationConfirmation.java | 61 ++++++ .../LogStatusNotificationRequest.java | 118 +++++++++++ ...SecurityEventNotificationConfirmation.java | 61 ++++++ .../SecurityEventNotificationRequest.java | 139 +++++++++++++ .../SignCertificateConfirmation.java | 95 +++++++++ .../securityext/SignCertificateRequest.java | 101 +++++++++ ...irmwareStatusNotificationConfirmation.java | 61 ++++++ ...gnedFirmwareStatusNotificationRequest.java | 123 +++++++++++ .../SignedUpdateFirmwareConfirmation.java | 95 +++++++++ .../SignedUpdateFirmwareRequest.java | 168 +++++++++++++++ .../types/CertificateHashDataType.java | 161 +++++++++++++++ .../CertificateSignedStatusEnumType.java | 44 ++++ .../types/CertificateStatusEnumType.java | 49 +++++ .../types/CertificateUseEnumType.java | 45 ++++ .../DeleteCertificateStatusEnumType.java | 49 +++++ .../types/FirmwareStatusEnumType.java | 114 ++++++++++ .../model/securityext/types/FirmwareType.java | 194 ++++++++++++++++++ .../types/GenericStatusEnumType.java | 42 ++++ ...GetInstalledCertificateStatusEnumType.java | 44 ++++ .../types/HashAlgorithmEnumType.java | 47 +++++ .../model/securityext/types/LogEnumType.java | 44 ++++ .../securityext/types/LogParametersType.java | 136 ++++++++++++ .../securityext/types/LogStatusEnumType.java | 50 +++++ .../types/MessageTriggerEnumType.java | 76 +++++++ .../types/TriggerMessageStatusEnumType.java | 49 +++++ .../types/UpdateFirmwareStatusEnumType.java | 60 ++++++ .../types/UploadLogStatusEnumType.java | 71 +++++++ .../IdentifierStringValidationRule.java | 47 +++++ .../validation/OCPPSecurityExtDatatypes.java | 56 +++++ .../StringMaxLengthValidationRule.java | 45 ++++ 42 files changed, 3791 insertions(+) create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedConfirmation.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedRequest.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateConfirmation.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateRequest.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageConfirmation.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageRequest.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsConfirmation.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsRequest.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogConfirmation.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogRequest.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateConfirmation.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateRequest.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/LogStatusNotificationConfirmation.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/LogStatusNotificationRequest.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationConfirmation.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationRequest.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateConfirmation.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateRequest.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedFirmwareStatusNotificationConfirmation.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedFirmwareStatusNotificationRequest.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareConfirmation.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareRequest.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateHashDataType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateSignedStatusEnumType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateStatusEnumType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateUseEnumType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/DeleteCertificateStatusEnumType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/FirmwareStatusEnumType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/FirmwareType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/GenericStatusEnumType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/GetInstalledCertificateStatusEnumType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/HashAlgorithmEnumType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogEnumType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogParametersType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogStatusEnumType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/MessageTriggerEnumType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/TriggerMessageStatusEnumType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/UpdateFirmwareStatusEnumType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/UploadLogStatusEnumType.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/validation/IdentifierStringValidationRule.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/validation/OCPPSecurityExtDatatypes.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/validation/StringMaxLengthValidationRule.java diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedConfirmation.java new file mode 100644 index 000000000..3bfacff8c --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedConfirmation.java @@ -0,0 +1,95 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.types.CertificateSignedStatusEnumType; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class CertificateSignedConfirmation implements Request { + + private CertificateSignedStatusEnumType status; + + /** + * Handle required fields. + * + * @param status CertificateSignedStatusEnumType. See {@link #setStatus(CertificateSignedStatusEnumType)} + */ + public CertificateSignedConfirmation(CertificateSignedStatusEnumType status) { + setStatus(status); + } + + /** + * Returns whether certificate signing has been accepted, otherwise rejected. + * + * @return {@link CertificateSignedStatusEnumType} + */ + public CertificateSignedStatusEnumType getStatus() { + return status; + } + + /** + * Required. Returns whether certificate signing has been accepted, otherwise rejected. + * + * @param status {@link CertificateSignedStatusEnumType} + */ + public void setStatus(CertificateSignedStatusEnumType status) { + this.status = status; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return status != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CertificateSignedConfirmation that = (CertificateSignedConfirmation) o; + return Objects.equals(status, that.status); + } + + @Override + public int hashCode() { + return Objects.hash(status); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedRequest.java new file mode 100644 index 000000000..73dd45bec --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedRequest.java @@ -0,0 +1,101 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.utilities.ModelUtil; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class CertificateSignedRequest implements Request { + + private static final int STRING_10000_CHAR_MAX_LENGTH = 10000; + + private String certificateChain; + + /** + * Handle required fields. + * + * @param certificateChain String. See {@link #setCertificateChain(String)} + */ + public CertificateSignedRequest(String certificateChain) { + setCertificateChain(certificateChain); + } + + /** + * The signed PEM encoded X.509 certificates. This can also contain the + * necessary sub CA certificates. The maximum size of this field is limited by the + * configuration key: CertificateSignedMaxSize. + * + * @return string[0..10000] + */ + public String getCertificateChain() { + return certificateChain; + } + + /** + * Required. The signed PEM encoded X.509 certificates. This can also contain the + * necessary sub CA certificates. The maximum size of this field is limited by the + * configuration key: CertificateSignedMaxSize. + * + * @param certificateChain string[0..10000] + */ + public void setCertificateChain(String certificateChain) { + this.certificateChain = certificateChain; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return ModelUtil.validate(certificateChain, STRING_10000_CHAR_MAX_LENGTH); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CertificateSignedRequest that = (CertificateSignedRequest) o; + return Objects.equals(certificateChain, that.certificateChain); + } + + @Override + public int hashCode() { + return Objects.hash(certificateChain); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("certificateChain", certificateChain) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateConfirmation.java new file mode 100644 index 000000000..4e0614169 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateConfirmation.java @@ -0,0 +1,95 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.types.DeleteCertificateStatusEnumType; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class DeleteCertificateConfirmation implements Request { + + private DeleteCertificateStatusEnumType status; + + /** + * Handle required fields. + * + * @param status DeleteCertificateStatusEnumType. See {@link #setStatus(DeleteCertificateStatusEnumType)} + */ + public DeleteCertificateConfirmation(DeleteCertificateStatusEnumType status) { + setStatus(status); + } + + /** + * Charge Point indicates if it can process the request. + * + * @return {@link DeleteCertificateStatusEnumType} + */ + public DeleteCertificateStatusEnumType getStatus() { + return status; + } + + /** + * Required. Charge Point indicates if it can process the request. + * + * @param status {@link DeleteCertificateStatusEnumType} + */ + public void setStatus(DeleteCertificateStatusEnumType status) { + this.status = status; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return status != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DeleteCertificateConfirmation that = (DeleteCertificateConfirmation) o; + return Objects.equals(status, that.status); + } + + @Override + public int hashCode() { + return Objects.hash(status); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateRequest.java new file mode 100644 index 000000000..46aae1f98 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateRequest.java @@ -0,0 +1,95 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.types.CertificateHashDataType; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class DeleteCertificateRequest implements Request { + + private CertificateHashDataType certificateHashData; + + /** + * Handle required fields. + * + * @param certificateHashData String. See {@link #setCertificateHashData(CertificateHashDataType)} + */ + public DeleteCertificateRequest(CertificateHashDataType certificateHashData) { + setCertificateHashData(certificateHashData); + } + + /** + * Indicates the certificate of which deletion is requested. + * + * @return {@link CertificateHashDataType} + */ + public CertificateHashDataType getCertificateHashData() { + return certificateHashData; + } + + /** + * Required. Indicates the certificate of which deletion is requested. + * + * @param certificateHashData {@link CertificateHashDataType} + */ + public void setCertificateHashData(CertificateHashDataType certificateHashData) { + this.certificateHashData = certificateHashData; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return certificateHashData != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DeleteCertificateRequest that = (DeleteCertificateRequest) o; + return Objects.equals(certificateHashData, that.certificateHashData); + } + + @Override + public int hashCode() { + return Objects.hash(certificateHashData); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("certificateHashData", certificateHashData) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageConfirmation.java new file mode 100644 index 000000000..3c192ce4c --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageConfirmation.java @@ -0,0 +1,95 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.types.TriggerMessageStatusEnumType; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class ExtendedTriggerMessageConfirmation implements Request { + + private TriggerMessageStatusEnumType status; + + /** + * Handle required fields. + * + * @param status TriggerMessageStatusEnumType. See {@link #setStatus(TriggerMessageStatusEnumType)} + */ + public ExtendedTriggerMessageConfirmation(TriggerMessageStatusEnumType status) { + setStatus(status); + } + + /** + * Indicates whether the Charge Point will send the requested notification or not. + * + * @return {@link TriggerMessageStatusEnumType} + */ + public TriggerMessageStatusEnumType getStatus() { + return status; + } + + /** + * Required. Indicates whether the Charge Point will send the requested notification or not. + * + * @param status {@link TriggerMessageStatusEnumType} + */ + public void setStatus(TriggerMessageStatusEnumType status) { + this.status = status; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return status != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ExtendedTriggerMessageConfirmation that = (ExtendedTriggerMessageConfirmation) o; + return Objects.equals(status, that.status); + } + + @Override + public int hashCode() { + return Objects.hash(status); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageRequest.java new file mode 100644 index 000000000..89ea9fc8a --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageRequest.java @@ -0,0 +1,117 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.types.MessageTriggerEnumType; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class ExtendedTriggerMessageRequest implements Request { + + private MessageTriggerEnumType requestedMessage; + private Integer connectorId; + + /** + * Handle required fields. + * + * @param requestedMessage MessageTriggerEnumType. See {@link #setRequestedMessage(MessageTriggerEnumType)} + */ + public ExtendedTriggerMessageRequest(MessageTriggerEnumType requestedMessage) { + setRequestedMessage(requestedMessage); + } + + /** + * Type of the message to be triggered. + * + * @return {@link MessageTriggerEnumType} + */ + public MessageTriggerEnumType getRequestedMessage() { + return requestedMessage; + } + + /** + * Required. Type of the message to be triggered. + * + * @param requestedMessage {@link MessageTriggerEnumType} + */ + public void setRequestedMessage(MessageTriggerEnumType requestedMessage) { + this.requestedMessage = requestedMessage; + } + + /** + * Only filled in when request applies to a specific connector. + * + * @return Integer connectorId > 0 + */ + public Integer getConnectorId() { + return connectorId; + } + + /** + * Optional. Only filled in when request applies to a specific connector. + * + * @param connectorId Integer connectorId > 0 + */ + public void setConnectorId(Integer connectorId) { + this.connectorId = connectorId; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return requestedMessage != null + && (connectorId == null || connectorId > 0); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ExtendedTriggerMessageRequest that = (ExtendedTriggerMessageRequest) o; + return Objects.equals(requestedMessage, that.requestedMessage) + && Objects.equals(connectorId, that.connectorId); + } + + @Override + public int hashCode() { + return Objects.hash(requestedMessage, connectorId); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("requestedMessage", requestedMessage) + .add("connectorId", connectorId) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsConfirmation.java new file mode 100644 index 000000000..97d3b1ca4 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsConfirmation.java @@ -0,0 +1,118 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.types.CertificateHashDataType; +import eu.chargetime.ocpp.model.securityext.types.GetInstalledCertificateStatusEnumType; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Arrays; +import java.util.Objects; + +public class GetInstalledCertificateIdsConfirmation implements Request { + + private GetInstalledCertificateStatusEnumType status; + private CertificateHashDataType[] certificateHashData; + + /** + * Handle required fields. + * + * @param status GetInstalledCertificateStatusEnumType. See {@link #setStatus(GetInstalledCertificateStatusEnumType)} + */ + public GetInstalledCertificateIdsConfirmation(GetInstalledCertificateStatusEnumType status) { + setStatus(status); + } + + /** + * Charge Point indicates if it can process the request. + * + * @return {@link GetInstalledCertificateStatusEnumType} + */ + public GetInstalledCertificateStatusEnumType getStatus() { + return status; + } + + /** + * Required. Charge Point indicates if it can process the request. + * + * @param status {@link GetInstalledCertificateStatusEnumType} + */ + public void setStatus(GetInstalledCertificateStatusEnumType status) { + this.status = status; + } + + /** + * The Charge Point includes the Certificate information for each available certificate. + * + * @return array of {@link CertificateHashDataType} + */ + public CertificateHashDataType[] getCertificateHashData() { + return certificateHashData; + } + + /** + * Optional. The Charge Point includes the Certificate information for each available certificate. + * + * @param certificateHashData array of {@link CertificateHashDataType} + */ + public void setCertificateHashData(CertificateHashDataType[] certificateHashData) { + this.certificateHashData = certificateHashData; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return status != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + GetInstalledCertificateIdsConfirmation that = (GetInstalledCertificateIdsConfirmation) o; + return Objects.equals(status, that.status) + && Arrays.equals(certificateHashData, that.certificateHashData); + } + + @Override + public int hashCode() { + return Objects.hash(status, Arrays.hashCode(certificateHashData)); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("certificateHashData", certificateHashData) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsRequest.java new file mode 100644 index 000000000..c6dd2e2ae --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsRequest.java @@ -0,0 +1,95 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.types.CertificateUseEnumType; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class GetInstalledCertificateIdsRequest implements Request { + + private CertificateUseEnumType certificateType; + + /** + * Handle required fields. + * + * @param certificateType CertificateUseEnumType. See {@link #setCertificateType(CertificateUseEnumType)} + */ + public GetInstalledCertificateIdsRequest(CertificateUseEnumType certificateType) { + setCertificateType(certificateType); + } + + /** + * Indicates the type of certificates requested. + * + * @return {@link CertificateUseEnumType} + */ + public CertificateUseEnumType getCertificateType() { + return certificateType; + } + + /** + * Required. Indicates the type of certificates requested. + * + * @param certificateType {@link CertificateUseEnumType} + */ + public void setCertificateType(CertificateUseEnumType certificateType) { + this.certificateType = certificateType; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return certificateType != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + GetInstalledCertificateIdsRequest that = (GetInstalledCertificateIdsRequest) o; + return Objects.equals(certificateType, that.certificateType); + } + + @Override + public int hashCode() { + return Objects.hash(certificateType); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("certificateType", certificateType) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogConfirmation.java new file mode 100644 index 000000000..a62e7a8cc --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogConfirmation.java @@ -0,0 +1,124 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.types.LogStatusEnumType; +import eu.chargetime.ocpp.utilities.ModelUtil; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class GetLogConfirmation implements Request { + + private static final int STRING_255_CHAR_MAX_LENGTH = 255; + + private LogStatusEnumType status; + private String filename; + + /** + * Handle required fields. + * + * @param status LogStatusEnumType. See {@link #setStatus(LogStatusEnumType)} + */ + public GetLogConfirmation(LogStatusEnumType status) { + setStatus(status); + } + + /** + * This field indicates whether the Charge Point was able to accept the + * request. + * + * @return {@link LogStatusEnumType} + */ + public LogStatusEnumType getStatus() { + return status; + } + + /** + * Required. This field indicates whether the Charge Point was able to accept the + * request. + * + * @param status {@link LogStatusEnumType} + */ + public void setStatus(LogStatusEnumType status) { + this.status = status; + } + + /** + * This contains the name of the log file that will be uploaded. This field is + * not present when no logging information is available. + * + * @return string[0..255] + */ + public String getFilename() { + return filename; + } + + /** + * Optional. This contains the name of the log file that will be uploaded. This field is + * not present when no logging information is available. + * + * @param filename string[0..255] + */ + public void setFilename(String filename) { + this.filename = filename; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return status != null + && (filename == null || ModelUtil.validate(filename, STRING_255_CHAR_MAX_LENGTH)); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + GetLogConfirmation that = (GetLogConfirmation) o; + return Objects.equals(status, that.status) + && Objects.equals(filename, that.filename); + } + + @Override + public int hashCode() { + return Objects.hash(status, filename); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("filename", filename) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogRequest.java new file mode 100644 index 000000000..145665719 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogRequest.java @@ -0,0 +1,194 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.types.LogEnumType; +import eu.chargetime.ocpp.model.securityext.types.LogParametersType; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class GetLogRequest implements Request { + + private LogEnumType logType; + private Integer requestId; + private Integer retries; + private Integer retryInterval; + private LogParametersType log; + + /** + * Handle required fields. + * + * @param logType LogEnumType. See {@link #setLogType(LogEnumType)} + * @param requestId Integer. See {@link #setRequestId(Integer)} + * @param log LogParametersType. See {@link #setLogParametersType(LogParametersType)} + */ + public GetLogRequest(LogEnumType logType, Integer requestId, LogParametersType log) { + setLogType(logType); + setRequestId(requestId); + setLogParametersType(log); + } + + /** + * This contains the type of log file that the Charge Point should send. + * + * @return {@link LogEnumType} + */ + public LogEnumType getLogType() { + return logType; + } + + /** + * Required. This contains the type of log file that the Charge Point should send. + * + * @param logType {@link LogEnumType} + */ + public void setLogType(LogEnumType logType) { + this.logType = logType; + } + + /** + * The Id of this request. + * + * @return Integer + */ + public Integer getRequestId() { + return requestId; + } + + /** + * Required. The Id of this request. + * + * @param requestId Integer + */ + public void setRequestId(Integer requestId) { + this.requestId = requestId; + } + + /** + * This specifies how many times the Charge Point must try to upload the log + * before giving up. If this field is not present, it is left to Charge Point + * to decide how many times it wants to retry. + * + * @return Integer + */ + public Integer getRetries() { + return retries; + } + + /** + * Optional. This specifies how many times the Charge Point must try to upload the log + * before giving up. If this field is not present, it is left to Charge Point + * to decide how many times it wants to retry. + * + * @param retries Integer + */ + public void setRetries(Integer retries) { + this.retries = retries; + } + + /** + * The interval in seconds after which a retry may be attempted. If this + * field is not present, it is left to Charge Point to decide how long to wait between + * attempts + * + * @return Integer + */ + public Integer getRetryInterval() { + return retryInterval; + } + + /** + * Optional. The interval in seconds after which a retry may be attempted. If this + * field is not present, it is left to Charge Point to decide how long to wait between + * attempts + * + * @param retryInterval Integer + */ + public void setRetryInterval(Integer retryInterval) { + this.retryInterval = retryInterval; + } + + /** + * This field specifies the requested log and the location to which the log + * should be sent. + * + * @return {@link LogParametersType} + */ + public LogParametersType getLogParametersType() { + return log; + } + + /** + * Required. This field specifies the requested log and the location to which the log + * should be sent. + * + * @param log {@link LogParametersType} + */ + public void setLogParametersType(LogParametersType log) { + this.log = log; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return logType != null && log != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + GetLogRequest that = (GetLogRequest) o; + return Objects.equals(logType, that.logType) + && Objects.equals(requestId, that.requestId) + && Objects.equals(retries, that.retries) + && Objects.equals(retryInterval, that.retryInterval) + && Objects.equals(log, that.log); + } + + @Override + public int hashCode() { + return Objects.hash(logType, requestId, retries, retryInterval, log); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("logType", logType) + .add("requestId", requestId) + .add("retries", retries) + .add("retryInterval", retryInterval) + .add("log", log) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateConfirmation.java new file mode 100644 index 000000000..3c7e06a15 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateConfirmation.java @@ -0,0 +1,95 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.types.CertificateStatusEnumType; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class InstallCertificateConfirmation implements Request { + + private CertificateStatusEnumType status; + + /** + * Handle required fields. + * + * @param status CertificateStatusEnumType. See {@link #setStatus(CertificateStatusEnumType)} + */ + public InstallCertificateConfirmation(CertificateStatusEnumType status) { + setStatus(status); + } + + /** + * Charge Point indicates if installation was successful. + * + * @return {@link CertificateStatusEnumType} + */ + public CertificateStatusEnumType getStatus() { + return status; + } + + /** + * Required. Charge Point indicates if installation was successful. + * + * @param status {@link CertificateStatusEnumType} + */ + public void setStatus(CertificateStatusEnumType status) { + this.status = status; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return status != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + InstallCertificateConfirmation that = (InstallCertificateConfirmation) o; + return Objects.equals(status, that.status); + } + + @Override + public int hashCode() { + return Objects.hash(status); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateRequest.java new file mode 100644 index 000000000..d3536f968 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateRequest.java @@ -0,0 +1,122 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.types.CertificateUseEnumType; +import eu.chargetime.ocpp.utilities.ModelUtil; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class InstallCertificateRequest implements Request { + + private static final int STRING_5500_CHAR_MAX_LENGTH = 5500; + + private CertificateUseEnumType certificateType; + private String certificate; + + /** + * Handle required fields. + * + * @param certificateType CertificateUseEnumType. See {@link #setCertificateType(CertificateUseEnumType)} + * @param certificate String. See {@link #setCertificate(String)} + */ + public InstallCertificateRequest(CertificateUseEnumType certificateType, String certificate) { + setCertificateType(certificateType); + setCertificate(certificate); + } + + /** + * Indicates the certificate type that is sent. + * + * @return {@link CertificateUseEnumType} + */ + public CertificateUseEnumType getCertificateType() { + return certificateType; + } + + /** + * Required. Indicates the certificate type that is sent. + * + * @param certificateType {@link CertificateUseEnumType} + */ + public void setCertificateType(CertificateUseEnumType certificateType) { + this.certificateType = certificateType; + } + + /** + * An PEM encoded X.509 certificate. + * + * @return string[0..5500] + */ + public String getCertificate() { + return certificate; + } + + /** + * Required. An PEM encoded X.509 certificate. + * + * @param certificate string[0..5500] + */ + public void setCertificate(String certificate) { + this.certificate = certificate; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return certificateType != null + && ModelUtil.validate(certificate, STRING_5500_CHAR_MAX_LENGTH); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + InstallCertificateRequest that = (InstallCertificateRequest) o; + return Objects.equals(certificateType, that.certificateType) + && Objects.equals(certificate, that.certificate); + } + + @Override + public int hashCode() { + return Objects.hash(certificateType, certificate); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("certificateType", certificateType) + .add("certificate", certificate) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/LogStatusNotificationConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/LogStatusNotificationConfirmation.java new file mode 100644 index 000000000..f396a289e --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/LogStatusNotificationConfirmation.java @@ -0,0 +1,61 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class LogStatusNotificationConfirmation implements Request { + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return true; + } + + @Override + public boolean equals(Object o) { + return this == o || o != null && getClass() == o.getClass(); + } + + @Override + public int hashCode() { + return Objects.hash(LogStatusNotificationConfirmation.class); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/LogStatusNotificationRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/LogStatusNotificationRequest.java new file mode 100644 index 000000000..c65709ce5 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/LogStatusNotificationRequest.java @@ -0,0 +1,118 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.types.UploadLogStatusEnumType; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class LogStatusNotificationRequest implements Request { + + private UploadLogStatusEnumType status; + private Integer requestId; + + /** + * Handle required fields. + * + * @param status UploadLogStatusEnumType. See {@link #setStatus(UploadLogStatusEnumType)} + */ + public LogStatusNotificationRequest(UploadLogStatusEnumType status) { + setStatus(status); + } + + /** + * This contains the status of the log upload. + * + * @return {@link UploadLogStatusEnumType} + */ + public UploadLogStatusEnumType getStatus() { + return status; + } + + /** + * Required. This contains the status of the log upload. + * + * @param status {@link UploadLogStatusEnumType} + */ + public void setStatus(UploadLogStatusEnumType status) { + this.status = status; + } + + /** + * The request id that was provided in the {@link GetLogRequest} + * that started this log upload. + * + * @return Integer + */ + public Integer getRequestId() { + return requestId; + } + + /** + * Optional. The request id that was provided in the {@link GetLogRequest} + * that started this log upload. + * + * @param requestId Integer + */ + public void setRequestId(Integer requestId) { + this.requestId = requestId; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return status != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + LogStatusNotificationRequest that = (LogStatusNotificationRequest) o; + return Objects.equals(status, that.status) + && Objects.equals(requestId, that.requestId); + } + + @Override + public int hashCode() { + return Objects.hash(status, requestId); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("requestId", requestId) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationConfirmation.java new file mode 100644 index 000000000..be45c5bcf --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationConfirmation.java @@ -0,0 +1,61 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class SecurityEventNotificationConfirmation implements Request { + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return true; + } + + @Override + public boolean equals(Object o) { + return this == o || o != null && getClass() == o.getClass(); + } + + @Override + public int hashCode() { + return Objects.hash(SecurityEventNotificationConfirmation.class); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationRequest.java new file mode 100644 index 000000000..0716abbdb --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationRequest.java @@ -0,0 +1,139 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.time.ZonedDateTime; +import java.util.Objects; + +public class SecurityEventNotificationRequest implements Request { + + private String type; + private ZonedDateTime timestamp; + private String techInfo; + + /** + * Handle required fields. + * + * @param type String. See {@link #setType(String)} + * @param timestamp dateTime. See {@link #setTimestamp(ZonedDateTime)} + */ + public SecurityEventNotificationRequest(String type, ZonedDateTime timestamp) { + setType(type); + setTimestamp(timestamp); + } + + /** + * Type of the security event. + * + * @return String + */ + public String getType() { + return type; + } + + /** + * Required. Type of the security event. + * + * @param type String + */ + public void setType(String type) { + this.type = type; + } + + /** + * Date and time at which the event occurred. + * + * @return dateTime + */ + public ZonedDateTime getTimestamp() { + return timestamp; + } + + /** + * Required. Date and time at which the event occurred. + * + * @param timestamp dateTime + */ + public void setTimestamp(ZonedDateTime timestamp) { + this.timestamp = timestamp; + } + + /** + * Additional information about the occurred security event. + * + * @return String + */ + public String getTechInfo() { + return techInfo; + } + + /** + * Optional. Additional information about the occurred security event. + * + * @param techInfo String + */ + public void setTechInfo(String techInfo) { + this.techInfo = techInfo; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return type != null && timestamp != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SecurityEventNotificationRequest that = (SecurityEventNotificationRequest) o; + return Objects.equals(type, that.type) + && Objects.equals(timestamp, that.timestamp) + && Objects.equals(techInfo, that.techInfo); + } + + @Override + public int hashCode() { + return Objects.hash(type, timestamp, techInfo); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("type", type) + .add("timestamp", timestamp) + .add("techInfo", techInfo) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateConfirmation.java new file mode 100644 index 000000000..f7f03c9ee --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateConfirmation.java @@ -0,0 +1,95 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.types.GenericStatusEnumType; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class SignCertificateConfirmation implements Request { + + private GenericStatusEnumType status; + + /** + * Handle required fields. + * + * @param status GenericStatusEnumType. See {@link #setStatus(GenericStatusEnumType)} + */ + public SignCertificateConfirmation(GenericStatusEnumType status) { + setStatus(status); + } + + /** + * Specifies whether the Central System can process the request. + * + * @return {@link GenericStatusEnumType} + */ + public GenericStatusEnumType getStatus() { + return status; + } + + /** + * Required. Specifies whether the Central System can process the request. + * + * @param status {@link GenericStatusEnumType} + */ + public void setStatus(GenericStatusEnumType status) { + this.status = status; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return status != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SignCertificateConfirmation that = (SignCertificateConfirmation) o; + return Objects.equals(status, that.status); + } + + @Override + public int hashCode() { + return Objects.hash(status); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateRequest.java new file mode 100644 index 000000000..e7f7573ab --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateRequest.java @@ -0,0 +1,101 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.utilities.ModelUtil; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class SignCertificateRequest implements Request { + + private static final int STRING_5500_CHAR_MAX_LENGTH = 5500; + + private String csr; + + /** + * Handle required fields. + * + * @param csr String. See {@link #setCsr(String)} + */ + public SignCertificateRequest(String csr) { + setCsr(csr); + } + + /** + * The Charge Point SHALL send the public key in form of a Certificate + * Signing Request (CSR) as described in RFC 2986 and then PEM encoded, + * using the {@link SignCertificateRequest} message. + * + * @return string[0..5500] + */ + public String getCsr() { + return csr; + } + + /** + * Required. The Charge Point SHALL send the public key in form of a Certificate + * Signing Request (CSR) as described in RFC 2986 and then PEM encoded, + * using the {@link SignCertificateRequest} message. + * + * @param csr string[0..5500] + */ + public void setCsr(String csr) { + this.csr = csr; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return ModelUtil.validate(csr, STRING_5500_CHAR_MAX_LENGTH); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SignCertificateRequest that = (SignCertificateRequest) o; + return Objects.equals(csr, that.csr); + } + + @Override + public int hashCode() { + return Objects.hash(csr); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("csr", csr) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedFirmwareStatusNotificationConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedFirmwareStatusNotificationConfirmation.java new file mode 100644 index 000000000..eb41e9f88 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedFirmwareStatusNotificationConfirmation.java @@ -0,0 +1,61 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class SignedFirmwareStatusNotificationConfirmation implements Request { + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return true; + } + + @Override + public boolean equals(Object o) { + return this == o || o != null && getClass() == o.getClass(); + } + + @Override + public int hashCode() { + return Objects.hash(SignedFirmwareStatusNotificationConfirmation.class); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedFirmwareStatusNotificationRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedFirmwareStatusNotificationRequest.java new file mode 100644 index 000000000..0fb647a0e --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedFirmwareStatusNotificationRequest.java @@ -0,0 +1,123 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest; +import eu.chargetime.ocpp.model.securityext.types.FirmwareStatusEnumType; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class SignedFirmwareStatusNotificationRequest implements Request { + + private FirmwareStatusEnumType status; + private Integer requestId; + + /** + * Handle required fields. + * + * @param status FirmwareStatusEnumType. See {@link #setStatus(FirmwareStatusEnumType)} + */ + public SignedFirmwareStatusNotificationRequest(FirmwareStatusEnumType status) { + setStatus(status); + } + + /** + * This contains the progress status of the firmware installation. + * + * @return {@link FirmwareStatusEnumType} + */ + public FirmwareStatusEnumType getStatus() { + return status; + } + + /** + * Required. This contains the progress status of the firmware installation. + * + * @param status {@link FirmwareStatusEnumType} + */ + public void setStatus(FirmwareStatusEnumType status) { + this.status = status; + } + + /** + * The request id that was provided in the {@link SignedUpdateFirmwareRequest} + * that started this firmware update. This field is mandatory, unless the message + * was triggered by a {@link TriggerMessageRequest} or the {@link ExtendedTriggerMessageRequest} AND + * there is no firmware update ongoing. + * + * @return Integer + */ + public Integer getRequestId() { + return requestId; + } + + /** + * Optional. The request id that was provided in the {@link SignedUpdateFirmwareRequest} + * that started this firmware update. This field is mandatory, unless the message + * was triggered by a {@link TriggerMessageRequest} or the {@link ExtendedTriggerMessageRequest} AND + * there is no firmware update ongoing. + * + * @param requestId Integer + */ + public void setRequestId(Integer requestId) { + this.requestId = requestId; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return status != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SignedFirmwareStatusNotificationRequest that = (SignedFirmwareStatusNotificationRequest) o; + return Objects.equals(status, that.status) + && Objects.equals(requestId, that.requestId); + } + + @Override + public int hashCode() { + return Objects.hash(status, requestId); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("requestId", requestId) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareConfirmation.java new file mode 100644 index 000000000..a1185e348 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareConfirmation.java @@ -0,0 +1,95 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.types.UpdateFirmwareStatusEnumType; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class SignedUpdateFirmwareConfirmation implements Request { + + private UpdateFirmwareStatusEnumType status; + + /** + * Handle required fields. + * + * @param status Integer. See {@link #setStatus(UpdateFirmwareStatusEnumType)} + */ + public SignedUpdateFirmwareConfirmation(UpdateFirmwareStatusEnumType status) { + setStatus(status); + } + + /** + * This field indicates whether the Charge Point was able to accept the request. + * + * @return {@link UpdateFirmwareStatusEnumType} + */ + public UpdateFirmwareStatusEnumType getStatus() { + return status; + } + + /** + * Required. This field indicates whether the Charge Point was able to accept the request. + * + * @param status {@link UpdateFirmwareStatusEnumType} + */ + public void setStatus(UpdateFirmwareStatusEnumType status) { + this.status = status; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return status != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SignedUpdateFirmwareConfirmation that = (SignedUpdateFirmwareConfirmation) o; + return Objects.equals(status, that.status); + } + + @Override + public int hashCode() { + return Objects.hash(status); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("retries", status) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareRequest.java new file mode 100644 index 000000000..fd9ee5942 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareRequest.java @@ -0,0 +1,168 @@ +package eu.chargetime.ocpp.model.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.types.FirmwareType; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class SignedUpdateFirmwareRequest implements Request { + + private Integer retries; + private Integer retryInterval; + private Integer requestId; + private FirmwareType firmware; + + /** + * Handle required fields. + * + * @param requestId Integer. See {@link #setRequestId(Integer)} + * @param firmware FirmwareType. See {@link #setFirmware(FirmwareType)} + */ + public SignedUpdateFirmwareRequest(Integer requestId, FirmwareType firmware) { + setRequestId(requestId); + setFirmware(firmware); + } + + /** + * This specifies how many times Charge Point must try to download the + * firmware before giving up. If this field is not present, it is left to Charge Point to + * decide how many times it wants to retry. + * + * @return Integer + */ + public Integer getRetries() { + return retries; + } + + /** + * Optional. This specifies how many times Charge Point must try to download the + * firmware before giving up. If this field is not present, it is left to Charge Point to + * decide how many times it wants to retry. + * + * @param retries Integer + */ + public void setRetries(Integer retries) { + this.retries = retries; + } + + /** + * The interval in seconds after which a retry may be attempted. If this + * field is not present, it is left to Charge Point to decide how long to wait between + * attempts. + * + * @return Integer + */ + public Integer getRetryInterval() { + return retryInterval; + } + + /** + * Optional. The interval in seconds after which a retry may be attempted. If this + * field is not present, it is left to Charge Point to decide how long to wait between + * attempts. + * + * @param retryInterval Integer + */ + public void setRetryInterval(Integer retryInterval) { + this.retryInterval = retryInterval; + } + + /** + * The Id of this request. + * + * @return Integer + */ + public Integer getRequestId() { + return requestId; + } + + /** + * Required. The Id of this request. + * + * @param requestId Integer + */ + public void setRequestId(Integer requestId) { + this.requestId = requestId; + } + + /** + * Specifies the firmware to be updated on the Charge Point. + * + * @return {@link FirmwareType} + */ + public FirmwareType getFirmware() { + return firmware; + } + + /** + * Required. Specifies the firmware to be updated on the Charge Point. + * + * @param firmware {@link FirmwareType} + */ + public void setFirmware(FirmwareType firmware) { + this.firmware = firmware; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return requestId != null && firmware != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SignedUpdateFirmwareRequest that = (SignedUpdateFirmwareRequest) o; + return Objects.equals(retries, that.retries) + && Objects.equals(retryInterval, that.retryInterval) + && Objects.equals(requestId, that.requestId) + && Objects.equals(firmware, that.firmware); + } + + @Override + public int hashCode() { + return Objects.hash(retries, retryInterval, requestId, firmware); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("retries", retries) + .add("retryInterval", retryInterval) + .add("requestId", requestId) + .add("firmware", firmware) + .add("isValid", validate()).toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateHashDataType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateHashDataType.java new file mode 100644 index 000000000..34c5f4fad --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateHashDataType.java @@ -0,0 +1,161 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Validatable; +import eu.chargetime.ocpp.model.validation.OCPPSecurityExtDatatypes; +import eu.chargetime.ocpp.model.validation.Validator; +import eu.chargetime.ocpp.model.validation.ValidatorBuilder; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.util.Objects; + +public class CertificateHashDataType implements Validatable { + private final transient Validator identifierString128Validator = + new ValidatorBuilder() + .addRule(OCPPSecurityExtDatatypes.identifierString()) + .addRule(OCPPSecurityExtDatatypes.string20()) + .setRequired(true) + .build(); + + private final transient Validator serialNumberValidator = + new ValidatorBuilder() + .addRule(OCPPSecurityExtDatatypes.string40()) + .setRequired(true) + .build(); + + private HashAlgorithmEnumType hashAlgorithm; + private String issuerNameHash; + private String issuerKeyHash; + private String serialNumber; + + /** + * Used algorithms for the hashes provided. + * + * @return {@link HashAlgorithmEnumType} + */ + public HashAlgorithmEnumType getHashAlgorithm() { + return hashAlgorithm; + } + + /** + * Required. Used algorithms for the hashes provided. + * + * @param hashAlgorithm {@link HashAlgorithmEnumType} + */ + public void setHashAlgorithm(HashAlgorithmEnumType hashAlgorithm) { + this.hashAlgorithm = hashAlgorithm; + } + + /** + * Required. Hashed value of the IssuerName. + * + * @param issuerNameHash identifierString[0..128] + */ + public void setHashAlgorithm(String issuerNameHash) { + this.issuerNameHash = issuerNameHash; + } + + /** + * Hashed value of the IssuerName. + * + * @return identifierString[0..128] + */ + public String getIssuerNameHash() { + return issuerNameHash; + } + + /** + * Hashed value of the issuers public key. + * + * @return identifierString[0..128] + */ + public String getIssuerKeyHash() { + return issuerKeyHash; + } + + /** + * Required. Hashed value of the issuers public key. + * + * @param issuerKeyHash String + */ + public void setIssuerKeyHash(String issuerKeyHash) { + this.issuerKeyHash = issuerKeyHash; + } + + /** + * The serial number of the certificate. + * + * @return identifierString[0..128] + */ + public String getSerialNumber() { + return serialNumber; + } + + /** + * Required. The serial number of the certificate. + * + * @param serialNumber string[0..40] + */ + public void setSerialNumber(String serialNumber) { + this.serialNumber = serialNumber; + } + + @Override + public boolean validate() { + return hashAlgorithm != null + && identifierString128Validator.safeValidate(issuerNameHash) + && identifierString128Validator.safeValidate(issuerKeyHash) + && serialNumberValidator.safeValidate(serialNumber); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CertificateHashDataType that = (CertificateHashDataType) o; + return Objects.equals(hashAlgorithm, that.hashAlgorithm) + && Objects.equals(issuerNameHash, that.issuerNameHash) + && Objects.equals(issuerKeyHash, that.issuerKeyHash) + && Objects.equals(serialNumber, that.serialNumber); + } + + @Override + public int hashCode() { + return Objects.hash(hashAlgorithm, issuerNameHash, issuerKeyHash, serialNumber); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("hashAlgorithm", hashAlgorithm) + .add("issuerNameHash", issuerNameHash) + .add("issuerKeyHash", issuerKeyHash) + .add("serialNumber", serialNumber) + .toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateSignedStatusEnumType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateSignedStatusEnumType.java new file mode 100644 index 000000000..517225263 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateSignedStatusEnumType.java @@ -0,0 +1,44 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.CertificateSignedConfirmation; + +/** + * CertificateSignedStatusEnumType is used by {@link CertificateSignedConfirmation} + */ +public enum CertificateSignedStatusEnumType { + /** + * Signed certificate is valid. + */ + Accepted, + + /** + * Signed certificate is invalid. + */ + Rejected +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateStatusEnumType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateStatusEnumType.java new file mode 100644 index 000000000..c7d5dcccc --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateStatusEnumType.java @@ -0,0 +1,49 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.InstallCertificateConfirmation; + +/** + * CertificateStatusEnumType is used by {@link InstallCertificateConfirmation} + */ +public enum CertificateStatusEnumType { + /** + * The installation of the certificate succeeded. + */ + Accepted, + + /** + * The certificate is valid and correct, but there is another reason the installation did not succeed. + */ + Failed, + + /** + * The certificate is invalid and/or incorrect OR the CPO tries to install more certificates than allowed. + */ + Rejected +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateUseEnumType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateUseEnumType.java new file mode 100644 index 000000000..284991e8e --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateUseEnumType.java @@ -0,0 +1,45 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.GetInstalledCertificateIdsRequest; +import eu.chargetime.ocpp.model.securityext.InstallCertificateRequest; + +/** + * CertificateUseEnumType is used by {@link GetInstalledCertificateIdsRequest}, {@link InstallCertificateRequest} + */ +public enum CertificateUseEnumType { + /** + * Root certificate, used by the CA to sign the Central System and Charge Point certificate. + */ + CentralSystemRootCertificate, + + /** + * Root certificate for verification of the Manufacturer certificate. + */ + ManufacturerRootCertificate +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/DeleteCertificateStatusEnumType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/DeleteCertificateStatusEnumType.java new file mode 100644 index 000000000..752ed2a7a --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/DeleteCertificateStatusEnumType.java @@ -0,0 +1,49 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.DeleteCertificateConfirmation; + +/** + * DeleteCertificateStatusEnumType is used by {@link DeleteCertificateConfirmation} + */ +public enum DeleteCertificateStatusEnumType { + /** + * Normal successful completion (no errors). + */ + Accepted, + + /** + * Processing failure. + */ + Failed, + + /** + * Requested resource not found. + */ + NotFound +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/FirmwareStatusEnumType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/FirmwareStatusEnumType.java new file mode 100644 index 000000000..6b0abd96f --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/FirmwareStatusEnumType.java @@ -0,0 +1,114 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.ExtendedTriggerMessageRequest; +import eu.chargetime.ocpp.model.securityext.SignedFirmwareStatusNotificationRequest; +import eu.chargetime.ocpp.model.securityext.SignedUpdateFirmwareRequest; + +/** + * Status of a firmware download. + * A value with "Intermediate state" in the description, is an intermediate state, update process is not finished. + * A value with "Failure end state" in the description, is an end state, update process has stopped, update failed. + * A value with "Successful end state" in the description, is an end state, update process has stopped, update successful. + * FirmwareStatusEnumType is used by {@link SignedFirmwareStatusNotificationRequest} + */ +public enum FirmwareStatusEnumType { + /** + * Intermediate state. New firmware has been downloaded by Charge Point. + */ + Downloaded, + + /** + * Failure end state. Charge Point failed to download firmware. + */ + DownloadFailed, + + /** + * Intermediate state. Firmware is being downloaded. + */ + Downloading, + + /** + * Intermediate state. Downloading of new firmware has been scheduled. + */ + DownloadScheduled, + + /** + * Intermediate state. Downloading has been paused. + */ + DownloadPaused, + + /** + * Charge Point is not performing firmware update related tasks. Status Idle SHALL only be used as in a + * {@link SignedFirmwareStatusNotificationRequest} that was triggered by {@link ExtendedTriggerMessageRequest}. + */ + Idle, + + /** + * Failure end state. Installation of new firmware has failed. + */ + InstallationFailed, + + /** + * Intermediate state. Firmware is being installed. + */ + Installing, + + /** + * Successful end state. New firmware has successfully been installed in Charge Point. + */ + Installed, + + /** + * Intermediate state. Charge Point is about to reboot to activate new firmware. This status MAY be omitted if a + * reboot is an integral part of the installation and cannot be reported separately + */ + InstallRebooting, + + /** + * Intermediate state. Installation of the downloaded firmware is scheduled to take place on installDateTime given + * in {@link SignedUpdateFirmwareRequest}. + */ + InstallScheduled, + + /** + * Failure end state. Verification of the new firmware (e.g. using a checksum or some other means) has failed and + * installation will not proceed. (Final failure state) + */ + InstallVerificationFailed, + + /** + * Failure end state. The firmware signature is not valid. + */ + InvalidSignature, + + /** + * Intermediate state. Provide signature successfully verified. + */ + SignatureVerified +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/FirmwareType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/FirmwareType.java new file mode 100644 index 000000000..58db459ab --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/FirmwareType.java @@ -0,0 +1,194 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Validatable; +import eu.chargetime.ocpp.model.securityext.SignedUpdateFirmwareRequest; +import eu.chargetime.ocpp.model.validation.OCPPSecurityExtDatatypes; +import eu.chargetime.ocpp.model.validation.StringMaxLengthValidationRule; +import eu.chargetime.ocpp.model.validation.Validator; +import eu.chargetime.ocpp.model.validation.ValidatorBuilder; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.time.ZonedDateTime; +import java.util.Objects; + +/** + * Represents a copy of the firmware that can be loaded/updated on the Charge Point. + * FirmwareType is used by {@link SignedUpdateFirmwareRequest} + */ +public class FirmwareType implements Validatable { + private final transient Validator locationValidator = + new ValidatorBuilder() + .addRule(OCPPSecurityExtDatatypes.string512()) + .setRequired(true) + .build(); + + private final transient Validator signingCertificateValidator = + new ValidatorBuilder() + .addRule(new StringMaxLengthValidationRule(5500)) + .setRequired(true) + .build(); + + private final transient Validator signatureValidator = + new ValidatorBuilder() + .addRule(new StringMaxLengthValidationRule(800)) + .setRequired(true) + .build(); + + private String location; + private ZonedDateTime retrieveDateTime; + private ZonedDateTime installDateTime; + private String signingCertificate; + private String signature; + + /** + * URI defining the origin of the firmware. + * + * @return string[0..512] + */ + public String getLocation() { + return location; + } + + /** + * Required. URI defining the origin of the firmware. + * + * @param location string[0..512] + */ + public void setLocation(String location) { + this.location = location; + } + + /** + * Date and time at which the firmware shall be retrieved. + * + * @return dateTime + */ + public ZonedDateTime getRetrieveDateTime() { + return retrieveDateTime; + } + + /** + * Required. Date and time at which the firmware shall be retrieved. + * + * @param retrieveDateTime dateTime + */ + public void setRetrieveDateTime(ZonedDateTime retrieveDateTime) { + this.retrieveDateTime = retrieveDateTime; + } + + /** + * Date and time at which the firmware shall be installed. + * + * @return dateTime + */ + public ZonedDateTime getInstallDateTime() { + return installDateTime; + } + + /** + * Optional. Date and time at which the firmware shall be installed. + * + * @param installDateTime dateTime + */ + public void setInstallDateTime(ZonedDateTime installDateTime) { + this.installDateTime = installDateTime; + } + + /** + * Certificate with which the firmware was signed. PEM encoded X.509 certificate. + * + * @return string[0..5500] + */ + public String getSigningCertificate() { + return signingCertificate; + } + + /** + * Required. Certificate with which the firmware was signed. PEM encoded X.509 certificate. + * + * @param signingCertificate string[0..5500] + */ + public void setSigningCertificate(String signingCertificate) { + this.signingCertificate = signingCertificate; + } + + /** + * Base64 encoded firmware signature. + * + * @return string[0..800] + */ + public String getSignature() { + return signature; + } + + /** + * Required. Base64 encoded firmware signature. + * + * @param signature string[0..800] + */ + public void setSignature(String signature) { + this.signature = signature; + } + + @Override + public boolean validate() { + return locationValidator.safeValidate(location) + && retrieveDateTime != null + && signingCertificateValidator.safeValidate(signingCertificate) + && signatureValidator.safeValidate(signature); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + FirmwareType that = (FirmwareType) o; + return Objects.equals(location, that.location) + && Objects.equals(retrieveDateTime, that.retrieveDateTime) + && Objects.equals(installDateTime, that.installDateTime) + && Objects.equals(signingCertificate, that.signingCertificate) + && Objects.equals(signature, that.signature); + } + + @Override + public int hashCode() { + return Objects.hash(location, retrieveDateTime, installDateTime, signingCertificate, signature); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("location", location) + .add("retrieveDateTime", retrieveDateTime) + .add("installDateTime", installDateTime) + .add("signingCertificate", signingCertificate) + .add("signature", signature) + .toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/GenericStatusEnumType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/GenericStatusEnumType.java new file mode 100644 index 000000000..449ddec52 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/GenericStatusEnumType.java @@ -0,0 +1,42 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +/** + * Generic message response status. + */ +public enum GenericStatusEnumType { + /** + * Request has been accepted and will be executed. + */ + Accepted, + + /** + * Request has not been accepted and will not be executed. + */ + Rejected +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/GetInstalledCertificateStatusEnumType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/GetInstalledCertificateStatusEnumType.java new file mode 100644 index 000000000..d8e9b4560 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/GetInstalledCertificateStatusEnumType.java @@ -0,0 +1,44 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.GetInstalledCertificateIdsConfirmation; + +/** + * GetInstalledCertificateStatusEnumType is used by {@link GetInstalledCertificateIdsConfirmation} + */ +public enum GetInstalledCertificateStatusEnumType { + /** + * Normal successful completion (no errors). + */ + Accepted, + + /** + * Requested certificate not found. + */ + NotFound +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/HashAlgorithmEnumType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/HashAlgorithmEnumType.java new file mode 100644 index 000000000..0af47e850 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/HashAlgorithmEnumType.java @@ -0,0 +1,47 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +/** + * HashAlgorithmEnumType is used by {@link CertificateHashDataType} + */ +public enum HashAlgorithmEnumType { + /** + * SHA-256 hash algorithm. + */ + SHA256, + + /** + * SHA-384 hash algorithm. + */ + SHA384, + + /** + * SHA-512 hash algorithm. + */ + SHA512 +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogEnumType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogEnumType.java new file mode 100644 index 000000000..790fd993d --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogEnumType.java @@ -0,0 +1,44 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.GetLogRequest; + +/** + * LogEnumType is used by {@link GetLogRequest} + */ +public enum LogEnumType { + /** + * This contains the field definition of a diagnostics log file. + */ + DiagnosticsLog, + + /** + * Sent by the Central System to the Charge Point to request that the Charge Point uploads the security log. + */ + SecurityLog +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogParametersType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogParametersType.java new file mode 100644 index 000000000..2dfd20b22 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogParametersType.java @@ -0,0 +1,136 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.Validatable; +import eu.chargetime.ocpp.model.validation.OCPPSecurityExtDatatypes; +import eu.chargetime.ocpp.model.validation.Validator; +import eu.chargetime.ocpp.model.validation.ValidatorBuilder; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import java.time.ZonedDateTime; +import java.util.Objects; + +public class LogParametersType implements Validatable { + private final transient Validator remoteLocationValidator = + new ValidatorBuilder() + .addRule(OCPPSecurityExtDatatypes.identifierString()) + .addRule(OCPPSecurityExtDatatypes.string512()) + .setRequired(true) + .build(); + + private String remoteLocation; + private ZonedDateTime oldestTimestamp; + private ZonedDateTime latestTimestamp; + + /** + * The URL of the location at the remote system where the log should be stored. + * + * @return String + */ + public String getRemoteLocation() { + return remoteLocation; + } + + /** + * Required. The URL of the location at the remote system where the log should be stored. + * + * @param remoteLocation String + */ + public void setRemoteLocation(String remoteLocation) { + this.remoteLocation = remoteLocation; + } + + /** + * This contains the date and time of the oldest logging information to + * include in the diagnostics. + * + * @return dateTime + */ + public ZonedDateTime getOldestTimestamp() { + return oldestTimestamp; + } + + /** + * Optional. This contains the date and time of the oldest logging information to + * include in the diagnostics. + * + * @param oldestTimestamp dateTime + */ + public void setOldestTimestamp(ZonedDateTime oldestTimestamp) { + this.oldestTimestamp = oldestTimestamp; + } + + /** + * This contains the date and time of the latest logging information to + * include in the diagnostics. + * + * @return dateTime + */ + public ZonedDateTime getLatestTimestamp() { + return latestTimestamp; + } + + /** + * Optional. This contains the date and time of the latest logging information to + * include in the diagnostics. + * + * @param latestTimestamp dateTime + */ + public void setLatestTimestamp(ZonedDateTime latestTimestamp) { + this.latestTimestamp = latestTimestamp; + } + + @Override + public boolean validate() { + return remoteLocationValidator.safeValidate(remoteLocation); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + LogParametersType that = (LogParametersType) o; + return Objects.equals(remoteLocation, that.remoteLocation) + && Objects.equals(oldestTimestamp, that.oldestTimestamp) + && Objects.equals(latestTimestamp, that.latestTimestamp); + } + + @Override + public int hashCode() { + return Objects.hash(remoteLocation, oldestTimestamp, latestTimestamp); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("remoteLocation", remoteLocation) + .add("oldestTimestamp", oldestTimestamp) + .add("latestTimestamp", latestTimestamp) + .toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogStatusEnumType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogStatusEnumType.java new file mode 100644 index 000000000..2103b551c --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogStatusEnumType.java @@ -0,0 +1,50 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.GetLogConfirmation; + +/** + * LogStatusEnumType is used by {@link GetLogConfirmation} + */ +public enum LogStatusEnumType { + /** + * Accepted this log upload. This does not mean the log file is uploaded is successfully, + * the Charge Point will now start the log file upload. + */ + Accepted, + + /** + * Log update request rejected. + */ + Rejected, + + /** + * Accepted this log upload, but in doing this has canceled an ongoing log file upload. + */ + AcceptedCanceled +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/MessageTriggerEnumType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/MessageTriggerEnumType.java new file mode 100644 index 000000000..da9ac8c03 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/MessageTriggerEnumType.java @@ -0,0 +1,76 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.core.BootNotificationRequest; +import eu.chargetime.ocpp.model.core.HeartbeatRequest; +import eu.chargetime.ocpp.model.core.MeterValuesRequest; +import eu.chargetime.ocpp.model.core.StatusNotificationRequest; +import eu.chargetime.ocpp.model.securityext.ExtendedTriggerMessageRequest; +import eu.chargetime.ocpp.model.securityext.LogStatusNotificationRequest; +import eu.chargetime.ocpp.model.securityext.SignCertificateRequest; +import eu.chargetime.ocpp.model.securityext.SignedFirmwareStatusNotificationRequest; + +/** + * MessageTriggerEnumType is used by {@link ExtendedTriggerMessageRequest} + */ +public enum MessageTriggerEnumType { + /** + * To trigger {@link BootNotificationRequest} + */ + BootNotification, + + /** + * To trigger {@link LogStatusNotificationRequest}. + */ + LogStatusNotification, + + /** + * To trigger {@link SignedFirmwareStatusNotificationRequest}. + */ + FirmwareStatusNotification, + + /** + * To trigger {@link HeartbeatRequest}. + */ + Heartbeat, + + /** + * To trigger {@link MeterValuesRequest}. + */ + MeterValues, + + /** + * To trigger {@link SignCertificateRequest} with certificateType: ChargePointCertificate. + */ + SignChargePointCertificate, + + /** + * To trigger {@link StatusNotificationRequest}. + */ + StatusNotification +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/TriggerMessageStatusEnumType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/TriggerMessageStatusEnumType.java new file mode 100644 index 000000000..ada354539 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/TriggerMessageStatusEnumType.java @@ -0,0 +1,49 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.ExtendedTriggerMessageConfirmation; + +/** + * TriggerMessageStatusEnumType is used by {@link ExtendedTriggerMessageConfirmation} + */ +public enum TriggerMessageStatusEnumType { + /** + * Requested message will be sent. + */ + Accepted, + + /** + * Requested message will not be sent. + */ + Rejected, + + /** + * Requested message cannot be sent because it is either not implemented or unknown. + */ + NotImplemented +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/UpdateFirmwareStatusEnumType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/UpdateFirmwareStatusEnumType.java new file mode 100644 index 000000000..bf99f1bf0 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/UpdateFirmwareStatusEnumType.java @@ -0,0 +1,60 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.SignedUpdateFirmwareConfirmation; + +/** + * UpdateFirmwareStatusEnumType is used by {@link SignedUpdateFirmwareConfirmation} + */ +public enum UpdateFirmwareStatusEnumType { + /** + * Accepted this firmware update request. This does not mean the firmware update is successful, the Charge Point will + * now start the firmware update process. + */ + Accepted, + + /** + * Firmware update request rejected. + */ + Rejected, + + /** + * Accepted this firmware update request, but in doing this has canceled an ongoing firmware update. + */ + AcceptedCanceled, + + /** + * The certificate is invalid. + */ + InvalidCertificate, + + /** + * Failure end state. The Firmware Signing certificate has been revoked. + */ + RevokedCertificate +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/UploadLogStatusEnumType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/UploadLogStatusEnumType.java new file mode 100644 index 000000000..d28270ad6 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/UploadLogStatusEnumType.java @@ -0,0 +1,71 @@ +package eu.chargetime.ocpp.model.securityext.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.ExtendedTriggerMessageRequest; +import eu.chargetime.ocpp.model.securityext.LogStatusNotificationRequest; + +/** + * UploadLogStatusEnumType is used by {@link LogStatusNotificationRequest} + */ +public enum UploadLogStatusEnumType { + /** + * A badly formatted packet or other protocol incompatibility was detected. + */ + BadMessage, + + /** + * The Charge Point is not uploading a log file. + * Idle SHALL only be used when the message was triggered by a {@link ExtendedTriggerMessageRequest}. + */ + Idle, + + /** + * The server does not support the operation. + */ + NotSupportedOperation, + + /** + * Insufficient permissions to perform the operation. + */ + PermissionDenied, + + /** + * File has been uploaded successfully. + */ + Uploaded, + + /** + * Failed to upload the requested file. + */ + UploadFailure, + + /** + * File is being uploaded. + */ + Uploading +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/validation/IdentifierStringValidationRule.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/validation/IdentifierStringValidationRule.java new file mode 100644 index 000000000..241d07034 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/validation/IdentifierStringValidationRule.java @@ -0,0 +1,47 @@ +package eu.chargetime.ocpp.model.validation; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2018 Thomas Volden + + 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. +*/ + +import eu.chargetime.ocpp.PropertyConstraintException; + +import java.util.regex.Pattern; + +public class IdentifierStringValidationRule implements IValidationRule { + private final String ERROR_MESSAGE = "Illegal character(s) in IdentifierString."; + private final String PATTERN = "([a-zA-Z0-9]|\\*|\\-|\\_|\\=|\\:|\\+|\\||\\@|\\.)+"; + + @Override + public void validate(String value) throws PropertyConstraintException { + if (!match(value)) { + throw new PropertyConstraintException(value, ERROR_MESSAGE); + } + } + + private boolean match(String value) { + Pattern pattern = Pattern.compile(PATTERN); + return pattern.matcher(value).matches(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/validation/OCPPSecurityExtDatatypes.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/validation/OCPPSecurityExtDatatypes.java new file mode 100644 index 000000000..1d276612a --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/validation/OCPPSecurityExtDatatypes.java @@ -0,0 +1,56 @@ +package eu.chargetime.ocpp.model.validation; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2018 Thomas Volden + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +public class OCPPSecurityExtDatatypes { + + public static IValidationRule string50() { + return new StringMaxLengthValidationRule(50); + } + + public static IValidationRule string20() { + return new StringMaxLengthValidationRule(20); + } + + public static IValidationRule string40() { + return new StringMaxLengthValidationRule(40); + } + + public static IValidationRule string512() { + return new StringMaxLengthValidationRule(512); + } + + public static IValidationRule string1000() { + return new StringMaxLengthValidationRule(1000); + } + + + + public static IValidationRule identifierString() { + return new IdentifierStringValidationRule(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/validation/StringMaxLengthValidationRule.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/validation/StringMaxLengthValidationRule.java new file mode 100644 index 000000000..bf7126e45 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/validation/StringMaxLengthValidationRule.java @@ -0,0 +1,45 @@ +package eu.chargetime.ocpp.model.validation; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2018 Thomas Volden + + 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. +*/ + +import eu.chargetime.ocpp.PropertyConstraintException; + +public class StringMaxLengthValidationRule implements IValidationRule { + + private static final String ERROR_MESSAGE = "Exceeded limit of %s chars"; + private final int maxLength; + + public StringMaxLengthValidationRule(int maxLength) { + this.maxLength = maxLength; + } + + @Override + public void validate(String value) throws PropertyConstraintException { + if (value.length() > maxLength) + throw new PropertyConstraintException( + value.length(), String.format(ERROR_MESSAGE, maxLength)); + } +} From a9c76a5411bfca8008b09a7181ccfc114d83d178 Mon Sep 17 00:00:00 2001 From: Mathias Oben Date: Tue, 14 Jun 2022 10:48:35 +0200 Subject: [PATCH 2/9] Extended validation in models and tests --- .../securityext/CertificateSignedRequest.java | 13 +- .../securityext/DeleteCertificateRequest.java | 2 +- .../ExtendedTriggerMessageRequest.java | 4 + ...etInstalledCertificateIdsConfirmation.java | 14 +- .../model/securityext/GetLogConfirmation.java | 13 +- .../ocpp/model/securityext/GetLogRequest.java | 10 +- .../InstallCertificateRequest.java | 14 +- .../SecurityEventNotificationRequest.java | 20 ++- .../securityext/SignCertificateRequest.java | 13 +- .../SignedUpdateFirmwareRequest.java | 2 +- .../types/CertificateHashDataType.java | 26 ++-- .../model/securityext/types/FirmwareType.java | 9 +- .../securityext/types/LogParametersType.java | 3 +- .../validation/OCPPSecurityExtDatatypes.java | 2 - .../CertificateSignedConfirmationTest.java | 77 +++++++++++ .../test/CertificateSignedRequestTest.java | 73 +++++++++++ .../DeleteCertificateConfirmationTest.java | 76 +++++++++++ .../test/DeleteCertificateRequestTest.java | 84 ++++++++++++ ...xtendedTriggerMessageConfirmationTest.java | 76 +++++++++++ .../ExtendedTriggerMessageRequestTest.java | 89 +++++++++++++ ...stalledCertificateIdsConfirmationTest.java | 100 +++++++++++++++ ...GetInstalledCertificateIdsRequestTest.java | 76 +++++++++++ .../test/GetLogConfirmationTest.java | 106 +++++++++++++++ .../securityext/test/GetLogRequestTest.java | 92 +++++++++++++ .../InstallCertificateConfirmationTest.java | 76 +++++++++++ .../test/InstallCertificateRequestTest.java | 79 ++++++++++++ ...LogStatusNotificationConfirmationTest.java | 48 +++++++ .../LogStatusNotificationRequestTest.java | 91 +++++++++++++ ...rityEventNotificationConfirmationTest.java | 48 +++++++ .../SecurityEventNotificationRequestTest.java | 112 ++++++++++++++++ .../test/SignCertificateConfirmationTest.java | 76 +++++++++++ .../test/SignCertificateRequestTest.java | 73 +++++++++++ ...areStatusNotificationConfirmationTest.java | 48 +++++++ ...FirmwareStatusNotificationRequestTest.java | 91 +++++++++++++ .../SignedUpdateFirmwareConfirmationTest.java | 76 +++++++++++ .../test/SignedUpdateFirmwareRequestTest.java | 105 +++++++++++++++ .../types/CertificateHashDataTypeTest.java | 116 +++++++++++++++++ .../test/types/FirmwareTypeTest.java | 121 ++++++++++++++++++ .../test/types/LogParametersTypeTest.java | 102 +++++++++++++++ 39 files changed, 2217 insertions(+), 39 deletions(-) create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/CertificateSignedConfirmationTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/CertificateSignedRequestTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/DeleteCertificateConfirmationTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/DeleteCertificateRequestTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/ExtendedTriggerMessageConfirmationTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/ExtendedTriggerMessageRequestTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetInstalledCertificateIdsConfirmationTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetInstalledCertificateIdsRequestTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetLogConfirmationTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetLogRequestTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/InstallCertificateConfirmationTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/InstallCertificateRequestTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/LogStatusNotificationConfirmationTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/LogStatusNotificationRequestTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SecurityEventNotificationConfirmationTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SecurityEventNotificationRequestTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignCertificateConfirmationTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignCertificateRequestTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignedFirmwareStatusNotificationConfirmationTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignedFirmwareStatusNotificationRequestTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignedUpdateFirmwareConfirmationTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignedUpdateFirmwareRequestTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/CertificateHashDataTypeTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/FirmwareTypeTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/LogParametersTypeTest.java diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedRequest.java index 73dd45bec..44fcc720d 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedRequest.java @@ -27,14 +27,20 @@ of this software and associated documentation files (the "Software"), to deal */ import eu.chargetime.ocpp.model.Request; -import eu.chargetime.ocpp.utilities.ModelUtil; +import eu.chargetime.ocpp.model.validation.StringMaxLengthValidationRule; +import eu.chargetime.ocpp.model.validation.Validator; +import eu.chargetime.ocpp.model.validation.ValidatorBuilder; import eu.chargetime.ocpp.utilities.MoreObjects; import java.util.Objects; public class CertificateSignedRequest implements Request { - private static final int STRING_10000_CHAR_MAX_LENGTH = 10000; + private static final transient Validator certificateChainValidator = + new ValidatorBuilder() + .addRule(new StringMaxLengthValidationRule(10000)) + .setRequired(true) + .build(); private String certificateChain; @@ -66,6 +72,7 @@ public String getCertificateChain() { * @param certificateChain string[0..10000] */ public void setCertificateChain(String certificateChain) { + certificateChainValidator.validate(certificateChain); this.certificateChain = certificateChain; } @@ -76,7 +83,7 @@ public boolean transactionRelated() { @Override public boolean validate() { - return ModelUtil.validate(certificateChain, STRING_10000_CHAR_MAX_LENGTH); + return certificateChainValidator.safeValidate(certificateChain); } @Override diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateRequest.java index 46aae1f98..0dfea4e0b 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateRequest.java @@ -70,7 +70,7 @@ public boolean transactionRelated() { @Override public boolean validate() { - return certificateHashData != null; + return certificateHashData != null && certificateHashData.validate(); } @Override diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageRequest.java index 89ea9fc8a..3ca3f4c44 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageRequest.java @@ -26,6 +26,7 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ +import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.model.securityext.types.MessageTriggerEnumType; import eu.chargetime.ocpp.utilities.MoreObjects; @@ -79,6 +80,9 @@ public Integer getConnectorId() { * @param connectorId Integer connectorId > 0 */ public void setConnectorId(Integer connectorId) { + if (connectorId != null && connectorId <= 0) { + throw new PropertyConstraintException(connectorId, "connectorId must be > 0"); + } this.connectorId = connectorId; } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsConfirmation.java index 97d3b1ca4..5cca8381e 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsConfirmation.java @@ -91,7 +91,19 @@ public boolean transactionRelated() { @Override public boolean validate() { - return status != null; + return status != null && validateCertificateHashData(); + } + + private boolean validateCertificateHashData() { + if (certificateHashData == null) { + return true; + } + for (CertificateHashDataType chd : certificateHashData) { + if (!chd.validate()) { + return false; + } + } + return true; } @Override diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogConfirmation.java index a62e7a8cc..add1acb8f 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogConfirmation.java @@ -28,6 +28,10 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.model.securityext.types.LogStatusEnumType; +import eu.chargetime.ocpp.model.validation.OCPPSecurityExtDatatypes; +import eu.chargetime.ocpp.model.validation.StringMaxLengthValidationRule; +import eu.chargetime.ocpp.model.validation.Validator; +import eu.chargetime.ocpp.model.validation.ValidatorBuilder; import eu.chargetime.ocpp.utilities.ModelUtil; import eu.chargetime.ocpp.utilities.MoreObjects; @@ -35,7 +39,10 @@ of this software and associated documentation files (the "Software"), to deal public class GetLogConfirmation implements Request { - private static final int STRING_255_CHAR_MAX_LENGTH = 255; + private static final transient Validator filenameValidator = + new ValidatorBuilder() + .addRule(new StringMaxLengthValidationRule(255)) + .build(); private LogStatusEnumType status; private String filename; @@ -86,6 +93,7 @@ public String getFilename() { * @param filename string[0..255] */ public void setFilename(String filename) { + filenameValidator.validate(filename); this.filename = filename; } @@ -96,8 +104,7 @@ public boolean transactionRelated() { @Override public boolean validate() { - return status != null - && (filename == null || ModelUtil.validate(filename, STRING_255_CHAR_MAX_LENGTH)); + return status != null && filenameValidator.safeValidate(filename); } @Override diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogRequest.java index 145665719..12518079d 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogRequest.java @@ -46,12 +46,12 @@ public class GetLogRequest implements Request { * * @param logType LogEnumType. See {@link #setLogType(LogEnumType)} * @param requestId Integer. See {@link #setRequestId(Integer)} - * @param log LogParametersType. See {@link #setLogParametersType(LogParametersType)} + * @param log LogParametersType. See {@link #setLog(LogParametersType)} */ public GetLogRequest(LogEnumType logType, Integer requestId, LogParametersType log) { setLogType(logType); setRequestId(requestId); - setLogParametersType(log); + setLog(log); } /** @@ -140,7 +140,7 @@ public void setRetryInterval(Integer retryInterval) { * * @return {@link LogParametersType} */ - public LogParametersType getLogParametersType() { + public LogParametersType getLog() { return log; } @@ -150,7 +150,7 @@ public LogParametersType getLogParametersType() { * * @param log {@link LogParametersType} */ - public void setLogParametersType(LogParametersType log) { + public void setLog(LogParametersType log) { this.log = log; } @@ -161,7 +161,7 @@ public boolean transactionRelated() { @Override public boolean validate() { - return logType != null && log != null; + return logType != null && requestId != null && log != null && log.validate(); } @Override diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateRequest.java index d3536f968..2b6074163 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateRequest.java @@ -28,14 +28,20 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.model.securityext.types.CertificateUseEnumType; -import eu.chargetime.ocpp.utilities.ModelUtil; +import eu.chargetime.ocpp.model.validation.StringMaxLengthValidationRule; +import eu.chargetime.ocpp.model.validation.Validator; +import eu.chargetime.ocpp.model.validation.ValidatorBuilder; import eu.chargetime.ocpp.utilities.MoreObjects; import java.util.Objects; public class InstallCertificateRequest implements Request { - private static final int STRING_5500_CHAR_MAX_LENGTH = 5500; + private static final transient Validator certificateValidator = + new ValidatorBuilder() + .addRule(new StringMaxLengthValidationRule(5500)) + .setRequired(true) + .build(); private CertificateUseEnumType certificateType; private String certificate; @@ -84,6 +90,7 @@ public String getCertificate() { * @param certificate string[0..5500] */ public void setCertificate(String certificate) { + certificateValidator.validate(certificate); this.certificate = certificate; } @@ -94,8 +101,7 @@ public boolean transactionRelated() { @Override public boolean validate() { - return certificateType != null - && ModelUtil.validate(certificate, STRING_5500_CHAR_MAX_LENGTH); + return certificateType != null && certificateValidator.safeValidate(certificate); } @Override diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationRequest.java index 0716abbdb..7407550f3 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationRequest.java @@ -27,6 +27,9 @@ of this software and associated documentation files (the "Software"), to deal */ import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.validation.StringMaxLengthValidationRule; +import eu.chargetime.ocpp.model.validation.Validator; +import eu.chargetime.ocpp.model.validation.ValidatorBuilder; import eu.chargetime.ocpp.utilities.MoreObjects; import java.time.ZonedDateTime; @@ -34,6 +37,17 @@ of this software and associated documentation files (the "Software"), to deal public class SecurityEventNotificationRequest implements Request { + private static final transient Validator typeValidator = + new ValidatorBuilder() + .addRule(new StringMaxLengthValidationRule(50)) + .setRequired(true) + .build(); + + private static final transient Validator techInfoValidator = + new ValidatorBuilder() + .addRule(new StringMaxLengthValidationRule(255)) + .build(); + private String type; private ZonedDateTime timestamp; private String techInfo; @@ -64,6 +78,7 @@ public String getType() { * @param type String */ public void setType(String type) { + typeValidator.validate(type); this.type = type; } @@ -100,6 +115,7 @@ public String getTechInfo() { * @param techInfo String */ public void setTechInfo(String techInfo) { + techInfoValidator.validate(techInfo); this.techInfo = techInfo; } @@ -110,7 +126,9 @@ public boolean transactionRelated() { @Override public boolean validate() { - return type != null && timestamp != null; + return typeValidator.safeValidate(type) + && timestamp != null + && techInfoValidator.safeValidate(techInfo); } @Override diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateRequest.java index e7f7573ab..ad34ea98a 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateRequest.java @@ -27,14 +27,20 @@ of this software and associated documentation files (the "Software"), to deal */ import eu.chargetime.ocpp.model.Request; -import eu.chargetime.ocpp.utilities.ModelUtil; +import eu.chargetime.ocpp.model.validation.StringMaxLengthValidationRule; +import eu.chargetime.ocpp.model.validation.Validator; +import eu.chargetime.ocpp.model.validation.ValidatorBuilder; import eu.chargetime.ocpp.utilities.MoreObjects; import java.util.Objects; public class SignCertificateRequest implements Request { - private static final int STRING_5500_CHAR_MAX_LENGTH = 5500; + private static final transient Validator csrValidator = + new ValidatorBuilder() + .addRule(new StringMaxLengthValidationRule(5500)) + .setRequired(true) + .build(); private String csr; @@ -66,6 +72,7 @@ public String getCsr() { * @param csr string[0..5500] */ public void setCsr(String csr) { + csrValidator.validate(csr); this.csr = csr; } @@ -76,7 +83,7 @@ public boolean transactionRelated() { @Override public boolean validate() { - return ModelUtil.validate(csr, STRING_5500_CHAR_MAX_LENGTH); + return csrValidator.safeValidate(csr); } @Override diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareRequest.java index fd9ee5942..4319cae8f 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareRequest.java @@ -137,7 +137,7 @@ public boolean transactionRelated() { @Override public boolean validate() { - return requestId != null && firmware != null; + return requestId != null && firmware != null && firmware.validate(); } @Override diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateHashDataType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateHashDataType.java index 34c5f4fad..8ef15f774 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateHashDataType.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateHashDataType.java @@ -28,6 +28,7 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.Validatable; import eu.chargetime.ocpp.model.validation.OCPPSecurityExtDatatypes; +import eu.chargetime.ocpp.model.validation.StringMaxLengthValidationRule; import eu.chargetime.ocpp.model.validation.Validator; import eu.chargetime.ocpp.model.validation.ValidatorBuilder; import eu.chargetime.ocpp.utilities.MoreObjects; @@ -35,14 +36,14 @@ of this software and associated documentation files (the "Software"), to deal import java.util.Objects; public class CertificateHashDataType implements Validatable { - private final transient Validator identifierString128Validator = + private static final transient Validator identifierString128Validator = new ValidatorBuilder() .addRule(OCPPSecurityExtDatatypes.identifierString()) - .addRule(OCPPSecurityExtDatatypes.string20()) + .addRule(new StringMaxLengthValidationRule(128)) .setRequired(true) .build(); - private final transient Validator serialNumberValidator = + private static final transient Validator serialNumberValidator = new ValidatorBuilder() .addRule(OCPPSecurityExtDatatypes.string40()) .setRequired(true) @@ -72,21 +73,22 @@ public void setHashAlgorithm(HashAlgorithmEnumType hashAlgorithm) { } /** - * Required. Hashed value of the IssuerName. + * Hashed value of the IssuerName. * - * @param issuerNameHash identifierString[0..128] + * @return identifierString[0..128] */ - public void setHashAlgorithm(String issuerNameHash) { - this.issuerNameHash = issuerNameHash; + public String getIssuerNameHash() { + return issuerNameHash; } /** - * Hashed value of the IssuerName. + * Required. Hashed value of the IssuerName. * - * @return identifierString[0..128] + * @param issuerNameHash identifierString[0..128] */ - public String getIssuerNameHash() { - return issuerNameHash; + public void setIssuerNameHash(String issuerNameHash) { + identifierString128Validator.validate(issuerNameHash); + this.issuerNameHash = issuerNameHash; } /** @@ -104,6 +106,7 @@ public String getIssuerKeyHash() { * @param issuerKeyHash String */ public void setIssuerKeyHash(String issuerKeyHash) { + identifierString128Validator.validate(issuerKeyHash); this.issuerKeyHash = issuerKeyHash; } @@ -122,6 +125,7 @@ public String getSerialNumber() { * @param serialNumber string[0..40] */ public void setSerialNumber(String serialNumber) { + serialNumberValidator.validate(serialNumber); this.serialNumber = serialNumber; } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/FirmwareType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/FirmwareType.java index 58db459ab..5f1b09163 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/FirmwareType.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/FirmwareType.java @@ -42,19 +42,19 @@ of this software and associated documentation files (the "Software"), to deal * FirmwareType is used by {@link SignedUpdateFirmwareRequest} */ public class FirmwareType implements Validatable { - private final transient Validator locationValidator = + private static final transient Validator locationValidator = new ValidatorBuilder() .addRule(OCPPSecurityExtDatatypes.string512()) .setRequired(true) .build(); - private final transient Validator signingCertificateValidator = + private static final transient Validator signingCertificateValidator = new ValidatorBuilder() .addRule(new StringMaxLengthValidationRule(5500)) .setRequired(true) .build(); - private final transient Validator signatureValidator = + private static final transient Validator signatureValidator = new ValidatorBuilder() .addRule(new StringMaxLengthValidationRule(800)) .setRequired(true) @@ -81,6 +81,7 @@ public String getLocation() { * @param location string[0..512] */ public void setLocation(String location) { + locationValidator.validate(location); this.location = location; } @@ -135,6 +136,7 @@ public String getSigningCertificate() { * @param signingCertificate string[0..5500] */ public void setSigningCertificate(String signingCertificate) { + signatureValidator.validate(signingCertificate); this.signingCertificate = signingCertificate; } @@ -153,6 +155,7 @@ public String getSignature() { * @param signature string[0..800] */ public void setSignature(String signature) { + signatureValidator.validate(signature); this.signature = signature; } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogParametersType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogParametersType.java index 2dfd20b22..db8d116ec 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogParametersType.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogParametersType.java @@ -36,7 +36,7 @@ of this software and associated documentation files (the "Software"), to deal import java.util.Objects; public class LogParametersType implements Validatable { - private final transient Validator remoteLocationValidator = + private static final transient Validator remoteLocationValidator = new ValidatorBuilder() .addRule(OCPPSecurityExtDatatypes.identifierString()) .addRule(OCPPSecurityExtDatatypes.string512()) @@ -62,6 +62,7 @@ public String getRemoteLocation() { * @param remoteLocation String */ public void setRemoteLocation(String remoteLocation) { + remoteLocationValidator.validate(remoteLocation); this.remoteLocation = remoteLocation; } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/validation/OCPPSecurityExtDatatypes.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/validation/OCPPSecurityExtDatatypes.java index 1d276612a..3122c679a 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/validation/OCPPSecurityExtDatatypes.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/validation/OCPPSecurityExtDatatypes.java @@ -48,8 +48,6 @@ public static IValidationRule string1000() { return new StringMaxLengthValidationRule(1000); } - - public static IValidationRule identifierString() { return new IdentifierStringValidationRule(); } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/CertificateSignedConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/CertificateSignedConfirmationTest.java new file mode 100644 index 000000000..35eb58d44 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/CertificateSignedConfirmationTest.java @@ -0,0 +1,77 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.CertificateSignedConfirmation; +import eu.chargetime.ocpp.model.securityext.types.CertificateSignedStatusEnumType; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class CertificateSignedConfirmationTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + CertificateSignedStatusEnumType status = CertificateSignedStatusEnumType.Accepted; + CertificateSignedConfirmation confirmation = new CertificateSignedConfirmation(status); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + CertificateSignedStatusEnumType status = CertificateSignedStatusEnumType.Accepted; + CertificateSignedConfirmation confirmation = new CertificateSignedConfirmation(null); + confirmation.setStatus(status); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_returnFalse() { + // Given + CertificateSignedConfirmation request = new CertificateSignedConfirmation(null); + + // When + boolean actual = request.validate(); + + // Then + assertFalse(actual); + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/CertificateSignedRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/CertificateSignedRequestTest.java new file mode 100644 index 000000000..47e231d94 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/CertificateSignedRequestTest.java @@ -0,0 +1,73 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.PropertyConstraintException; +import eu.chargetime.ocpp.model.securityext.CertificateSignedRequest; +import eu.chargetime.ocpp.utilities.TestUtilities; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class CertificateSignedRequestTest { + + @Test + public void validate_constructor_returnsTrue() { + // given + String certificateChain = givenCertificateChain(); + CertificateSignedRequest request = new CertificateSignedRequest(certificateChain); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test(expected = PropertyConstraintException.class) + public void constructor_nullCertificateChain_throwsPropertyConstraintException() { + // When + new CertificateSignedRequest(null); + + // Then throws + } + + @Test(expected = PropertyConstraintException.class) + public void setCertificateChain_exceedingLengthString_throwsPropertyConstraintException() { + // Given + String certificateChain = TestUtilities.aString(10001); + + // When + new CertificateSignedRequest(certificateChain); + + // Then throws + } + + private String givenCertificateChain() { + return "PEM encoded X.509 certificate"; + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/DeleteCertificateConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/DeleteCertificateConfirmationTest.java new file mode 100644 index 000000000..7b4670853 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/DeleteCertificateConfirmationTest.java @@ -0,0 +1,76 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.DeleteCertificateConfirmation; +import eu.chargetime.ocpp.model.securityext.types.DeleteCertificateStatusEnumType; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class DeleteCertificateConfirmationTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + DeleteCertificateStatusEnumType status = DeleteCertificateStatusEnumType.Accepted; + DeleteCertificateConfirmation confirmation = new DeleteCertificateConfirmation(status); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + DeleteCertificateStatusEnumType status = DeleteCertificateStatusEnumType.Accepted; + DeleteCertificateConfirmation confirmation = new DeleteCertificateConfirmation(null); + confirmation.setStatus(status); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_returnFalse() { + // Given + DeleteCertificateConfirmation request = new DeleteCertificateConfirmation(null); + + // When + boolean actual = request.validate(); + + // Then + assertFalse(actual); + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/DeleteCertificateRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/DeleteCertificateRequestTest.java new file mode 100644 index 000000000..fb2c3ff5d --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/DeleteCertificateRequestTest.java @@ -0,0 +1,84 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.DeleteCertificateRequest; +import eu.chargetime.ocpp.model.securityext.types.CertificateHashDataType; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class DeleteCertificateRequestTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + CertificateHashDataType certificateHashData = givenCertificateHashDataType(); + DeleteCertificateRequest request = new DeleteCertificateRequest(certificateHashData); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + CertificateHashDataType certificateHashData = givenCertificateHashDataType(); + DeleteCertificateRequest request = new DeleteCertificateRequest(null); + request.setCertificateHashData(certificateHashData); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_returnFalse() { + // Given + DeleteCertificateRequest request = new DeleteCertificateRequest(null); + + // When + boolean actual = request.validate(); + + // Then + assertFalse(actual); + } + + private CertificateHashDataType givenCertificateHashDataType() { + CertificateHashDataType certificateHashDataType = mock(CertificateHashDataType.class); + when(certificateHashDataType.validate()).thenReturn(true); + return certificateHashDataType; + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/ExtendedTriggerMessageConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/ExtendedTriggerMessageConfirmationTest.java new file mode 100644 index 000000000..1afe3078b --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/ExtendedTriggerMessageConfirmationTest.java @@ -0,0 +1,76 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.ExtendedTriggerMessageConfirmation; +import eu.chargetime.ocpp.model.securityext.types.TriggerMessageStatusEnumType; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class ExtendedTriggerMessageConfirmationTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + TriggerMessageStatusEnumType status = TriggerMessageStatusEnumType.Accepted; + ExtendedTriggerMessageConfirmation confirmation = new ExtendedTriggerMessageConfirmation(status); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + TriggerMessageStatusEnumType status = TriggerMessageStatusEnumType.Accepted; + ExtendedTriggerMessageConfirmation confirmation = new ExtendedTriggerMessageConfirmation(null); + confirmation.setStatus(status); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_returnFalse() { + // Given + ExtendedTriggerMessageConfirmation request = new ExtendedTriggerMessageConfirmation(null); + + // When + boolean actual = request.validate(); + + // Then + assertFalse(actual); + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/ExtendedTriggerMessageRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/ExtendedTriggerMessageRequestTest.java new file mode 100644 index 000000000..da20f2526 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/ExtendedTriggerMessageRequestTest.java @@ -0,0 +1,89 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.PropertyConstraintException; +import eu.chargetime.ocpp.model.securityext.ExtendedTriggerMessageRequest; +import eu.chargetime.ocpp.model.securityext.types.MessageTriggerEnumType; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class ExtendedTriggerMessageRequestTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + MessageTriggerEnumType requestedMessage = MessageTriggerEnumType.BootNotification; + ExtendedTriggerMessageRequest request = new ExtendedTriggerMessageRequest(requestedMessage); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + MessageTriggerEnumType requestedMessage = MessageTriggerEnumType.BootNotification; + ExtendedTriggerMessageRequest request = new ExtendedTriggerMessageRequest(null); + request.setRequestedMessage(requestedMessage); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_returnFalse() { + // Given + ExtendedTriggerMessageRequest request = new ExtendedTriggerMessageRequest(null); + + // When + boolean actual = request.validate(); + + // Then + assertFalse(actual); + } + + @Test(expected = PropertyConstraintException.class) + public void setConnectorId_invalidValue_throwsPropertyConstraintException() { + // Given + Integer connectorId = 0; + ExtendedTriggerMessageRequest request = new ExtendedTriggerMessageRequest(null); + + // When + request.setConnectorId(connectorId); + + // Then throws + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetInstalledCertificateIdsConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetInstalledCertificateIdsConfirmationTest.java new file mode 100644 index 000000000..854e35cfb --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetInstalledCertificateIdsConfirmationTest.java @@ -0,0 +1,100 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.GetInstalledCertificateIdsConfirmation; +import eu.chargetime.ocpp.model.securityext.types.CertificateHashDataType; +import eu.chargetime.ocpp.model.securityext.types.GetInstalledCertificateStatusEnumType; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class GetInstalledCertificateIdsConfirmationTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + GetInstalledCertificateStatusEnumType status = GetInstalledCertificateStatusEnumType.Accepted; + GetInstalledCertificateIdsConfirmation confirmation = new GetInstalledCertificateIdsConfirmation(status); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + GetInstalledCertificateStatusEnumType status = GetInstalledCertificateStatusEnumType.Accepted; + GetInstalledCertificateIdsConfirmation confirmation = new GetInstalledCertificateIdsConfirmation(null); + confirmation.setStatus(status); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_returnFalse() { + // Given + GetInstalledCertificateIdsConfirmation request = new GetInstalledCertificateIdsConfirmation(null); + + // When + boolean actual = request.validate(); + + // Then + assertFalse(actual); + } + + @Test + public void validate_setRequiredAndOptional_returnsTrue() { + // Given + GetInstalledCertificateStatusEnumType status = GetInstalledCertificateStatusEnumType.Accepted; + GetInstalledCertificateIdsConfirmation confirmation = new GetInstalledCertificateIdsConfirmation(null); + confirmation.setStatus(status); + confirmation.setCertificateHashData(givenCertificateHashData()); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + private CertificateHashDataType[] givenCertificateHashData() { + CertificateHashDataType certificateHashDataType = mock(CertificateHashDataType.class); + when(certificateHashDataType.validate()).thenReturn(true); + return new CertificateHashDataType[]{certificateHashDataType}; + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetInstalledCertificateIdsRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetInstalledCertificateIdsRequestTest.java new file mode 100644 index 000000000..b3c9ebe1b --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetInstalledCertificateIdsRequestTest.java @@ -0,0 +1,76 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.GetInstalledCertificateIdsRequest; +import eu.chargetime.ocpp.model.securityext.types.CertificateUseEnumType; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class GetInstalledCertificateIdsRequestTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + CertificateUseEnumType certificateType = CertificateUseEnumType.CentralSystemRootCertificate; + GetInstalledCertificateIdsRequest request = new GetInstalledCertificateIdsRequest(certificateType); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + CertificateUseEnumType certificateType = CertificateUseEnumType.CentralSystemRootCertificate; + GetInstalledCertificateIdsRequest request = new GetInstalledCertificateIdsRequest(null); + request.setCertificateType(certificateType); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_returnFalse() { + // Given + GetInstalledCertificateIdsRequest request = new GetInstalledCertificateIdsRequest(null); + + // When + boolean actual = request.validate(); + + // Then + assertFalse(actual); + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetLogConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetLogConfirmationTest.java new file mode 100644 index 000000000..fe647d013 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetLogConfirmationTest.java @@ -0,0 +1,106 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.PropertyConstraintException; +import eu.chargetime.ocpp.model.securityext.GetLogConfirmation; +import eu.chargetime.ocpp.model.securityext.types.LogStatusEnumType; +import eu.chargetime.ocpp.utilities.TestUtilities; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class GetLogConfirmationTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + LogStatusEnumType status = LogStatusEnumType.Accepted; + GetLogConfirmation confirmation = new GetLogConfirmation(status); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + LogStatusEnumType status = LogStatusEnumType.Accepted; + GetLogConfirmation confirmation = new GetLogConfirmation(null); + confirmation.setStatus(status); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_returnFalse() { + // Given + GetLogConfirmation request = new GetLogConfirmation(null); + + // When + boolean actual = request.validate(); + + // Then + assertFalse(actual); + } + + @Test + public void validate_setRequiredAndOptional_returnsTrue() { + // Given + LogStatusEnumType status = LogStatusEnumType.Accepted; + String filename = "file.log"; + GetLogConfirmation confirmation = new GetLogConfirmation(null); + confirmation.setStatus(status); + confirmation.setFilename(filename); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test(expected = PropertyConstraintException.class) + public void setFilename_exceedingLengthString_throwsPropertyConstraintException() { + // Given + String filename = TestUtilities.aString(256); + GetLogConfirmation confirmation = new GetLogConfirmation(null); + + // When + confirmation.setFilename(filename); + + // Then throws + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetLogRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetLogRequestTest.java new file mode 100644 index 000000000..06db5c9d2 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetLogRequestTest.java @@ -0,0 +1,92 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.GetLogRequest; +import eu.chargetime.ocpp.model.securityext.types.LogEnumType; +import eu.chargetime.ocpp.model.securityext.types.LogParametersType; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class GetLogRequestTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + LogEnumType logType = LogEnumType.DiagnosticsLog; + Integer requestId = 1; + LogParametersType log = givenLogParametersType(); + GetLogRequest request = new GetLogRequest(logType, requestId, log); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + LogEnumType logType = LogEnumType.DiagnosticsLog; + Integer requestId = 1; + LogParametersType log = givenLogParametersType(); + GetLogRequest request = new GetLogRequest(null, null, null); + + request.setLogType(logType); + request.setRequestId(requestId); + request.setLog(log); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_returnFalse() { + // Given + GetLogRequest request = new GetLogRequest(null, null, null); + + // When + boolean actual = request.validate(); + + // Then + assertFalse(actual); + } + + private LogParametersType givenLogParametersType() { + LogParametersType logParametersType = mock(LogParametersType.class); + when(logParametersType.validate()).thenReturn(true); + return logParametersType; + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/InstallCertificateConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/InstallCertificateConfirmationTest.java new file mode 100644 index 000000000..eff4fc053 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/InstallCertificateConfirmationTest.java @@ -0,0 +1,76 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.InstallCertificateConfirmation; +import eu.chargetime.ocpp.model.securityext.types.CertificateStatusEnumType; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class InstallCertificateConfirmationTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + CertificateStatusEnumType status = CertificateStatusEnumType.Accepted; + InstallCertificateConfirmation confirmation = new InstallCertificateConfirmation(status); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + CertificateStatusEnumType status = CertificateStatusEnumType.Accepted; + InstallCertificateConfirmation confirmation = new InstallCertificateConfirmation(null); + confirmation.setStatus(status); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_returnFalse() { + // Given + InstallCertificateConfirmation request = new InstallCertificateConfirmation(null); + + // When + boolean actual = request.validate(); + + // Then + assertFalse(actual); + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/InstallCertificateRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/InstallCertificateRequestTest.java new file mode 100644 index 000000000..11c18faa2 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/InstallCertificateRequestTest.java @@ -0,0 +1,79 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.PropertyConstraintException; +import eu.chargetime.ocpp.model.securityext.InstallCertificateRequest; +import eu.chargetime.ocpp.model.securityext.types.CertificateUseEnumType; +import eu.chargetime.ocpp.utilities.TestUtilities; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class InstallCertificateRequestTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + CertificateUseEnumType certificateType = CertificateUseEnumType.CentralSystemRootCertificate; + String certificate = givenCertificate(); + InstallCertificateRequest request = new InstallCertificateRequest(certificateType, certificate); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test(expected = PropertyConstraintException.class) + public void constructor_nullCertificate_throwsPropertyConstraintException() { + // Given + CertificateUseEnumType certificateType = CertificateUseEnumType.CentralSystemRootCertificate; + + // When + new InstallCertificateRequest(certificateType, null); + + // Then throws + } + + @Test(expected = PropertyConstraintException.class) + public void setCertificate_exceedingLengthString_throwsPropertyConstraintException() { + // Given + String certificate = TestUtilities.aString(5501); + InstallCertificateRequest request = new InstallCertificateRequest(null, null); + + // When + request.setCertificate(certificate); + + // Then throws + } + + private String givenCertificate() { + return "A PEM encoded X.509 certificate"; + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/LogStatusNotificationConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/LogStatusNotificationConfirmationTest.java new file mode 100644 index 000000000..2dfce93d0 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/LogStatusNotificationConfirmationTest.java @@ -0,0 +1,48 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.LogStatusNotificationConfirmation; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class LogStatusNotificationConfirmationTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + LogStatusNotificationConfirmation request = new LogStatusNotificationConfirmation(); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/LogStatusNotificationRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/LogStatusNotificationRequestTest.java new file mode 100644 index 000000000..803500d1b --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/LogStatusNotificationRequestTest.java @@ -0,0 +1,91 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.LogStatusNotificationRequest; +import eu.chargetime.ocpp.model.securityext.types.UploadLogStatusEnumType; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class LogStatusNotificationRequestTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + UploadLogStatusEnumType status = UploadLogStatusEnumType.Uploaded; + LogStatusNotificationRequest request = new LogStatusNotificationRequest(status); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + UploadLogStatusEnumType status = UploadLogStatusEnumType.Uploaded; + LogStatusNotificationRequest request = new LogStatusNotificationRequest(null); + request.setStatus(status); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequiredAndOptional_returnsTrue() { + // Given + UploadLogStatusEnumType status = UploadLogStatusEnumType.Uploaded; + LogStatusNotificationRequest request = new LogStatusNotificationRequest(null); + request.setStatus(status); + request.setRequestId(123); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_returnFalse() { + // Given + LogStatusNotificationRequest request = new LogStatusNotificationRequest(null); + + // When + boolean actual = request.validate(); + + // Then + assertFalse(actual); + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SecurityEventNotificationConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SecurityEventNotificationConfirmationTest.java new file mode 100644 index 000000000..4a44c5e05 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SecurityEventNotificationConfirmationTest.java @@ -0,0 +1,48 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.SecurityEventNotificationConfirmation; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class SecurityEventNotificationConfirmationTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + SecurityEventNotificationConfirmation request = new SecurityEventNotificationConfirmation(); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SecurityEventNotificationRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SecurityEventNotificationRequestTest.java new file mode 100644 index 000000000..30637accb --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SecurityEventNotificationRequestTest.java @@ -0,0 +1,112 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.PropertyConstraintException; +import eu.chargetime.ocpp.model.securityext.SecurityEventNotificationRequest; +import eu.chargetime.ocpp.utilities.TestUtilities; +import org.junit.Test; + +import java.time.ZonedDateTime; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class SecurityEventNotificationRequestTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + String type = givenType(); + ZonedDateTime timestamp = ZonedDateTime.now(); + SecurityEventNotificationRequest request = new SecurityEventNotificationRequest(type, timestamp); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test(expected = PropertyConstraintException.class) + public void constructor_nullType_throwsPropertyConstraintException() { + // Given + ZonedDateTime timestamp = ZonedDateTime.now(); + + // When + new SecurityEventNotificationRequest(null, timestamp); + + // Then throws + } + + @Test + public void validate_returnFalse() { + // Given + String type = givenType(); + SecurityEventNotificationRequest request = new SecurityEventNotificationRequest(type, null); + + // When + boolean actual = request.validate(); + + // Then + assertFalse(actual); + } + + @Test(expected = PropertyConstraintException.class) + public void setType_exceedingLengthString_throwsPropertyConstraintException() { + // Given + String type = TestUtilities.aString(51); + ZonedDateTime timestamp = ZonedDateTime.now(); + + // When + new SecurityEventNotificationRequest(type, timestamp); + + // Then throws + } + + @Test(expected = PropertyConstraintException.class) + public void setTechInfo_exceedingLengthString_throwsPropertyConstraintException() { + // Given + String type = givenType(); + ZonedDateTime timestamp = ZonedDateTime.now(); + String techInfo = TestUtilities.aString(256); + SecurityEventNotificationRequest request = new SecurityEventNotificationRequest(type, timestamp); + + // When + request.setTechInfo(techInfo); + + // Then throws + } + + private String givenType() { + return "A type string"; + } + + private String givenTechInfo() { + return "A technical info string"; + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignCertificateConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignCertificateConfirmationTest.java new file mode 100644 index 000000000..b26e13ecf --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignCertificateConfirmationTest.java @@ -0,0 +1,76 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.SignCertificateConfirmation; +import eu.chargetime.ocpp.model.securityext.types.GenericStatusEnumType; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class SignCertificateConfirmationTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + GenericStatusEnumType status = GenericStatusEnumType.Accepted; + SignCertificateConfirmation confirmation = new SignCertificateConfirmation(status); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + GenericStatusEnumType status = GenericStatusEnumType.Accepted; + SignCertificateConfirmation confirmation = new SignCertificateConfirmation(null); + confirmation.setStatus(status); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_returnFalse() { + // Given + SignCertificateConfirmation request = new SignCertificateConfirmation(null); + + // When + boolean actual = request.validate(); + + // Then + assertFalse(actual); + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignCertificateRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignCertificateRequestTest.java new file mode 100644 index 000000000..0cd0d72b3 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignCertificateRequestTest.java @@ -0,0 +1,73 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.PropertyConstraintException; +import eu.chargetime.ocpp.model.securityext.SignCertificateRequest; +import eu.chargetime.ocpp.utilities.TestUtilities; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class SignCertificateRequestTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + String csr = givenCsr(); + SignCertificateRequest request = new SignCertificateRequest(csr); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test(expected = PropertyConstraintException.class) + public void constructor_nullCsr_throwsPropertyConstraintException() { + // When + new SignCertificateRequest(null); + + // Then throws + } + + @Test(expected = PropertyConstraintException.class) + public void setCsr_exceedingLengthString_throwsPropertyConstraintException() { + // Given + String csr = TestUtilities.aString(5501); + + // When + new SignCertificateRequest(csr); + + // Then throws + } + + private String givenCsr() { + return "A Certificate Signing Request (CSR) as described in RFC 2986 and then PEM encoded"; + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignedFirmwareStatusNotificationConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignedFirmwareStatusNotificationConfirmationTest.java new file mode 100644 index 000000000..6edd1ebfa --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignedFirmwareStatusNotificationConfirmationTest.java @@ -0,0 +1,48 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.SignedFirmwareStatusNotificationConfirmation; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class SignedFirmwareStatusNotificationConfirmationTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + SignedFirmwareStatusNotificationConfirmation request = new SignedFirmwareStatusNotificationConfirmation(); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignedFirmwareStatusNotificationRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignedFirmwareStatusNotificationRequestTest.java new file mode 100644 index 000000000..271a9591d --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignedFirmwareStatusNotificationRequestTest.java @@ -0,0 +1,91 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.SignedFirmwareStatusNotificationRequest; +import eu.chargetime.ocpp.model.securityext.types.FirmwareStatusEnumType; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class SignedFirmwareStatusNotificationRequestTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + FirmwareStatusEnumType status = FirmwareStatusEnumType.Downloaded; + SignedFirmwareStatusNotificationRequest request = new SignedFirmwareStatusNotificationRequest(status); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + FirmwareStatusEnumType status = FirmwareStatusEnumType.Downloaded; + SignedFirmwareStatusNotificationRequest request = new SignedFirmwareStatusNotificationRequest(null); + request.setStatus(status); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequiredAndOptional_returnsTrue() { + // Given + FirmwareStatusEnumType status = FirmwareStatusEnumType.Downloaded; + SignedFirmwareStatusNotificationRequest request = new SignedFirmwareStatusNotificationRequest(null); + request.setStatus(status); + request.setRequestId(123); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_returnFalse() { + // Given + SignedFirmwareStatusNotificationRequest request = new SignedFirmwareStatusNotificationRequest(null); + + // When + boolean actual = request.validate(); + + // Then + assertFalse(actual); + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignedUpdateFirmwareConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignedUpdateFirmwareConfirmationTest.java new file mode 100644 index 000000000..9597ef285 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignedUpdateFirmwareConfirmationTest.java @@ -0,0 +1,76 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.SignedUpdateFirmwareConfirmation; +import eu.chargetime.ocpp.model.securityext.types.UpdateFirmwareStatusEnumType; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class SignedUpdateFirmwareConfirmationTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + UpdateFirmwareStatusEnumType status = UpdateFirmwareStatusEnumType.Accepted; + SignedUpdateFirmwareConfirmation confirmation = new SignedUpdateFirmwareConfirmation(status); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + UpdateFirmwareStatusEnumType status = UpdateFirmwareStatusEnumType.Accepted; + SignedUpdateFirmwareConfirmation confirmation = new SignedUpdateFirmwareConfirmation(null); + confirmation.setStatus(status); + + // When + boolean actual = confirmation.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_returnFalse() { + // Given + SignedUpdateFirmwareConfirmation request = new SignedUpdateFirmwareConfirmation(null); + + // When + boolean actual = request.validate(); + + // Then + assertFalse(actual); + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignedUpdateFirmwareRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignedUpdateFirmwareRequestTest.java new file mode 100644 index 000000000..a1e755fda --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignedUpdateFirmwareRequestTest.java @@ -0,0 +1,105 @@ +package eu.chargetime.ocpp.model.securityext.test; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.SignedUpdateFirmwareRequest; +import eu.chargetime.ocpp.model.securityext.types.FirmwareType; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class SignedUpdateFirmwareRequestTest { + + @Test + public void validate_constructor_returnsTrue() { + // Given + Integer requestId = 123; + FirmwareType firmware = givenFirmware(); + SignedUpdateFirmwareRequest request = new SignedUpdateFirmwareRequest(requestId, firmware); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + Integer requestId = 123; + FirmwareType firmware = givenFirmware(); + SignedUpdateFirmwareRequest request = new SignedUpdateFirmwareRequest(null, null); + request.setRequestId(requestId); + request.setFirmware(firmware); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequiredAndOptional_returnsTrue() { + // Given + Integer requestId = 123; + FirmwareType firmware = givenFirmware(); + SignedUpdateFirmwareRequest request = new SignedUpdateFirmwareRequest(null, null); + request.setRequestId(requestId); + request.setFirmware(firmware); + request.setRetries(1); + request.setRetryInterval(2); + + // When + boolean actual = request.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_returnFalse() { + // Given + SignedUpdateFirmwareRequest request = new SignedUpdateFirmwareRequest(null, null); + + // When + boolean actual = request.validate(); + + // Then + assertFalse(actual); + } + + private FirmwareType givenFirmware() { + FirmwareType firmwareType = mock(FirmwareType.class); + when(firmwareType.validate()).thenReturn(true); + return firmwareType; + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/CertificateHashDataTypeTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/CertificateHashDataTypeTest.java new file mode 100644 index 000000000..e39724fe9 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/CertificateHashDataTypeTest.java @@ -0,0 +1,116 @@ +package eu.chargetime.ocpp.model.securityext.test.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.PropertyConstraintException; +import eu.chargetime.ocpp.model.securityext.types.CertificateHashDataType; +import eu.chargetime.ocpp.model.securityext.types.HashAlgorithmEnumType; +import eu.chargetime.ocpp.utilities.TestUtilities; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class CertificateHashDataTypeTest { + + @Test + public void validate_constructor_returnsFalse() { + // Given + CertificateHashDataType dataType = new CertificateHashDataType(); + + // When + boolean actual = dataType.validate(); + + // Then + assertFalse(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + HashAlgorithmEnumType hashAlgorithm = HashAlgorithmEnumType.SHA256; + String issuerKeyHash = givenIdentifierString(); + String issuerNameHash = givenIdentifierString(); + String serialNumber = givenSerialNumber(); + CertificateHashDataType dataType = new CertificateHashDataType(); + + dataType.setHashAlgorithm(hashAlgorithm); + dataType.setIssuerNameHash(issuerNameHash); + dataType.setIssuerKeyHash(issuerKeyHash); + dataType.setSerialNumber(serialNumber); + + // When + boolean actual = dataType.validate(); + + // Then + assertTrue(actual); + } + + @Test(expected = PropertyConstraintException.class) + public void setIssuerNameHash_nonIdentifierString_throwsPropertyConstraintException() { + // Given + String issuerNameHash = TestUtilities.aString(50); + CertificateHashDataType dataType = new CertificateHashDataType(); + + // When + dataType.setIssuerNameHash(issuerNameHash); + + // Then throws + } + + @Test(expected = PropertyConstraintException.class) + public void setIssuerKeyHash_nonIdentifierString_throwsPropertyConstraintException() { + // Given + String issuerKeyHash = TestUtilities.aString(50); + CertificateHashDataType dataType = new CertificateHashDataType(); + + // When + dataType.setIssuerKeyHash(issuerKeyHash); + + // Then throws + } + + @Test(expected = PropertyConstraintException.class) + public void setSerialNumber_exceedingLengthString_throwsPropertyConstraintException() { + // Given + String serialNumber = TestUtilities.aString(41); + CertificateHashDataType dataType = new CertificateHashDataType(); + + // When + dataType.setSerialNumber(serialNumber); + + // Then throws + } + + private String givenIdentifierString() { + return "an-identifier-string"; + } + + private String givenSerialNumber() { + return "123"; + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/FirmwareTypeTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/FirmwareTypeTest.java new file mode 100644 index 000000000..d6e940fbe --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/FirmwareTypeTest.java @@ -0,0 +1,121 @@ +package eu.chargetime.ocpp.model.securityext.test.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.PropertyConstraintException; +import eu.chargetime.ocpp.model.securityext.types.FirmwareType; +import eu.chargetime.ocpp.utilities.TestUtilities; +import org.junit.Test; + +import java.time.ZonedDateTime; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class FirmwareTypeTest { + + @Test + public void validate_constructor_returnsFalse() { + // Given + FirmwareType type = new FirmwareType(); + + // When + boolean actual = type.validate(); + + // Then + assertFalse(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + String location = givenLocation(); + ZonedDateTime retrieveDateTime = ZonedDateTime.now(); + String signingCertificate = givenSigningCertificate(); + String signature = givenSignature(); + FirmwareType type = new FirmwareType(); + + type.setLocation(location); + type.setRetrieveDateTime(retrieveDateTime); + type.setSigningCertificate(signingCertificate); + type.setSignature(signature); + + // When + boolean actual = type.validate(); + + // Then + assertTrue(actual); + } + + @Test(expected = PropertyConstraintException.class) + public void setLocation_exceedingLengthString_throwsPropertyConstraintException() { + // Given + String location = TestUtilities.aString(513); + FirmwareType type = new FirmwareType(); + + // When + type.setLocation(location); + + // Then throws + } + + @Test(expected = PropertyConstraintException.class) + public void setSigningCertificate_exceedingLengthString_throwsPropertyConstraintException() { + // Given + String signingCertificate = TestUtilities.aString(5501); + FirmwareType type = new FirmwareType(); + + // When + type.setSigningCertificate(signingCertificate); + + // Then throws + } + + @Test(expected = PropertyConstraintException.class) + public void setSignature_exceedingLengthString_throwsPropertyConstraintException() { + // Given + String signature = TestUtilities.aString(801); + FirmwareType type = new FirmwareType(); + + // When + type.setSignature(signature); + + // Then throws + } + + private String givenSigningCertificate() { + return "an-identifier-string"; + } + + private String givenSignature() { + return "PEM encoded X.509 certificate"; + } + + private String givenLocation() { + return "Location"; + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/LogParametersTypeTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/LogParametersTypeTest.java new file mode 100644 index 000000000..d51e9f919 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/LogParametersTypeTest.java @@ -0,0 +1,102 @@ +package eu.chargetime.ocpp.model.securityext.test.types; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.PropertyConstraintException; +import eu.chargetime.ocpp.model.securityext.types.LogParametersType; +import eu.chargetime.ocpp.utilities.TestUtilities; +import org.junit.Test; + +import java.time.ZonedDateTime; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class LogParametersTypeTest { + + @Test + public void validate_constructor_returnsFalse() { + // Given + LogParametersType type = new LogParametersType(); + + // When + boolean actual = type.validate(); + + // Then + assertFalse(actual); + } + + @Test + public void validate_setRequired_returnsTrue() { + // Given + String remoteLocation = givenLocation(); + LogParametersType type = new LogParametersType(); + + type.setRemoteLocation(remoteLocation); + + // When + boolean actual = type.validate(); + + // Then + assertTrue(actual); + } + + @Test + public void validate_setRequiredAndOptional_returnsTrue() { + // Given + String remoteLocation = givenLocation(); + ZonedDateTime oldestTimestamp = ZonedDateTime.now(); + ZonedDateTime latestTimestamp = ZonedDateTime.now(); + LogParametersType type = new LogParametersType(); + + type.setRemoteLocation(remoteLocation); + type.setOldestTimestamp(oldestTimestamp); + type.setLatestTimestamp(latestTimestamp); + + // When + boolean actual = type.validate(); + + // Then + assertTrue(actual); + } + + @Test(expected = PropertyConstraintException.class) + public void setLocation_exceedingLengthString_throwsPropertyConstraintException() { + // Given + String location = TestUtilities.aString(513); + LogParametersType type = new LogParametersType(); + + // When + type.setRemoteLocation(location); + + // Then throws + } + + private String givenLocation() { + return "Location"; + } +} From 06ee19a2a3696e86ccaf45b3c97222ca37f8e2e9 Mon Sep 17 00:00:00 2001 From: Mathias Oben Date: Tue, 14 Jun 2022 16:20:32 +0200 Subject: [PATCH 3/9] Confirmations should implement Confirmation instead of Request --- .../securityext/CertificateSignedConfirmation.java | 9 ++------- .../securityext/DeleteCertificateConfirmation.java | 9 ++------- .../ExtendedTriggerMessageConfirmation.java | 9 ++------- .../GetInstalledCertificateIdsConfirmation.java | 9 ++------- .../ocpp/model/securityext/GetLogConfirmation.java | 11 ++--------- .../securityext/InstallCertificateConfirmation.java | 9 ++------- .../LogStatusNotificationConfirmation.java | 9 ++------- .../SecurityEventNotificationConfirmation.java | 9 ++------- .../securityext/SignCertificateConfirmation.java | 9 ++------- .../SignedFirmwareStatusNotificationConfirmation.java | 9 ++------- .../securityext/SignedUpdateFirmwareConfirmation.java | 9 ++------- 11 files changed, 22 insertions(+), 79 deletions(-) diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedConfirmation.java index 3bfacff8c..4403ad513 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedConfirmation.java @@ -26,13 +26,13 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.securityext.types.CertificateSignedStatusEnumType; import eu.chargetime.ocpp.utilities.MoreObjects; import java.util.Objects; -public class CertificateSignedConfirmation implements Request { +public class CertificateSignedConfirmation implements Confirmation { private CertificateSignedStatusEnumType status; @@ -63,11 +63,6 @@ public void setStatus(CertificateSignedStatusEnumType status) { this.status = status; } - @Override - public boolean transactionRelated() { - return false; - } - @Override public boolean validate() { return status != null; diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateConfirmation.java index 4e0614169..55f91ef15 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateConfirmation.java @@ -26,13 +26,13 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.securityext.types.DeleteCertificateStatusEnumType; import eu.chargetime.ocpp.utilities.MoreObjects; import java.util.Objects; -public class DeleteCertificateConfirmation implements Request { +public class DeleteCertificateConfirmation implements Confirmation { private DeleteCertificateStatusEnumType status; @@ -63,11 +63,6 @@ public void setStatus(DeleteCertificateStatusEnumType status) { this.status = status; } - @Override - public boolean transactionRelated() { - return false; - } - @Override public boolean validate() { return status != null; diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageConfirmation.java index 3c192ce4c..4b510fc5f 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageConfirmation.java @@ -26,13 +26,13 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.securityext.types.TriggerMessageStatusEnumType; import eu.chargetime.ocpp.utilities.MoreObjects; import java.util.Objects; -public class ExtendedTriggerMessageConfirmation implements Request { +public class ExtendedTriggerMessageConfirmation implements Confirmation { private TriggerMessageStatusEnumType status; @@ -63,11 +63,6 @@ public void setStatus(TriggerMessageStatusEnumType status) { this.status = status; } - @Override - public boolean transactionRelated() { - return false; - } - @Override public boolean validate() { return status != null; diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsConfirmation.java index 5cca8381e..602c01e6c 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsConfirmation.java @@ -26,7 +26,7 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.securityext.types.CertificateHashDataType; import eu.chargetime.ocpp.model.securityext.types.GetInstalledCertificateStatusEnumType; import eu.chargetime.ocpp.utilities.MoreObjects; @@ -34,7 +34,7 @@ of this software and associated documentation files (the "Software"), to deal import java.util.Arrays; import java.util.Objects; -public class GetInstalledCertificateIdsConfirmation implements Request { +public class GetInstalledCertificateIdsConfirmation implements Confirmation { private GetInstalledCertificateStatusEnumType status; private CertificateHashDataType[] certificateHashData; @@ -84,11 +84,6 @@ public void setCertificateHashData(CertificateHashDataType[] certificateHashData this.certificateHashData = certificateHashData; } - @Override - public boolean transactionRelated() { - return false; - } - @Override public boolean validate() { return status != null && validateCertificateHashData(); diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogConfirmation.java index add1acb8f..9702f2ff9 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogConfirmation.java @@ -26,18 +26,16 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.securityext.types.LogStatusEnumType; -import eu.chargetime.ocpp.model.validation.OCPPSecurityExtDatatypes; import eu.chargetime.ocpp.model.validation.StringMaxLengthValidationRule; import eu.chargetime.ocpp.model.validation.Validator; import eu.chargetime.ocpp.model.validation.ValidatorBuilder; -import eu.chargetime.ocpp.utilities.ModelUtil; import eu.chargetime.ocpp.utilities.MoreObjects; import java.util.Objects; -public class GetLogConfirmation implements Request { +public class GetLogConfirmation implements Confirmation { private static final transient Validator filenameValidator = new ValidatorBuilder() @@ -97,11 +95,6 @@ public void setFilename(String filename) { this.filename = filename; } - @Override - public boolean transactionRelated() { - return false; - } - @Override public boolean validate() { return status != null && filenameValidator.safeValidate(filename); diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateConfirmation.java index 3c7e06a15..eb8749bac 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateConfirmation.java @@ -26,13 +26,13 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.securityext.types.CertificateStatusEnumType; import eu.chargetime.ocpp.utilities.MoreObjects; import java.util.Objects; -public class InstallCertificateConfirmation implements Request { +public class InstallCertificateConfirmation implements Confirmation { private CertificateStatusEnumType status; @@ -63,11 +63,6 @@ public void setStatus(CertificateStatusEnumType status) { this.status = status; } - @Override - public boolean transactionRelated() { - return false; - } - @Override public boolean validate() { return status != null; diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/LogStatusNotificationConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/LogStatusNotificationConfirmation.java index f396a289e..e7d8466a5 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/LogStatusNotificationConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/LogStatusNotificationConfirmation.java @@ -26,17 +26,12 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; import java.util.Objects; -public class LogStatusNotificationConfirmation implements Request { - - @Override - public boolean transactionRelated() { - return false; - } +public class LogStatusNotificationConfirmation implements Confirmation { @Override public boolean validate() { diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationConfirmation.java index be45c5bcf..baafec165 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationConfirmation.java @@ -26,17 +26,12 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; import java.util.Objects; -public class SecurityEventNotificationConfirmation implements Request { - - @Override - public boolean transactionRelated() { - return false; - } +public class SecurityEventNotificationConfirmation implements Confirmation { @Override public boolean validate() { diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateConfirmation.java index f7f03c9ee..eb7aa1f5b 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateConfirmation.java @@ -26,13 +26,13 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.securityext.types.GenericStatusEnumType; import eu.chargetime.ocpp.utilities.MoreObjects; import java.util.Objects; -public class SignCertificateConfirmation implements Request { +public class SignCertificateConfirmation implements Confirmation { private GenericStatusEnumType status; @@ -63,11 +63,6 @@ public void setStatus(GenericStatusEnumType status) { this.status = status; } - @Override - public boolean transactionRelated() { - return false; - } - @Override public boolean validate() { return status != null; diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedFirmwareStatusNotificationConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedFirmwareStatusNotificationConfirmation.java index eb41e9f88..29a0e246c 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedFirmwareStatusNotificationConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedFirmwareStatusNotificationConfirmation.java @@ -26,17 +26,12 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; import java.util.Objects; -public class SignedFirmwareStatusNotificationConfirmation implements Request { - - @Override - public boolean transactionRelated() { - return false; - } +public class SignedFirmwareStatusNotificationConfirmation implements Confirmation { @Override public boolean validate() { diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareConfirmation.java index a1185e348..c38cafacf 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareConfirmation.java @@ -26,13 +26,13 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.securityext.types.UpdateFirmwareStatusEnumType; import eu.chargetime.ocpp.utilities.MoreObjects; import java.util.Objects; -public class SignedUpdateFirmwareConfirmation implements Request { +public class SignedUpdateFirmwareConfirmation implements Confirmation { private UpdateFirmwareStatusEnumType status; @@ -63,11 +63,6 @@ public void setStatus(UpdateFirmwareStatusEnumType status) { this.status = status; } - @Override - public boolean transactionRelated() { - return false; - } - @Override public boolean validate() { return status != null; From 32057af38bc3de05dbd054c416243e48f7e74063 Mon Sep 17 00:00:00 2001 From: Mathias Oben Date: Wed, 15 Jun 2022 15:35:15 +0200 Subject: [PATCH 4/9] Initial implementation of profiles, features and handlers for 'Improved security for OCPP 1.6-J' --- .../ClientSecurityExtEventHandler.java | 100 ++++++++++ .../securityext/ClientSecurityExtProfile.java | 157 +++++++++++++++ .../ServerSecurityExtEventHandler.java | 76 +++++++ .../securityext/ServerSecurityExtProfile.java | 187 ++++++++++++++++++ .../securityext/CertificateSignedFeature.java | 56 ++++++ .../securityext/DeleteCertificateFeature.java | 56 ++++++ .../ExtendedTriggerMessageFeature.java | 56 ++++++ .../GetInstalledCertificateIdsFeature.java | 56 ++++++ .../feature/securityext/GetLogFeature.java | 56 ++++++ .../InstallCertificateFeature.java | 56 ++++++ .../LogStatusNotificationFeature.java | 56 ++++++ .../SecurityEventNotificationFeature.java | 56 ++++++ .../securityext/SignCertificateFeature.java | 56 ++++++ ...gnedFirmwareStatusNotificationFeature.java | 56 ++++++ .../SignedUpdateFirmwareFeature.java | 56 ++++++ 15 files changed, 1136 insertions(+) create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/securityext/ClientSecurityExtEventHandler.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/securityext/ClientSecurityExtProfile.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/securityext/ServerSecurityExtEventHandler.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/securityext/ServerSecurityExtProfile.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/CertificateSignedFeature.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/DeleteCertificateFeature.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/ExtendedTriggerMessageFeature.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/GetInstalledCertificateIdsFeature.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/GetLogFeature.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/InstallCertificateFeature.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/LogStatusNotificationFeature.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/SecurityEventNotificationFeature.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/SignCertificateFeature.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/SignedFirmwareStatusNotificationFeature.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/SignedUpdateFirmwareFeature.java diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/securityext/ClientSecurityExtEventHandler.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/securityext/ClientSecurityExtEventHandler.java new file mode 100644 index 000000000..540badd8f --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/securityext/ClientSecurityExtEventHandler.java @@ -0,0 +1,100 @@ +package eu.chargetime.ocpp.feature.profile.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.CertificateSignedConfirmation; +import eu.chargetime.ocpp.model.securityext.CertificateSignedRequest; +import eu.chargetime.ocpp.model.securityext.DeleteCertificateConfirmation; +import eu.chargetime.ocpp.model.securityext.DeleteCertificateRequest; +import eu.chargetime.ocpp.model.securityext.ExtendedTriggerMessageConfirmation; +import eu.chargetime.ocpp.model.securityext.ExtendedTriggerMessageRequest; +import eu.chargetime.ocpp.model.securityext.GetInstalledCertificateIdsConfirmation; +import eu.chargetime.ocpp.model.securityext.GetInstalledCertificateIdsRequest; +import eu.chargetime.ocpp.model.securityext.GetLogConfirmation; +import eu.chargetime.ocpp.model.securityext.GetLogRequest; +import eu.chargetime.ocpp.model.securityext.InstallCertificateConfirmation; +import eu.chargetime.ocpp.model.securityext.InstallCertificateRequest; +import eu.chargetime.ocpp.model.securityext.SignedUpdateFirmwareConfirmation; +import eu.chargetime.ocpp.model.securityext.SignedUpdateFirmwareRequest; + +public interface ClientSecurityExtEventHandler { + /** + * Handle a {@link CertificateSignedRequest} and return a {@link CertificateSignedConfirmation}. + * + * @param request incoming {@link CertificateSignedRequest} to handle. + * @return outgoing {@link CertificateSignedConfirmation} to reply with. + */ + CertificateSignedConfirmation handleCertificateSignedRequest(CertificateSignedRequest request); + + /** + * Handle a {@link DeleteCertificateRequest} and return a {@link DeleteCertificateConfirmation}. + * + * @param request incoming {@link DeleteCertificateRequest} to handle. + * @return outgoing {@link DeleteCertificateConfirmation} to reply with. + */ + DeleteCertificateConfirmation handleDeleteCertificateRequest(DeleteCertificateRequest request); + + /** + * Handle a {@link ExtendedTriggerMessageRequest} and return a {@link ExtendedTriggerMessageConfirmation}. + * + * @param request incoming {@link ExtendedTriggerMessageRequest} to handle. + * @return outgoing {@link ExtendedTriggerMessageConfirmation} to reply with. + */ + ExtendedTriggerMessageConfirmation handleExtendedTriggerMessageRequest(ExtendedTriggerMessageRequest request); + + /** + * Handle a {@link GetInstalledCertificateIdsRequest} and return a {@link GetInstalledCertificateIdsConfirmation}. + * + * @param request incoming {@link GetInstalledCertificateIdsRequest} to handle. + * @return outgoing {@link GetInstalledCertificateIdsConfirmation} to reply with. + */ + GetInstalledCertificateIdsConfirmation handleGetInstalledCertificateIdsRequest(GetInstalledCertificateIdsRequest request); + + /** + * Handle a {@link GetLogRequest} and return a {@link GetLogConfirmation}. + * + * @param request incoming {@link GetLogRequest} to handle. + * @return outgoing {@link GetLogConfirmation} to reply with. + */ + GetLogConfirmation handleGetLogRequest(GetLogRequest request); + + /** + * Handle a {@link InstallCertificateRequest} and return a {@link InstallCertificateConfirmation}. + * + * @param request incoming {@link InstallCertificateRequest} to handle. + * @return outgoing {@link InstallCertificateConfirmation} to reply with. + */ + InstallCertificateConfirmation handleInstallCertificateRequest(InstallCertificateRequest request); + + /** + * Handle a {@link SignedUpdateFirmwareRequest} and return a {@link SignedUpdateFirmwareConfirmation}. + * + * @param request incoming {@link SignedUpdateFirmwareRequest} to handle. + * @return outgoing {@link SignedUpdateFirmwareConfirmation} to reply with. + */ + SignedUpdateFirmwareConfirmation handleSignedUpdateFirmwareRequest(SignedUpdateFirmwareRequest request); +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/securityext/ClientSecurityExtProfile.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/securityext/ClientSecurityExtProfile.java new file mode 100644 index 000000000..09bbddeeb --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/securityext/ClientSecurityExtProfile.java @@ -0,0 +1,157 @@ +package eu.chargetime.ocpp.feature.profile.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.feature.Feature; +import eu.chargetime.ocpp.feature.ProfileFeature; +import eu.chargetime.ocpp.feature.profile.Profile; +import eu.chargetime.ocpp.feature.securityext.CertificateSignedFeature; +import eu.chargetime.ocpp.feature.securityext.DeleteCertificateFeature; +import eu.chargetime.ocpp.feature.securityext.ExtendedTriggerMessageFeature; +import eu.chargetime.ocpp.feature.securityext.GetInstalledCertificateIdsFeature; +import eu.chargetime.ocpp.feature.securityext.GetLogFeature; +import eu.chargetime.ocpp.feature.securityext.InstallCertificateFeature; +import eu.chargetime.ocpp.feature.securityext.LogStatusNotificationFeature; +import eu.chargetime.ocpp.feature.securityext.SecurityEventNotificationFeature; +import eu.chargetime.ocpp.feature.securityext.SignCertificateFeature; +import eu.chargetime.ocpp.feature.securityext.SignedFirmwareStatusNotificationFeature; +import eu.chargetime.ocpp.feature.securityext.SignedUpdateFirmwareFeature; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.CertificateSignedRequest; +import eu.chargetime.ocpp.model.securityext.DeleteCertificateRequest; +import eu.chargetime.ocpp.model.securityext.ExtendedTriggerMessageRequest; +import eu.chargetime.ocpp.model.securityext.GetInstalledCertificateIdsRequest; +import eu.chargetime.ocpp.model.securityext.GetLogRequest; +import eu.chargetime.ocpp.model.securityext.InstallCertificateRequest; +import eu.chargetime.ocpp.model.securityext.LogStatusNotificationRequest; +import eu.chargetime.ocpp.model.securityext.SecurityEventNotificationRequest; +import eu.chargetime.ocpp.model.securityext.SignCertificateRequest; +import eu.chargetime.ocpp.model.securityext.SignedFirmwareStatusNotificationRequest; +import eu.chargetime.ocpp.model.securityext.SignedUpdateFirmwareRequest; +import eu.chargetime.ocpp.model.securityext.types.FirmwareStatusEnumType; +import eu.chargetime.ocpp.model.securityext.types.UploadLogStatusEnumType; + +import java.time.ZonedDateTime; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +public class ClientSecurityExtProfile implements Profile { + + private final Set features; + private final ClientSecurityExtEventHandler eventHandler; + + public ClientSecurityExtProfile(ClientSecurityExtEventHandler handler) { + this.features = new HashSet<>(); + this.eventHandler = handler; + + features.add(new CertificateSignedFeature(this)); + features.add(new DeleteCertificateFeature(this)); + features.add(new ExtendedTriggerMessageFeature(this)); + features.add(new GetInstalledCertificateIdsFeature(this)); + features.add(new GetLogFeature(this)); + features.add(new InstallCertificateFeature(this)); + features.add(new LogStatusNotificationFeature(null)); + features.add(new SecurityEventNotificationFeature(null)); + features.add(new SignCertificateFeature(null)); + features.add(new SignedFirmwareStatusNotificationFeature(null)); + features.add(new SignedUpdateFirmwareFeature(this)); + } + + @Override + public ProfileFeature[] getFeatureList() { + return features.toArray(new ProfileFeature[0]); + } + + @Override + public Confirmation handleRequest(UUID sessionIndex, Request request) { + Confirmation result = null; + + if (request instanceof CertificateSignedRequest) { + result = eventHandler.handleCertificateSignedRequest((CertificateSignedRequest) request); + } else if (request instanceof DeleteCertificateRequest) { + result = eventHandler.handleDeleteCertificateRequest((DeleteCertificateRequest) request); + } else if (request instanceof ExtendedTriggerMessageRequest) { + result = eventHandler.handleExtendedTriggerMessageRequest((ExtendedTriggerMessageRequest) request); + } else if (request instanceof GetInstalledCertificateIdsRequest) { + result = eventHandler.handleGetInstalledCertificateIdsRequest((GetInstalledCertificateIdsRequest) request); + } else if (request instanceof GetLogRequest) { + result = eventHandler.handleGetLogRequest((GetLogRequest) request); + } else if (request instanceof InstallCertificateRequest) { + result = eventHandler.handleInstallCertificateRequest((InstallCertificateRequest) request); + }else if (request instanceof SignedUpdateFirmwareRequest) { + result = eventHandler.handleSignedUpdateFirmwareRequest((SignedUpdateFirmwareRequest) request); + } + + return result; + } + + /** + * Create a client {@link LogStatusNotificationRequest} with required values. + * + * @return an instance of {@link LogStatusNotificationRequest}. + * @see LogStatusNotificationRequest + * @see LogStatusNotificationFeature + */ + public LogStatusNotificationRequest createLogStatusNotificationRequest(UploadLogStatusEnumType status) { + return new LogStatusNotificationRequest(status); + } + + /** + * Create a client {@link SecurityEventNotificationRequest} with required values. + * + * @return an instance of {@link SecurityEventNotificationRequest} + * @see SecurityEventNotificationRequest + * @see SecurityEventNotificationFeature + */ + public SecurityEventNotificationRequest createSecurityEventNotificationRequest(String type, ZonedDateTime timestamp) { + return new SecurityEventNotificationRequest(type, timestamp); + } + + /** + * Create a client {@link SignCertificateRequest} with required values. + * + * @return an instance of {@link SignCertificateRequest}. + * @see SignCertificateRequest + * @see SignCertificateFeature + */ + public SignCertificateRequest createSignCertificateRequest(String csr) { + return new SignCertificateRequest(csr); + } + + /** + * Create a client {@link SignedFirmwareStatusNotificationRequest}. + * + * @return an instance of {@link SignedFirmwareStatusNotificationRequest} + * @see SignedFirmwareStatusNotificationRequest + * @see SignedFirmwareStatusNotificationFeature + */ + public SignedFirmwareStatusNotificationRequest createSignedFirmwareStatusNotificationRequest(FirmwareStatusEnumType status) { + return new SignedFirmwareStatusNotificationRequest(status); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/securityext/ServerSecurityExtEventHandler.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/securityext/ServerSecurityExtEventHandler.java new file mode 100644 index 000000000..ef9574493 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/securityext/ServerSecurityExtEventHandler.java @@ -0,0 +1,76 @@ +package eu.chargetime.ocpp.feature.profile.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.LogStatusNotificationConfirmation; +import eu.chargetime.ocpp.model.securityext.LogStatusNotificationRequest; +import eu.chargetime.ocpp.model.securityext.SecurityEventNotificationConfirmation; +import eu.chargetime.ocpp.model.securityext.SecurityEventNotificationRequest; +import eu.chargetime.ocpp.model.securityext.SignCertificateConfirmation; +import eu.chargetime.ocpp.model.securityext.SignCertificateRequest; +import eu.chargetime.ocpp.model.securityext.SignedFirmwareStatusNotificationConfirmation; +import eu.chargetime.ocpp.model.securityext.SignedFirmwareStatusNotificationRequest; + +import java.util.UUID; + +public interface ServerSecurityExtEventHandler { + /** + * Handle a {@link LogStatusNotificationRequest} and return a {@link LogStatusNotificationConfirmation}. + * + * @param sessionIndex source of the request. + * @param request incoming {@link LogStatusNotificationRequest} to handle. + * @return outgoing {@link LogStatusNotificationConfirmation} to reply with. + */ + LogStatusNotificationConfirmation handleLogStatusNotificationRequest(UUID sessionIndex, LogStatusNotificationRequest request); + + /** + * Handle a {@link SecurityEventNotificationRequest} and return a {@link SecurityEventNotificationConfirmation}. + * + * @param sessionIndex source of the request. + * @param request incoming {@link SecurityEventNotificationRequest} to handle. + * @return outgoing {@link SecurityEventNotificationConfirmation} to reply with. + */ + SecurityEventNotificationConfirmation handleSecurityEventNotificationRequest(UUID sessionIndex, SecurityEventNotificationRequest request); + + /** + * Handle a {@link SignCertificateRequest} and return a {@link SignCertificateConfirmation}. + * + * @param sessionIndex source of the request. + * @param request incoming {@link SignCertificateRequest} to handle. + * @return outgoing {@link SignCertificateConfirmation} to reply with. + */ + SignCertificateConfirmation handleSignCertificateRequest(UUID sessionIndex, SignCertificateRequest request); + + /** + * Handle a {@link SignedFirmwareStatusNotificationRequest} and return a {@link SignedFirmwareStatusNotificationConfirmation}. + * + * @param sessionIndex source of the request. + * @param request incoming {@link SignedFirmwareStatusNotificationRequest} to handle. + * @return outgoing {@link SignedFirmwareStatusNotificationConfirmation} to reply with. + */ + SignedFirmwareStatusNotificationConfirmation handleSignedFirmwareStatusNotificationRequest(UUID sessionIndex, SignedFirmwareStatusNotificationRequest request); +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/securityext/ServerSecurityExtProfile.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/securityext/ServerSecurityExtProfile.java new file mode 100644 index 000000000..2e305f0d4 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/securityext/ServerSecurityExtProfile.java @@ -0,0 +1,187 @@ +package eu.chargetime.ocpp.feature.profile.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.feature.Feature; +import eu.chargetime.ocpp.feature.ProfileFeature; +import eu.chargetime.ocpp.feature.profile.Profile; +import eu.chargetime.ocpp.feature.securityext.CertificateSignedFeature; +import eu.chargetime.ocpp.feature.securityext.DeleteCertificateFeature; +import eu.chargetime.ocpp.feature.securityext.ExtendedTriggerMessageFeature; +import eu.chargetime.ocpp.feature.securityext.GetInstalledCertificateIdsFeature; +import eu.chargetime.ocpp.feature.securityext.GetLogFeature; +import eu.chargetime.ocpp.feature.securityext.InstallCertificateFeature; +import eu.chargetime.ocpp.feature.securityext.LogStatusNotificationFeature; +import eu.chargetime.ocpp.feature.securityext.SecurityEventNotificationFeature; +import eu.chargetime.ocpp.feature.securityext.SignCertificateFeature; +import eu.chargetime.ocpp.feature.securityext.SignedFirmwareStatusNotificationFeature; +import eu.chargetime.ocpp.feature.securityext.SignedUpdateFirmwareFeature; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.CertificateSignedRequest; +import eu.chargetime.ocpp.model.securityext.DeleteCertificateRequest; +import eu.chargetime.ocpp.model.securityext.ExtendedTriggerMessageRequest; +import eu.chargetime.ocpp.model.securityext.GetInstalledCertificateIdsRequest; +import eu.chargetime.ocpp.model.securityext.GetLogRequest; +import eu.chargetime.ocpp.model.securityext.InstallCertificateRequest; +import eu.chargetime.ocpp.model.securityext.LogStatusNotificationRequest; +import eu.chargetime.ocpp.model.securityext.SecurityEventNotificationRequest; +import eu.chargetime.ocpp.model.securityext.SignCertificateRequest; +import eu.chargetime.ocpp.model.securityext.SignedFirmwareStatusNotificationRequest; +import eu.chargetime.ocpp.model.securityext.SignedUpdateFirmwareRequest; +import eu.chargetime.ocpp.model.securityext.types.CertificateHashDataType; +import eu.chargetime.ocpp.model.securityext.types.CertificateUseEnumType; +import eu.chargetime.ocpp.model.securityext.types.FirmwareType; +import eu.chargetime.ocpp.model.securityext.types.LogEnumType; +import eu.chargetime.ocpp.model.securityext.types.LogParametersType; +import eu.chargetime.ocpp.model.securityext.types.MessageTriggerEnumType; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +public class ServerSecurityExtProfile implements Profile { + + private final Set features; + private final ServerSecurityExtEventHandler handler; + + public ServerSecurityExtProfile(ServerSecurityExtEventHandler handler) { + this.features = new HashSet<>(); + this.handler = handler; + + features.add(new CertificateSignedFeature(null)); + features.add(new DeleteCertificateFeature(null)); + features.add(new ExtendedTriggerMessageFeature(null)); + features.add(new GetInstalledCertificateIdsFeature(null)); + features.add(new GetLogFeature(null)); + features.add(new InstallCertificateFeature(null)); + features.add(new LogStatusNotificationFeature(this)); + features.add(new SecurityEventNotificationFeature(this)); + features.add(new SignCertificateFeature(this)); + features.add(new SignedFirmwareStatusNotificationFeature(this)); + features.add(new SignedUpdateFirmwareFeature(null)); + } + + @Override + public ProfileFeature[] getFeatureList() { + return features.toArray(new ProfileFeature[0]); + } + + @Override + public Confirmation handleRequest(UUID sessionIndex, Request request) { + Confirmation result = null; + + if (request instanceof LogStatusNotificationRequest) { + result = handler.handleLogStatusNotificationRequest(sessionIndex, (LogStatusNotificationRequest) request); + } else if (request instanceof SecurityEventNotificationRequest) { + result = handler.handleSecurityEventNotificationRequest(sessionIndex, (SecurityEventNotificationRequest) request); + } else if (request instanceof SignCertificateRequest) { + result = handler.handleSignCertificateRequest(sessionIndex, (SignCertificateRequest) request); + } else if (request instanceof SignedFirmwareStatusNotificationRequest) { + result = handler.handleSignedFirmwareStatusNotificationRequest(sessionIndex, (SignedFirmwareStatusNotificationRequest) request); + } + + return result; + } + + /** + * Create a client {@link CertificateSignedRequest} with required values. + * + * @return an instance of {@link CertificateSignedRequest} + * @see CertificateSignedRequest + * @see CertificateSignedFeature + */ + public CertificateSignedRequest createCertificateSignedRequest(String certificateChain) { + return new CertificateSignedRequest(certificateChain); + } + + /** + * Create a client {@link DeleteCertificateRequest} with required values. + * + * @return an instance of {@link DeleteCertificateRequest} + * @see DeleteCertificateRequest + * @see DeleteCertificateFeature + */ + public DeleteCertificateRequest createDeleteCertificateRequest(CertificateHashDataType certificateHashData) { + return new DeleteCertificateRequest(certificateHashData); + } + + /** + * Create a client {@link ExtendedTriggerMessageFeature}. + * + * @return an instance of {@link ExtendedTriggerMessageRequest} + * @see ExtendedTriggerMessageRequest + * @see ExtendedTriggerMessageFeature + */ + public ExtendedTriggerMessageRequest createExtendedTriggerMessageRequest(MessageTriggerEnumType requestedMessage) { + return new ExtendedTriggerMessageRequest(requestedMessage); + } + + /** + * Create a client {@link GetInstalledCertificateIdsRequest} required values. + * + * @return an instance of {@link GetInstalledCertificateIdsRequest} + * @see GetInstalledCertificateIdsRequest + * @see GetInstalledCertificateIdsFeature + */ + public GetInstalledCertificateIdsRequest createGetInstalledCertificateIdsRequest(CertificateUseEnumType certificateType) { + return new GetInstalledCertificateIdsRequest(certificateType); + } + + /** + * Create a client {@link GetLogRequest}. + * + * @return an instance of {@link GetLogRequest} + * @see GetLogRequest + * @see GetLogFeature + */ + public GetLogRequest createGetLogRequest(LogEnumType logType, Integer requestId, LogParametersType log) { + return new GetLogRequest(logType, requestId, log); + } + + /** + * Create a client {@link InstallCertificateRequest} with required values. + * + * @return an instance of {@link InstallCertificateRequest} + * @see InstallCertificateRequest + * @see InstallCertificateFeature + */ + public InstallCertificateRequest createInstallCertificateRequest(CertificateUseEnumType certificateType, String certificate) { + return new InstallCertificateRequest(certificateType, certificate); + } + + /** + * Create a client {@link SignedUpdateFirmwareRequest} with required values. + * + * @return an instance of {@link SignedUpdateFirmwareRequest} + * @see SignedUpdateFirmwareRequest + * @see SignedUpdateFirmwareFeature + */ + public SignedUpdateFirmwareRequest createSignedUpdateFirmwareRequest(Integer requestId, FirmwareType firmware) { + return new SignedUpdateFirmwareRequest(requestId, firmware); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/CertificateSignedFeature.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/CertificateSignedFeature.java new file mode 100644 index 000000000..3a740c1f9 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/CertificateSignedFeature.java @@ -0,0 +1,56 @@ +package eu.chargetime.ocpp.feature.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.feature.ProfileFeature; +import eu.chargetime.ocpp.feature.profile.Profile; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.CertificateSignedConfirmation; +import eu.chargetime.ocpp.model.securityext.CertificateSignedRequest; + +public class CertificateSignedFeature extends ProfileFeature { + + public CertificateSignedFeature(Profile ownerProfile) { + super(ownerProfile); + } + + @Override + public Class getRequestType() { + return CertificateSignedRequest.class; + } + + @Override + public Class getConfirmationType() { + return CertificateSignedConfirmation.class; + } + + @Override + public String getAction() { + return "CertificateSigned"; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/DeleteCertificateFeature.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/DeleteCertificateFeature.java new file mode 100644 index 000000000..3ec880182 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/DeleteCertificateFeature.java @@ -0,0 +1,56 @@ +package eu.chargetime.ocpp.feature.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.feature.ProfileFeature; +import eu.chargetime.ocpp.feature.profile.Profile; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.DeleteCertificateConfirmation; +import eu.chargetime.ocpp.model.securityext.DeleteCertificateRequest; + +public class DeleteCertificateFeature extends ProfileFeature { + + public DeleteCertificateFeature(Profile ownerProfile) { + super(ownerProfile); + } + + @Override + public Class getRequestType() { + return DeleteCertificateRequest.class; + } + + @Override + public Class getConfirmationType() { + return DeleteCertificateConfirmation.class; + } + + @Override + public String getAction() { + return "DeleteCertificate"; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/ExtendedTriggerMessageFeature.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/ExtendedTriggerMessageFeature.java new file mode 100644 index 000000000..d27263967 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/ExtendedTriggerMessageFeature.java @@ -0,0 +1,56 @@ +package eu.chargetime.ocpp.feature.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.feature.ProfileFeature; +import eu.chargetime.ocpp.feature.profile.Profile; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.ExtendedTriggerMessageConfirmation; +import eu.chargetime.ocpp.model.securityext.ExtendedTriggerMessageRequest; + +public class ExtendedTriggerMessageFeature extends ProfileFeature { + + public ExtendedTriggerMessageFeature(Profile ownerProfile) { + super(ownerProfile); + } + + @Override + public Class getRequestType() { + return ExtendedTriggerMessageRequest.class; + } + + @Override + public Class getConfirmationType() { + return ExtendedTriggerMessageConfirmation.class; + } + + @Override + public String getAction() { + return "ExtendedTriggerMessage"; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/GetInstalledCertificateIdsFeature.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/GetInstalledCertificateIdsFeature.java new file mode 100644 index 000000000..04b10d7b6 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/GetInstalledCertificateIdsFeature.java @@ -0,0 +1,56 @@ +package eu.chargetime.ocpp.feature.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.feature.ProfileFeature; +import eu.chargetime.ocpp.feature.profile.Profile; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.GetInstalledCertificateIdsConfirmation; +import eu.chargetime.ocpp.model.securityext.GetInstalledCertificateIdsRequest; + +public class GetInstalledCertificateIdsFeature extends ProfileFeature { + + public GetInstalledCertificateIdsFeature(Profile ownerProfile) { + super(ownerProfile); + } + + @Override + public Class getRequestType() { + return GetInstalledCertificateIdsRequest.class; + } + + @Override + public Class getConfirmationType() { + return GetInstalledCertificateIdsConfirmation.class; + } + + @Override + public String getAction() { + return "GetInstalledCertificateIds"; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/GetLogFeature.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/GetLogFeature.java new file mode 100644 index 000000000..df47f7a62 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/GetLogFeature.java @@ -0,0 +1,56 @@ +package eu.chargetime.ocpp.feature.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.feature.ProfileFeature; +import eu.chargetime.ocpp.feature.profile.Profile; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.GetLogConfirmation; +import eu.chargetime.ocpp.model.securityext.GetLogRequest; + +public class GetLogFeature extends ProfileFeature { + + public GetLogFeature(Profile ownerProfile) { + super(ownerProfile); + } + + @Override + public Class getRequestType() { + return GetLogRequest.class; + } + + @Override + public Class getConfirmationType() { + return GetLogConfirmation.class; + } + + @Override + public String getAction() { + return "GetLog"; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/InstallCertificateFeature.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/InstallCertificateFeature.java new file mode 100644 index 000000000..c371089ae --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/InstallCertificateFeature.java @@ -0,0 +1,56 @@ +package eu.chargetime.ocpp.feature.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.feature.ProfileFeature; +import eu.chargetime.ocpp.feature.profile.Profile; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.InstallCertificateConfirmation; +import eu.chargetime.ocpp.model.securityext.InstallCertificateRequest; + +public class InstallCertificateFeature extends ProfileFeature { + + public InstallCertificateFeature(Profile ownerProfile) { + super(ownerProfile); + } + + @Override + public Class getRequestType() { + return InstallCertificateRequest.class; + } + + @Override + public Class getConfirmationType() { + return InstallCertificateConfirmation.class; + } + + @Override + public String getAction() { + return "InstallCertificate"; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/LogStatusNotificationFeature.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/LogStatusNotificationFeature.java new file mode 100644 index 000000000..4f66eaca8 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/LogStatusNotificationFeature.java @@ -0,0 +1,56 @@ +package eu.chargetime.ocpp.feature.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.feature.ProfileFeature; +import eu.chargetime.ocpp.feature.profile.Profile; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.LogStatusNotificationConfirmation; +import eu.chargetime.ocpp.model.securityext.LogStatusNotificationRequest; + +public class LogStatusNotificationFeature extends ProfileFeature { + + public LogStatusNotificationFeature(Profile ownerProfile) { + super(ownerProfile); + } + + @Override + public Class getRequestType() { + return LogStatusNotificationRequest.class; + } + + @Override + public Class getConfirmationType() { + return LogStatusNotificationConfirmation.class; + } + + @Override + public String getAction() { + return "LogStatusNotification"; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/SecurityEventNotificationFeature.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/SecurityEventNotificationFeature.java new file mode 100644 index 000000000..51297b05f --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/SecurityEventNotificationFeature.java @@ -0,0 +1,56 @@ +package eu.chargetime.ocpp.feature.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.feature.ProfileFeature; +import eu.chargetime.ocpp.feature.profile.Profile; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.SecurityEventNotificationConfirmation; +import eu.chargetime.ocpp.model.securityext.SecurityEventNotificationRequest; + +public class SecurityEventNotificationFeature extends ProfileFeature { + + public SecurityEventNotificationFeature(Profile ownerProfile) { + super(ownerProfile); + } + + @Override + public Class getRequestType() { + return SecurityEventNotificationRequest.class; + } + + @Override + public Class getConfirmationType() { + return SecurityEventNotificationConfirmation.class; + } + + @Override + public String getAction() { + return "SecurityEventNotification"; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/SignCertificateFeature.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/SignCertificateFeature.java new file mode 100644 index 000000000..305bd3504 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/SignCertificateFeature.java @@ -0,0 +1,56 @@ +package eu.chargetime.ocpp.feature.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.feature.ProfileFeature; +import eu.chargetime.ocpp.feature.profile.Profile; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.SignCertificateConfirmation; +import eu.chargetime.ocpp.model.securityext.SignCertificateRequest; + +public class SignCertificateFeature extends ProfileFeature { + + public SignCertificateFeature(Profile ownerProfile) { + super(ownerProfile); + } + + @Override + public Class getRequestType() { + return SignCertificateRequest.class; + } + + @Override + public Class getConfirmationType() { + return SignCertificateConfirmation.class; + } + + @Override + public String getAction() { + return "SignCertificate"; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/SignedFirmwareStatusNotificationFeature.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/SignedFirmwareStatusNotificationFeature.java new file mode 100644 index 000000000..512d121f7 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/SignedFirmwareStatusNotificationFeature.java @@ -0,0 +1,56 @@ +package eu.chargetime.ocpp.feature.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.feature.ProfileFeature; +import eu.chargetime.ocpp.feature.profile.Profile; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.SignedFirmwareStatusNotificationConfirmation; +import eu.chargetime.ocpp.model.securityext.SignedFirmwareStatusNotificationRequest; + +public class SignedFirmwareStatusNotificationFeature extends ProfileFeature { + + public SignedFirmwareStatusNotificationFeature(Profile ownerProfile) { + super(ownerProfile); + } + + @Override + public Class getRequestType() { + return SignedFirmwareStatusNotificationRequest.class; + } + + @Override + public Class getConfirmationType() { + return SignedFirmwareStatusNotificationConfirmation.class; + } + + @Override + public String getAction() { + return "SignedFirmwareStatusNotification"; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/SignedUpdateFirmwareFeature.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/SignedUpdateFirmwareFeature.java new file mode 100644 index 000000000..25060b491 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/securityext/SignedUpdateFirmwareFeature.java @@ -0,0 +1,56 @@ +package eu.chargetime.ocpp.feature.securityext; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.feature.ProfileFeature; +import eu.chargetime.ocpp.feature.profile.Profile; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.securityext.SignedUpdateFirmwareConfirmation; +import eu.chargetime.ocpp.model.securityext.SignedUpdateFirmwareRequest; + +public class SignedUpdateFirmwareFeature extends ProfileFeature { + + public SignedUpdateFirmwareFeature(Profile ownerProfile) { + super(ownerProfile); + } + + @Override + public Class getRequestType() { + return SignedUpdateFirmwareRequest.class; + } + + @Override + public Class getConfirmationType() { + return SignedUpdateFirmwareConfirmation.class; + } + + @Override + public String getAction() { + return "SignedUpdateFirmware"; + } +} From 92b8ddf234bdc80b7f59b9e68186fdeb24370f5e Mon Sep 17 00:00:00 2001 From: Mathias Oben Date: Wed, 15 Jun 2022 15:37:47 +0200 Subject: [PATCH 5/9] Tests for security client and server profiles --- .../ClientSecurityExtProfileTest.java | 264 +++++++++++++++++ .../ServerSecurityExtProfileTest.java | 266 ++++++++++++++++++ 2 files changed, 530 insertions(+) create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/securityext/ClientSecurityExtProfileTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/securityext/ServerSecurityExtProfileTest.java diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/securityext/ClientSecurityExtProfileTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/securityext/ClientSecurityExtProfileTest.java new file mode 100644 index 000000000..95c98fe0d --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/securityext/ClientSecurityExtProfileTest.java @@ -0,0 +1,264 @@ +package eu.chargetime.ocpp.feature.profile.test.securityext; + +import eu.chargetime.ocpp.feature.Feature; +import eu.chargetime.ocpp.feature.profile.securityext.ClientSecurityExtEventHandler; +import eu.chargetime.ocpp.feature.profile.securityext.ClientSecurityExtProfile; +import eu.chargetime.ocpp.feature.profile.test.ProfileTest; +import eu.chargetime.ocpp.feature.securityext.CertificateSignedFeature; +import eu.chargetime.ocpp.feature.securityext.DeleteCertificateFeature; +import eu.chargetime.ocpp.feature.securityext.ExtendedTriggerMessageFeature; +import eu.chargetime.ocpp.feature.securityext.GetInstalledCertificateIdsFeature; +import eu.chargetime.ocpp.feature.securityext.GetLogFeature; +import eu.chargetime.ocpp.feature.securityext.InstallCertificateFeature; +import eu.chargetime.ocpp.feature.securityext.LogStatusNotificationFeature; +import eu.chargetime.ocpp.feature.securityext.SecurityEventNotificationFeature; +import eu.chargetime.ocpp.feature.securityext.SignCertificateFeature; +import eu.chargetime.ocpp.feature.securityext.SignedFirmwareStatusNotificationFeature; +import eu.chargetime.ocpp.feature.securityext.SignedUpdateFirmwareFeature; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.securityext.CertificateSignedConfirmation; +import eu.chargetime.ocpp.model.securityext.CertificateSignedRequest; +import eu.chargetime.ocpp.model.securityext.DeleteCertificateConfirmation; +import eu.chargetime.ocpp.model.securityext.DeleteCertificateRequest; +import eu.chargetime.ocpp.model.securityext.ExtendedTriggerMessageConfirmation; +import eu.chargetime.ocpp.model.securityext.ExtendedTriggerMessageRequest; +import eu.chargetime.ocpp.model.securityext.GetInstalledCertificateIdsConfirmation; +import eu.chargetime.ocpp.model.securityext.GetInstalledCertificateIdsRequest; +import eu.chargetime.ocpp.model.securityext.GetLogConfirmation; +import eu.chargetime.ocpp.model.securityext.GetLogRequest; +import eu.chargetime.ocpp.model.securityext.InstallCertificateConfirmation; +import eu.chargetime.ocpp.model.securityext.InstallCertificateRequest; +import eu.chargetime.ocpp.model.securityext.LogStatusNotificationRequest; +import eu.chargetime.ocpp.model.securityext.SecurityEventNotificationRequest; +import eu.chargetime.ocpp.model.securityext.SignCertificateRequest; +import eu.chargetime.ocpp.model.securityext.SignedFirmwareStatusNotificationRequest; +import eu.chargetime.ocpp.model.securityext.SignedUpdateFirmwareConfirmation; +import eu.chargetime.ocpp.model.securityext.SignedUpdateFirmwareRequest; +import eu.chargetime.ocpp.model.securityext.types.FirmwareStatusEnumType; +import eu.chargetime.ocpp.model.securityext.types.UploadLogStatusEnumType; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import java.time.ZonedDateTime; +import java.util.UUID; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +@RunWith(MockitoJUnitRunner.class) +public class ClientSecurityExtProfileTest extends ProfileTest { + private static final UUID SESSION_ID = null; + + private ClientSecurityExtProfile profile; + + @Mock + private ClientSecurityExtEventHandler handler; + + @Before + public void setup() { + profile = new ClientSecurityExtProfile(handler); + } + + @Test + public void getFeatureList_containsAllFeature() { + // When + Feature[] features = profile.getFeatureList(); + + // then + assertTrue(findFeature(features, "CertificateSigned") instanceof CertificateSignedFeature); + assertTrue(findFeature(features, "DeleteCertificate") instanceof DeleteCertificateFeature); + assertTrue(findFeature(features, "ExtendedTriggerMessage") instanceof ExtendedTriggerMessageFeature); + assertTrue(findFeature(features, "GetInstalledCertificateIds") instanceof GetInstalledCertificateIdsFeature); + assertTrue(findFeature(features, "GetLog") instanceof GetLogFeature); + assertTrue(findFeature(features, "InstallCertificate") instanceof InstallCertificateFeature); + assertTrue(findFeature(features, "LogStatusNotification") instanceof LogStatusNotificationFeature); + assertTrue(findFeature(features, "SecurityEventNotification") instanceof SecurityEventNotificationFeature); + assertTrue(findFeature(features, "SignCertificate") instanceof SignCertificateFeature); + assertTrue(findFeature(features, "SignedFirmwareStatusNotification") instanceof SignedFirmwareStatusNotificationFeature); + assertTrue(findFeature(features, "SignedUpdateFirmware") instanceof SignedUpdateFirmwareFeature); + } + + @Test + public void createLogStatusNotificationRequest_withParams_returnsCompleteRequest() { + // Given + UploadLogStatusEnumType status = UploadLogStatusEnumType.Uploaded; + + // When + LogStatusNotificationRequest actual = profile.createLogStatusNotificationRequest(status); + + // Then + assertEquals(status, actual.getStatus()); + assertNull(actual.getRequestId()); + } + + @Test + public void createSecurityEventNotificationRequest_withParams_returnsCompleteRequest() { + // Given + String type = "type"; + ZonedDateTime timestamp = ZonedDateTime.now(); + + // When + SecurityEventNotificationRequest actual = profile.createSecurityEventNotificationRequest(type, timestamp); + + // Then + assertEquals(type, actual.getType()); + assertEquals(timestamp, actual.getTimestamp()); + assertNull(actual.getTechInfo()); + } + + @Test + public void createSignCertificateRequest_withParams_returnsCompleteRequest() { + // Given + String csr = "csr"; + + // When + SignCertificateRequest actual = profile.createSignCertificateRequest(csr); + + // Then + assertEquals(csr, actual.getCsr()); + } + + @Test + public void createSignedFirmwareStatusNotificationRequest_withParams_returnsCompleteRequest() { + // Given + FirmwareStatusEnumType status = FirmwareStatusEnumType.Downloaded; + + // When + SignedFirmwareStatusNotificationRequest actual = profile.createSignedFirmwareStatusNotificationRequest(status); + + // Then + assertEquals(status, actual.getStatus()); + assertNull(actual.getRequestId()); + } + + @Test + public void handleRequest_whenCertificateSignedRequest_callsHandleCertificateSignedRequest() { + // Given + CertificateSignedRequest request = mock(CertificateSignedRequest.class); + CertificateSignedConfirmation confirmation = mock(CertificateSignedConfirmation.class); + when(handler.handleCertificateSignedRequest(request)).thenReturn(confirmation); + + // When + Confirmation actual = profile.handleRequest(SESSION_ID, request); + + // Then + assertEquals(confirmation, actual); + } + + @Test + public void handleRequest_whenDeleteCertificateRequest_callsHandleDeleteCertificateRequest() { + // Given + DeleteCertificateRequest request = mock(DeleteCertificateRequest.class); + DeleteCertificateConfirmation confirmation = mock(DeleteCertificateConfirmation.class); + when(handler.handleDeleteCertificateRequest(request)).thenReturn(confirmation); + + // When + Confirmation actual = profile.handleRequest(SESSION_ID, request); + + // Then + assertEquals(confirmation, actual); + } + + @Test + public void handleRequest_whenExtendedTriggerMessageRequest_callsHandleExtendedTriggerMessageRequest() { + // Given + ExtendedTriggerMessageRequest request = mock(ExtendedTriggerMessageRequest.class); + ExtendedTriggerMessageConfirmation confirmation = mock(ExtendedTriggerMessageConfirmation.class); + when(handler.handleExtendedTriggerMessageRequest(request)).thenReturn(confirmation); + + // When + Confirmation actual = profile.handleRequest(SESSION_ID, request); + + // Then + assertEquals(confirmation, actual); + } + + @Test + public void handleRequest_whenGetInstalledCertificateIdsRequest_callsHandleGetInstalledCertificateIdsRequest() { + // Given + GetInstalledCertificateIdsRequest request = mock(GetInstalledCertificateIdsRequest.class); + GetInstalledCertificateIdsConfirmation confirmation = mock(GetInstalledCertificateIdsConfirmation.class); + when(handler.handleGetInstalledCertificateIdsRequest(request)).thenReturn(confirmation); + + // When + Confirmation actual = profile.handleRequest(SESSION_ID, request); + + // Then + assertEquals(confirmation, actual); + } + + @Test + public void handleRequest_whenGetLogRequest_callsHandleGetLogRequest() { + // Given + GetLogRequest request = mock(GetLogRequest.class); + GetLogConfirmation confirmation = mock(GetLogConfirmation.class); + when(handler.handleGetLogRequest(request)).thenReturn(confirmation); + + // When + Confirmation actual = profile.handleRequest(SESSION_ID, request); + + // Then + assertEquals(confirmation, actual); + } + + @Test + public void handleRequest_whenInstallCertificateRequest_callsHandleInstallCertificateRequest() { + // Given + InstallCertificateRequest request = mock(InstallCertificateRequest.class); + InstallCertificateConfirmation confirmation = mock(InstallCertificateConfirmation.class); + when(handler.handleInstallCertificateRequest(request)).thenReturn(confirmation); + + // When + Confirmation actual = profile.handleRequest(SESSION_ID, request); + + // Then + assertEquals(confirmation, actual); + } + + @Test + public void handleRequest_whenSignedUpdateFirmwareRequest_callsHandleSignedUpdateFirmwareRequest() { + // Given + SignedUpdateFirmwareRequest request = mock(SignedUpdateFirmwareRequest.class); + SignedUpdateFirmwareConfirmation confirmation = mock(SignedUpdateFirmwareConfirmation.class); + when(handler.handleSignedUpdateFirmwareRequest(request)).thenReturn(confirmation); + + // When + Confirmation actual = profile.handleRequest(SESSION_ID, request); + + // Then + assertEquals(confirmation, actual); + } + +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/securityext/ServerSecurityExtProfileTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/securityext/ServerSecurityExtProfileTest.java new file mode 100644 index 000000000..85e74f702 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/securityext/ServerSecurityExtProfileTest.java @@ -0,0 +1,266 @@ +package eu.chargetime.ocpp.feature.profile.test.securityext; + +import eu.chargetime.ocpp.feature.Feature; +import eu.chargetime.ocpp.feature.profile.securityext.ServerSecurityExtEventHandler; +import eu.chargetime.ocpp.feature.profile.securityext.ServerSecurityExtProfile; +import eu.chargetime.ocpp.feature.profile.test.ProfileTest; +import eu.chargetime.ocpp.feature.securityext.CertificateSignedFeature; +import eu.chargetime.ocpp.feature.securityext.DeleteCertificateFeature; +import eu.chargetime.ocpp.feature.securityext.ExtendedTriggerMessageFeature; +import eu.chargetime.ocpp.feature.securityext.GetInstalledCertificateIdsFeature; +import eu.chargetime.ocpp.feature.securityext.GetLogFeature; +import eu.chargetime.ocpp.feature.securityext.InstallCertificateFeature; +import eu.chargetime.ocpp.feature.securityext.LogStatusNotificationFeature; +import eu.chargetime.ocpp.feature.securityext.SecurityEventNotificationFeature; +import eu.chargetime.ocpp.feature.securityext.SignCertificateFeature; +import eu.chargetime.ocpp.feature.securityext.SignedFirmwareStatusNotificationFeature; +import eu.chargetime.ocpp.feature.securityext.SignedUpdateFirmwareFeature; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.securityext.CertificateSignedRequest; +import eu.chargetime.ocpp.model.securityext.DeleteCertificateRequest; +import eu.chargetime.ocpp.model.securityext.ExtendedTriggerMessageRequest; +import eu.chargetime.ocpp.model.securityext.GetInstalledCertificateIdsRequest; +import eu.chargetime.ocpp.model.securityext.GetLogRequest; +import eu.chargetime.ocpp.model.securityext.InstallCertificateRequest; +import eu.chargetime.ocpp.model.securityext.LogStatusNotificationConfirmation; +import eu.chargetime.ocpp.model.securityext.LogStatusNotificationRequest; +import eu.chargetime.ocpp.model.securityext.SecurityEventNotificationConfirmation; +import eu.chargetime.ocpp.model.securityext.SecurityEventNotificationRequest; +import eu.chargetime.ocpp.model.securityext.SignCertificateConfirmation; +import eu.chargetime.ocpp.model.securityext.SignCertificateRequest; +import eu.chargetime.ocpp.model.securityext.SignedFirmwareStatusNotificationConfirmation; +import eu.chargetime.ocpp.model.securityext.SignedFirmwareStatusNotificationRequest; +import eu.chargetime.ocpp.model.securityext.SignedUpdateFirmwareRequest; +import eu.chargetime.ocpp.model.securityext.types.CertificateHashDataType; +import eu.chargetime.ocpp.model.securityext.types.CertificateUseEnumType; +import eu.chargetime.ocpp.model.securityext.types.FirmwareType; +import eu.chargetime.ocpp.model.securityext.types.LogEnumType; +import eu.chargetime.ocpp.model.securityext.types.LogParametersType; +import eu.chargetime.ocpp.model.securityext.types.MessageTriggerEnumType; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import java.util.UUID; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +@RunWith(MockitoJUnitRunner.class) +public class ServerSecurityExtProfileTest extends ProfileTest { + private static final UUID SESSION_ID = UUID.randomUUID(); + + private ServerSecurityExtProfile profile; + + @Mock + private ServerSecurityExtEventHandler handler; + + @Before + public void setup() { + profile = new ServerSecurityExtProfile(handler); + } + + @Test + public void getFeatureList_containsAllFeature() { + // When + Feature[] features = profile.getFeatureList(); + + // then + assertTrue(findFeature(features, "CertificateSigned") instanceof CertificateSignedFeature); + assertTrue(findFeature(features, "DeleteCertificate") instanceof DeleteCertificateFeature); + assertTrue(findFeature(features, "ExtendedTriggerMessage") instanceof ExtendedTriggerMessageFeature); + assertTrue(findFeature(features, "GetInstalledCertificateIds") instanceof GetInstalledCertificateIdsFeature); + assertTrue(findFeature(features, "GetLog") instanceof GetLogFeature); + assertTrue(findFeature(features, "InstallCertificate") instanceof InstallCertificateFeature); + assertTrue(findFeature(features, "LogStatusNotification") instanceof LogStatusNotificationFeature); + assertTrue(findFeature(features, "SecurityEventNotification") instanceof SecurityEventNotificationFeature); + assertTrue(findFeature(features, "SignCertificate") instanceof SignCertificateFeature); + assertTrue(findFeature(features, "SignedFirmwareStatusNotification") instanceof SignedFirmwareStatusNotificationFeature); + assertTrue(findFeature(features, "SignedUpdateFirmware") instanceof SignedUpdateFirmwareFeature); + } + + @Test + public void createCertificateSignedRequest_withParams_returnsCompleteRequest() { + // Given + String certificateChain = "certChain"; + + // When + CertificateSignedRequest actual = profile.createCertificateSignedRequest(certificateChain); + + // Then + assertEquals(certificateChain, actual.getCertificateChain()); + } + + @Test + public void createDeleteCertificateRequest_withParams_returnsCompleteRequest() { + // Given + CertificateHashDataType certificateHashData = new CertificateHashDataType(); + + // When + DeleteCertificateRequest actual = profile.createDeleteCertificateRequest(certificateHashData); + + // Then + assertEquals(certificateHashData, actual.getCertificateHashData()); + } + + @Test + public void createExtendedTriggerMessageRequest_withParams_returnsCompleteRequest() { + // Given + MessageTriggerEnumType requestedMessage = MessageTriggerEnumType.BootNotification; + + // When + ExtendedTriggerMessageRequest actual = profile.createExtendedTriggerMessageRequest(requestedMessage); + + // Then + assertEquals(requestedMessage, actual.getRequestedMessage()); + assertNull(actual.getConnectorId()); + } + + @Test + public void createGetInstalledCertificateIdsRequest_withParams_returnsCompleteRequest() { + // Given + CertificateUseEnumType certificateType = CertificateUseEnumType.CentralSystemRootCertificate; + + // When + GetInstalledCertificateIdsRequest actual = profile.createGetInstalledCertificateIdsRequest(certificateType); + + // Then + assertEquals(certificateType, actual.getCertificateType()); + } + + @Test + public void createGetLogRequest_withParams_returnsCompleteRequest() { + // Given + LogEnumType logType = LogEnumType.SecurityLog; + Integer requestId = 123; + LogParametersType log = new LogParametersType(); + + // When + GetLogRequest actual = profile.createGetLogRequest(logType, requestId, log); + + // Then + assertEquals(logType, actual.getLogType()); + assertEquals(requestId, actual.getRequestId()); + assertNull(actual.getRetries()); + assertNull(actual.getRetryInterval()); + assertEquals(log, actual.getLog()); + } + + @Test + public void createInstallCertificateRequest_withParams_returnsCompleteRequest() { + // Given + CertificateUseEnumType certificateType = CertificateUseEnumType.CentralSystemRootCertificate; + String certificate = "certificate"; + + // When + InstallCertificateRequest actual = profile.createInstallCertificateRequest(certificateType, certificate); + + // Then + assertEquals(certificateType, actual.getCertificateType()); + assertEquals(certificate, actual.getCertificate()); + } + + @Test + public void createSignedUpdateFirmwareRequest_withParams_returnsCompleteRequest() { + // Given + Integer requestId = 123; + FirmwareType firmware = new FirmwareType(); + + // When + SignedUpdateFirmwareRequest actual = profile.createSignedUpdateFirmwareRequest(requestId, firmware); + + // Then + assertNull(actual.getRetries()); + assertNull(actual.getRetryInterval()); + assertEquals(requestId, actual.getRequestId()); + assertEquals(firmware, actual.getFirmware()); + } + + @Test + public void handleRequest_whenLogStatusNotificationRequest_callsHandleLogStatusNotificationRequest() { + // Given + LogStatusNotificationRequest request = mock(LogStatusNotificationRequest.class); + LogStatusNotificationConfirmation confirmation = mock(LogStatusNotificationConfirmation.class); + when(handler.handleLogStatusNotificationRequest(SESSION_ID, request)).thenReturn(confirmation); + + // When + Confirmation actual = profile.handleRequest(SESSION_ID, request); + + // Then + assertEquals(confirmation, actual); + } + + @Test + public void handleRequest_whenSecurityEventNotificationRequest_callsHandleSecurityEventNotificationRequest() { + // Given + SecurityEventNotificationRequest request = mock(SecurityEventNotificationRequest.class); + SecurityEventNotificationConfirmation confirmation = mock(SecurityEventNotificationConfirmation.class); + when(handler.handleSecurityEventNotificationRequest(SESSION_ID, request)).thenReturn(confirmation); + + // When + Confirmation actual = profile.handleRequest(SESSION_ID, request); + + // Then + assertEquals(confirmation, actual); + } + + @Test + public void handleRequest_whenSignCertificateRequest_callsSignCertificateRequest() { + // Given + SignCertificateRequest request = mock(SignCertificateRequest.class); + SignCertificateConfirmation confirmation = mock(SignCertificateConfirmation.class); + when(handler.handleSignCertificateRequest(SESSION_ID, request)).thenReturn(confirmation); + + // When + Confirmation actual = profile.handleRequest(SESSION_ID, request); + + // Then + assertEquals(confirmation, actual); + } + + @Test + public void handleRequest_whenSignedFirmwareStatusNotificationRequest_callsHandleSignedFirmwareStatusNotificationRequest() { + // Given + SignedFirmwareStatusNotificationRequest request = mock(SignedFirmwareStatusNotificationRequest.class); + SignedFirmwareStatusNotificationConfirmation confirmation = mock(SignedFirmwareStatusNotificationConfirmation.class); + when(handler.handleSignedFirmwareStatusNotificationRequest(SESSION_ID, request)).thenReturn(confirmation); + + // When + Confirmation actual = profile.handleRequest(SESSION_ID, request); + + // Then + assertEquals(confirmation, actual); + } + +} From d9ef87d44b86122ff307e366b9b448126eaa2ec5 Mon Sep 17 00:00:00 2001 From: Mathias Oben Date: Wed, 15 Jun 2022 16:04:02 +0200 Subject: [PATCH 6/9] Fix javadoc symbol --- .../ocpp/model/securityext/ExtendedTriggerMessageRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageRequest.java index 3ca3f4c44..0b1eb31c6 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageRequest.java @@ -68,7 +68,7 @@ public void setRequestedMessage(MessageTriggerEnumType requestedMessage) { /** * Only filled in when request applies to a specific connector. * - * @return Integer connectorId > 0 + * @return Integer connectorId > 0 */ public Integer getConnectorId() { return connectorId; From ae0246872144fdebaa5fb7f6e0b1913d86890ee9 Mon Sep 17 00:00:00 2001 From: Mathias Oben Date: Wed, 22 Jun 2022 15:38:44 +0200 Subject: [PATCH 7/9] Add private constructors for serialization and validation fixes --- .../model/securityext/CertificateSignedConfirmation.java | 6 ++++++ .../ocpp/model/securityext/CertificateSignedRequest.java | 6 ++++++ .../model/securityext/DeleteCertificateConfirmation.java | 6 ++++++ .../ocpp/model/securityext/DeleteCertificateRequest.java | 6 ++++++ .../securityext/ExtendedTriggerMessageConfirmation.java | 6 ++++++ .../model/securityext/ExtendedTriggerMessageRequest.java | 6 ++++++ .../securityext/GetInstalledCertificateIdsConfirmation.java | 6 ++++++ .../securityext/GetInstalledCertificateIdsRequest.java | 6 ++++++ .../ocpp/model/securityext/GetLogConfirmation.java | 6 ++++++ .../eu/chargetime/ocpp/model/securityext/GetLogRequest.java | 6 ++++++ .../model/securityext/InstallCertificateConfirmation.java | 6 ++++++ .../ocpp/model/securityext/InstallCertificateRequest.java | 6 ++++++ .../model/securityext/LogStatusNotificationRequest.java | 6 ++++++ .../model/securityext/SecurityEventNotificationRequest.java | 6 ++++++ .../ocpp/model/securityext/SignCertificateConfirmation.java | 6 ++++++ .../ocpp/model/securityext/SignCertificateRequest.java | 6 ++++++ .../SignedFirmwareStatusNotificationRequest.java | 6 ++++++ .../model/securityext/SignedUpdateFirmwareConfirmation.java | 6 ++++++ .../ocpp/model/securityext/SignedUpdateFirmwareRequest.java | 6 ++++++ .../model/securityext/types/CertificateHashDataType.java | 2 +- .../ocpp/model/securityext/types/FirmwareType.java | 2 +- .../ocpp/model/securityext/types/LogParametersType.java | 1 - 22 files changed, 116 insertions(+), 3 deletions(-) diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedConfirmation.java index 4403ad513..9b4b8f83a 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedConfirmation.java @@ -36,6 +36,12 @@ public class CertificateSignedConfirmation implements Confirmation { private CertificateSignedStatusEnumType status; + /** + * Private default constructor for serialization purposes. + */ + private CertificateSignedConfirmation() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedRequest.java index 44fcc720d..9b3ca7b5b 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/CertificateSignedRequest.java @@ -44,6 +44,12 @@ public class CertificateSignedRequest implements Request { private String certificateChain; + /** + * Private default constructor for serialization purposes. + */ + private CertificateSignedRequest() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateConfirmation.java index 55f91ef15..d7d72ba3d 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateConfirmation.java @@ -36,6 +36,12 @@ public class DeleteCertificateConfirmation implements Confirmation { private DeleteCertificateStatusEnumType status; + /** + * Private default constructor for serialization purposes. + */ + private DeleteCertificateConfirmation() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateRequest.java index 0dfea4e0b..ea0ad879e 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/DeleteCertificateRequest.java @@ -36,6 +36,12 @@ public class DeleteCertificateRequest implements Request { private CertificateHashDataType certificateHashData; + /** + * Private default constructor for serialization purposes. + */ + private DeleteCertificateRequest() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageConfirmation.java index 4b510fc5f..a3ff629e0 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageConfirmation.java @@ -36,6 +36,12 @@ public class ExtendedTriggerMessageConfirmation implements Confirmation { private TriggerMessageStatusEnumType status; + /** + * Private default constructor for serialization purposes. + */ + private ExtendedTriggerMessageConfirmation() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageRequest.java index 0b1eb31c6..247b757b2 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/ExtendedTriggerMessageRequest.java @@ -38,6 +38,12 @@ public class ExtendedTriggerMessageRequest implements Request { private MessageTriggerEnumType requestedMessage; private Integer connectorId; + /** + * Private default constructor for serialization purposes. + */ + private ExtendedTriggerMessageRequest() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsConfirmation.java index 602c01e6c..260d60636 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsConfirmation.java @@ -39,6 +39,12 @@ public class GetInstalledCertificateIdsConfirmation implements Confirmation { private GetInstalledCertificateStatusEnumType status; private CertificateHashDataType[] certificateHashData; + /** + * Private default constructor for serialization purposes. + */ + private GetInstalledCertificateIdsConfirmation() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsRequest.java index c6dd2e2ae..762fb43b6 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetInstalledCertificateIdsRequest.java @@ -36,6 +36,12 @@ public class GetInstalledCertificateIdsRequest implements Request { private CertificateUseEnumType certificateType; + /** + * Private default constructor for serialization purposes. + */ + private GetInstalledCertificateIdsRequest() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogConfirmation.java index 9702f2ff9..d8423569a 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogConfirmation.java @@ -45,6 +45,12 @@ public class GetLogConfirmation implements Confirmation { private LogStatusEnumType status; private String filename; + /** + * Private default constructor for serialization purposes. + */ + private GetLogConfirmation() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogRequest.java index 12518079d..638ba43eb 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/GetLogRequest.java @@ -41,6 +41,12 @@ public class GetLogRequest implements Request { private Integer retryInterval; private LogParametersType log; + /** + * Private default constructor for serialization purposes. + */ + private GetLogRequest() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateConfirmation.java index eb8749bac..d1ef0e755 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateConfirmation.java @@ -36,6 +36,12 @@ public class InstallCertificateConfirmation implements Confirmation { private CertificateStatusEnumType status; + /** + * Private default constructor for serialization purposes. + */ + private InstallCertificateConfirmation() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateRequest.java index 2b6074163..884f6b43b 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/InstallCertificateRequest.java @@ -46,6 +46,12 @@ public class InstallCertificateRequest implements Request { private CertificateUseEnumType certificateType; private String certificate; + /** + * Private default constructor for serialization purposes. + */ + private InstallCertificateRequest() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/LogStatusNotificationRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/LogStatusNotificationRequest.java index c65709ce5..852196a05 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/LogStatusNotificationRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/LogStatusNotificationRequest.java @@ -37,6 +37,12 @@ public class LogStatusNotificationRequest implements Request { private UploadLogStatusEnumType status; private Integer requestId; + /** + * Private default constructor for serialization purposes. + */ + private LogStatusNotificationRequest() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationRequest.java index 7407550f3..b61a62e51 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SecurityEventNotificationRequest.java @@ -52,6 +52,12 @@ public class SecurityEventNotificationRequest implements Request { private ZonedDateTime timestamp; private String techInfo; + /** + * Private default constructor for serialization purposes. + */ + private SecurityEventNotificationRequest() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateConfirmation.java index eb7aa1f5b..679d8be37 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateConfirmation.java @@ -36,6 +36,12 @@ public class SignCertificateConfirmation implements Confirmation { private GenericStatusEnumType status; + /** + * Private default constructor for serialization purposes. + */ + private SignCertificateConfirmation() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateRequest.java index ad34ea98a..f623a4087 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignCertificateRequest.java @@ -44,6 +44,12 @@ public class SignCertificateRequest implements Request { private String csr; + /** + * Private default constructor for serialization purposes. + */ + private SignCertificateRequest() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedFirmwareStatusNotificationRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedFirmwareStatusNotificationRequest.java index 0fb647a0e..471536fb9 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedFirmwareStatusNotificationRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedFirmwareStatusNotificationRequest.java @@ -38,6 +38,12 @@ public class SignedFirmwareStatusNotificationRequest implements Request { private FirmwareStatusEnumType status; private Integer requestId; + /** + * Private default constructor for serialization purposes. + */ + private SignedFirmwareStatusNotificationRequest() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareConfirmation.java index c38cafacf..ea1f8cbe6 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareConfirmation.java @@ -36,6 +36,12 @@ public class SignedUpdateFirmwareConfirmation implements Confirmation { private UpdateFirmwareStatusEnumType status; + /** + * Private default constructor for serialization purposes. + */ + private SignedUpdateFirmwareConfirmation() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareRequest.java index 4319cae8f..52cc35776 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/SignedUpdateFirmwareRequest.java @@ -39,6 +39,12 @@ public class SignedUpdateFirmwareRequest implements Request { private Integer requestId; private FirmwareType firmware; + /** + * Private default constructor for serialization purposes. + */ + private SignedUpdateFirmwareRequest() { + } + /** * Handle required fields. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateHashDataType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateHashDataType.java index 8ef15f774..4df302bca 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateHashDataType.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/CertificateHashDataType.java @@ -113,7 +113,7 @@ public void setIssuerKeyHash(String issuerKeyHash) { /** * The serial number of the certificate. * - * @return identifierString[0..128] + * @return string[0..40] */ public String getSerialNumber() { return serialNumber; diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/FirmwareType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/FirmwareType.java index 5f1b09163..129e1d2e1 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/FirmwareType.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/FirmwareType.java @@ -136,7 +136,7 @@ public String getSigningCertificate() { * @param signingCertificate string[0..5500] */ public void setSigningCertificate(String signingCertificate) { - signatureValidator.validate(signingCertificate); + signingCertificateValidator.validate(signingCertificate); this.signingCertificate = signingCertificate; } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogParametersType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogParametersType.java index db8d116ec..179e3fdd3 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogParametersType.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/securityext/types/LogParametersType.java @@ -38,7 +38,6 @@ of this software and associated documentation files (the "Software"), to deal public class LogParametersType implements Validatable { private static final transient Validator remoteLocationValidator = new ValidatorBuilder() - .addRule(OCPPSecurityExtDatatypes.identifierString()) .addRule(OCPPSecurityExtDatatypes.string512()) .setRequired(true) .build(); From ec79d0500526edc03b4a69375c2d760500636eab Mon Sep 17 00:00:00 2001 From: Mathias Oben Date: Wed, 22 Jun 2022 15:39:32 +0200 Subject: [PATCH 8/9] Add tests for maximum length strings --- .../test/CertificateSignedRequestTest.java | 11 +++++ .../test/GetLogConfirmationTest.java | 13 ++++++ .../test/InstallCertificateRequestTest.java | 14 ++++++- .../SecurityEventNotificationRequestTest.java | 26 ++++++++++++ .../test/SignCertificateRequestTest.java | 11 +++++ .../types/CertificateHashDataTypeTest.java | 12 ++++++ .../test/types/FirmwareTypeTest.java | 40 ++++++++++++++++++- .../test/types/LogParametersTypeTest.java | 12 ++++++ 8 files changed, 135 insertions(+), 4 deletions(-) diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/CertificateSignedRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/CertificateSignedRequestTest.java index 47e231d94..7991d9d12 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/CertificateSignedRequestTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/CertificateSignedRequestTest.java @@ -56,6 +56,17 @@ public void constructor_nullCertificateChain_throwsPropertyConstraintException() // Then throws } + @Test + public void setCertificateChain_maximumLengthString_nothingThrown() { + // Given + String certificateChain = TestUtilities.aString(10000); + + // When + new CertificateSignedRequest(certificateChain); + + // Then nothing thrown + } + @Test(expected = PropertyConstraintException.class) public void setCertificateChain_exceedingLengthString_throwsPropertyConstraintException() { // Given diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetLogConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetLogConfirmationTest.java index fe647d013..cb41e1b4c 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetLogConfirmationTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetLogConfirmationTest.java @@ -28,6 +28,7 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.securityext.GetLogConfirmation; +import eu.chargetime.ocpp.model.securityext.types.CertificateHashDataType; import eu.chargetime.ocpp.model.securityext.types.LogStatusEnumType; import eu.chargetime.ocpp.utilities.TestUtilities; import org.junit.Test; @@ -92,6 +93,18 @@ public void validate_setRequiredAndOptional_returnsTrue() { assertTrue(actual); } + @Test + public void setFilename_maximumLengthString_nothingThrown() { + // Given + String filename = TestUtilities.aString(255); + GetLogConfirmation confirmation = new GetLogConfirmation(null); + + // When + confirmation.setFilename(filename); + + // Then nothing thrown + } + @Test(expected = PropertyConstraintException.class) public void setFilename_exceedingLengthString_throwsPropertyConstraintException() { // Given diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/InstallCertificateRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/InstallCertificateRequestTest.java index 11c18faa2..5d009e7aa 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/InstallCertificateRequestTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/InstallCertificateRequestTest.java @@ -61,14 +61,24 @@ public void constructor_nullCertificate_throwsPropertyConstraintException() { // Then throws } + @Test + public void setCertificate_maximumLengthString_nothingThrown() { + // Given + String certificate = TestUtilities.aString(5500); + + // When + new InstallCertificateRequest(null, certificate); + + // Then nothing thrown + } + @Test(expected = PropertyConstraintException.class) public void setCertificate_exceedingLengthString_throwsPropertyConstraintException() { // Given String certificate = TestUtilities.aString(5501); - InstallCertificateRequest request = new InstallCertificateRequest(null, null); // When - request.setCertificate(certificate); + new InstallCertificateRequest(null, certificate); // Then throws } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SecurityEventNotificationRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SecurityEventNotificationRequestTest.java index 30637accb..bfbf729d4 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SecurityEventNotificationRequestTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SecurityEventNotificationRequestTest.java @@ -76,6 +76,18 @@ public void validate_returnFalse() { assertFalse(actual); } + @Test + public void setType_maximumLengthString_nothingThrown() { + // Given + String type = TestUtilities.aString(50); + ZonedDateTime timestamp = ZonedDateTime.now(); + + // When + new SecurityEventNotificationRequest(type, timestamp); + + // Then nothing thrown + } + @Test(expected = PropertyConstraintException.class) public void setType_exceedingLengthString_throwsPropertyConstraintException() { // Given @@ -88,6 +100,20 @@ public void setType_exceedingLengthString_throwsPropertyConstraintException() { // Then throws } + @Test + public void setTechInfo_maximumLengthString_nothingThrown() { + // Given + String type = givenType(); + ZonedDateTime timestamp = ZonedDateTime.now(); + String techInfo = TestUtilities.aString(255); + SecurityEventNotificationRequest request = new SecurityEventNotificationRequest(type, timestamp); + + // When + request.setTechInfo(techInfo); + + // Then nothing thrown + } + @Test(expected = PropertyConstraintException.class) public void setTechInfo_exceedingLengthString_throwsPropertyConstraintException() { // Given diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignCertificateRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignCertificateRequestTest.java index 0cd0d72b3..76138faf8 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignCertificateRequestTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignCertificateRequestTest.java @@ -56,6 +56,17 @@ public void constructor_nullCsr_throwsPropertyConstraintException() { // Then throws } + @Test + public void setType_maximumLengthString_nothingThrown() { + // Given + String csr = TestUtilities.aString(5500); + + // When + new SignCertificateRequest(csr); + + // Then nothing thrown + } + @Test(expected = PropertyConstraintException.class) public void setCsr_exceedingLengthString_throwsPropertyConstraintException() { // Given diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/CertificateHashDataTypeTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/CertificateHashDataTypeTest.java index e39724fe9..7ef89f0c9 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/CertificateHashDataTypeTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/CertificateHashDataTypeTest.java @@ -94,6 +94,18 @@ public void setIssuerKeyHash_nonIdentifierString_throwsPropertyConstraintExcepti // Then throws } + @Test + public void setSerialNumber_maximumLengthString_nothingThrown() { + // Given + String serialNumber = TestUtilities.aString(40); + CertificateHashDataType dataType = new CertificateHashDataType(); + + // When + dataType.setSerialNumber(serialNumber); + + // Then nothing thrown + } + @Test(expected = PropertyConstraintException.class) public void setSerialNumber_exceedingLengthString_throwsPropertyConstraintException() { // Given diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/FirmwareTypeTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/FirmwareTypeTest.java index d6e940fbe..0e675c5c9 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/FirmwareTypeTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/FirmwareTypeTest.java @@ -71,6 +71,18 @@ public void validate_setRequired_returnsTrue() { assertTrue(actual); } + @Test + public void setLocation_maximumLengthString_nothingThrown() { + // Given + String location = TestUtilities.aString(512); + FirmwareType type = new FirmwareType(); + + // When + type.setLocation(location); + + // Then nothing thrown + } + @Test(expected = PropertyConstraintException.class) public void setLocation_exceedingLengthString_throwsPropertyConstraintException() { // Given @@ -83,6 +95,18 @@ public void setLocation_exceedingLengthString_throwsPropertyConstraintException( // Then throws } + @Test + public void setSigningCertificate_maximumLengthString_nothingThrown() { + // Given + String signingCertificate = TestUtilities.aString(5500); + FirmwareType type = new FirmwareType(); + + // When + type.setSigningCertificate(signingCertificate); + + // Then nothing thrown + } + @Test(expected = PropertyConstraintException.class) public void setSigningCertificate_exceedingLengthString_throwsPropertyConstraintException() { // Given @@ -95,6 +119,18 @@ public void setSigningCertificate_exceedingLengthString_throwsPropertyConstraint // Then throws } + @Test + public void setSignature_maximumLengthString_nothingThrown() { + // Given + String signature = TestUtilities.aString(800); + FirmwareType type = new FirmwareType(); + + // When + type.setSignature(signature); + + // Then nothing thrown + } + @Test(expected = PropertyConstraintException.class) public void setSignature_exceedingLengthString_throwsPropertyConstraintException() { // Given @@ -108,11 +144,11 @@ public void setSignature_exceedingLengthString_throwsPropertyConstraintException } private String givenSigningCertificate() { - return "an-identifier-string"; + return "PEM encoded X.509 certificate"; } private String givenSignature() { - return "PEM encoded X.509 certificate"; + return "Base64 encoded firmware signature"; } private String givenLocation() { diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/LogParametersTypeTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/LogParametersTypeTest.java index d51e9f919..90c056dfb 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/LogParametersTypeTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/LogParametersTypeTest.java @@ -84,6 +84,18 @@ public void validate_setRequiredAndOptional_returnsTrue() { assertTrue(actual); } + @Test + public void setLocation_maximumLengthString_nothingThrown() { + // Given + String location = TestUtilities.aString(512); + LogParametersType type = new LogParametersType(); + + // When + type.setRemoteLocation(location); + + // Then nothing thrown + } + @Test(expected = PropertyConstraintException.class) public void setLocation_exceedingLengthString_throwsPropertyConstraintException() { // Given From ce6bad7931bb44592bb372d72d7db19fdc461f67 Mon Sep 17 00:00:00 2001 From: Mathias Oben Date: Wed, 22 Jun 2022 15:40:52 +0200 Subject: [PATCH 9/9] Add integration tests --- .../chargetime/ocpp/test/DummyHandlers.java | 48 +++++++- .../ocpp/test/FakeCentralSystem.java | 114 ++++++++++++++++- .../chargetime/ocpp/test/FakeChargePoint.java | 116 ++++++++++++++++++ .../json/JSONCertificateSignedSpec.groovy | 50 ++++++++ .../json/JSONDeleteCertificateSpec.groovy | 59 +++++++++ .../JSONExtendedTriggerMessageSpec.groovy | 51 ++++++++ .../JSONGetInstalledCertificateIdsSpec.groovy | 51 ++++++++ .../securityext/json/JSONGetLogSpec.groovy | 56 +++++++++ .../json/JSONInstallCertificateSpec.groovy | 54 ++++++++ .../json/JSONLogStatusNotificationSpec.groovy | 51 ++++++++ .../JSONSecurityEventNotificationSpec.groovy | 52 ++++++++ .../json/JSONSignCertificateSpec.groovy | 50 ++++++++ ...ignedFirmwareStatusNotificationSpec.groovy | 51 ++++++++ .../json/JSONSignedUpdateFirmwareSpec.groovy | 60 +++++++++ 14 files changed, 851 insertions(+), 12 deletions(-) create mode 100644 ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONCertificateSignedSpec.groovy create mode 100644 ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONDeleteCertificateSpec.groovy create mode 100644 ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONExtendedTriggerMessageSpec.groovy create mode 100644 ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONGetInstalledCertificateIdsSpec.groovy create mode 100644 ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONGetLogSpec.groovy create mode 100644 ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONInstallCertificateSpec.groovy create mode 100644 ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONLogStatusNotificationSpec.groovy create mode 100644 ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONSecurityEventNotificationSpec.groovy create mode 100644 ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONSignCertificateSpec.groovy create mode 100644 ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONSignedFirmwareStatusNotificationSpec.groovy create mode 100644 ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONSignedUpdateFirmwareSpec.groovy diff --git a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/DummyHandlers.java b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/DummyHandlers.java index fa7c9a285..f9586f96c 100644 --- a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/DummyHandlers.java +++ b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/DummyHandlers.java @@ -6,6 +6,7 @@ Copyright (C) 2016-2018 Thomas Volden Copyright (C) 2019 Kevin Raddatz + Copyright (C) 2022 Mathias Oben Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -29,6 +30,7 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.ServerEvents; import eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler; import eu.chargetime.ocpp.feature.profile.ServerFirmwareManagementEventHandler; +import eu.chargetime.ocpp.feature.profile.securityext.ServerSecurityExtEventHandler; import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.model.SessionInformation; @@ -37,6 +39,9 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest; import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationConfirmation; import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationRequest; +import eu.chargetime.ocpp.model.securityext.*; +import eu.chargetime.ocpp.model.securityext.types.GenericStatusEnumType; + import java.lang.reflect.Type; import java.time.ZonedDateTime; import java.util.UUID; @@ -160,6 +165,39 @@ public FirmwareStatusNotificationConfirmation handleFirmwareStatusNotificationRe }; } + public ServerSecurityExtEventHandler createServerSecurityExtEventHandler() { + return new ServerSecurityExtEventHandler() { + + @Override + public LogStatusNotificationConfirmation handleLogStatusNotificationRequest(UUID sessionIndex, LogStatusNotificationRequest request) { + receivedRequest = request; + LogStatusNotificationConfirmation confirmation = new LogStatusNotificationConfirmation(); + return failurePoint(confirmation); + } + + @Override + public SecurityEventNotificationConfirmation handleSecurityEventNotificationRequest(UUID sessionIndex, SecurityEventNotificationRequest request) { + receivedRequest = request; + SecurityEventNotificationConfirmation confirmation = new SecurityEventNotificationConfirmation(); + return failurePoint(confirmation); + } + + @Override + public SignCertificateConfirmation handleSignCertificateRequest(UUID sessionIndex, SignCertificateRequest request) { + receivedRequest = request; + SignCertificateConfirmation confirmation = new SignCertificateConfirmation(GenericStatusEnumType.Accepted); + return failurePoint(confirmation); + } + + @Override + public SignedFirmwareStatusNotificationConfirmation handleSignedFirmwareStatusNotificationRequest(UUID sessionIndex, SignedFirmwareStatusNotificationRequest request) { + receivedRequest = request; + SignedFirmwareStatusNotificationConfirmation confirmation = new SignedFirmwareStatusNotificationConfirmation(); + return failurePoint(confirmation); + } + }; + } + public ServerEvents generateServerEventsHandler() { return new ServerEvents() { @Override @@ -201,9 +239,8 @@ public boolean wasLatestRequest(Type requestType) { && requestType.equals(receivedRequest.getClass()); } - public T getReceivedRequest(T requestType) { - if (wasLatestRequest(requestType.getClass())) return (T) receivedRequest; - return null; + public T getReceivedRequest(Class clazz) { + return wasLatestRequest(clazz) ? (T) receivedRequest : null; } public boolean wasLatestConfirmation(Type confirmationType) { @@ -212,9 +249,8 @@ public boolean wasLatestConfirmation(Type confirmationType) { && confirmationType.equals(receivedConfirmation.getClass()); } - public T getReceivedConfirmation(T confirmationType) { - if (wasLatestConfirmation(confirmationType.getClass())) return (T) receivedConfirmation; - return null; + public T getReceivedConfirmation(Class clazz) { + return wasLatestConfirmation(clazz) ? (T) receivedConfirmation : null; } public void setRiggedToFail(boolean riggedToFail) { diff --git a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeCentralSystem.java b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeCentralSystem.java index f55429236..6db5b0183 100644 --- a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeCentralSystem.java +++ b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeCentralSystem.java @@ -7,6 +7,7 @@ Copyright (C) 2016-2018 Thomas Volden Copyright (C) 2019 Kevin Raddatz +Copyright (C) 2022 Mathias Oben Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -31,6 +32,7 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.JSONConfiguration; import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.feature.profile.*; +import eu.chargetime.ocpp.feature.profile.securityext.ServerSecurityExtProfile; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.model.core.*; import eu.chargetime.ocpp.model.firmware.*; @@ -41,6 +43,8 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.reservation.CancelReservationRequest; import eu.chargetime.ocpp.model.reservation.ReserveNowConfirmation; import eu.chargetime.ocpp.model.reservation.ReserveNowRequest; +import eu.chargetime.ocpp.model.securityext.*; +import eu.chargetime.ocpp.model.securityext.types.*; import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileConfirmation; import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileRequest; import eu.chargetime.ocpp.test.FakeCentral.serverType; @@ -91,6 +95,11 @@ private void initializeServer() { ServerReservationProfile serverReservationProfile = new ServerReservationProfile(); server.addFeatureProfile(serverReservationProfile); + + ServerSecurityExtProfile serverSecurityExtProfile = new ServerSecurityExtProfile( + dummyHandlers.createServerSecurityExtEventHandler() + ); + server.addFeatureProfile(serverSecurityExtProfile); } public boolean isClosed() { @@ -141,7 +150,7 @@ public boolean hasHandledAuthorizeRequest() { public boolean hasHandledBootNotification(String vendor, String model) { boolean result = false; BootNotificationRequest request = - dummyHandlers.getReceivedRequest(new BootNotificationRequest()); + dummyHandlers.getReceivedRequest(BootNotificationRequest.class); if (request != null) { result = request.getChargePointVendor().equals(vendor); result &= request.getChargePointModel().equals(model); @@ -188,7 +197,7 @@ public boolean hasReceivedSetChargingProfileConfirmation() { public boolean hasReceivedChangeAvailabilityConfirmation(String status) { boolean result = false; ChangeAvailabilityConfirmation confirmation = - dummyHandlers.getReceivedConfirmation(new ChangeAvailabilityConfirmation()); + dummyHandlers.getReceivedConfirmation(ChangeAvailabilityConfirmation.class); if (confirmation != null) result = confirmation.getStatus().toString().equals(status); return result; } @@ -279,7 +288,7 @@ public void sendRemoteStartTransactionWithProfileRequest(int connectorId, String public boolean hasReceivedRemoteStartTransactionConfirmation(String status) { boolean result = false; RemoteStartTransactionConfirmation confirmation = - dummyHandlers.getReceivedConfirmation(new RemoteStartTransactionConfirmation()); + dummyHandlers.getReceivedConfirmation(RemoteStartTransactionConfirmation.class); if (confirmation != null) result = confirmation.getStatus().toString().equals(status); return result; } @@ -293,7 +302,7 @@ public void sendRemoteStopTransactionRequest(int transactionId) throws Exception public boolean hasReceivedRemoteStopTransactionConfirmation(String status) { boolean result = false; RemoteStopTransactionConfirmation confirmation = - dummyHandlers.getReceivedConfirmation(new RemoteStopTransactionConfirmation()); + dummyHandlers.getReceivedConfirmation(RemoteStopTransactionConfirmation.class); if (confirmation != null) result = confirmation.getStatus().toString().equals(status); return result; } @@ -348,7 +357,7 @@ public void sendSetChargingProfileRequest(Integer connectorId, ChargingProfile c public boolean hasReceivedResetConfirmation(String status) { boolean result = false; - ResetConfirmation confirmation = dummyHandlers.getReceivedConfirmation(new ResetConfirmation()); + ResetConfirmation confirmation = dummyHandlers.getReceivedConfirmation(ResetConfirmation.class); if (confirmation != null) result = confirmation.getStatus().toString().equals(status); return result; } @@ -374,11 +383,104 @@ public void sendUnlockConnectorRequest(int connectorId) throws Exception { public boolean hasReceivedUnlockConnectorConfirmation(String status) { boolean result = false; UnlockConnectorConfirmation confirmation = - dummyHandlers.getReceivedConfirmation(new UnlockConnectorConfirmation()); + dummyHandlers.getReceivedConfirmation(UnlockConnectorConfirmation.class); if (confirmation != null) result = confirmation.getStatus().toString().equals(status); return result; } + public void sendCertificateSignedRequest(String certificateChain) throws Exception { + Request request = new CertificateSignedRequest(certificateChain); + send(request); + } + + public boolean hasReceivedCertificateSignedConfirmation(String status) { + CertificateSignedConfirmation confirmation = + dummyHandlers.getReceivedConfirmation(CertificateSignedConfirmation.class); + return confirmation != null && confirmation.getStatus().toString().equals(status); + } + + public void sendDeleteCertificateRequest(CertificateHashDataType certificateHashDataType) throws Exception { + Request request = new DeleteCertificateRequest(certificateHashDataType); + send(request); + } + + public boolean hasReceivedDeleteCertificateConfirmation(String status) { + DeleteCertificateConfirmation confirmation = + dummyHandlers.getReceivedConfirmation(DeleteCertificateConfirmation.class); + return confirmation != null && confirmation.getStatus().toString().equals(status); + } + + public void sendExtendedTriggerMessageRequest(MessageTriggerEnumType requestedMessage) throws Exception { + Request request = new ExtendedTriggerMessageRequest(requestedMessage); + send(request); + } + + public boolean hasReceivedExtendedTriggerMessageConfirmation(String status) { + ExtendedTriggerMessageConfirmation confirmation = + dummyHandlers.getReceivedConfirmation(ExtendedTriggerMessageConfirmation.class); + return confirmation != null && confirmation.getStatus().toString().equals(status); + } + + public void sendGetInstalledCertificateIdsRequest(CertificateUseEnumType certificateType) throws Exception { + Request request = new GetInstalledCertificateIdsRequest(certificateType); + send(request); + } + + public boolean hasReceivedGetInstalledCertificateIdsConfirmation(String status) { + GetInstalledCertificateIdsConfirmation confirmation = + dummyHandlers.getReceivedConfirmation(GetInstalledCertificateIdsConfirmation.class); + return confirmation != null && confirmation.getStatus().toString().equals(status); + } + + public void sendGetLogRequest(LogEnumType logType, Integer requestId, LogParametersType log) throws Exception { + Request request = new GetLogRequest(logType, requestId, log); + send(request); + } + + public boolean hasReceivedGetLogConfirmation(String status) { + GetLogConfirmation confirmation = + dummyHandlers.getReceivedConfirmation(GetLogConfirmation.class); + return confirmation != null && confirmation.getStatus().toString().equals(status); + } + + public void sendInstallCertificateRequest(CertificateUseEnumType certificateType, String certificate) throws Exception { + Request request = new InstallCertificateRequest(certificateType, certificate); + send(request); + } + + public boolean hasReceivedInstallCertificateConfirmation(String status) { + InstallCertificateConfirmation confirmation = + dummyHandlers.getReceivedConfirmation(InstallCertificateConfirmation.class); + return confirmation != null && confirmation.getStatus().toString().equals(status); + } + + public boolean hasHandledLogStatusNotificationRequest() { + return dummyHandlers.wasLatestRequest(LogStatusNotificationRequest.class); + } + + public boolean hasHandledSecurityEventNotificationRequest() { + return dummyHandlers.wasLatestRequest(SecurityEventNotificationRequest.class); + } + + public boolean hasHandledSignCertificateRequest() { + return dummyHandlers.wasLatestRequest(SignCertificateRequest.class); + } + + public boolean hasHandledSignedFirmwareStatusNotificationRequest() { + return dummyHandlers.wasLatestRequest(SignedFirmwareStatusNotificationRequest.class); + } + + public void sendSignedUpdateFirmwareRequest(Integer requestId, FirmwareType firmware) throws Exception { + Request request = new SignedUpdateFirmwareRequest(requestId, firmware); + send(request); + } + + public boolean hasReceivedSignedUpdateFirmwareConfirmation(String status) { + SignedUpdateFirmwareConfirmation confirmation = + dummyHandlers.getReceivedConfirmation(SignedUpdateFirmwareConfirmation.class); + return confirmation != null && confirmation.getStatus().toString().equals(status); + } + public void rigNextRequestToFail() { dummyHandlers.setRiggedToFail(true); } diff --git a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeChargePoint.java b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeChargePoint.java index cbada0592..7030e9941 100644 --- a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeChargePoint.java +++ b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeChargePoint.java @@ -8,6 +8,7 @@ Copyright (C) 2016-2018 Thomas Volden Copyright (C) 2019 Kevin Raddatz +Copyright (C) 2022 Mathias Oben Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -30,6 +31,8 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.*; import eu.chargetime.ocpp.feature.profile.*; +import eu.chargetime.ocpp.feature.profile.securityext.ClientSecurityExtEventHandler; +import eu.chargetime.ocpp.feature.profile.securityext.ClientSecurityExtProfile; import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.model.core.*; @@ -39,6 +42,8 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest; import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageStatus; import eu.chargetime.ocpp.model.reservation.*; +import eu.chargetime.ocpp.model.securityext.*; +import eu.chargetime.ocpp.model.securityext.types.*; import eu.chargetime.ocpp.model.smartcharging.*; import java.net.MalformedURLException; import java.net.URL; @@ -51,6 +56,7 @@ public class FakeChargePoint { private final ClientFirmwareManagementProfile firmware; private final ClientLocalAuthListProfile localAuthList; private final ClientReservationProfile reservation; + private final ClientSecurityExtProfile securityExt; private IClientAPI client; private Confirmation receivedConfirmation; private Request receivedRequest; @@ -223,6 +229,51 @@ public CancelReservationConfirmation handleCancelReservationRequest( } }); + securityExt = + new ClientSecurityExtProfile(new ClientSecurityExtEventHandler() { + @Override + public CertificateSignedConfirmation handleCertificateSignedRequest(CertificateSignedRequest request) { + receivedRequest = request; + return new CertificateSignedConfirmation(CertificateSignedStatusEnumType.Accepted); + } + + @Override + public DeleteCertificateConfirmation handleDeleteCertificateRequest(DeleteCertificateRequest request) { + receivedRequest = request; + return new DeleteCertificateConfirmation(DeleteCertificateStatusEnumType.Accepted); + } + + @Override + public ExtendedTriggerMessageConfirmation handleExtendedTriggerMessageRequest(ExtendedTriggerMessageRequest request) { + receivedRequest = request; + return new ExtendedTriggerMessageConfirmation(TriggerMessageStatusEnumType.Accepted); + } + + @Override + public GetInstalledCertificateIdsConfirmation handleGetInstalledCertificateIdsRequest(GetInstalledCertificateIdsRequest request) { + receivedRequest = request; + return new GetInstalledCertificateIdsConfirmation(GetInstalledCertificateStatusEnumType.Accepted); + } + + @Override + public GetLogConfirmation handleGetLogRequest(GetLogRequest request) { + receivedRequest = request; + return new GetLogConfirmation(LogStatusEnumType.Accepted); + } + + @Override + public InstallCertificateConfirmation handleInstallCertificateRequest(InstallCertificateRequest request) { + receivedRequest = request; + return new InstallCertificateConfirmation(CertificateStatusEnumType.Accepted); + } + + @Override + public SignedUpdateFirmwareConfirmation handleSignedUpdateFirmwareRequest(SignedUpdateFirmwareRequest request) { + receivedRequest = request; + return new SignedUpdateFirmwareConfirmation(UpdateFirmwareStatusEnumType.Accepted); + } + }); + switch (type) { case JSON: client = new JSONTestClient(core); @@ -239,6 +290,7 @@ public CancelReservationConfirmation handleCancelReservationRequest( client.addFeatureProfile(firmware); client.addFeatureProfile(localAuthList); client.addFeatureProfile(reservation); + client.addFeatureProfile(securityExt); } public enum clientType { @@ -338,6 +390,26 @@ public void sendFirmwareStatusNotificationRequest(FirmwareStatus status) throws send(request); } + public void sendLogStatusNotificationRequest(UploadLogStatusEnumType uploadLogStatusEnumType) throws Exception { + LogStatusNotificationRequest request = securityExt.createLogStatusNotificationRequest(uploadLogStatusEnumType); + send(request); + } + + public void sendSecurityEventNotificationRequest(String type, ZonedDateTime timestamp) throws Exception { + SecurityEventNotificationRequest request = securityExt.createSecurityEventNotificationRequest(type, timestamp); + send(request); + } + + public void sendSignCertificateRequest(String csr) throws Exception { + SignCertificateRequest request = securityExt.createSignCertificateRequest(csr); + send(request); + } + + public void sendSignedFirmwareStatusNotificationRequest(FirmwareStatusEnumType status) throws Exception { + SignedFirmwareStatusNotificationRequest request = securityExt.createSignedFirmwareStatusNotificationRequest(status); + send(request); + } + public void clearMemory() { receivedConfirmation = null; receivedException = null; @@ -414,6 +486,22 @@ public boolean hasReceivedStopTransactionConfirmation() { return (receivedConfirmation instanceof StopTransactionConfirmation); } + public boolean hasReceivedLogStatusNotificationConfirmation() { + return receivedConfirmation instanceof LogStatusNotificationConfirmation; + } + + public boolean hasReceivedSecurityEventNotificationConfirmation() { + return receivedConfirmation instanceof SecurityEventNotificationConfirmation; + } + + public boolean hasReceivedSignCertificateConfirmation() { + return receivedConfirmation instanceof SignCertificateConfirmation; + } + + public boolean hasReceivedSignedFirmwareStatusNotificationConfirmation() { + return receivedConfirmation instanceof SignedFirmwareStatusNotificationConfirmation; + } + public void disconnect() { client.disconnect(); } @@ -482,6 +570,34 @@ public boolean hasHandledUnlockConnectorRequest() { return receivedRequest instanceof UnlockConnectorRequest; } + public boolean hasHandledCertificateSignedRequest() { + return receivedRequest instanceof CertificateSignedRequest; + } + + public boolean hasHandledDeleteCertificateRequest() { + return receivedRequest instanceof DeleteCertificateRequest; + } + + public boolean hasHandledExtendedTriggerMessageRequest() { + return receivedRequest instanceof ExtendedTriggerMessageRequest; + } + + public boolean hasHandledGetInstalledCertificateIdsRequest() { + return receivedRequest instanceof GetInstalledCertificateIdsRequest; + } + + public boolean hasHandledGetLogRequest() { + return receivedRequest instanceof GetLogRequest; + } + + public boolean hasHandledInstallCertificateRequest() { + return receivedRequest instanceof InstallCertificateRequest; + } + + public boolean hasHandledSignedUpdateFirmwareRequest() { + return receivedRequest instanceof SignedUpdateFirmwareRequest; + } + public boolean hasReceivedError() { return receivedException != null; } diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONCertificateSignedSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONCertificateSignedSpec.groovy new file mode 100644 index 000000000..c0ecb246f --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONCertificateSignedSpec.groovy @@ -0,0 +1,50 @@ +package eu.chargetime.ocpp.test.profiles.securityext.json + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.test.base.json.JSONBaseSpec +import spock.util.concurrent.PollingConditions + +class JSONCertificateSignedSpec extends JSONBaseSpec { + + def "Central system sends a CertificateSigned request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + + when: + centralSystem.sendCertificateSignedRequest("certificateChain") + + then: + conditions.eventually { + assert chargePoint.hasHandledCertificateSignedRequest() + } + + then: + conditions.eventually { + assert centralSystem.hasReceivedCertificateSignedConfirmation("Accepted") + } + } +} diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONDeleteCertificateSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONDeleteCertificateSpec.groovy new file mode 100644 index 000000000..76aa00763 --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONDeleteCertificateSpec.groovy @@ -0,0 +1,59 @@ +package eu.chargetime.ocpp.test.profiles.securityext.json + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.types.CertificateHashDataType +import eu.chargetime.ocpp.model.securityext.types.HashAlgorithmEnumType +import eu.chargetime.ocpp.test.base.json.JSONBaseSpec +import spock.util.concurrent.PollingConditions + +class JSONDeleteCertificateSpec extends JSONBaseSpec { + + def "Central system sends a DeleteCertificate request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + + given: + CertificateHashDataType certificateHashDataType = new CertificateHashDataType(); + certificateHashDataType.setHashAlgorithm(HashAlgorithmEnumType.SHA256) + certificateHashDataType.setIssuerNameHash("issuerNameHash") + certificateHashDataType.setIssuerKeyHash("issuerKeyHash") + certificateHashDataType.setSerialNumber("123") + + when: + centralSystem.sendDeleteCertificateRequest(certificateHashDataType) + + then: + conditions.eventually { + assert chargePoint.hasHandledDeleteCertificateRequest() + } + + then: + conditions.eventually { + assert centralSystem.hasReceivedDeleteCertificateConfirmation("Accepted") + } + } +} diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONExtendedTriggerMessageSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONExtendedTriggerMessageSpec.groovy new file mode 100644 index 000000000..e3838a9c0 --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONExtendedTriggerMessageSpec.groovy @@ -0,0 +1,51 @@ +package eu.chargetime.ocpp.test.profiles.securityext.json + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.types.MessageTriggerEnumType +import eu.chargetime.ocpp.test.base.json.JSONBaseSpec +import spock.util.concurrent.PollingConditions + +class JSONExtendedTriggerMessageSpec extends JSONBaseSpec { + + def "Central system sends a ExtendedTriggerMessage request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + + when: + centralSystem.sendExtendedTriggerMessageRequest(MessageTriggerEnumType.BootNotification) + + then: + conditions.eventually { + assert chargePoint.hasHandledExtendedTriggerMessageRequest() + } + + then: + conditions.eventually { + assert centralSystem.hasReceivedExtendedTriggerMessageConfirmation("Accepted") + } + } +} diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONGetInstalledCertificateIdsSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONGetInstalledCertificateIdsSpec.groovy new file mode 100644 index 000000000..fba2126f1 --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONGetInstalledCertificateIdsSpec.groovy @@ -0,0 +1,51 @@ +package eu.chargetime.ocpp.test.profiles.securityext.json + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.types.CertificateUseEnumType +import eu.chargetime.ocpp.test.base.json.JSONBaseSpec +import spock.util.concurrent.PollingConditions + +class JSONGetInstalledCertificateIdsSpec extends JSONBaseSpec { + + def "Central system sends a GetInstalledCertificateIds request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + + when: + centralSystem.sendGetInstalledCertificateIdsRequest(CertificateUseEnumType.CentralSystemRootCertificate) + + then: + conditions.eventually { + assert chargePoint.hasHandledGetInstalledCertificateIdsRequest() + } + + then: + conditions.eventually { + assert centralSystem.hasReceivedGetInstalledCertificateIdsConfirmation("Accepted") + } + } +} diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONGetLogSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONGetLogSpec.groovy new file mode 100644 index 000000000..501d91a8e --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONGetLogSpec.groovy @@ -0,0 +1,56 @@ +package eu.chargetime.ocpp.test.profiles.securityext.json + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.types.LogEnumType +import eu.chargetime.ocpp.model.securityext.types.LogParametersType +import eu.chargetime.ocpp.test.base.json.JSONBaseSpec +import spock.util.concurrent.PollingConditions + +class JSONGetLogSpec extends JSONBaseSpec { + + def "Central system sends a GetLog request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + + given: + LogParametersType log = new LogParametersType(); + log.setRemoteLocation("remoteLocation") + + when: + centralSystem.sendGetLogRequest(LogEnumType.DiagnosticsLog, 1, log) + + then: + conditions.eventually { + assert chargePoint.hasHandledGetLogRequest() + } + + then: + conditions.eventually { + assert centralSystem.hasReceivedGetLogConfirmation("Accepted") + } + } +} diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONInstallCertificateSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONInstallCertificateSpec.groovy new file mode 100644 index 000000000..76ca98a68 --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONInstallCertificateSpec.groovy @@ -0,0 +1,54 @@ +package eu.chargetime.ocpp.test.profiles.securityext.json + +import eu.chargetime.ocpp.model.securityext.types.CertificateUseEnumType + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.types.LogEnumType +import eu.chargetime.ocpp.model.securityext.types.LogParametersType +import eu.chargetime.ocpp.test.base.json.JSONBaseSpec +import spock.util.concurrent.PollingConditions + +class JSONInstallCertificateSpec extends JSONBaseSpec { + + def "Central system sends a InstallCertificate request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + + when: + centralSystem.sendInstallCertificateRequest(CertificateUseEnumType.CentralSystemRootCertificate, "certificate") + + then: + conditions.eventually { + assert chargePoint.hasHandledInstallCertificateRequest() + } + + then: + conditions.eventually { + assert centralSystem.hasReceivedInstallCertificateConfirmation("Accepted") + } + } +} diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONLogStatusNotificationSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONLogStatusNotificationSpec.groovy new file mode 100644 index 000000000..fb6a34f33 --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONLogStatusNotificationSpec.groovy @@ -0,0 +1,51 @@ +package eu.chargetime.ocpp.test.profiles.securityext.json + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.types.UploadLogStatusEnumType +import eu.chargetime.ocpp.test.base.json.JSONBaseSpec +import spock.util.concurrent.PollingConditions + +class JSONLogStatusNotificationSpec extends JSONBaseSpec { + + def "Charge point sends a LogStatusNotification request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + + when: + chargePoint.sendLogStatusNotificationRequest(UploadLogStatusEnumType.BadMessage) + + then: + conditions.eventually { + assert centralSystem.hasHandledLogStatusNotificationRequest() + } + + then: + conditions.eventually { + assert chargePoint.hasReceivedLogStatusNotificationConfirmation() + } + } +} diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONSecurityEventNotificationSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONSecurityEventNotificationSpec.groovy new file mode 100644 index 000000000..2e2a92e81 --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONSecurityEventNotificationSpec.groovy @@ -0,0 +1,52 @@ +package eu.chargetime.ocpp.test.profiles.securityext.json + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.test.base.json.JSONBaseSpec +import spock.util.concurrent.PollingConditions + +import java.time.ZonedDateTime + +class JSONSecurityEventNotificationSpec extends JSONBaseSpec { + + def "Charge point sends a SecurityEventNotification request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + + when: + chargePoint.sendSecurityEventNotificationRequest("type", ZonedDateTime.now()) + + then: + conditions.eventually { + assert centralSystem.hasHandledSecurityEventNotificationRequest() + } + + then: + conditions.eventually { + assert chargePoint.hasReceivedSecurityEventNotificationConfirmation() + } + } +} diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONSignCertificateSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONSignCertificateSpec.groovy new file mode 100644 index 000000000..4993147fc --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONSignCertificateSpec.groovy @@ -0,0 +1,50 @@ +package eu.chargetime.ocpp.test.profiles.securityext.json + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.test.base.json.JSONBaseSpec +import spock.util.concurrent.PollingConditions + +class JSONSignCertificateSpec extends JSONBaseSpec { + + def "Charge point sends a SignCertificate request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + + when: + chargePoint.sendSignCertificateRequest("csr") + + then: + conditions.eventually { + assert centralSystem.hasHandledSignCertificateRequest() + } + + then: + conditions.eventually { + assert chargePoint.hasReceivedSignCertificateConfirmation() + } + } +} diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONSignedFirmwareStatusNotificationSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONSignedFirmwareStatusNotificationSpec.groovy new file mode 100644 index 000000000..1c9440e2e --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONSignedFirmwareStatusNotificationSpec.groovy @@ -0,0 +1,51 @@ +package eu.chargetime.ocpp.test.profiles.securityext.json + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.types.FirmwareStatusEnumType +import eu.chargetime.ocpp.test.base.json.JSONBaseSpec +import spock.util.concurrent.PollingConditions + +class JSONSignedFirmwareStatusNotificationSpec extends JSONBaseSpec { + + def "Charge point sends a SignedFirmwareStatusNotification request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + + when: + chargePoint.sendSignedFirmwareStatusNotificationRequest(FirmwareStatusEnumType.Idle) + + then: + conditions.eventually { + assert centralSystem.hasHandledSignedFirmwareStatusNotificationRequest() + } + + then: + conditions.eventually { + assert chargePoint.hasReceivedSignedFirmwareStatusNotificationConfirmation() + } + } +} diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONSignedUpdateFirmwareSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONSignedUpdateFirmwareSpec.groovy new file mode 100644 index 000000000..2302dbf6c --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/securityext/json/JSONSignedUpdateFirmwareSpec.groovy @@ -0,0 +1,60 @@ +package eu.chargetime.ocpp.test.profiles.securityext.json + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2022 Mathias Oben + + 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. +*/ + +import eu.chargetime.ocpp.model.securityext.types.FirmwareType +import eu.chargetime.ocpp.test.base.json.JSONBaseSpec +import spock.util.concurrent.PollingConditions + +import java.time.ZonedDateTime + +class JSONSignedUpdateFirmwareSpec extends JSONBaseSpec { + + def "Central system sends a SignedUpdateFirmware request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + + given: + FirmwareType firmware = new FirmwareType(); + firmware.setLocation("location") + firmware.setRetrieveDateTime(ZonedDateTime.now()) + firmware.setSigningCertificate("signingCertificate") + firmware.setSignature("signature") + + when: + centralSystem.sendSignedUpdateFirmwareRequest(1, firmware) + + then: + conditions.eventually { + assert chargePoint.hasHandledSignedUpdateFirmwareRequest() + } + + then: + conditions.eventually { + assert centralSystem.hasReceivedSignedUpdateFirmwareConfirmation("Accepted") + } + } +}