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

Adding GCM encryption support. #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cont1nuity
Copy link

@cont1nuity cont1nuity commented Aug 13, 2024

This adds GCM encryption which can be toogled on via new client option encryptionVersion (1 = ECB, 2 = GCM). It is needed for newer firmware versions and replaces existing ECB for all pack encryptions BUT the scan command, which still runs on ECB for compatibility.

Tested on firmware 362001065279+U-WB05RT13V1.23

This satisfies #22.

@aivus
Copy link
Contributor

aivus commented Aug 13, 2024

@cont1nuity any ideas how to determine on scan command or in any other way that we need to use GCM?

@cont1nuity
Copy link
Author

cont1nuity commented Aug 13, 2024

Unfortunately no. The scan command appears not to return the firmware of all devices nor consistent other version information...
Example from my device:
{"t":"dev","cid":"<mac>","bc":"00000000000000000000000000000000","brand":"gree","catalog":"gree","mac":"<mac>","mid":"10001","model":"gree","name":"","lock":0,"series":"gree","vender":"1","ver":"V2.0.0","ModelType":"32776","hid":"362001065279+U-WB05RT13V1.23.bin"}
Other example where GCM fixed it:
{ "t": "dev", "cid": "<mac>", "bc": "gree", "brand": "gree", "catalog": "gree", "mac": "<mac>", "mid": "3018", "model": "gree", "name": "c605d5a1", "series": "gree", "vender": "1", "ver": "V1.0.0.0", "lock": 0 }

Edit: I don't see any common ground here. I would have gone for scan auto-detection, if I knew where to look. :(

@aivus
Copy link
Contributor

aivus commented Sep 17, 2024

@cont1nuity
Copy link
Author

@cont1nuity JFYI tomikaa87/gree-remote@e5c1065

This might be an indicator. Do we have any reference devices with older firmware? The bad example I posted above might have been another issue, but the symptoms were the same and it was fixed after a GCM implementation was added. I am not sure if V2 is reliable.

The approach in the linked commit is similar, though: if timeout or decryption did not work, then switch to GCM and try again. V2 is just used as an additional indicator.
Do you want this added here as well?

@aivus
Copy link
Contributor

aivus commented Sep 27, 2024

Do we have any reference devices with older firmware?

I have a device with quite old firmware. I cannot test on it right now, but I found a response from it:
https://github.com/aivus/com.gree/blob/db72699c10f7729a18ee3fa7d60f9c6478ef8f26/drivers/gree_cooper_hunter_hvac/network/finder.js#L60-L72

Do you want this added here as well?

I'm just thinking about possible ways for autodetect. Even v1 -> error -> v2 -> success would be great, but I'm not sure how hard to implement it here.

@cont1nuity
Copy link
Author

I tried implementing auto-select initially, but I am not too comfortable with the codebase, so it was not too easy for me and I opted for setting only to get the support on the way.

@inwaar inwaar linked an issue Oct 6, 2024 that may be closed by this pull request
This adds GCM encryption which can be toogled on via new client option `encryptionVersion` (1 = ECB, 2 = GCM). It is needed for newer firmware versions and replaces existing ECB for all pack encryptions BUT the scan command, which still runs on ECB for compatibility.

Tested on firmware 362001065279+U-WB05RT13V1.23
@inwaar
Copy link
Owner

inwaar commented Oct 6, 2024

Hi @cont1nuity, could you check if https://github.com/inwaar/gree-hvac-client/tree/gcm works for you?

@aivus
Copy link
Contributor

aivus commented Oct 13, 2024

@inwaar I pushed the changes to the users and got the next:

