homebridge-lg-thinq-2 2.0.13 → 2.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Change Log
2
2
 
3
+ ## v2.0.15
4
+
5
+ ### Homebridge UI
6
+
7
+ * Fixed the **Plugin Logs** window of the Homebridge UI always being empty. It shows the log lines whose prefix is the platform `name` in the config, and without a `name` it looked for `homebridge-lg-thinq-2`, while Homebridge prefixes this plugin's lines with `LGThinQ`. The config now has `"name": "LGThinQ"` by default: the settings screen adds it to existing configs (click **Save** once), and the README examples include it. Verified in Homebridge UI 5.30.1.
8
+
9
+ ## v2.0.14
10
+
11
+ ### Reliability
12
+
13
+ * The MQTT root certificate and client certificate received from LG are now validated before they are written to disk: they must be PEM certificates that parse as X.509, with no other content. If LG or the certificate host returns something else, such as an error page, the plugin logs a clear error, writes no file, and retries later, instead of saving it as a certificate and failing with a TLS error. Checked against the real AWS and LG root certificates.
14
+ * Known issue: the legacy root certificate URL (VeriSign G5, only used for MQTT hosts that are neither AWS IoT nor LG) now redirects to the DigiCert home page. It is now reported as an invalid certificate instead of being saved.
15
+
3
16
  ## v2.0.13
4
17
 
5
18
  ### Security
package/README.md CHANGED
@@ -117,6 +117,7 @@ Add the platform to the `platforms` section of your Homebridge `config.json`:
117
117
  ```json
118
118
  {
119
119
  "platform": "LGThinQ",
120
+ "name": "LGThinQ",
120
121
  "auth_mode": "token",
121
122
  "refresh_token": "refresh-token-from-lg-login",
122
123
  "country": "US",
@@ -130,6 +131,7 @@ To add only some devices, or to set device options, list the devices by id:
130
131
  ```json
131
132
  {
132
133
  "platform": "LGThinQ",
134
+ "name": "LGThinQ",
133
135
  "auth_mode": "token",
134
136
  "refresh_token": "refresh-token-from-lg-login",
135
137
  "country": "US",
@@ -151,6 +153,7 @@ Device ids are shown in the Homebridge log when the plugin discovers devices.
151
153
  | Option | Required | Default | Description |
152
154
  | --- | --- | --- | --- |
153
155
  | `platform` | Yes | | Must be `LGThinQ`. |
156
+ | `name` | No | `LGThinQ` | Prefix of this plugin in the Homebridge log. The **Plugin Logs** window of the Homebridge UI shows the log lines with this prefix, so it stays empty without a name. The settings screen adds it. |
154
157
  | `auth_mode` | Yes | `account` | `token` to sign in with a refresh token, or `account` to sign in with username and password. |
155
158
  | `refresh_token` | With `token` | | Refresh token from the LG login (Homebridge UI or `thinq` command). |
156
159
  | `username` | With `account` | | LG ThinQ account username. |
@@ -5,6 +5,12 @@
5
5
  "customUi": true,
6
6
  "strictValidation": false,
7
7
  "schema": {
8
+ "name": {
9
+ "title": "Name",
10
+ "type": "string",
11
+ "default": "LGThinQ",
12
+ "description": "Prefix of this plugin in the Homebridge log. The Plugin Logs window shows the log lines with this prefix."
13
+ },
8
14
  "auth_mode": {
9
15
  "title": "Auth Mode",
10
16
  "type": "string",
@@ -1,3 +1,4 @@
1
+ import { X509Certificate } from 'crypto';
1
2
  import * as FS from 'fs';
2
3
  import * as Path from 'path';
3
4
  import forge from 'node-forge';
@@ -113,8 +114,43 @@ export async function writeIfChanged(path, content, mode) {
113
114
  await FS.promises.chmod(path, mode);
114
115
  }
115
116
  }
117
+ const PEM_CERTIFICATE_BLOCK = /-----BEGIN CERTIFICATE-----\r?\n[\s\S]*?-----END CERTIFICATE-----/g;
118
+ /**
119
+ * Checks that certificate data received from LG is one or more PEM certificates,
120
+ * and returns it. Throws without including the data, which could be anything,
121
+ * such as an HTML error page.
122
+ *
123
+ * The data is written to disk for the MQTT client, so nothing else is accepted:
124
+ * no text outside the certificate blocks, and every block must parse as an X.509
125
+ * certificate.
126
+ */
127
+ export function validatePemCertificates(data, description) {
128
+ const invalid = (reason) => new Error(`LG returned an invalid ${description} (${reason}); skipping this connection attempt.`);
129
+ if (typeof data !== 'string') {
130
+ throw invalid('not text');
131
+ }
132
+ const blocks = data.match(PEM_CERTIFICATE_BLOCK) ?? [];
133
+ if (blocks.length === 0) {
134
+ throw invalid('no PEM certificate');
135
+ }
136
+ if (data.replace(PEM_CERTIFICATE_BLOCK, '').trim() !== '') {
137
+ throw invalid('unexpected content outside the PEM certificates');
138
+ }
139
+ for (const block of blocks) {
140
+ try {
141
+ new X509Certificate(block);
142
+ }
143
+ catch {
144
+ throw invalid('a PEM block is not a valid X.509 certificate');
145
+ }
146
+ }
147
+ return data;
148
+ }
116
149
  export async function writeMqttCertificateFiles(options) {
117
- const { mqttDir, rootCA, privateKey, certificatePem } = options;
150
+ const { mqttDir, privateKey } = options;
151
+ // Validate both certificates from LG before writing any file.
152
+ const rootCA = validatePemCertificates(options.rootCA, 'MQTT root certificate');
153
+ const certificatePem = validatePemCertificates(options.certificatePem, 'MQTT client certificate');
118
154
  await FS.promises.mkdir(mqttDir, { recursive: true, mode: MQTT_DIRECTORY_MODE });
119
155
  await FS.promises.chmod(mqttDir, MQTT_DIRECTORY_MODE);
120
156
  const paths = mqttCertificatePaths(mqttDir);
@@ -303,6 +303,7 @@
303
303
 
304
304
  <script>
305
305
  const homebridge = window.homebridge;
306
+ const DEFAULT_PLATFORM_NAME = 'LGThinQ';
306
307
  let configForm;
307
308
 
308
309
  const byId = (id) => document.getElementById(id);
@@ -653,6 +654,14 @@
653
654
  }
654
655
  configuration = pluginConfig[0];
655
656
 
657
+ // Homebridge prefixes this plugin's log lines with the config "name", and the
658
+ // Plugin Logs window only shows the lines with that prefix. Without a name the
659
+ // window looks for the package name and shows nothing, so add the default one.
660
+ if (!configuration.name) {
661
+ configuration.name = DEFAULT_PLATFORM_NAME;
662
+ await homebridge.updatePluginConfig([configuration]);
663
+ }
664
+
656
665
  let optionSelected = findCountryLanguageOption(configuration.country, configuration.language);
657
666
  if (!optionSelected) {
658
667
  optionSelected = findCountryLanguageOption('US', 'en-US');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Homebridge LG ThinQ 2",
3
3
  "name": "homebridge-lg-thinq-2",
4
- "version": "2.0.13",
4
+ "version": "2.0.15",
5
5
  "description": "Community-maintained continuation of homebridge-lg-thinq: a Homebridge plugin for controlling/monitoring LG ThinQ devices via the LG ThinQ platform.",
6
6
  "license": "Apache-2.0",
7
7
  "type": "module",