mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-11 00:14:50 +03:00
Login password RSA encrypt/decrypt
This commit is contained in:
parent
dfb3a07536
commit
1066af98d4
10 changed files with 4695 additions and 94 deletions
|
|
@ -4,6 +4,8 @@
|
|||
'use strict';
|
||||
|
||||
var
|
||||
oEncryptObject = null,
|
||||
|
||||
Utils = {},
|
||||
|
||||
window = require('window'),
|
||||
|
|
@ -170,30 +172,55 @@
|
|||
};
|
||||
|
||||
/**
|
||||
* @param {string} sValue
|
||||
* @param {string} sHash
|
||||
* @param {string} sKey
|
||||
* @param {string} sLongKey
|
||||
* @return {string|boolean}
|
||||
* @param {string} sPublicKey
|
||||
* @return {JSEncrypt}
|
||||
*/
|
||||
Utils.rsaEncode = function (sValue, sHash, sKey, sLongKey)
|
||||
Utils.rsaObject = function (sPublicKey)
|
||||
{
|
||||
if (window.crypto && window.crypto.getRandomValues && window.RSAKey && sHash && sKey && sLongKey)
|
||||
if (sPublicKey && (null === oEncryptObject || (oEncryptObject && oEncryptObject.__sPublicKey !== sPublicKey)) &&
|
||||
window.crypto && window.crypto.getRandomValues && window.JSEncrypt)
|
||||
{
|
||||
var oRsa = new window.RSAKey();
|
||||
oRsa.setPublic(sLongKey, sKey);
|
||||
oEncryptObject = new JSEncrypt();
|
||||
oEncryptObject.setPublicKey(sPublicKey);
|
||||
oEncryptObject.__sPublicKey = sPublicKey;
|
||||
}
|
||||
else
|
||||
{
|
||||
oEncryptObject = false;
|
||||
}
|
||||
|
||||
sValue = oRsa.encrypt(Utils.fakeMd5() + ':' + sValue + ':' + Utils.fakeMd5());
|
||||
if (false !== sValue)
|
||||
return oEncryptObject;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sValue
|
||||
* @param {string} sPublicKey
|
||||
* @return {string}
|
||||
*/
|
||||
Utils.rsaEncode = function (sValue, sPublicKey)
|
||||
{
|
||||
if (window.crypto && window.crypto.getRandomValues && window.JSEncrypt && sPublicKey)
|
||||
{
|
||||
var
|
||||
sResultValue = false,
|
||||
oEncrypt = Utils.rsaObject(sPublicKey);
|
||||
;
|
||||
|
||||
if (oEncrypt)
|
||||
{
|
||||
return 'rsa:' + sHash + ':' + sValue;
|
||||
sResultValue = oEncrypt.encrypt(Utils.fakeMd5() + ':' + sValue + ':' + Utils.fakeMd5())
|
||||
}
|
||||
|
||||
if (false !== sResultValue && Utils.isNormal(sResultValue))
|
||||
{
|
||||
return 'rsa:xxx:' + sResultValue;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return sValue;
|
||||
};
|
||||
|
||||
Utils.rsaEncode.supported = !!(window.crypto && window.crypto.getRandomValues && window.RSAKey);
|
||||
Utils.rsaEncode.supported = !!(window.crypto && window.crypto.getRandomValues && window.JSEncrypt);
|
||||
|
||||
/**
|
||||
* @param {string} sText
|
||||
|
|
|
|||
|
|
@ -163,29 +163,10 @@
|
|||
}, this)
|
||||
;
|
||||
|
||||
if (!!Settings.settingsGet('UseRsaEncryption') && Utils.rsaEncode.supported)
|
||||
if (!!Settings.settingsGet('UseRsaEncryption') && Utils.rsaEncode.supported &&
|
||||
Settings.settingsGet('RsaPublicKey'))
|
||||
{
|
||||
Remote.getPublicKey(_.bind(function (sResult, oData) {
|
||||
|
||||
var bRequest = false;
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result &&
|
||||
Utils.isArray(oData.Result) && oData.Result[0] && oData.Result[1] && oData.Result[2])
|
||||
{
|
||||
var sEncryptedPassword = Utils.rsaEncode(sPassword, oData.Result[0], oData.Result[1], oData.Result[2]);
|
||||
if (sEncryptedPassword)
|
||||
{
|
||||
fLoginRequest(sEncryptedPassword);
|
||||
bRequest = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!bRequest)
|
||||
{
|
||||
this.submitRequest(false);
|
||||
this.submitError(Utils.getNotification(Enums.Notification.UnknownError));
|
||||
}
|
||||
|
||||
}, this));
|
||||
fLoginRequest(Utils.rsaEncode(sPassword, Settings.settingsGet('RsaPublicKey')));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue