Encrypt/decrypt with multiple addresses in a single GPG key

This commit is contained in:
Carles Escrig Royo 2016-04-06 20:26:29 +02:00
parent d14375d022
commit a34da5de0d
No known key found for this signature in database
GPG key ID: 5E6F07C704111773
8 changed files with 141 additions and 62 deletions

View file

@ -426,25 +426,36 @@ class AppUser extends AbstractApp
if (oItem && oItem.primaryKey)
{
var
aEmails = [],
aUsers = [],
oPrimaryUser = oItem.getPrimaryUser(),
sUser = (oPrimaryUser && oPrimaryUser.user) ? oPrimaryUser.user.userId.userid
: (oItem.users && oItem.users[0] ? oItem.users[0].userId.userid : '')
;
oEmail.clear();
oEmail.mailsoParse(sUser);
if (oItem.users) {
_.each(oItem.users, (oItem) => {
oEmail.clear();
oEmail.mailsoParse(oItem.userId.userid);
if (oEmail.validate())
{
aEmails.push(oEmail.email);
aUsers.push(oItem.userId.userid);
}
});
}
if (oEmail.validate())
if (aEmails.length)
{
aKeys.push(new OpenPgpKeyModel(
iIndex,
oItem.primaryKey.getFingerprint(),
oItem.primaryKey.getKeyId().toHex().toLowerCase(),
sUser,
oEmail.email,
aUsers,
aEmails,
oItem.isPrivate(),
oItem.armor())
oItem.armor(),
sUser)
);
}
}

View file

@ -18,23 +18,25 @@
* @param {string} iIndex
* @param {string} sGuID
* @param {string} sID
* @param {string} sUserID
* @param {string} sEmail
* @param {array} aUserIDs
* @param {array} aEmails
* @param {boolean} bIsPrivate
* @param {string} sArmor
* @param {string} sUserID
* @constructor
*/
function OpenPgpKeyModel(iIndex, sGuID, sID, sUserID, sEmail, bIsPrivate, sArmor)
function OpenPgpKeyModel(iIndex, sGuID, sID, aUserIDs, aEmails, bIsPrivate, sArmor, sUserID)
{
AbstractModel.call(this, 'OpenPgpKeyModel');
this.index = iIndex;
this.id = sID;
this.guid = sGuID;
this.user = sUserID;
this.email = sEmail;
this.users = aUserIDs;
this.emails = aEmails;
this.armor = sArmor;
this.isPrivate = !!bIsPrivate;
this.selectUser(sUserID);
this.deleteAccess = ko.observable(false);
}
@ -45,7 +47,9 @@
OpenPgpKeyModel.prototype.id = '';
OpenPgpKeyModel.prototype.guid = '';
OpenPgpKeyModel.prototype.user = '';
OpenPgpKeyModel.prototype.users = [];
OpenPgpKeyModel.prototype.email = '';
OpenPgpKeyModel.prototype.emails = [];
OpenPgpKeyModel.prototype.armor = '';
OpenPgpKeyModel.prototype.isPrivate = false;
@ -74,6 +78,26 @@
return oKey && oKey.keys ? oKey.keys : null;
};
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];
}
}
OpenPgpKeyModel.prototype.selectUser = function (sUser)
{
this.select(sUser, 'users');
}
OpenPgpKeyModel.prototype.selectEmail = function (sEmail)
{
this.select(sEmail, 'emails');
}
module.exports = OpenPgpKeyModel;
}());
}());

View file

@ -59,7 +59,7 @@
PgpUserStore.prototype.findPublicKeysByEmail = function (sEmail)
{
return _.compact(_.flatten(_.map(this.openpgpkeysPublic(), function (oItem) {
var oKey = oItem && sEmail === oItem.email ? oItem : null;
var oKey = oItem && -1 !== oItem.emails.indexOf(sEmail) ? oItem : null;
return oKey ? oKey.getNativeKeys() : [null];
}), true));
};
@ -99,7 +99,7 @@
PgpUserStore.prototype.findPublicKeyByEmailNotNative = function (sEmail)
{
return _.find(this.openpgpkeysPublic(), function (oItem) {
return oItem && sEmail === oItem.email;
return oItem && -1 !== oItem.emails.indexOf(sEmail);
}) || null;
};
@ -110,7 +110,7 @@
PgpUserStore.prototype.findPrivateKeyByEmailNotNative = function (sEmail)
{
return _.find(this.openpgpkeysPrivate(), function (oItem) {
return oItem && sEmail === oItem.email;
return oItem && -1 !== oItem.emails.indexOf(sEmail);
}) || null;
};
@ -125,7 +125,7 @@
oPrivateKeys = [],
oPrivateKey = null,
oKey = _.find(this.openpgpkeysPrivate(), function (oItem) {
return oItem && sEmail === oItem.email;
return oItem && -1 !== oItem.emails.indexOf(sEmail);
})
;