>>> cid:502cc6c2bebe: 10/13/2024, 7:47:30 AM
OUT.MSG {
  cols: [
    'Pow',    'Mod',
    'TemUn',  'SetTem',
    'TemSen', 'WdSpd',
    'Air',    'Blo',
    'Health', 'SwhSlp',
    'Lig',    'SwingLfRig',
    'SwUpDn', 'Quiet',
    'Tur',    'SvSt',
    'StHt'
  ],
  mac: '502cc6c2bebe',
  t: 'status'
} IYJW6H1zZnrdR2Sm
>>> cid:502cc6c2bebe: 10/13/2024, 7:47:30 AM
SOCKET.SEND {
  cid: 'app',
  i: 0,
  t: 'pack',
  uid: 0,
  pack: '6/OmY+cRNpUjofbIngY27jLSrnHYBRF2KozGTAPhaylLGP5Nm2H9X3FCe0/excvAmzpV69mg7++/3u+97e2M34OG5Bp5OCcKB62NWP0nNz3ArOuOuWzJ4WooF5mubG0Q9uL8iPlFFqHjXLC+8bIn2w29lwLLNLb5Wwc7/7mAAUBYDjwz8uogzdQ3uxkftOvZPFSRTpkwEnFVLqoqDxyIy6RUwOrjD1DqDjQdg19WkRz8Y8UdLktp8FTilS2Tj0XD',
  tag: undefined
}
>>> cid:502cc6c2bebe: 10/13/2024, 7:47:30 AM
IN.MSG {
  t: 'pack',
  i: 0,
  uid: 0,
  cid: '',
  tcid: 'app',
  pack: 'chbBbqlftcdyI2Y91YQTLsN9iyNcbwHjM7ZrZIGhql3j+I+1sfxVVl1t5u8mB4hsUYJrET3zhDfRvpLhs7lEJjD1vuGHb7hwAWpb238dDT3eoU7L+Uzi4Zy8Dybrzk0OGkLMnFFUKDGEqPpv4CQwoNruyDC9LxL2KghGLExmgdCKUYLfnp4/pOkD1oemQECjsVH1uU/ZUFFVVEobMQKLicTL+aEu8LDtnRfmzkfCPvwcLJRLCfYCWJVLQtG1Rag6HJdnAyQnxQSGOVvaRBUsGH4KTwgpyx4blb+BIjct8R+PTr68Tfw4kx3AgiBxT0itDWeWBuek0SaZ2Ut5KO8sfA=='
}
>>> cid:502cc6c2bebe: 10/13/2024, 7:47:30 AM
IN.MSG.UNPACK {
  t: 'dat',
  uid: 0,
  mac: '502cc6c2bebe',
  cid: '502cc6c2bebe',
  dat: [
    1, 4, 0, 18, 58, 1, 0,
    0, 0, 0,  1,  0, 1, 0,
    0, 0, 0
  ],
  cols: [
    'Pow',    'Mod',
    'TemUn',  'SetTem',
    'TemSen', 'WdSpd',
    'Air',    'Blo',
    'Health', 'SwhSlp',
    'Lig',    'SwingLfRig',
    'SwUpDn', 'Quiet',
    'Tur',    'SvSt',
    'StHt'
  ],
  r: 200
}
>>> cid:9424b8b22c11: 10/13/2024, 7:47:31 AM
SOCKET Reconnecting...
>>> cid:9424b8b22c11: 10/13/2024, 7:47:31 AM
SOCKET.SEND { t: 'scan' }
2024-10-13T07:47:31.902Z [log] [ManagerDrivers] [Driver:gree_cooper_hunter_hvac] [Device:351d6d71-558a-4901-8a2e-b19f1b781eed] [ERROR] Message: ClientConnectTimeoutError: Connecting to HVAC timed out
    at Client._initialize (/node_modules/gree-hvac-client/src/client.js:221:32)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  origin: undefined,
  props: undefined
}
2024-10-13T07:47:31.903Z [log] [ManagerDrivers] [Driver:gree_cooper_hunter_hvac] [Device:351d6d71-558a-4901-8a2e-b19f1b781eed] [offline] mark device offline
>>> cid:9424b8b22c11: 10/13/2024, 7:47:31 AM
IN.MSG {
  t: 'pack',
  i: 1,
  uid: 0,
  cid: '',
  tcid: '',
  pack: 'LP24Ek0OaYogxs3iQLjL4ILtTaJrtujBip3pETNnfhqMa9lM2RqI/KytvJ32IsGSZXrOr+MakVzzXHbghPeyiui/giRwi/22P1NeJSbhyoDt21IYC5nmTB0FSNCtGSQCq+qmiRmaZjpRwuO7Fe5EbibgXFd9QzwqbcON7BL5RO4JPRFZzjLrUDkhvMjz32yVMkOVsFsTAafzePY7qSehbZIhsbG6Ck8X1+GBAEqEtdxSARmdHzsfl0hV7CQKMyULqf7+wHqDf2mz9uzNFv2ejQPpn0gG1yCMDrcqGdH2dZ/aQZM3xU7NrlE38PT7UzxFphjtFkYpY2Dv1B44KKRYoOFBUKk+E+bwkK7C6TnvNoKsH6bNGMeBkcgCC2vvIqV6'
}
>>> cid:9424b8b22c11: 10/13/2024, 7:47:31 AM
IN.MSG.UNPACK {
  t: 'dev',
  cid: '9424b8b22c11',
  bc: '00000000000000000000000000000000',
  brand: 'gree',
  catalog: 'gree',
  mac: '9424b8b22c11',
  mid: '10001',
  model: 'gree',
  name: '',
  lock: 0,
  series: 'gree',
  vender: '1',
  ver: 'V2.0.0',
  ModelType: '32792',
  hid: '362001065279+U-WB05RT13V1.21.bin'
}

