iobroker-community-adapters / ioBroker.solarlog

iobroker Adapter to access your solarlog meter data
MIT License
12 stars 5 forks source link

ACCESS DENIED nach Firmwareupdate, Solar-Log Base 15 6.1.0 Build 163 - 12.04.2024 #221

Open lcd4linux opened 3 months ago

lcd4linux commented 3 months ago

Nach dem letzten Update des SolarLog Base 15 auf die Version 6.1.0 Build 163, werden keine Objekte mehr aktualisiert, wenn der Login passwortgeschützt ist. Im Log wird "ACCESS DENIED" wiederholt gemeldet.

To Reproduce
Steps to reproduce the behavior:

  1. Mit Passwortschutz -> ACCESS DENIED
  2. Ohne Passwortschutz -> scheinbar ohne Fehler

Screenshots & Logfiles
SolarLog_DebugLog.txt SolarLog_DebugLog_ohne_Passwort.txt

Versions:

solarsaver commented 3 months ago

Same issues here with a SL Base 100 after update to 6.1.1 Build 164 - 03.05.2024 - no sync , Access Denied and no errors without set PW but no access to most Objects.

solarresearch commented 3 months ago

PW are somehow hashed in 6.1.1 Build 164 - 03.05.2024, when using the extracted hashed PW in the 2.3.0. adapter Login Succeeds... BUT still ACCESS DENIED on majority of objects

forelleblau commented 2 months ago

Danke für die Meldung. Erstaunlich ist, dass das Login und die Statusprüfung vor der Datenabfrage funktionieren, der Zugriff auf die Daten dann aber nicht gewährt wird. Ich hab leider kein SL Base um den Austausch zwischen WEBUI und SL zu analysieren und herauszufinden was geändert hat. Wenn da jemand aushelfen könnte wäre das sehr hilfreich.

lcd4linux commented 2 months ago

Wenn da jemand aushelfen könnte wäre das sehr hilfreich.

Gerne, wenn ich das irgendwie bewerkstelligen kann. Was muss ich genau tun?

solarresearch commented 2 months ago

Danke für die Meldung. Erstaunlich ist, dass das Login und die Statusprüfung vor der Datenabfrage funktionieren, der Zugriff auf die Daten dann aber nicht gewährt wird. Ich hab leider kein SL Base um den Austausch zwischen WEBUI und SL zu analysieren und herauszufinden was geändert hat. Wenn da jemand aushelfen könnte wäre das sehr hilfreich.

Entschuldigt die verspätete Rückmeldung Mail mit Info zum möglichen Testzugriff an marceladam@gmx.ch geschickt ... hoffe ist angekommen

rubenlangius commented 2 months ago

I ran into similar issues with a project for a client, and since your project has helped me figure out the api of the solarlog I thought it would be nice to help out with the new solarlog login procedure.

According to their release notes they updated the login procedure as follows:

We updated the storage format of all login passwords (User, Installer, Installer/PM) to an up to date cryptographic algorithm. Although the passwords are no longer part of the configuration and don’t change if you apply a configuration."

I found that with the new firmware they provide a "salt" for each user type that is used to hash the password. This can be found under key 550 using the normal /getjp call. I'm using the admin user type which matches with the key 107, other user types use other keys.

The following python code snippet shows how I retrieve the salt and use it to hash the password:

        session = requests.Session()
        payload = "{\"550\":{\"103\":null,\"104\":null,\"106\":null,\"107\":null,\"109\":null,\"110\":null,\"112\":null},\"801\":{\"170\":null}}"
        headers = {
            'Connection': 'keep-alive',
            'Content-Type': 'text/plain',
        }

        try:
            response = requests.request("POST", f"http://{solarLog.get('IPAddress')}/getjp", headers=headers, data=payload, timeout=5)            
        except Exception as err:
            print('Basic solarlog request failed', solarLog.get('MqttTopic'), err)

        salt = response.json().get('550').get('107')

        try:
            if salt != 'QUERY IMPOSSIBLE 000' and salt is not None:
                hashed_password = bcrypt.hashpw(solarLog.get('Pwd').encode(), salt.encode())
                password = hashed_password.decode('utf-8')
            else: 
                password = solarLog.get('Pwd')
        except Exception as err:
            print('Crypto login failed', solarLog.get('MqttTopic') ,err)

        loginResponse = session.post(f"http://{solarLog.get('IPAddress')}/login", data="u=admin&p="+password, timeout=5)

The returned cookie on a login call can be used for subsequent protected calls but in order to make it work I found that I had to add an extra header: 'X-SL-CSRF-PROTECTION': '1'.

With this setup I am able to retrieve data for objects like inverters, sensors. Hope it helps!

forelleblau commented 2 months ago

Thanks a lot to @rubenlangius ! Ich werde versuchen, das im Solarlog-Adapter einzuprogrammieren. Leider kann ich nichts versprechen, was den Termin anbelangt, voraussichtlich komme ich erst gegen Ende Juli dazu - mal sehen. Wenn jemand lieber schneller ist, freue ich mich gerne über einen entsprechenden PR.

solarresearch commented 2 months ago

Just adding the extra header: 'X-SL-CSRF-PROTECTION': '1' as mentionend by @rubenlangius (THANK U!!!) in main.js after line 199 and using the extracted hashed password seems to work( no more access denied) , and has no negativ effect on solarlogs with older firmware. for now that helps me with further testing