Server: Support passphrase for SSL private key (#4488)
* SSL: support passphrase for private key * Recommend CLI argument or environment variable for key passphrase * Fix SSL passphrase handling to ensure it is always a string
This commit is contained in:
@@ -40,9 +40,15 @@ browserLaunch:
|
|||||||
port: 8000
|
port: 8000
|
||||||
# -- SSL options --
|
# -- SSL options --
|
||||||
ssl:
|
ssl:
|
||||||
|
# Enable SSL/TLS encryption
|
||||||
enabled: false
|
enabled: false
|
||||||
|
# Path to certificate (relative to server root)
|
||||||
certPath: "./certs/cert.pem"
|
certPath: "./certs/cert.pem"
|
||||||
|
# Path to private key (relative to server root)
|
||||||
keyPath: "./certs/privkey.pem"
|
keyPath: "./certs/privkey.pem"
|
||||||
|
# Private key passphrase (leave empty if not needed)
|
||||||
|
# For better security, use a CLI argument or an environment variable (SILLYTAVERN_SSL_KEYPASSPHRASE)
|
||||||
|
keyPassphrase: ""
|
||||||
# -- SECURITY CONFIGURATION --
|
# -- SECURITY CONFIGURATION --
|
||||||
# Toggle whitelist mode
|
# Toggle whitelist mode
|
||||||
whitelistMode: true
|
whitelistMode: true
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import { initConfig } from './config-init.js';
|
|||||||
* @property {boolean} ssl If enable SSL
|
* @property {boolean} ssl If enable SSL
|
||||||
* @property {string} certPath Path to certificate
|
* @property {string} certPath Path to certificate
|
||||||
* @property {string} keyPath Path to private key
|
* @property {string} keyPath Path to private key
|
||||||
|
* @property {string} keyPassphrase SSL private key passphrase
|
||||||
* @property {boolean} whitelistMode If enable whitelist mode
|
* @property {boolean} whitelistMode If enable whitelist mode
|
||||||
* @property {boolean} basicAuthMode If enable basic authentication
|
* @property {boolean} basicAuthMode If enable basic authentication
|
||||||
* @property {boolean} requestProxyEnabled If enable outgoing request proxy
|
* @property {boolean} requestProxyEnabled If enable outgoing request proxy
|
||||||
@@ -70,6 +71,7 @@ export class CommandLineParser {
|
|||||||
ssl: false,
|
ssl: false,
|
||||||
certPath: 'certs/cert.pem',
|
certPath: 'certs/cert.pem',
|
||||||
keyPath: 'certs/privkey.pem',
|
keyPath: 'certs/privkey.pem',
|
||||||
|
keyPassphrase: '',
|
||||||
whitelistMode: true,
|
whitelistMode: true,
|
||||||
basicAuthMode: false,
|
basicAuthMode: false,
|
||||||
requestProxyEnabled: false,
|
requestProxyEnabled: false,
|
||||||
@@ -193,6 +195,11 @@ export class CommandLineParser {
|
|||||||
default: null,
|
default: null,
|
||||||
describe: 'Path to SSL private key file',
|
describe: 'Path to SSL private key file',
|
||||||
})
|
})
|
||||||
|
.option('keyPassphrase', {
|
||||||
|
type: 'string',
|
||||||
|
default: null,
|
||||||
|
describe: 'Passphrase for the SSL private key',
|
||||||
|
})
|
||||||
.option('whitelist', {
|
.option('whitelist', {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: null,
|
default: null,
|
||||||
@@ -291,6 +298,7 @@ export class CommandLineParser {
|
|||||||
ssl: cliArguments.ssl ?? getConfigValue('ssl.enabled', defaultConfig.ssl, 'boolean'),
|
ssl: cliArguments.ssl ?? getConfigValue('ssl.enabled', defaultConfig.ssl, 'boolean'),
|
||||||
certPath: cliArguments.certPath ?? getConfigValue('ssl.certPath', defaultConfig.certPath),
|
certPath: cliArguments.certPath ?? getConfigValue('ssl.certPath', defaultConfig.certPath),
|
||||||
keyPath: cliArguments.keyPath ?? getConfigValue('ssl.keyPath', defaultConfig.keyPath),
|
keyPath: cliArguments.keyPath ?? getConfigValue('ssl.keyPath', defaultConfig.keyPath),
|
||||||
|
keyPassphrase: cliArguments.keyPassphrase ?? getConfigValue('ssl.keyPassphrase', defaultConfig.keyPassphrase),
|
||||||
whitelistMode: cliArguments.whitelist ?? getConfigValue('whitelistMode', defaultConfig.whitelistMode, 'boolean'),
|
whitelistMode: cliArguments.whitelist ?? getConfigValue('whitelistMode', defaultConfig.whitelistMode, 'boolean'),
|
||||||
basicAuthMode: cliArguments.basicAuthMode ?? getConfigValue('basicAuthMode', defaultConfig.basicAuthMode, 'boolean'),
|
basicAuthMode: cliArguments.basicAuthMode ?? getConfigValue('basicAuthMode', defaultConfig.basicAuthMode, 'boolean'),
|
||||||
requestProxyEnabled: cliArguments.requestProxyEnabled ?? getConfigValue('requestProxy.enabled', defaultConfig.requestProxyEnabled, 'boolean'),
|
requestProxyEnabled: cliArguments.requestProxyEnabled ?? getConfigValue('requestProxy.enabled', defaultConfig.requestProxyEnabled, 'boolean'),
|
||||||
|
|||||||
@@ -233,9 +233,11 @@ export class ServerStartup {
|
|||||||
#createHttpsServer(url, ipVersion) {
|
#createHttpsServer(url, ipVersion) {
|
||||||
this.#verifySslOptions();
|
this.#verifySslOptions();
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
/** @type {import('https').ServerOptions} */
|
||||||
const sslOptions = {
|
const sslOptions = {
|
||||||
cert: fs.readFileSync(this.cliArgs.certPath),
|
cert: fs.readFileSync(this.cliArgs.certPath),
|
||||||
key: fs.readFileSync(this.cliArgs.keyPath),
|
key: fs.readFileSync(this.cliArgs.keyPath),
|
||||||
|
passphrase: String(this.cliArgs.keyPassphrase ?? ''),
|
||||||
};
|
};
|
||||||
const server = https.createServer(sslOptions, this.app);
|
const server = https.createServer(sslOptions, this.app);
|
||||||
server.on('error', reject);
|
server.on('error', reject);
|
||||||
|
|||||||
Reference in New Issue
Block a user