From e86af198886f8a09e56e975e109928331b7aac58 Mon Sep 17 00:00:00 2001 From: meriadec Date: Fri, 19 Oct 2018 16:42:47 +0200 Subject: [PATCH 01/14] Implement shasum & signature check on auto-update --- package.json | 1 + src/config/errors.js | 5 + src/main/autoUpdate.js | 32 ----- src/main/bridge.js | 11 -- src/main/updater/createAppUpdater.js | 86 +++++++++++++ src/main/updater/createElectronAppUpdater.js | 62 ++++++++++ src/main/updater/createMockAppUpdater.js | 40 ++++++ src/main/updater/ledger-pubkey.js | 111 +++++++++++++++++ src/main/updater/mocks/mock-privkey-1.asc | 33 +++++ src/main/updater/mocks/mock-privkey-2.asc | 33 +++++ src/main/updater/mocks/mock-pubkey-1.asc | 19 +++ src/main/updater/mocks/mock-pubkey-2.asc | 19 +++ src/main/updater/mocks/pubkey-1.asc | 52 ++++++++ src/main/updater/mocks/pubkey-2.asc | 52 ++++++++ ...r-live-desktop-1.2.1-linux-x86_64.AppImage | 1 + ...ktop-1.2.1-linux-x86_64.AppImage.sha512sum | 1 + ...-1.2.1-linux-x86_64.AppImage.sha512sum.sig | 16 +++ .../mocks/sigko-shasumok/update-info.json | 3 + ...r-live-desktop-1.2.1-linux-x86_64.AppImage | 1 + ...ktop-1.2.1-linux-x86_64.AppImage.sha512sum | 1 + ...-1.2.1-linux-x86_64.AppImage.sha512sum.sig | 16 +++ .../mocks/sigok-shasumko/update-info.json | 3 + ...r-live-desktop-1.2.1-linux-x86_64.AppImage | 1 + ...ktop-1.2.1-linux-x86_64.AppImage.sha512sum | 1 + ...-1.2.1-linux-x86_64.AppImage.sha512sum.sig | 16 +++ .../mocks/sigok-shasumok/update-info.json | 3 + src/main/updater/pgpHelper.js | 40 ++++++ src/main/updater/updater.spec.js | 114 ++++++++++++++++++ yarn.lock | 111 ++++++++++++++++- 29 files changed, 836 insertions(+), 48 deletions(-) delete mode 100644 src/main/autoUpdate.js create mode 100644 src/main/updater/createAppUpdater.js create mode 100644 src/main/updater/createElectronAppUpdater.js create mode 100644 src/main/updater/createMockAppUpdater.js create mode 100644 src/main/updater/ledger-pubkey.js create mode 100644 src/main/updater/mocks/mock-privkey-1.asc create mode 100644 src/main/updater/mocks/mock-privkey-2.asc create mode 100644 src/main/updater/mocks/mock-pubkey-1.asc create mode 100644 src/main/updater/mocks/mock-pubkey-2.asc create mode 100644 src/main/updater/mocks/pubkey-1.asc create mode 100644 src/main/updater/mocks/pubkey-2.asc create mode 100644 src/main/updater/mocks/sigko-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage create mode 100644 src/main/updater/mocks/sigko-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum create mode 100644 src/main/updater/mocks/sigko-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum.sig create mode 100644 src/main/updater/mocks/sigko-shasumok/update-info.json create mode 100644 src/main/updater/mocks/sigok-shasumko/ledger-live-desktop-1.2.1-linux-x86_64.AppImage create mode 100644 src/main/updater/mocks/sigok-shasumko/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum create mode 100644 src/main/updater/mocks/sigok-shasumko/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum.sig create mode 100644 src/main/updater/mocks/sigok-shasumko/update-info.json create mode 100644 src/main/updater/mocks/sigok-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage create mode 100644 src/main/updater/mocks/sigok-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum create mode 100644 src/main/updater/mocks/sigok-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum.sig create mode 100644 src/main/updater/mocks/sigok-shasumok/update-info.json create mode 100644 src/main/updater/pgpHelper.js create mode 100644 src/main/updater/updater.spec.js diff --git a/package.json b/package.json index e1702c32..1896a7f7 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "lru-cache": "^4.1.3", "measure-scrollbar": "^1.1.0", "moment": "^2.22.2", + "openpgp": "^4.2.1", "qrcode": "^1.2.0", "qrloop": "0.8.1", "qs": "^6.5.1", diff --git a/src/config/errors.js b/src/config/errors.js index c9ea06a3..493f5fa8 100644 --- a/src/config/errors.js +++ b/src/config/errors.js @@ -51,3 +51,8 @@ export const FeeNotLoaded = createCustomErrorClass('FeeNotLoaded') export const NoDBPathGiven = createCustomErrorClass('NoDBPathGiven') export const DBWrongPassword = createCustomErrorClass('DBWrongPassword') export const DBNotReset = createCustomErrorClass('DBNotReset') + +// auto-update errors +export const UpdateIncorrectHash = createCustomErrorClass('UpdateIncorrectHash') +export const UpdateIncorrectSig = createCustomErrorClass('UpdateIncorrectSig') +export const UpdateFetchFileFail = createCustomErrorClass('UpdateFetchFileFail') diff --git a/src/main/autoUpdate.js b/src/main/autoUpdate.js deleted file mode 100644 index 1b50e078..00000000 --- a/src/main/autoUpdate.js +++ /dev/null @@ -1,32 +0,0 @@ -// @flow - -import { app, BrowserWindow } from 'electron' -import { autoUpdater } from 'electron-updater' - -type SendFunction = (type: string, data: *) => void - -export default (notify: SendFunction) => { - autoUpdater.on('checking-for-update', () => notify('checking')) - autoUpdater.on('update-available', info => notify('updateAvailable', info)) - autoUpdater.on('update-not-available', () => notify('updateNotAvailable')) - autoUpdater.on('error', err => notify('error', err)) - autoUpdater.on('download-progress', progress => notify('downloadProgress', progress)) - autoUpdater.on('update-downloaded', () => notify('downloaded')) - - autoUpdater.checkForUpdatesAndNotify() -} - -export function quitAndInstall() { - setImmediate(() => { - const browserWindows = BrowserWindow.getAllWindows() - - // Fixes quitAndInstall not quitting on macOS, as suggested on - // https://github.com/electron-userland/electron-builder/issues/1604#issuecomment-306709572 - app.removeAllListeners('window-all-closed') - browserWindows.forEach(browserWindow => { - browserWindow.removeAllListeners('close') - }) - - autoUpdater.quitAndInstall(false) - }) -} diff --git a/src/main/bridge.js b/src/main/bridge.js index e302d559..e6527fa4 100644 --- a/src/main/bridge.js +++ b/src/main/bridge.js @@ -12,7 +12,6 @@ import user from 'helpers/user' import { resolveLogsDirectory, cleanUpBeforeClosingSync } from 'helpers/log' import { deserializeError } from 'helpers/errors' -import setupAutoUpdater, { quitAndInstall } from './autoUpdate' import { setInternalProcessPID } from './terminator' import { getMainWindow } from './app' @@ -145,13 +144,3 @@ ipcMain.on('sentryLogsChanged', (event, payload) => { if (!p) return p.send({ type: 'sentryLogsChanged', payload }) }) - -// TODO move this to "command" pattern -ipcMain.on('updater', (event, { type, data }) => { - const handler = { - init: setupAutoUpdater, - quitAndInstall, - }[type] - const send = (type: string, data: *) => event.sender.send('updater', { type, data }) - handler(send, data, type) -}) diff --git a/src/main/updater/createAppUpdater.js b/src/main/updater/createAppUpdater.js new file mode 100644 index 00000000..1346040e --- /dev/null +++ b/src/main/updater/createAppUpdater.js @@ -0,0 +1,86 @@ +// @flow + +import { UpdateIncorrectHash, UpdateIncorrectSig } from 'config/errors' +import * as pgpHelper from './pgpHelper' + +type Opts = { + filename: string, + computeHash: () => Promise, + getNextKey: (?string) => Promise, + getNextKeySignature: string => Promise, + getHashFile: () => Promise, + getHashFileSignature: () => Promise, +} + +export default function createAppUpdater(opts: Opts): { verify: () => Promise } { + const { + filename, + computeHash, + getNextKey, + getNextKeySignature, + getHashFile, + getHashFileSignature, + } = opts + + // main logic: + // - fetch hashFile + its signature + // - verify signature + // - compare hash with update hash + // throw if any step fail. + async function verify() { + const [hashFile, hashFileSignature] = await Promise.all([getHashFile(), getHashFileSignature()]) + await verifyHashFileSignature(hashFile, hashFileSignature, await getNextKey()) + await compareHash(hashFile) + } + + // compute the update hash and compare it to the hash located in hash file + async function compareHash(hashFile) { + const computedHash = await computeHash() + const hashFromFile = extractHashFromHashFile(hashFile, filename) + if (hashFromFile !== computedHash) { + throw new UpdateIncorrectHash(computedHash) + } + } + + // verify hash signature with given pubkey + // if it fails, try to get next key and repeat + // if no more key, throw + async function verifyHashFileSignature(hash, sigContent, pubKey) { + try { + await pgpHelper.verify(hash, sigContent, pubKey) + } catch (err) { + try { + const nextPubKey = await getNextPubKey(pubKey) + await verifyHashFileSignature(hash, sigContent, nextPubKey) + } catch (err) { + throw new UpdateIncorrectSig() + } + } + } + + // fetch the next pubkey based on the previous key fingerprint + // also fetch signature, and verify against previous pubkey + async function getNextPubKey(pubKey) { + const fingerprint = await pgpHelper.getFingerprint(pubKey) + const nextPubKey = await getNextKey(fingerprint) + const nextPubKeySignature = await getNextKeySignature(fingerprint) + await pgpHelper.verify(nextPubKey, nextPubKeySignature, pubKey) + return nextPubKey + } + + return { + verify, + } +} + +// a hash file looks like: " \n " +// we only need the hash for the given filename +function extractHashFromHashFile(hashFile, filename) { + let hash + hashFile.split('\n').find(r => { + const row = r.split(/\s+/) + hash = row[1] === filename ? row[0] : '' + return !!hash + }) + return hash +} diff --git a/src/main/updater/createElectronAppUpdater.js b/src/main/updater/createElectronAppUpdater.js new file mode 100644 index 00000000..166b1057 --- /dev/null +++ b/src/main/updater/createElectronAppUpdater.js @@ -0,0 +1,62 @@ +// @flow + +import crypto from 'crypto' +import path from 'path' +import fs from 'fs' + +import network from 'api/network' +import { UpdateFetchFileFail } from 'config/errors' +import { fsReadFile } from 'helpers/fs' +import createAppUpdater from './createAppUpdater' + +import pubKey from './ledger-pubkey' + +export default async ({ feedURL, updateVersion }: { feedURL: string, updateVersion: string }) => { + const { app } = require('electron') + const updateFolder = path.resolve(app.getPath('userData'), '__update__') + const { fileName: filename } = await readUpdateInfos(updateFolder) + + const hashFileURL = `${feedURL}/ledger-live-desktop-${updateVersion}.sha512sum` + const hashSigFileURL = `${feedURL}/ledger-live-desktop-${updateVersion}.sha512sum.sig` + const keysURL = `${feedURL}/pubkeys` + + return createAppUpdater({ + filename, + computeHash: () => sha512sumPath(path.resolve(updateFolder, filename)), + getHashFile: () => getDistantFileContent(hashFileURL), + getHashFileSignature: () => getDistantFileContent(hashSigFileURL), + getNextKey: (fingerprint: ?string) => + fingerprint ? getDistantFileContent(`${keysURL}/${fingerprint}.asc`) : pubKey, + getNextKeySignature: async (fingerprint: string) => + getDistantFileContent(`${keysURL}/${fingerprint}.asc.sig`), + }) +} + +// read the electron-updater file. we basically only need the filename here, +// because the hash file contains hashes for all platforms (better to have +// only 1 file to sign lel) +export async function readUpdateInfos(updateFolder: string) { + const updateInfoPath = path.resolve(updateFolder, 'update-info.json') + const updateInfoContent = await fsReadFile(updateInfoPath) + return JSON.parse(updateInfoContent) +} + +// compute hash for given path. i guess we only need that here +export function sha512sumPath(filePath: string) { + return new Promise((resolve, reject) => { + const sum = crypto.createHash('sha512') + const stream = fs.createReadStream(filePath) + stream.on('data', data => sum.update(data)) + stream.on('end', () => resolve(sum.digest('hex'))) + stream.on('error', reject) + }) +} + +async function getDistantFileContent(url: string) { + try { + const res = await network({ method: 'GET', url }) + return res.data + } catch (err) { + throw new UpdateFetchFileFail(url) + } +} diff --git a/src/main/updater/createMockAppUpdater.js b/src/main/updater/createMockAppUpdater.js new file mode 100644 index 00000000..84b6045a --- /dev/null +++ b/src/main/updater/createMockAppUpdater.js @@ -0,0 +1,40 @@ +// @flow + +import createAppUpdater from './createAppUpdater' + +export default ({ + filename, + computedHash, + hashFile, + signature, + pubKey, + pubKeys, +}: { + filename: string, + computedHash: string, + hashFile: string, + signature: string, + pubKey: string, + pubKeys: Array<{ fingerprint: string, content: string, signature: string }>, +}) => + createAppUpdater({ + filename, + computeHash: () => Promise.resolve(computedHash), + getHashFile: () => Promise.resolve(hashFile), + getHashFileSignature: () => Promise.resolve(signature), + getNextKey: async (fingerprint: ?string) => { + if (!fingerprint) return Promise.resolve(pubKey) + const key = pubKeys.find(k => k.fingerprint === fingerprint) + if (!key) { + throw new Error(`Cannot find key for fingerprint ${fingerprint}`) + } + return key.content + }, + getNextKeySignature: async (fingerprint: string) => { + const key = pubKeys.find(k => k.fingerprint === fingerprint) + if (!key) { + throw new Error(`Cannot find signature for key ${fingerprint}`) + } + return key.signature + }, + }) diff --git a/src/main/updater/ledger-pubkey.js b/src/main/updater/ledger-pubkey.js new file mode 100644 index 00000000..f39f2859 --- /dev/null +++ b/src/main/updater/ledger-pubkey.js @@ -0,0 +1,111 @@ +// TODO: it's actually my key. replace with qorum key. + +export default `-----BEGIN PGP PUBLIC KEY BLOCK----- + +mQINBFvQ9SEBEADbDiM5dfhqdZae0QFSd9QVf8k7hmt+7Ybz4vwRN+s3Xfz9feBC +QBu/UePLpc18Jb1nnHUa7bf3FRilvCG0Lwl0SrSYJ7dmOPsWqE4lHnuBF1AAzFh0 +MR/I6ydOl9fe6thamzv1a61gV+yp+fSKHS0BUv+jto1XV0YOpKnODxOnVIh0n+pf +KpsGSLug0/S6yLZCQPZucTNegZxe96XTaRE61Lr0PrqiOZMtJMSFQ5qzUuvRirSg +q2uOosfM0JiCIogr5myXk3NPAv1wD236+J/Rvh6fOxH9jvvpbSHJkeCBQbLnp+/6 +ubkxg3vgqWwSFNxxOuqbyv0h2dEdnmUUAk5nUOkXt4Pj5f/RqSYe3W4TXEGAvVgP +ow4nfEyMEwM/c6frct3iOHLj6D5a4E1DPHxQ6f8WxjtCUQJPvbBpszArPX2jpjPx +6kEmhCRavdR5veXZldOquWeiaGX2SpV9S6YdgcKe9/XnytpryUT6So3pAQBw18md +vj89wThSTDIVGcD5OPE82VmAAFzgBrUBXHYqP2pxq7wL78zV8sjLYVF0Q8eNplNf +mCtI2ppRZYFv+Epr0N02urSuvS8uim/ZBtaHfV/7vD7h5prNVEVv+kLvXjNSl3p6 +ShCm8V0dtbVoQ4Vh3HU06t3jOg0YXu1o+KopezT58v9kl9N4yUgJmXDfUQARAQAB +tCtNZXJpYWRlYyBQaWxsZXQgPG1lcmlhZGVjLnBpbGxldEBnbWFpbC5jb20+iQJU +BBMBCAA+FiEEyrtcOETZkizulGGq/pgOS6k/n0MFAlvQ9SECGwEFCQPCZwAFCwkI +BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ/pgOS6k/n0OHhg//Z6y8dFJnRgVOr8yK +BGIYM58mikMpdbt7/XByVW3t8tZqZlhhLfRVU/u6Jz69R1bggbJ1Feii3NQB/E3W +pBX7IEHy5uh/12ldkNISdVLb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NNIiNZkI7qLkICzjbdpL2 +SX7Kzyh2AIa1Rh2Rx0CA8D3louS1wDBnwj072wEZCLylQrc5J2NdwVsyHcioH3F5 +YLwcKtHLvPjQebqnYcQxNFs49TjHBnR8IvwMWiB8bNZBlTr4CzHr4lIqoTVFVopD +OX1kZkqJ2gaj03hbcin9JdzhK1LAKahfhLxD+zMYPTw4K8mzvYtvuvfOZU2BzCfB +l9yvtrF3GXu94iP29sq/QLehl8IF7TyHBZr7a9LEF1boa7GDBkPcFkuKSymTCQii +VFlYGtM46Q063vXBCFg6NnEl/0Qcvurr6RlDhTxOubxKZaZdvUwDAarDqHWpEeXo +edRfWORPob99dvdcajU0yKWXPzqMtaO8Orsm/P9rXq6fR7LVmJ6o7g+gorJDE8aB ++m3OuSSqq19QL8cmwZ1lVMdGOD8+knAxrr1+bq33QdekBycZ+A== +=97OE +-----END PGP PUBLIC KEY BLOCK-----` diff --git a/src/main/updater/mocks/mock-privkey-1.asc b/src/main/updater/mocks/mock-privkey-1.asc new file mode 100644 index 00000000..845fe737 --- /dev/null +++ b/src/main/updater/mocks/mock-privkey-1.asc @@ -0,0 +1,33 @@ +-----BEGIN PGP PRIVATE KEY BLOCK----- + +lQHYBFv8BAcBBADRLTFoRU3IUz37E70wy2jv7jg7QLSoHnJglcUYzq+RCBnQAfxQ +NOcQtJDKOJyo1v3819o5pxnrxWAutM/CNpjanzcWM1yLfHjrKo8BbHlmIbWBmV7w +8te+rm/VlyNi30D1eIIJy276nByW4rMLcfFe4T055xbEvRNvQzR+KfrCBwARAQAB +AAP8Dv3XMart5TKaGZmTkKCzd6ayHwUHLZlpByUUyC9gA9v5xZ+uzqzL9rWKPwQJ +rkwiTfHGcSVZxT0TJKXO0hOJpthgqbMnHokIhrYeNrDbU4l4tgE74Ik+8F3dGGns +C48Q+6lfACbpLMz7wq+60lLT7tzBKgYGA4G35W9+CY9jz8ECAOX3SpqFpOkoYcjh +GsmBSlTs9Kz4JyZDdigiM7xrroe9zkXtwuGUY2X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IIn9esKxU8ym/z9o22YRiQH/SHFD/b/KSZKKQnKOrcKtj2gLT0MW/gL2 +mUxenook+hEoZyBwIOEabz2o5rznmXCXnxlgZ2sIX4Ymx67b/0BtuqaSiLYEGAEI +ACAWIQRFn9oIzt6F4K+CjaW/lvlIBOQEbgUCW/wEBwIbDAAKCRC/lvlIBOQEbkeR +BACd1FWQvo1qNTuNC9IwHLLhBQbT8OEHn/TIP2daR0dNjsvcfvpmX4kXEHWFRW7G +CWaoWMNYtWFk8GrGXKDjZ50wLCw9rj/xJdjdz8vDjVZT3Si0MOrDI9WJLbBNrCBO +h52YTF89KXceUoBVqOgVta4ArbiagOK35ezlWjvg6H2slw== +=IP04 +-----END PGP PRIVATE KEY BLOCK----- diff --git a/src/main/updater/mocks/mock-privkey-2.asc b/src/main/updater/mocks/mock-privkey-2.asc new file mode 100644 index 00000000..726a25d4 --- /dev/null +++ b/src/main/updater/mocks/mock-privkey-2.asc @@ -0,0 +1,33 @@ +-----BEGIN PGP PRIVATE KEY BLOCK----- + +lQHYBFv8BCEBBADA0YaD4Sa50kD9g2o/t6qkMMBZtmYt0kh/F+rAEBCYQL1H6dhA +FAUt7k9EYLAzUw03ByAB2WR097te1xEos9eUWz9YIUMJxE6Tk66kys0z+X1uZQcc +Gywxrg9EsMWQPwDSOJjFEKsMV81X7UjInh38+Dx/gy8sLUUClXDpo7HZiQARAQAB +AAP+ITy85ETOaR+uJkUd7ofZeV4R+iTv7hwedRIJXDwosCYQurG7nigVUHqQ3WeR +V/eMAp1OziLMJ0GA4fNOuOZvVY3ZuwcQFaejRMkItOgvuc4lZZ5IvZzoQrJ04NOO +mT6dugZpD3MYtnxoEftNvjEE/ezc1Wch5Nu06jo0fqb5tsUCANhuUemRQkqL+1sZ +HdhQT3vgxRae1WebH8pEjczLflNteydGE8+ND38tAYaQOqSj8Gs6v7uH9YUwHMMZ +vVT6/msCAOQSEFQ40mG9x+pTLWqfHFR6VeBKOuz+AnygYKIjKJ8eTgXay/2bT9P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B5fNJkY3BKNzuuEKAICx3hMqajrYi2 +BBgBCAAgFiEEZw9JnIvRSktqHp5Tnk0uEMs+0z8FAlv8BCECGwwACgkQnk0uEMs+ +0z8XgAP/c75yAyOCLLKUjD2Ov3Xwn/4YR8/mayZNFGkJ28FRWyxrw4zWVE3TCJVK +8AKUpa8QA9FL0maahWV4EQzcOvO4MKwohbUZ6/XLLd9NhMa9L5pZzsGUT2JQQN/i +yk+I22jpK0+ILJwqwB28EBzwkqRJLSgfPwbeRJ9Ni7D9qf8T1VU= +=vt8y +-----END PGP PRIVATE KEY BLOCK----- diff --git a/src/main/updater/mocks/mock-pubkey-1.asc b/src/main/updater/mocks/mock-pubkey-1.asc new file mode 100644 index 00000000..9230034c --- /dev/null +++ b/src/main/updater/mocks/mock-pubkey-1.asc @@ -0,0 +1,19 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mI0EW/wEBwEEANEtMWhFTchTPfsTvTDLaO/uODtAtKgecmCVxRjOr5EIGdAB/FA0 +5xC0kMo4nKjW/fzX2jmnGevFYC60z8I2mNqfNxYzXIt8eOsqjwFseWYhtYGZXvDy +176ub9WXI2LfQPV4ggnLbvqcHJbiswtx8V7hPTnnFsS9E29DNH4p+sIHABEBAAG0 +IkZvbyBCYXIgKE1vY2sgS2V5IDEpIDxmb29AYmFyLmNvbT6IzgQTAQgAOBYhBEWf +2gjO3oXgr4KNpb+W+UgE5ARuBQJb/AQHAhsDBQsJCAcCBhUKCQgLAgQWAgMBAh4B +AheAAAoJEL+W+UgE5ARubZcD/1dZ1J23CZaM5xVWRUCbS3QnfSBteS2HnsXdPwd7 +AWZuXSc3tvbZDVm5R3PsQcQKej7rkT8rwSmXeIKzzQnw/LcxS0b943lV662Izs2+ +BuroOteWXdIxZ+rWgspAqYC3Liiw15vZZwiEfXBw9CB4aI3Y3S4xmy9SqbvzfMaD +iZXDuI0EW/wEBwEEAOUUNwoEzjt/+YReQsPmQsKuBi9KxU1dvbcI0OG5xYdlp4Zg +G9GjhJwvvH1aHiNU3qyRLF2PjL7dmM6xFIppTF8sakW2H34oE2nY9IS0HYdFNaIa +g0vkG0isSrdRuVl38EClkvEEXnb/L7y/J3EDiBwW+4jWTd0SnS9C1IX+pzozABEB +AAGItgQYAQgAIBYhBEWf2gjO3oXgr4KNpb+W+UgE5ARuBQJb/AQHAhsMAAoJEL+W ++UgE5ARuR5EEAJ3UVZC+jWo1O40L0jAcsuEFBtPw4Qef9Mg/Z1pHR02Oy9x++mZf +iRcQdYVFbsYJZqhYw1i1YWTwasZcoONnnTAsLD2uP/El2N3Py8ONVlPdKLQw6sMj +1YktsE2sIE6HnZhMXz0pdx5SgFWo6BW1rgCtuJqA4rfl7OVaO+DofayX +=jimW +-----END PGP PUBLIC KEY BLOCK----- diff --git a/src/main/updater/mocks/mock-pubkey-2.asc b/src/main/updater/mocks/mock-pubkey-2.asc new file mode 100644 index 00000000..e0928360 --- /dev/null +++ b/src/main/updater/mocks/mock-pubkey-2.asc @@ -0,0 +1,19 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mI0EW/wEIQEEAMDRhoPhJrnSQP2Daj+3qqQwwFm2Zi3SSH8X6sAQEJhAvUfp2EAU +BS3uT0RgsDNTDTcHIAHZZHT3u17XESiz15RbP1ghQwnETpOTrqTKzTP5fW5lBxwb +LDGuD0SwxZA/ANI4mMUQqwxXzVftSMieHfz4PH+DLywtRQKVcOmjsdmJABEBAAG0 +JkZpenogQmFyciAoTW9jayBLZXkgMikgPGZpenpAYmFyci5jb20+iM4EEwEIADgW +IQRnD0mci9FKS2oenlOeTS4Qyz7TPwUCW/wEIQIbAwULCQgHAgYVCgkICwIEFgID +AQIeAQIXgAAKCRCeTS4Qyz7TP8TJA/9mMMA5SlkvbwHvUpfXalPkc/DqjU644Qg1 +EqBhK/N5baBpJdrpwTll0/CUFQQaJBnsVHSoQ0v9oBBflsaQFDkRPalRZAETGYB9 +fWyGH5jZiWPtLdGLbYjr8exl1J8pyeld4hF/erjG8XwXSGxxf7YcytMghv6Q/Q6C +yTwe850QPriNBFv8BCEBBACkrayUHg6fK2dMI0gZKdR0WMyxwXXKg+kc1tlsrxqf +b/bHUVtCy+VlpIS2SGcEAfXSIPmeesj5OA4p6e6egPeVFoy6qWOTLR0U9x4GqW/u +UsEzFAiB6IRK1h2HMLsp5wOV8RTf2ENDiObRh3zqEEJ7zANHQm4sDoaRUIHo5Rsb +uQARAQABiLYEGAEIACAWIQRnD0mci9FKS2oenlOeTS4Qyz7TPwUCW/wEIQIbDAAK +CRCeTS4Qyz7TPxeAA/9zvnIDI4IsspSMPY6/dfCf/hhHz+ZrJk0UaQnbwVFbLGvD +jNZUTdMIlUrwApSlrxAD0UvSZpqFZXgRDNw687gwrCiFtRnr9cst302Exr0vmlnO +wZRPYlBA3+LKT4jbaOkrT4gsnCrAHbwQHPCSpEktKB8/Bt5En02LsP2p/xPVVQ== +=Bk7g +-----END PGP PUBLIC KEY BLOCK----- diff --git a/src/main/updater/mocks/pubkey-1.asc b/src/main/updater/mocks/pubkey-1.asc new file mode 100644 index 00000000..fd38889b --- /dev/null +++ b/src/main/updater/mocks/pubkey-1.asc @@ -0,0 +1,52 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mQINBFpI+bMBEAC2IdjxklcsWMRE/fFd+jQV5/8XfRXpQAgpmkuQcCR7Q7vmpZVr +u4TmJlptUD7ZHnSgcI82tyLFlsp6Z/fBIJGWwlGS0Jj7Q5XtUp1Lyvrs7QTO+J6e +WIH7geMraPXTuLvPniSCUWf+QdafA3NWQQBQQDrjBoBGcVPnqDjcmUvAJnMP7zgB ++TeMN7B8PgkqUYYVpuCOedXov3NZnPozKAcWeF+hMNvR8MW/Gb2IMXVhE4hADGEx +VgFDgJqAjJEZQbpuA0R9SEi42xnCrUKVEnseCbqp3asJ7bd2pmK/GShwictraIr1 +qETegXRQDhGDqs0oL4Db/X96ia4L+paA5/822D8myR/5Oe4TnpwqrOyf6xu/1pSR +EYkGYYjgScEny3BfjPnWXYjCD+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6jy5mp9IVrBewLrtihHfmJA6foy/5 +HqA2C4eFcOhj4PQt8NWe3Nhnfv6HhFCWFsEV2FNjTUP60MZPt9kCnWowAY3yMl4Y +9yuYrelGq309OMOwbCSAT8nfqg9MC91Pbf5+rITaNkWMQF7lgQ+dyKg7Wc8XG1Hf +MBbAUHukiCuHsukqDfw7lzdguw2hOXtpNDPByy+fSSFrJRjyTq2HJwobG5eUxcb8 +EkivS1d3bM28fkmUNQOHR6bOFc30yluYkab7RmQjJf4IhQKAsWiGdH5MUhD2yWTf +jg6Hritq8MTEmI6x9pUfT8/cKyK4fwp8AjFuIXYms/Rpx/tjeiC4q8TuSrzheCga +aeK5/y8Two0UfxIWrsyrnrqdFLeVlt3ID3taw0+L0s7DNtpj4zPjuog7gxtdR1r4 +xUG5TBVcAbYkwHY5ql39WSwj3MqWkagg8la1Mg/o9eiMy+WCFrdamGzfykFU8hxQ +sfB6/eqK4Q== +=UKRx +-----END PGP PUBLIC KEY BLOCK----- diff --git a/src/main/updater/mocks/pubkey-2.asc b/src/main/updater/mocks/pubkey-2.asc new file mode 100644 index 00000000..44cd4ec0 --- /dev/null +++ b/src/main/updater/mocks/pubkey-2.asc @@ -0,0 +1,52 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mQINBFuJaJEBEAC0EKlDi8LpOpwTfFjTSxrbdtwKONLU0b9l/oOv6MGwzWrirhZc +Qx0HqCER1e7CJvqD8dHfommYGKMwHGMBoA+SuACUEcD++bcw702tdjtDo22+5lw0 +u+VhOYSO7JkcKdPRaidSrgd647c4qI1IKCyTSNRYP8j8O8hoUB+kj5/darxCJUYR +P4KYR6/cjYXCmmueCIVakVg1d2hDRgIQ4yM0ASXrZGJweHVDuBTskXQ4C34dKqbQ +FN7sVAofaFT8/xiDEdThjQWVzZ4suLX8EWfF5Fl/UI8WaVgh5Q+hkhmNNJWD48T/ +0vOCDdbortl08eQFjI6dc8Bu8PJ9sFh1tU/NNbuKLRUGTA15EISa1Rhvij7KLW6E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8ANf +BkYdpeM+kcf/jiJdP432SfbiuUuj/Y5ojuM1bqGjXtvGK+9LJE4TnSJzR31fhhOC +mo9avBAK5biAXyf5UWQ0hoxwHum0UyjQxoUf1xh8cGIyQFLZnleNs3641CnAJW/X +qOAbe4TBKAn+qBaab40UAPuuGoPfOw9ZPOuIPCQxR5l0rik8EZleOQfzZIkjSWW0 +77BjBffoqd48U36gmsQNz51xScfqZ5tYAiJ46JkvxpedYtc0acA2C/tHno4Hdy26 +yauvf66jdLQMjYitaQl/B2WbPuD5+2M44vlGps6ebltWocqMaSsNSsfEAL2I6JdA +wrVaCks64UhWHSXq8Ot1ovMLAYCWthphjRcHda5sEfHnRJgt7A5lithlx2OuQ8g1 +dZ5ZjDgWawapLoR3Y2LsIeMlzNtYa/t0nQpVj+hcCwBUYtR4avg86Uy6NpnrP6Gl +GiRPADApLuTLl+h8ZEBTV3PHMQHIXBHNxwDbaO+YcUyeIA8c6BAJt6G2t+S5rBVR +sEQGv7WFrXcyYM38 +=/9tA +-----END PGP PUBLIC KEY BLOCK----- diff --git a/src/main/updater/mocks/sigko-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage b/src/main/updater/mocks/sigko-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage new file mode 100644 index 00000000..05b2f3e6 --- /dev/null +++ b/src/main/updater/mocks/sigko-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage @@ -0,0 +1 @@ +sigko-shasumok diff --git a/src/main/updater/mocks/sigko-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum b/src/main/updater/mocks/sigko-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum new file mode 100644 index 00000000..b853635d --- /dev/null +++ b/src/main/updater/mocks/sigko-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum @@ -0,0 +1 @@ +26ca4f4aa377a8cbe434463debe94d9ec923b930a3053d4fe7129440b48667ac66db03e0f6c417671e16ea9445148d2124df6d34184514f05b26aa14a0790f4b ledger-live-desktop-1.2.1-linux-x86_64.AppImage diff --git a/src/main/updater/mocks/sigko-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum.sig b/src/main/updater/mocks/sigko-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum.sig new file mode 100644 index 00000000..1e2574a1 --- /dev/null +++ b/src/main/updater/mocks/sigko-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum.sig @@ -0,0 +1,16 @@ +-----BEGIN PGP SIGNATURE----- + +iQIzBAABCAAdFiEEhhzv+bPVtMW9pE7JhKxNYN+ul88FAlvKAJIACgkQhKxNYN+u +l8/FJQ/+PvYCbEZB77BGBHPvoEjkTbp4lP9RYzIS1Ial0HUZ6CDsMOfFEVsfM7VQ +MTluvUERshVc5OX2Z4Y+G/eMYHInwZX+ytjWQ7/rXa4M/3na97ND/JwQjNmiIzjT +Fxaiis0BqwulOff9bvgu0AKrA6Bq/DiBKV2EuWwNKVADuUhoAru53YWtAg0mFU87 +XRSR6bww1/fDe9pD/PzWNJxonMHjZDz3KYQOh5RXqNE9sgI51hMVpqNW5O1H/N5P +GvqNDB0piyH85CbiZgvYhDVzVBhpuu1+gQLYMYRAsU8Grp5jJmnbTX81kJsqzyrY +1MNwH4v/nr1KIA/H/SwCXLgDX013VPc7U0rD74dZI8IJn2le/72U5jZknPM0B7vl +KBWgEOq3XYSqW5jlY4N4wdHmNvMiTureiLfZmOjV2XLk8aLX+/LpABHLBduGM3hZ +wsj7+av7jFce4w6bBNoew+P3OMS6aHyORTUkMKvGSACI4PchGHSgG6rmGM183o64 +opexXsnit5vIYQKbJATp2nuUmW9TD2kK6mDjk2Hio4wAR6KvawUf4prIkF1rR/M5 +4DrJ3Oq9ntvmApyE8o5t/uOFE/HSuS/+ZGn1nieSPJTME6WtSYWV9gxfLOgErpXD +GoibMFoInfjh/rPE5JwoCuIaBGYOuFS9ytwlYAPcA7sJQlb9vLE= +=KWhh +-----END PGP SIGNATURE----- diff --git a/src/main/updater/mocks/sigko-shasumok/update-info.json b/src/main/updater/mocks/sigko-shasumok/update-info.json new file mode 100644 index 00000000..fb193762 --- /dev/null +++ b/src/main/updater/mocks/sigko-shasumok/update-info.json @@ -0,0 +1,3 @@ +{ + "fileName": "ledger-live-desktop-1.2.1-linux-x86_64.AppImage" +} diff --git a/src/main/updater/mocks/sigok-shasumko/ledger-live-desktop-1.2.1-linux-x86_64.AppImage b/src/main/updater/mocks/sigok-shasumko/ledger-live-desktop-1.2.1-linux-x86_64.AppImage new file mode 100644 index 00000000..20008850 --- /dev/null +++ b/src/main/updater/mocks/sigok-shasumko/ledger-live-desktop-1.2.1-linux-x86_64.AppImage @@ -0,0 +1 @@ +sigok-shasumok diff --git a/src/main/updater/mocks/sigok-shasumko/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum b/src/main/updater/mocks/sigok-shasumko/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum new file mode 100644 index 00000000..8ed6ec6e --- /dev/null +++ b/src/main/updater/mocks/sigok-shasumko/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum @@ -0,0 +1 @@ +this_is_ko_26ca4f4aa377a8cbe434463debe94d9ec923b930a3053d4fe7129440b48667ac66db03e0f6c417671e16ea9445148d2124df6d34184514f05b26aa14a0790f4b ledger-live-desktop-1.2.1-linux-x86_64.AppImage diff --git a/src/main/updater/mocks/sigok-shasumko/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum.sig b/src/main/updater/mocks/sigok-shasumko/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum.sig new file mode 100644 index 00000000..c8da22d6 --- /dev/null +++ b/src/main/updater/mocks/sigok-shasumko/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum.sig @@ -0,0 +1,16 @@ +-----BEGIN PGP SIGNATURE----- + +iQIzBAABCAAdFiEESKQ3KFYSBLGhLWtAHS/CMF4ss5kFAlvKBL4ACgkQHS/CMF4s +s5lbKxAAndUSWP3tL+aBl/Jn1Fjr48bPlRHFpqUY1bW59uAEB0C1xkHCvExkH7Wh +oc1nT3DsE+khwfhPeruKiNBcgtLtPWBW0PaY7N1tcafzYVldBZYSRfZotv1wEuqF +vt4kgqzCTPLOLfaUxTP7esDv6oIdHY7bah/0QsgvPiOxtT+/Kb/6OIXGT6IyWJxX +6Z/oc2lzkxmIyALFp53YEejUeCayiATVcoR15MCOK2zofU9RBk0BI2R50cNlefpX +WttXOfFP5l2EecZA0S3vA8am66+nG3jKHA8cLIqc//X1pgFCNbZXxCt2kTiE4ri6 +8XW0ne9tGvHk+fG2/4ZhNK2dqzwSD5Yitd2g5HU3ZOUxVdmH5K2XyFF5Zhixca+c +ivFlH00LEagF8hhxkf2tZWSG8fLvffNmzPdkQ1HySq4FpT/K33twb+MYHAWtwEP6 +/Epyiq7S15aB2SRkdOnBv1VQWf0wGZO/ABKutgF8xrOh13prLLSmXFenIdXGsdnP +2Wlawn6GyvSOcK+s6Z6AuETXXVdGnUQDuwjUyqQXUWp4Fm0xInTTPcgruh7Ip3Ra +vBeQcYr4i/aB37X6fUVogzq4Sy2DvDUnG7uMmaVyDxK6RhQ9/M3Jql/6ffCJPXm5 +J7AqoM/QCHfVkXhvgKKwq8hxb6JLSykjB9h//AonCVRcKW/dqY8= +=kaOO +-----END PGP SIGNATURE----- diff --git a/src/main/updater/mocks/sigok-shasumko/update-info.json b/src/main/updater/mocks/sigok-shasumko/update-info.json new file mode 100644 index 00000000..fb193762 --- /dev/null +++ b/src/main/updater/mocks/sigok-shasumko/update-info.json @@ -0,0 +1,3 @@ +{ + "fileName": "ledger-live-desktop-1.2.1-linux-x86_64.AppImage" +} diff --git a/src/main/updater/mocks/sigok-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage b/src/main/updater/mocks/sigok-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage new file mode 100644 index 00000000..20008850 --- /dev/null +++ b/src/main/updater/mocks/sigok-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage @@ -0,0 +1 @@ +sigok-shasumok diff --git a/src/main/updater/mocks/sigok-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum b/src/main/updater/mocks/sigok-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum new file mode 100644 index 00000000..b853635d --- /dev/null +++ b/src/main/updater/mocks/sigok-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum @@ -0,0 +1 @@ +26ca4f4aa377a8cbe434463debe94d9ec923b930a3053d4fe7129440b48667ac66db03e0f6c417671e16ea9445148d2124df6d34184514f05b26aa14a0790f4b ledger-live-desktop-1.2.1-linux-x86_64.AppImage diff --git a/src/main/updater/mocks/sigok-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum.sig b/src/main/updater/mocks/sigok-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum.sig new file mode 100644 index 00000000..d4a145f1 --- /dev/null +++ b/src/main/updater/mocks/sigok-shasumok/ledger-live-desktop-1.2.1-linux-x86_64.AppImage.sha512sum.sig @@ -0,0 +1,16 @@ +-----BEGIN PGP SIGNATURE----- + +iQIzBAABCAAdFiEESKQ3KFYSBLGhLWtAHS/CMF4ss5kFAlvJ+ysACgkQHS/CMF4s +s5mepQ/8DkHSiLEdpMx1GHRX7ElRbhefD7ZAbBCaf/1igpx9K/+SrKvVkgywX2us +D+MU6vmxcFLuMMb5NWpY2s7/0iC+fj36x33fCSvRkmmxxXWf+SzyFozX8sAc/vOo +2x1KTR5jvxspZS0/ERX2KH/88hIWH9kzLsrk/qvppWXpJvEVS5hEHKijLST1aw+c +4L01n9dBwTAsMLo8xm7ybcU86yKUsvbd96XJHuQoqJeg4TOqveUuEmh1J/9jaXnO +3ZcPOtOP42jKuIOFglGMTgtFwR/WN7kxb5eS7wDodvTJE0YzpxeugW4WEfJ2nspZ +3ZCW3G4DD38/uN5MGnPEM77pqKqDZJY7wPHTO2PbXa6w5+WkW9cvE38fBikdQsnX +nKIuvsqQRBBsIOmVe4m+VJ3wrBPpk7IrYSp54+M8XWf8EkkyZYxtMhE+1bqPhRqG +aTIw6qJXJ+yDowe8cFaEybs4xcUl2t4QWHIXM5Y09ZFcwhD5UQwtXz9x6jJogR2j +W8MLeNnAUhRxFY/hySq+wJasKMDKbWXGPk3TmMNn8P+6g6HEllM4KucJty2OH50t +nJbYt0da3Br2W8os1RPA71MmfW6nGhzcFhX2ShKLicyw46Tyc0GGaO29oDwgQkRc +wcbFJmZVMj9ZuZArmfhFL53ZQj9kbAF2qWPNt+L369jSmw5tAko= +=z2+Z +-----END PGP SIGNATURE----- diff --git a/src/main/updater/mocks/sigok-shasumok/update-info.json b/src/main/updater/mocks/sigok-shasumok/update-info.json new file mode 100644 index 00000000..fb193762 --- /dev/null +++ b/src/main/updater/mocks/sigok-shasumok/update-info.json @@ -0,0 +1,3 @@ +{ + "fileName": "ledger-live-desktop-1.2.1-linux-x86_64.AppImage" +} diff --git a/src/main/updater/pgpHelper.js b/src/main/updater/pgpHelper.js new file mode 100644 index 00000000..d31f41d6 --- /dev/null +++ b/src/main/updater/pgpHelper.js @@ -0,0 +1,40 @@ +// @flow + +import * as openpgp from 'openpgp' + +export async function getFingerprint(pubKey: string) { + const { keys } = await openpgp.key.readArmored(pubKey) + if (!keys.length) { + throw new Error('No key found in pubKey') + } + return keys[0].getFingerprint() +} + +export async function verify(msgContent: string, sigContent: string, pubKeyContent: string) { + const signature = await openpgp.signature.readArmored(sigContent) + const message = openpgp.message.fromText(msgContent) + const { keys: publicKeys } = await openpgp.key.readArmored(pubKeyContent) + const pgpOpts = { message, publicKeys, signature } + const verified = await openpgp.verify(pgpOpts) + + if (verified.signatures.length === 0) { + throw new Error('No signature found') + } + + if (!verified.signatures.every(sig => sig.valid)) { + throw new Error('Signature check failed') + } +} + +export async function sign(msgContent: string, privKeyContent: string) { + const privKey = (await openpgp.key.readArmored(privKeyContent)).keys[0] + + const options = { + message: openpgp.cleartext.fromText(msgContent), + privateKeys: [privKey], + detached: true, + } + + const signed = await openpgp.sign(options) + return signed.signature +} diff --git a/src/main/updater/updater.spec.js b/src/main/updater/updater.spec.js new file mode 100644 index 00000000..69c5801c --- /dev/null +++ b/src/main/updater/updater.spec.js @@ -0,0 +1,114 @@ +import path from 'path' +import crypto from 'crypto' + +import { fsReadFile } from 'helpers/fs' +import { UpdateIncorrectHash, UpdateIncorrectSig } from 'config/errors' +import createMockAppUpdater from './createMockAppUpdater' +import { sha512sumPath, readUpdateInfos } from './createElectronAppUpdater' +import * as pgpHelper from './pgpHelper' + +const base = path.resolve(__dirname, 'mocks') + +describe('AppUpdater', () => { + describe('simple cases', () => { + test('should not throw if correct hash & correct sig', async () => { + await verifyMockFolder('sigok-shasumok', 'pubkey-1.asc') + }) + + test('should throw if correct hash but incorrect pubkey', async () => { + const p = verifyMockFolder('sigok-shasumok', 'pubkey-2.asc') + await expectFail(p, UpdateIncorrectSig) + }) + + test('should throw if incorrect hash but correct sig', async () => { + const p = verifyMockFolder('sigok-shasumko', 'pubkey-1.asc') + await expectFail(p, UpdateIncorrectHash) + }) + + test('should throw if correct hash but incorrect sig', async () => { + const p = verifyMockFolder('sigko-shasumok', 'pubkey-1.asc') + await expectFail(p, UpdateIncorrectSig) + }) + }) + + describe('key invalidation', () => { + test('should verify successfully by using getNextKey()', async () => { + const filename = 'foo.exe' + const mockPrivKey1 = await fsReadFile(path.resolve(base, 'mock-privkey-1.asc'), 'ascii') + const mockPubKey1 = await fsReadFile(path.resolve(base, 'mock-pubkey-1.asc'), 'ascii') + const mockPrivKey2 = await fsReadFile(path.resolve(base, 'mock-privkey-2.asc'), 'ascii') + const mockPubKey2 = await fsReadFile(path.resolve(base, 'mock-pubkey-2.asc'), 'ascii') + + // This is the desired scenario: + // + // Let's simulate a release. + // + // 1) create binary (lol) and its hash. this is basically the app update + const update = '0010011-content-of-the-app-01110001010111' + + // 2) create hash of update + const hash = sha512sum(update) + const hashFile = `${hash} ${filename}` // yeah, the hash file contains also file name + + // 3) sign the hash with the *KEY 2* (the app will use the *KEY 1* first) + const signature = await pgpHelper.sign(hashFile, mockPrivKey2) + + // 4) sign *KEY 2* with *KEY 1* and get the *KEY 1* fingerprint, ye. + const mockPubKey2Signature = await pgpHelper.sign(mockPubKey2, mockPrivKey1) + const mockPubKey1Fingerprint = await pgpHelper.getFingerprint(mockPubKey1) + + // 5) app updater, with all thoses infos + const updater = await createMockAppUpdater({ + filename, + computedHash: hash, + hashFile, + signature, + pubKey: mockPubKey1, + pubKeys: [ + { + fingerprint: mockPubKey1Fingerprint, + content: mockPubKey2, + signature: mockPubKey2Signature, + }, + ], + }) + + await updater.verify() + }) + }) +}) + +async function expectFail(promise, errType) { + let err + try { + await promise + } catch (e) { + err = e + } + expect(err).toBeDefined() + expect(err).toBeInstanceOf(errType) +} + +async function verifyMockFolder(folderName, pubKeyName, pubKeys = []) { + const mock = path.resolve(base, folderName) + const { fileName: filename } = await readUpdateInfos(mock) + const computedHash = await sha512sumPath(path.resolve(mock, filename)) + const hashFile = await fsReadFile(path.resolve(mock, `${filename}.sha512sum`), 'ascii') + const signature = await fsReadFile(path.resolve(mock, `${filename}.sha512sum.sig`), 'ascii') + const pubKey = await fsReadFile(path.resolve(base, pubKeyName)) + const updater = await createMockAppUpdater({ + filename, + computedHash, + hashFile, + signature, + pubKey, + pubKeys, + }) + await updater.verify() +} + +export function sha512sum(content) { + const sum = crypto.createHash('sha512') + sum.update(content) + return sum.digest('hex') +} diff --git a/yarn.lock b/yarn.lock index 9afa1d4a..cf086e7b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1791,6 +1791,13 @@ redux "^4.0.0" reselect "^3.0.1" +"@mattiasbuelens/web-streams-polyfill@0.1.0-alpha.4": + version "0.1.0-alpha.4" + resolved "https://registry.yarnpkg.com/@mattiasbuelens/web-streams-polyfill/-/web-streams-polyfill-0.1.0-alpha.4.tgz#fde9688fac83ff40e3be1a01973c867e12a74492" + integrity sha512-WAsiWLWc7ZNS1b0qFAoKSFLeqXesPa60YelVE3pPKc6pZ4iuSW9l6DBxY4hMPQj1dQCBDrUHJj/NDSjE85bTRQ== + dependencies: + "@types/whatwg-streams" "0.0.5" + "@mrmlnc/readdir-enhanced@^2.2.1": version "2.2.1" resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde" @@ -2112,6 +2119,11 @@ resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.13.6.tgz#128d1685a7c34d31ed17010fc87d6a12c1de6976" integrity sha512-5Th3OsZ4gTRdr9Mho83BQ23cex4sRhOR4XTG+m+cJc0FhtUBK9Vn62hBJ+pnQYnSxoPOsKoAPOx6FcphxBC8ng== +"@types/whatwg-streams@0.0.5": + version "0.0.5" + resolved "https://registry.yarnpkg.com/@types/whatwg-streams/-/whatwg-streams-0.0.5.tgz#66c3852b8e33f2a2ca225a6d8fd8096e34d17fe6" + integrity sha512-y1UgRuGO64x/v+UIerA2AMquW/qxaIUD95rbf8FYxtVG//D3381+JexnZfcEiZSqXErdxdPmXpz8srY7gs9Grw== + "@types/ws@^3.2.0": version "3.2.1" resolved "https://registry.yarnpkg.com/@types/ws/-/ws-3.2.1.tgz#b0c1579e58e686f83ce0a97bb9463d29705827fb" @@ -2346,6 +2358,13 @@ acorn@^5.0.0, acorn@^5.3.0, acorn@^5.5.0, acorn@^5.6.2: resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.1.tgz#f095829297706a7c9776958c0afc8930a9b9d9d8" integrity sha512-d+nbxBUGKg7Arpsvbnlq61mc12ek3EY8EQldM3GPAhWJ1UVxC6TDGbIvUMNU6obBX3i1+ptCIzV4vq0gFPEGVQ== +address-rfc2822@^2.0.3: + version "2.0.4" + resolved "https://registry.yarnpkg.com/address-rfc2822/-/address-rfc2822-2.0.4.tgz#2dbd3b8d6c2de1e957c1a8549dc012d40bbc3431" + integrity sha1-Lb07jWwt4elXwahUncAS1Au8NDE= + dependencies: + email-addresses "^3.0.0" + address@1.0.3, address@^1.0.1: version "1.0.3" resolved "https://registry.yarnpkg.com/address/-/address-1.0.3.tgz#b5f50631f8d6cec8bd20c963963afb55e06cbce9" @@ -2721,6 +2740,10 @@ asap@~2.0.3: resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46" integrity sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY= +"asmcrypto.js@github:openpgpjs/asmcrypto": + version "2.3.0" + resolved "https://codeload.github.com/openpgpjs/asmcrypto/tar.gz/6e4e407b9b8ae317925a9e677cc7b4de3e447e83" + asn1.js@^4.0.0: version "4.10.1" resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-4.10.1.tgz#b9c2bf5805f1e64aadeed6df3a2bfafb5a73f5a0" @@ -2730,6 +2753,15 @@ asn1.js@^4.0.0: inherits "^2.0.1" minimalistic-assert "^1.0.0" +asn1.js@^5.0.0: + version "5.0.1" + resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-5.0.1.tgz#7668b56416953f0ce3421adbb3893ace59c96f59" + integrity sha512-aO8EaEgbgqq77IEw+1jfx5c9zTbzvkfuRBuZsSsPnTHMkmd5AI4J6OtITLZFa381jReeaQL67J0GBTUu0+ZTVw== + dependencies: + bn.js "^4.0.0" + inherits "^2.0.1" + minimalistic-assert "^1.0.0" + asn1@~0.2.3: version "0.2.3" resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.3.tgz#dac8787713c9966849fc8180777ebe9c1ddf3b86" @@ -4240,7 +4272,7 @@ bn.js@^3.1.1: resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-3.3.0.tgz#1138e577889fdc97bbdab51844f2190dfc0ae3d7" integrity sha1-ETjld4if3Je72rUYRPIZDfwK49c= -bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.0, bn.js@^4.11.3, bn.js@^4.4.0: +bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.0, bn.js@^4.11.3, bn.js@^4.11.8, bn.js@^4.4.0: version "4.11.8" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f" integrity sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA== @@ -4541,6 +4573,14 @@ buffer@^5.0.3: base64-js "^1.0.2" ieee754 "^1.1.4" +buffer@^5.0.8: + version "5.2.1" + resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.2.1.tgz#dd57fa0f109ac59c602479044dca7b8b3d0b71d6" + integrity sha512-c+Ko0loDaFfuPWiL02ls9Xd3GO3cPVmUobQ6t3rXNUk304u6hGq+8N/kFi+QEIKhzK3uwolVhLzszmfLmMLnqg== + dependencies: + base64-js "^1.0.2" + ieee754 "^1.1.4" + buffer@^5.1.0: version "5.2.0" resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.2.0.tgz#53cf98241100099e9eeae20ee6d51d21b16e541e" @@ -6939,6 +6979,23 @@ elliptic@^6.0.0, elliptic@^6.2.3: minimalistic-assert "^1.0.0" minimalistic-crypto-utils "^1.0.0" +"elliptic@github:openpgpjs/elliptic": + version "6.4.0" + resolved "https://codeload.github.com/openpgpjs/elliptic/tar.gz/e187e706e11fa51bcd20e46e5119054be4e2a4a6" + dependencies: + bn.js "^4.4.0" + brorand "^1.0.1" + hash.js "^1.0.0" + hmac-drbg "^1.0.0" + inherits "^2.0.1" + minimalistic-assert "^1.0.0" + minimalistic-crypto-utils "^1.0.0" + +email-addresses@^3.0.0: + version "3.0.2" + resolved "https://registry.yarnpkg.com/email-addresses/-/email-addresses-3.0.2.tgz#a31280d19baf86669840a0aa45be1d7f6e7df315" + integrity sha512-IMn9dnwLMsgZjdUHswB/UZ0S8LQ/u+2/qjnHJ9tCtp3QHZsIYwJCiJOo2FT0i3CwwK/dtSODYtxuvzV4D9MY5g== + emoji-regex@^6.1.0: version "6.5.1" resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-6.5.1.tgz#9baea929b155565c11ea41c6626eaa65cef992c2" @@ -8705,6 +8762,14 @@ hash.js@^1.0.0, hash.js@^1.0.3: inherits "^2.0.3" minimalistic-assert "^1.0.0" +hash.js@^1.1.3: + version "1.1.5" + resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.1.5.tgz#e38ab4b85dfb1e0c40fe9265c0e9b54854c23812" + integrity sha512-eWI5HG9Np+eHV1KQhisXWwM+4EPPYe5dFX1UZZH7k/E3JzDEazVH+VGlZi6R94ZqImq+A3D1mCEtrFIfg/E7sA== + dependencies: + inherits "^2.0.3" + minimalistic-assert "^1.0.1" + hawk@~3.1.3: version "3.1.3" resolved "https://registry.yarnpkg.com/hawk/-/hawk-3.1.3.tgz#078444bd7c1640b0fe540d2c9b73d59678e8e1c4" @@ -11123,7 +11188,7 @@ mini-css-extract-plugin@^0.4.0: loader-utils "^1.1.0" webpack-sources "^1.1.0" -minimalistic-assert@^1.0.0: +minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7" integrity sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A== @@ -11363,7 +11428,7 @@ node-fetch@^1.0.1: encoding "^0.1.11" is-stream "^1.0.1" -node-fetch@^2.1.1: +node-fetch@^2.1.1, node-fetch@^2.1.2: version "2.2.0" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.2.0.tgz#4ee79bde909262f9775f731e3656d0db55ced5b5" integrity sha512-OayFWziIxiHY8bCUyLX6sTpDH8Jsbp4FfYd1j1f7vZyfgkcOnAyM4oQR16f8a0s7Gl/viMGRey8eScYk4V4EZA== @@ -11439,6 +11504,13 @@ node-loader@^0.6.0: resolved "https://registry.yarnpkg.com/node-loader/-/node-loader-0.6.0.tgz#c797ef51095ed5859902b157f6384f6361e05ae8" integrity sha1-x5fvUQle1YWZArFX9jhPY2HgWug= +node-localstorage@~1.3.0: + version "1.3.1" + resolved "https://registry.yarnpkg.com/node-localstorage/-/node-localstorage-1.3.1.tgz#3177ef42837f398aee5dd75e319b281e40704243" + integrity sha512-NMWCSWWc6JbHT5PyWlNT2i8r7PgGYXVntmKawY83k/M0UJScZ5jirb61TLnqKwd815DfBQu+lR3sRw08SPzIaQ== + dependencies: + write-file-atomic "^1.1.4" + node-modules-regexp@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/node-modules-regexp/-/node-modules-regexp-1.0.0.tgz#8d9dbe28964a4ac5712e9131642107c71e90ec40" @@ -11783,6 +11855,25 @@ opener@^1.4.3: resolved "https://registry.yarnpkg.com/opener/-/opener-1.4.3.tgz#5c6da2c5d7e5831e8ffa3964950f8d6674ac90b8" integrity sha1-XG2ixdflgx6P+jlklQ+NZnSskLg= +openpgp@^4.2.1: + version "4.2.1" + resolved "https://registry.yarnpkg.com/openpgp/-/openpgp-4.2.1.tgz#5d693ca9d90f52f0826447a37596b6a9a5a725da" + integrity sha512-spO7D5LVS8H8ktpX55XDNzvIktMQA7CHZVCt3i4REeP3rbFlzvRbg0cR699yC/hwH0dx09/z+6C+fH4lmbyucw== + dependencies: + "@mattiasbuelens/web-streams-polyfill" "0.1.0-alpha.4" + address-rfc2822 "^2.0.3" + asmcrypto.js "github:openpgpjs/asmcrypto" + asn1.js "^5.0.0" + bn.js "^4.11.8" + buffer "^5.0.8" + elliptic "github:openpgpjs/elliptic" + hash.js "^1.1.3" + node-fetch "^2.1.2" + node-localstorage "~1.3.0" + pako "^1.0.6" + seek-bzip "github:openpgpjs/seek-bzip" + web-stream-tools "github:openpgpjs/web-stream-tools" + opn@5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/opn/-/opn-5.2.0.tgz#71fdf934d6827d676cecbea1531f95d354641225" @@ -11976,7 +12067,7 @@ package-json@^4.0.0: registry-url "^3.0.3" semver "^5.1.0" -pako@~1.0.5: +pako@^1.0.6, pako@~1.0.5: version "1.0.6" resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.6.tgz#0101211baa70c4bca4a0f63f2206e97b7dfaf258" integrity sha512-lQe48YPsMJAig+yngZ87Lus+NF+3mtu7DVOBu6b/gHO1YpKwIj5AWjZ/TOS7i46HD/UixzWb1zeWDZfGZ3iYcg== @@ -14347,6 +14438,12 @@ secp256k1@^3.0.1: nan "^2.2.1" safe-buffer "^5.1.0" +"seek-bzip@github:openpgpjs/seek-bzip": + version "1.0.5-git" + resolved "https://codeload.github.com/openpgpjs/seek-bzip/tar.gz/3aca608ffedc055a1da1d898ecb244804ef32209" + dependencies: + commander "~2.8.1" + select-hose@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca" @@ -16272,6 +16369,10 @@ wdio-dot-reporter@~0.0.8: resolved "https://registry.yarnpkg.com/wdio-dot-reporter/-/wdio-dot-reporter-0.0.10.tgz#facfb7c9c5984149951f59cbc3cd0752101cf0e0" integrity sha512-A0TCk2JdZEn3M1DSG9YYbNRcGdx/YRw19lTiRpgwzH4qqWkO/oRDZRmi3Snn4L2j54KKTfPalBhlOtc8fojVgg== +"web-stream-tools@github:openpgpjs/web-stream-tools": + version "0.0.1" + resolved "https://codeload.github.com/openpgpjs/web-stream-tools/tar.gz/9ab800d46add161db496506d67338202ad0114ce" + webdriverio@^4.8.0: version "4.13.1" resolved "https://registry.yarnpkg.com/webdriverio/-/webdriverio-4.13.1.tgz#624ef4ca569f3c9a5e8e9b11302b4431eda1fb8a" @@ -16721,7 +16822,7 @@ wrappy@1: resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= -write-file-atomic@^1.2.0: +write-file-atomic@^1.1.4, write-file-atomic@^1.2.0: version "1.3.4" resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-1.3.4.tgz#f807a4f0b1d9e913ae7a48112e6cc3af1991b45f" integrity sha1-+Aek8LHZ6ROuekgRLmzDrxmRtF8= From afb8000eaee306d093b89b3a0331193472c2efeb Mon Sep 17 00:00:00 2001 From: meriadec Date: Tue, 4 Dec 2018 16:04:56 +0100 Subject: [PATCH 02/14] Ability to run commands from the main process --- src/internals/index.js | 59 ++------------------------------------ src/main/bridge.js | 13 +++++++-- src/main/commandHandler.js | 48 +++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 58 deletions(-) create mode 100644 src/main/commandHandler.js diff --git a/src/internals/index.js b/src/internals/index.js index a35995b8..44aab9a6 100644 --- a/src/internals/index.js +++ b/src/internals/index.js @@ -1,12 +1,12 @@ // @flow import '@babel/polyfill' -import commands from 'commands' import logger from 'logger' import uuid from 'uuid/v4' import { setImplementation } from 'api/network' import sentry from 'sentry/node' import { EXPERIMENTAL_HTTP_ON_RENDERER } from 'config/constants' import { serializeError } from 'helpers/errors' +import { executeCommand, unsubscribeCommand } from 'main/commandHandler' require('../env') @@ -52,64 +52,11 @@ if (EXPERIMENTAL_HTTP_ON_RENDERER) { }) } -const subscriptions = {} - process.on('message', m => { if (m.type === 'command') { - const { data, requestId, id } = m.command - const cmd = commands.find(cmd => cmd.id === id) - if (!cmd) { - logger.warn(`command ${id} not found`) - return - } - const startTime = Date.now() - logger.onCmd('cmd.START', id, 0, data) - try { - subscriptions[requestId] = cmd.impl(data).subscribe({ - next: data => { - logger.onCmd('cmd.NEXT', id, Date.now() - startTime, data) - process.send({ - type: 'cmd.NEXT', - requestId, - data, - }) - }, - complete: () => { - delete subscriptions[requestId] - logger.onCmd('cmd.COMPLETE', id, Date.now() - startTime) - process.send({ - type: 'cmd.COMPLETE', - requestId, - }) - }, - error: error => { - logger.warn('Command error:', error) - delete subscriptions[requestId] - logger.onCmd('cmd.ERROR', id, Date.now() - startTime, error) - process.send({ - type: 'cmd.ERROR', - requestId, - data: serializeError(error), - }) - }, - }) - } catch (error) { - logger.warn('Command error:', error) - delete subscriptions[requestId] - logger.onCmd('cmd.ERROR', id, Date.now() - startTime, error) - process.send({ - type: 'cmd.ERROR', - requestId, - data: serializeError(error), - }) - } + executeCommand(m.command, process.send.bind(process)) } else if (m.type === 'command-unsubscribe') { - const { requestId } = m - const sub = subscriptions[requestId] - if (sub) { - sub.unsubscribe() - delete subscriptions[requestId] - } + unsubscribeCommand(m.requestId) } else if (m.type === 'executeHttpQueryPayload') { const { payload } = m const defer = defers[payload.id] diff --git a/src/main/bridge.js b/src/main/bridge.js index e6527fa4..1d80be18 100644 --- a/src/main/bridge.js +++ b/src/main/bridge.js @@ -10,6 +10,7 @@ import logger from 'logger' import sentry, { captureException } from 'sentry/node' import user from 'helpers/user' import { resolveLogsDirectory, cleanUpBeforeClosingSync } from 'helpers/log' +import { executeCommand, unsubscribeCommand } from 'main/commandHandler' import { deserializeError } from 'helpers/errors' import { setInternalProcessPID } from './terminator' @@ -77,10 +78,18 @@ ipcMain.on('clean-processes', () => { ipcMainListenReceiveCommands({ onUnsubscribe: requestId => { - if (!internalProcess) return - internalProcess.send({ type: 'command-unsubscribe', requestId }) + unsubscribeCommand(requestId) + if (internalProcess) { + internalProcess.send({ type: 'command-unsubscribe', requestId }) + } }, onCommand: (command, notifyCommandEvent) => { + // ability to run command from the main process + if (command.id.startsWith('main:')) { + executeCommand(command, notifyCommandEvent) + return + } + if (!internalProcess) bootInternalProcess() const p = internalProcess invariant(p, 'internalProcess not started !?') diff --git a/src/main/commandHandler.js b/src/main/commandHandler.js new file mode 100644 index 00000000..18abacc7 --- /dev/null +++ b/src/main/commandHandler.js @@ -0,0 +1,48 @@ +import commands from 'commands' +import logger from 'logger' +import { serializeError } from 'helpers/errors' + +const subscriptions = {} + +export function executeCommand(command, send) { + const { data, requestId, id } = command + const cmd = commands.find(cmd => cmd.id === id) + if (!cmd) { + logger.warn(`command ${id} not found`) + return + } + const startTime = Date.now() + logger.onCmd('cmd.START', id, 0, data) + try { + subscriptions[requestId] = cmd.impl(data).subscribe({ + next: data => { + logger.onCmd('cmd.NEXT', id, Date.now() - startTime, data) + send({ type: 'cmd.NEXT', requestId, data }) + }, + complete: () => { + delete subscriptions[requestId] + logger.onCmd('cmd.COMPLETE', id, Date.now() - startTime) + send({ type: 'cmd.COMPLETE', requestId }) + }, + error: error => { + logger.warn('Command error:', error) + delete subscriptions[requestId] + logger.onCmd('cmd.ERROR', id, Date.now() - startTime, error) + send({ type: 'cmd.ERROR', requestId, data: serializeError(error) }) + }, + }) + } catch (error) { + logger.warn('Command error:', error) + delete subscriptions[requestId] + logger.onCmd('cmd.ERROR', id, Date.now() - startTime, error) + send({ type: 'cmd.ERROR', requestId, data: serializeError(error) }) + } +} + +export function unsubscribeCommand(requestId) { + const sub = subscriptions[requestId] + if (sub) { + sub.unsubscribe() + delete subscriptions[requestId] + } +} From c4035ecd747089e779b729fd5bd1903156761024 Mon Sep 17 00:00:00 2001 From: meriadec Date: Sat, 8 Dec 2018 17:00:23 +0100 Subject: [PATCH 03/14] Bump react & react-dom to v16.6.3 This fix a context problem that was preventing UpdateNotifier to correctly update. Feel free to ping me if you want me to show you. --- package.json | 4 ++-- yarn.lock | 32 +++++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 1896a7f7..3daa54d1 100644 --- a/package.json +++ b/package.json @@ -75,8 +75,8 @@ "qs": "^6.5.1", "raven": "^2.5.0", "raven-js": "^3.24.2", - "react": "^16.6.1", - "react-dom": "^16.4.1", + "react": "^16.6.3", + "react-dom": "^16.6.3", "react-i18next": "^7.7.0", "react-key-handler": "^1.0.1", "react-markdown": "^3.3.2", diff --git a/yarn.lock b/yarn.lock index cf086e7b..e5ec2274 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13188,15 +13188,15 @@ react-docgen@^3.0.0-beta11: node-dir "^0.1.10" recast "^0.12.6" -react-dom@^16.4.1: - version "16.4.1" - resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.4.1.tgz#7f8b0223b3a5fbe205116c56deb85de32685dad6" - integrity sha512-1Gin+wghF/7gl4Cqcvr1DxFX2Osz7ugxSwl6gBqCMpdrxHjIFUS7GYxrFftZ9Ln44FHw0JxCFD9YtZsrbR5/4A== +react-dom@^16.6.3: + version "16.6.3" + resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.6.3.tgz#8fa7ba6883c85211b8da2d0efeffc9d3825cccc0" + integrity sha512-8ugJWRCWLGXy+7PmNh8WJz3g1TaTUt1XyoIcFN+x0Zbkoz+KKdUyx1AQLYJdbFXjuF41Nmjn5+j//rxvhFjgSQ== dependencies: - fbjs "^0.8.16" loose-envify "^1.1.0" object-assign "^4.1.1" - prop-types "^15.6.0" + prop-types "^15.6.2" + scheduler "^0.11.2" react-error-overlay@^4.0.0: version "4.0.0" @@ -13474,7 +13474,7 @@ react-treebeard@^2.1.0: shallowequal "^0.2.2" velocity-react "^1.3.1" -react@*, react@^16.2.0, react@^16.6.1: +react@*, react@^16.2.0: version "16.6.1" resolved "https://registry.yarnpkg.com/react/-/react-16.6.1.tgz#ee2aef4f0a09e494594882029821049772f915fe" integrity sha512-OtawJThYlvRgm9BXK+xTL7BIlDx8vv21j+fbQDjRRUyok6y7NyjlweGorielTahLZHYIdKUoK2Dp9ByVWuMqxw== @@ -13484,6 +13484,16 @@ react@*, react@^16.2.0, react@^16.6.1: prop-types "^15.6.2" scheduler "^0.11.0" +react@^16.6.3: + version "16.6.3" + resolved "https://registry.yarnpkg.com/react/-/react-16.6.3.tgz#25d77c91911d6bbdd23db41e70fb094cc1e0871c" + integrity sha512-zCvmH2vbEolgKxtqXL2wmGCUxUyNheYn/C+PD1YAjfxHC54+MhdruyhO7QieQrYsYeTxrn93PM2y0jRH1zEExw== + dependencies: + loose-envify "^1.1.0" + object-assign "^4.1.1" + prop-types "^15.6.2" + scheduler "^0.11.2" + reactcss@^1.2.0: version "1.2.3" resolved "https://registry.yarnpkg.com/reactcss/-/reactcss-1.2.3.tgz#c00013875e557b1cf0dfd9a368a1c3dab3b548dd" @@ -14389,6 +14399,14 @@ scheduler@^0.11.0: loose-envify "^1.1.0" object-assign "^4.1.1" +scheduler@^0.11.2: + version "0.11.3" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.11.3.tgz#b5769b90cf8b1464f3f3cfcafe8e3cd7555a2d6b" + integrity sha512-i9X9VRRVZDd3xZw10NY5Z2cVMbdYg6gqFecfj79USv1CFN+YrJ3gIPRKf1qlY+Sxly4djoKdfx1T+m9dnRB8kQ== + dependencies: + loose-envify "^1.1.0" + object-assign "^4.1.1" + schema-utils@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-0.3.0.tgz#f5877222ce3e931edae039f17eb3716e7137f8cf" From 3d0a47e91408ead75fbbc0d22a38c46ecf598e07 Mon Sep 17 00:00:00 2001 From: meriadec Date: Sat, 8 Dec 2018 17:10:01 +0100 Subject: [PATCH 04/14] Ability to pass NotifComponent to SidebarListItem --- src/components/base/SideBar/SideBarListItem.js | 13 +++---------- src/components/base/SideBar/stories.js | 1 - 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/components/base/SideBar/SideBarListItem.js b/src/components/base/SideBar/SideBarListItem.js index d50f0368..695af3bd 100644 --- a/src/components/base/SideBar/SideBarListItem.js +++ b/src/components/base/SideBar/SideBarListItem.js @@ -11,7 +11,7 @@ export type Props = { icon?: any, // TODO: type should be more precise, but, eh ¯\_(ツ)_/¯ disabled?: boolean, iconActiveColor: ?string, - hasNotif?: boolean, + NotifComponent?: React$ComponentType<*>, isActive?: boolean, onClick?: void => void, isActive?: boolean, @@ -24,7 +24,7 @@ class SideBarListItem extends PureComponent { label, desc, iconActiveColor, - hasNotif, + NotifComponent, onClick, isActive, disabled, @@ -47,7 +47,7 @@ class SideBarListItem extends PureComponent { )} {!!desc && desc(this.props)} - {!!hasNotif && } + {NotifComponent && } ) } @@ -85,11 +85,4 @@ const Container = styled(Tabbable).attrs({ }}; ` -const Bullet = styled.div` - background: ${p => p.theme.colors.wallet}; - width: 8px; - height: 8px; - border-radius: 100%; -` - export default SideBarListItem diff --git a/src/components/base/SideBar/stories.js b/src/components/base/SideBar/stories.js index 3f7297b0..edc9a0d1 100644 --- a/src/components/base/SideBar/stories.js +++ b/src/components/base/SideBar/stories.js @@ -33,7 +33,6 @@ const SIDEBAR_ITEMS = [ label: 'Third very very very very long text very long text very long', icon: IconControls, iconActiveColor: '#27a2db', - hasNotif: true, }, { key: 'fourth', From 7d0dbeaabdcf14d4afe9adc1e9e4be1b94e655e8 Mon Sep 17 00:00:00 2001 From: meriadec Date: Sun, 9 Dec 2018 14:28:54 +0100 Subject: [PATCH 05/14] Make ReleaseNotes modal take care of itself --- src/components/modals/ReleaseNotes/index.js | 55 ++++++++++++++++++--- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/src/components/modals/ReleaseNotes/index.js b/src/components/modals/ReleaseNotes/index.js index cf4a4b35..68d08028 100644 --- a/src/components/modals/ReleaseNotes/index.js +++ b/src/components/modals/ReleaseNotes/index.js @@ -1,16 +1,55 @@ // @flow -import React from 'react' +import React, { PureComponent } from 'react' +import { connect } from 'react-redux' +import semver from 'semver' + +import type { State } from 'reducers' +import { openModal } from 'reducers/modals' +import { lastUsedVersionSelector } from 'reducers/settings' +import { saveSettings } from 'actions/settings' import { MODAL_RELEASES_NOTES } from 'config/constants' import Modal from 'components/base/Modal' import ReleaseNotesBody from './ReleaseNotesBody' -const ReleaseNotesModal = () => ( - } - /> -) +type Props = { + openModal: Function, + saveSettings: Function, + lastUsedVersion: string, +} + +const mapStateToProps = (state: State) => ({ + lastUsedVersion: lastUsedVersionSelector(state), +}) + +const mapDispatchToProps = { + openModal, + saveSettings, +} + +class ReleaseNotesModal extends PureComponent { + componentDidMount() { + const { lastUsedVersion, saveSettings, openModal } = this.props + const currentVersion = __APP_VERSION__ + + if (semver.gt(currentVersion, lastUsedVersion)) { + openModal(MODAL_RELEASES_NOTES, currentVersion) + saveSettings({ lastUsedVersion: currentVersion }) + } + } + + render() { + return ( + } + /> + ) + } +} -export default ReleaseNotesModal +export default connect( + mapStateToProps, + mapDispatchToProps, +)(ReleaseNotesModal) From ce090e14a5c7262258464ddc4629d27011249689 Mon Sep 17 00:00:00 2001 From: meriadec Date: Sun, 9 Dec 2018 14:29:02 +0100 Subject: [PATCH 06/14] Integrate UI for auto-update --- src/commands/autoUpdate.js | 51 +++++++++ src/commands/index.js | 4 + src/commands/quitAndInstallElectronUpdate.js | 30 +++++ src/components/App.js | 17 +-- src/components/DashboardPage/index.js | 4 +- src/components/MainSideBar/index.js | 9 +- .../UpdateNotifier/UpdateDownloaded.js | 103 ------------------ .../UpdateNotifier/UpdateInstalled.js | 48 -------- src/components/UpdateNotifier/index.js | 17 --- src/components/Updater/Banner.js | 75 +++++++++++++ src/components/Updater/DebugUpdater.js | 70 ++++++++++++ src/components/Updater/UpdateDot.js | 88 +++++++++++++++ src/components/Updater/UpdaterContext.js | 95 ++++++++++++++++ src/components/layout/Default.js | 4 + src/reducers/index.js | 4 - src/reducers/update.js | 48 -------- src/renderer/events.js | 25 ----- 17 files changed, 432 insertions(+), 260 deletions(-) create mode 100644 src/commands/autoUpdate.js create mode 100644 src/commands/quitAndInstallElectronUpdate.js delete mode 100644 src/components/UpdateNotifier/UpdateDownloaded.js delete mode 100644 src/components/UpdateNotifier/UpdateInstalled.js delete mode 100644 src/components/UpdateNotifier/index.js create mode 100644 src/components/Updater/Banner.js create mode 100644 src/components/Updater/DebugUpdater.js create mode 100644 src/components/Updater/UpdateDot.js create mode 100644 src/components/Updater/UpdaterContext.js delete mode 100644 src/reducers/update.js diff --git a/src/commands/autoUpdate.js b/src/commands/autoUpdate.js new file mode 100644 index 00000000..9dd08d0b --- /dev/null +++ b/src/commands/autoUpdate.js @@ -0,0 +1,51 @@ +// @flow + +import { createCommand, Command } from 'helpers/ipc' +import { Observable } from 'rxjs' + +import createElectronAppUpdater from 'main/updater/createElectronAppUpdater' +import type { UpdateStatus } from 'components/Updater/UpdaterContext' + +type Input = {} +type Result = { + status: UpdateStatus, + payload?: *, +} + +const cmd: Command = createCommand('main:autoUpdate', () => + Observable.create(o => { + const { autoUpdater } = require('electron-updater') + + const sendStatus = (status, payload) => { + o.next({ status, payload }) + } + + const handleDownload = async info => { + try { + const appUpdater = await createElectronAppUpdater({ + feedURL: process.env.LL_UPDATE_FEED || 'https://insert.feed.here', + updateVersion: info.version, + }) + await appUpdater.verify() + sendStatus('check-success') + } catch (err) { + // todo delete update file + o.error(err) + } + } + + autoUpdater.on('checking-for-update', () => sendStatus('checking-for-update')) + autoUpdater.on('update-available', info => sendStatus('update-available', info)) + autoUpdater.on('update-not-available', info => sendStatus('update-not-available', info)) + autoUpdater.on('download-progress', p => sendStatus('download-progress', p)) + autoUpdater.on('update-downloaded', handleDownload) + autoUpdater.on('error', err => o.error(err)) + + autoUpdater.autoInstallOnAppQuit = false + autoUpdater.checkForUpdates() + + return () => {} + }), +) + +export default cmd diff --git a/src/commands/index.js b/src/commands/index.js index 1022021c..07f5733a 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -4,6 +4,7 @@ import invariant from 'invariant' import type { Command } from 'helpers/ipc' import debugAppInfosForCurrency from 'commands/debugAppInfosForCurrency' +import autoUpdate from 'commands/autoUpdate' import getAddress from 'commands/getAddress' import getDeviceInfo from 'commands/getDeviceInfo' import getCurrentFirmware from 'commands/getCurrentFirmware' @@ -28,6 +29,7 @@ import listAppVersions from 'commands/listAppVersions' import listCategories from 'commands/listCategories' import listenDevices from 'commands/listenDevices' import ping from 'commands/ping' +import quitAndInstallElectronUpdate from 'commands/quitAndInstallElectronUpdate' import shouldFlashMcu from 'commands/shouldFlashMcu' import signTransaction from 'commands/signTransaction' import testApdu from 'commands/testApdu' @@ -37,6 +39,7 @@ import uninstallApp from 'commands/uninstallApp' const all: Array> = [ debugAppInfosForCurrency, + autoUpdate, getAddress, getDeviceInfo, getCurrentFirmware, @@ -61,6 +64,7 @@ const all: Array> = [ listCategories, listenDevices, ping, + quitAndInstallElectronUpdate, shouldFlashMcu, signTransaction, testApdu, diff --git a/src/commands/quitAndInstallElectronUpdate.js b/src/commands/quitAndInstallElectronUpdate.js new file mode 100644 index 00000000..4ed02af8 --- /dev/null +++ b/src/commands/quitAndInstallElectronUpdate.js @@ -0,0 +1,30 @@ +// @flow + +import { createCommand, Command } from 'helpers/ipc' +import { Observable } from 'rxjs' + +type Input = void +type Result = void + +const cmd: Command = createCommand('main:quitAndInstallElectronUpdate', () => + Observable.create(o => { + const { app, BrowserWindow } = require('electron') + const { autoUpdater } = require('electron-updater') + const browserWindows = BrowserWindow.getAllWindows() + + // Fixes quitAndInstall not quitting on macOS, as suggested on + // https://github.com/electron-userland/electron-builder/issues/1604#issuecomment-306709572 + app.removeAllListeners('window-all-closed') + browserWindows.forEach(browserWindow => { + browserWindow.removeAllListeners('close') + }) + + // couldn't find a way to catch if fail ¯\_(ツ)_/¯ + autoUpdater.quitAndInstall(false) + + o.complete() + return () => {} + }), +) + +export default cmd diff --git a/src/components/App.js b/src/components/App.js index a6b3d186..4db32693 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -16,6 +16,7 @@ import ThrowBlock from 'components/ThrowBlock' import Default from 'components/layout/Default' import CounterValues from 'helpers/countervalues' import { BridgeSyncProvider } from 'bridge/BridgeSyncContext' +import { UpdaterProvider } from 'components/Updater/UpdaterContext' const App = ({ store, @@ -31,13 +32,15 @@ const App = ({ - - - - - - - + + + + + + + + + diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index 203651b7..82692d8b 100644 --- a/src/components/DashboardPage/index.js +++ b/src/components/DashboardPage/index.js @@ -24,7 +24,7 @@ import { saveSettings } from 'actions/settings' import TrackPage from 'analytics/TrackPage' import RefreshAccountsOrdering from 'components/RefreshAccountsOrdering' -import UpdateNotifier from 'components/UpdateNotifier' +import UpdateBanner from 'components/Updater/Banner' import BalanceInfos from 'components/BalanceSummary/BalanceInfos' import BalanceSummary from 'components/BalanceSummary' import Box from 'components/base/Box' @@ -84,7 +84,7 @@ class DashboardPage extends PureComponent { return ( - + ({ accounts: accountsSelector(state), - updateStatus: getUpdateStatus(state), developerMode: developerModeSelector(state), }) @@ -54,7 +52,6 @@ type Props = { location: Location, push: string => void, openModal: string => void, - updateStatus: UpdateStatus, developerMode: boolean, } @@ -96,7 +93,7 @@ class MainSideBar extends PureComponent { handleOpenImportModal = () => this.props.openModal(MODAL_ADD_ACCOUNTS) render() { - const { t, accounts, location, updateStatus, developerMode } = this.props + const { t, accounts, location, developerMode } = this.props const { pathname } = location const addAccountButton = ( @@ -122,7 +119,7 @@ class MainSideBar extends PureComponent { iconActiveColor="wallet" onClick={this.handleClickDashboard} isActive={pathname === '/'} - hasNotif={updateStatus === 'downloaded'} + NotifComponent={UpdateDot} /> ({ - updateStatus: getUpdateStatus(state), - updateData: getUpdateData(state), -}) - -const Container = styled(Box).attrs({ - py: '8px', - px: 3, - bg: 'wallet', - color: 'white', - mt: '-50px', - mb: '35px', - style: p => ({ - transform: `translate3d(0, ${p.offset}%, 0)`, - }), -})` - border-radius: ${radii[1]}px; -` - -const NotifText = styled(Text).attrs({ - ff: 'Open Sans|SemiBold', - fontSize: 4, -})`` - -class UpdateDownloaded extends PureComponent { - renderStatus() { - const { updateStatus, t } = this.props - switch (updateStatus) { - case 'idle': - case 'checking': - case 'unavailable': - case 'error': - case 'available': - case 'progress': - return null - case 'downloaded': - return ( - - - - {t('update.newVersionReady')} - - - sendEvent('updater', 'quitAndInstall')} - > - {t('update.relaunch')} - - - - ) - default: - return null - } - } - - render() { - const { updateStatus, ...props } = this.props - - const isToggled = updateStatus === 'downloaded' - - if (!isToggled) { - return null - } - return {this.renderStatus()} - } -} - -export default compose( - connect( - mapStateToProps, - null, - ), - translate(), -)(UpdateDownloaded) diff --git a/src/components/UpdateNotifier/UpdateInstalled.js b/src/components/UpdateNotifier/UpdateInstalled.js deleted file mode 100644 index b0fbcdc5..00000000 --- a/src/components/UpdateNotifier/UpdateInstalled.js +++ /dev/null @@ -1,48 +0,0 @@ -// @flow - -import { PureComponent } from 'react' -import { connect } from 'react-redux' -import semver from 'semver' - -import { openModal } from 'reducers/modals' -import { lastUsedVersionSelector } from 'reducers/settings' -import { saveSettings } from 'actions/settings' -import { MODAL_RELEASES_NOTES } from 'config/constants' - -import type { State } from 'reducers' - -type Props = { - openModal: Function, - saveSettings: Function, - lastUsedVersion: string, -} - -const mapStateToProps = (state: State) => ({ - lastUsedVersion: lastUsedVersionSelector(state), -}) - -const mapDispatchToProps = { - openModal, - saveSettings, -} - -class UpdateInstalled extends PureComponent { - componentDidMount() { - const { lastUsedVersion, saveSettings, openModal } = this.props - const currentVersion = __APP_VERSION__ - - if (semver.gt(currentVersion, lastUsedVersion)) { - openModal(MODAL_RELEASES_NOTES, currentVersion) - saveSettings({ lastUsedVersion: currentVersion }) - } - } - - render() { - return null - } -} - -export default connect( - mapStateToProps, - mapDispatchToProps, -)(UpdateInstalled) diff --git a/src/components/UpdateNotifier/index.js b/src/components/UpdateNotifier/index.js deleted file mode 100644 index 6ea65461..00000000 --- a/src/components/UpdateNotifier/index.js +++ /dev/null @@ -1,17 +0,0 @@ -// @flow - -import React, { PureComponent, Fragment } from 'react' - -import UpdateDownloaded from './UpdateDownloaded' -import UpdateInstalled from './UpdateInstalled' - -export default class UpdateNotifier extends PureComponent<{}> { - render() { - return ( - - - - - ) - } -} diff --git a/src/components/Updater/Banner.js b/src/components/Updater/Banner.js new file mode 100644 index 00000000..d0d0321e --- /dev/null +++ b/src/components/Updater/Banner.js @@ -0,0 +1,75 @@ +// @flow + +import React, { PureComponent } from 'react' +import styled from 'styled-components' + +import { radii } from 'styles/theme' + +import TranslatedError from 'components/TranslatedError' +import Box from 'components/base/Box' + +import { withUpdaterContext } from './UpdaterContext' +import type { UpdaterContextType } from './UpdaterContext' + +type Props = { + context: UpdaterContextType, +} + +export const VISIBLE_STATUS = ['download-progress', 'checking', 'check-success', 'error'] + +class UpdaterTopBanner extends PureComponent { + render() { + const { context } = this.props + const { status, quitAndInstall, downloadProgress, error } = context + + if (!VISIBLE_STATUS.includes(status)) return null + + return ( + + {status === 'download-progress' && `Downloading update... ${Math.round(downloadProgress)}%`} + {status === 'checking' && `Verifying update...`} + {status === 'error' && + error && ( +
+ {'Error during update. Please download again.'} + + + +
+ )} + {status === 'check-success' && ( +
+ {'Update ready to install. '} + {'install now'} +
+ )} +
+ ) + } +} + +const Container = styled(Box).attrs({ + py: '8px', + px: 3, + bg: p => (p.status === 'error' ? 'alertRed' : 'wallet'), + color: 'white', + mt: -20, + mb: 20, + fontSize: 4, +})` + border-radius: ${radii[1]}px; +` + +const DownloadLink = styled.span` + color: white; + text-decoration: underline; + cursor: pointer; +` + +const ErrorContainer = styled.div` + margin-top: 10px; + font-family: monospace; + font-size: 10px; +` + +export default withUpdaterContext(UpdaterTopBanner) diff --git a/src/components/Updater/DebugUpdater.js b/src/components/Updater/DebugUpdater.js new file mode 100644 index 00000000..32cf4c19 --- /dev/null +++ b/src/components/Updater/DebugUpdater.js @@ -0,0 +1,70 @@ +// @flow +/* eslint-disable react/jsx-no-literals */ + +import React, { Component } from 'react' + +import { withUpdaterContext } from './UpdaterContext' +import type { UpdaterContextType } from './UpdaterContext' + +const statusToDebug = ['idle', 'download-progress', 'checking', 'check-success', 'error'] + +type Props = { + context: UpdaterContextType, +} + +class DebugUpdater extends Component { + render() { + const { context } = this.props + const { status, setStatus, quitAndInstall } = context + return ( +
+

