mirror of
https://github.com/moparisthebest/mail
synced 2024-11-26 02:42:17 -05:00
commit
ce78e71cd7
@ -331,8 +331,8 @@ module.exports = function(grunt) {
|
||||
'node_modules/sinon/pkg/sinon.js',
|
||||
'node_modules/browsercrow/src/*.js',
|
||||
'node_modules/browsersmtp/src/*.js',
|
||||
'src/lib/openpgp/openpgp.js',
|
||||
'src/lib/openpgp/openpgp.worker.js',
|
||||
'src/lib/openpgp/openpgp.min.js',
|
||||
'src/lib/openpgp/openpgp.worker.min.js',
|
||||
'src/lib/forge/forge.min.js',
|
||||
'dist/js/pbkdf2-worker.min.js'
|
||||
],
|
||||
@ -342,7 +342,7 @@ module.exports = function(grunt) {
|
||||
expand: true,
|
||||
flatten: true,
|
||||
cwd: 'src/lib/',
|
||||
src: ['openpgp/openpgp.js', 'openpgp/openpgp.worker.js', 'forge/forge.min.js'],
|
||||
src: ['openpgp/openpgp.min.js', 'openpgp/openpgp.worker.min.js', 'forge/forge.min.js'],
|
||||
dest: 'dist/js/'
|
||||
},
|
||||
font: {
|
||||
|
@ -42,8 +42,8 @@
|
||||
"jquery": "~2.1.1",
|
||||
"mailreader": "~0.4.0",
|
||||
"ng-infinite-scroll": "~1.1.2",
|
||||
"pgpbuilder": "~0.4.0",
|
||||
"pgpmailer": "~0.4.0",
|
||||
"pgpbuilder": "~0.5.0",
|
||||
"pgpmailer": "~0.5.0",
|
||||
"tcp-socket": "~0.3.13",
|
||||
"wo-smtpclient": "^0.3.8",
|
||||
"angularjs": "https://github.com/whiteout-io/angular.js/tarball/npm-version",
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
<!-- The Scripts -->
|
||||
<script src="socket.io/socket.io.js"></script>
|
||||
<script src="js/openpgp.js"></script>
|
||||
<script src="js/openpgp.min.js"></script>
|
||||
<script src="js/forge.min.js"></script>
|
||||
<script src="js/app.min.js"></script>
|
||||
</head>
|
||||
|
@ -9,7 +9,7 @@ var util = openpgp.util,
|
||||
|
||||
var PGP = function() {
|
||||
openpgp.config.prefer_hash_algorithm = openpgp.enums.hash.sha256;
|
||||
openpgp.initWorker(config.workerPath + '/openpgp.worker.js');
|
||||
openpgp.initWorker(config.workerPath + '/openpgp.worker.min.js');
|
||||
};
|
||||
|
||||
/**
|
||||
@ -31,20 +31,13 @@ PGP.prototype.generateKeys = function(options, callback) {
|
||||
numBits: options.keySize,
|
||||
userId: userId,
|
||||
passphrase: passphrase
|
||||
}, onGenerated);
|
||||
|
||||
function onGenerated(err, keys) {
|
||||
if (err) {
|
||||
callback(new Error('Keygeneration failed!'));
|
||||
return;
|
||||
}
|
||||
|
||||
}).then(function(keys) {
|
||||
callback(null, {
|
||||
keyId: keys.key.primaryKey.getKeyId().toHex().toUpperCase(),
|
||||
privateKeyArmored: keys.privateKeyArmored,
|
||||
publicKeyArmored: keys.publicKeyArmored
|
||||
});
|
||||
}
|
||||
}).catch(callback);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -287,10 +280,10 @@ PGP.prototype.encrypt = function(plaintext, publicKeysArmored, callback) {
|
||||
|
||||
if (publicKeys) {
|
||||
// encrypt and sign the plaintext
|
||||
openpgp.signAndEncryptMessage(publicKeys, this._privateKey, plaintext, callback);
|
||||
openpgp.signAndEncryptMessage(publicKeys, this._privateKey, plaintext).then(callback.bind(null, null)).catch(callback);
|
||||
} else {
|
||||
// if no public keys are available encrypt for myself
|
||||
openpgp.signAndEncryptMessage([this._publicKey], this._privateKey, plaintext, callback);
|
||||
openpgp.signAndEncryptMessage([this._publicKey], this._privateKey, plaintext).then(callback.bind(null, null)).catch(callback);
|
||||
}
|
||||
};
|
||||
|
||||
@ -325,17 +318,10 @@ PGP.prototype.decrypt = function(ciphertext, publicKeyArmored, callback) {
|
||||
}
|
||||
|
||||
// decrypt and verify pgp message
|
||||
openpgp.decryptAndVerifyMessage(this._privateKey, publicKeys, message, onDecrypted);
|
||||
|
||||
function onDecrypted(err, decrypted) {
|
||||
if (err) {
|
||||
callback(new Error('Error decrypting and verifying PGP message!'));
|
||||
return;
|
||||
}
|
||||
|
||||
openpgp.decryptAndVerifyMessage(this._privateKey, publicKeys, message).then(function(decrypted) {
|
||||
// return decrypted plaintext
|
||||
callback(null, decrypted.text, checkSignatureValidity(decrypted.signatures));
|
||||
}
|
||||
}).catch(callback);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -369,14 +355,9 @@ PGP.prototype.verifyClearSignedMessage = function(clearSignedText, publicKeyArmo
|
||||
return;
|
||||
}
|
||||
|
||||
openpgp.verifyClearSignedMessage(publicKeys, message, function(err, result) {
|
||||
if (err) {
|
||||
callback(new Error('Error verifying PGP message!'));
|
||||
return;
|
||||
}
|
||||
|
||||
openpgp.verifyClearSignedMessage(publicKeys, message).then(function(result) {
|
||||
callback(null, checkSignatureValidity(result.signatures));
|
||||
});
|
||||
}).catch(callback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
File diff suppressed because it is too large
Load Diff
7
src/lib/openpgp/openpgp.min.js
vendored
Normal file
7
src/lib/openpgp/openpgp.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -1,172 +0,0 @@
|
||||
;(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||||
// GPG4Browsers - An OpenPGP implementation in javascript
|
||||
// Copyright (C) 2011 Recurity Labs GmbH
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
window = {}; // to make UMD bundles work
|
||||
|
||||
importScripts('openpgp.js');
|
||||
|
||||
var MIN_SIZE_RANDOM_BUFFER = 40000;
|
||||
var MAX_SIZE_RANDOM_BUFFER = 60000;
|
||||
|
||||
window.openpgp.crypto.random.randomBuffer.init(MAX_SIZE_RANDOM_BUFFER);
|
||||
|
||||
onmessage = function (event) {
|
||||
var data = null,
|
||||
err = null,
|
||||
msg = event.data,
|
||||
correct = false;
|
||||
switch (msg.event) {
|
||||
case 'seed-random':
|
||||
if (!(msg.buf instanceof Uint8Array)) {
|
||||
msg.buf = new Uint8Array(msg.buf);
|
||||
}
|
||||
window.openpgp.crypto.random.randomBuffer.set(msg.buf);
|
||||
break;
|
||||
case 'encrypt-message':
|
||||
try {
|
||||
if (!msg.keys.length) {
|
||||
msg.keys = [msg.keys];
|
||||
}
|
||||
msg.keys = msg.keys.map(packetlistCloneToKey);
|
||||
data = window.openpgp.encryptMessage(msg.keys, msg.text);
|
||||
} catch (e) {
|
||||
err = e.message;
|
||||
}
|
||||
response({event: 'method-return', data: data, err: err});
|
||||
break;
|
||||
case 'sign-and-encrypt-message':
|
||||
try {
|
||||
if (!msg.publicKeys.length) {
|
||||
msg.publicKeys = [msg.publicKeys];
|
||||
}
|
||||
msg.publicKeys = msg.publicKeys.map(packetlistCloneToKey);
|
||||
msg.privateKey = packetlistCloneToKey(msg.privateKey);
|
||||
data = window.openpgp.signAndEncryptMessage(msg.publicKeys, msg.privateKey, msg.text);
|
||||
} catch (e) {
|
||||
err = e.message;
|
||||
}
|
||||
response({event: 'method-return', data: data, err: err});
|
||||
break;
|
||||
case 'decrypt-message':
|
||||
try {
|
||||
msg.privateKey = packetlistCloneToKey(msg.privateKey);
|
||||
msg.message = packetlistCloneToMessage(msg.message.packets);
|
||||
data = window.openpgp.decryptMessage(msg.privateKey, msg.message);
|
||||
} catch (e) {
|
||||
err = e.message;
|
||||
}
|
||||
response({event: 'method-return', data: data, err: err});
|
||||
break;
|
||||
case 'decrypt-and-verify-message':
|
||||
try {
|
||||
msg.privateKey = packetlistCloneToKey(msg.privateKey);
|
||||
if (!msg.publicKeys.length) {
|
||||
msg.publicKeys = [msg.publicKeys];
|
||||
}
|
||||
msg.publicKeys = msg.publicKeys.map(packetlistCloneToKey);
|
||||
msg.message = packetlistCloneToMessage(msg.message.packets);
|
||||
data = window.openpgp.decryptAndVerifyMessage(msg.privateKey, msg.publicKeys, msg.message);
|
||||
} catch (e) {
|
||||
err = e.message;
|
||||
}
|
||||
response({event: 'method-return', data: data, err: err});
|
||||
break;
|
||||
case 'sign-clear-message':
|
||||
try {
|
||||
msg.privateKeys = msg.privateKeys.map(packetlistCloneToKey);
|
||||
data = window.openpgp.signClearMessage(msg.privateKeys, msg.text);
|
||||
} catch (e) {
|
||||
err = e.message;
|
||||
}
|
||||
response({event: 'method-return', data: data, err: err});
|
||||
break;
|
||||
case 'verify-clear-signed-message':
|
||||
try {
|
||||
if (!msg.publicKeys.length) {
|
||||
msg.publicKeys = [msg.publicKeys];
|
||||
}
|
||||
msg.publicKeys = msg.publicKeys.map(packetlistCloneToKey);
|
||||
var packetlist = window.openpgp.packet.List.fromStructuredClone(msg.message.packets);
|
||||
msg.message = new window.openpgp.cleartext.CleartextMessage(msg.message.text, packetlist);
|
||||
data = window.openpgp.verifyClearSignedMessage(msg.publicKeys, msg.message);
|
||||
} catch (e) {
|
||||
err = e.message;
|
||||
}
|
||||
response({event: 'method-return', data: data, err: err});
|
||||
break;
|
||||
case 'generate-key-pair':
|
||||
try {
|
||||
data = window.openpgp.generateKeyPair(msg.options);
|
||||
data.key = data.key.toPacketlist();
|
||||
} catch (e) {
|
||||
err = e.message;
|
||||
}
|
||||
response({event: 'method-return', data: data, err: err});
|
||||
break;
|
||||
case 'decrypt-key':
|
||||
try {
|
||||
msg.privateKey = packetlistCloneToKey(msg.privateKey);
|
||||
correct = msg.privateKey.decrypt(msg.password);
|
||||
if (correct) {
|
||||
data = msg.privateKey.toPacketlist();
|
||||
} else {
|
||||
err = 'Wrong password';
|
||||
}
|
||||
} catch (e) {
|
||||
err = e.message;
|
||||
}
|
||||
response({event: 'method-return', data: data, err: err});
|
||||
break;
|
||||
case 'decrypt-key-packet':
|
||||
try {
|
||||
msg.privateKey = packetlistCloneToKey(msg.privateKey);
|
||||
msg.keyIds = msg.keyIds.map(window.openpgp.Keyid.fromClone);
|
||||
correct = msg.privateKey.decryptKeyPacket(msg.keyIds, msg.password);
|
||||
if (correct) {
|
||||
data = msg.privateKey.toPacketlist();
|
||||
} else {
|
||||
err = 'Wrong password';
|
||||
}
|
||||
} catch (e) {
|
||||
err = e.message;
|
||||
}
|
||||
response({event: 'method-return', data: data, err: err});
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown Worker Event.');
|
||||
}
|
||||
};
|
||||
|
||||
function response(event) {
|
||||
if (window.openpgp.crypto.random.randomBuffer.size < MIN_SIZE_RANDOM_BUFFER) {
|
||||
postMessage({event: 'request-seed'});
|
||||
}
|
||||
postMessage(event);
|
||||
}
|
||||
|
||||
function packetlistCloneToKey(packetlistClone) {
|
||||
var packetlist = window.openpgp.packet.List.fromStructuredClone(packetlistClone);
|
||||
return new window.openpgp.key.Key(packetlist);
|
||||
}
|
||||
|
||||
function packetlistCloneToMessage(packetlistClone) {
|
||||
var packetlist = window.openpgp.packet.List.fromStructuredClone(packetlistClone);
|
||||
return new window.openpgp.message.Message(packetlist);
|
||||
}
|
||||
},{}]},{},[1])
|
||||
;
|
1
src/lib/openpgp/openpgp.worker.min.js
vendored
Normal file
1
src/lib/openpgp/openpgp.worker.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
/*! OpenPGPjs.org this is LGPL licensed code, see LICENSE/our website for more information.- v0.8.1 - 2014-10-20 */!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(){function a(a){window.openpgp.crypto.random.randomBuffer.size<d&&postMessage({event:"request-seed"}),postMessage(a)}function b(a){var b=window.openpgp.packet.List.fromStructuredClone(a);return new window.openpgp.key.Key(b)}function c(a){var b=window.openpgp.packet.List.fromStructuredClone(a);return new window.openpgp.message.Message(b)}window={},Function.prototype.bind||(Function.prototype.bind=function(a){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var b=Array.prototype.slice.call(arguments,1),c=this,d=function(){},e=function(){return c.apply(this instanceof d&&a?this:a,b.concat(Array.prototype.slice.call(arguments)))};return d.prototype=this.prototype,e.prototype=new d,e}),importScripts("openpgp.min.js");var d=4e4,e=6e4;window.openpgp.crypto.random.randomBuffer.init(e),self.onmessage=function(d){var e=null,f=null,g=d.data,h=!1;switch(g.event){case"seed-random":g.buf instanceof Uint8Array||(g.buf=new Uint8Array(g.buf)),window.openpgp.crypto.random.randomBuffer.set(g.buf);break;case"encrypt-message":g.keys.length||(g.keys=[g.keys]),g.keys=g.keys.map(b),window.openpgp.encryptMessage(g.keys,g.text).then(function(b){a({event:"method-return",data:b})}).catch(function(b){a({event:"method-return",err:b.message})});break;case"sign-and-encrypt-message":g.publicKeys.length||(g.publicKeys=[g.publicKeys]),g.publicKeys=g.publicKeys.map(b),g.privateKey=b(g.privateKey),window.openpgp.signAndEncryptMessage(g.publicKeys,g.privateKey,g.text).then(function(b){a({event:"method-return",data:b})}).catch(function(b){a({event:"method-return",err:b.message})});break;case"decrypt-message":g.privateKey=b(g.privateKey),g.message=c(g.message.packets),window.openpgp.decryptMessage(g.privateKey,g.message).then(function(b){a({event:"method-return",data:b})}).catch(function(b){a({event:"method-return",err:b.message})});break;case"decrypt-and-verify-message":g.privateKey=b(g.privateKey),g.publicKeys.length||(g.publicKeys=[g.publicKeys]),g.publicKeys=g.publicKeys.map(b),g.message=c(g.message.packets),window.openpgp.decryptAndVerifyMessage(g.privateKey,g.publicKeys,g.message).then(function(b){a({event:"method-return",data:b})}).catch(function(b){a({event:"method-return",err:b.message})});break;case"sign-clear-message":g.privateKeys=g.privateKeys.map(b),window.openpgp.signClearMessage(g.privateKeys,g.text).then(function(b){a({event:"method-return",data:b})}).catch(function(b){a({event:"method-return",err:b.message})});break;case"verify-clear-signed-message":g.publicKeys.length||(g.publicKeys=[g.publicKeys]),g.publicKeys=g.publicKeys.map(b);var i=window.openpgp.packet.List.fromStructuredClone(g.message.packets);g.message=new window.openpgp.cleartext.CleartextMessage(g.message.text,i),window.openpgp.verifyClearSignedMessage(g.publicKeys,g.message).then(function(b){a({event:"method-return",data:b})}).catch(function(b){a({event:"method-return",err:b.message})});break;case"generate-key-pair":window.openpgp.generateKeyPair(g.options).then(function(b){b.key=b.key.toPacketlist(),a({event:"method-return",data:b})}).catch(function(b){a({event:"method-return",err:b.message})});break;case"decrypt-key":try{g.privateKey=b(g.privateKey),h=g.privateKey.decrypt(g.password),h?e=g.privateKey.toPacketlist():f="Wrong password"}catch(j){f=j.message}a({event:"method-return",data:e,err:f});break;case"decrypt-key-packet":try{g.privateKey=b(g.privateKey),g.keyIds=g.keyIds.map(window.openpgp.Keyid.fromClone),h=g.privateKey.decryptKeyPacket(g.keyIds,g.password),h?e=g.privateKey.toPacketlist():f="Wrong password"}catch(j){f=j.message}a({event:"method-return",data:e,err:f});break;default:throw new Error("Unknown Worker Event.")}}},{}]},{},[1]);
|
@ -18,7 +18,7 @@
|
||||
mocha.setup('bdd');
|
||||
</script>
|
||||
|
||||
<script src="../lib/openpgp.js"></script>
|
||||
<script src="../lib/openpgp.min.js"></script>
|
||||
<script src="../lib/forge.min.js"></script>
|
||||
<script src="index.js"></script>
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
mocha.setup('bdd');
|
||||
</script>
|
||||
|
||||
<script src="../lib/openpgp.js"></script>
|
||||
<script src="../lib/openpgp.min.js"></script>
|
||||
<script src="../lib/forge.min.js"></script>
|
||||
<script src="index.js"></script>
|
||||
|
||||
|
@ -11,7 +11,7 @@ describe('PGP Crypto Api unit tests', function() {
|
||||
keySize = 512,
|
||||
keyId = 'F6F60E9B42CDFF4C',
|
||||
pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n' +
|
||||
'Version: OpenPGP.js v0.7.2\r\n' +
|
||||
'Version: OpenPGP.js v0.8.1\r\n' +
|
||||
'Comment: Whiteout Mail - https://whiteout.io\r\n' +
|
||||
'\r\n' +
|
||||
'xk0EUlhMvAEB/2MZtCUOAYvyLFjDp3OBMGn3Ev8FwjzyPbIF0JUw+L7y2XR5\r\n' +
|
||||
@ -22,7 +22,7 @@ describe('PGP Crypto Api unit tests', function() {
|
||||
'=6XMW\r\n' +
|
||||
'-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n',
|
||||
privkey = '-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n' +
|
||||
'Version: OpenPGP.js v0.7.2\r\n' +
|
||||
'Version: OpenPGP.js v0.8.1\r\n' +
|
||||
'Comment: Whiteout Mail - https://whiteout.io\r\n' +
|
||||
'\r\n' +
|
||||
'xcBeBFJYTLwBAf9jGbQlDgGL8ixYw6dzgTBp9xL/BcI88j2yBdCVMPi+8tl0\r\n' +
|
||||
@ -363,13 +363,13 @@ describe('PGP Crypto Api unit tests', function() {
|
||||
});
|
||||
});
|
||||
it('should work without signature', function(done) {
|
||||
var ct = openpgp.encryptMessage([pgp._publicKey], message);
|
||||
|
||||
pgp.decrypt(ct, undefined, function(err, pt, signValid) {
|
||||
expect(err).to.not.exist;
|
||||
expect(pt).to.equal(message);
|
||||
expect(signValid).to.be.undefined;
|
||||
done();
|
||||
openpgp.encryptMessage([pgp._publicKey], message).then(function(ct) {
|
||||
pgp.decrypt(ct, undefined, function(err, pt, signValid) {
|
||||
expect(err).to.not.exist;
|
||||
expect(pt).to.equal(message);
|
||||
expect(signValid).to.be.undefined;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('should fail to verify if public keys are empty', function(done) {
|
||||
@ -395,8 +395,11 @@ describe('PGP Crypto Api unit tests', function() {
|
||||
describe('Verify clearsigned message', function() {
|
||||
var clearsigned;
|
||||
|
||||
beforeEach(function() {
|
||||
clearsigned = openpgp.signClearMessage(pgp._privateKey, 'this is a clearsigned message');
|
||||
beforeEach(function(done) {
|
||||
openpgp.signClearMessage(pgp._privateKey, 'this is a clearsigned message').then(function(signed) {
|
||||
clearsigned = signed;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should work', function(done) {
|
||||
@ -426,11 +429,13 @@ describe('PGP Crypto Api unit tests', function() {
|
||||
describe('Verify detached signature', function() {
|
||||
var signedMessage, signature;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function(done) {
|
||||
signedMessage = 'this is a signed message';
|
||||
var clearsigned = openpgp.signClearMessage(pgp._privateKey, signedMessage);
|
||||
var signatureHeader = '-----BEGIN PGP SIGNATURE-----';
|
||||
signature = signatureHeader + clearsigned.split(signatureHeader).pop();
|
||||
openpgp.signClearMessage(pgp._privateKey, signedMessage).then(function(clearsigned) {
|
||||
var signatureHeader = '-----BEGIN PGP SIGNATURE-----';
|
||||
signature = signatureHeader + clearsigned.split(signatureHeader).pop();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should work', function(done) {
|
||||
|
Loading…
Reference in New Issue
Block a user