I am trying to connect to an opcua server with unknown securityMode and securityPolicy. Probably I have a basic understanding problem, but according to the OPCUA specification I can get the EndpointDescription via the local DiscoveryServer and then open a SecureChannel (session).
Currently I connect to the server without specifying the security settings, read out the endpoints and would then select an appropriate security setting and reconnect.
const getEndpoints = function (endpointUrl) {
return new Promise(function (resolve, reject) {
let client = new opcua.OPCUAClient();
client.connect(endpointUrl, function (err) {
if(err) reject(new Error(err));
client.getEndpointsRequest(function (err,endpoints) {
let reducedEndpoints = endpoints.map(endpoint =>
({
endpointUrl: endpoint.endpointUrl,
securityMode: endpoint.securityMode,
securityPolicy: endpoint.securityPolicyUri,
})
);
resolve(endpoints);
// resolve(reducedEndpoints);
client.disconnect();
})
})
})
}
const connect = function (endpointUrl, options) {
return new Promise(function (resolve, reject) {
const defaultOptions = {
connectionStrategy: {
maxRetry: 6,
},
keepSessionAlive: true,
endpoint_must_exist: false,
securityMode: options.MessageSecurityMode.NONE,
securityPolicy: SecurityPolicy.None,
};
let client = new opcua.OPCUAClient(Object.assign({}, defaultOptions, options));
client.connect(endpointUrl, function (err) {
if(err) {
reject(new Error(err));
}
resolve(client)
});
});
};
That doesn't feel right. It would be nice if someone would help me with an example.
Best Regards