OpenPGP Key Storage (Settings) (#53)

Import, Delete, Generate, View
This commit is contained in:
RainLoop Team 2014-03-13 02:29:33 +04:00
parent 5a5c6af2c6
commit 5ece4cc0ec
47 changed files with 1333 additions and 539 deletions

View file

@ -209,38 +209,6 @@ MailBoxMessageViewViewModel.prototype.replyOrforward = function (sType)
kn.showScreenPopup(PopupsComposeViewModel, [sType, RL.data().message()]);
};
MailBoxMessageViewViewModel.prototype.receivePrivateKey = function ()
{
var self = this;
kn.showScreenPopup(PopupsPgpKey, [true, function (sPrivatePassphrase, sPrivateKey) {
var oMessage = self.message(), mPgpMessage, mPgpKey, mDecPgpKey;
if (oMessage)
{
try
{
mPgpMessage = window.openpgp.message.readArmored(oMessage.plainRaw);
mPgpKey = window.openpgp.key.readArmored(sPrivateKey);
if (mPgpMessage && mPgpKey && mPgpKey.keys && mPgpKey.keys[0])
{
mDecPgpKey = mPgpKey.keys[0];
if ('' !== sPrivatePassphrase)
{
mDecPgpKey.decrypt(sPrivatePassphrase);
}
oMessage.body.html(
'<pre class="b-plain-openpgp encrypted">' +
window.openpgp.decryptMessage(mDecPgpKey, mPgpMessage) +
'</pre>'
);
}
}
catch (oExt) {}
}
}]);
};
MailBoxMessageViewViewModel.prototype.onBuild = function (oDom)
{
var

View file

@ -115,15 +115,4 @@ PopupsAddAccountViewModel.prototype.onFocus = function ()
PopupsAddAccountViewModel.prototype.onBuild = function ()
{
this.allowCustomLogin(!!RL.settingsGet('AllowCustomLogin'));
var self = this;
$window.on('keydown', function (oEvent) {
var bResult = true;
if (oEvent && Enums.EventKeyCode.Esc === oEvent.keyCode && self.modalVisibility())
{
Utils.delegateRun(self, 'cancelCommand');
bResult = false;
}
return bResult;
});
};

View file

@ -0,0 +1,61 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsAddOpenPgpKeyViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsAddOpenPgpKey');
this.key = ko.observable('');
this.key.error = ko.observable(false);
this.key.focus = ko.observable(false);
this.key.subscribe(function () {
this.key.error(false);
}, this);
this.addOpenPgpKeyCommand = Utils.createCommand(this, function () {
var
sKey = Utils.trim(this.key()),
oOpenpgpKeyring = RL.data().openpgpKeyring
;
this.key.error('' === sKey);
if (!oOpenpgpKeyring || this.key.error())
{
return false;
}
oOpenpgpKeyring.importKey(sKey);
oOpenpgpKeyring.store();
RL.reloadOpenPgpKeys();
Utils.delegateRun(this, 'cancelCommand');
return true;
});
Knoin.constructorEnd(this);
}
Utils.extendAsViewModel('PopupsAddOpenPgpKeyViewModel', PopupsAddOpenPgpKeyViewModel);
PopupsAddOpenPgpKeyViewModel.prototype.clearPopup = function ()
{
this.key('');
this.key.error(false);
};
PopupsAddOpenPgpKeyViewModel.prototype.onShow = function ()
{
this.clearPopup();
};
PopupsAddOpenPgpKeyViewModel.prototype.onFocus = function ()
{
this.key.focus(true);
};

View file

@ -129,17 +129,3 @@ PopupsAdvancedSearchViewModel.prototype.onFocus = function ()
{
this.fromFocus(true);
};
PopupsAdvancedSearchViewModel.prototype.onBuild = function ()
{
var self = this;
$window.on('keydown', function (oEvent) {
var bResult = true;
if (oEvent && Enums.EventKeyCode.Esc === oEvent.keyCode && self.modalVisibility())
{
Utils.delegateRun(self, 'cancelCommand');
bResult = false;
}
return bResult;
});
};

View file

@ -18,6 +18,8 @@ function PopupsAskViewModel()
this.fYesAction = null;
this.fNoAction = null;
this.bDisabeCloseOnEsc = true;
Knoin.constructorEnd(this);
}

View file

