|
|
|
@ -86,7 +86,7 @@ var createLoginBlockPath = function (Env, publicKey) { // FIXME BLOCKS
|
|
|
|
|
return Path.join(Env.paths.block, safeKey.slice(0, 2), safeKey);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var validateAncestorProof = function (Env, proof, _cb) {
|
|
|
|
|
Block.validateAncestorProof = function (Env, proof, _cb) {
|
|
|
|
|
var cb = Util.once(Util.mkAsync(_cb));
|
|
|
|
|
/* prove that you own an existing block by signing for its publicKey */
|
|
|
|
|
try {
|
|
|
|
@ -97,7 +97,6 @@ var validateAncestorProof = function (Env, proof, _cb) {
|
|
|
|
|
var u8_sig = Nacl.util.decodeBase64(sig);
|
|
|
|
|
var valid = false;
|
|
|
|
|
nThen(function (w) {
|
|
|
|
|
// XXX restricted-registration do this in a worker
|
|
|
|
|
valid = Nacl.sign.detached.verify(u8_pub, u8_sig, u8_pub);
|
|
|
|
|
if (!valid) {
|
|
|
|
|
w.abort();
|
|
|
|
@ -130,14 +129,23 @@ Block.writeLoginBlock = function (Env, safeKey, msg, _cb) { // FIXME BLOCKS
|
|
|
|
|
|
|
|
|
|
var validatedBlock, parsed, path;
|
|
|
|
|
nThen(function (w) {
|
|
|
|
|
if (Util.escapeKeyCharacters(publicKey) !== safeKey) {
|
|
|
|
|
w.abort();
|
|
|
|
|
return void cb("INCORRECT_KEY");
|
|
|
|
|
}
|
|
|
|
|
}).nThen(function (w) {
|
|
|
|
|
if (!Env.restrictRegistration) { return; }
|
|
|
|
|
if (!registrationProof) {
|
|
|
|
|
// we allow users with existing blocks to create new ones
|
|
|
|
|
// call back with error if registration is restricted and no proof of an existing block was provided
|
|
|
|
|
w.abort();
|
|
|
|
|
Env.Log.info("BLOCK_REJECTED_REGISTRATION", {
|
|
|
|
|
safeKey: safeKey,
|
|
|
|
|
publicKey: publicKey,
|
|
|
|
|
});
|
|
|
|
|
return cb("E_RESTRICTED");
|
|
|
|
|
}
|
|
|
|
|
validateAncestorProof(Env, registrationProof, w(function (err, provenKey) {
|
|
|
|
|
Env.validateAncestorProof(registrationProof, w(function (err, provenKey) {
|
|
|
|
|
if (err || !provenKey) { // double check that a key was validated
|
|
|
|
|
w.abort();
|
|
|
|
|
Env.Log.warn('BLOCK_REJECTED_INVALID_ANCESTOR', {
|
|
|
|
@ -191,6 +199,7 @@ Block.writeLoginBlock = function (Env, safeKey, msg, _cb) { // FIXME BLOCKS
|
|
|
|
|
blockId: publicKey,
|
|
|
|
|
isChange: Boolean(registrationProof),
|
|
|
|
|
previousKey: previousKey,
|
|
|
|
|
path: path,
|
|
|
|
|
});
|
|
|
|
|
cb();
|
|
|
|
|
});
|
|
|
|
@ -212,26 +221,33 @@ Block.removeLoginBlock = function (Env, safeKey, msg, cb) { // FIXME BLOCKS
|
|
|
|
|
var signature = msg[1];
|
|
|
|
|
var block = Nacl.util.decodeUTF8('DELETE_BLOCK'); // clients and the server will have to agree on this constant
|
|
|
|
|
|
|
|
|
|
validateLoginBlock(Env, publicKey, signature, block, function (e /*::, validatedBlock */) {
|
|
|
|
|
if (e) { return void cb(e); }
|
|
|
|
|
// derive the filepath
|
|
|
|
|
var path = createLoginBlockPath(Env, publicKey);
|
|
|
|
|
|
|
|
|
|
// make sure the path is valid
|
|
|
|
|
if (typeof(path) !== 'string') {
|
|
|
|
|
return void cb('E_INVALID_BLOCK_PATH');
|
|
|
|
|
nThen(function (w) {
|
|
|
|
|
if (Util.escapeKeyCharacters(publicKey) !== safeKey) {
|
|
|
|
|
w.abort();
|
|
|
|
|
return void cb("INCORRECT_KEY");
|
|
|
|
|
}
|
|
|
|
|
}).nThen(function () {
|
|
|
|
|
validateLoginBlock(Env, publicKey, signature, block, function (e /*::, validatedBlock */) {
|
|
|
|
|
if (e) { return void cb(e); }
|
|
|
|
|
// derive the filepath
|
|
|
|
|
var path = createLoginBlockPath(Env, publicKey);
|
|
|
|
|
|
|
|
|
|
// FIXME COLDSTORAGE
|
|
|
|
|
Fs.unlink(path, function (err) {
|
|
|
|
|
Env.Log.info('DELETION_BLOCK_BY_OWNER_RPC', {
|
|
|
|
|
publicKey: publicKey,
|
|
|
|
|
path: path,
|
|
|
|
|
status: err? String(err): 'SUCCESS',
|
|
|
|
|
});
|
|
|
|
|
// make sure the path is valid
|
|
|
|
|
if (typeof(path) !== 'string') {
|
|
|
|
|
return void cb('E_INVALID_BLOCK_PATH');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (err) { return void cb(err); }
|
|
|
|
|
cb();
|
|
|
|
|
// FIXME COLDSTORAGE
|
|
|
|
|
Fs.unlink(path, function (err) {
|
|
|
|
|
Env.Log.info('DELETION_BLOCK_BY_OWNER_RPC', {
|
|
|
|
|
publicKey: publicKey,
|
|
|
|
|
path: path,
|
|
|
|
|
status: err? String(err): 'SUCCESS',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (err) { return void cb(err); }
|
|
|
|
|
cb();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|