mirror of
https://github.com/moparisthebest/mail
synced 2024-11-24 18:02:15 -05:00
Ignore keys from HKP server in keychain.getUserKeyPair
Remove unused getPublicKeys function
This commit is contained in:
parent
f8e5ea6d89
commit
5bf0890c02
@ -57,40 +57,6 @@ Keychain.prototype.verifyPublicKey = function(uuid) {
|
||||
return this._publicKeyDao.verify(uuid);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an array of public keys by looking in local storage and
|
||||
* fetching missing keys from the cloud service.
|
||||
* @param ids [Array] the key ids as [{_id, userId}]
|
||||
* @return [PublicKeyCollection] The requiested public keys
|
||||
*/
|
||||
Keychain.prototype.getPublicKeys = function(ids) {
|
||||
var self = this,
|
||||
jobs = [],
|
||||
pubkeys = [];
|
||||
|
||||
ids.forEach(function(i) {
|
||||
// lookup locally and in storage
|
||||
var promise = self.lookupPublicKey(i._id).then(function(pubkey) {
|
||||
if (!pubkey) {
|
||||
throw new Error('Error looking up public key!');
|
||||
}
|
||||
|
||||
// check if public key with that id has already been fetched
|
||||
var already = _.findWhere(pubkeys, {
|
||||
_id: i._id
|
||||
});
|
||||
if (!already) {
|
||||
pubkeys.push(pubkey);
|
||||
}
|
||||
});
|
||||
jobs.push(promise);
|
||||
});
|
||||
|
||||
return Promise.all(jobs).then(function() {
|
||||
return pubkeys;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks for public key updates of a given user id
|
||||
* @param {String} options.userId The user id (email address) for which to check the key
|
||||
@ -191,7 +157,7 @@ Keychain.prototype.getReceiverPublicKey = function(userId) {
|
||||
var pubkey = _.findWhere(allPubkeys, {
|
||||
userId: userId
|
||||
});
|
||||
// query mutliple userIds (for imported public keys)
|
||||
// query mutliple userIds
|
||||
if (!pubkey) {
|
||||
for (var i = 0, match; i < allPubkeys.length; i++) {
|
||||
userIds = self._pgp.getKeyParams(allPubkeys[i].publicKey).userIds;
|
||||
@ -636,7 +602,7 @@ Keychain.prototype.getUserKeyPair = function(userId) {
|
||||
userId: userId
|
||||
});
|
||||
|
||||
if (pubkey && pubkey._id) {
|
||||
if (pubkey && pubkey._id && !pubkey.source) {
|
||||
// that user's public key is already in local storage...
|
||||
// sync keypair to the cloud
|
||||
return syncKeypair(pubkey._id);
|
||||
@ -645,13 +611,13 @@ Keychain.prototype.getUserKeyPair = function(userId) {
|
||||
// no public key by that user id in storage
|
||||
// find from cloud by email address
|
||||
return self._publicKeyDao.getByUserId(userId).then(function(cloudPubkey) {
|
||||
if (cloudPubkey && cloudPubkey._id) {
|
||||
if (cloudPubkey && cloudPubkey._id && !cloudPubkey.source) {
|
||||
// there is a public key for that user already in the cloud...
|
||||
// sync keypair to local storage
|
||||
return syncKeypair(cloudPubkey._id);
|
||||
}
|
||||
|
||||
// continue without keypair... generate in crypto.js
|
||||
// continue without keypair... generate or import new keypair
|
||||
});
|
||||
});
|
||||
|
||||
@ -660,10 +626,12 @@ Keychain.prototype.getUserKeyPair = function(userId) {
|
||||
// persist key pair in local storage
|
||||
return self.lookupPublicKey(keypairId).then(function(pub) {
|
||||
savedPubkey = pub;
|
||||
|
||||
// persist private key in local storage
|
||||
return self.lookupPrivateKey(keypairId).then(function(priv) {
|
||||
savedPrivkey = priv;
|
||||
});
|
||||
return self.lookupPrivateKey(keypairId);
|
||||
|
||||
}).then(function(priv) {
|
||||
savedPrivkey = priv;
|
||||
|
||||
}).then(function() {
|
||||
var keys = {};
|
||||
|
@ -417,45 +417,6 @@ describe('Keychain DAO unit tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('get public keys by id', function() {
|
||||
it('should fail', function(done) {
|
||||
keychainDao.getPublicKeys([]).then(function(keys) {
|
||||
expect(keys.length).to.equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail', function(done) {
|
||||
lawnchairDaoStub.read.returns(rejects(42));
|
||||
|
||||
var ids = [{
|
||||
_id: '12345'
|
||||
}];
|
||||
keychainDao.getPublicKeys(ids).catch(function(err) {
|
||||
expect(err).to.exist;
|
||||
expect(lawnchairDaoStub.read.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should work from local storage', function(done) {
|
||||
lawnchairDaoStub.read.returns(resolves({
|
||||
_id: '12345',
|
||||
publicKey: 'asdf'
|
||||
}));
|
||||
|
||||
var ids = [{
|
||||
_id: '12345'
|
||||
}];
|
||||
keychainDao.getPublicKeys(ids).then(function(keys) {
|
||||
expect(keys.length).to.equal(1);
|
||||
expect(keys[0]._id).to.equal('12345');
|
||||
expect(lawnchairDaoStub.read.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('get receiver public key', function() {
|
||||
it('should fail due to error in lawnchair list', function(done) {
|
||||
lawnchairDaoStub.list.returns(rejects(42));
|
||||
@ -598,6 +559,40 @@ describe('Keychain DAO unit tests', function() {
|
||||
expect(keys.privateKey).to.exist;
|
||||
expect(lawnchairDaoStub.list.calledOnce).to.be.true;
|
||||
expect(lawnchairDaoStub.read.calledTwice).to.be.true;
|
||||
expect(pubkeyDaoStub.getByUserId.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should work if local key is from a source other than the whiteout key server', function(done) {
|
||||
lawnchairDaoStub.list.returns(resolves([{
|
||||
_id: '12345',
|
||||
userId: testUser,
|
||||
publicKey: 'asdf',
|
||||
source: 'pgp.mit.edu'
|
||||
}]));
|
||||
pubkeyDaoStub.getByUserId.returns(resolves());
|
||||
|
||||
keychainDao.getUserKeyPair(testUser).then(function(keys) {
|
||||
expect(keys).to.not.exist;
|
||||
expect(lawnchairDaoStub.list.calledOnce).to.be.true;
|
||||
expect(lawnchairDaoStub.read.called).to.be.false;
|
||||
expect(pubkeyDaoStub.getByUserId.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should work if cloud public key is from a source other than the whiteout key server', function(done) {
|
||||
lawnchairDaoStub.list.returns(resolves());
|
||||
pubkeyDaoStub.getByUserId.returns(resolves({
|
||||
_id: '12345',
|
||||
publicKey: 'asdf',
|
||||
source: 'pgp.mit.edu'
|
||||
}));
|
||||
|
||||
keychainDao.getUserKeyPair(testUser).then(function(keys) {
|
||||
expect(keys).to.not.exist;
|
||||
expect(pubkeyDaoStub.getByUserId.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user