Require auth key for node registration
This commit is contained in:
1
.env.example
Normal file
1
.env.example
Normal file
@@ -0,0 +1 @@
|
||||
NODE_AUTH_KEY=ay1234
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
.env
|
||||
node_modules
|
||||
|
||||
17
package-lock.json
generated
17
package-lock.json
generated
@@ -10,6 +10,7 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^1.2.2",
|
||||
"dotenv": "^16.1.4",
|
||||
"express": "^4.18.2",
|
||||
"uuid": "^9.0.0",
|
||||
"ws": "^8.13.0"
|
||||
@@ -258,6 +259,17 @@
|
||||
"npm": "1.2.8000 || >= 1.4.16"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.1.4",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.1.4.tgz",
|
||||
"integrity": "sha512-m55RtE8AsPeJBpOIFKihEmqUcoVncQIwo7x9U8ZwLEZw9ZpXboz2c+rvog+jUaJvVrZ5kBOeYQBX5+8Aa/OZQw==",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/motdotla/dotenv?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/ee-first": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
||||
@@ -1245,6 +1257,11 @@
|
||||
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
|
||||
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg=="
|
||||
},
|
||||
"dotenv": {
|
||||
"version": "16.1.4",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.1.4.tgz",
|
||||
"integrity": "sha512-m55RtE8AsPeJBpOIFKihEmqUcoVncQIwo7x9U8ZwLEZw9ZpXboz2c+rvog+jUaJvVrZ5kBOeYQBX5+8Aa/OZQw=="
|
||||
},
|
||||
"ee-first": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^1.2.2",
|
||||
"dotenv": "^16.1.4",
|
||||
"express": "^4.18.2",
|
||||
"uuid": "^9.0.0",
|
||||
"ws": "^8.13.0"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
require('dotenv').config()
|
||||
const express = require("express");
|
||||
var crypto = require('crypto');
|
||||
const { finished } = require("stream");
|
||||
@@ -82,6 +83,11 @@ wss.on('connection', function connection(ws) {
|
||||
console.log('received: %s', data);
|
||||
|
||||
if(request["register"]){
|
||||
if(request["register"]["auth_key"] !== process.env.NODE_AUTH_KEY) {
|
||||
console.log("INVALID AUTH KEY. Disconnecting ", nodeID);
|
||||
ws.close(4000, "Invalid auth key");
|
||||
return;
|
||||
}
|
||||
ws.send(JSON.stringify({"welcome": { "clientId": nodeID }}));
|
||||
console.log("Node registered", nodeID);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user