Skip to content

Commit 9b08abd

Browse files
committed
IP configuration option and SAN multi value
1 parent 29de0b0 commit 9b08abd

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ The below run time configuration are available, which can be configured either v
3636
- Lightning-RPC Path - Configure the path where `lightning-rpc` file is located. It will default to standard lightning path if not configured
3737
- RPC Command - - Enable additional RPC commands for `/rpc` endpoint
3838
- Domain - An external domain to be used for the self-signed certificate
39+
- IP - A static IP to be used for the self-signed certificate
3940

4041
#### Option 1: Via Config file `cl-rest-config.json`
4142
For running the server, rename the file `sample-cl-rest-config.json` to `cl-rest-config.json`. Following parameters can be configured in the config file:
@@ -46,6 +47,7 @@ For running the server, rename the file `sample-cl-rest-config.json` to `cl-rest
4647
- LNRPCPATH (Default: ` `)
4748
- RPCCOMMANDS (Default: `["*"]`)
4849
- DOMAIN (Default: `localhost`)
50+
- IP (Default: `127.0.0.1`)
4951
- BIND (Default: `::`)
5052

5153
#### Option 2: With the plugin configuration, if used as a plugin
@@ -60,6 +62,7 @@ If running as a plugin, configure the below options in your core lightning `conf
6062
- `rest-lnrpcpath`
6163
- `rest-rpc`
6264
- `rest-domain`
65+
- `rest-ip`
6366
- `rest-bind`
6467

6568
Defaults are the same as in option # 1 with the exception that `rest-rpc` is a comma separated string.
@@ -129,6 +132,10 @@ With the default config, APIs will be served over `https` (a self signed certifi
129132
Sample url: `https://localhost:3001/v1/getinfo/`
130133

131134
Providing a `DOMAIN` to the c-lightning-REST configuration will add the domain as a `subjectAltName` to the openssl certificate, permitting successful certificate validation by users and applications, e.g. Zeus, when connecting to the server at via that domain.
135+
The same thing can be achieved with the `IP` configuration parameter, but for a static IP instead of a DNS domain.
136+
137+
Additionally, both `DOMAIN` and `IP` support specifying multiple comma-separated values, for instance `localhost,example.com,ln.example.com`, or `127.0.0.1,4.5.6.7`.
138+
The resulting TLS certificate will be able to validate HTTPS responses received from any of these domains and IPs.
132139

133140
If you are *upgrading* a server which is already configured, you should first backup and your entire `./certs` directory in case you need to restore it later.
134141
Following this you should delete *only* the `.certs/certificate.pem` and `.certs/key.pem` files, so that new SSL certificates can be generated which take the `subjectAltName` into consideration.

cl-rest.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const PORT = config.PORT;
3030
const EXECMODE = config.EXECMODE;
3131
const DOCPORT = config.DOCPORT;
3232
const DOMAIN = config.DOMAIN || "localhost";
33+
const IP = config.IP || "127.0.0.1";
3334

3435
// Check if any interface on the device has an IPv6 address
3536
const os = require('os');
@@ -62,9 +63,12 @@ try {
6263
if ( ! fs.existsSync( key ) || ! fs.existsSync( certificate ) ) {
6364
global.logger.log("Generating SSL cert and key");
6465
try {
66+
let subjectAltNames = config.DOMAIN.split(',').map((domain) => `DNS:${ domain }`).join(',');
67+
subjectAltNames += ',' + config.IP.split(',').map((ip) => `IP:${ ip }`).join(',');
68+
6569
execSync( 'openssl version', execOptions );
6670
execSync(
67-
`openssl req -x509 -newkey rsa:2048 -keyout ./certs/key.tmp.pem -out ${ certificate } -days 365 -nodes -subj "/C=US/ST=Foo/L=Bar/O=Baz/CN=c-lightning-rest" -addext "subjectAltName = DNS:${ DOMAIN }"`,
71+
`openssl req -x509 -newkey rsa:2048 -keyout ./certs/key.tmp.pem -out ${ certificate } -days 365 -nodes -subj "/C=US/ST=Foo/L=Bar/O=Baz/CN=c-lightning-rest" -addext "subjectAltName = ${ subjectAltNames }"`,
6872
execOptions
6973
);
7074
execSync( `openssl rsa -in ./certs/key.tmp.pem -out ${ key }`, execOptions );

clrest.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ restPlugin.addOption('rest-execmode', 'production', 'rest exec mode', 'string');
1212
restPlugin.addOption('rest-rpc', ' ', 'allowed rpc commands', 'string');
1313
restPlugin.addOption('rest-lnrpcpath', ' ', 'path for lightning-rpc', 'string');
1414
restPlugin.addOption('rest-domain', ' ', 'domain name for self-signed cert', 'string');
15+
restPlugin.addOption('rest-ip', ' ', 'IP for self-signed cert', 'string');
1516
restPlugin.addOption('rest-bind', ' ', 'Binding address', 'string');
1617

1718
restPlugin.onInit = params => {
@@ -25,6 +26,7 @@ restPlugin.onInit = params => {
2526
RPCCOMMANDS: params.options['rest-rpc'].trim().split(",").map(s => s.trim()),
2627
LNRPCPATH: params.options['rest-lnrpcpath'],
2728
DOMAIN: params.options['rest-domain'].trim(),
29+
IP: params.options['rest-ip'].trim(),
2830
BIND: params.options['rest-bind'].trim(),
2931
PLUGIN: restPlugin
3032
}

sample-cl-rest-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"EXECMODE": "production",
66
"RPCCOMMANDS": ["*"],
77
"DOMAIN": "localhost",
8+
"IP": "127.0.0.1",
89
"BIND": "::"
910
}

0 commit comments

Comments
 (0)