@ -389,6 +389,8 @@ function PopupsComposeViewModel()
// this.driveCallback = _.bind(this.driveCallback, this);
this.bDisabeCloseOnEsc = true;
Knoin.constructorEnd(this);
}

View file

@ -600,25 +600,6 @@ PopupsContactsViewModel.prototype.onBuild = function (oDom)
})
;
$window.on('keydown', function (oEvent) {
var bResult = true;
if (oEvent && self.modalVisibility())
{
if (Enums.EventKeyCode.Esc === oEvent.keyCode)
{
Utils.delegateRun(self, 'closeCommand');
bResult = false;
}
else if (oEvent.ctrlKey && Enums.EventKeyCode.S === oEvent.keyCode)
{
self.saveCommand();
bResult = false;
}
}
return bResult;
});
this.initUploader();
};

View file

@ -196,20 +196,6 @@ PopupsDomainViewModel.prototype.onFocus = function ()
}
};
PopupsDomainViewModel.prototype.onBuild = function ()
{
var self = this;
$window.on('keydown', function (oEvent) {
var bResult = true;
if (oEvent && Enums.EventKeyCode.Esc === oEvent.keyCode && self.modalVisibility())
{
Utils.delegateRun(self, 'cancelCommand');
bResult = false;
}
return bResult;
});
};
PopupsDomainViewModel.prototype.clearForm = function ()
{
this.edit(false);

View file

@ -95,17 +95,3 @@ PopupsFolderClearViewModel.prototype.onShow = function (oFolder)
this.selectedFolder(oFolder);
}
};
PopupsFolderClearViewModel.prototype.onBuild = function ()
{
var self = this;
$window.on('keydown', function (oEvent) {
var bResult = true;
if (oEvent && Enums.EventKeyCode.Esc === oEvent.keyCode && self.modalVisibility())
{
Utils.delegateRun(self, 'cancelCommand');
bResult = false;
}
return bResult;
});
};

View file

@ -109,17 +109,3 @@ PopupsFolderCreateViewModel.prototype.onFocus = function ()
{
this.folderName.focused(true);
};
PopupsFolderCreateViewModel.prototype.onBuild = function ()
{
var self = this;
$window.on('keydown', function (oEvent) {
var bResult = true;
if (oEvent && Enums.EventKeyCode.Esc === oEvent.keyCode && self.modalVisibility())
{
Utils.delegateRun(self, 'cancelCommand');
bResult = false;
}
return bResult;
});
};

View file

@ -104,17 +104,3 @@ PopupsFolderSystemViewModel.prototype.onShow = function (iNotificationType)
this.notification(sNotification);
};
PopupsFolderSystemViewModel.prototype.onBuild = function ()
{
var self = this;
$window.on('keydown', function (oEvent) {
var bResult = true;
if (oEvent && Enums.EventKeyCode.Esc === oEvent.keyCode && self.modalVisibility())
{
Utils.delegateRun(self, 'cancelCommand');
bResult = false;
}
return bResult;
});
};

View file

@ -0,0 +1,90 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsGenerateNewOpenPgpKeyViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsGenerateNewOpenPgpKey');
this.email = ko.observable('');
this.email.focus = ko.observable('');
this.email.error = ko.observable(false);
this.name = ko.observable('');
this.password = ko.observable('');
this.keyBitLength = ko.observable(2048);
this.submitRequest = ko.observable(false);
this.email.subscribe(function () {
this.email.error(false);
}, this);
this.generateOpenPgpKeyCommand = Utils.createCommand(this, function () {
var
self = this,
sUserID = '',
mKeyPair = null,
oOpenpgpKeyring = RL.data().openpgpKeyring
;
this.email.error('' === Utils.trim(this.email()));
if (!oOpenpgpKeyring || this.email.error())
{
return false;
}
sUserID = this.email();
if ('' !== this.name())
{
sUserID = this.name() + ' <' + sUserID + '>';
}
this.submitRequest(true);
_.delay(function () {
mKeyPair = window.openpgp.generateKeyPair(1, Utils.pInt(self.keyBitLength()), sUserID, Utils.trim(self.password()));
if (mKeyPair && mKeyPair.privateKeyArmored)
{
oOpenpgpKeyring.importKey(mKeyPair.privateKeyArmored);
oOpenpgpKeyring.importKey(mKeyPair.publicKeyArmored);
oOpenpgpKeyring.store();
RL.reloadOpenPgpKeys();
Utils.delegateRun(self, 'cancelCommand');
}
self.submitRequest(false);
}, 100);
return true;
});
Knoin.constructorEnd(this);
}
Utils.extendAsViewModel('PopupsGenerateNewOpenPgpKeyViewModel', PopupsGenerateNewOpenPgpKeyViewModel);
PopupsGenerateNewOpenPgpKeyViewModel.prototype.clearPopup = function ()
{
this.name('');
this.password('');
this.email('');
this.email.error(false);
this.keyBitLength(2048);
};
PopupsGenerateNewOpenPgpKeyViewModel.prototype.onShow = function ()
{
this.clearPopup();
};
PopupsGenerateNewOpenPgpKeyViewModel.prototype.onFocus = function ()
{
this.email.focus(true);
};

