Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authorizekey allows too few characters #304

Open
baldur4464 opened this issue Jan 16, 2024 · 7 comments
Open

Authorizekey allows too few characters #304

baldur4464 opened this issue Jan 16, 2024 · 7 comments

Comments

@baldur4464
Copy link

Hello, I am currently working on a project that automatically checks incoming messages for plausibility. During development, I came across a problem.

My project emulates a Central System (CS) and I first tested it with a Chargepoint (CP) simulation (Open-OCPP). The CP was always able to connect to the CS.

When we then tried to test my project on a real charge point, no connection was established. This always resulted in a 404 Websocket Upgrade Failure. Since we had no further debug information, I used Wireshark to check the incoming and outgoing messages.

I noticed that the CP's AuthorizeKey contains more than 20 characters. I then checked in your code how this key is checked and there I noticed that the length must be between 16 - 20 characters long and if this condition is not met, the websocket cannot be established.

Now the question arises, is there a reason why the characters are limited to 20 characters? Otherwise, I would like to suggest increasing the number of characters, as I do not see a security problem in this case.

@TVolden
Copy link
Member

TVolden commented Jan 19, 2024

Hi @baldur4464,

Thanks for reaching out. I would argue that all limits are defined by the official specification, but I would have to look it up. Does anyone know if the limit is defined by the OCA specification?

A quick fix is to fork the project and remove the limit.

@jmluy
Copy link
Contributor

jmluy commented Jan 22, 2024

This is the description for AuthorizationKey.

The basic authentication password is used for HTTP Basic Authentication, minimal length: 16 bytes.
It is strongly advised to be randomly generated binary to get maximal entropy. Hexadecimal represented (20 bytes maximum, represented as a string of up to 40 hexadecimal digits).
This configuration key is write-only, so that it cannot be accidentally stored in plaintext by the Central System when it reads out all configuration keys.
This configuration key is required unless only "security profile 3 - TLS with client side certificates" is implemented.

@robert-s-ubi
Copy link
Contributor

Unfortunately, this is all wrong! The OCPP 1.6 AuthorizationKey is only represented as 32-40 hexadecimal characters when configured using the ChangeConfigurationRequest (because that only allows strings to be sent as values).

But when the AuthorizationKey is to be used for HTTP Basic Authentication, it MUST BE DECODED and sent as a byte array of 16 to 20 BYTES. The limit of 20 was totally correct.

@rpseng
Copy link

rpseng commented Jun 28, 2024

In this PR it was also changed from bytearray to a String. That is why the length had to be adjusted. In the original code it was not functional, as the decoding was wrong. There was a mixup between the string representation and the bytearray.

@robert-s-ubi
Copy link
Contributor

robert-s-ubi commented Jun 28, 2024

The password IS a byte array of 16 to 20 bytes, as per the OCPP 1.6 specification. Where do you see a mixup with the string representation? The only string representation is the BASE64 encoding, and that is correctly decoded to a byte array.

@rpseng
Copy link

rpseng commented Jun 28, 2024

Hello, the problem I experienced (and only worked with that fix) was when I try to connect to a custom server (using the present library) using a password. I'm using https://github.com/matth-x/MicroOcppSimulator for testing. Unless that simulator is not conforming.

The only physical charger I have is an EVlink, but it does not support a password at all to test.

@robert-s-ubi
Copy link
Contributor

From what I see, MicroOcppSimulator does not support HTTP Basic Authentication at all, and even gets the security profile wrong (HTTP Basic Authentication is Security Profile 1). From src/net_wasm.c:

    if (!auth_key.empty()) {
        MO_DBG_WARN("WASM app does not support Securiy Profile 2 yet");

So that is definitely not a reference for compliant OCPP 1.6 HTTP Basic Authentication handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants