Permalink
Browse files

[init] Initial commit

  • Loading branch information...
0 parents commit cca6763fdf44f26581d932f0a408d14d96f3315c @AvianFlu committed Jun 17, 2011
Showing with 128 additions and 0 deletions.
  1. +19 −0 LICENSE
  2. +89 −0 gpgstore
  3. +20 −0 package.json
@@ -0,0 +1,19 @@
+Copyright (C) <2011> by <Charles McConnell>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,89 @@
+#!/usr/bin/env node
+
+var argv = require('optimist').argv,
+ fs = require('fs'),
+ childProcess = require('child_process'),
+ async = require('async');
+
+
+if (!argv._[0]) {
+ console.log('Usage: gpgstore [master file]');
+ process.exit(1);
+}
+else {
+ getMaster();
+}
+
+function getMaster() {
+ var tiers,
+ file,
+ tierCount,
+ keyID;
+ fs.readFile(argv._[0], function (err, data) {
+ if (err) { console.log(err); }
+ try {
+ tiers = JSON.parse(data);
+ }
+ catch(err) {
+ console.log('Sorry, error parsing your JSON.');
+ console.log(err.stack);
+ process.exit(1);
+ }
+ tierCount = tiers.length;
+ for (var i = 0; i < tierCount; i++) {
+ async.series( [
+ function (callback) {
+ file = 'tier' + i.toString();
+ keyID = tiers[0].keyID;
+ callback(null, file, keyID);
+ },
+ function (callback) {
+ fs.writeFile(file, JSON.stringify(tiers), function (err) {
+ if (err) { console.log(err); }
+ callback(null, err);
+ });
+ },
+ ], callback);
+ function callback (err, results) {
+ if (err) { console.log(err); }
+ spawnArgs = ['--encrypt', '-r', results[0][1], '-o', results[0][0] + '.gpg', results[0][0]];
+ console.log(spawnArgs.join(' '));
+ encrypt(spawnArgs);
+ }
+ tiers.shift();
+ }
+ });
+}
+
+//The only encryption currently supported is file-to-file.
+function encrypt(spawnArgs) {
+ var gpg = childProcess.spawn('gpg', spawnArgs);
+ gpg.stderr.on('data', function (data) {
+ console.log('stderr: '+data);
+ });
+ gpg.stdout.on('data', function (data) {
+ console.log('stdout: '+data);
+ });
+ gpg.on('exit', function (code) {
+ if (code > 0) { console.log('gpg exited with status code: ', code); }
+ fs.unlink(spawnArgs[5], function (err) {
+ if (err) { console.log(err); }
+ });
+ });
+}
+
+//Decrypt, either file-to-buffer or file-to-file.
+function decrypt() {
+ if (typeof options.dest === 'undefined') {
+ gpg.decryptFile(options.source, function (err, result) {
+ if (err) { console.log(err); }
+ console.log(result);
+ });
+ }
+ else {
+ gpg.decryptToFile(options, function (err) {
+ if (err) { console.log(err); }
+ });
+ }
+}
+
@@ -0,0 +1,20 @@
+{
+ "name": "gpgstore",
+ "description": "Experimental sensitive data storage tool.",
+ "version": "0.0.1",
+ "author": "AvianFlu",
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/AvianFlu/gpgstore.git"
+ },
+ "bin": {
+ "gpgstore": "./gpgstore"
+ },
+ "dependencies": {
+ "async": ">=0.1.9",
+ "optimist": ">=0.2.4"
+ },
+ "engine": [
+ "node >=0.4.0"
+ ]
+}

0 comments on commit cca6763

Please sign in to comment.