MCPcopy Create free account
hub / github.com/bytespider/Meross / exchangeKeys

Method exchangeKeys

packages/lib/src/device.ts:183–215  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

181 }
182
183 async exchangeKeys() {
184 deviceLogger.info(`Exchanging keys for device ${this.id}`);
185
186 if (!this.encryptionKeys.localKeys) {
187 deviceLogger.debug(`Generating local keys for device ${this.id}`);
188 this.encryptionKeys.localKeys = await generateKeyPair();
189 }
190
191 const { publicKey, privateKey } = this.encryptionKeys.localKeys;
192
193 const message = new ConfigureECDHMessage({ publicKey });
194
195 const {
196 payload: {
197 ecdhe: { pubkey },
198 },
199 } = await this.sendMessage(message);
200
201 const remotePublicKey = Buffer.from(pubkey, 'base64');
202 this.encryptionKeys.remotePublicKey = remotePublicKey;
203
204 // derive the shared key
205 const sharedKey = await deriveSharedKey(privateKey, remotePublicKey);
206
207 // ...and now for the dumb part
208 // Meross take the shared key and MD5 it
209 const sharedKeyMd5 = await md5(sharedKey, 'hex');
210
211 // then use the 32 hex characters as the shared key
212 this.encryptionKeys.sharedKey = Buffer.from(sharedKeyMd5, 'utf8');
213
214 return;
215 }
216
217 async configureDeviceTime(
218 timestamp: number,

Callers 2

exchangeKeysFunction · 0.80
exchangeKeysFunction · 0.80

Calls 4

sendMessageMethod · 0.95
generateKeyPairFunction · 0.85
deriveSharedKeyFunction · 0.85
md5Function · 0.85

Tested by

no test coverage detected