Skip to content

Commit ce83149

Browse files
committed
Fix port and key mapping in modered
1 parent a3b6c4f commit ce83149

9 files changed

Lines changed: 47 additions & 31 deletions

File tree

OpenFlowNodeRED/src/Config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class Config {
1414
public static saml_crt: string = Config.getEnv("saml_crt", "");
1515

1616
public static port: number = parseInt(Config.getEnv("port", "1880"));
17-
public static nodered_port: number = parseInt(Config.getEnv("port", "0"));
17+
public static nodered_port: number = parseInt(Config.getEnv("nodered_port", "0"));
1818
public static domain: string = Config.getEnv("domain", "localhost");
1919
public static protocol: string = Config.getEnv("protocol", "http");
2020
public static nodered_domain_schema: string = Config.getEnv("nodered_domain_schema", "");

OpenFlowNodeRED/src/Crypt.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,42 @@
11
import * as crypto from "crypto";
2-
import * as bcrypt from "bcryptjs";
2+
import * as bcrypt from "bcryptjs";
33
import * as jsonwebtoken from "jsonwebtoken";
44
import { Config } from "./Config";
55
import { TokenUser } from "./Message";
66

77
export class Crypt {
8-
static encryption_key:string = Config.aes_secret.substr(0,32); // must be 256 bytes (32 characters)
9-
static iv_length:number = 16; // for AES, this is always 16
10-
static bcrypt_salt_rounds:number = 12;
8+
// static encryption_key:string = Config.aes_secret.substr(0,32); // must be 256 bytes (32 characters)
9+
static iv_length: number = 16; // for AES, this is always 16
10+
static bcrypt_salt_rounds: number = 12;
1111

12-
static encrypt(text:string):string {
13-
let iv:Buffer = crypto.randomBytes(Crypt.iv_length);
14-
let cipher:crypto.Cipher = crypto.createCipheriv("aes-256-cbc", Buffer.from(Crypt.encryption_key), iv);
15-
let encrypted:Buffer = cipher.update((text as any));
12+
static encryption_key(): string {
13+
var c = Config;
14+
return c.aes_secret.substr(0, 32);
15+
}
16+
17+
static encrypt(text: string): string {
18+
let iv: Buffer = crypto.randomBytes(Crypt.iv_length);
19+
let cipher: crypto.Cipher = crypto.createCipheriv("aes-256-cbc", Buffer.from(Crypt.encryption_key()), iv);
20+
let encrypted: Buffer = cipher.update((text as any));
1621
encrypted = Buffer.concat([encrypted, cipher.final()]);
1722
return iv.toString("hex") + ":" + encrypted.toString("hex");
1823
}
1924

20-
static decrypt(text:string):string {
21-
let textParts:string[] = text.split(":");
22-
let iv:Buffer = Buffer.from(textParts.shift(), "hex");
23-
let encryptedText:Buffer = Buffer.from(textParts.join(":"), "hex");
24-
let decipher:crypto.Decipher = crypto.createDecipheriv("aes-256-cbc", Buffer.from(Crypt.encryption_key), iv);
25-
let decrypted:Buffer = decipher.update(encryptedText);
25+
static decrypt(text: string): string {
26+
let textParts: string[] = text.split(":");
27+
let iv: Buffer = Buffer.from(textParts.shift(), "hex");
28+
let encryptedText: Buffer = Buffer.from(textParts.join(":"), "hex");
29+
let decipher: crypto.Decipher = crypto.createDecipheriv("aes-256-cbc", Buffer.from(Crypt.encryption_key()), iv);
30+
let decrypted: Buffer = decipher.update(encryptedText);
2631
decrypted = Buffer.concat([decrypted, decipher.final()]);
2732
return decrypted.toString();
2833
}
2934

30-
static async hash(password: string):Promise<string> {
35+
static async hash(password: string): Promise<string> {
3136
return new Promise<string>(async (resolve, reject) => {
3237
try {
33-
bcrypt.hash(password, Crypt.bcrypt_salt_rounds, async (error, hash)=> {
34-
if(error) { return reject(error); }
38+
bcrypt.hash(password, Crypt.bcrypt_salt_rounds, async (error, hash) => {
39+
if (error) { return reject(error); }
3540
resolve(hash);
3641
});
3742
} catch (error) {
@@ -40,11 +45,11 @@ export class Crypt {
4045
});
4146
}
4247

43-
static async compare(password: string, passwordhash:string):Promise<boolean> {
48+
static async compare(password: string, passwordhash: string): Promise<boolean> {
4449
return new Promise<boolean>(async (resolve, reject) => {
4550
try {
46-
bcrypt.compare(password, passwordhash, async (error, res)=> {
47-
if(error) { return reject(error); }
51+
bcrypt.compare(password, passwordhash, async (error, res) => {
52+
if (error) { return reject(error); }
4853
resolve(res);
4954
});
5055
} catch (error) {
@@ -54,13 +59,13 @@ export class Crypt {
5459
}
5560

5661
static createToken(user: TokenUser): string {
57-
var token:string = jsonwebtoken.sign({ data: user }, Crypt.encryption_key,
62+
var token: string = jsonwebtoken.sign({ data: user }, Crypt.encryption_key(),
5863
{ expiresIn: "1h" }); // 60 (seconds), "2 days", "10h", "7d"
5964
return token;
6065
}
6166

6267
static verityToken(token: string): TokenUser {
63-
var o:any = jsonwebtoken.verify(token, Crypt.encryption_key);
68+
var o: any = jsonwebtoken.verify(token, Crypt.encryption_key());
6469
o.data = TokenUser.assign(o.data);
6570
return o.data;
6671
}

OpenFlowNodeRED/src/WebServer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ export class WebServer {
104104
});
105105

106106
this.settings = new nodered_settings();
107+
var c = Config;
108+
if (Config.nodered_port > 0) {
109+
this.settings.uiPort = Config.nodered_port;
110+
}
111+
else {
112+
this.settings.uiPort = Config.port;
113+
}
114+
115+
116+
107117
this.settings.userDir = path.join(__dirname, "./nodered");
108118
this.settings.nodesDir = path.join(__dirname, "./nodered");
109119

OpenFlowNodeRED/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ function isNumeric(num) {
2828
}
2929
(async function (): Promise<void> {
3030
try {
31+
var c = Config;
3132
var socket: WebSocketClient = new WebSocketClient(logger, Config.api_ws_url);
3233
socket.events.on("onopen", async () => {
3334

3435
var q: SigninMessage = new SigninMessage();
3536
if (Config.jwt !== "") {
3637
q.jwt = Config.jwt;
37-
} else if (Crypt.encryption_key !== "") {
38+
} else if (Crypt.encryption_key() !== "") {
3839
var user = new TokenUser();
3940
if (NoderedUtil.IsNullEmpty(Config.nodered_sa)) {
4041
user.name = "nodered" + Config.nodered_id;

OpenFlowNodeRED/src/nodered/nodes/NoderedUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export class NoderedUtil {
197197
Logger.instanse.debug("GetToken::isNumeric: " + this.isNumeric(Config.nodered_id));
198198
if (Config.jwt !== "") {
199199
q.jwt = Config.jwt;
200-
} else if (Crypt.encryption_key !== "") {
200+
} else if (Crypt.encryption_key() !== "") {
201201
var user = new TokenUser();
202202
if (NoderedUtil.IsNullEmpty(Config.nodered_sa)) {
203203
user.name = "nodered" + Config.nodered_id;

OpenFlowNodeRED/src/nodered/nodes/api_nodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class api_get_jwt {
6767
} else {
6868
if (Config.jwt !== "") {
6969
q.jwt = Config.jwt;
70-
} else if (Crypt.encryption_key !== "") {
70+
} else if (Crypt.encryption_key() !== "") {
7171
var user = new TokenUser();
7272
if (NoderedUtil.IsNullEmpty(Config.nodered_sa)) {
7373
user.name = "nodered" + Config.nodered_id;

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.391
1+
0.0.392

docker-compose-traefik.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ services:
4545
- "traefik.http.routers.web.rule=Host(`localhost.openrpa.dk`)"
4646
- "traefik.http.routers.web.entrypoints=web"
4747
- "traefik.frontend.passHostHeader=true"
48-
image: "cloudhack/openflow:0.0.391"
48+
image: "cloudhack/openflow:0.0.392"
4949
container_name: "web"
5050
environment:
5151
- auto_create_users=true
@@ -80,7 +80,7 @@ services:
8080
- "traefik.http.routers.nodered.rule=Host(`nodered1.localhost.openrpa.dk`)"
8181
- "traefik.http.routers.nodered.entrypoints=web"
8282
- "traefik.http.services.nodered.loadbalancer.server.port=1880"
83-
image: "cloudhack/openflownodered:0.0.391"
83+
image: "cloudhack/openflownodered:0.0.392"
8484
container_name: "nodered"
8585
environment:
8686
# - nodered_id=1

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services:
1717
- "5672:5672"
1818
- "15672:15672"
1919
web:
20-
image: "cloudhack/openflow:0.0.391"
20+
image: "cloudhack/openflow:0.0.392"
2121
environment:
2222
- auto_create_users=true
2323
- auto_create_domains=
@@ -49,7 +49,7 @@ services:
4949
- "80:80"
5050
- "5858:5858"
5151
nodered:
52-
image: "cloudhack/openflownodered:0.0.391"
52+
image: "cloudhack/openflownodered:0.0.392"
5353
environment:
5454
# - nodered_id=1
5555
- nodered_sa=nodered1

0 commit comments

Comments
 (0)