mirror of
https://github.com/moparisthebest/mail
synced 2024-11-26 19:02:20 -05:00
Merge pull request #40 from whiteout-io/dev/openpgp_0.5
[WO-298] integrate openpgp.js v0.5.0
This commit is contained in:
commit
b7e0236af8
@ -10,7 +10,7 @@ define(function(require) {
|
|||||||
|
|
||||||
var PGP = function() {
|
var PGP = function() {
|
||||||
openpgp.config.prefer_hash_algorithm = openpgp.enums.hash.sha256;
|
openpgp.config.prefer_hash_algorithm = openpgp.enums.hash.sha256;
|
||||||
openpgp.initWorker(config.workerPath + '/../lib/openpgp/openpgp.worker.js');
|
openpgp.initWorker(config.workerPath + '/../lib/openpgp/openpgp.worker.min.js');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,7 +52,7 @@ define(function(require) {
|
|||||||
*/
|
*/
|
||||||
PGP.prototype.getFingerprint = function(keyArmored) {
|
PGP.prototype.getFingerprint = function(keyArmored) {
|
||||||
function fingerprint(key) {
|
function fingerprint(key) {
|
||||||
return util.hexstrdump(key.getKeyPacket().getFingerprint()).toUpperCase();
|
return key.getKeyPacket().getFingerprint().toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
// process armored key input
|
// process armored key input
|
||||||
@ -105,7 +105,7 @@ define(function(require) {
|
|||||||
return {
|
return {
|
||||||
_id: packet.getKeyId().toHex().toUpperCase(),
|
_id: packet.getKeyId().toHex().toUpperCase(),
|
||||||
userId: key.getUserIds()[0].split('<')[1].split('>')[0],
|
userId: key.getUserIds()[0].split('<')[1].split('>')[0],
|
||||||
fingerprint: util.hexstrdump(packet.getFingerprint()).toUpperCase(),
|
fingerprint: packet.getFingerprint().toUpperCase(),
|
||||||
algorithm: packet.algorithm,
|
algorithm: packet.algorithm,
|
||||||
bitSize: packet.getBitSize(),
|
bitSize: packet.getBitSize(),
|
||||||
created: packet.created,
|
created: packet.created,
|
||||||
|
12
src/lib/openpgp/openpgp.min.js
vendored
12
src/lib/openpgp/openpgp.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,157 +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.min.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':
|
|
||||||
window.openpgp.crypto.random.randomBuffer.set(msg.buf);
|
|
||||||
break;
|
|
||||||
case 'encrypt-message':
|
|
||||||
try {
|
|
||||||
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 {
|
|
||||||
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);
|
|
||||||
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 {
|
|
||||||
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.keyType, msg.numBits, msg.userId, msg.passphrase);
|
|
||||||
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.5.0 - 2014-03-31 */!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={},importScripts("openpgp.min.js");var d=4e4,e=6e4;window.openpgp.crypto.random.randomBuffer.init(e),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":try{g.keys=g.keys.map(b),e=window.openpgp.encryptMessage(g.keys,g.text)}catch(i){f=i.message}a({event:"method-return",data:e,err:f});break;case"sign-and-encrypt-message":try{g.publicKeys=g.publicKeys.map(b),g.privateKey=b(g.privateKey),e=window.openpgp.signAndEncryptMessage(g.publicKeys,g.privateKey,g.text)}catch(i){f=i.message}a({event:"method-return",data:e,err:f});break;case"decrypt-message":try{g.privateKey=b(g.privateKey),g.message=c(g.message.packets),e=window.openpgp.decryptMessage(g.privateKey,g.message)}catch(i){f=i.message}a({event:"method-return",data:e,err:f});break;case"decrypt-and-verify-message":try{g.privateKey=b(g.privateKey),g.publicKeys=g.publicKeys.map(b),g.message=c(g.message.packets),e=window.openpgp.decryptAndVerifyMessage(g.privateKey,g.publicKeys,g.message)}catch(i){f=i.message}a({event:"method-return",data:e,err:f});break;case"sign-clear-message":try{g.privateKeys=g.privateKeys.map(b),e=window.openpgp.signClearMessage(g.privateKeys,g.text)}catch(i){f=i.message}a({event:"method-return",data:e,err:f});break;case"verify-clear-signed-message":try{g.publicKeys=g.publicKeys.map(b);var j=window.openpgp.packet.List.fromStructuredClone(g.message.packets);g.message=new window.openpgp.cleartext.CleartextMessage(g.message.text,j),e=window.openpgp.verifyClearSignedMessage(g.publicKeys,g.message)}catch(i){f=i.message}a({event:"method-return",data:e,err:f});break;case"generate-key-pair":try{e=window.openpgp.generateKeyPair(g.keyType,g.numBits,g.userId,g.passphrase),e.key=e.key.toPacketlist()}catch(i){f=i.message}a({event:"method-return",data:e,err:f});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(i){f=i.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(i){f=i.message}a({event:"method-return",data:e,err:f});break;default:throw new Error("Unknown Worker Event.")}}},{}]},{},[1]);
|
@ -13,7 +13,7 @@ define(function(require) {
|
|||||||
keySize = 512,
|
keySize = 512,
|
||||||
keyId = 'F6F60E9B42CDFF4C',
|
keyId = 'F6F60E9B42CDFF4C',
|
||||||
pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n' +
|
pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n' +
|
||||||
'Version: OpenPGP.js v0.4.1\r\n' +
|
'Version: OpenPGP.js v0.5.0\r\n' +
|
||||||
'Comment: http://openpgpjs.org\r\n' +
|
'Comment: http://openpgpjs.org\r\n' +
|
||||||
'\r\n' +
|
'\r\n' +
|
||||||
'xk0EUlhMvAEB/2MZtCUOAYvyLFjDp3OBMGn3Ev8FwjzyPbIF0JUw+L7y2XR5\r\n' +
|
'xk0EUlhMvAEB/2MZtCUOAYvyLFjDp3OBMGn3Ev8FwjzyPbIF0JUw+L7y2XR5\r\n' +
|
||||||
@ -24,7 +24,7 @@ define(function(require) {
|
|||||||
'=6XMW\r\n' +
|
'=6XMW\r\n' +
|
||||||
'-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n',
|
'-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n',
|
||||||
privkey = '-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n' +
|
privkey = '-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n' +
|
||||||
'Version: OpenPGP.js v0.4.1\r\n' +
|
'Version: OpenPGP.js v0.5.0\r\n' +
|
||||||
'Comment: http://openpgpjs.org\r\n' +
|
'Comment: http://openpgpjs.org\r\n' +
|
||||||
'\r\n' +
|
'\r\n' +
|
||||||
'xcBeBFJYTLwBAf9jGbQlDgGL8ixYw6dzgTBp9xL/BcI88j2yBdCVMPi+8tl0\r\n' +
|
'xcBeBFJYTLwBAf9jGbQlDgGL8ixYw6dzgTBp9xL/BcI88j2yBdCVMPi+8tl0\r\n' +
|
||||||
|
Loading…
Reference in New Issue
Block a user