From 2b6d70a525ae9b089aecef4be563a07c0e2c5ea9 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Tue, 30 Apr 2019 19:16:05 +0200 Subject: [PATCH] Avoid using randomBytes() when encrypting options This way we avoid delaying the opening of a project when reusing an existing Atom window. --- src/main-process/atom-application.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main-process/atom-application.js b/src/main-process/atom-application.js index cec7fe67e..63be2b7d7 100644 --- a/src/main-process/atom-application.js +++ b/src/main-process/atom-application.js @@ -87,10 +87,15 @@ const createSocketSecret = async (atomVersion) => { return socketSecret } -const encryptOptions = async (options, secret) => { +const encryptOptions = (options, secret) => { const message = JSON.stringify(options) - const initVector = await getRandomBytes(16) + // Even if the following IV is not cryptographically secure, there's a really good chance + // it's going to be unique between executions which is the requirement for GCM. + const initVectorHash = crypto.createHash('sha1') + initVectorHash.update(Date.now() + '') + initVectorHash.update(Math.random() + '') + const initVector = initVectorHash.digest() const cipher = crypto.createCipheriv('aes-256-gcm', secret, initVector) @@ -148,12 +153,10 @@ class AtomApplication extends EventEmitter { return new Promise(resolve => { const client = net.connect({path: socketPath}, () => { - encryptOptions(options, socketSecret).then((encryptedOptions) => { - client.write(encryptedOptions, () => { - client.end() - app.quit() - resolve(null) - }) + client.write(encryptOptions(options, socketSecret), () => { + client.end() + app.quit() + resolve(null) }) })