mirror of
https://github.com/moparisthebest/mail
synced 2024-12-21 23:08:50 -05:00
Add error handling for invalid PGP key user id
This commit is contained in:
parent
39d19df187
commit
f32863dc54
@ -106,7 +106,7 @@ PGP.prototype.getKeyId = function(keyArmored) {
|
||||
* Read all relevant params of an armored key.
|
||||
*/
|
||||
PGP.prototype.getKeyParams = function(keyArmored) {
|
||||
var key, packet, userIds;
|
||||
var key, packet, userIds, emailAddress;
|
||||
|
||||
// process armored key input
|
||||
if (keyArmored) {
|
||||
@ -122,15 +122,24 @@ PGP.prototype.getKeyParams = function(keyArmored) {
|
||||
// read user names and email addresses
|
||||
userIds = [];
|
||||
key.getUserIds().forEach(function(userId) {
|
||||
if (!userId || userId.indexOf('<') < 0 || userId.indexOf('>') < 0) {
|
||||
return;
|
||||
}
|
||||
userIds.push({
|
||||
name: userId.split('<')[0].trim(),
|
||||
emailAddress: userId.split('<')[1].split('>')[0].trim()
|
||||
});
|
||||
});
|
||||
|
||||
// check user ID
|
||||
emailAddress = userIds[0] && userIds[0].emailAddress;
|
||||
if (!emailAddress) {
|
||||
throw new Error('Cannot parse PGP key user ID!');
|
||||
}
|
||||
|
||||
return {
|
||||
_id: packet.getKeyId().toHex().toUpperCase(),
|
||||
userId: userIds[0].emailAddress, // the primary (first) email address of the key
|
||||
userId: emailAddress, // the primary (first) email address of the key
|
||||
userIds: userIds, // a dictonary of all the key's name/address pairs
|
||||
fingerprint: packet.getFingerprint().toUpperCase(),
|
||||
algorithm: packet.algorithm,
|
||||
|
Loading…
Reference in New Issue
Block a user