Skip to content

Commit 41fd37d

Browse files
AhmedAbouelkherlorenzodonini
authored andcommitted
Implemented OCPP 1.6j security extension (#1)
* Added required fixes for PR lorenzodonini/ocpp-go/266 * revert `CertificateHashData` to be 40 chars long instead of 20
1 parent d768175 commit 41fd37d

10 files changed

+34
-42
lines changed

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ go 1.16
55
require (
66
github.com/Shopify/toxiproxy v2.1.4+incompatible
77
github.com/go-playground/locales v0.12.1 // indirect
8-
github.com/go-playground/universal-translator v0.16.0 // indirect
8+
github.com/go-playground/universal-translator v0.16.0
99
github.com/gorilla/mux v1.7.3
1010
github.com/gorilla/websocket v1.4.1
1111
github.com/kr/pretty v0.1.0 // indirect
1212
github.com/leodido/go-urn v1.1.0 // indirect
13-
github.com/relvacode/iso8601 v1.3.0 // indirect
13+
github.com/relvacode/iso8601 v1.3.0
1414
github.com/sirupsen/logrus v1.4.2
1515
github.com/stretchr/testify v1.8.0
1616
golang.org/x/sys v0.0.0-20220804214406-8e32c043e418 // indirect

ocpp1.6/certificates/delete_certificate.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ type DeleteCertificateRequest struct {
3939
// This field definition of the DeleteCertificate response payload, sent by the Charging Station to the CSMS in response to a DeleteCertificateRequest.
4040
// In case the request was invalid, or couldn't be processed, an error will be sent instead.
4141
type DeleteCertificateResponse struct {
42-
Status DeleteCertificateStatus `json:"status" validate:"required,deleteCertificateStatus16"`
43-
StatusInfo *types.StatusInfo `json:"statusInfo,omitempty" validate:"omitempty"`
42+
Status DeleteCertificateStatus `json:"status" validate:"required,deleteCertificateStatus16"`
4443
}
4544

4645
// The CSMS requests the Charging Station to delete a specific installed certificate by sending a DeleteCertificateRequest.

ocpp1.6/certificates/get_installed_certificates.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ type GetInstalledCertificateIdsRequest struct {
3636

3737
// The field definition of the GetInstalledCertificateIds response payload sent by the Charging Station to the CSMS in response to a GetInstalledCertificateIdsRequest.
3838
type GetInstalledCertificateIdsResponse struct {
39-
Status GetInstalledCertificateStatus `json:"status" validate:"required,getInstalledCertificateStatus16"`
40-
StatusInfo *types.StatusInfo `json:"statusInfo,omitempty" validate:"omitempty"`
41-
CertificateHashDataChain []types.CertificateHashDataChain `json:"certificateHashData,omitempty" validate:"omitempty,dive"`
39+
Status GetInstalledCertificateStatus `json:"status" validate:"required,getInstalledCertificateStatus16"`
40+
CertificateHashData []types.CertificateHashData `json:"certificateHashData,omitempty" validate:"omitempty,dive"`
4241
}
4342

4443
// To facilitate the management of the Charging Station’s installed certificates, a method of retrieving the installed certificates is provided.

ocpp1.6/certificates/install_certificate.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ type InstallCertificateRequest struct {
3939
// This field definition of the InstallCertificate response payload, sent by the Charging Station to the CSMS in response to a InstallCertificateRequest.
4040
// In case the request was invalid, or couldn't be processed, an error will be sent instead.
4141
type InstallCertificateResponse struct {
42-
Status InstallCertificateStatus `json:"status" validate:"required,installCertificateStatus16"`
43-
StatusInfo *types.StatusInfo `json:"statusInfo,omitempty" validate:"omitempty"`
42+
Status InstallCertificateStatus `json:"status" validate:"required,installCertificateStatus16"`
4443
}
4544

4645
// The CSMS requests the Charging Station to install a new certificate by sending an InstallCertificateRequest.

ocpp1.6/extendedtriggermessage/extended_trigger_message.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ type ExtendedTriggerMessageType string
2828
type ExtendedTriggerMessageStatus string
2929

3030
const (
31-
ExtendedTriggerMessageTypeBootNotification ExtendedTriggerMessageType = "BootNotification" // This contains the field definition of a diagnostics log file
32-
ExtendedTriggerMessageTypeLogStatusNotification ExtendedTriggerMessageType = "LogStatusNotification" // Sent by the CSMS to the Charging Station to request that the Charging Station uploads the security log
33-
ExtendedTriggerMessageTypeHeartbeat ExtendedTriggerMessageType = "Heartbeat" // Accepted this log upload. This does not mean the log file is uploaded is successfully, the Charging Station will now start the log file upload.
34-
ExtendedTriggerMessageTypeMeterValues ExtendedTriggerMessageType = "MeterValues" // Log update request rejected.
35-
ExtendedTriggerMessageTypeSignChargingStationCertificate ExtendedTriggerMessageType = "SignChargingStationCertificate" // Accepted this log upload, but in doing this has canceled an ongoing log file upload.
36-
ExtendedTriggerMessageTypeFirmwareStatusNotification ExtendedTriggerMessageType = "FirmwareStatusNotification" // Accepted this log upload, but in doing this has canceled an ongoing log file upload.
37-
ExtendedTriggerMessageTypeStatusNotification ExtendedTriggerMessageType = "StatusNotification" // Accepted this log upload, but in doing this has canceled an ongoing log file upload.
31+
ExtendedTriggerMessageTypeBootNotification ExtendedTriggerMessageType = "BootNotification" // This contains the field definition of a diagnostics log file
32+
ExtendedTriggerMessageTypeLogStatusNotification ExtendedTriggerMessageType = "LogStatusNotification" // Sent by the CSMS to the Charging Station to request that the Charging Station uploads the security log
33+
ExtendedTriggerMessageTypeHeartbeat ExtendedTriggerMessageType = "Heartbeat" // Accepted this log upload. This does not mean the log file is uploaded is successfully, the Charging Station will now start the log file upload.
34+
ExtendedTriggerMessageTypeMeterValues ExtendedTriggerMessageType = "MeterValues" // Log update request rejected.
35+
ExtendedTriggerMessageTypeSignChargingStationCertificate ExtendedTriggerMessageType = "SignChargePointCertificate" // Accepted this log upload, but in doing this has canceled an ongoing log file upload.
36+
ExtendedTriggerMessageTypeFirmwareStatusNotification ExtendedTriggerMessageType = "FirmwareStatusNotification" // Accepted this log upload, but in doing this has canceled an ongoing log file upload.
37+
ExtendedTriggerMessageTypeStatusNotification ExtendedTriggerMessageType = "StatusNotification" // Accepted this log upload, but in doing this has canceled an ongoing log file upload.
3838

3939
ExtendedTriggerMessageStatusAccepted ExtendedTriggerMessageStatus = "Accepted"
4040
ExtendedTriggerMessageStatusRejected ExtendedTriggerMessageStatus = "Rejected"

ocpp1.6/securefirmware/signed_update_firmware_status_notitfication.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,28 @@ const (
3030
FirmwareStatusInstallVerificationFailed FirmwareStatus = "InstallVerificationFailed"
3131
FirmwareStatusInvalidSignature FirmwareStatus = "InvalidSignature"
3232
FirmwareStatusSignatureVerified FirmwareStatus = "SignatureVerified"
33+
FirmwareStatusCertificateVerified FirmwareStatus = "CertificateVerified"
34+
FirmwareStatusInvalidCertificate FirmwareStatus = "InvalidCertificate"
35+
FirmwareStatusRevokedCertificate FirmwareStatus = "RevokedCertificate"
3336
)
3437

3538
func isValidFirmwareStatus(fl validator.FieldLevel) bool {
3639
status := FirmwareStatus(fl.Field().String())
3740
switch status {
38-
case FirmwareStatusDownloaded, FirmwareStatusDownloadFailed, FirmwareStatusDownloading, FirmwareStatusDownloadScheduled, FirmwareStatusDownloadPaused, FirmwareStatusIdle, FirmwareStatusInstallationFailed, FirmwareStatusInstalling, FirmwareStatusInstalled, FirmwareStatusInstallRebooting, FirmwareStatusInstallScheduled, FirmwareStatusInstallVerificationFailed, FirmwareStatusInvalidSignature, FirmwareStatusSignatureVerified:
41+
case FirmwareStatusDownloaded,
42+
FirmwareStatusDownloadFailed,
43+
FirmwareStatusDownloading,
44+
FirmwareStatusDownloadScheduled,
45+
FirmwareStatusDownloadPaused,
46+
FirmwareStatusIdle,
47+
FirmwareStatusInstallationFailed,
48+
FirmwareStatusInstalling,
49+
FirmwareStatusInstalled,
50+
FirmwareStatusInstallRebooting,
51+
FirmwareStatusInstallScheduled,
52+
FirmwareStatusInstallVerificationFailed,
53+
FirmwareStatusInvalidSignature,
54+
FirmwareStatusSignatureVerified:
3955
return true
4056
default:
4157
return false

ocpp1.6/security/certificate_signed.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ func isValidCertificateSignedStatus(fl validator.FieldLevel) bool {
3232

3333
// The field definition of the CertificateSignedRequest PDU sent by the CSMS to the Charging Station.
3434
type CertificateSignedRequest struct {
35-
CertificateChain string `json:"certificateChain" validate:"required,max=10000"`
36-
TypeOfCertificate types.CertificateSigningUse `json:"certificateType,omitempty" validate:"omitempty,certificateSigningUse16"`
35+
CertificateChain string `json:"certificateChain" validate:"required,max=10000"`
3736
}
3837

3938
// The field definition of the CertificateSignedResponse payload sent by the Charging Station to the CSMS in response to a CertificateSignedRequest.
4039
type CertificateSignedResponse struct {
41-
Status CertificateSignedStatus `json:"status" validate:"required,certificateSignedStatus16"`
42-
StatusInfo *types.StatusInfo `json:"statusInfo,omitempty" validate:"omitempty"`
40+
Status CertificateSignedStatus `json:"status" validate:"required,certificateSignedStatus16"`
4341
}
4442

4543
// During the a certificate update procedure, the CSMS sends a new certificate, signed by a CA,
@@ -69,6 +67,7 @@ func (c CertificateSignedResponse) GetFeatureName() string {
6967
}
7068

7169
// Creates a new CertificateSignedRequest, containing all required fields. Additional optional fields may be set afterwards.
70+
// The maximum size of this field is be limited by the configuration key: CertificateSignedMaxSize
7271
func NewCertificateSignedRequest(certificateChain string) *CertificateSignedRequest {
7372
return &CertificateSignedRequest{CertificateChain: certificateChain}
7473
}

ocpp1.6/security/sign_certificate.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ type SignCertificateRequest struct {
1919
// This field definition of the SignCertificate response payload, sent by the CSMS to the Charging Station in response to a SignCertificateRequest.
2020
// In case the request was invalid, or couldn't be processed, an error will be sent instead.
2121
type SignCertificateResponse struct {
22-
Status types.GenericStatus `json:"status" validate:"required,genericStatus16"` // Specifies whether the CSMS can process the request.
23-
StatusInfo *types.StatusInfo `json:"statusInfo,omitempty" validate:"omitempty"` // Detailed status information.
22+
Status types.GenericStatus `json:"status" validate:"required,genericStatus16"` // Specifies whether the CSMS can process the request.
2423
}
2524

2625
// If a Charging Station detected, that its certificate is due to expire, it will generate a new public/private key pair,

ocpp1.6/types/security_extension.go

-17
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,3 @@ type CertificateHashData struct {
8686
IssuerKeyHash string `json:"issuerKeyHash" validate:"required,max=128"`
8787
SerialNumber string `json:"serialNumber" validate:"required,max=40"`
8888
}
89-
90-
// CertificateHashDataChain
91-
type CertificateHashDataChain struct {
92-
CertificateType CertificateUse `json:"certificateType" validate:"required,certificateUse"`
93-
CertificateHashData CertificateHashData `json:"certificateHashData" validate:"required"`
94-
ChildCertificateHashData []CertificateHashData `json:"childCertificateHashData,omitempty" validate:"omitempty,dive"`
95-
}
96-
97-
func isValidHashAlgorithmType(fl validator.FieldLevel) bool {
98-
algorithm := HashAlgorithmType(fl.Field().String())
99-
switch algorithm {
100-
case SHA256, SHA384, SHA512:
101-
return true
102-
default:
103-
return false
104-
}
105-
}

ocpp1.6/types/types.go

-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const (
1111
)
1212

1313
type PropertyViolation struct {
14-
error
1514
Property string
1615
}
1716

@@ -333,5 +332,4 @@ func init() {
333332
_ = Validate.RegisterValidation("certificateSigningUse16", isValidCertificateSigningUse)
334333
_ = Validate.RegisterValidation("isValidCertificateUse", isValidCertificateUse)
335334
_ = Validate.RegisterValidation("genericStatus16", isValidGenericStatus)
336-
_ = Validate.RegisterValidation("hashAlgorithm16", isValidHashAlgorithmType)
337335
}

0 commit comments

Comments
 (0)