mirror of
https://github.com/moparisthebest/mail
synced 2024-11-29 12:22:22 -05:00
cleanup keychain dao
This commit is contained in:
parent
6224d01afd
commit
cb8df440f2
@ -16,8 +16,8 @@
|
|||||||
<script src="js/jqm-config.js"></script>
|
<script src="js/jqm-config.js"></script>
|
||||||
<script src="lib/jquery.mobile-1.2.0.min.js"></script>
|
<script src="lib/jquery.mobile-1.2.0.min.js"></script>
|
||||||
<script src="lib/lawnchair/lawnchair-git.min.js"></script>
|
<script src="lib/lawnchair/lawnchair-git.min.js"></script>
|
||||||
<script src="lib/lawnchair/lawnchair-adapter-indexed-db-git.js"></script>
|
|
||||||
<script src="lib/lawnchair/lawnchair-adapter-webkit-sqlite-git.js"></script>
|
<script src="lib/lawnchair/lawnchair-adapter-webkit-sqlite-git.js"></script>
|
||||||
|
<script src="lib/lawnchair/lawnchair-adapter-indexed-db-git.js"></script>
|
||||||
|
|
||||||
<script src="lib/forge/forge.rsa.bundle.js"></script>
|
<script src="lib/forge/forge.rsa.bundle.js"></script>
|
||||||
<script src="lib/uuid.js"></script>
|
<script src="lib/uuid.js"></script>
|
||||||
|
@ -50,31 +50,24 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
|||||||
* return [Object] The user's key pair {publicKey, privateKey}
|
* return [Object] The user's key pair {publicKey, privateKey}
|
||||||
*/
|
*/
|
||||||
this.getUserKeyPair = function(userId, callback) {
|
this.getUserKeyPair = function(userId, callback) {
|
||||||
// lookup public key id
|
// search for user's public key
|
||||||
jsonDao.read('publickey_' + userId, function(pubkeyId) {
|
jsonDao.list('publickey', 0, null, function(allPubkeys) {
|
||||||
if (!pubkeyId || !pubkeyId._id) {
|
var pubkey = _.findWhere(allPubkeys, {
|
||||||
// no public key by that id in storage
|
userId: userId
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!pubkey) {
|
||||||
|
// no public key by that user id in storage
|
||||||
// TODO: find from cloud
|
// TODO: find from cloud
|
||||||
// TODO: persist in local storage
|
// TODO: persist in local storage
|
||||||
callback();
|
callback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// lookup public key in storage and cloud
|
|
||||||
lookupPublicKey(pubkeyId._id, function(err, pubkey) {
|
|
||||||
if (err || !pubkey) {
|
|
||||||
callback({
|
|
||||||
errMsg: 'Error looking up public key!',
|
|
||||||
err: err
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// public key found
|
// public key found
|
||||||
// get corresponding private key
|
// get corresponding private key
|
||||||
fetchEncryptedPrivateKey(pubkey);
|
fetchEncryptedPrivateKey(pubkey);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
function fetchEncryptedPrivateKey(publicKey) {
|
function fetchEncryptedPrivateKey(publicKey) {
|
||||||
// try to read private key from local storage
|
// try to read private key from local storage
|
||||||
@ -210,10 +203,9 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
|||||||
|
|
||||||
function saveLocalPublicKey(pubkey, callback) {
|
function saveLocalPublicKey(pubkey, callback) {
|
||||||
// persist public key (email, _id)
|
// persist public key (email, _id)
|
||||||
var pkLookupKey = 'publickey_' + pubkey.userId;
|
var pkLookupKey = 'publickey_' + pubkey._id;
|
||||||
jsonDao.persist(pkLookupKey, {
|
|
||||||
_id: pubkey._id
|
jsonDao.persist(pkLookupKey, pubkey, function(res1) {
|
||||||
}, function(res1) {
|
|
||||||
// validate result
|
// validate result
|
||||||
if (res1.key !== pkLookupKey) {
|
if (res1.key !== pkLookupKey) {
|
||||||
callback({
|
callback({
|
||||||
@ -222,28 +214,15 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// persist public key in local storage
|
|
||||||
var pkKey = 'publickey_' + pubkey._id;
|
|
||||||
jsonDao.persist(pkKey, pubkey, function(res2) {
|
|
||||||
// validate result
|
|
||||||
if (res2.key !== pkKey) {
|
|
||||||
callback({
|
|
||||||
errMsg: 'Persisting public key in local storage went wrong!'
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveLocalPrivateKey(privkey, callback) {
|
function saveLocalPrivateKey(privkey, callback) {
|
||||||
// persist private key (email, _id)
|
// persist private key (email, _id)
|
||||||
var prkLookupKey = 'privatekey_' + privkey.userId;
|
var prkLookupKey = 'privatekey_' + privkey._id;
|
||||||
jsonDao.persist(prkLookupKey, {
|
|
||||||
_id: privkey._id
|
jsonDao.persist(prkLookupKey, privkey, function(res1) {
|
||||||
}, function(res1) {
|
|
||||||
// validate result
|
// validate result
|
||||||
if (res1.key !== prkLookupKey) {
|
if (res1.key !== prkLookupKey) {
|
||||||
callback({
|
callback({
|
||||||
@ -252,20 +231,8 @@ app.dao.KeychainDAO = function(jsonDao, cloudstorage) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// persist private key
|
|
||||||
var prkKey = 'privatekey_' + privkey._id;
|
|
||||||
jsonDao.persist(prkKey, privkey, function(res2) {
|
|
||||||
// validate result
|
|
||||||
if (res2.key !== prkKey) {
|
|
||||||
callback({
|
|
||||||
errMsg: 'Persisting private key in local storage went wrong!'
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
@ -21,8 +21,8 @@
|
|||||||
<script src="../../src/lib/underscore-1.4.4.min.js"></script>
|
<script src="../../src/lib/underscore-1.4.4.min.js"></script>
|
||||||
<script src="../../src/lib/backbone-1.0.0.min.js"></script>
|
<script src="../../src/lib/backbone-1.0.0.min.js"></script>
|
||||||
<script src="../../src/lib/lawnchair/lawnchair-git.min.js"></script>
|
<script src="../../src/lib/lawnchair/lawnchair-git.min.js"></script>
|
||||||
<script src="../../src/lib/lawnchair/lawnchair-adapter-indexed-db-git.js"></script>
|
|
||||||
<script src="../../src/lib/lawnchair/lawnchair-adapter-webkit-sqlite-git.js"></script>
|
<script src="../../src/lib/lawnchair/lawnchair-adapter-webkit-sqlite-git.js"></script>
|
||||||
|
<script src="../../src/lib/lawnchair/lawnchair-adapter-indexed-db-git.js"></script>
|
||||||
|
|
||||||
<script src="../../src/lib/forge/forge.rsa.bundle.js"></script>
|
<script src="../../src/lib/forge/forge.rsa.bundle.js"></script>
|
||||||
<script src="../../src/lib/uuid.js"></script>
|
<script src="../../src/lib/uuid.js"></script>
|
||||||
|
Loading…
Reference in New Issue
Block a user