Update openpgpjs (1.2.0 -> 2.3.0) (#1023)

This commit is contained in:
RainLoop Team 2016-05-05 03:14:38 +03:00
parent 125d4e0282
commit a655b94aba
19 changed files with 20792 additions and 195 deletions

View file

@ -455,6 +455,7 @@ class AppUser extends AbstractApp
iIndex,
oItem.primaryKey.getFingerprint(),
oItem.primaryKey.getKeyId().toHex().toLowerCase(),
_.uniq(_.compact(_.map(oItem.getKeyIds(), (item) => item && item.toHex ? item.toHex() : null))),
aUsers,
aEmails,
oItem.isPrivate(),
@ -1297,7 +1298,8 @@ class AppUser extends AbstractApp
{
try
{
PgpStore.openpgp.initWorker(Links.openPgpWorkerJs());
// PgpStore.openpgp.initWorker(Links.openPgpWorkerJs()); // 1.2.0
PgpStore.openpgp.initWorker({path: Links.openPgpWorkerJs()}); // 2.3.0
}
catch (e)
{
@ -1305,8 +1307,6 @@ class AppUser extends AbstractApp
}
}
// PgpStore.openpgp.config.useWebCrypto = false;
PgpStore.openpgpKeyring = new openpgp.Keyring();
PgpStore.capaOpenPGP(true);

View file

@ -137,7 +137,7 @@
{name: 'styles'},
{name: 'basicstyles', groups: ['basicstyles', 'cleanup', 'bidi']},
{name: 'colors'},
{name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align']},
Globals.bMobileDevice ? {} : {name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align']},
{name: 'links'},
{name: 'insert'},
{name: 'document', groups: ['mode', 'document', 'doctools']},

View file

@ -18,6 +18,7 @@
* @param {string} iIndex
* @param {string} sGuID
* @param {string} sID
* @param {array} aIDs
* @param {array} aUserIDs
* @param {array} aEmails
* @param {boolean} bIsPrivate
@ -25,17 +26,19 @@
* @param {string} sUserID
* @constructor
*/
function OpenPgpKeyModel(iIndex, sGuID, sID, aUserIDs, aEmails, bIsPrivate, sArmor, sUserID)
function OpenPgpKeyModel(iIndex, sGuID, sID, aIDs, aUserIDs, aEmails, bIsPrivate, sArmor, sUserID)
{
AbstractModel.call(this, 'OpenPgpKeyModel');
this.index = iIndex;
this.id = sID;
this.ids = Utils.isNonEmptyArray(aIDs) ? aIDs : [sID];
this.guid = sGuID;
this.users = aUserIDs;
this.emails = aEmails;
this.armor = sArmor;
this.isPrivate = !!bIsPrivate;
this.selectUser(sUserID);
this.deleteAccess = ko.observable(false);
@ -45,6 +48,7 @@
OpenPgpKeyModel.prototype.index = 0;
OpenPgpKeyModel.prototype.id = '';
OpenPgpKeyModel.prototype.ids = [];
OpenPgpKeyModel.prototype.guid = '';
OpenPgpKeyModel.prototype.user = '';
OpenPgpKeyModel.prototype.users = [];
@ -80,11 +84,14 @@
OpenPgpKeyModel.prototype.select = function (sPattern, sProperty)
{
var index = this[sProperty].indexOf(sPattern);
if (index !== -1) {
this.user = this.users[index];
this.email = this.emails[index];
if (this[sProperty])
{
var index = this[sProperty].indexOf(sPattern);
if (index !== -1)
{
this.user = this.users[index];
this.email = this.emails[index];
}
}
};

View file

@ -42,24 +42,27 @@
return !!this.openpgp;
};
PgpUserStore.prototype.findKeyByHex = function (aKeys,sHash)
{
return _.find(aKeys, function (oItem) {
return sHash && oItem && (sHash === oItem.id || -1 < oItem.ids.indexOf(sHash));
});
};
PgpUserStore.prototype.findPublicKeyByHex = function (sHash)
{
return _.find(this.openpgpkeysPublic(), function (oItem) {
return sHash && oItem && sHash === oItem.id;
});
return this.findKeyByHex(this.openpgpkeysPublic(), sHash);
};
PgpUserStore.prototype.findPrivateKeyByHex = function (sHash)
{
return _.find(this.openpgpkeysPrivate(), function (oItem) {
return sHash && oItem && sHash === oItem.id;
});
return this.findKeyByHex(this.openpgpkeysPrivate(), sHash);
};
PgpUserStore.prototype.findPublicKeysByEmail = function (sEmail)
{
return _.compact(_.flatten(_.map(this.openpgpkeysPublic(), function (oItem) {
var oKey = oItem && -1 !== oItem.emails.indexOf(sEmail) ? oItem : null;
var oKey = oItem && -1 < oItem.emails.indexOf(sEmail) ? oItem : null;
return oKey ? oKey.getNativeKeys() : [null];
}), true));
};
@ -99,7 +102,7 @@
PgpUserStore.prototype.findPublicKeyByEmailNotNative = function (sEmail)
{
return _.find(this.openpgpkeysPublic(), function (oItem) {
return oItem && -1 !== oItem.emails.indexOf(sEmail);
return oItem && -1 < oItem.emails.indexOf(sEmail);
}) || null;
};
@ -110,7 +113,7 @@
PgpUserStore.prototype.findPrivateKeyByEmailNotNative = function (sEmail)
{
return _.find(this.openpgpkeysPrivate(), function (oItem) {
return oItem && -1 !== oItem.emails.indexOf(sEmail);
return oItem && -1 < oItem.emails.indexOf(sEmail);
}) || null;
};
@ -121,7 +124,7 @@
PgpUserStore.prototype.findAllPublicKeysByEmailNotNative = function (sEmail)
{
return _.filter(this.openpgpkeysPublic(), function (oItem) {
return oItem && -1 !== oItem.emails.indexOf(sEmail);
return oItem && -1 < oItem.emails.indexOf(sEmail);
}) || null;
};
@ -132,7 +135,7 @@
PgpUserStore.prototype.findAllPrivateKeysByEmailNotNative = function (sEmail)
{
return _.filter(this.openpgpkeysPrivate(), function (oItem) {
return oItem && -1 !== oItem.emails.indexOf(sEmail);
return oItem && -1 < oItem.emails.indexOf(sEmail);
}) || null;
};
@ -147,7 +150,7 @@
oPrivateKeys = [],
oPrivateKey = null,
oKey = _.find(this.openpgpkeysPrivate(), function (oItem) {
return oItem && -1 !== oItem.emails.indexOf(sEmail);
return oItem && -1 < oItem.emails.indexOf(sEmail);
})
;
@ -189,38 +192,34 @@
aPrivateKeys = this.findPrivateKeysByEncryptionKeyIds(oMessage.getEncryptionKeyIds(), aRecipients, true);
if (aPrivateKeys && 0 < aPrivateKeys.length)
{
kn.showScreenPopup(require('View/Popup/MessageOpenPgp'), [function (oDecriptedKey) {
kn.showScreenPopup(require('View/Popup/MessageOpenPgp'), [function (oDecryptedKey) {
if (oDecriptedKey)
if (oDecryptedKey)
{
var oPrivateKey = null, oDecryptedMessage = null;
try
{
oDecryptedMessage = oMessage.decrypt(oDecriptedKey);
}
catch (e)
{
oDecryptedMessage = null;
}
if (oDecryptedMessage)
{
oPrivateKey = self.findPrivateKeyByHex(oDecriptedKey.primaryKey.keyid.toHex());
if (oPrivateKey)
oMessage.decrypt(oDecryptedKey).then(function(oDecryptedMessage){
var oPrivateKey = null;
if (oDecryptedMessage)
{
self.verifyMessage(oDecryptedMessage, function (oValidKey, aSigningKeyIds) {
fCallback(oPrivateKey, oDecryptedMessage, oValidKey || null, aSigningKeyIds || null);
});
oPrivateKey = self.findPrivateKeyByHex(oDecryptedKey.primaryKey.keyid.toHex());
if (oPrivateKey)
{
self.verifyMessage(oDecryptedMessage, function (oValidKey, aSigningKeyIds) {
fCallback(oPrivateKey, oDecryptedMessage, oValidKey || null, aSigningKeyIds || null);
});
}
else
{
fCallback(oPrivateKey, oDecryptedMessage);
}
}
else
{
fCallback(oPrivateKey, oDecryptedMessage);
}
}
else
{
fCallback(oPrivateKey, oDecryptedMessage);
}
}, function() {
fCallback(null, null);
});
}
else
{
@ -299,6 +298,129 @@
}
};
/**
* @static
*/
PgpUserStore.domControlEncryptedClickHelper = function (self, mDom, sArmoredMessage, aRecipients)
{
return function () {
var oMessage = null, $this = $(this);
if ($this.hasClass('success'))
{
return false;
}
try
{
oMessage = self.openpgp.message.readArmored(sArmoredMessage);
}
catch (e)
{
Utils.log(e);
}
if (oMessage && oMessage.getText && oMessage.verify && oMessage.decrypt)
{
self.decryptMessage(oMessage, aRecipients, function (oValidPrivateKey, oDecryptedMessage, oValidPublicKey, aSigningKeyIds) {
if (oDecryptedMessage)
{
if (oValidPublicKey)
{
self.controlsHelper(mDom, $this, true, Translator.i18n('PGP_NOTIFICATIONS/GOOD_SIGNATURE', {
'USER': oValidPublicKey.user + ' (' + oValidPublicKey.id + ')'
}), oDecryptedMessage.getText());
}
else if (oValidPrivateKey)
{
var
aKeyIds = Utils.isNonEmptyArray(aSigningKeyIds) ? aSigningKeyIds : null,
sAdditional = aKeyIds ? _.compact(_.map(aKeyIds, function (oItem) {
return oItem && oItem.toHex ? oItem.toHex() : null;
})).join(', ') : ''
;
self.controlsHelper(mDom, $this, false,
Translator.i18n('PGP_NOTIFICATIONS/UNVERIFIRED_SIGNATURE') +
(sAdditional ? ' (' + sAdditional + ')' : ''),
oDecryptedMessage.getText());
}
else
{
self.controlsHelper(mDom, $this, false,
Translator.i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
}
}
else
{
self.controlsHelper(mDom, $this, false,
Translator.i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
}
});
return false;
}
self.controlsHelper(mDom, $this, false, Translator.i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
return false;
};
};
/**
* @static
*/
PgpUserStore.domControlSignedClickHelper = function (self, mDom, sArmoredMessage)
{
return function () {
var oMessage = null, $this = $(this);
if ($this.hasClass('success') || $this.hasClass('error'))
{
return false;
}
try
{
oMessage = self.openpgp.cleartext.readArmored(sArmoredMessage);
}
catch (e)
{
Utils.log(e);
}
if (oMessage && oMessage.getText && oMessage.verify)
{
self.verifyMessage(oMessage, function (oValidKey, aSigningKeyIds) {
if (oValidKey)
{
self.controlsHelper(mDom, $this, true, Translator.i18n('PGP_NOTIFICATIONS/GOOD_SIGNATURE', {
'USER': oValidKey.user + ' (' + oValidKey.id + ')'
}), oMessage.getText());
}
else
{
var
aKeyIds = Utils.isNonEmptyArray(aSigningKeyIds) ? aSigningKeyIds : null,
sAdditional = aKeyIds ? _.compact(_.map(aKeyIds, function (oItem) {
return oItem && oItem.toHex ? oItem.toHex() : null;
})).join(', ') : ''
;
self.controlsHelper(mDom, $this, false,
Translator.i18n('PGP_NOTIFICATIONS/UNVERIFIRED_SIGNATURE') +
(sAdditional ? ' (' + sAdditional + ')' : ''));
}
});
return false;
}
self.controlsHelper(mDom, $this, false, Translator.i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
return false;
};
};
/**
* @param {*} mDom
* @param {MessageModel} oRainLoopMessage
@ -310,7 +432,6 @@
mDom.addClass('inited');
var
self = this,
bEncrypted = mDom.hasClass('encrypted'),
bSigned = mDom.hasClass('signed'),
oVerControl = null,
@ -326,123 +447,16 @@
if (bEncrypted)
{
oVerControl = $('<div class="b-openpgp-control"><i class="icon-lock"></i></div>')
.attr('title', Translator.i18n('MESSAGE/PGP_ENCRYPTED_MESSAGE_DESC'));
oVerControl.on('click', function () {
if ($(this).hasClass('success'))
{
return false;
}
var oMessage = null;
try
{
oMessage = self.openpgp.message.readArmored(sData);
}
catch (e)
{
Utils.log(e);
}
if (oMessage && oMessage.getText && oMessage.verify && oMessage.decrypt)
{
self.decryptMessage(oMessage, aRecipients, function (oValidPrivateKey, oDecriptedMessage, oValidPublicKey, aSigningKeyIds) {
if (oDecriptedMessage)
{
if (oValidPublicKey)
{
self.controlsHelper(mDom, oVerControl, true, Translator.i18n('PGP_NOTIFICATIONS/GOOD_SIGNATURE', {
'USER': oValidPublicKey.user + ' (' + oValidPublicKey.id + ')'
}), oDecriptedMessage.getText());
}
else if (oValidPrivateKey)
{
var
aKeyIds = Utils.isNonEmptyArray(aSigningKeyIds) ? aSigningKeyIds : null,
sAdditional = aKeyIds ? _.compact(_.map(aKeyIds, function (oItem) {
return oItem && oItem.toHex ? oItem.toHex() : null;
})).join(', ') : ''
;
self.controlsHelper(mDom, oVerControl, false,
Translator.i18n('PGP_NOTIFICATIONS/UNVERIFIRED_SIGNATURE') +
(sAdditional ? ' (' + sAdditional + ')' : ''),
oDecriptedMessage.getText());
}
else
{
self.controlsHelper(mDom, oVerControl, false,
Translator.i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
}
}
else
{
self.controlsHelper(mDom, oVerControl, false,
Translator.i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
}
});
return false;
}
self.controlsHelper(mDom, oVerControl, false, Translator.i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
return false;
});
.attr('title', Translator.i18n('MESSAGE/PGP_ENCRYPTED_MESSAGE_DESC'))
.on('click', PgpUserStore.domControlEncryptedClickHelper(this, mDom, sData, aRecipients))
;
}
else if (bSigned)
{
oVerControl = $('<div class="b-openpgp-control"><i class="icon-lock"></i></div>')
.attr('title', Translator.i18n('MESSAGE/PGP_SIGNED_MESSAGE_DESC'));
oVerControl.on('click', function () {
if ($(this).hasClass('success') || $(this).hasClass('error'))
{
return false;
}
var oMessage = null;
try
{
oMessage = self.openpgp.cleartext.readArmored(sData);
}
catch (e)
{
Utils.log(e);
}
if (oMessage && oMessage.getText && oMessage.verify)
{
self.verifyMessage(oMessage, function (oValidKey, aSigningKeyIds) {
if (oValidKey)
{
self.controlsHelper(mDom, oVerControl, true, Translator.i18n('PGP_NOTIFICATIONS/GOOD_SIGNATURE', {
'USER': oValidKey.user + ' (' + oValidKey.id + ')'
}), oMessage.getText());
}
else
{
var
aKeyIds = Utils.isNonEmptyArray(aSigningKeyIds) ? aSigningKeyIds : null,
sAdditional = aKeyIds ? _.compact(_.map(aKeyIds, function (oItem) {
return oItem && oItem.toHex ? oItem.toHex() : null;
})).join(', ') : ''
;
self.controlsHelper(mDom, oVerControl, false,
Translator.i18n('PGP_NOTIFICATIONS/UNVERIFIRED_SIGNATURE') +
(sAdditional ? ' (' + sAdditional + ')' : ''));
}
});
return false;
}
self.controlsHelper(mDom, oVerControl, false, Translator.i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
return false;
});
.attr('title', Translator.i18n('MESSAGE/PGP_SIGNED_MESSAGE_DESC'))
.on('click', PgpUserStore.domControlSignedClickHelper(this, mDom, sData))
;
}
if (oVerControl)

View file

@ -95,6 +95,10 @@
}
.icon-star-empty {
opacity: .5;
&:hover {
opacity: 1;
}
}
}

View file

@ -184,15 +184,28 @@
{
if (oPrivateKey && 0 === aPublicKeys.length)
{
oPromise = PgpStore.openpgp.signClearMessage([oPrivateKey], self.text());
// oPromise = PgpStore.openpgp.signClearMessage([oPrivateKey], self.text()); // 1.2.0
oPromise = PgpStore.openpgp.sign({
data: self.text(),
privateKeys: [oPrivateKey]
});
}
else if (oPrivateKey && 0 < aPublicKeys.length)
{
oPromise = PgpStore.openpgp.signAndEncryptMessage(aPublicKeys, oPrivateKey, self.text());
// oPromise = PgpStore.openpgp.signAndEncryptMessage(aPublicKeys, oPrivateKey, self.text()); // 1.2.0
oPromise = PgpStore.openpgp.encrypt({
data: self.text(),
publicKeys: aPublicKeys,
privateKeys: [oPrivateKey]
});
}
else if (!oPrivateKey && 0 < aPublicKeys.length)
{
oPromise = PgpStore.openpgp.encryptMessage(aPublicKeys, self.text());
// oPromise = PgpStore.openpgp.encryptMessage(aPublicKeys, self.text()); // 1.2.0
oPromise = PgpStore.openpgp.encrypt({
data: self.text(),
publicKeys: aPublicKeys
});
}
}
catch (e)
@ -210,7 +223,7 @@
{
oPromise.then(function (mData) {
self.resultCallback(mData);
self.resultCallback(mData.data);
self.cancelCommand();
})['catch'](function (e) {

View file

@ -41,7 +41,7 @@
var
self = this,
sUserID = '',
oUserIds = {},
oOpenpgpKeyring = PgpStore.openpgpKeyring
;
@ -51,10 +51,10 @@
return false;
}
sUserID = this.email();
oUserIds['email'] = this.email();
if ('' !== this.name())
{
sUserID = this.name() + ' <' + sUserID + '>';
oUserIds['name'] = this.name();
}
this.submitRequest(true);
@ -66,7 +66,7 @@
try {
mPromise = PgpStore.openpgp.generateKeyPair({
'userId': sUserID,
'userId': oUserIds,
'numBits': Utils.pInt(self.keyBitLength()),
'passphrase': Utils.trim(self.password())
});