now authenticating sockets by checking the password hash
This commit is contained in:
@ -69,10 +69,10 @@ export class SocketConnection {
|
||||
*/
|
||||
authenticate() {
|
||||
let done = plugins.q.defer();
|
||||
this.socket.on("dataAuth", dataArg => {
|
||||
this.socket.on("dataAuth", (dataArg:ISocketConnectionAuthenticationObject) => {
|
||||
plugins.beautylog.log("received authentication data. now hashing and comparing...");
|
||||
this.socket.removeListener("dataAuth", () => { });
|
||||
if ((true)) { // TODO: authenticate password
|
||||
if (helpers.checkPasswordForRole(dataArg)) { // TODO: authenticate password
|
||||
this.alias = dataArg.alias
|
||||
this.authenticated = true;
|
||||
this.role = helpers.getSocketRoleByName(dataArg.role);
|
||||
|
@ -3,12 +3,20 @@ import * as plugins from "./smartsocket.plugins";
|
||||
// classes
|
||||
import { Smartsocket } from "./smartsocket.classes.smartsocket";
|
||||
import { SocketFunction, allSocketFunctions } from "./smartsocket.classes.socketfunction";
|
||||
import { SocketConnection } from "./smartsocket.classes.socketconnection";
|
||||
import { SocketConnection, ISocketConnectionAuthenticationObject } from "./smartsocket.classes.socketconnection";
|
||||
import { SocketRequest, allSocketRequests, TSocketRequestSide } from "./smartsocket.classes.socketrequest";
|
||||
import { SocketRole, allSocketRoles } from "./smartsocket.classes.socketrole";
|
||||
|
||||
// SocketConnection helpers
|
||||
export let checkPasswordForRole = (dataArg: ISocketConnectionAuthenticationObject): boolean => {
|
||||
let targetPasswordHash = getSocketRoleByName(dataArg.role).passwordHash;
|
||||
let computedCompareHash = plugins.nodehash.sha256FromStringSync(dataArg.password);
|
||||
return targetPasswordHash === computedCompareHash;
|
||||
}
|
||||
|
||||
|
||||
// SocketFunction helpers
|
||||
export let getSocketFunctionByName = (functionNameArg: string):SocketFunction => {
|
||||
export let getSocketFunctionByName = (functionNameArg: string): SocketFunction => {
|
||||
return allSocketFunctions.find((socketFunctionArg) => { return socketFunctionArg.name === functionNameArg });
|
||||
}
|
||||
|
||||
@ -17,8 +25,8 @@ export let getSocketFunctionByName = (functionNameArg: string):SocketFunction =>
|
||||
/**
|
||||
* get corresponding Socketrequest instance by shortId
|
||||
*/
|
||||
export let getSocketRequestById = (shortIdArg:string,requestSide?:TSocketRequestSide):SocketRequest => {
|
||||
return allSocketRequests.find((socketRequestArg) => {return socketRequestArg.shortid === shortIdArg})
|
||||
export let getSocketRequestById = (shortIdArg: string, requestSide?: TSocketRequestSide): SocketRequest => {
|
||||
return allSocketRequests.find((socketRequestArg) => { return socketRequestArg.shortid === shortIdArg })
|
||||
}
|
||||
|
||||
// SocketRole helpers
|
||||
|
@ -1,6 +1,7 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export import lik = require("lik");
|
||||
export import nodehash = require("nodehash");
|
||||
export import q = require("q");
|
||||
export import shortid = require("shortid");
|
||||
export import socketIo = require("socket.io");
|
||||
|
Reference in New Issue
Block a user