11# ocpp-go
22
3- [ ![ Build Status] ( https://travis-ci.org /lorenzodonini/ocpp-go. svg?branch=master )] ( https://travis-ci.org /lorenzodonini/ocpp-go )
3+ [ ![ Build Status] ( https://github.com /lorenzodonini/ocpp-go/actions/workflows/test.yaml/badge. svg )] ( https://github.com /lorenzodonini/ocpp-go/actions/workflows/test.yaml )
44[ ![ GoDoc] ( https://img.shields.io/badge/godoc-reference-5272B4 )] ( https://godoc.org/github.com/lorenzodonini/ocpp-go )
55[ ![ Coverage Status] ( https://coveralls.io/repos/github/lorenzodonini/ocpp-go/badge.svg?branch=master )] ( https://coveralls.io/github/lorenzodonini/ocpp-go?branch=master )
66[ ![ Go report] ( https://goreportcard.com/badge/github.com/lorenzodonini/ocpp-go )] ( https://goreportcard.com/report/github.com/lorenzodonini/ocpp-go )
@@ -20,6 +20,7 @@ but naming changed.**
2020Planned milestones and features:
2121
2222- [x] OCPP 1.6
23+ - [x] OCPP 1.6 Security extension (experimental)
2324- [x] OCPP 2.0.1 (examples working, but will need more real-world testing)
2425- [ ] Dedicated package for configuration management
2526
@@ -346,6 +347,102 @@ Then run the following:
346347docker-compose -f example/1.6/docker-compose.tls.yml up charge-point
347348```
348349
350+ ## OCPP 1.6 Security extension
351+
352+ The library supports the OCPP 1.6 Security extension, which adds support for additional messages that aren't a part of
353+ original OCPP 1.6 specification. The security extension is optional, but recommended to implement.
354+
355+ There aren't any clear examples how to determine if a charge point supports security extensions via ` SupportedProfiles `
356+ configuration key or which profiles are required to be implemented in order to support the security extension.
357+ As of now, the security extension is split into multiple profiles/functional blocks:
358+
359+ - ` ExtendedTriggerMessage `
360+ - ` Certificates ` (certificate management)
361+ - ` Security ` (event notifications, certificate signing)
362+ - ` SecureFirmware ` (secure firmware update)
363+ - ` Logging `
364+
365+ ### HTTP Basic Auth
366+
367+ The security extension specifies how to secure the communication between charge points and central systems
368+ using HTTP Basic Auth and/or certificates. These are already provided in the websocket server/client
369+ implementation.
370+
371+ Example charge point:
372+
373+ ``` go
374+ wsClient := ws.NewClient ()
375+ wsClient.SetBasicAuth (" foo" , " bar" )
376+ cp := ocpp16.NewChargePoint (chargePointID, nil , wsClient)
377+ ```
378+
379+ Example central system:
380+
381+ ``` go
382+ server := ws.NewServer ()
383+ server.SetBasicAuthHandler (func (username string , password string ) bool {
384+ // todo Handle basic auth
385+ return true
386+ })
387+ cs := ocpp16.NewCentralSystem (nil , server)
388+ ```
389+
390+ ### Certificate-based authentication (mTLS)
391+
392+ The security extension specifies how to secure the communication between charge points and central systems
393+ using mTLS (client certificates). The library provides the necessary functionality to configure TLS,
394+ but mTLS itself is not in scope and should be handled by the user.
395+
396+ ### Additional configuration keys
397+
398+ The OCPP 1.6 security extension introduces additional configuration keys.
399+ These are not a part of the standard library, but they impact how the charge point should behave.
400+
401+ The charge point websocket client should be restarted when the ` AuthorizationKey ` configuration changes.
402+
403+ ### Central System
404+
405+ To add support for security extension in the central system, you have the following handlers:
406+
407+ ``` go
408+ // Support callbacks for all OCPP 1.6 profiles
409+ handler := &CentralSystemHandler{chargePoints: map [string ]*ChargePointState{}}
410+ centralSystem.SetCoreHandler (handler)
411+ centralSystem.SetLocalAuthListHandler (handler)
412+ centralSystem.SetFirmwareManagementHandler (handler)
413+ centralSystem.SetReservationHandler (handler)
414+ centralSystem.SetRemoteTriggerHandler (handler)
415+ centralSystem.SetSmartChargingHandler (handler)
416+
417+ // Add callbacks for OCPP 1.6 security profiles
418+ centralSystem.SetSecurityHandler (handler)
419+ centralSystem.SetSecureFirmwareHandler (handler)
420+ centralSystem.SetLogHandler (handler)
421+
422+ ```
423+
424+ ### Charge Point
425+
426+ To add support for security extension in the charge point, you have the following handlers:
427+
428+ ``` go
429+ handler := &ChargePointHandler{}
430+ // Support callbacks for all OCPP 1.6 profiles
431+ chargePoint.SetCoreHandler (handler)
432+ chargePoint.SetFirmwareManagementHandler (handler)
433+ chargePoint.SetLocalAuthListHandler (handler)
434+ chargePoint.SetReservationHandler (handler)
435+ chargePoint.SetRemoteTriggerHandler (handler)
436+ chargePoint.SetSmartChargingHandler (handler)
437+ // OCPP 1.6j Security extension
438+ chargePoint.SetCertificateHandler (handler)
439+ chargePoint.SetLogHandler (handler)
440+ chargePoint.SetSecureFirmwareHandler (handler)
441+ chargePoint.SetExtendedTriggerMessageHandler (handler)
442+ chargePoint.SetSecurityHandler (handler)
443+
444+ ```
445+
349446## Advanced Features
350447
351448The library offers several advanced features, especially at websocket and ocpp-j level.
@@ -389,18 +486,27 @@ own logging system.
389486
390487### Websocket ping-pong
391488
392- The websocket package currently supports client-initiated pings only .
489+ The websocket package supports configuring ping pong for both endpoints .
393490
394- If your setup requires the server to be the initiator of a ping-pong (e.g. for web-based charge points),
395- you may disable ping-pong entirely and just rely on the heartbeat mechanism:
491+ By default, the client sends a ping every 54 seconds and waits for a pong for 60 seconds, before timing out.
492+ The values can be configured as follows:
493+ ``` go
494+ cfg := ws.NewClientTimeoutConfig ()
495+ cfg.PingPeriod = 10 * time.Second
496+ cfg.PongWait = 20 * time.Second
497+ websocketClient.SetTimeoutConfig (cfg)
498+ ```
396499
500+ By default, the server does not send out any pings and waits for a ping from the client for 60 seconds, before timing out.
501+ To configure the server to send out pings, the ` PingPeriod ` and ` PongWait ` must be set to a value greater than 0:
397502``` go
398503cfg := ws.NewServerTimeoutConfig ()
399- cfg.PingWait = 0 // this instructs the server to wait forever
504+ cfg.PingPeriod = 10 * time.Second
505+ cfg.PongWait = 20 * time.Second
400506websocketServer.SetTimeoutConfig (cfg)
401507```
402508
403- > A server-initiated ping may be supported in a future release .
509+ To disable sending ping messages, set the ` PingPeriod ` value to ` 0 ` .
404510
405511## OCPP 2.0.1 Usage
406512
0 commit comments