|
| 1 | +package eu.chargetime.ocpp.feature.profile.securityext; |
| 2 | + |
| 3 | +/* |
| 4 | + ChargeTime.eu - Java-OCA-OCPP |
| 5 | +
|
| 6 | + MIT License |
| 7 | +
|
| 8 | + Copyright (C) 2022 Mathias Oben <[email protected]> |
| 9 | +
|
| 10 | + Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 | + of this software and associated documentation files (the "Software"), to deal |
| 12 | + in the Software without restriction, including without limitation the rights |
| 13 | + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 | + copies of the Software, and to permit persons to whom the Software is |
| 15 | + furnished to do so, subject to the following conditions: |
| 16 | +
|
| 17 | + The above copyright notice and this permission notice shall be included in all |
| 18 | + copies or substantial portions of the Software. |
| 19 | +
|
| 20 | + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 23 | + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 25 | + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 26 | + SOFTWARE. |
| 27 | +*/ |
| 28 | + |
| 29 | +import eu.chargetime.ocpp.feature.Feature; |
| 30 | +import eu.chargetime.ocpp.feature.ProfileFeature; |
| 31 | +import eu.chargetime.ocpp.feature.profile.Profile; |
| 32 | +import eu.chargetime.ocpp.feature.securityext.CertificateSignedFeature; |
| 33 | +import eu.chargetime.ocpp.feature.securityext.DeleteCertificateFeature; |
| 34 | +import eu.chargetime.ocpp.feature.securityext.ExtendedTriggerMessageFeature; |
| 35 | +import eu.chargetime.ocpp.feature.securityext.GetInstalledCertificateIdsFeature; |
| 36 | +import eu.chargetime.ocpp.feature.securityext.GetLogFeature; |
| 37 | +import eu.chargetime.ocpp.feature.securityext.InstallCertificateFeature; |
| 38 | +import eu.chargetime.ocpp.feature.securityext.LogStatusNotificationFeature; |
| 39 | +import eu.chargetime.ocpp.feature.securityext.SecurityEventNotificationFeature; |
| 40 | +import eu.chargetime.ocpp.feature.securityext.SignCertificateFeature; |
| 41 | +import eu.chargetime.ocpp.feature.securityext.SignedFirmwareStatusNotificationFeature; |
| 42 | +import eu.chargetime.ocpp.feature.securityext.SignedUpdateFirmwareFeature; |
| 43 | +import eu.chargetime.ocpp.model.Confirmation; |
| 44 | +import eu.chargetime.ocpp.model.Request; |
| 45 | +import eu.chargetime.ocpp.model.securityext.CertificateSignedRequest; |
| 46 | +import eu.chargetime.ocpp.model.securityext.DeleteCertificateRequest; |
| 47 | +import eu.chargetime.ocpp.model.securityext.ExtendedTriggerMessageRequest; |
| 48 | +import eu.chargetime.ocpp.model.securityext.GetInstalledCertificateIdsRequest; |
| 49 | +import eu.chargetime.ocpp.model.securityext.GetLogRequest; |
| 50 | +import eu.chargetime.ocpp.model.securityext.InstallCertificateRequest; |
| 51 | +import eu.chargetime.ocpp.model.securityext.LogStatusNotificationRequest; |
| 52 | +import eu.chargetime.ocpp.model.securityext.SecurityEventNotificationRequest; |
| 53 | +import eu.chargetime.ocpp.model.securityext.SignCertificateRequest; |
| 54 | +import eu.chargetime.ocpp.model.securityext.SignedFirmwareStatusNotificationRequest; |
| 55 | +import eu.chargetime.ocpp.model.securityext.SignedUpdateFirmwareRequest; |
| 56 | +import eu.chargetime.ocpp.model.securityext.types.FirmwareStatusEnumType; |
| 57 | +import eu.chargetime.ocpp.model.securityext.types.UploadLogStatusEnumType; |
| 58 | + |
| 59 | +import java.time.ZonedDateTime; |
| 60 | +import java.util.HashSet; |
| 61 | +import java.util.Set; |
| 62 | +import java.util.UUID; |
| 63 | + |
| 64 | +public class ClientSecurityExtProfile implements Profile { |
| 65 | + |
| 66 | + private final Set<Feature> features; |
| 67 | + private final ClientSecurityExtEventHandler eventHandler; |
| 68 | + |
| 69 | + public ClientSecurityExtProfile(ClientSecurityExtEventHandler handler) { |
| 70 | + this.features = new HashSet<>(); |
| 71 | + this.eventHandler = handler; |
| 72 | + |
| 73 | + features.add(new CertificateSignedFeature(this)); |
| 74 | + features.add(new DeleteCertificateFeature(this)); |
| 75 | + features.add(new ExtendedTriggerMessageFeature(this)); |
| 76 | + features.add(new GetInstalledCertificateIdsFeature(this)); |
| 77 | + features.add(new GetLogFeature(this)); |
| 78 | + features.add(new InstallCertificateFeature(this)); |
| 79 | + features.add(new LogStatusNotificationFeature(null)); |
| 80 | + features.add(new SecurityEventNotificationFeature(null)); |
| 81 | + features.add(new SignCertificateFeature(null)); |
| 82 | + features.add(new SignedFirmwareStatusNotificationFeature(null)); |
| 83 | + features.add(new SignedUpdateFirmwareFeature(this)); |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public ProfileFeature[] getFeatureList() { |
| 88 | + return features.toArray(new ProfileFeature[0]); |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public Confirmation handleRequest(UUID sessionIndex, Request request) { |
| 93 | + Confirmation result = null; |
| 94 | + |
| 95 | + if (request instanceof CertificateSignedRequest) { |
| 96 | + result = eventHandler.handleCertificateSignedRequest((CertificateSignedRequest) request); |
| 97 | + } else if (request instanceof DeleteCertificateRequest) { |
| 98 | + result = eventHandler.handleDeleteCertificateRequest((DeleteCertificateRequest) request); |
| 99 | + } else if (request instanceof ExtendedTriggerMessageRequest) { |
| 100 | + result = eventHandler.handleExtendedTriggerMessageRequest((ExtendedTriggerMessageRequest) request); |
| 101 | + } else if (request instanceof GetInstalledCertificateIdsRequest) { |
| 102 | + result = eventHandler.handleGetInstalledCertificateIdsRequest((GetInstalledCertificateIdsRequest) request); |
| 103 | + } else if (request instanceof GetLogRequest) { |
| 104 | + result = eventHandler.handleGetLogRequest((GetLogRequest) request); |
| 105 | + } else if (request instanceof InstallCertificateRequest) { |
| 106 | + result = eventHandler.handleInstallCertificateRequest((InstallCertificateRequest) request); |
| 107 | + }else if (request instanceof SignedUpdateFirmwareRequest) { |
| 108 | + result = eventHandler.handleSignedUpdateFirmwareRequest((SignedUpdateFirmwareRequest) request); |
| 109 | + } |
| 110 | + |
| 111 | + return result; |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Create a client {@link LogStatusNotificationRequest} with required values. |
| 116 | + * |
| 117 | + * @return an instance of {@link LogStatusNotificationRequest}. |
| 118 | + * @see LogStatusNotificationRequest |
| 119 | + * @see LogStatusNotificationFeature |
| 120 | + */ |
| 121 | + public LogStatusNotificationRequest createLogStatusNotificationRequest(UploadLogStatusEnumType status) { |
| 122 | + return new LogStatusNotificationRequest(status); |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Create a client {@link SecurityEventNotificationRequest} with required values. |
| 127 | + * |
| 128 | + * @return an instance of {@link SecurityEventNotificationRequest} |
| 129 | + * @see SecurityEventNotificationRequest |
| 130 | + * @see SecurityEventNotificationFeature |
| 131 | + */ |
| 132 | + public SecurityEventNotificationRequest createSecurityEventNotificationRequest(String type, ZonedDateTime timestamp) { |
| 133 | + return new SecurityEventNotificationRequest(type, timestamp); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * Create a client {@link SignCertificateRequest} with required values. |
| 138 | + * |
| 139 | + * @return an instance of {@link SignCertificateRequest}. |
| 140 | + * @see SignCertificateRequest |
| 141 | + * @see SignCertificateFeature |
| 142 | + */ |
| 143 | + public SignCertificateRequest createSignCertificateRequest(String csr) { |
| 144 | + return new SignCertificateRequest(csr); |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * Create a client {@link SignedFirmwareStatusNotificationRequest}. |
| 149 | + * |
| 150 | + * @return an instance of {@link SignedFirmwareStatusNotificationRequest} |
| 151 | + * @see SignedFirmwareStatusNotificationRequest |
| 152 | + * @see SignedFirmwareStatusNotificationFeature |
| 153 | + */ |
| 154 | + public SignedFirmwareStatusNotificationRequest createSignedFirmwareStatusNotificationRequest(FirmwareStatusEnumType status) { |
| 155 | + return new SignedFirmwareStatusNotificationRequest(status); |
| 156 | + } |
| 157 | +} |
0 commit comments