From 30cd5c1efcedabbf29c1756f4b8bbbfa364d189d Mon Sep 17 00:00:00 2001 From: mikakaraila Date: Mon, 20 Jul 2020 21:57:43 +0300 Subject: [PATCH] Fixed ANONYMOUS / USER session --- opcua/102-opcuaclient.js | 20 +++++++++++--------- opcua/104-opcuaserver.js | 4 ++-- package.json | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/opcua/102-opcuaclient.js b/opcua/102-opcuaclient.js index b6656ca..c2104ed 100644 --- a/opcua/102-opcuaclient.js +++ b/opcua/102-opcuaclient.js @@ -116,7 +116,7 @@ module.exports = function (RED) { if (!clientPkg) verbose_warn("Cannot find node-opcua-client package with client certificate"); // Client certificate from node-opcua-client\certificates, created by node-opcua installation - if (connectionOption.securityPolicy !== opcua.SecurityPolicy.None) { + if (opcuaEndpoint.securityPolicy !== "None") { connectionOption.certificateFile = path.join(clientPkg, "/certificates/client_selfsigned_cert_2048.pem"), connectionOption.privateKeyFile = path.join(clientPkg, "/certificates/PKI/own/private/private_key.pem") verbose_log("Using client certificate " + connectionOption.certificateFile); @@ -124,7 +124,6 @@ module.exports = function (RED) { else { verbose_log("Client certificate not used!"); } - connectionOption.endpoint_must_exist = false; connectionOption.defaultSecureTokenLifetime = 40000; connectionOption.connectionStrategy = { @@ -133,12 +132,13 @@ module.exports = function (RED) { maxDelay: 30 * 1000 }; connectionOption.keepSessionAlive = true; - verbose_log(connectionOption); - verbose_log(opcuaEndpoint); + verbose_log("Connection options:" + JSON.stringify(connectionOption)); + verbose_log("EndPoint: " + JSON.stringify(opcuaEndpoint)); - if (opcuaEndpoint.login) { + if (opcuaEndpoint.login === true) { userIdentity.userName = opcuaEndpoint.credentials.user; userIdentity.password = opcuaEndpoint.credentials.password; + verbose_log("UserIdentity: " + JSON.stringify(userIdentity)); } var items = []; @@ -233,8 +233,7 @@ module.exports = function (RED) { function create_opcua_client(callback) { node.client = null; - verbose_warn("create Client ..."); - verbose_log(connectionOption); + verbose_warn("Create Client: " + JSON.stringify(connectionOption)); try { node.client = opcua.OPCUAClient.create(connectionOption); } @@ -346,8 +345,10 @@ module.exports = function (RED) { verbose_log("async series - create session ..."); try { // TODO Add other security parameters to create session to server - if (opcuaEndpoint.login) { - node.client.createSession({userIdentity, "clientName": "Node-red OPC UA Client node " + node.name}, function (err, session) { + if (opcuaEndpoint.login === true) { + verbose_log("Create session with userIdentity: " + JSON.stringify(userIdentity)); + // {"clientName": "Node-red OPC UA Client node " + node.name}, + node.client.createSession(userIdentity, function (err, session) { if (!err) { // verbose_warn("Session name " + "Node-red OPC UA Client node " + node.name.toString().green.bold); session.sessionName = "Node-red OPC UA Client node " + node.name; @@ -368,6 +369,7 @@ module.exports = function (RED) { }); } else { // ANONYMOUS no userIdentify to pass for creating session + verbose_log("Create session as ANONYMOUS"); node.client.createSession({"clientName": "Node-red OPC UA Client node " + node.name}, function (err, session) { if (!err) { // verbose_warn("Session name " + "Node-red OPC UA Client node " + node.name.toString().green.bold); diff --git a/opcua/104-opcuaserver.js b/opcua/104-opcuaserver.js index 37c4805..1bfb2b6 100644 --- a/opcua/104-opcuaserver.js +++ b/opcua/104-opcuaserver.js @@ -132,8 +132,8 @@ module.exports = function (RED) { }; server_options.buildInfo = { productName: node.name.concat(" OPC UA server for node-red"), - buildNumber: "0.2.69", - buildDate: "2020-07-20T10:43:00" + buildNumber: "0.2.70", + buildDate: "2020-07-20T21:56:00" }; verbose_log("Server options:" + JSON.stringify(server_options)); server = new opcua.OPCUAServer(server_options); diff --git a/package.json b/package.json index ff55c2b..9690ff5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-contrib-opcua", - "version": "0.2.69", + "version": "0.2.70", "description": "A Node-RED node to communicate via OPC UA based on node-opcua library.", "repository": { "type": "git",