diff --git a/nodes/core/io/05-tls.html b/nodes/core/io/05-tls.html index 5de7e99c4..7befd1f1f 100644 --- a/nodes/core/io/05-tls.html +++ b/nodes/core/io/05-tls.html @@ -15,17 +15,42 @@ --> diff --git a/nodes/core/io/05-tls.js b/nodes/core/io/05-tls.js index a0929d988..a93ed1b39 100644 --- a/nodes/core/io/05-tls.js +++ b/nodes/core/io/05-tls.js @@ -21,34 +21,65 @@ module.exports = function(RED) { function TLSConfig(n) { RED.nodes.createNode(this,n); this.valid = true; + this.verifyservercert = n.verifyservercert; var certPath = n.cert.trim(); var keyPath = n.key.trim(); var caPath = n.ca.trim(); - if ( (certPath.length > 0) !== (keyPath.length > 0)) { - this.valid = false; - this.error(RED._("tls.error.missing-file")); - return; - } - this.verifyservercert = n.verifyservercert; + if ((certPath.length > 0) || (keyPath.length > 0)) { - try { - if (certPath) { - this.cert = fs.readFileSync(certPath); + if ( (certPath.length > 0) !== (keyPath.length > 0)) { + this.valid = false; + this.error(RED._("tls.error.missing-file")); + return; } - if (keyPath) { - this.key = fs.readFileSync(keyPath); + + try { + if (certPath) { + this.cert = fs.readFileSync(certPath); + } + if (keyPath) { + this.key = fs.readFileSync(keyPath); + } + if (caPath) { + this.ca = fs.readFileSync(caPath); + } + } catch(err) { + this.valid = false; + this.error(err.toString()); + return; + } + } else { + if (this.credentials) { + var certData = this.credentials.certdata || ""; + var keyData = this.credentials.keydata || ""; + var caData = this.credentials.cadata || ""; + + if ((certData.length > 0) !== (keyData.length > 0)) { + this.valid = false; + this.error(RED._("tls.error.missing-file")); + return; + } + + if (certData) { + this.cert = certData; + } + if (keyData) { + this.key = keyData; + } + if (caData) { + this.ca = caData; + } } - if (caPath) { - this.ca = fs.readFileSync(caPath); - } - } catch(err) { - this.valid = false; - this.error(err.toString()); - return; } } - RED.nodes.registerType("tls-config",TLSConfig); + RED.nodes.registerType("tls-config", TLSConfig, { + credentials: { + certdata: {type:"text"}, + keydata: {type:"text"}, + cadata: {type:"text"} + } + }); TLSConfig.prototype.addTLSOptions = function(opts) { if (this.valid) { diff --git a/nodes/core/locales/en-US/messages.json b/nodes/core/locales/en-US/messages.json index 0ad39f7a8..448382e4a 100644 --- a/nodes/core/locales/en-US/messages.json +++ b/nodes/core/locales/en-US/messages.json @@ -126,6 +126,8 @@ "tls": { "tls": "TLS configuration", "label": { + "use-local-files": "Use key and certificates from local files", + "upload": "Upload", "cert": "Certificate", "key": "Private Key", "ca": "CA Certificate", diff --git a/red/api/info.js b/red/api/info.js index e2661bdc3..72ec52b93 100644 --- a/red/api/info.js +++ b/red/api/info.js @@ -43,6 +43,10 @@ module.exports = { safeSettings.flowFilePretty = settings.flowFilePretty; } + if (settings.tlsDisableLocalFiles) { + safeSettings.tlsDisableLocalFiles = settings.tlsDisableLocalFiles; + } + if (!runtime.nodes.paletteEditorEnabled()) { safeSettings.editorTheme = safeSettings.editorTheme || {}; safeSettings.editorTheme.palette = safeSettings.editorTheme.palette || {}; diff --git a/settings.js b/settings.js index 79e8839f7..6b9228343 100644 --- a/settings.js +++ b/settings.js @@ -47,6 +47,10 @@ module.exports = { // The maximum length, in characters, of any message sent to the debug sidebar tab debugMaxLength: 1000, + // To disable the option for using local files for storing keys and certificates in the TLS configuration + // node, set this to true + //tlsDisableLocalFiles:true, + // Colourise the console output of the debug node //debugUseColors: true,