Skip to content

About

Local Controller

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

217 Commits

Folders and files

Repository files navigation

LocalController

One EV charging local controller, with a web interface in front of it: a C# HTTP backend built on Hermod, and a frontend of HTML, SCSS and TypeScript bundled by webpack and embedded into the assembly - so the local controller is one binary to deploy and needs nothing installed beside it.

Nothing is rendered on the server. The browser loads one bundle and talks to the controller over a JSON API and one Server-Sent Events stream.

  browser  ──  GET /                       the SPA stub and the bundle
           ──  POST /ext/login             the session cookie
           ──  GET  /api/v1/auth/me        what that account may do here
           ──  GET  /api/v1/configuration  what the controller is made of
           ──  GET  /api/v1/logs           what happened up to now
           ──  GET  /api/v1/events         and everything from now on (SSE)

A local controller sits between a CSMS above it and the charging stations below, and is usually the only thing in a car park with a keyboard within reach of it. That is what the web interface is for: it is the one place where somebody can see what the box is doing without having a back end to ask.

Everything a running local controller is before it is a local controller - its log, its configuration file, name resolution and the time, who may sign in, and the HTTP server all of that sits behind - is not here. That is WWCP_Node, the part a vehicle, a charging station and a local controller share, and LocalController is one WWCPNode with an OCPP node, a port for the charging stations below it and a line up to the CSMS above: its sections - ocpp, webSocketServer, csms - go into the same configuration file, and its routes into the JSON API every node has below /api - the node's NodeHTTPAPI, with the CSMS and the charging station port on top.

What it can be told

