Skip to content

Commit

Permalink
Fixed ANONYMOUS / USER session
Browse files Browse the repository at this point in the history
  • Loading branch information
mikakaraila committed Jul 20, 2020
1 parent 4eee0e1 commit 30cd5c1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
20 changes: 11 additions & 9 deletions opcua/102-opcuaclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,14 @@ 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);
}
else {
verbose_log("Client certificate not used!");
}

connectionOption.endpoint_must_exist = false;
connectionOption.defaultSecureTokenLifetime = 40000;
connectionOption.connectionStrategy = {
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions opcua/104-opcuaserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 30cd5c1

Please sign in to comment.