tag: undefined is suspicious here. It was working fine with the original changes from @cont1nuity and manual selecting the encryption version

@inwaar
Copy link
Owner

inwaar commented Oct 13, 2024

@aivus do you have a full log of debug messages from a working version?

@aivus
Copy link
Contributor

aivus commented Oct 13, 2024

Found the logs for the same device:

>>> cid:9424b8b22c11: 9/25/2024, 10:51:58 AM
OUT.MSG {
  cols: [
    'Pow',    'Mod',
    'TemUn',  'SetTem',
    'TemSen', 'WdSpd',
    'Air',    'Blo',
    'Health', 'SwhSlp',
    'Lig',    'SwingLfRig',
    'SwUpDn', 'Quiet',
    'Tur',    'SvSt',
    'StHt'
  ],
  mac: '9424b8b22c11',
  t: 'status'
} sjcMkgeKpzQQv3CQ
>>> cid:9424b8b22c11: 9/25/2024, 10:51:58 AM
SOCKET.SEND {
  cid: 'app',
  i: 0,
  t: 'pack',
  uid: 0,
  pack: 'CwLmGn//3AkiCkavv3W1QYelmEi0+Snzc7VwLVcQIcFTDBKjXnqi1krmp9kO8NPHpMR8SjS7CPRpnEkN/NjtmzRC3rTNzUjnPGiajiBADmeMXQ5IUtOMGs/B97W1tbo0hU990WnOWQUyjGkLDP73gSKN0oC3Q0PNxDFLjkolseggBkINQvYQHq/0LZie2h4ViD7/uYTzoN6lXa7TgpMqqm6WHls+vKnLRAoWdCIF5s8=',
  tag: 'FJ15cSuQVcFVEveXlmwmNg=='
}
>>> cid:9424b8b22c11: 9/25/2024, 10:51:58 AM
IN.MSG {
  t: 'pack',
  tag: 'Q3Q06nYtRwHKqC4eDhY9rl==',
  i: 0,
  uid: 0,
  cid: '',
  tcid: 'app',
  pack: 'CwLxVymumlINCjrivT79QfD60Ej1uh60JMInO0kGEJxFakWtTWeirg3ondhC6N3cx5IbWGj7FuRLxAoN/NjLli9CyM21hBineCyKli4lSyPuHU5GTt3wX5jP67vW7uJ20i8rrzCFS3Q8/X0xEMm7mVWN05qpBBvNpXx72RQlya8eJX9bTPhhKK/oPNfh2h4sjDCO5sjouM7GW8XB1INluR7dQFtmvNGFWFxbIh8Tpd6S1HIvYN4OCRbr85cvdD1c8odh4s0MIlMizy8osFNg17jlHZRaj9S1xdFpeP4GHEAXq/ORPhNlF/Z6/l+X/G/OxpidVeYBqXE0rON8ZRY='
}
Message:  {
  t: 'dev',
  cid: '9424b8b22c11',
  bc: '00000000000000000000000000000000',
  brand: 'gree',
  catalog: 'gree',
  mac: '9424b8b22c11',
  mid: '10001',
  model: 'gree',
  name: '',
  lock: 0,
  series: 'gree',
  vender: '1',
  ver: 'V2.0.0',
  ModelType: '32792',
  hid: '362001065279+U-WB05RT13V1.21.bin'
}

If it's not enough, I can ask users to push other logs

@inwaar
Copy link
Owner

inwaar commented Oct 27, 2024

@aivus could you check if this another approach works?
https://github.com/inwaar/gree-hvac-client/tree/public-aes-gcm-poc

@aivus
Copy link
Contributor

aivus commented Nov 22, 2024

Hey @inwaar

Thanks for the update.

It took a while to return back to the topic. I just pushed the changes to the users and will let you know it works for them or not. I'll keep you posted.

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

Successfully merging this pull request may close these issues.

Support of a new encryption method
3 participants