Skip to content

Commit 6fdeca9

Browse files
committed
Make the riot-desktop callback args more generic and encrypt the args
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent 67cf1e7 commit 6fdeca9

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

electron_app/src/electron-main.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const tray = require('./tray');
3535
const vectorMenu = require('./vectormenu');
3636
const webContentsHandler = require('./webcontents-handler');
3737
const updater = require('./updater');
38-
const {getProfileFromDeeplink, protocolInit} = require('./protocol');
38+
const {getProfileFromDeeplink, protocolInit, getArgs} = require('./protocol');
3939

4040
const windowStateKeeper = require('electron-window-state');
4141
const Store = require('electron-store');
@@ -237,10 +237,8 @@ ipcMain.on('ipcCall', async function(ev, payload) {
237237
case 'getConfig':
238238
ret = vectorConfig;
239239
break;
240-
case 'getUserDataPath':
241-
if (argv['profile-dir'] || argv['profile']) {
242-
ret = app.getPath('userData');
243-
}
240+
case 'getRiotDesktopSsoArgs':
241+
ret = getArgs(argv);
244242
break;
245243

246244
default:

electron_app/src/protocol.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,47 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
const {app} = require('electron');
17+
const {app} = require("electron");
18+
const crypto = require("crypto");
1819

1920
const PROTOCOL = "riot://";
20-
const SEARCH_PARAM = "riot-desktop-user-data-path";
21+
const SEARCH_PARAM = "riot-desktop-args";
2122

2223
const processUrl = (url) => {
2324
if (!global.mainWindow) return;
2425
console.log("Handling link: ", url);
2526
global.mainWindow.loadURL(url.replace(PROTOCOL, "vector://"));
2627
};
2728

29+
const algorithm = "aes-192-cbc";
30+
31+
const getKeyIv = () => ({
32+
key: crypto.scryptSync(app.getPath("exe"), "salt", 24),
33+
iv: Buffer.alloc(16, 0),
34+
});
35+
36+
const encrypt = (plaintext) => {
37+
const {key, iv} = getKeyIv();
38+
const cipher = crypto.createCipheriv(algorithm, key, iv);
39+
let ciphertext = cipher.update(plaintext, "utf8", "hex");
40+
ciphertext += cipher.final("hex");
41+
return ciphertext;
42+
};
43+
44+
const decrypt = (ciphertext) => {
45+
const {key, iv} = getKeyIv();
46+
const decipher = crypto.createDecipheriv(algorithm, key, iv);
47+
let plaintext = decipher.update(ciphertext, "hex", "utf8");
48+
plaintext += decipher.final("utf8");
49+
return plaintext;
50+
};
51+
2852
module.exports = {
53+
getArgs: (argv) => {
54+
if (argv['profile-dir'] || argv['profile']) {
55+
return encrypt(app.getPath('userData'));
56+
}
57+
},
2958
getProfileFromDeeplink: (args) => {
3059
// check if we are passed a profile in the SSO callback url
3160
const deeplinkUrl = args.find(arg => arg.startsWith('riot://'));
@@ -34,7 +63,7 @@ module.exports = {
3463
if (parsedUrl.protocol === 'riot:') {
3564
const profile = parsedUrl.searchParams.get(SEARCH_PARAM);
3665
console.log("Forwarding to profile: ", profile);
37-
return profile;
66+
return decrypt(profile);
3867
}
3968
}
4069
},

src/vector/platform/ElectronPlatform.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ export default class ElectronPlatform extends VectorBasePlatform {
230230
}
231231

232232
// we assume this happens before any SSO actions occur but do not block.
233-
this._ipcCall('getUserDataPath').then(userDataPath => {
234-
this.userDataPath = userDataPath;
233+
this._ipcCall('getRiotDesktopSsoArgs').then(riotDesktopSsoArgs => {
234+
this.riotDesktopSsoArgs = riotDesktopSsoArgs;
235235
});
236236
}
237237

@@ -429,8 +429,8 @@ export default class ElectronPlatform extends VectorBasePlatform {
429429
getSSOCallbackUrl(hsUrl: string, isUrl: string): URL {
430430
const url = super.getSSOCallbackUrl(hsUrl, isUrl);
431431
url.protocol = "riot";
432-
if (this.userDataPath) {
433-
url.searchParams.set("riot-desktop-user-data-path", this.userDataPath);
432+
if (this.riotDesktopSsoArgs) {
433+
url.searchParams.set("riot-desktop-args", this.riotDesktopSsoArgs);
434434
}
435435
return url;
436436
}

0 commit comments

Comments
 (0)