add some logging and avoid some errors

This commit is contained in:
ansuz 2021-04-29 07:09:16 +05:30
parent b1e69e5c91
commit 15a8284a30
3 changed files with 17 additions and 9 deletions

View File

@ -112,7 +112,7 @@ var validateAncestorProof = function (Env, proof, _cb) {
return void cb("E_MISSING_ANCESTOR");
}));
}).nThen(function () {
cb(void 0, valid);
cb(void 0, pub);
});
} catch (err) {
return void cb(err);
@ -126,6 +126,7 @@ Block.writeLoginBlock = function (Env, safeKey, msg, _cb) { // FIXME BLOCKS
var signature = msg[1];
var block = msg[2];
var registrationProof = msg[3];
var previousKey;
var validatedBlock, parsed, path;
nThen(function (w) {
@ -136,13 +137,15 @@ Block.writeLoginBlock = function (Env, safeKey, msg, _cb) { // FIXME BLOCKS
w.abort();
return cb("E_RESTRICTED");
}
validateAncestorProof(Env, registrationProof, w(function (err, validated) {
if (err || !validated) { // double check that it was validated
validateAncestorProof(Env, registrationProof, w(function (err, provenKey) {
if (err || !provenKey) { // double check that a key was validated
w.abort();
// XXX Log
return void cb("E_RESTRICTED"); // XXX restricted-registration we can provide more descriptive errors if we check that the client will understand them
Env.Log.warn('BLOCK_REJECTED_INVALID_ANCESTOR', {
error: err,
});
return void cb("E_RESTRICTED");
}
// else fall through to the next block
previousKey = provenKey;
}));
}).nThen(function (w) {
validateLoginBlock(Env, publicKey, signature, block, w(function (e, _validatedBlock) {
@ -183,7 +186,12 @@ Block.writeLoginBlock = function (Env, safeKey, msg, _cb) { // FIXME BLOCKS
// actually write the block
Fs.writeFile(path, Buffer.from(validatedBlock), { encoding: "binary", }, function (err) {
if (err) { return void cb(err); }
// XXX log the safeKey to map publicKey <=> block
Env.Log.info('BLOCK_WRITE_BY_OWNER', {
safeKey: safeKey,
blockId: publicKey,
isChange: Boolean(registrationProof),
previousKey: previousKey,
});
cb();
});
});

View File

@ -276,7 +276,7 @@ var serveConfig = makeRouteCache(function (host) {
defaultStorageLimit: Env.defaultStorageLimit,
maxUploadSize: Env.maxUploadSize,
premiumUploadSize: Env.premiumUploadSize,
restrictRegistration: Env.restrictRegistration, // XXX restricted-registration
restrictRegistration: Env.restrictRegistration,
}, null, '\t'),
'obj.httpSafeOrigin = ' + (function () {
if (config.httpSafeOrigin) { return '"' + config.httpSafeOrigin + '"'; }

View File

@ -96,7 +96,7 @@ define([
// return an array with the sig and the pubkey
return JSON.stringify([u8_pub, u8_sig].map(Nacl.util.encodeBase64));
} catch (err) {
throw err; // XXX restricted-registration
return void console.error(err);
}
};