View file

@ -147,17 +147,3 @@ PopupsIdentityViewModel.prototype.onFocus = function ()
this.email.focused(true);
}
};
PopupsIdentityViewModel.prototype.onBuild = function ()
{
var self = this;
$window.on('keydown', function (oEvent) {
var bResult = true;
if (oEvent && Enums.EventKeyCode.Esc === oEvent.keyCode && self.modalVisibility())
{
Utils.delegateRun(self, 'cancelCommand');
bResult = false;
}
return bResult;
});
};

View file

@ -54,20 +54,6 @@ PopupsLanguagesViewModel.prototype.onHide = function ()
this.exp(false);
};
PopupsLanguagesViewModel.prototype.onBuild = function ()
{
var self = this;
$window.on('keydown', function (oEvent) {
var bResult = true;
if (oEvent && Enums.EventKeyCode.Esc === oEvent.keyCode && self.modalVisibility())
{
Utils.delegateRun(self, 'cancelCommand');
bResult = false;
}
return bResult;
});
};
PopupsLanguagesViewModel.prototype.changeLanguage = function (sLang)
{
RL.data().mainLanguage(sLang);

View file

@ -1,64 +0,0 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsPgpKey()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsPgpKey');
this.key = ko.observable('');
this.passphrase = ko.observable('');
this.bPrivate = null;
this.fCallback = null;
// commands
this.sendPgp = Utils.createCommand(this, function () {
var sKey = Utils.trim(this.key());
if (this.fCallback && sKey)
{
this.fCallback(this.passphrase(), sKey);
}
this.cancelCommand();
});
Knoin.constructorEnd(this);
}
Utils.extendAsViewModel('PopupsPgpKey', PopupsPgpKey);
PopupsPgpKey.prototype.clearPopup = function ()
{
// this.key('');
// this.passphrase('');
this.bPrivate = null;
this.fCallback = null;
};
PopupsPgpKey.prototype.onBuild = function ()
{
var self = this;
$window.on('keydown', function (oEvent) {
var bResult = true;
if (oEvent && self.modalVisibility() && Enums.EventKeyCode.Esc === oEvent.keyCode)
{
Utils.delegateRun(self, 'closeCommand');
bResult = false;
}
return bResult;
});
};
PopupsPgpKey.prototype.onShow = function (bPrivate, fCallback)
{
this.clearPopup();
this.bPrivate = bPrivate;
this.fCallback = fCallback;
};

View file

@ -59,6 +59,8 @@ function PopupsPluginViewModel()
}, this.hasConfiguration);
this.bDisabeCloseOnEsc = true;
Knoin.constructorEnd(this);
}

View file

@ -0,0 +1,41 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsViewOpenPgpKeyViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsViewOpenPgpKey');
this.key = ko.observable('');
this.keyDom = ko.observable(null);
Knoin.constructorEnd(this);
}
Utils.extendAsViewModel('PopupsViewOpenPgpKeyViewModel', PopupsViewOpenPgpKeyViewModel);
PopupsViewOpenPgpKeyViewModel.prototype.clearPopup = function ()
{
this.key('');
};
PopupsViewOpenPgpKeyViewModel.prototype.selectKey = function ()
{
var oEl = this.keyDom();
if (oEl)
{
Utils.selectElement(oEl);
}
};
PopupsViewOpenPgpKeyViewModel.prototype.onShow = function (oOpenPgpKey)
{
this.clearPopup();
if (oOpenPgpKey)
{
this.key(oOpenPgpKey.armor);
}
};