node-opcua-samples 2.97.0 → 2.98.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/get_endpoints.d.ts +2 -2
- package/dist/get_endpoints.js +141 -141
- package/dist/mini_server.d.ts +1 -1
- package/dist/mini_server.js +88 -88
- package/dist/server_with_changing_password.d.ts +1 -1
- package/dist/server_with_changing_password.js +100 -100
- package/dist/server_with_push_certificate.d.ts +2 -2
- package/dist/server_with_push_certificate.js +111 -111
- package/dist/simple_client_ts.d.ts +2 -2
- package/dist/simple_client_ts.js +661 -661
- package/dist/simple_findservers.d.ts +2 -2
- package/dist/simple_findservers.js +48 -48
- package/dist/simple_secure_server.d.ts +2 -2
- package/dist/simple_secure_server.js +125 -125
- package/dist/simple_server_with_custom_extension_objects.d.ts +2 -2
- package/dist/simple_server_with_custom_extension_objects.js +81 -81
- package/dist/stressing_client.d.ts +1 -1
- package/dist/stressing_client.js +36 -36
- package/dist/tiny_client.d.ts +1 -1
- package/dist/tiny_client.js +32 -32
- package/package.json +15 -12
- package/bin/createOPCUACertificate.cmd +0 -6
- package/bin/create_certificates.js +0 -2
- package/bin/crypto_create_CA.js +0 -2
- package/bin/demo_server_with_alarm.js +0 -51
- package/bin/findServersOnNetwork.js +0 -32
- package/bin/get_endpoints.ts +0 -166
- package/bin/machineryServer.js +0 -83
- package/bin/mini_server.ts +0 -106
- package/bin/more.js +0 -40
- package/bin/node-opcua.js +0 -2
- package/bin/opcua_interceptor.js +0 -122
- package/bin/server_with_changing_password.ts +0 -97
- package/bin/server_with_push_certificate.ts +0 -122
- package/bin/simple_client.js +0 -830
- package/bin/simple_client_ts.ts +0 -847
- package/bin/simple_findservers.ts +0 -45
- package/bin/simple_secure_server.ts +0 -152
- package/bin/simple_server_with_custom_extension_objects.ts +0 -89
- package/bin/stressing_client.ts +0 -28
- package/bin/tiny_client.ts +0 -24
package/bin/opcua_interceptor.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/* eslint no-process-exit: 0 */
|
|
2
|
-
"use strict";
|
|
3
|
-
const net = require("net");
|
|
4
|
-
|
|
5
|
-
const chalk = require("chalk");
|
|
6
|
-
const yargs = require("yargs");
|
|
7
|
-
const argv = yargs.usage("Usage: $0 --portServer [num] --port [num] --hostname <hostname> -block").argv;
|
|
8
|
-
|
|
9
|
-
const opcua = require("node-opcua");
|
|
10
|
-
|
|
11
|
-
const { hexDump } = require("node-opcua-utils");
|
|
12
|
-
const { MessageBuilder } = require("../lib/misc/message_builder");
|
|
13
|
-
const { BinaryStream } = require("../lib/misc/binaryStream");
|
|
14
|
-
|
|
15
|
-
const { analyseExtensionObject } = require("../lib/misc/analyzePacket");
|
|
16
|
-
const { messageHeaderToString } = require("../lib/misc/message_header");
|
|
17
|
-
|
|
18
|
-
const s = require("../lib/datamodel/structures");
|
|
19
|
-
|
|
20
|
-
const remote_port = parseInt(argv.port, 10) || 4841;
|
|
21
|
-
const hostname = argv.hostname || "localhost";
|
|
22
|
-
|
|
23
|
-
const my_port = parseInt(argv.portServer, 10) || remote_port + 1;
|
|
24
|
-
|
|
25
|
-
const TrafficAnalyser = function (id) {
|
|
26
|
-
this.id = id;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
TrafficAnalyser.prototype.add = function (data) {
|
|
30
|
-
const stream = new BinaryStream(data);
|
|
31
|
-
if (argv.block) {
|
|
32
|
-
console.log(hexDump(data));
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const messageHeader = opcua.readMessageHeader(stream);
|
|
36
|
-
|
|
37
|
-
if (messageHeader.msgType === "ERR") {
|
|
38
|
-
const err = new s.TCPErrorMessage();
|
|
39
|
-
err.decode(stream);
|
|
40
|
-
console.log(" Error 0x" + err.statusCode.toString() + " reason:" + err.reason);
|
|
41
|
-
console.log(hexDump(data));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const messageBuild = new MessageBuilder();
|
|
45
|
-
messageBuild.on("full_message_body", function (full_message_body) {
|
|
46
|
-
console.log(hexDump(full_message_body));
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
analyseExtensionObject(full_message_body);
|
|
50
|
-
} catch (err) {
|
|
51
|
-
console.log(chalk.red("ERROR : "), err);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
switch (messageHeader.msgType) {
|
|
56
|
-
case "HEL":
|
|
57
|
-
case "ACK":
|
|
58
|
-
if (this.id % 2) {
|
|
59
|
-
console.log(chalk.red.bold(JSON.stringify(messageHeader, null, "")));
|
|
60
|
-
} else {
|
|
61
|
-
console.log(chalk.yellow.bold(JSON.stringify(messageHeader, null, "")));
|
|
62
|
-
}
|
|
63
|
-
break;
|
|
64
|
-
|
|
65
|
-
case "OPN": // open secure channel
|
|
66
|
-
case "CLO": // close secure channel
|
|
67
|
-
case "MSG": // message
|
|
68
|
-
// decode secure message
|
|
69
|
-
if (this.id % 2) {
|
|
70
|
-
console.log(chalk.red.bold(messageHeaderToString(data)));
|
|
71
|
-
} else {
|
|
72
|
-
console.log(chalk.yellow.bold(messageHeaderToString(data)));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
messageBuild.feed(data);
|
|
76
|
-
break;
|
|
77
|
-
case "ERR":
|
|
78
|
-
console.log(hexDump(data));
|
|
79
|
-
break;
|
|
80
|
-
default:
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
require("net")
|
|
86
|
-
.createServer(function (socket) {
|
|
87
|
-
console.log("connected");
|
|
88
|
-
const ta_client = new TrafficAnalyser(1);
|
|
89
|
-
|
|
90
|
-
const ta_server = new TrafficAnalyser(2);
|
|
91
|
-
|
|
92
|
-
const proxy_client = new net.Socket();
|
|
93
|
-
proxy_client.connect(remote_port, hostname);
|
|
94
|
-
|
|
95
|
-
proxy_client.on("data", function (data) {
|
|
96
|
-
console.log(" server -> client : packet length " + data.length);
|
|
97
|
-
ta_server.add(data);
|
|
98
|
-
try {
|
|
99
|
-
socket.write(data);
|
|
100
|
-
} catch (err) {
|
|
101
|
-
/** */
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
socket.on("data", function (data) {
|
|
106
|
-
console.log(" client -> server : packet length " + data.length);
|
|
107
|
-
ta_client.add(data);
|
|
108
|
-
proxy_client.write(data);
|
|
109
|
-
});
|
|
110
|
-
socket.on("close", function () {
|
|
111
|
-
console.log("server disconnected (CLOSE)");
|
|
112
|
-
proxy_client.end();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
socket.on("end", function () {
|
|
116
|
-
console.log("server disconnected (END)");
|
|
117
|
-
});
|
|
118
|
-
})
|
|
119
|
-
.listen(my_port);
|
|
120
|
-
|
|
121
|
-
console.log(" registering OPCUA server on port " + my_port);
|
|
122
|
-
console.log(" +-> redirecting conversation to server port " + remote_port);
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { OPCUAServer, makeRoles, WellKnownRoles, NodeId, nodesets } from "node-opcua";
|
|
2
|
-
|
|
3
|
-
const port = 2510;
|
|
4
|
-
let server: OPCUAServer;
|
|
5
|
-
const users = [
|
|
6
|
-
{
|
|
7
|
-
username: "user1",
|
|
8
|
-
password: "passwor1",
|
|
9
|
-
roles: makeRoles([WellKnownRoles.AuthenticatedUser, WellKnownRoles.ConfigureAdmin])
|
|
10
|
-
}
|
|
11
|
-
];
|
|
12
|
-
|
|
13
|
-
const userManager = {
|
|
14
|
-
isValidUser: (username: string, password: string): boolean => {
|
|
15
|
-
const uIndex = users.findIndex(function (u) {
|
|
16
|
-
return u.username === username;
|
|
17
|
-
});
|
|
18
|
-
if (uIndex < 0) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
if (users[uIndex].password !== password) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
return true;
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
getUserRoles: (username: string): NodeId[] => {
|
|
28
|
-
const uIndex = users.findIndex(function (x) {
|
|
29
|
-
return x.username === username;
|
|
30
|
-
});
|
|
31
|
-
if (uIndex < 0) {
|
|
32
|
-
return makeRoles("Anonymous");
|
|
33
|
-
}
|
|
34
|
-
const userRole = users[uIndex].roles;
|
|
35
|
-
return userRole;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
async function startServer() {
|
|
39
|
-
server = new OPCUAServer({
|
|
40
|
-
port: port,
|
|
41
|
-
nodeset_filename: [nodesets.standard],
|
|
42
|
-
userManager,
|
|
43
|
-
maxConnectionsPerEndpoint: 1,
|
|
44
|
-
serverCapabilities: {
|
|
45
|
-
maxSessions: 2,
|
|
46
|
-
maxSubscriptions: 10,
|
|
47
|
-
maxSubscriptionsPerSession: 3
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
await server.initialize();
|
|
51
|
-
await server.start();
|
|
52
|
-
|
|
53
|
-
server.on("newChannel", () => {
|
|
54
|
-
console.log("server => new channel");
|
|
55
|
-
});
|
|
56
|
-
server.on("session_activated", () => {
|
|
57
|
-
console.log("server session activated");
|
|
58
|
-
});
|
|
59
|
-
server.on("connectionRefused", () => {
|
|
60
|
-
console.log("server connection refused");
|
|
61
|
-
});
|
|
62
|
-
server.on("session_closed", () => {
|
|
63
|
-
console.log("server sesion closed");
|
|
64
|
-
});
|
|
65
|
-
server.on("create_session", () => {
|
|
66
|
-
console.log("server create session");
|
|
67
|
-
});
|
|
68
|
-
return server;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
(async () => {
|
|
72
|
-
let counter = 0;
|
|
73
|
-
|
|
74
|
-
process.on("SIGINT", () => {
|
|
75
|
-
if (counter > 5) {
|
|
76
|
-
process.exit();
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
while (true) {
|
|
81
|
-
users[0].password = `password${counter % 2}`;
|
|
82
|
-
counter++;
|
|
83
|
-
console.log("user: user1, password: ", users[0].password);
|
|
84
|
-
const server = await startServer();
|
|
85
|
-
console.log("server started at", server.getEndpointUrl());
|
|
86
|
-
|
|
87
|
-
await new Promise((resolve) => {
|
|
88
|
-
console.log("waiting for CTRL+C to cycle");
|
|
89
|
-
process.once("SIGINT", resolve);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
console.log("now shutting down");
|
|
93
|
-
|
|
94
|
-
await server.shutdown(1000);
|
|
95
|
-
console.log("server stopped for maintenance");
|
|
96
|
-
}
|
|
97
|
-
})();
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
/* eslint no-process-exit: 0 */
|
|
3
|
-
// tslint:disable:no-console
|
|
4
|
-
import * as path from "path";
|
|
5
|
-
import * as chalk from "chalk";
|
|
6
|
-
|
|
7
|
-
import { makeRoles, nodesets, OPCUACertificateManager, OPCUAServer, OPCUAServerOptions, WellKnownRoles } from "node-opcua";
|
|
8
|
-
import { CertificateManager } from "node-opcua-pki";
|
|
9
|
-
import { installPushCertificateManagement } from "node-opcua-server-configuration";
|
|
10
|
-
import * as yargs from "yargs";
|
|
11
|
-
|
|
12
|
-
const rootFolder = path.join(__dirname, "../../..");
|
|
13
|
-
|
|
14
|
-
import envPaths from "env-paths";
|
|
15
|
-
const config = envPaths("node-opcua-default").config;
|
|
16
|
-
const pkiFolder = path.join(config, "PKI");
|
|
17
|
-
|
|
18
|
-
const certificateManager = new OPCUACertificateManager({
|
|
19
|
-
automaticallyAcceptUnknownCertificate: true,
|
|
20
|
-
name: "PKI",
|
|
21
|
-
rootFolder: pkiFolder
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const users = [
|
|
25
|
-
{
|
|
26
|
-
username: "user1",
|
|
27
|
-
password: "password1",
|
|
28
|
-
role: makeRoles([WellKnownRoles.AuthenticatedUser, WellKnownRoles.ConfigureAdmin, WellKnownRoles.SecurityAdmin])
|
|
29
|
-
},
|
|
30
|
-
{ username: "user2", password: "password2", role: makeRoles([WellKnownRoles.AuthenticatedUser, WellKnownRoles.Operator]) }
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
const userManager = {
|
|
34
|
-
isValidUser(username: string, password: string) {
|
|
35
|
-
const uIndex = users.findIndex((x) => x.username === username);
|
|
36
|
-
if (uIndex < 0) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
if (users[uIndex].password !== password) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
return true;
|
|
43
|
-
},
|
|
44
|
-
getUserRoles(username: string) {
|
|
45
|
-
const uIndex = users.findIndex((x) => x.username === username);
|
|
46
|
-
if (uIndex < 0) {
|
|
47
|
-
return [];
|
|
48
|
-
}
|
|
49
|
-
const userRole = users[uIndex].role;
|
|
50
|
-
return userRole;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
async function main() {
|
|
55
|
-
const argv = await yargs.wrap(132).option("port", {
|
|
56
|
-
alias: "p",
|
|
57
|
-
default: "26543",
|
|
58
|
-
describe: "port to listen"
|
|
59
|
-
}).argv;
|
|
60
|
-
|
|
61
|
-
const port = parseInt(argv.port, 10) || 26555;
|
|
62
|
-
|
|
63
|
-
const serverOptions: OPCUAServerOptions = {
|
|
64
|
-
port,
|
|
65
|
-
|
|
66
|
-
nodeset_filename: [nodesets.standard],
|
|
67
|
-
|
|
68
|
-
serverCertificateManager: certificateManager,
|
|
69
|
-
userCertificateManager: certificateManager,
|
|
70
|
-
|
|
71
|
-
userManager
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
process.title = "Node OPCUA Server on port : " + serverOptions.port;
|
|
75
|
-
const tmpFolder = path.join(__dirname, "../certificates/myApp");
|
|
76
|
-
|
|
77
|
-
const applicationGroup = new CertificateManager({
|
|
78
|
-
location: tmpFolder
|
|
79
|
-
});
|
|
80
|
-
await applicationGroup.initialize();
|
|
81
|
-
|
|
82
|
-
const server = new OPCUAServer(serverOptions);
|
|
83
|
-
|
|
84
|
-
console.log(" Configuration rootdir = ", server.serverCertificateManager.rootDir);
|
|
85
|
-
console.log(chalk.yellow(" server PID :"), process.pid);
|
|
86
|
-
|
|
87
|
-
await server.initialize();
|
|
88
|
-
|
|
89
|
-
const addressSpace = server.engine.addressSpace!;
|
|
90
|
-
// to do: expose new nodeid here
|
|
91
|
-
const ns = addressSpace.getNamespaceIndex("http://yourorganisation.org/my_data_type/");
|
|
92
|
-
|
|
93
|
-
await installPushCertificateManagement(addressSpace, {
|
|
94
|
-
applicationGroup: server.serverCertificateManager,
|
|
95
|
-
userTokenGroup: server.userCertificateManager,
|
|
96
|
-
applicationUri: server.serverInfo.applicationUri!
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
console.log("Certificate rejected folder ", server.serverCertificateManager.rejectedFolder);
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
await server.start();
|
|
103
|
-
} catch (err) {
|
|
104
|
-
console.log(" Server failed to start ... exiting");
|
|
105
|
-
process.exit(-3);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const endpointUrl = server.getEndpointUrl()!;
|
|
109
|
-
|
|
110
|
-
console.log(chalk.yellow(" server on port :"), chalk.cyan(server.endpoints[0].port.toString()));
|
|
111
|
-
console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl));
|
|
112
|
-
console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
|
|
113
|
-
|
|
114
|
-
process.once("SIGINT", async () => {
|
|
115
|
-
// only work on linux apparently
|
|
116
|
-
await server.shutdown(1000);
|
|
117
|
-
console.log(chalk.red.bold(" shutting down completed "));
|
|
118
|
-
process.exit(-1);
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
main();
|