Page What it changes Permission
Configuration nothing - it answers "what am I running" configuration:read
DNS client the name servers and how they are asked; a test lookup, of all of them or of one dns:edit, dns:run
NTS client the time servers and the rules for believing them; a synchronisation, and a test of one server step by step nts:edit, nts:run
SSH server whether the command line is served over SSH, on which port, and whether passwords open it - in effect at once; its host key, who is connected, the keys of the accounts and what it offers ssh:edit
Your account (the name at the foot of the menu) your own name, e-mail address and how to reach you; your API keys and SSH keys - added, switched off and on, removed your own account, whatever the role
CSMS connection whether the controller reports to a CSMS at all, and how its lines up are kept: pings, timeouts, the TLS identity a line holds up where it names none csms:edit
Connections the lines up to the CSMS: where each connects to - or, where The other end connects is ticked, where the CSMS connects to the controller -, what it signs in with, how its server is believed, how it is doing - and a test of one; on its tab Credentials, the passwords and one-time tokens the connections sign in with csms:edit, csms:run
Certificate store the TLS roots of the servers the controller connects to, and their certificates - certificates alone, no private key certificates:edit
Client identities who the controller is as a client, each with its private key: the TLS identities its lines up to the CSMS hold up - brought with their key, or whose key is made here (tab New key) and waits for its certificate - and, under SSH keys, the keys an ssh:// line signs in with beside the controller's own certificates:edit; certificates:run to make a key and bring its certificate, and to make or remove an SSH key
Charging stations the server the charging stations connect to: its port, how a station may authenticate (clientAuthentication, OCPP's security profiles), the names it is reachable as, what it logs, and whether they may connect over SSH as well stations:edit
Logins and groups which charging stations may sign in, with what - a password, a one-time token (over SSH as well, bound to its session), an SSH key - and what their group allows them stations:edit
Accepted chains which certificate authorities a charging station may be vouched for by certificates:edit
Commissioning whether a tool may speak OCPP to the controller over its SSH server, as its CSMS would - on or off at once; where a tool connects, and who is connected commissioning:edit
State nothing - it shows whether the line up to the CSMS stands and since when, which charging stations were seen when and over what, and the grid operator's limits in force state:read
Logs nothing - it reads log:read

Looking at a page takes read on the resource in its column: dns:read for the DNS client, stations:read for the charging stations. The clock is for anybody signed in. The log and the event stream take log:read, because they show the charging stations and their connections - the same over SSH, where a session without it is not shown the log. The State page is apart from the configuration: nothing on it says where the line goes, whom the station port lets in or what anybody signs in with, so that state:read can be given to people who are to read none of that. Which roles hold what is under "Who may open it" below.

Everything on the DNS and NTS pages takes effect the moment it is saved, for everything inside the controller that resolves a name or reads a clock, and is written to configuration.json in the same breath - the file first, because a change that was applied but not written down disappears at the next start without anybody noticing.

What this controller says it is in OCPP - its node id, vendor, model, serial number - is read from the ocpp section of that file at the start and is deliberately not changeable while running: an identification is what a CSMS knows this controller by, and changing it under a live connection would not rename the controller, it would make it a second one nobody is talking to.

The lines up to the CSMS are connections, as a charging station's are: each with its address, the credentials it names, the certificate it holds up, how its server is believed, the version of HTTP it is opened over and how its messages are written. They are kept in ocpp-connections/ beside the configuration file - the credentials for their owner alone, and never in the configuration file - and looked after on the Connections pages or with /api/v1/configuration/connections, .../authentications and .../sshKeys; GET /api/v1/status/connections says how each is doing, and POST .../connections/test tries one without writing anything. It is the code a charging station connects with (WWCP_Node's WWCPNode, over OCPP by WWCP_OCPP_Node's OCPPConnecting), so what a connection can do there it can do here. A controller may have several: each is connected by itself, and the next endpoint of a peer where one cannot be reached. The oldest that connects by itself leads to the CSMS in charge, which is told what the controller says of its own accord.

The station port is shared code as well: the webSocketServer section, the charging stations that may sign in and their login groups (websocket-logins.json), the chains a station's certificate may lead to (ocpp-client-trust/), OCPP over SSH, a CSMS that connects on the same port, the routes below /api/v1/configuration/ocpp-server and the three pages that look after them are WWCP_OCPP_Node's OCPPServingNode, which a gateway has too. What is the controller's own is what it does with them: whether a CSMS may connect to it at all (only while it reports to one), the CSMS it tells of a switch of the port's key, and the stations it counts on its State page.

What the csms section of the configuration file says is what a connection does not: whether the controller reports to a CSMS at all (enabled), the frame its lines speak in (networkingMode), how they are kept (pingEvery, requestTimeout, reconnectInitialDelay, reconnectMaxDelay), the versions of TLS, and clientCertificate. A controller configured before its lines were connections had one line there - url, securityProfile, httpVersion - with its credentials in csms-credentials.json and how it believed its CSMS in csms-keypins.json. At its first start with the store they become a connection: with its password or, where it had none, its one-time token - one that had both signs in with the password and keeps the token as credentials of their own -, its key pins and their version, how it trusts them, and the signers of pin sets. The file of the credentials is removed, that of the key pins kept as csms-keypins.json.takenOver, and the start says what was done. The three fields are no longer read, and PUT /api/v1/configuration/csms refuses them: a line is changed where the connections are. There is no security profile to say any more - a connection is profile 1 without TLS, 2 over wss://, and 3 where it holds up a certificate.

A connection is connected when the controller starts, and kept up by the WebSocket client it was connected with. A CSMS that is not there yet, or goes away later - restarted, deployed again - is connected again by itself: after reconnectInitialDelay seconds of the csms section at first, and twice as long after every attempt that fails, up to reconnectMaxDelay. So is one that answers "not yet" - 408, 429, or a 5xx from a proxy whose CSMS is still starting - though not before a Retry-After it sends, five minutes at most. An answer that means no, such as a wrong password, is final, whether it comes at the start or on the way back: the connection is not tried again until it is changed or the controller restarted. The Connections page says which of these it is for each, and the CSMS page whether a line is up and since when.

A connection signs in with a password or a one-time token - bound to the TLS session where its credentials say so, which it is over HTTP/3 and nothing else - or with a certificate: one of its own, kept with the connections, or the TLS identity of the certificate store the csms section names by its handle as clientCertificate, looked after on the Client identities page and chosen on the CSMS page, which every line over wss:// that names no certificate of its own holds up. One that is not in the store, switched off or out of its validity is said so, and the line not connected with it. Over TLS, the CSMS's certificate is judged by the node as a time server's is: issued for the name it is connected to, and chaining to a root this machine trusts or to a TLS root of the store kept for every use. What it was believed with is remembered in known-servers.json, and another certificate than before is said. A CSMS reads who is connecting from the last segment of the address, as OCPP has every client say it: wss://csms.example.org/ocpp/lc001.

The lines speak in the frame of the overlay network unless networkingMode in the csms section says "standard": every frame names where it goes and where it comes from, and the connection tells the CSMS so in the header X-OCPP-NetworkingMode: OverlayNetwork. That is what lets the CSMS see the stations behind the controller, each by its own name, and reach them - to hand them their key pins, say. "standard", the plain OCPP frame, is for a CSMS that knows nothing of the overlay network: then everything the CSMS sends down is taken for the controller's own, everything a station sends up for the controller's, and the CSMS sees one station where there are several. Until 2026-11-12 a file that said nothing meant standard; the start says which mode it is, and whether the file said so. A CSMS of the overlay network takes what a login sends in another station's name only from a local controller's: at this project's CSMS the controller's login is marked as one - localControllers lc001 on, or "Local controller" on the page of its station logins - and until it is, what the controller forwards of its stations is dropped there, and the CSMS's log says so. Either way the controller answers what is addressed to it and forwards what is addressed to a station; a change waits for the lines to be connected again.

Over wss:// the CSMS is believed either by its certificate, as a CA vouches for it, or - key-pinned, as the charging stations believe their local controller - by the key pin of its key and by nothing else of its certificate ("Key Pins and Raw Public Keys for Local Controllers", sections 5.4 to 5.7). The key pins are a connection's, set where the connection is; with trust on first use the key pin of the first key the CSMS shows is learned, and is on probation until a pin set signed by one of the signers of pin sets (POST /api/v1/configuration/connections/pinSetSigners, .../pinSetSigners/remove) confirms it - over OCPP, as SetVariables of the TLSClientController instance named by the connection's id, with ServerKeyPins and a higher ServerKeyPinsVersion. While a connection is on probation nothing that comes over it is carried out, and nothing is sent on to a station: only that pin set, and reads of TLSClientController, pass. A pin set without the key learned closes the connection, which is then held to the signed pins; a probation that runs out forgets the key and learns again. Each step is told to the CSMS as a security event of this controller's (KeyPinLearned, KeyPinConfirmed, KeyPinRejected, KeyPinProbationExpired, InvalidCsmsCertificate). What is learned and signed is written down with the connection; the decisions are WWCP_OCPP_Node's key-pin core, which the charging stations use as well. Every change needs csms:edit and applies the next time the connection is made.

What only a CSMS asks of a node it manages - InstallSSHKey, DeleteSSHKey, SetVariables, GetVariables, a Reset, its files and its signature policies, every request of OCPP 2.1 a CSMS sends - comes over this line and from no charging station. A station can write the frame of the overlay network whatever the line speaks, address the controller itself and call itself the CSMS: such a request is refused with a SecurityError. What a station sends on goes up to the CSMS, in the station's own name: a frame that names another sender is dropped, and one addressed to another station of the controller is refused. An answer the controller passes on goes to whoever asked, whatever the answer names.

Where the controller cannot connect to its CSMS - behind a firewall that lets nothing out, on a network only the back end reaches - the CSMS connects to the controller. OCPP stays as it is; only who opens the WebSocket is the other way round. There is no port of its own for it: the CSMS comes in over the port of the charging stations. On the Connections page a connection is written down with The other end connects ticked: its URL is the one the CSMS connects to - wss://controller.example.org:9000/csms-01 - and the last part of it the name the CSMS comes under. That is the name of its WebSocket login, and it signs in as a charging station does - one way in for both, judged by the login and its group:

  • A password or a one-time token of its login. A token bound to the TLS session is checked with keying material only the TLS of HTTP/3 exports: such a CSMS is let in where it opens its WebSocket over HTTP/3 - which the station port takes where webSocketServer says "http3": true, and not where it says nothing -, and a raw token is not taken instead.
  • A client certificate known by its key: a key pin of its login, and the key is the whole check - no chain, no name, no validity period.
  • A client certificate checked by its CA: of a chain the station port accepts (Accepted chains), issued to the name the CSMS comes under - with or without a login of that name, as for a station.

The connection names nothing it signs in with: credentials of the controller, key pins and roots on it are refused, with what to do instead - they are what the controller proves itself with, and holds a server to, where it connects.

A client certificate is security profile 3, as it is for a charging station; it opens no charging station's path, and a key a station has opens nothing under the name of the CSMS. "Connect by itself" is what lets it in: off, nothing comes in under its name, and one that is in is let go of. The page shows it as waiting until the CSMS connects and as connected from then on.

At the door the login is judged first, as for a station; then the name decides: whoever comes under the name of such a connection is let in as that or not at all - by its own login, on its own path - and a charging station's password opens nothing under it. A login whose name a connection the other end makes comes under is that back end's, and no charging station's. Once in, it is the line up of the controller as much as one the controller connected to: what the stations send on goes up over it, what it asks of a station goes down, what only a CSMS asks of the controller it may ask, and it is neither counted nor listed among the charging stations. A CSMS of the overlay network says so in the header of its connection, X-OCPP-NetworkingMode: OverlayNetwork, as the controller does where it connects; one that says nothing speaks the plain frame of OCPP, and what it sends is for the controller. All of it needs the station server switched on and the controller reporting to a CSMS at all ("csms": { "enabled": true }).

Registering. Over every line up - one the controller connects to, and one a CSMS connects - the controller registers as a charging station does, and with the same code (WWCP_OCPP_Node's OCPPServingNode.Registration.cs): once the line is up its OCPP node sends a BootNotification - its vendor, model and serial number, and that it powered up -, asks again after the interval a Pending or a Rejected gives, or a minute where the CSMS does not answer, and sends heartbeats at the interval an Accepted gives, to every back end that accepted it. Where it stands, the primary's registration, is RegistrationJSON() - {"2.1": {"state", "since", "interval", "nextTry", "problem"}}, as a station says it for each of its two nodes. A CSMS of WWCP_OCPP knows a controller that registers by the mark of its login, or by the connection it connects over, and does not take it for a charging station: it installs no station roots on it and renews no certificate of it.

The charging stations may speak OCPP over SSH as well, where ssh in the webSocketServer section says so - "ssh": { "enabled": true }, switched off unless somebody says otherwise, and on and off without a restart. There is no port of its own: a station signs in to the controller's SSH server - the one of the command line, the ssh section's port - under its identification, with an SSH key it was given under Logins and groups, and asks for the subsystem ocpp@open.charging.cloud; it pins the controller's host key as it would a certificate. A key is a line of an authorized_keys file, so from= and expiry-time= in front of it hold, and one key is one charging station. It lets the station in where the station and its group are switched on and the group accepts SSH keys (sshkey) - no security profile is asked, as SSH is none - and the station gets OCPP and nothing else: no command line, no command, no SFTP. A key taken away, a station or its group switched off, ends the session it opened at once. Which OCPP versions are offered is the WebSocket port's, unless subprotocols beside enabled says otherwise; maxMessageSize and pingEverySeconds there too wait for the next start.

A station that has a TOTP secret here signs in without a key as well: with the SSH method totp@open.charging.cloud, the one-time token of that secret bound to the session identifier of the SSH connection it is sent in, so that it is good in that session and nowhere else (white paper "SSH Authentication Extensions for OCPP"). Its group has to accept one-time passwords (totp), as over the WebSocket port; what the station gets is what a key gets it, and a secret changed or taken away ends the session it opened. A one-time token that is not bound to the session is a password to an SSH server, and a password lets no charging station in.

The whole way from both ends, step by step - the options of a key, the settings and what to look at when a station does not connect - is in Charging stations over SSH: a walk-through of LocalControllerCLI.

A commissioning tool may speak OCPP to the controller on the same subsystem, as its CSMS would, where the commissioning section switches it on - "commissioning": { "enabled": true }, off where the file says nothing, and on and off at once on the page Commissioning or with PUT /api/v1/configuration/commissioning {"enabled": false}. Who signed in says what comes: an account that may run commissioning - the system administrator, unless a role in the file says otherwise - is a tool, a WebSocket login with an SSH key a charging station. The tool is a networking node of its own, named after its account and never the CSMS; its connection is read as the controller's line up, so that what it asks is answered by the controller, and not sent on to the CSMS as a station's request is. Switched off, every tool is let go of at once, and no station.

The grid operator the charging pool is connected behind may limit it over OpenADR 3: the controller is then a VEN of the grid operator's VTN, as the openADR section says - "openADR": { "enabled": true, "vtnURL": "https://grid.example/openadr3/", "clientID": "lc-paradies" }, switched off unless somebody says otherwise. The client ID is the VEN name the grid operator gave this controller; the client secret beside it is kept in openadr-credentials.json beside the configuration, written for its owner alone as the CSMS credentials are, and never in the configuration file. The controller signs in with the client credentials grant of OAuth 2.0 at the token URL the VTN names (auth/server, or auth/token below it), keeps the bearer token for most of its life and renews it five minutes before it ends, or at once when the VTN says 401 to it. Every pollEvery seconds - 30 by default - it asks for the events meant for it: each interval of an event is a limit, IMPORT_CAPACITY_LIMIT for what the pool may draw from the grid and EXPORT_CAPACITY_LIMIT for what it may feed in, in kW, and of those in force the lowest of each kind holds. They are logged as they come and go, shown by the JSON API and the command line, and not yet passed on to the charging stations. On every event the controller sends one report, saying what it took from it; which ones it has reported on is asked of the VTN after a start, so none is reported on twice. The VTN's certificate is judged as the CSMS's is. A VTN that cannot be reached is said once, and the limits read last stay until they are over. There is no page for it yet: GET/PUT /api/v1/configuration/openADR, PUT/DELETE .../openADR/credentials with { "clientSecret" }, and POST .../openADR/poll - openadr:read, openadr:edit and openadr:run.

Running it

From the repository that has this one as a submodule (LocalControllerCLI):

dotnet run --project LocalControllerCLI

At the first start there are no accounts, so the controller makes one up for the user root, keeps it under accounts/ and prints the password once:

  ┌─ First start: there were no accounts, so one was made up for you ─────────
  │  user      root
  │  password  QBDD77Lc7HseB-xORuuw8RpX
  │  It is shown here once and kept only as a hash. Write it down.
  └───────────────────────────────────────────────────────────────────────────

Then open http://127.0.0.1:2350/ and sign in.

Recommended for the first start: bring root your own SSH key, for the command line over SSH -

dotnet run --project LocalControllerCLI -- --authorize-ssh-key root=C:\Users\you\.ssh\id_ed25519.pub

Without it, the first start makes up a key pair for root and prints its private key once, below the password, from -----BEGIN OPENSSH PRIVATE KEY----- to the END line, to be saved as a file only you can read. See LocalControllerCLI for signing in with it.

Whoever signs in over SSH gets the command line of the local controller, whichever program runs it: the commands every node has, syncNTS among them; those of every node that serves charging stations, stationKeys and stationPins, which a gateway has as well; and beside them what only a local controller can be told - openADR and serverKeys. The last two are this library's, in LocalController/CommandLine/; stationKeys and stationPins are WWCP_OCPP_Node's, in WWCP_OCPP_Node/Serving/CommandLine/, and ControllerCLI registers them, asking for the controller's stations as its pages do. None of them is the program's, so that a local controller in the test environment can be told the same as one run by LocalControllerCLI.

Port 2350 and not 2348: an OpenChargingCloud charging station uses 2348 and 2349, and a controller and a station are often tried out on the same bench.

Building

dotnet build builds the frontend too: LocalController.csproj runs npm ci (when Frontend/node_modules is missing or older than package.json or package-lock.json) and npm run build (only when something changed under Frontend/src, or under libs/WWCP_Node/Frontend/src, which holds what the web interface of every kind of node shares and is bundled in as @node/...), then embeds every file of Frontend/dist as a manifest resource named cloud.charging.open.LocalController.HTTPRoot.<path> - which is what Hermod's EmbeddedContentSource reads and MapSinglePageApplication serves.

dotnet build                            the whole thing
dotnet build -p:SkipFrontendBuild=true  backend only, reusing the existing dist/ -
                                        and where there is none, no web interface
                                        at all, which is a warning and not an error
npm run watch     (in Frontend/)        rebuild the bundle as it is edited
npm run typecheck (in Frontend/)        tsc --noEmit

While editing the frontend, start the controller with --frontend libs/LocalController/LocalController/Frontend/dist so that it serves the directory npm run watch writes into: a reload in the browser then shows the change, without rebuilding the C# side.

The tests

dotnet test libs/LocalController/LocalControllerTests

They start real controllers and talk to them over HTTP the way the browser does: the bundle is served, the sign-in works, a change to the name servers reaches both the shared DNS client and the file, the log filters, the event stream delivers, and a controller that is told to stop stops.

What of that every node has to answer alike is WWCP_Node's conformance suite, NodeConformanceTests in WWCP_Node_TestKit, which LocalControllerConformance runs against a local controller - see WWCP_Node's README. What the node below does without a web interface in front of it - its log, its clock, its configuration file, its start - is tested in WWCP_Node's own suite, once for every kind of node. The rest is what only a local controller does: its CSMS, its station port, its OCPP identity and its section of the file, the roles and resources that are its own, and the name its log files go by. The stores of the station port - its logins and groups, its accepted chains, its keys and certificates, the section itself - are WWCP_OCPP_Node's, and so are their tests (WWCP_OCPP_Node_Tests/Serving); what a controller does with them is tested here.

Each test gets a controller of its own, on a port from the kit's TestPorts - one the operating system has just confirmed is free, and that no other test of the run has been handed - and with its own directory for the two files a controller writes: so they neither fight with each other nor with a controller somebody has running on 2350 while they work.

They never touch the network. The configuration written before each controller is built switches the time client off, which is what stops the clock check from being scheduled at all; the conformance suite's few tests that need it on hold it to a server on this machine that nothing answers on. The DNS client is only ever asked what it is configured as. A test suite that needs a name server to answer is a test suite that fails on a train.

Name resolution and the time servers

Both are read from configuration.json, in the same two sections the vehicle, the charging station and the energy meter use, so one file can be written once and copied between them:

{
  "dns": { "enabled": true, "servers": [ "192.168.1.1" ] },
  "nts": { "groups": {
    "legal": { "enabled": true,
               "servers": [ "ptbtime1.ptb.de", "ptbtime2.ptb.de",
                            "ptbtime3.ptb.de", "ptbtime4.ptb.de" ],
               "minServers": 2,
               "checkEverySeconds": 900,
               "legalTimeAuthority": "PTB" }
  } }
}

That dns block is one name server, asked over UDP on port 53. An entry of its servers is an address or a host name, or an object saying more than that - the form the DNS page writes the list back in:

{ "address": "192.168.1.1", "port": 53, "transport": "UDP", "queryTimeoutSeconds": 2 }

udp://192.168.1.1:53 is how the log names a name server, not a form the file takes. A file saying it is refused at the start, with the entry named.

That nts block is what a local controller asks when the file says nothing at all: one group of time servers, legal, the PTB's four, of which two have to answer. Further groups stand beside it under groups, each with servers of its own; a section that names its servers outside groups - the flat form of older files - is refused at the start, and says to move them into nts.groups.legal. Naming them changes nothing; it is written out here because a file that names its time servers is a file somebody can check.

Every key of the section, and what it is when absent:

Key Default
enabled true whether to ask at all
servers the four above a list, see below
minServers 2, or all of them when fewer how many must answer for the group to have a time
maxDeviationSeconds 60 how far apart they may be before it is written down
hostname - one server instead of a list
ntsKEPort, ntpPort 4460, 123 for that one server
timeoutSeconds 10 per request of that one server
checkEverySeconds 900 how often the clock is checked
legalTimeAuthority - who the operator says stands behind it
legalTimeToleranceSeconds 1 how far off the clock may be
legalTimeMaxAgeSeconds 3600 how old the last check may be

An entry of servers is a host name, or an object saying more than the name:

{ "hostname": "time.local", "priority": 0, "ntsKEPort": 4460, "enabled": true }

Servers sharing a priority are one band and are asked together; a lower priority is asked first. The four above share priority 0, because they are peers - putting them in separate bands would say something about them that is not true.

A section naming a single hostname and no list becomes a group of one, which is what every file written before there were groups says, and it keeps working. A group of one is held to a quorum of one, and a section asking two of it is refused.

A section that is absent is not a section set to nothing: it means the file has no opinion, and what the constructor was handed stands. The same holds key by key - a section mentioning nothing but enabled leaves the servers alone rather than quietly reducing four to one, and one mentioning nothing but minServers or maxDeviationSeconds holds the servers the controller already has to it. A quorum those servers could never reach is refused: at the start, before anything is asked, and over the API, before anything is written into the file - as is a save that would leave the file one the next start refuses.

A host name written back into this file carries the root label - ptbtime1.ptb.de. - because that is the absolute form it was parsed into, and not a stray character. What the controller prints for somebody to read drops it again.

A time server, and a name server asked over TLS or HTTPS, may be held to a certificate or a root, and may learn one on first use - see WWCP_Node's README. What is learned is written into the server's entry at the first key exchange or handshake after a save, mostly with the NTS or DNS page still open. So the pages send every server back with what they showed it held to, under pinsAsShown: their next save keeps what was learned in between, and still takes away a pin that was shown and removed there.

The clock

LocalController takes a TimeProvider as its last constructor parameter and hands it to everything of its own that asks what time it is: the timestamp of every log entry, CreatedAt and the uptime the status resource reports. The system clock by default; an NTS-disciplined or a fake one where a test says so. The sign-in sessions are not among them - they belong to the HTTPExt API and run on its clock.

It is the first thing the node below assigns, before the event log is built, because the log stamps its entries with it - a clock set afterwards would leave the log reading the system one, which is a log that cannot be held against anything.

sealed class FixedClock(DateTimeOffset Start) : TimeProvider
{
    public DateTimeOffset Now { get; set; } = Start;
    public override DateTimeOffset GetUtcNow() => Now;
}

var clock           = new FixedClock(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero));
var localController = new LocalController(TimeProvider: clock);

var at    = localController.CreatedAt;               // 2000-01-01T00:00:00Z
clock.Now = clock.Now.AddHours(13);
var up    = localController.TimeProvider.GetUtcNow() - at;   // 13 hours of uptime

The clock is never set from NTS. Every fifteen minutes the controller asks its time servers what time it is, measures the difference and reports it - and leaves its own clock exactly where it was. Everything below this controller reads the time from here, so a jump backwards would put two meter readings out of order in a record written somewhere else entirely, with nothing in it to say why.

GET /api/v1/clock is that measurement, and the one word it never guesses is "legal": that needs a claim the operator wrote into nts.legalTimeAuthority, a check against those very servers, a recent one, and a small difference. It names the group it is checked against, its servers and how many of them have to answer. Any of those missing and the answer says unverified and names which one in why.

The log

Every entry carries a timestamp, a level (debug, info, notice, warning, error, critical) and any number of tags (http, ocpp, dns, nts, web, auth, ...). The Logs page filters on both - the level counts as a tag, so critical and ocpp can be picked together.

Anything in the local controller can write to it:

localController.Log.Warning("The CSMS did not answer the BootNotification.", "ocpp");

What the libraries below write through Illias' DebugX lands there too, tagged trace plus whatever the controller's own table, LocalController.TraceTags, finds in the text: OCPP going past in both directions, and which side a line is about - the CSMS above or a charging station below. That works in a debug build only: Debug.WriteLine carries [Conditional("DEBUG")], so a release build of those libraries compiles the calls away. --no-trace switches the bridge off.

A program that reads commands on the same console hands the log a way to write around the line being typed, so that an entry arriving mid-word neither lands inside the command nor waits for it:

localController.ShareConsoleWith(cli.WriteBlock);   // line off, entry whole, line back

The few things the log says on stderr about itself - a listener that failed, a log file that cannot be written - go around the line the same way.

Three places keep it, because they answer different questions. The console shows it to whoever started the controller, at the level they chose; the Logs page keeps the last two thousand entries; and a LogPath handed to the constructor writes every entry, down to the debug ones, into one file per UTC day below it - localcontroller-2026-09-24.log, appended to and flushed after each entry. LocalControllerCLI does that below logs/ unless told --no-log-file, since the other two are gone with the process. Nothing is ever deleted. A file that cannot be written is said once on stderr, and the file says how many entries it missed once it can be written again.

The entries are numbered and the number only ever grows. A browser loads a snapshot from /api/v1/logs, which says how far it reaches, and then applies everything newer from /api/v1/events - so a reconnect that replays a few cached events costs bytes and nothing else.

The stream asks, before every entry it sends and at every heartbeat, whether whoever opened it would still be let in. Once the session it was opened with has ended - signed out, expired, or taken back with the account's others - the stream ends too, without the entry, and the browser's next try is answered with a 401. One opened with an API key ends the same way once the key is revoked or has run out, and one opened with Basic auth once its password has changed.

The certificate store

The node's store, with the kinds of TLS in it and none of ISO 15118's, which are a vehicle's: the TLS roots a server this controller connects to may chain to - a time server, a name server over TLS or HTTPS - beside the ones this machine trusts; the server certificates of such servers, kept so that one can be held to its fingerprint; and the TLS identities this controller presents itself, each with its private key - the one it signs in to the CSMS with under security profile 3 among them. It also keeps a TLS server identity, who the web interface is where that is served over HTTPS from the store - "web": { "tls": { "certificate": "store" } } in the configuration file, or --https. --import-certificate tlsServerIdentity=<file> puts one in with --https on the same command line; otherwise it goes in on the Server identities page - brought with its key, or its key made there before HTTPS is switched on - or by copying it in. And it keeps issuing CAs (tlsIntermediate): the CAs between a root and the certificate of a CSMS that connects to the controller and shows its certificate alone, kept to build its chain with and believed nothing by themselves. An identity the controller signs in to its CSMS with that was brought with the certificates of the CAs above it sends them beside its own at every handshake; one brought alone is shown alone. On Windows, the TLS of the operating system sends along only what it finds in a certificate store: those certificates are written into the intermediate store of the user the controller runs as (CurrentUser\CA) when it connects, and stay there - believed for nothing, as it is no store of roots. The store lives in certificates/ beside configuration.json, one file per certificate and an index.json saying what each is called, whether it is switched on and what it is kept for; a file copied into the right directory by hand is taken in at the next start. One certificate may be kept as several kinds - a TLS root and a kind made up, say.

It is looked after on three pages. Certificate store keeps certificates alone, with no private key: the TLS roots and the server certificates - an upload there leaves a key in the box out, and says where it goes. Client identities keeps who the controller is as a client, each with its key: the TLS identities, and the one the CSMS connection signs in with is marked there. An identity is brought with its key, or its key is made on the controller - on the New key tab - and only its signing request and the certificate that answers it ever travel; the Connections page says which one each line up to the CSMS shows. A controller of before kept such keys in ocpp-client-keys/ beside the configuration file: they are moved into the store at the first start that finds them, and a connection that showed one shows the identity it became. Server identities keeps who the web interface is, with its key - brought with it, or made on its New key tab, as a charging station makes it, so that a key need not be carried to the controller - and what the charging station port presents, told the listener ocpp: a certificate an authority issued for a key made on the New key tab, or a server key the stations pin, shown in a self-signed carrier certificate where no certificate issued for it is valid. Its card there - and serverKeys on the command line, and /api/v1/certificates/serverKeys/ocpp - shows the key pin of the current key and of the announced next one, makes either, and switches to the next one, naming the pin it expects; a key never takes the place of what is shown by itself, the current key's carrier is not deleted, switched off or told another listener, and where nothing is valid the port goes on presenting what it presented last. The CSMS reads the pins and switches through EVQICtrlr[TLSServer], and is told of every switch. Each page has three tabs: by usage, every certificate once, and the upload, where certificates are pasted or files dropped and every one of them is kept as every kind ticked.

A TLS root and a server certificate are told what they are for - the name servers, the time servers, or every use - at the upload and later: a root kept for the name servers alone vouches for no time server, and only a root kept for every use vouches for the CSMS. A local controller names no listeners an identity could be shown on some of and not others, so the page offers it no uses of its own; any certificate may be marked with a usage made up, for a configuration or code to name later. The dialog in which a time server or a name server is pinned offers the store's certificates for its service, and a pinned fingerprint the store keeps is named by its label.

It is the node's store and every node's routes, the vehicle's among them - GET and POST /api/v1/certificates, POST /api/v1/certificates/inspect, POST /api/v1/certificates/reload, and GET, PATCH and DELETE /api/v1/certificates/{id} - at certificates:read to look and certificates:edit to change, and the server keys below /api/v1/certificates/serverKeys. The chains the charging station port accepts from charging stations are not in it: they keep the store of their own they have always had, on the page "Accepted chains" - ocpp-client-trust/ beside configuration.json. Like the node's store, the accounts and the logs, it is readable by the account the controller runs under alone - 0700 on Unix, on Windows an access list of that account, SYSTEM and the administrators - and what an older controller left open is taken back at the next start; where the file system cannot do that, the log says so.

The private keys are kept unencrypted, as the vehicle's are, and the page says so as soon as there is one. The identity the CSMS connection signs in with is marked on the page, and is not deleted until another one is chosen - switching it off is what taking it out of service usually means.

A change that is fine in itself, and that its file cannot take, is answered 500 with why: the charging station server and the CSMS connection in the configuration file, the credentials of the line up, the logins and groups, and the accepted chains. What is in effect stays as it was, and a chain written before what is said of it could not be is taken away again, rather than accepted at the next start. These were answered with the status of a refusal, and a full disk was a station "not found". What was wrong with a change is answered as it was; the node's own routes answer the same way.

What is said of an accepted chain is written beside what it replaces and moved over it when it is renamed or switched on or off: a change the disk runs out in leaves what was there whole. Written in its place, it cut that off, and at the next start the chain was not read at all.

A chain is taken away whole or not at all: its files are set aside, as *.removed, before any of them is deleted, and put back where one of them cannot be - held open by somebody, as Windows keeps a file then. Deleted one after the other, the files before that one were gone, and the chain was listed until the next start and gone after it (found by the charging station). A file that cannot be put back, or deleted once all are aside, is left over under its *.removed name, which the next start does not read, and said in the log.

Who may open it

The accounts are Hermod's HTTPExtAPI, mounted at /ext and kept under accounts/: the users, their passwords as PBKDF2-SHA256 PHC strings, the sessions and the API keys. Signing in happens at POST /ext/login - that is the only place that can check a password - and the cookie it sets is what this controller's own API reads. Basic auth and API keys work just as well, because Hermod offers all three.

What somebody may do comes from the user groups they are in. Each group is one role, under the same name, and a role is a list of permissions, each an operation on a resource - written dns:edit. That is the model of every node, described in WWCP_Node under "Who may sign in"; the operations are read, edit and run, and the resources are the node's configuration, dns, nts, certificates, ssh and log, the node's six that a signed OCPP message can ask for - node, reset (a restart once idle), reset-immediate (a restart at once, which cuts every station behind the controller off from the CSMS), state, firmware and signatures - and the three a local controller adds: csms, the line up to the CSMS, stations, the charging stations and which of them may sign in, and openadr, the grid operator's VTN it reads its limits from.

Role May
viewer read everything: *:read
support see what is going on and have it reported again (state:read, state:run), and restart the controller once it is idle (reset:run) - nothing else: no configuration, no log
cpo read everything, and run the site: change the name and time servers and ask them (dns and nts, edit and run), change the line up to the CSMS and the charging stations (csms:edit, stations:edit), make the keys the lines up are connected with and bring their certificates (certificates:run), and the grid operator's VTN and ask it (openadr:edit, openadr:run); restart the controller, once idle and at once, have it send a message and report its state again, and install its firmware (reset:run, reset-immediate:run, node:run, state:run, firmware:edit)
systemadmin everything this controller can be told, the certificates and who may sign what (signatures:edit) included

The viewer, the support and the administrators are the node's, the CPO is the local controller's. The certificates are the one resource only the administrators may change: somebody who can add a certificate authority can let in a charging station that nobody issued a password to. One thing in the store is no such decision, and is certificates:run, which the CPO holds as well: making a key the controller connects to its CSMS with (the New key tab of the identities), bringing the certificate that came back for it - pasted beside the key, which is matched to it - and taking a key back that still waits for one. The upload, where a certificate comes with its key and a root comes at all, is the administrators', and so are the charging station port's keys.

The same roles say who may sign what is sent to the controller itself over OCPP (white paper "Signed OCPP Messages and Signer Roles", section 5.3): a key the controller knows by one of its roles may sign what that role may do on the web page and at the command line, and nothing else. LocalControllerActionPermissions is the table of what each action needs - a Reset once idle reset:run, at once reset-immediate:run; a TriggerMessage node:run, or certificates:edit for a new certificate; InstallCertificate, DeleteCertificate and CertificateSigned certificates:edit; SetNetworkProfile csms:edit; GetLog log:read; SyncNetworkTime and TestTimeServer nts:run; UpdateFirmware firmware:edit; the stations' SSH keys stations:edit and stations:read; the roles and signature policies signatures:edit. SetVariables and GetVariables have no row: each entry is decided by itself, by the resource of its component, and one the signers may not change or read is refused with NotAuthorized while the others are applied - the name servers (DNSClientController, DNSServerController) are dns, the time (ClockCtrlr, NTPController and theirs) nts, the keys of the station port (EVQICtrlr) certificates, the line up to the CSMS (TLSClientController) csms, the station port itself (OCPPServerController) and who may sign in there (StationLoginController, StationLoginGroupController) stations, anything else configuration. The controller shows its name servers and its time over OCPP as a charging station does, through WWCP_OCPP_Node's DeviceModelBridge, and its station port as the page Charging stations shows it: the section webSocketServer, OCPP over SSH and the logging of the port, besides what the port is doing. A CSMS may change all of it, as the page may: what takes effect at the next start - the address, the port, the OCPP and TLS versions, the connections, the pings and the revocation checks - is written down and answered RebootRequired, and switching the port off, HTTP/3 or OCPP over SSH takes effect once the answer is out, even where the CSMS came in on that very port. And the charging stations that may sign in, and their login groups, as the page lists them: an instance of StationLoginController for every station and of StationLoginGroupController for every group. A CSMS lists a station by giving it a first way in - a Password, a TOTPSecret, an SSHKeyAdd or KeyPins - makes a group by its AuthMethods and SecurityProfiles, and takes either away by setting Listed to false. The password and the shared secret of the one-time token are written and never read out, and the CSMS brings them itself: nothing is made up for it, as an answer to SetVariables carries no value back. What the controller forwards is not decided here: the station it goes to holds it against its own resources, and the controller's role is no power of attorney for it. The policy is off by default - the controller then behaves as before it had one.

The roles section of configuration.json adds roles, or says differently what one of them may do - and a role there that names a resource this controller does not have stops the start, rather than quietly granting nothing. A role of the file under the name of one of the node's - viewer or support - says differently what that one may do:

"roles": { "helpdesk": [ "dns:read", "stations:read" ] }

The groups are made at every start, so a group deleted by hand does not leave a role nobody can ever hold again. A group that is none of these, and none the file names, grants nothing - a role this controller has never heard of is a role it cannot enforce.

Membership is asked on every request rather than remembered at the sign-in, so taking somebody out of a group takes effect on their next request. The permissions travel to the browser, spelt out resource by resource, so a page can grey out what somebody may not do - a courtesy, not a lock: every request is checked again on arrival.

Behind a reverse proxy every request comes from the proxy. The web section names the proxies that are believed when they say who the client is, and the one header they say it in - X-Forwarded-For unless it says otherwise; an API key bound to addresses opens the door only from them, and password guesses are counted per client:

"web": { "trustedProxies": [ "127.0.0.1", "::1" ] }

From anybody else, and without the section, the client is the TCP peer, whatever its headers say. How the header is read is described in WWCP_Node under "Who may sign in".

The sign-in's password, every API key and the session cookie travel with every request, and beyond the loopback over plain HTTP they cross the network in the clear; the controller then says so in its log, below its banner and above every page to its administrators. The web section is the way out: HTTPS of the controller's own - with the store's TLS server identity, or certbot's PEM files, read again when they change - with HSTS and a port that redirects to it, or the reverse proxies in front that do the HTTPS and are believed when they say so. --https, --https-cert <file> with --https-key <file>, --redirect-port <number> and --trusted-proxy <address> say the same and win over the file - see WWCP_Node's README.

Your participation

This software is Open Source under the Affero GPL 3.0 license. We appreciate your participation in this ongoing project, and your help to improve it and the e-mobility ICT in general. If you find bugs, want to request a feature or send us a pull request, feel free to use the normal GitHub features to do so. For this please read the Contributor License Agreement carefully and send us a signed copy or use a similar free and open license.

About

Local Controller

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages