Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenPGP Key Storage (Settings) (#53)
Import, Delete, Generate, View
- Loading branch information
Showing
47 changed files
with
1,333 additions
and
539 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */ | ||
|
||
/** | ||
* @param {string} iIndex | ||
* @param {string} sID | ||
* @param {string} sUserID | ||
* @param {boolean} bIsPrivate | ||
* @param {string} sArmor | ||
* @constructor | ||
*/ | ||
function OpenPgpKeyModel(iIndex, sID, sUserID, bIsPrivate, sArmor) | ||
{ | ||
this.index = iIndex; | ||
this.id = sID; | ||
this.user = sUserID; | ||
this.armor = sArmor; | ||
this.isPrivate = !!bIsPrivate; | ||
|
||
this.deleteAccess = ko.observable(false); | ||
} | ||
|
||
OpenPgpKeyModel.prototype.index = 0; | ||
OpenPgpKeyModel.prototype.id = ''; | ||
OpenPgpKeyModel.prototype.user = ''; | ||
OpenPgpKeyModel.prototype.armor = ''; | ||
OpenPgpKeyModel.prototype.isPrivate = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */ | ||
|
||
/** | ||
* @constructor | ||
*/ | ||
function SettingsOpenPGP() | ||
{ | ||
this.openpgpkeys = RL.data().openpgpkeys; | ||
|
||
this.openpgpkeysPublic = ko.computed(function () { | ||
return _.filter(this.openpgpkeys(), function (oItem) { | ||
return !!(oItem && !oItem.isPrivate); | ||
}); | ||
}, this); | ||
|
||
this.openpgpkeysPrivate = ko.computed(function () { | ||
return _.filter(this.openpgpkeys(), function (oItem) { | ||
return !!(oItem && oItem.isPrivate); | ||
}); | ||
}, this); | ||
|
||
this.openPgpKeyForDeletion = ko.observable(null).extend({'falseTimeout': 3000}).extend({'toggleSubscribe': [this, | ||
function (oPrev) { | ||
if (oPrev) | ||
{ | ||
oPrev.deleteAccess(false); | ||
} | ||
}, function (oNext) { | ||
if (oNext) | ||
{ | ||
oNext.deleteAccess(true); | ||
} | ||
} | ||
]}); | ||
} | ||
|
||
Utils.addSettingsViewModel(SettingsOpenPGP, 'SettingsOpenPGP', 'SETTINGS_LABELS/LABEL_OPEN_PGP_NAME', 'openpgp'); | ||
|
||
SettingsOpenPGP.prototype.addOpenPgpKey = function () | ||
{ | ||
kn.showScreenPopup(PopupsAddOpenPgpKeyViewModel); | ||
}; | ||
|
||
SettingsOpenPGP.prototype.generateOpenPgpKey = function () | ||
{ | ||
kn.showScreenPopup(PopupsGenerateNewOpenPgpKeyViewModel); | ||
}; | ||
|
||
SettingsOpenPGP.prototype.viewOpenPgpKey = function (oOpenPgpKey) | ||
{ | ||
if (oOpenPgpKey) | ||
{ | ||
kn.showScreenPopup(PopupsViewOpenPgpKeyViewModel, [oOpenPgpKey]); | ||
} | ||
}; | ||
|
||
/** | ||
* @param {OpenPgpKeyModel} oOpenPgpKeyToRemove | ||
*/ | ||
SettingsOpenPGP.prototype.deleteOpenPgpKey = function (oOpenPgpKeyToRemove) | ||
{ | ||
if (oOpenPgpKeyToRemove && oOpenPgpKeyToRemove.deleteAccess()) | ||
{ | ||
this.openPgpKeyForDeletion(null); | ||
|
||
var | ||
oOpenpgpKeyring = RL.data().openpgpKeyring, | ||
fRemoveAccount = function (oOpenPgpKey) { | ||
return oOpenPgpKeyToRemove === oOpenPgpKey; | ||
} | ||
; | ||
|
||
if (oOpenPgpKeyToRemove && oOpenpgpKeyring) | ||
{ | ||
this.openpgpkeys.remove(fRemoveAccount); | ||
|
||
oOpenpgpKeyring.removeKey(oOpenPgpKeyToRemove.index); | ||
oOpenpgpKeyring.store(); | ||
|
||
RL.reloadOpenPgpKeys(); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */ | ||
|
||
/** | ||
* @constructor | ||
*/ | ||
function OpenPgpLocalStorageDriver() | ||
{ | ||
} | ||
|
||
/* | ||
* Declare the localstore itemname | ||
*/ | ||
OpenPgpLocalStorageDriver.prototype.item = 'armoredRainLoopKeys'; | ||
|
||
/** | ||
* Load the keyring from HTML5 local storage and initializes this instance. | ||
* @return {Array<module:key~Key>} array of keys retrieved from localstore | ||
*/ | ||
OpenPgpLocalStorageDriver.prototype.load = function () | ||
{ | ||
var | ||
iIndex = 0, | ||
iLen = 0, | ||
aKeys = [], | ||
aArmoredKeys = JSON.parse(window.localStorage.getItem(this.item)) | ||
; | ||
|
||
if (aArmoredKeys && 0 < aArmoredKeys.length) | ||
{ | ||
for (iLen = aArmoredKeys.length; iIndex < iLen; iIndex++) | ||
{ | ||
aKeys.push( | ||
window.openpgp.key.readArmored(aArmoredKeys[iIndex]).keys[0] | ||
); | ||
} | ||
} | ||
|
||
return aKeys; | ||
}; | ||
|
||
/** | ||
* Saves the current state of the keyring to HTML5 local storage. | ||
* The privateKeys array and publicKeys array gets Stringified using JSON | ||
* @param {Array<module:key~Key>} aKeys array of keys to save in localstore | ||
*/ | ||
OpenPgpLocalStorageDriver.prototype.store = function (aKeys) | ||
{ | ||
var | ||
iIndex = 0, | ||
iLen = aKeys.length, | ||
aArmoredKeys = [] | ||
; | ||
|
||
for (; iIndex < iLen; iIndex++) | ||
{ | ||
aArmoredKeys.push(aKeys[iIndex].armor()); | ||
} | ||
|
||
window.localStorage.setItem(this.item, JSON.stringify(aArmoredKeys)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.