|
|
|
|
@ -39,7 +39,12 @@ module.exports = {
|
|
|
|
|
|
|
|
|
|
// Handle SSL Options
|
|
|
|
|
|
|
|
|
|
let dbUseSSL = (WIKI.config.db.ssl === true || WIKI.config.db.ssl === 'true' || WIKI.config.db.ssl === 1 || WIKI.config.db.ssl === '1')
|
|
|
|
|
let isTruthy = function(value) {
|
|
|
|
|
return (value === true || value === 'true' || value === 1 || value === '1')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let dbUseSSL = isTruthy(WIKI.config.db.ssl)
|
|
|
|
|
let rejectUnauthorized = !_.isEmpty(process.env.DB_SSL_REJECTUNAUTHORIZED) ? isTruthy(process.env.DB_SSL_REJECTUNAUTHORIZED) : true;
|
|
|
|
|
let sslOptions = null
|
|
|
|
|
if (dbUseSSL && _.isPlainObject(dbConfig) && _.get(WIKI.config.db, 'sslOptions.auto', null) === false) {
|
|
|
|
|
sslOptions = WIKI.config.db.sslOptions
|
|
|
|
|
@ -60,18 +65,22 @@ module.exports = {
|
|
|
|
|
sslOptions = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle inline SSL CA Certificate mode
|
|
|
|
|
// Handle self-signed CA file or concatenated string
|
|
|
|
|
// https://node-postgres.com/features/ssl
|
|
|
|
|
if (!_.isEmpty(process.env.DB_SSL_CA)) {
|
|
|
|
|
const chunks = []
|
|
|
|
|
for (let i = 0, charsLength = process.env.DB_SSL_CA.length; i < charsLength; i += 64) {
|
|
|
|
|
chunks.push(process.env.DB_SSL_CA.substring(i, i + 64))
|
|
|
|
|
try {
|
|
|
|
|
ca = fs.readFileSync(process.env.DB_SSL_CA).toString()
|
|
|
|
|
} catch(_) {
|
|
|
|
|
const chunks = []
|
|
|
|
|
for (let i = 0, charsLength = process.env.DB_SSL_CA.length; i < charsLength; i += 64) {
|
|
|
|
|
chunks.push(process.env.DB_SSL_CA.substring(i, i + 64))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ca = '-----BEGIN CERTIFICATE-----\n' + chunks.join('\n') + '\n-----END CERTIFICATE-----\n'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbUseSSL = true
|
|
|
|
|
sslOptions = {
|
|
|
|
|
rejectUnauthorized: true,
|
|
|
|
|
ca: '-----BEGIN CERTIFICATE-----\n' + chunks.join('\n') + '\n-----END CERTIFICATE-----\n'
|
|
|
|
|
}
|
|
|
|
|
sslOptions = { rejectUnauthorized, ca }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Engine-specific config
|
|
|
|
|
@ -80,7 +89,7 @@ module.exports = {
|
|
|
|
|
dbClient = 'pg'
|
|
|
|
|
|
|
|
|
|
if (dbUseSSL && _.isPlainObject(dbConfig)) {
|
|
|
|
|
dbConfig.ssl = (sslOptions === true) ? { rejectUnauthorized: true } : sslOptions
|
|
|
|
|
dbConfig.ssl = (sslOptions === true) ? { rejectUnauthorized } : sslOptions
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
case 'mariadb':
|
|
|
|
|
|