From b1f92aac8918daa8a22f3c3d33720cf041b2b738 Mon Sep 17 00:00:00 2001 From: Gabe Isman Date: Tue, 19 Apr 2016 18:58:05 -0700 Subject: [PATCH] Rough VeraCrypt integration Needs some more error handling and messaging. Only tested on OS X. --- app/components/Export.js | 18 +++++++++++++- app/lib/veracrypt.js | 52 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 app/lib/veracrypt.js diff --git a/app/components/Export.js b/app/components/Export.js index 7aab3e3..4561878 100644 --- a/app/components/Export.js +++ b/app/components/Export.js @@ -6,6 +6,8 @@ import CopyButton from './CopyButton'; import SaveFileButton from './SaveFileButton'; import PuzzleIcon from './PuzzleIcon'; import Modal from './Modal'; +import { remote } from 'electron'; +import openVolume from 'app/lib/veracrypt'; export default class Export extends Component { @@ -25,7 +27,21 @@ export default class Export extends Component { } handleVeracrypt() { - console.log('veracrypt'); + return new Promise((resolve, reject) => { + remote.dialog.showOpenDialog({ + title: 'Select VeraCrypt volume', + properties: ['openFile'] + }, (filenames) => { + const path = filenames[0]; + openVolume(path, this.props.secret) + .then(resolve) // Nothing to do on success + .catch((err) => { + // TODO: Display an error message. + console.log(err); + reject(err); + }); + }); + }); } render() { diff --git a/app/lib/veracrypt.js b/app/lib/veracrypt.js new file mode 100644 index 0000000..07cf18c --- /dev/null +++ b/app/lib/veracrypt.js @@ -0,0 +1,52 @@ +import { remote } from 'electron'; +/* eslint-disable camelcase */ +const child_process = remote.require('child_process'); +/* eslint-enable */ + +export default function openVolume(path, password) { + // There is some work to do to make this work cross-platform. + // The VeraCrypt linux installer puts a symlink to the binary in /usr/bin, + // but the Mac installer doesn't (annoyingly). The Windows binary has a + // different interface entirely, documented at + // https://veracrypt.codeplex.com/wikipage?title=Command%20Line%20Usage. + let binary; + let fallbackBinary; + let args = `--mount ${path} --password ${password} --explore`; + if (process.platform === 'darwin') { + binary = '/Applications/VeraCrypt.app/Contents/MacOS/VeraCrypt'; + fallbackBinary = 'veracrypt'; + } else if (process.platform === 'linux') { + binary = 'veracrypt'; + } else if (process.platform === 'win32') { + binary = 'VeraCrypt.exe'; + args = `/volume ${path} /password ${password} /explore`; + } else { + return Promise.reject('Unsupported platform'); + } + + return execPromise(`${binary} ${args}`) + .catch((errObj) => { + if (fallbackBinary) { + return execPromise(`${fallbackBinary} ${args}`) + .catch(parseErrors); + } + return errObj; + }).catch(parseErrors); +} + +function execPromise(command) { + return new Promise((resolve, reject) => { + child_process.exec(command, (err, stdout, stderr) => { + if (err) { + reject({ err, stderr }); + } + + resolve(stdout); + }); + }); +} + +function parseErrors(errObj) { + // TODO: Figure out if this needs to be better + return errObj.err; +}