+ DEBUG UPDATE
+ ------------
+

+ status: {status} +
+ {statusToDebug.map(s => ( + + ))} +
+
+ simulate update +
+
+ +
+
+ ) + } +} + +const styles = { + root: { + position: 'fixed', + bottom: 0, + right: 0, + padding: 10, + fontSize: 10, + background: 'black', + color: 'white', + fontFamily: 'monospace', + zIndex: 1000, + maxWidth: 250, + }, + btn: { + cursor: 'pointer', + background: 'lightgreen', + color: 'black', + border: 'none', + marginRight: 10, + marginTop: 10, + padding: '0px 10px', + }, +} + +export default withUpdaterContext(DebugUpdater) diff --git a/src/components/Updater/UpdateDot.js b/src/components/Updater/UpdateDot.js new file mode 100644 index 00000000..01a34bb5 --- /dev/null +++ b/src/components/Updater/UpdateDot.js @@ -0,0 +1,88 @@ +// @flow + +import React from 'react' +import styled, { keyframes } from 'styled-components' + +import { colors } from 'styles/theme' + +import { withUpdaterContext } from './UpdaterContext' +import { VISIBLE_STATUS } from './Banner' +import type { UpdaterContextType, UpdateStatus } from './UpdaterContext' + +type Props = { + context: UpdaterContextType, +} + +const rotate = keyframes` + 0% { + transform: rotate(0deg); + } + 100% { + transform: rotate(360deg); + } +` + +const getColor = ({ status }: { status: UpdateStatus }) => + status === 'error' ? colors.alertRed : colors.wallet + +const getOpacity = ({ status }: { status: UpdateStatus }) => + status === 'download-progress' || status === 'checking' ? 0.5 : 1 + +const Dot = styled.div` + opacity: ${getOpacity}; + width: 8px; + height: 8px; + background-color: ${getColor}; + border-radius: 50%; +` + +const Spinner = styled.div` + opacity: 0.5; + position: absolute; + top: -3px; + left: -3px; + animation: ${rotate} 1.5s linear infinite; + width: 14px; + height: 14px; + + &:before { + content: ''; + position: absolute; + right: 0; + bottom: 0; + width: 4px; + height: 4px; + background-color: ${colors.wallet}; + border-radius: 50%; + } + + &:after { + content: ''; + position: absolute; + width: 4px; + height: 4px; + background-color: ${colors.wallet}; + border-radius: 50%; + } +` + +function UpdateDot(props: Props) { + const { context } = props + const { status } = context + if (!VISIBLE_STATUS.includes(status)) return null + const showSpinner = status === 'download-progress' || status === 'checking' + return ( +
+ {showSpinner && } + +
+ ) +} + +const styles = { + container: { + position: 'relative', + }, +} + +export default withUpdaterContext(UpdateDot) diff --git a/src/components/Updater/UpdaterContext.js b/src/components/Updater/UpdaterContext.js new file mode 100644 index 00000000..91351a48 --- /dev/null +++ b/src/components/Updater/UpdaterContext.js @@ -0,0 +1,95 @@ +// @flow + +import React, { Component } from 'react' + +import autoUpdate from 'commands/autoUpdate' +import quitAndInstallElectronUpdate from 'commands/quitAndInstallElectronUpdate' + +export type UpdateStatus = + | 'idle' + | 'checking-for-update' + | 'update-available' + | 'update-not-available' + | 'download-progress' + | 'update-downloaded' + | 'checking' + | 'check-success' + | 'error' + +export type UpdaterContextType = { + status: UpdateStatus, + downloadProgress: number, + quitAndInstall: () => void, + setStatus: UpdateStatus => void, + error: ?Error, +} + +type UpdaterProviderProps = { + children: *, +} + +type UpdaterProviderState = { + status: UpdateStatus, + downloadProgress: number, + error: ?Error, +} + +const UpdaterContext = React.createContext() + +class Provider extends Component { + constructor() { + super() + + if (__PROD__) { + this.sub = autoUpdate.send({}).subscribe({ + next: e => { + if (e.status === 'download-progress') { + const downloadProgress = e.payload && e.payload.percent ? e.payload.percent : 0 + this.setState({ status: e.status, downloadProgress }) + } else { + this.setStatus(e.status) + } + }, + error: error => this.setState({ status: 'error', error }), + }) + } + + this.state = { + status: 'idle', + downloadProgress: 0, + error: null, + } + } + + componentWillUnmount() { + if (this.sub) { + this.sub.unsubscribe() + } + } + + sub = null + + setStatus = (status: UpdateStatus) => this.setState({ status }) + setDownloadProgress = (downloadProgress: number) => this.setState({ downloadProgress }) + quitAndInstall = () => quitAndInstallElectronUpdate.send().toPromise() + + render() { + const { status, downloadProgress, error } = this.state + const value = { + status, + downloadProgress, + error, + setStatus: this.setStatus, + quitAndInstall: this.quitAndInstall, + } + return {this.props.children} + } +} + +export const withUpdaterContext = (ComponentToDecorate: React$ComponentType<*>) => (props: *) => ( + + {context => } + +) + +export const UpdaterProvider = Provider diff --git a/src/components/layout/Default.js b/src/components/layout/Default.js index f79744ac..63ccd83c 100644 --- a/src/components/layout/Default.js +++ b/src/components/layout/Default.js @@ -34,6 +34,8 @@ import IsUnlocked from 'components/IsUnlocked' import SideBar from 'components/MainSideBar' import TopBar from 'components/TopBar' import SyncBackground from 'components/SyncBackground' +import DebugUpdater from 'components/Updater/DebugUpdater' + import SyncContinuouslyPendingOperations from '../SyncContinouslyPendingOperations' const Main = styled(GrowScroll).attrs({ @@ -97,6 +99,8 @@ class Default extends Component { ))} + {process.env.DEBUG_UPDATE && } + diff --git a/src/reducers/index.js b/src/reducers/index.js index a84f2d3e..4a1d03ab 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -13,7 +13,6 @@ import currenciesStatus from './currenciesStatus' import devices from './devices' import modals from './modals' import settings from './settings' -import update from './update' import onboarding from './onboarding' import bridgeSync from './bridgeSync' @@ -22,7 +21,6 @@ import type { ApplicationState } from './application' import type { DevicesState } from './devices' import type { ModalsState } from './modals' import type { SettingsState } from './settings' -import type { UpdateState } from './update' import type { OnboardingState } from './onboarding' import type { BridgeSyncState } from './bridgeSync' import type { CurrenciesStatusState } from './currenciesStatus' @@ -36,7 +34,6 @@ export type State = { modals: ModalsState, router: LocationShape, settings: SettingsState, - update: UpdateState, onboarding: OnboardingState, bridgeSync: BridgeSyncState, } @@ -50,7 +47,6 @@ export default combineReducers({ modals, router, settings, - update, onboarding, bridgeSync, }) diff --git a/src/reducers/update.js b/src/reducers/update.js deleted file mode 100644 index 5eac36b5..00000000 --- a/src/reducers/update.js +++ /dev/null @@ -1,48 +0,0 @@ -// @flow - -import { handleActions, createAction } from 'redux-actions' - -export type UpdateStatus = - | 'idle' - | 'checking' - | 'available' - | 'progress' - | 'unavailable' - | 'error' - | 'downloaded' - -export type UpdateState = { - status: UpdateStatus, - data?: Object, -} - -const state: UpdateState = { - status: 'idle', - data: {}, -} - -const handlers = { - UPDATE_SET_STATUS: (state: UpdateState, { payload }: { payload: UpdateState }): UpdateState => - payload, -} - -// Actions - -export const setUpdateStatus = createAction( - 'UPDATE_SET_STATUS', - (status: UpdateStatus, data?: Object): UpdateState => ({ status, data }), -) - -// Selectors - -export function getUpdateStatus(state: { update: UpdateState }): UpdateStatus { - return state.update.status -} - -export function getUpdateData(state: { update: UpdateState }): Object { - return state.update.data || {} -} - -// Default export - -export default handleActions(handlers, state) diff --git a/src/renderer/events.js b/src/renderer/events.js index 59324cd1..f233913c 100644 --- a/src/renderer/events.js +++ b/src/renderer/events.js @@ -21,7 +21,6 @@ import { onSetDeviceBusy } from 'components/DeviceBusyIndicator' import { onSetLibcoreBusy } from 'components/LibcoreBusyIndicator' import { lock } from 'reducers/application' -import { setUpdateStatus } from 'reducers/update' import { addDevice, removeDevice, resetDevices } from 'actions/devices' import listenDevices from 'commands/listenDevices' @@ -32,11 +31,6 @@ const d = { update: debug('lwd:update'), } -type MsgPayload = { - type: string, - data: any, -} - // TODO port remaining to command pattern export function sendEvent(channel: string, msgType: string, data: any) { ipcRenderer.send(channel, { @@ -109,25 +103,6 @@ export default ({ store }: { store: Object }) => { onSetDeviceBusy(busy) }) } - - if (__PROD__) { - // TODO move this to "command" pattern - const updaterHandlers = { - checking: () => store.dispatch(setUpdateStatus('checking')), - updateAvailable: info => store.dispatch(setUpdateStatus('available', info)), - updateNotAvailable: () => store.dispatch(setUpdateStatus('unavailable')), - error: err => store.dispatch(setUpdateStatus('error', err)), - downloadProgress: progress => store.dispatch(setUpdateStatus('progress', progress)), - downloaded: () => store.dispatch(setUpdateStatus('downloaded')), - } - ipcRenderer.on('updater', (event: any, payload: MsgPayload) => { - const { type, data } = payload - updaterHandlers[type](data) - }) - - // Start check of eventual updates - checkUpdates() - } } if (module.hot) { From 41ec097931b1b035827c1ab138916a8610fb2320 Mon Sep 17 00:00:00 2001 From: meriadec Date: Wed, 12 Dec 2018 10:28:13 +0100 Subject: [PATCH 07/14] For now, always allow update even if check failed --- src/commands/autoUpdate.js | 12 +++++++++--- src/config/constants.js | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/commands/autoUpdate.js b/src/commands/autoUpdate.js index 9dd08d0b..e4e466a0 100644 --- a/src/commands/autoUpdate.js +++ b/src/commands/autoUpdate.js @@ -3,6 +3,7 @@ import { createCommand, Command } from 'helpers/ipc' import { Observable } from 'rxjs' +import { UPDATE_CHECK_IGNORE, UPDATE_CHECK_FEED } from 'config/constants' import createElectronAppUpdater from 'main/updater/createElectronAppUpdater' import type { UpdateStatus } from 'components/Updater/UpdaterContext' @@ -23,14 +24,19 @@ const cmd: Command = createCommand('main:autoUpdate', () => const handleDownload = async info => { try { const appUpdater = await createElectronAppUpdater({ - feedURL: process.env.LL_UPDATE_FEED || 'https://insert.feed.here', + feedURL: UPDATE_CHECK_FEED, updateVersion: info.version, }) await appUpdater.verify() sendStatus('check-success') } catch (err) { - // todo delete update file - o.error(err) + // don't throw if the check fail for now. it's a white bullet. + if (UPDATE_CHECK_IGNORE) { + // TODO: track the error + sendStatus('check-success') + } else { + o.error(err) + } } } diff --git a/src/config/constants.js b/src/config/constants.js index ac43b517..47aa4670 100644 --- a/src/config/constants.js +++ b/src/config/constants.js @@ -95,6 +95,11 @@ export const EXPERIMENTAL_MARKET_INDICATOR_SETTINGS = boolFromEnv( ) export const USE_MOCK_DATA = boolFromEnv('USE_MOCK_DATA') +// Auto update + +export const UPDATE_CHECK_IGNORE = boolFromEnv('UPDATE_IGNORE_CHECK', true) +export const UPDATE_CHECK_FEED = stringFromEnv('UPDATE_CHECK_FEED', 'https://insert.feed.here') + // Other constants export const MAX_ACCOUNT_NAME_SIZE = 50 From d8da84033354b271ff660877732a0527eddc2d9c Mon Sep 17 00:00:00 2001 From: meriadec Date: Wed, 12 Dec 2018 10:42:06 +0100 Subject: [PATCH 08/14] Remove node_modules cache in release script --- scripts/release.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/release.sh b/scripts/release.sh index 34a31fcb..e95ec8d3 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -67,6 +67,7 @@ if [[ $(uname) == 'Linux' ]]; then # only run it on one target, to prevent race "failed to create a draft release" fi +runJob "rm -rf ./node_modules/.cache" "Removing node modules cache..." "done" "fail" runJob "yarn compile" "compiling..." "compiled" "failed to compile" "verbose" if [[ $(uname) == 'Linux' ]]; then From 7c9fb0d314c33146ba223e91dd67eec3d46bd458 Mon Sep 17 00:00:00 2001 From: meriadec Date: Thu, 13 Dec 2018 17:10:14 +0100 Subject: [PATCH 09/14] Polishing the update Banner --- src/commands/autoUpdate.js | 1 + src/components/Updater/Banner.js | 111 ++++++++++++++++++++++------ src/components/Updater/UpdateDot.js | 55 +------------- src/config/urls.js | 2 + src/icons/Donjon.js | 39 ++++++++++ src/icons/TriangleWarning.js | 13 +++- static/i18n/en/app.json | 9 ++- 7 files changed, 150 insertions(+), 80 deletions(-) create mode 100644 src/icons/Donjon.js diff --git a/src/commands/autoUpdate.js b/src/commands/autoUpdate.js index e4e466a0..23bef623 100644 --- a/src/commands/autoUpdate.js +++ b/src/commands/autoUpdate.js @@ -23,6 +23,7 @@ const cmd: Command = createCommand('main:autoUpdate', () => const handleDownload = async info => { try { + sendStatus('checking') const appUpdater = await createElectronAppUpdater({ feedURL: UPDATE_CHECK_FEED, updateVersion: info.version, diff --git a/src/components/Updater/Banner.js b/src/components/Updater/Banner.js index d0d0321e..9c30daae 100644 --- a/src/components/Updater/Banner.js +++ b/src/components/Updater/Banner.js @@ -2,11 +2,17 @@ import React, { PureComponent } from 'react' import styled from 'styled-components' +import { Trans } from 'react-i18next' +import { urls } from 'config/urls' import { radii } from 'styles/theme' +import { openURL } from 'helpers/linking' -import TranslatedError from 'components/TranslatedError' +import Spinner from 'components/base/Spinner' import Box from 'components/base/Box' +import IconUpdate from 'icons/Update' +import IconDonjon from 'icons/Donjon' +import IconWarning from 'icons/TriangleWarning' import { withUpdaterContext } from './UpdaterContext' import type { UpdaterContextType } from './UpdaterContext' @@ -17,38 +23,98 @@ type Props = { export const VISIBLE_STATUS = ['download-progress', 'checking', 'check-success', 'error'] +type Content = { + Icon: React$ComponentType<*>, + message: React$Node, + Right?: React$ComponentType<*>, +} + +type RightProps = { + downloadProgress: number, // eslint-disable-line react/no-unused-prop-types + quitAndInstall: () => void, // eslint-disable-line react/no-unused-prop-types + reDownload: () => void, // eslint-disable-line react/no-unused-prop-types +} + +const CONTENT_BY_STATUS: { [_: string]: Content } = { + 'download-progress': { + Icon: Spinner, + message: , + Right: ({ downloadProgress }: RightProps) => ( + + ), + }, + checking: { + Icon: IconDonjon, + message: , + }, + 'check-success': { + Icon: IconUpdate, + message: , + Right: ({ quitAndInstall }: RightProps) => ( + + + + ), + }, + error: { + Icon: IconWarning, + message: , + Right: ({ reDownload }: RightProps) => ( + + + + ), + }, +} + class UpdaterTopBanner extends PureComponent { + reDownload = () => { + openURL(urls.liveHome) + } + render() { const { context } = this.props - const { status, quitAndInstall, downloadProgress, error } = context + const { status, quitAndInstall, downloadProgress } = context if (!VISIBLE_STATUS.includes(status)) return null + const content: ?Content = CONTENT_BY_STATUS[status] + if (!content) return null + + const { Icon, message, Right } = content + return ( - {status === 'download-progress' && `Downloading update... ${Math.round(downloadProgress)}%`} - {status === 'checking' && `Verifying update...`} - {status === 'error' && - error && ( -
- {'Error during update. Please download again.'} - - - -
- )} - {status === 'check-success' && ( -
- {'Update ready to install. '} - {'install now'} -
+ {Icon && ( + + {/* $FlowFixMe let me do my stuff, flow */} + + + )} + {message} + {Right && ( + + + )}
) } } +const IconContainer = styled.div` + margin-right: 15px; + display: flex; + align-items: center; +` + const Container = styled(Box).attrs({ + horizontal: true, + align: 'center', py: '8px', px: 3, bg: p => (p.status === 'error' ? 'alertRed' : 'wallet'), @@ -56,20 +122,19 @@ const Container = styled(Box).attrs({ mt: -20, mb: 20, fontSize: 4, + ff: 'Open Sans|SemiBold', })` border-radius: ${radii[1]}px; ` -const DownloadLink = styled.span` +const FakeLink = styled.span` color: white; text-decoration: underline; cursor: pointer; ` -const ErrorContainer = styled.div` - margin-top: 10px; - font-family: monospace; - font-size: 10px; +const RightContainer = styled.div` + margin-left: auto; ` export default withUpdaterContext(UpdaterTopBanner) diff --git a/src/components/Updater/UpdateDot.js b/src/components/Updater/UpdateDot.js index 01a34bb5..65a81a98 100644 --- a/src/components/Updater/UpdateDot.js +++ b/src/components/Updater/UpdateDot.js @@ -1,7 +1,7 @@ // @flow import React from 'react' -import styled, { keyframes } from 'styled-components' +import styled from 'styled-components' import { colors } from 'styles/theme' @@ -13,15 +13,6 @@ type Props = { context: UpdaterContextType, } -const rotate = keyframes` - 0% { - transform: rotate(0deg); - } - 100% { - transform: rotate(360deg); - } -` - const getColor = ({ status }: { status: UpdateStatus }) => status === 'error' ? colors.alertRed : colors.wallet @@ -36,53 +27,11 @@ const Dot = styled.div` border-radius: 50%; ` -const Spinner = styled.div` - opacity: 0.5; - position: absolute; - top: -3px; - left: -3px; - animation: ${rotate} 1.5s linear infinite; - width: 14px; - height: 14px; - - &:before { - content: ''; - position: absolute; - right: 0; - bottom: 0; - width: 4px; - height: 4px; - background-color: ${colors.wallet}; - border-radius: 50%; - } - - &:after { - content: ''; - position: absolute; - width: 4px; - height: 4px; - background-color: ${colors.wallet}; - border-radius: 50%; - } -` - function UpdateDot(props: Props) { const { context } = props const { status } = context if (!VISIBLE_STATUS.includes(status)) return null - const showSpinner = status === 'download-progress' || status === 'checking' - return ( -
- {showSpinner && } - -
- ) -} - -const styles = { - container: { - position: 'relative', - }, + return } export default withUpdaterContext(UpdateDot) diff --git a/src/config/urls.js b/src/config/urls.js index 1e0d5376..d022acdf 100644 --- a/src/config/urls.js +++ b/src/config/urls.js @@ -1,6 +1,8 @@ // @flow export const urls = { + liveHome: 'https://www.ledger.com/pages/ledger-live', + // Social twitter: 'https://twitter.com/LedgerHQ', github: 'https://github.com/LedgerHQ/ledger-live-desktop', diff --git a/src/icons/Donjon.js b/src/icons/Donjon.js new file mode 100644 index 00000000..1353a6a7 --- /dev/null +++ b/src/icons/Donjon.js @@ -0,0 +1,39 @@ +// @flow + +import React, { Fragment } from 'react' + +const path = ( + + + + + + + + +) + +export default ({ size, ...p }: { size: number }) => ( + + {path} + +) diff --git a/src/icons/TriangleWarning.js b/src/icons/TriangleWarning.js index c53743bd..72062996 100644 --- a/src/icons/TriangleWarning.js +++ b/src/icons/TriangleWarning.js @@ -9,8 +9,17 @@ const path = ( /> ) -export default ({ height, width, ...p }: { height: number, width: number }) => ( - +export default ({ + height, + width, + size, + ...p +}: { + height?: number, + width?: number, + size?: number, +}) => ( + {path} ) diff --git a/static/i18n/en/app.json b/static/i18n/en/app.json index 5f7804a6..bf20ecbf 100644 --- a/static/i18n/en/app.json +++ b/static/i18n/en/app.json @@ -478,8 +478,13 @@ } }, "update": { - "newVersionReady": "A new update is available", - "relaunch": "Update now" + "downloadInProgress": "Downloading update...", + "downloadProgress": "{{progress}}% completed", + "checking": "Checking update...", + "checkSuccess": "Update ready to install", + "quitAndInstall": "Install now", + "error": "Error during update. Please download again", + "reDownload": "Download again" }, "crash": { "oops": "Oops, something went wrong", From 2f760f230f1724915e63426e3d8b99129069c8f9 Mon Sep 17 00:00:00 2001 From: meriadec Date: Tue, 18 Dec 2018 00:18:21 +0100 Subject: [PATCH 10/14] Add script to generate shasum file from a release --- scripts/create-release-shasums.sh | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 scripts/create-release-shasums.sh diff --git a/scripts/create-release-shasums.sh b/scripts/create-release-shasums.sh new file mode 100644 index 00000000..d6d2166b --- /dev/null +++ b/scripts/create-release-shasums.sh @@ -0,0 +1,51 @@ +#!/bin/env bash + +# Fetch release binaries for all platforms +# and produce a .sha512sum file in the current folder + +# exit on error +set -e + +[[ "$GH_TOKEN" == "" ]] && echo "GH_TOKEN is unset" && exit 1 + +function main { + ASSETS_FILTER="(AppImage|zip|exe)" + PKG_VER=$(grep version package.json | sed -E 's/.*: "(.*)",/\1/g') + OUTPUT_FILE="ledger-live-desktop-$PKG_VER.sha512sum" + + read -p "> release version ($PKG_VER): " -r RELEASE_VERSION + RELEASE_VERSION=${RELEASE_VERSION:-$PKG_VER} + + RELEASES=$(do_request "/repos/LedgerHQ/ledger-live-desktop/releases") + printf """ + console.log( + (%s).find(r => r.tag_name === 'v%s').assets + .filter(a => a.name.match(/\\.%s$/)) + .map(a => a.browser_download_url) + .join('\\\n') + ) + """ "$RELEASES" "$RELEASE_VERSION" "$ASSETS_FILTER" >"$TMP_FILE1" + node "$TMP_FILE1" | tee "$TMP_FILE2" + + pushd "$TMP_DIR" >/dev/null + while IFS= read -r line ; do + curl -L -O "$line" + done < "$TMP_FILE2" + sha512sum -- * > "$OLDPWD/$OUTPUT_FILE" + popd >/dev/null +} + +TMP_DIR=$(mktemp -d) +TMP_FILE1=$(mktemp) +TMP_FILE2=$(mktemp) + +function cleanup { + rm -rf "$TMP_FILE1" "$TMP_FILE2" "$TMP_DIR" +} + +function do_request { + curl -H "Authorization: token $GH_TOKEN" "https://api.github.com$1" +} + +trap cleanup EXIT +main From b7b81ad420176c984d43729ab6fc0c8cb500a447 Mon Sep 17 00:00:00 2001 From: Juan Cortes Ross Date: Wed, 6 Feb 2019 01:08:43 +0100 Subject: [PATCH 11/14] Refactor of top banner and nano-x promotional banner --- src/components/DashboardPage/index.js | 26 +++++- src/components/TopBanner.js | 129 ++++++++++++++++++++++++++ src/components/Updater/Banner.js | 88 +++--------------- src/config/urls.js | 3 + static/i18n/en/app.json | 3 + 5 files changed, 171 insertions(+), 78 deletions(-) create mode 100644 src/components/TopBanner.js diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index 82692d8b..a9ba5ec8 100644 --- a/src/components/DashboardPage/index.js +++ b/src/components/DashboardPage/index.js @@ -3,6 +3,7 @@ import React, { PureComponent, Fragment } from 'react' import uniq from 'lodash/uniq' import { compose } from 'redux' +import IconExternalLink from 'icons/ExternalLink' import { translate } from 'react-i18next' import { connect } from 'react-redux' import { push } from 'react-router-redux' @@ -31,10 +32,14 @@ import Box from 'components/base/Box' import PillsDaysCount from 'components/PillsDaysCount' import OperationsList from 'components/OperationsList' import StickyBackToTop from 'components/StickyBackToTop' +import styled from 'styled-components' +import { openURL } from 'helpers/linking' import EmptyState from './EmptyState' import CurrentGreetings from './CurrentGreetings' import SummaryDesc from './SummaryDesc' import AccountCardList from './AccountCardList' +import TopBanner, { FakeLink } from '../TopBanner' +import { urls } from '../../config/urls' const mapStateToProps = createStructuredSelector({ accounts: accountsSelector, @@ -84,7 +89,20 @@ class DashboardPage extends PureComponent { return ( - + + + openURL(urls.nanoX)}>{t('common.learnMore')} + ), + }} + bannerId={'promoteMobile'} + dismissable + /> + { ) } } +// This forces only one visible top banner at a time +const TopBannerContainer = styled.div` + & > *:not(:first-child) { + display: none; + } +` export default compose( connect( diff --git a/src/components/TopBanner.js b/src/components/TopBanner.js new file mode 100644 index 00000000..0dd0ca6d --- /dev/null +++ b/src/components/TopBanner.js @@ -0,0 +1,129 @@ +// @flow + +import React, { PureComponent } from 'react' +import styled from 'styled-components' +import { connect } from 'react-redux' +import Box from 'components/base/Box' +import { radii } from 'styles/theme' +import IconCross from 'icons/Cross' +import { createStructuredSelector } from 'reselect' +import { dismissBanner } from '../actions/settings' +import { dismissedBannersSelector } from '../reducers/settings' + +export type Content = { + Icon?: React$ComponentType<*>, + message: React$Node, + right?: React$Node, +} + +type Props = { + content?: Content, + status: string, + dismissable: boolean, + bannerId?: string, + dismissedBanners: string[], + dismissBanner: string => void, +} + +const mapStateToProps = createStructuredSelector({ + dismissedBanners: dismissedBannersSelector, +}) + +const mapDispatchToProps = { + dismissBanner, +} + +class TopBanner extends PureComponent { + static defaultProps = { + status: '', + dismissable: false, + } + + onDismiss = () => { + const { bannerId, dismissBanner } = this.props + + if (bannerId) { + dismissBanner(bannerId) + } + } + + render() { + const { dismissedBanners, bannerId, dismissable, content, status } = this.props + + if (!content || (bannerId && dismissedBanners.includes(bannerId))) return null + + const { Icon, message, right } = content + + return ( + + {Icon && ( + + + + )} + {message} + {right} + {dismissable && ( + + + + )} + + ) + } +} + +export default connect( + mapStateToProps, + mapDispatchToProps, +)(TopBanner) + +const IconContainer = styled.div` + margin-right: 15px; + display: flex; + align-items: center; +` + +const colorForStatus = { + error: 'alertRed', +} + +const Container = styled(Box).attrs({ + horizontal: true, + align: 'center', + py: '8px', + px: 3, + bg: p => colorForStatus[p.status] || 'wallet', + color: 'white', + mt: -20, + mb: 20, + fontSize: 4, + ff: 'Open Sans|SemiBold', +})` + border-radius: ${radii[1]}px; +` + +const RightContainer = styled.div` + margin-left: auto; +` + +export const FakeLink = styled.span` + color: white; + text-decoration: underline; + cursor: pointer; +` + +const CloseContainer = styled(Box).attrs({ + color: 'white', +})` + z-index: 1; + margin-left: 10px; + cursor: pointer; + &:hover { + color: ${p => p.theme.colors.graphite}; + } + + &:active { + color: ${p => p.theme.colors.graphite}; + } +` diff --git a/src/components/Updater/Banner.js b/src/components/Updater/Banner.js index 9c30daae..40758af4 100644 --- a/src/components/Updater/Banner.js +++ b/src/components/Updater/Banner.js @@ -1,21 +1,20 @@ // @flow import React, { PureComponent } from 'react' -import styled from 'styled-components' import { Trans } from 'react-i18next' import { urls } from 'config/urls' -import { radii } from 'styles/theme' import { openURL } from 'helpers/linking' import Spinner from 'components/base/Spinner' -import Box from 'components/base/Box' import IconUpdate from 'icons/Update' import IconDonjon from 'icons/Donjon' import IconWarning from 'icons/TriangleWarning' import { withUpdaterContext } from './UpdaterContext' import type { UpdaterContextType } from './UpdaterContext' +import TopBanner, { FakeLink } from '../TopBanner' +import type { Content } from '../TopBanner' type Props = { context: UpdaterContextType, @@ -23,25 +22,11 @@ type Props = { export const VISIBLE_STATUS = ['download-progress', 'checking', 'check-success', 'error'] -type Content = { - Icon: React$ComponentType<*>, - message: React$Node, - Right?: React$ComponentType<*>, -} - -type RightProps = { - downloadProgress: number, // eslint-disable-line react/no-unused-prop-types - quitAndInstall: () => void, // eslint-disable-line react/no-unused-prop-types - reDownload: () => void, // eslint-disable-line react/no-unused-prop-types -} - -const CONTENT_BY_STATUS: { [_: string]: Content } = { +const CONTENT_BY_STATUS = (quitAndInstall, reDownload, progress): { [string]: Content } => ({ 'download-progress': { Icon: Spinner, message: , - Right: ({ downloadProgress }: RightProps) => ( - - ), + right: , }, checking: { Icon: IconDonjon, @@ -50,7 +35,7 @@ const CONTENT_BY_STATUS: { [_: string]: Content } = { 'check-success': { Icon: IconUpdate, message: , - Right: ({ quitAndInstall }: RightProps) => ( + right: ( @@ -59,13 +44,13 @@ const CONTENT_BY_STATUS: { [_: string]: Content } = { error: { Icon: IconWarning, message: , - Right: ({ reDownload }: RightProps) => ( + right: ( ), }, -} +}) class UpdaterTopBanner extends PureComponent { reDownload = () => { @@ -75,66 +60,15 @@ class UpdaterTopBanner extends PureComponent { render() { const { context } = this.props const { status, quitAndInstall, downloadProgress } = context - if (!VISIBLE_STATUS.includes(status)) return null - const content: ?Content = CONTENT_BY_STATUS[status] + const content: ?Content = CONTENT_BY_STATUS(quitAndInstall, this.reDownload, downloadProgress)[ + status + ] if (!content) return null - const { Icon, message, Right } = content - - return ( - - {Icon && ( - - {/* $FlowFixMe let me do my stuff, flow */} - - - )} - {message} - {Right && ( - - - - )} - - ) + return } } -const IconContainer = styled.div` - margin-right: 15px; - display: flex; - align-items: center; -` - -const Container = styled(Box).attrs({ - horizontal: true, - align: 'center', - py: '8px', - px: 3, - bg: p => (p.status === 'error' ? 'alertRed' : 'wallet'), - color: 'white', - mt: -20, - mb: 20, - fontSize: 4, - ff: 'Open Sans|SemiBold', -})` - border-radius: ${radii[1]}px; -` - -const FakeLink = styled.span` - color: white; - text-decoration: underline; - cursor: pointer; -` - -const RightContainer = styled.div` - margin-left: auto; -` - export default withUpdaterContext(UpdaterTopBanner) diff --git a/src/config/urls.js b/src/config/urls.js index 9a194a1b..8ac91581 100644 --- a/src/config/urls.js +++ b/src/config/urls.js @@ -8,6 +8,9 @@ export const urls = { github: 'https://github.com/LedgerHQ/ledger-live-desktop', reddit: 'https://www.reddit.com/r/ledgerwallet/', + // Products + nanoX: 'https://www.ledger.com/pages/ledger-nano-x', + // Ledger support faq: 'https://support.ledgerwallet.com/hc/en-us', terms: 'https://www.ledger.com/pages/terms-of-use-and-disclaimer', diff --git a/static/i18n/en/app.json b/static/i18n/en/app.json index 89b2aa4c..3f6fc47d 100644 --- a/static/i18n/en/app.json +++ b/static/i18n/en/app.json @@ -111,6 +111,9 @@ } } }, + "banners": { + "promoteMobile": "Enjoy the Ledger Live experience, now available on mobile with the Ledger Nano X" + }, "dashboard": { "title": "Portfolio", "emptyAccountTile": { From c7a95c60d203a8983404de46c77ba702a067fce9 Mon Sep 17 00:00:00 2001 From: Juan Cortes Ross Date: Wed, 6 Feb 2019 13:59:38 +0100 Subject: [PATCH 12/14] Updated UI to the design --- src/components/DashboardPage/index.js | 7 ++++--- src/components/TopBanner.js | 7 ++++--- src/icons/device/NanoX.js | 30 +++++++++++++++++++++++++++ src/icons/device/index.js | 1 + 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 src/icons/device/NanoX.js diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index a9ba5ec8..d23db34e 100644 --- a/src/components/DashboardPage/index.js +++ b/src/components/DashboardPage/index.js @@ -3,7 +3,7 @@ import React, { PureComponent, Fragment } from 'react' import uniq from 'lodash/uniq' import { compose } from 'redux' -import IconExternalLink from 'icons/ExternalLink' +import IconNanoX from 'icons/device/NanoX' import { translate } from 'react-i18next' import { connect } from 'react-redux' import { push } from 'react-router-redux' @@ -94,12 +94,13 @@ class DashboardPage extends PureComponent { openURL(urls.nanoX)}>{t('common.learnMore')} ), }} - bannerId={'promoteMobile'} + status={'dark'} + bannerId={'promoteMobile2'} dismissable /> diff --git a/src/components/TopBanner.js b/src/components/TopBanner.js index 0dd0ca6d..bad4c141 100644 --- a/src/components/TopBanner.js +++ b/src/components/TopBanner.js @@ -65,7 +65,7 @@ class TopBanner extends PureComponent { {right} {dismissable && ( - + )} @@ -86,6 +86,7 @@ const IconContainer = styled.div` const colorForStatus = { error: 'alertRed', + dark: '#142533', } const Container = styled(Box).attrs({ @@ -120,10 +121,10 @@ const CloseContainer = styled(Box).attrs({ margin-left: 10px; cursor: pointer; &:hover { - color: ${p => p.theme.colors.graphite}; + color: #eee; } &:active { - color: ${p => p.theme.colors.graphite}; + color: #eee; } ` diff --git a/src/icons/device/NanoX.js b/src/icons/device/NanoX.js new file mode 100644 index 00000000..f72d05a4 --- /dev/null +++ b/src/icons/device/NanoX.js @@ -0,0 +1,30 @@ +// @flow + +import React from 'react' + +export default ({ size = 30, ...p }: { size: number }) => ( + + + + + + + + + + + + + + + + + +) diff --git a/src/icons/device/index.js b/src/icons/device/index.js index b8802bf8..f5282739 100644 --- a/src/icons/device/index.js +++ b/src/icons/device/index.js @@ -1,2 +1,3 @@ export Blue from './Blue' export NanoS from './NanoS' +export NanoX from './NanoX' From bdbdedc0c2a332d459519663e4f57514578d308c Mon Sep 17 00:00:00 2001 From: Juan Cortes Ross Date: Thu, 7 Feb 2019 10:17:12 +0100 Subject: [PATCH 13/14] Updated the url for campaign analytics --- src/components/DashboardPage/index.js | 6 ++++-- src/config/urls.js | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index d23db34e..e7daa927 100644 --- a/src/components/DashboardPage/index.js +++ b/src/components/DashboardPage/index.js @@ -96,11 +96,13 @@ class DashboardPage extends PureComponent { message: t('banners.promoteMobile'), Icon: IconNanoX, right: ( - openURL(urls.nanoX)}>{t('common.learnMore')} + openURL(urls.promoNanoX)}> + {t('common.learnMore')} + ), }} status={'dark'} - bannerId={'promoteMobile2'} + bannerId={'promoNanoX'} dismissable /> diff --git a/src/config/urls.js b/src/config/urls.js index 8ac91581..4802926b 100644 --- a/src/config/urls.js +++ b/src/config/urls.js @@ -8,8 +8,9 @@ export const urls = { github: 'https://github.com/LedgerHQ/ledger-live-desktop', reddit: 'https://www.reddit.com/r/ledgerwallet/', - // Products - nanoX: 'https://www.ledger.com/pages/ledger-nano-x', + // Campaigns + promoNanoX: + 'https://www.ledger.com/pages/ledger-nano-x#utm_source=Ledger%20Live%20Desktop%20App&utm_medium=Ledger%20Live&utm_campaign=Ledger%20Live%20Desktop%20-%20Banner%20LNX', // Ledger support faq: 'https://support.ledgerwallet.com/hc/en-us', From 17b679b75cd25340eca8d78a3612104d294a79a0 Mon Sep 17 00:00:00 2001 From: Juan Cortes Ross Date: Thu, 7 Feb 2019 19:30:27 +0100 Subject: [PATCH 14/14] Removes the bottom border from topbar and makes it conditionally render if no banners are present, comment the logic for the updater until we have it ready to ship. --- src/commands/autoUpdate.js | 12 ++++++------ src/components/DashboardPage/index.js | 8 ++++++++ src/components/TopBar/index.js | 4 +--- src/components/layout/Default.js | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/commands/autoUpdate.js b/src/commands/autoUpdate.js index 23bef623..93204a37 100644 --- a/src/commands/autoUpdate.js +++ b/src/commands/autoUpdate.js @@ -21,14 +21,14 @@ const cmd: Command = createCommand('main:autoUpdate', () => o.next({ status, payload }) } - const handleDownload = async info => { + const handleDownload = async _ => { try { sendStatus('checking') - const appUpdater = await createElectronAppUpdater({ - feedURL: UPDATE_CHECK_FEED, - updateVersion: info.version, - }) - await appUpdater.verify() + // const appUpdater = await createElectronAppUpdater({ + // feedURL: UPDATE_CHECK_FEED, + // updateVersion: info.version, + // }) + // await appUpdater.verify() sendStatus('check-success') } catch (err) { // don't throw if the check fail for now. it's a white bullet. diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index e7daa927..f3317bb5 100644 --- a/src/components/DashboardPage/index.js +++ b/src/components/DashboardPage/index.js @@ -105,6 +105,7 @@ class DashboardPage extends PureComponent { bannerId={'promoNanoX'} dismissable /> + p.theme.colors.fog}; + margin-bottom: 15px; + margin-top: -20px; +` export default compose( connect( diff --git a/src/components/TopBar/index.js b/src/components/TopBar/index.js index b18914c5..c8f21afc 100644 --- a/src/components/TopBar/index.js +++ b/src/components/TopBar/index.js @@ -42,9 +42,7 @@ const Inner = styled(Box).attrs({ grow: true, flow: 4, align: 'center', -})` - border-bottom: 1px solid ${p => p.theme.colors.fog}; -` +})`` const Bar = styled.div` margin-left: 5px; diff --git a/src/components/layout/Default.js b/src/components/layout/Default.js index dbe41b7f..14156b39 100644 --- a/src/components/layout/Default.js +++ b/src/components/layout/Default.js @@ -43,7 +43,7 @@ const Main = styled(GrowScroll).attrs({ px: 6, })` outline: none; - padding-top: ${p => p.theme.sizes.topBarHeight + p.theme.space[7]}px; + padding-top: ${p => p.theme.sizes.topBarHeight + p.theme.space[4]}px; ` type Props = {