WIP maybe I missed something
This commit is contained in:
parent
0a9ea95796
commit
54bc29f28c
@ -72,6 +72,7 @@ define([
|
|||||||
|
|
||||||
opt.channel64 = Util.hexToBase64(channelHex);
|
opt.channel64 = Util.hexToBase64(channelHex);
|
||||||
|
|
||||||
|
// XXX why don't we generate a v2 ?
|
||||||
opt.userHash = '/1/edit/' + [opt.channel64, opt.keys.editKeyStr].join('/') + '/';
|
opt.userHash = '/1/edit/' + [opt.channel64, opt.keys.editKeyStr].join('/') + '/';
|
||||||
|
|
||||||
return opt;
|
return opt;
|
||||||
@ -90,6 +91,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var loadUserObject = function (opt, cb) {
|
var loadUserObject = function (opt, cb) {
|
||||||
|
console.log(opt);
|
||||||
var config = {
|
var config = {
|
||||||
websocketURL: NetConfig.getWebsocketURL(),
|
websocketURL: NetConfig.getWebsocketURL(),
|
||||||
channel: opt.channelHex,
|
channel: opt.channelHex,
|
||||||
@ -102,6 +104,8 @@ define([
|
|||||||
owners: [opt.edPublic]
|
owners: [opt.edPublic]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log(config);
|
||||||
|
|
||||||
var rt = opt.rt = Listmap.create(config);
|
var rt = opt.rt = Listmap.create(config);
|
||||||
rt.proxy
|
rt.proxy
|
||||||
.on('ready', function () {
|
.on('ready', function () {
|
||||||
@ -178,6 +182,8 @@ define([
|
|||||||
console.error("Found a login block but failed to decrypt");
|
console.error("Found a login block but failed to decrypt");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.error(decryptedBlock);
|
||||||
res.blockInfo = decryptedBlock;
|
res.blockInfo = decryptedBlock;
|
||||||
}));
|
}));
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
@ -253,11 +259,12 @@ define([
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
}).nThen(function (waitFor) { // MODERN REGISTRATION
|
}).nThen(function (waitFor) { // MODERN REGISTRATION / LOGIN
|
||||||
var opt;
|
var opt;
|
||||||
if (res.blockInfo) {
|
if (res.blockInfo) {
|
||||||
opt = loginOptionsFromBlock(res.blockInfo);
|
opt = loginOptionsFromBlock(res.blockInfo);
|
||||||
userHash = res.blockInfo.User_hash;
|
userHash = res.blockInfo.User_hash;
|
||||||
|
console.error(opt, userHash);
|
||||||
} else {
|
} else {
|
||||||
console.log("allocating random bytes for a new user object");
|
console.log("allocating random bytes for a new user object");
|
||||||
opt = allocateBytes(Nacl.randomBytes(Exports.requiredBytes));
|
opt = allocateBytes(Nacl.randomBytes(Exports.requiredBytes));
|
||||||
@ -271,6 +278,8 @@ define([
|
|||||||
return void cb('MODERN_REGISTRATION_INIT');
|
return void cb('MODERN_REGISTRATION_INIT');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.error(JSON.stringify(rt.proxy));
|
||||||
|
|
||||||
// export the realtime object you checked
|
// export the realtime object you checked
|
||||||
RT = rt;
|
RT = rt;
|
||||||
|
|
||||||
|
|||||||
@ -724,6 +724,7 @@ define([
|
|||||||
|
|
||||||
var Cred, Block, Login;
|
var Cred, Block, Login;
|
||||||
Nthen(function (waitFor) {
|
Nthen(function (waitFor) {
|
||||||
|
console.log("loading necessary modules");
|
||||||
require([
|
require([
|
||||||
'/customize/credential.js',
|
'/customize/credential.js',
|
||||||
'/common/outer/login-block.js',
|
'/common/outer/login-block.js',
|
||||||
@ -735,11 +736,13 @@ define([
|
|||||||
}));
|
}));
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
// confirm that the provided password is correct
|
// confirm that the provided password is correct
|
||||||
|
console.log("checking whether the password you entered was correct");
|
||||||
Cred.deriveFromPassphrase(accountName, password, Login.requiredBytes, waitFor(function (bytes) {
|
Cred.deriveFromPassphrase(accountName, password, Login.requiredBytes, waitFor(function (bytes) {
|
||||||
var allocated = Login.allocateBytes(bytes);
|
var allocated = Login.allocateBytes(bytes);
|
||||||
oldBlockKeys = allocated.blockKeys;
|
oldBlockKeys = allocated.blockKeys;
|
||||||
if (blockHash) {
|
if (blockHash) {
|
||||||
if (blockHash !== allocated.blockHash) {
|
if (blockHash !== allocated.blockHash) {
|
||||||
|
console.log("password did not yield the correct blockHash ?");
|
||||||
// incorrect password probably
|
// incorrect password probably
|
||||||
waitFor.abort();
|
waitFor.abort();
|
||||||
return void cb({
|
return void cb({
|
||||||
@ -750,6 +753,7 @@ define([
|
|||||||
} else {
|
} else {
|
||||||
// otherwise they're a legacy user, and we should check against the User_hash
|
// otherwise they're a legacy user, and we should check against the User_hash
|
||||||
if (hash !== allocated.userHash) {
|
if (hash !== allocated.userHash) {
|
||||||
|
console.log("password did not yield the correct userHash");
|
||||||
waitFor.abort();
|
waitFor.abort();
|
||||||
return void cb({
|
return void cb({
|
||||||
error: 'INVALID_PASSWORD',
|
error: 'INVALID_PASSWORD',
|
||||||
@ -759,6 +763,7 @@ define([
|
|||||||
}));
|
}));
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
// Check if our drive is already owned
|
// Check if our drive is already owned
|
||||||
|
console.log("checking if old drive is owned");
|
||||||
common.anonRpcMsg('GET_METADATA', secret.channel, waitFor(function (err, obj) {
|
common.anonRpcMsg('GET_METADATA', secret.channel, waitFor(function (err, obj) {
|
||||||
if (err || obj.error) { return; }
|
if (err || obj.error) { return; }
|
||||||
if (obj.owners && Array.isArray(obj.owners) &&
|
if (obj.owners && Array.isArray(obj.owners) &&
|
||||||
@ -778,21 +783,38 @@ define([
|
|||||||
owners: [edPublic]
|
owners: [edPublic]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log("copying contents of old drive to new location");
|
||||||
Crypt.get(hash, waitFor(function (err, val) {
|
Crypt.get(hash, waitFor(function (err, val) {
|
||||||
if (err) {
|
if (err) {
|
||||||
waitFor.abort();
|
waitFor.abort();
|
||||||
return void cb({ error: err });
|
return void cb({ error: err });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(val);
|
||||||
|
console.log("%s => %s", hash, newHash);
|
||||||
Crypt.put(newHash, val, waitFor(function (err) {
|
Crypt.put(newHash, val, waitFor(function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
waitFor.abort();
|
waitFor.abort();
|
||||||
|
console.error(err);
|
||||||
return void cb({ error: err });
|
return void cb({ error: err });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
console.error('checking content at newHash: %s', newHash);
|
||||||
|
|
||||||
|
Crypt.get(newHash, function (err, val) {
|
||||||
|
if (err) {
|
||||||
|
waitFor.abort();
|
||||||
|
console.log(err);
|
||||||
|
return void cb({ error: err });
|
||||||
|
}
|
||||||
|
console.error(val);
|
||||||
|
});
|
||||||
}), optsPut);
|
}), optsPut);
|
||||||
}));
|
}));
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
// Drive content copied: get the new block location
|
// Drive content copied: get the new block location
|
||||||
|
console.log("deriving new credentials from passphrase");
|
||||||
Cred.deriveFromPassphrase(accountName, newPassword, Login.requiredBytes, waitFor(function (bytes) {
|
Cred.deriveFromPassphrase(accountName, newPassword, Login.requiredBytes, waitFor(function (bytes) {
|
||||||
var allocated = Login.allocateBytes(bytes);
|
var allocated = Login.allocateBytes(bytes);
|
||||||
newBlockSeed = allocated.blockSeed;
|
newBlockSeed = allocated.blockSeed;
|
||||||
@ -800,14 +822,19 @@ define([
|
|||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
// Write the new login block
|
// Write the new login block
|
||||||
var keys = Block.genkeys(newBlockSeed);
|
var keys = Block.genkeys(newBlockSeed);
|
||||||
var content = Block.serialize(JSON.stringify({
|
|
||||||
|
var temp = {
|
||||||
User_name: accountName,
|
User_name: accountName,
|
||||||
User_hash: newHash,
|
User_hash: newHash,
|
||||||
edPublic: edPublic,
|
edPublic: edPublic,
|
||||||
// edPrivate XXX
|
// edPrivate XXX
|
||||||
}), keys);
|
};
|
||||||
|
|
||||||
|
var content = Block.serialize(JSON.stringify(temp), keys);
|
||||||
|
|
||||||
|
console.log("writing new login block");
|
||||||
common.writeLoginBlock(content, waitFor(function (obj) {
|
common.writeLoginBlock(content, waitFor(function (obj) {
|
||||||
|
console.log("new login block written");
|
||||||
var newBlockHash = Block.getBlockHash(keys);
|
var newBlockHash = Block.getBlockHash(keys);
|
||||||
LocalStore.setBlockHash(newBlockHash);
|
LocalStore.setBlockHash(newBlockHash);
|
||||||
if (obj && obj.error) {
|
if (obj && obj.error) {
|
||||||
@ -817,11 +844,13 @@ define([
|
|||||||
}));
|
}));
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
// New drive hash is in login block, unpin the old one and pin the new one
|
// New drive hash is in login block, unpin the old one and pin the new one
|
||||||
|
console.log("unpinning old drive and pinning new one");
|
||||||
common.unpinPads([secret.channel], waitFor());
|
common.unpinPads([secret.channel], waitFor());
|
||||||
common.pinPads([newSecret.channel], waitFor());
|
common.pinPads([newSecret.channel], waitFor());
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
// Remove block hash
|
// Remove block hash
|
||||||
if (blockHash) {
|
if (blockHash) {
|
||||||
|
console.log('removing old login block');
|
||||||
var removeData = Block.remove(oldBlockKeys);
|
var removeData = Block.remove(oldBlockKeys);
|
||||||
common.removeLoginBlock(removeData, waitFor(function (obj) {
|
common.removeLoginBlock(removeData, waitFor(function (obj) {
|
||||||
if (obj && obj.error) { return void console.error(obj.error); }
|
if (obj && obj.error) { return void console.error(obj.error); }
|
||||||
@ -829,6 +858,7 @@ define([
|
|||||||
}
|
}
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
if (oldIsOwned) {
|
if (oldIsOwned) {
|
||||||
|
console.log('removing old drive');
|
||||||
common.removeOwnedChannel(secret.channel, waitFor(function (obj) {
|
common.removeOwnedChannel(secret.channel, waitFor(function (obj) {
|
||||||
if (obj && obj.error) {
|
if (obj && obj.error) {
|
||||||
// Deal with it as if it was not owned
|
// Deal with it as if it was not owned
|
||||||
@ -842,6 +872,7 @@ define([
|
|||||||
}
|
}
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
if (!oldIsOwned) {
|
if (!oldIsOwned) {
|
||||||
|
console.error('deprecating old drive.');
|
||||||
postMessage("SET", {
|
postMessage("SET", {
|
||||||
key: [Constants.deprecatedKey],
|
key: [Constants.deprecatedKey],
|
||||||
value: true
|
value: true
|
||||||
@ -855,6 +886,8 @@ define([
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}).nThen(function () {
|
}).nThen(function () {
|
||||||
|
console.error('done ?');
|
||||||
|
return;
|
||||||
// We have the new drive, with the new login block
|
// We have the new drive, with the new login block
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user