mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 13:09:21 +03:00
OpenPGP improvements (first step)
openpgpjs: 0.7.2 -> 0.10.1 additional fixes
This commit is contained in:
parent
09334159c2
commit
34a9b8cbc5
28 changed files with 1363 additions and 644 deletions
|
|
@ -632,7 +632,7 @@
|
|||
oEditor.setPlain(sResult);
|
||||
});
|
||||
},
|
||||
this.oEditor.getData(),
|
||||
this.oEditor.getData(false, true),
|
||||
this.currentIdentity(),
|
||||
this.to(),
|
||||
this.cc(),
|
||||
|
|
|
|||
|
|
@ -109,25 +109,20 @@
|
|||
|
||||
if (self.resultCallback && bResult)
|
||||
{
|
||||
try {
|
||||
|
||||
var oPromise = null;
|
||||
try
|
||||
{
|
||||
if (oPrivateKey && 0 === aPublicKeys.length)
|
||||
{
|
||||
self.resultCallback(
|
||||
PgpStore.openpgp.signClearMessage([oPrivateKey], self.text())
|
||||
);
|
||||
oPromise = PgpStore.openpgp.signClearMessage([oPrivateKey], self.text());
|
||||
}
|
||||
else if (oPrivateKey && 0 < aPublicKeys.length)
|
||||
{
|
||||
self.resultCallback(
|
||||
PgpStore.openpgp.signAndEncryptMessage(aPublicKeys, oPrivateKey, self.text())
|
||||
);
|
||||
oPromise = PgpStore.openpgp.signAndEncryptMessage(aPublicKeys, oPrivateKey, self.text());
|
||||
}
|
||||
else if (!oPrivateKey && 0 < aPublicKeys.length)
|
||||
{
|
||||
self.resultCallback(
|
||||
PgpStore.openpgp.encryptMessage(aPublicKeys, self.text())
|
||||
);
|
||||
oPromise = PgpStore.openpgp.encryptMessage(aPublicKeys, self.text());
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
|
|
@ -135,14 +130,30 @@
|
|||
self.notification(Translator.i18n('PGP_NOTIFICATIONS/PGP_ERROR', {
|
||||
'ERROR': '' + e
|
||||
}));
|
||||
|
||||
bResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (bResult)
|
||||
{
|
||||
self.cancelCommand();
|
||||
if (oPromise)
|
||||
{
|
||||
try
|
||||
{
|
||||
oPromise.then(function (mData) {
|
||||
|
||||
self.resultCallback(mData);
|
||||
self.cancelCommand();
|
||||
|
||||
})['catch'](function (e) {
|
||||
self.notification(Translator.i18n('PGP_NOTIFICATIONS/PGP_ERROR', {
|
||||
'ERROR': '' + e
|
||||
}));
|
||||
});
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
self.notification(Translator.i18n('PGP_NOTIFICATIONS/PGP_ERROR', {
|
||||
'ERROR': '' + e
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.submitRequest(false);
|
||||
|
|
|
|||
179
dev/View/Popup/MessageOpenPgp.js
Normal file
179
dev/View/Popup/MessageOpenPgp.js
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
key = require('key'),
|
||||
|
||||
Utils = require('Common/Utils'),
|
||||
Enums = require('Common/Enums'),
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function MessageOpenPgpPopupView()
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsMessageOpenPgp');
|
||||
|
||||
this.notification = ko.observable('');
|
||||
|
||||
this.selectedKey = ko.observable(null);
|
||||
this.privateKeys = ko.observableArray([]);
|
||||
|
||||
this.password = ko.observable('');
|
||||
this.password.focus = ko.observable(false);
|
||||
this.buttonFocus = ko.observable(false);
|
||||
|
||||
this.resultCallback = null;
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
|
||||
// commands
|
||||
this.doCommand = Utils.createCommand(this, function () {
|
||||
|
||||
this.submitRequest(true);
|
||||
|
||||
_.delay(_.bind(function() {
|
||||
|
||||
var
|
||||
oPrivateKeys = [],
|
||||
oPrivateKey = null
|
||||
;
|
||||
|
||||
try
|
||||
{
|
||||
if (this.resultCallback && this.selectedKey())
|
||||
{
|
||||
oPrivateKeys = this.selectedKey().getNativeKeys();
|
||||
oPrivateKey = oPrivateKeys && oPrivateKeys[0] ? oPrivateKeys[0] : null;
|
||||
|
||||
if (oPrivateKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!oPrivateKey.decrypt(Utils.pString(this.password())))
|
||||
{
|
||||
oPrivateKey = null;
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
oPrivateKey = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (oExc)
|
||||
{
|
||||
oPrivateKey = null;
|
||||
}
|
||||
|
||||
this.submitRequest(false);
|
||||
|
||||
this.cancelCommand();
|
||||
this.resultCallback(oPrivateKey);
|
||||
|
||||
}, this), 100);
|
||||
|
||||
}, function () {
|
||||
return !this.submitRequest();
|
||||
});
|
||||
|
||||
this.sDefaultKeyScope = Enums.KeyState.PopupMessageOpenPGP;
|
||||
|
||||
kn.constructorEnd(this);
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/Popup/MessageOpenPgp'], MessageOpenPgpPopupView);
|
||||
_.extend(MessageOpenPgpPopupView.prototype, AbstractView.prototype);
|
||||
|
||||
MessageOpenPgpPopupView.prototype.clearPopup = function ()
|
||||
{
|
||||
this.notification('');
|
||||
|
||||
this.password('');
|
||||
this.password.focus(false);
|
||||
this.buttonFocus(false);
|
||||
|
||||
this.selectedKey(false);
|
||||
this.submitRequest(false);
|
||||
|
||||
this.resultCallback = null;
|
||||
this.privateKeys([]);
|
||||
};
|
||||
|
||||
MessageOpenPgpPopupView.prototype.onBuild = function (oDom)
|
||||
{
|
||||
key('tab,shift+tab', Enums.KeyState.PopupMessageOpenPGP, _.bind(function () {
|
||||
|
||||
switch (true)
|
||||
{
|
||||
case this.password.focus():
|
||||
this.buttonFocus(true);
|
||||
break;
|
||||
case this.buttonFocus():
|
||||
this.password.focus(true);
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}, this));
|
||||
|
||||
var self = this;
|
||||
|
||||
oDom
|
||||
.on('click', '.key-list__item', function () {
|
||||
|
||||
oDom.find('.key-list__item .key-list__item__radio')
|
||||
.addClass('icon-radio-unchecked')
|
||||
.removeClass('icon-radio-checked')
|
||||
;
|
||||
|
||||
$(this).find('.key-list__item__radio')
|
||||
.removeClass('icon-radio-unchecked')
|
||||
.addClass('icon-radio-checked')
|
||||
;
|
||||
|
||||
self.selectedKey(ko.dataFor(this));
|
||||
|
||||
self.password.focus(true);
|
||||
})
|
||||
;
|
||||
};
|
||||
|
||||
MessageOpenPgpPopupView.prototype.onHideWithDelay = function ()
|
||||
{
|
||||
this.clearPopup();
|
||||
};
|
||||
|
||||
MessageOpenPgpPopupView.prototype.onShowWithDelay = function ()
|
||||
{
|
||||
this.password.focus(true);
|
||||
// this.buttonFocus(true);
|
||||
};
|
||||
|
||||
MessageOpenPgpPopupView.prototype.onShow = function (fCallback, aPrivateKeys)
|
||||
{
|
||||
this.clearPopup();
|
||||
|
||||
this.resultCallback = fCallback;
|
||||
this.privateKeys(aPrivateKeys);
|
||||
|
||||
if (this.viewModelDom)
|
||||
{
|
||||
this.viewModelDom.find('.key-list__item').first().click();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = MessageOpenPgpPopupView;
|
||||
|
||||
}());
|
||||
|
|
@ -62,29 +62,36 @@
|
|||
|
||||
_.delay(function () {
|
||||
|
||||
mKeyPair = false;
|
||||
var mPromise = false;
|
||||
|
||||
try {
|
||||
mKeyPair = PgpStore.openpgp.generateKeyPair({
|
||||
|
||||
mPromise = PgpStore.openpgp.generateKeyPair({
|
||||
'userId': sUserID,
|
||||
'numBits': Utils.pInt(self.keyBitLength()),
|
||||
'passphrase': Utils.trim(self.password())
|
||||
});
|
||||
} catch (e) {
|
||||
// window.console.log(e);
|
||||
}
|
||||
|
||||
if (mKeyPair && mKeyPair.privateKeyArmored)
|
||||
{
|
||||
oOpenpgpKeyring.privateKeys.importKey(mKeyPair.privateKeyArmored);
|
||||
oOpenpgpKeyring.publicKeys.importKey(mKeyPair.publicKeyArmored);
|
||||
oOpenpgpKeyring.store();
|
||||
mPromise.then(function () {
|
||||
|
||||
require('App/User').reloadOpenPgpKeys();
|
||||
Utils.delegateRun(self, 'cancelCommand');
|
||||
}
|
||||
self.submitRequest(false);
|
||||
|
||||
if (mKeyPair && mKeyPair.privateKeyArmored)
|
||||
{
|
||||
oOpenpgpKeyring.privateKeys.importKey(mKeyPair.privateKeyArmored);
|
||||
oOpenpgpKeyring.publicKeys.importKey(mKeyPair.publicKeyArmored);
|
||||
oOpenpgpKeyring.store();
|
||||
|
||||
require('App/User').reloadOpenPgpKeys();
|
||||
Utils.delegateRun(self, 'cancelCommand');
|
||||
}
|
||||
|
||||
})['catch'](function() {
|
||||
self.submitRequest(false);
|
||||
});
|
||||
|
||||
} catch (e) {}
|
||||
|
||||
self.submitRequest(false);
|
||||
|
||||
}, 100);
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -303,16 +303,6 @@
|
|||
this.viewIsImportant = ko.observable(false);
|
||||
this.viewIsFlagged = ko.observable(false);
|
||||
|
||||
// PGP
|
||||
this.viewPgpPassword = ko.observable('');
|
||||
this.viewPgpSignedVerifyStatus = ko.computed(function () {
|
||||
return this.message() ? this.message().pgpSignedVerifyStatus() : Enums.SignedVerifyStatus.None;
|
||||
}, this);
|
||||
|
||||
this.viewPgpSignedVerifyUser = ko.computed(function () {
|
||||
return this.message() ? this.message().pgpSignedVerifyUser() : '';
|
||||
}, this);
|
||||
|
||||
this.viewFromDkimStatusIconClass = ko.computed(function () {
|
||||
|
||||
var sResult = 'icon-none iconcolor-display-none';
|
||||
|
|
@ -361,8 +351,6 @@
|
|||
|
||||
this.messageActiveDom(null);
|
||||
|
||||
this.viewPgpPassword('');
|
||||
|
||||
if (oMessage)
|
||||
{
|
||||
this.showAttachmnetControls(false);
|
||||
|
|
@ -523,48 +511,6 @@
|
|||
return sResult;
|
||||
};
|
||||
|
||||
MessageViewMailBoxUserView.prototype.isPgpActionVisible = function ()
|
||||
{
|
||||
return Enums.SignedVerifyStatus.Success !== this.viewPgpSignedVerifyStatus();
|
||||
};
|
||||
|
||||
MessageViewMailBoxUserView.prototype.isPgpStatusVerifyVisible = function ()
|
||||
{
|
||||
return Enums.SignedVerifyStatus.None !== this.viewPgpSignedVerifyStatus();
|
||||
};
|
||||
|
||||
MessageViewMailBoxUserView.prototype.isPgpStatusVerifySuccess = function ()
|
||||
{
|
||||
return Enums.SignedVerifyStatus.Success === this.viewPgpSignedVerifyStatus();
|
||||
};
|
||||
|
||||
MessageViewMailBoxUserView.prototype.pgpStatusVerifyMessage = function ()
|
||||
{
|
||||
var sResult = '';
|
||||
switch (this.viewPgpSignedVerifyStatus())
|
||||
{
|
||||
case Enums.SignedVerifyStatus.UnknownPublicKeys:
|
||||
sResult = Translator.i18n('PGP_NOTIFICATIONS/NO_PUBLIC_KEYS_FOUND');
|
||||
break;
|
||||
case Enums.SignedVerifyStatus.UnknownPrivateKey:
|
||||
sResult = Translator.i18n('PGP_NOTIFICATIONS/NO_PRIVATE_KEY_FOUND');
|
||||
break;
|
||||
case Enums.SignedVerifyStatus.Unverified:
|
||||
sResult = Translator.i18n('PGP_NOTIFICATIONS/UNVERIFIRED_SIGNATURE');
|
||||
break;
|
||||
case Enums.SignedVerifyStatus.Error:
|
||||
sResult = Translator.i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR');
|
||||
break;
|
||||
case Enums.SignedVerifyStatus.Success:
|
||||
sResult = Translator.i18n('PGP_NOTIFICATIONS/GOOD_SIGNATURE', {
|
||||
'USER': this.viewPgpSignedVerifyUser()
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
return sResult;
|
||||
};
|
||||
|
||||
MessageViewMailBoxUserView.prototype.fullScreen = function ()
|
||||
{
|
||||
this.fullScreenMode(true);
|
||||
|
|
@ -1256,31 +1202,6 @@
|
|||
return 0 < iCnt ? (100 > iCnt ? iCnt : '99+') : '';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {MessageModel} oMessage
|
||||
*/
|
||||
MessageViewMailBoxUserView.prototype.verifyPgpSignedClearMessage = function (oMessage)
|
||||
{
|
||||
if (oMessage)
|
||||
{
|
||||
oMessage.verifyPgpSignedClearMessage();
|
||||
}
|
||||
|
||||
this.checkHeaderHeight();
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {MessageModel} oMessage
|
||||
*/
|
||||
MessageViewMailBoxUserView.prototype.decryptPgpEncryptedMessage = function (oMessage)
|
||||
{
|
||||
if (oMessage)
|
||||
{
|
||||
oMessage.decryptPgpEncryptedMessage(this.viewPgpPassword());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {MessageModel} oMessage
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue