[FEATURE] vault client: create encrypted blob decrypt key if missing

if the key is missing, upon login the key will be automatically
generated and saved to the blobvault.
This commit is contained in:
Matthew Fettig
2014-06-17 13:20:28 -07:00
parent e50ddd6237
commit dc62dbe022
2 changed files with 37 additions and 4 deletions

View File

@@ -102,10 +102,11 @@ BlobObj.prototype.init = function(fn) {
if (err || !resp.body || resp.body.result !== 'success') {
return fn(new Error('Could not retrieve blob'));
}
self.revision = resp.body.revision;
self.revision = resp.body.revision;
self.encrypted_secret = resp.body.encrypted_secret;
self.missing_fields = resp.body.missing_fields;
if (!self.decrypt(resp.body.blob)) {
return fn(new Error('Error while decrypting blob'));
}

View File

@@ -145,6 +145,38 @@ VaultClient.prototype.login = function(username, password, callback) {
//save for relogin
self.infos[keys.id] = authInfo;
//migrate missing fields
if (blob.missing_fields) {
if (blob.missing_fields.encrypted_blobdecrypt_key) {
console.log("migration: saving encrypted blob decrypt key");
self._deriveUnlockKey(authInfo, password, {}, function(err, authInfo, unlock) {
if (unlock.unlock) {
var secret;
try {
secret = crypt.decrypt(unlock.unlock, blob.encrypted_secret);
} catch (error) {
return console.log(error);
}
options = {
username : authInfo.username.toLowerCase(),
blob : blob,
masterkey : secret,
keys : {
id : keys.id,
crypt : keys.crypt,
unlock : unlock.unlock
}
};
blobClient.updateKeys(options, function(err, resp){
console.log(err, resp);
});
}
});
}
}
callback(null, {
blob : blob,
username : authInfo.username,
@@ -474,7 +506,7 @@ VaultClient.prototype.register = function(options, fn) {
function getAuthInfo(callback) {
self.getAuthInfo(username, function(err, authInfo){
if (!authInfo.username) authInfo.username = username;
return callback (err, authInfo, password);
});
};