@@ -3,6 +3,7 @@ import { Config } from "../_models/Config";
3
3
import { ConfigTSLClient } from "../_models/ConfigTSLClient" ;
4
4
import fs from "fs-extra" ;
5
5
import path from "path" ;
6
+ import { randomBytes } from "crypto" ;
6
7
import { clone } from "./clone" ;
7
8
import { uuidv4 } from "./uuid" ;
8
9
import { addUser } from "./auth" ;
@@ -20,7 +21,7 @@ const config_file = getConfigFilePath();
20
21
21
22
export const ConfigDefaults : Config = {
22
23
security : {
23
- jwt_private_key : require ( 'crypto' ) . randomBytes ( 256 ) . toString ( 'base64' ) ,
24
+ jwt_private_key : "" ,
24
25
} ,
25
26
users : [ ] ,
26
27
cloud_destinations : [ ] ,
@@ -39,7 +40,7 @@ export const ConfigDefaults: Config = {
39
40
] ,
40
41
externalAddress : "http://0.0.0.0:4455/#/tally" ,
41
42
remoteErrorReporting : false ,
42
- uuid : uuidv4 ( )
43
+ uuid : ""
43
44
}
44
45
45
46
export let currentConfig : Config = clone ( ConfigDefaults ) ;
@@ -87,17 +88,17 @@ export function readConfig(): void {
87
88
...clone ( ConfigDefaults ) ,
88
89
...loadedConfig ,
89
90
} ;
90
- if ( ! loadedConfig . users || loadedConfig . users . length === 0 ) {
91
+ if ( ! loadedConfig . users || typeof loadedConfig . users !== "object" || loadedConfig . users . length === 0 ) {
91
92
logger ( 'Migrating user configs to the new format.' , 'info-quiet' ) ;
92
93
currentConfig . users = [ ] ;
93
94
addUser ( {
94
- username : currentConfig . security . username_producer || "producer" ,
95
- password : currentConfig . security . password_producer || "12345" ,
95
+ username : loadedConfig . security . username_producer || "producer" ,
96
+ password : loadedConfig . security . password_producer || "12345" ,
96
97
roles : "producer"
97
98
} ) ;
98
99
addUser ( {
99
- username : currentConfig . security . username_settings || "admin" ,
100
- password : currentConfig . security . password_settings || "12345" ,
100
+ username : loadedConfig . security . username_settings || "admin" ,
101
+ password : loadedConfig . security . password_settings || "12345" ,
101
102
roles : "admin"
102
103
} ) ;
103
104
delete currentConfig . security . username_producer ;
@@ -106,12 +107,14 @@ export function readConfig(): void {
106
107
delete currentConfig . security . password_settings ;
107
108
SaveConfig ( ) ;
108
109
}
109
- if ( ! loadedConfig . uuid ) {
110
+ if ( ! loadedConfig . uuid || typeof loadedConfig . uuid !== "string" ) {
110
111
logger ( 'Adding an uuid identifier to this server for using MDNS.' , 'info-quiet' ) ;
112
+ currentConfig . uuid = uuidv4 ( ) ;
111
113
SaveConfig ( ) ; //uuid added if missing on config save
112
114
}
113
- if ( ! loadedConfig . security . jwt_private_key ) {
115
+ if ( ! loadedConfig . security . jwt_private_key || typeof loadedConfig . security . jwt_private_key !== "string" ) {
114
116
logger ( 'Adding a private key for JWT authentication.' , 'info-quiet' ) ;
117
+ currentConfig . security . jwt_private_key = randomBytes ( 256 ) . toString ( 'base64' ) ;
115
118
SaveConfig ( ) ; //uuid added if missing on config save
116
119
}
117
120
}
0 commit comments