View file

@ -33,8 +33,14 @@
min-height: 40px;
&-wrp {
overflow: hidden;
text-overflow: ellipsis;
&:hover {
overflow: auto;
}
&:hover .key-list__item-name {
overflow: visible;
}
&.empty {
text-align: center;
@ -48,33 +54,35 @@
color: #333;
white-space: nowrap;
padding-bottom: 4px;
&-delete {
display: inline;
cursor: pointer;
margin-right: 5px;
&:last-child {
padding-bottom: 0;
}
&-name {
margin-right: 5px;
&-delete {
cursor: pointer;
}
&-names {
color: #333;
display: inline;
&.empty {
color: red;
}
}
&-name {
overflow: hidden;
text-overflow: ellipsis;
}
&-error {
margin-right: 5px;
color: red;
display: inline;
}
&-hash {
margin-right: 5px;
color: #aaa;
display: inline;
}
}
}
@ -82,6 +90,10 @@
.key-actions {
margin-top: 10px;
min-height: 40px;
select option.even {
background-color: #f5f5f5;
}
}
}
@ -103,15 +115,21 @@
white-space: nowrap;
&__radio {
padding-right: 5px;
padding: 3px 5px 0 0;
vertical-align: top;
}
&__name {
border-bottom: 1px solid transparent;
&:hover {
border-bottom: 1px dashed #555;
}
}
&__names {
display: inline-block;
}
}
}
}
@ -129,4 +147,4 @@
}
}
}
}
}

View file

@ -31,6 +31,14 @@
var self = this;
this.optionsCaption = Translator.i18n('PGP_NOTIFICATIONS/ADD_A_PUBLICK_KEY');
this.addOptionClass = function (oDomOption, oItem)
{
self.defautOptionsAfterRender(oDomOption, oItem);
if (oItem) {
oDomOption.classList.add(oItem['class']);
}
};
this.notification = ko.observable('');
@ -54,13 +62,17 @@
}, this);
this.publicKeysOptions = ko.computed(function () {
return _.compact(_.map(PgpStore.openpgpkeysPublic(), function (oKey) {
return -1 < Utils.inArray(oKey, self.encryptKeysView()) ? null : {
'id': oKey.guid,
'name': '(' + oKey.id.substr(-8).toUpperCase() + ') ' + oKey.user,
'key': oKey
};
}));
return _.compact(_.flatten(_.map(PgpStore.openpgpkeysPublic(), function (oKey, iIndex) {
return -1 < Utils.inArray(oKey, self.encryptKeysView()) ? null :
_.map(oKey.users, function (sUser) {
return {
'id': oKey.guid,
'name': '(' + oKey.id.substr(-8).toUpperCase() + ') ' + sUser,
'key': oKey,
'class': iIndex % 2 ? 'odd' : 'even'
};
});
}), true));
});
this.submitRequest = ko.observable(false);
@ -236,7 +248,7 @@
aKeys.push({
'empty': !oOption.key,
'selected': ko.observable(!!oOption.key),
'user': oOption.key.user,
'users': oOption.key.users,
'hash': oOption.key.id.substr(-8).toUpperCase(),
'key': oOption.key
});
@ -364,7 +376,7 @@
if (oKey)
{
this.signKey({
'user': oKey.user || sEmail,
'users': oKey.users || [sEmail],
'hash': oKey.id.substr(-8).toUpperCase(),
'key': oKey
});
@ -383,7 +395,7 @@
return {
'empty': !oKey,
'selected': ko.observable(!!oKey),
'user': oKey ? (oKey.user || sEmail) : sEmail,
'users': oKey ? (oKey.users || [sEmail]) : [sEmail],
'hash': oKey ? oKey.id.substr(-8).toUpperCase() : '',
'key': oKey
};
@ -400,4 +412,4 @@
module.exports = ComposeOpenPgpPopupView;
}());
}());

View file

@ -184,4 +184,4 @@ _.delay(_.bind(function() {
module.exports = MessageOpenPgpPopupView;
}());
}());