This repository has been archived by the owner on Jun 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Needs some more error handling and messaging. Only tested on OS X.
- Loading branch information
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |