Skip to content
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.

Commit

Permalink
Rough VeraCrypt integration
Browse files Browse the repository at this point in the history
Needs some more error handling and messaging. Only tested on OS X.
  • Loading branch information
GabeIsman committed Apr 20, 2016
1 parent 8022f9d commit b1f92aa
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
18 changes: 17 additions & 1 deletion app/components/Export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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() {
Expand Down
52 changes: 52 additions & 0 deletions app/lib/veracrypt.js
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit b1f92aa

Please sign in to comment.