semi-functional allow-list implementation in historyKeeper
This commit is contained in:
11
lib/rpc.js
11
lib/rpc.js
@@ -9,6 +9,7 @@ const Block = require("./commands/block");
|
||||
const Metadata = require("./commands/metadata");
|
||||
const Channel = require("./commands/channel");
|
||||
const Upload = require("./commands/upload");
|
||||
const HK = require("./hk-util");
|
||||
|
||||
var RPC = module.exports;
|
||||
|
||||
@@ -117,7 +118,7 @@ var handleAuthenticatedMessage = function (Env, unsafeKey, msg, respond, Server)
|
||||
return void Respond('UNSUPPORTED_RPC_CALL', msg);
|
||||
};
|
||||
|
||||
var rpc = function (Env, Server, data, respond) {
|
||||
var rpc = function (Env, Server, userId, data, respond) {
|
||||
if (!Array.isArray(data)) {
|
||||
Env.Log.debug('INVALID_ARG_FORMET', data);
|
||||
return void respond('INVALID_ARG_FORMAT');
|
||||
@@ -143,8 +144,9 @@ var rpc = function (Env, Server, data, respond) {
|
||||
var publicKey = msg.shift();
|
||||
|
||||
// make sure a user object is initialized in the cookie jar
|
||||
var session;
|
||||
if (publicKey) {
|
||||
Core.getSession(Env.Sessions, publicKey);
|
||||
session = Core.getSession(Env.Sessions, publicKey);
|
||||
} else {
|
||||
Env.Log.debug("NO_PUBLIC_KEY_PROVIDED", publicKey);
|
||||
}
|
||||
@@ -174,6 +176,7 @@ var rpc = function (Env, Server, data, respond) {
|
||||
// check the signature on the message
|
||||
// refuse the command if it doesn't validate
|
||||
if (Core.checkSignature(Env, serialized, signature, publicKey) === true) {
|
||||
HK.authenticateNetfluxSession(Env, userId, publicKey);
|
||||
return void handleAuthenticatedMessage(Env, publicKey, msg, respond, Server);
|
||||
}
|
||||
return void respond("INVALID_SIGNATURE_OR_PUBLIC_KEY");
|
||||
@@ -202,9 +205,9 @@ RPC.create = function (Env, cb) {
|
||||
Core.expireSessions(Sessions);
|
||||
}, Core.SESSION_EXPIRATION_TIME);
|
||||
|
||||
cb(void 0, function (Server, data, respond) {
|
||||
cb(void 0, function (Server, userId, data, respond) {
|
||||
try {
|
||||
return rpc(Env, Server, data, respond);
|
||||
return rpc(Env, Server, userId, data, respond);
|
||||
} catch (e) {
|
||||
console.log("Error from RPC with data " + JSON.stringify(data));
|
||||
console.log(e.stack);
|
||||
|
||||
Reference in New Issue
Block a user