ShonP40 / ha-palgate

Palgate Home Assistant integration
Apache License 2.0
7 stars 2 forks source link

Is this integration broken ? #2

Open the-mentor opened 1 year ago

the-mentor commented 1 year ago

I'm running HA 2023.5.4. I've installed the integration and I'm trying to open my building's gate.

I got the AuthToken and RefreshToken from the palgate app via root on my android phone.

i added the gate via the device ID and i tried to use both the AuthToken and RefreshToken but when i try to open the gate i get unauthorized. I saw somewhere that pal gate changed its authentication method and i wanted to see if this integration supports it.

thanks in advance -DM

the-mentor commented 1 year ago

I forgot to mention that I found the AuthToken and refresh token via a rooted Android device in the following path cat /data/data/com.bluegate.app/files/PersistedInstallation.******.json

here is the Is the content with redacted information

{
  "Fid": "redacted-fid",
  "Status": 3,
  "AuthToken": "redacted-token",
  "RefreshToken": "redacted-refresh-token",
  "TokenCreationEpochInSecs": 1684852460,
  "ExpiresInSecs": 604800
}

so i just tried to use the AuthToken from this json file.

nasser83 commented 1 year ago

have you had any luck in making this work ?

the-mentor commented 1 year ago

@nasser83 no luck unfortunately. I kind of abandoned it for the moment

ShonP40 commented 1 year ago

@the-mentor sorry for getting back to you late (GitHub stopped sending me notifications from this repo for whatever reason).

If you get unauthorized in the logs, it means that the token is invalid/not for this API URL.

From what I understand, new tokens aren’t compatible with the API I’ve used here or they just need a different request to work.

I’m waiting for the folks over at https://github.com/RoeiOfri/homebridge-palgate-opener/issues/17 to figure this out so I could update the integration to support it.

ShonP40 commented 1 year ago

My token got invalidated a while ago so I can’t push any more updates to this integration atm but I can confirm that it’s still working as is if you use a proper token.

vrublevskys commented 4 months ago

I did it! Currently I'm reverse engineered android app and found encryption algorithm. I wrote a simple android app, copied encryption function to it, and it works! I could be do a PR, but I newbie in Python. So @ShonP40 I can share my Kotlin/Java code with you. Please, contact me

ShonP40 commented 4 months ago

I did it!

Currently I'm reverse engineered android app and found encryption algorithm. I wrote a simple android app, copied encryption function to it, and it works! I could be do a PR, but I newbie in Python. So @ShonP40 I can share my Kotlin/Java code with you. Please, contact me

Did the token that you get work with this integration?

If so, can you add me to the repo you have for that app?

vrublevskys commented 4 months ago

Did the token that you get work with this integration?

The token generates every time you making request. It's based on user session token.

If so, can you add me to the repo you have for that app?

Invited you in my repo

ostratonov commented 2 months ago

Did the token that you get work with this integration?

The token generates every time you making request. It's based on user session token.

If so, can you add me to the repo you have for that app?

Invited you in my repo

hi, can you invite me as well?

omercnet commented 2 months ago

I did it! Currently I'm reverse engineered android app and found encryption algorithm. I wrote a simple android app, copied encryption function to it, and it works! I could be do a PR, but I newbie in Python. So @ShonP40 I can share my Kotlin/Java code with you. Please, contact me

@vrublevskys please share the code, I'm working on automating this for ha

Knilo commented 2 weeks ago

I would also love to see if I can adapt it into an end to end plugin. Please share access to the repo :)

the-mentor commented 2 weeks ago

I think this is the repo https://github.com/vrublevskys/ha-palgate

ShonP40 commented 2 weeks ago

That repo isn’t enough You still need a way of extracting your token Which can only be done on a rooted Android device at the moment

the-mentor commented 2 weeks ago

@ShonP40 i have the token I extracted on a rooted device but it wasn't enough because of the authentication change Was the HA integration updated to work with the new authentication system?

omercnet commented 2 weeks ago

I have reversed the logic and be to run it locally outside the app in plain Java

Having trouble implementing the logic in python

On Sun, 22 Sep 2024 at 16:31 Avri Chen-Roth @.***> wrote:

