mirror of
https://github.com/moparisthebest/mail
synced 2024-11-25 18:32:20 -05:00
WIP: started refactoring keychain
This commit is contained in:
parent
26553e49d7
commit
a80169ebe2
@ -54,8 +54,8 @@ Keychain.prototype.requestPermissionForKeyUpdate = function(params, callback) {
|
|||||||
* @param {String} uuid The uuid to verify the key
|
* @param {String} uuid The uuid to verify the key
|
||||||
* @param {Function} callback(error) Callback with an optional error object when the verification is done. If the was an error, the error object contains the information for it.
|
* @param {Function} callback(error) Callback with an optional error object when the verification is done. If the was an error, the error object contains the information for it.
|
||||||
*/
|
*/
|
||||||
Keychain.prototype.verifyPublicKey = function(uuid, callback) {
|
Keychain.prototype.verifyPublicKey = function(uuid) {
|
||||||
this._publicKeyDao.verify(uuid, callback);
|
return this._publicKeyDao.verify(uuid);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -901,43 +901,26 @@ Keychain.prototype.putUserKeyPair = function(keypair, callback) {
|
|||||||
// Helper functions
|
// Helper functions
|
||||||
//
|
//
|
||||||
|
|
||||||
Keychain.prototype.lookupPublicKey = function(id, callback) {
|
Keychain.prototype.lookupPublicKey = function(id) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (!id) {
|
if (!id) {
|
||||||
callback({
|
return new Promise(function() {
|
||||||
errMsg: 'ID must be set for public key query!'
|
throw new Error('ID must be set for public key query!');
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// lookup in local storage
|
// lookup in local storage
|
||||||
self._lawnchairDAO.read(DB_PUBLICKEY + '_' + id, function(err, pubkey) {
|
return self._lawnchairDAO.read(DB_PUBLICKEY + '_' + id).then(function(pubkey) {
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pubkey) {
|
if (pubkey) {
|
||||||
callback(null, pubkey);
|
return pubkey;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch from cloud storage
|
// fetch from cloud storage
|
||||||
self._publicKeyDao.get(id, function(err, cloudPubkey) {
|
return self._publicKeyDao.get(id).then(function(cloudPubkey) {
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// cache public key in cache
|
// cache public key in cache
|
||||||
self.saveLocalPublicKey(cloudPubkey, function(err) {
|
return self.saveLocalPublicKey(cloudPubkey).then(function() {
|
||||||
if (err) {
|
return cloudPubkey;
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null, cloudPubkey);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -946,28 +929,28 @@ Keychain.prototype.lookupPublicKey = function(id, callback) {
|
|||||||
/**
|
/**
|
||||||
* List all the locally stored public keys
|
* List all the locally stored public keys
|
||||||
*/
|
*/
|
||||||
Keychain.prototype.listLocalPublicKeys = function(callback) {
|
Keychain.prototype.listLocalPublicKeys = function() {
|
||||||
// search local keyring for public key
|
// search local keyring for public key
|
||||||
this._lawnchairDAO.list(DB_PUBLICKEY, 0, null, callback);
|
return this._lawnchairDAO.list(DB_PUBLICKEY, 0, null);
|
||||||
};
|
};
|
||||||
|
|
||||||
Keychain.prototype.removeLocalPublicKey = function(id, callback) {
|
Keychain.prototype.removeLocalPublicKey = function(id) {
|
||||||
this._lawnchairDAO.remove(DB_PUBLICKEY + '_' + id, callback);
|
return this._lawnchairDAO.remove(DB_PUBLICKEY + '_' + id);
|
||||||
};
|
};
|
||||||
|
|
||||||
Keychain.prototype.lookupPrivateKey = function(id, callback) {
|
Keychain.prototype.lookupPrivateKey = function(id) {
|
||||||
// lookup in local storage
|
// lookup in local storage
|
||||||
this._lawnchairDAO.read(DB_PRIVATEKEY + '_' + id, callback);
|
return this._lawnchairDAO.read(DB_PRIVATEKEY + '_' + id);
|
||||||
};
|
};
|
||||||
|
|
||||||
Keychain.prototype.saveLocalPublicKey = function(pubkey, callback) {
|
Keychain.prototype.saveLocalPublicKey = function(pubkey) {
|
||||||
// persist public key (email, _id)
|
// persist public key (email, _id)
|
||||||
var pkLookupKey = DB_PUBLICKEY + '_' + pubkey._id;
|
var pkLookupKey = DB_PUBLICKEY + '_' + pubkey._id;
|
||||||
this._lawnchairDAO.persist(pkLookupKey, pubkey, callback);
|
return this._lawnchairDAO.persist(pkLookupKey, pubkey);
|
||||||
};
|
};
|
||||||
|
|
||||||
Keychain.prototype.saveLocalPrivateKey = function(privkey, callback) {
|
Keychain.prototype.saveLocalPrivateKey = function(privkey) {
|
||||||
// persist private key (email, _id)
|
// persist private key (email, _id)
|
||||||
var prkLookupKey = DB_PRIVATEKEY + '_' + privkey._id;
|
var prkLookupKey = DB_PRIVATEKEY + '_' + privkey._id;
|
||||||
this._lawnchairDAO.persist(prkLookupKey, privkey, callback);
|
return this._lawnchairDAO.persist(prkLookupKey, privkey);
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user