@ShonP40 https://github.com/ShonP40 i have the token I extracted on a rooted device but it wasn't enough because of the authentication change Was the HA integration updated to work with the new authentication system?

— Reply to this email directly, view it on GitHub https://github.com/ShonP40/ha-palgate/issues/2#issuecomment-2366789547, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE4FQXYYWX7RMG34G2T3DLZX3BBRAVCNFSM6AAAAAAYNPPFBCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNRWG44DSNJUG4 . You are receiving this because you commented.Message ID: @.***>

Knilo commented 2 weeks ago

Why can’t you call that logic from python using something like py4j?

also if you share the code we would all be happy to help translate it to python

3052 commented 2 weeks ago

the first request seems to be basically this:

POST https://api1.pal-es.com/v1/bt/un/k11 HTTP/2.0

its the second request thats failing for me:

POST https://api1.pal-es.com/v1/bt/un/verify/start/+12345678901?countryCode=us&os=android HTTP/2.0

{
  "v": 1,
  "s": "cbcaffb0-2d70-4dab-bc99-b475cb5028f0",
  "b": "F883B121D238F41D930F281C7A742A1ED75ACD96079AB58B3961CA17B86E993C87B6...",
  "type": "sms",
  "k": "EC7FF1016262879E2075220E428216F3"
}

HTTP/2.0 400 

{"status":"failed","msg":"Unable to register: Security check not passed!"}
omercnet commented 2 weeks ago

Why can’t you call that logic from python using something like py4j?

also if you share the code we would all be happy to help translate it to python

it requires installing java with HA - which is not supported

we can definitely have an alpha plugin that requires it but don't think it'll be adopted by the community

ShonP40 commented 2 weeks ago

Also, there’s another way of linking PalGate gates into HA You can just link PalGate into Google Home & then have HA call a Google Assistant action to trigger it

omercnet commented 2 days ago

I can build an addon that will solve this - would you guys want that? or just an plain integration?

the problem is that java is required in order to run, in an addon I can add whatever I want but I can't require java in a plain integration

wdyt?

3052 commented 2 days ago

@omercnet just post the source code to your solution

omercnet commented 1 day ago

@omercnet just post the source code to your solution

you are so kind <3

here's the source code to generate a token

package com.bluegate.shared;

public class FaceDetectNative {

    static {
        java.lang.System.loadLibrary("native-lib");
    }

    public static void main(String[] args) throws Exception {
        long ts = 1L + System.currentTimeMillis() / 1000;
        String userId = "<USERID>";
        String sessionToken = "<SESSION TOKEN>";
        String token = intToHexString(
                FaceDetectNative.getFacialLandmarks(hexStringToByteArray(sessionToken), ts, Long.parseLong(userId), 1));

        System.out.println(token);
    }

    static String intToHexString(int[] iArr) {
        StringBuilder sb2 = new StringBuilder();
        int length = iArr.length;

        for (int i10 = 0; i10 < length; i10++) {
            sb2.append(String.format("%02X", new Object[] { Integer.valueOf(iArr[i10]) }));
        }

        return sb2.toString();
    }

    static byte[] hexStringToByteArray(String str) {
        int length = str.length();

        byte[] bArr = new byte[(length / 2)];
        for (int i10 = 0; i10 < length; i10 += 2) {
            bArr[i10 / 2] = (byte) (Character.digit(str.charAt(i10 + 1), 16)
                    + (Character.digit(str.charAt(i10), 16) << 4));
        }

        return bArr;
    }

    public static native int[] getFacialLandmarks(byte[] bArr, long j, long j2, int i);

}

but it requires java and the libnative-lib.so for the right platform

that's why I'm trying to say, it must be an addon or an integration with py4j (that requires java)

I'll start working on an addon because that's easiest, will try a simple integration after that

omercnet commented 1 day ago

I have it working.. working on packing it now into an integration

3052 commented 1 day ago

hm actually if I rename to native-lib.dll I get close. with x86:

Exception in thread "main" java.lang.UnsatisfiedLinkError: native-lib.dll: Can't load this .dll (machine code=0x34) on a AMD 64-bit platform

with x86_64:

Exception in thread "main" java.lang.UnsatisfiedLinkError: native-lib.dll: Can't load this .dll (machine code=0x6556) on a AMD 64-bit platform