Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
throw new Error(" invalid security ");
}
// istanbul ignore next
if (securityMode !== MessageSecurityMode.None && securityPolicy === SecurityPolicy.None) {
throw new Error(" invalid security ");
}
//
const port = this.port;
// resource Path is a string added at the end of the url such as "/UA/Server"
const resourcePath = (options.resourcePath || "").replace(/\\/g, "/");
assert(resourcePath.length === 0 || resourcePath.charAt(0) === "/");
const hostname = options.hostname || getFullyQualifiedDomainName();
const endpointUrl = `opc.tcp://${hostname}:${port}${resourcePath}`;
const endpoint_desc = this.getEndpointDescription(securityMode, securityPolicy, endpointUrl);
// istanbul ignore next
if (endpoint_desc) {
throw new Error(" endpoint already exist");
}
// now build endpointUrl
this._endpoints.push(_makeEndpointDescription({
endpointUrl,
hostname,
port,
server: this.serverInfo,
throw new Error(" invalid security ");
}
// istanbul ignore next
if (securityMode !== MessageSecurityMode.None && securityPolicy === SecurityPolicy.None) {
throw new Error(" invalid security ");
}
//
const port = this.port;
// resource Path is a string added at the end of the url such as "/UA/Server"
const resourcePath = (options.resourcePath || "").replace(/\\/g, "/");
assert(resourcePath.length === 0 || resourcePath.charAt(0) === "/", "resourcePath should start with /");
const hostname = options.hostname || getFullyQualifiedDomainName();
const endpointUrl = `opc.tcp://${hostname}:${port}${resourcePath}`;
const endpoint_desc = this.getEndpointDescription(securityMode, securityPolicy, endpointUrl);
// istanbul ignore next
if (endpoint_desc) {
throw new Error(" endpoint already exist");
}
// now build endpointUrl
this._endpoints.push(_makeEndpointDescription({
endpointUrl,
hostname,
port,
server: this.serverInfo,
public addEndpointDescription(
securityMode: MessageSecurityMode,
securityPolicy: SecurityPolicy,
options?: EndpointDescriptionParams
) {
if (!options) {
options = { hostname: getFullyQualifiedDomainName() };
}
options.allowAnonymous = (options.allowAnonymous === undefined) ? true : options.allowAnonymous;
// istanbul ignore next
if (securityMode === MessageSecurityMode.None && securityPolicy !== SecurityPolicy.None) {
throw new Error(" invalid security ");
}
// istanbul ignore next
if (securityMode !== MessageSecurityMode.None && securityPolicy === SecurityPolicy.None) {
throw new Error(" invalid security ");
}
//
const port = this.port;
async function install(this: OPCUAServerPartial): Promise {
if (!this.$$privateKeyPEM) {
this.$$privateKeyPEM =
await promisify(fs.readFile)(this.serverCertificateManager.privateKey, "utf8");
}
if (!this.$$certificateChain) {
const certificateFile = path.join(this.serverCertificateManager.rootDir, "own/certs/certificate.pem");
const exists = await (promisify(fs.exists)(certificateFile));
if (!exists) {
// this is the first time server is launch
// let's create a default self signed certificate with limited validity
const fqdn = await getFullyQualifiedDomainName();
const ipAddresses = await getIpAddresses();
const applicationUri =
(this.serverInfo ? this.serverInfo!.applicationUri! : null) || "uri:MISSING";
const options = {
applicationUri: this.serverInfo!.applicationUri!,
dns: [fqdn],
ip: ipAddresses,
subject: "/CN=MyCommonName;/L=Paris",
startDate: new Date(),
public addEndpointDescription(
securityMode: MessageSecurityMode,
securityPolicy: SecurityPolicy,
options?: EndpointDescriptionParams
) {
if (!options) {
options = { hostname: getFullyQualifiedDomainName() };
}
options.allowAnonymous = (options.allowAnonymous === undefined) ? true : options.allowAnonymous;
// istanbul ignore next
if (securityMode === MessageSecurityMode.None && securityPolicy !== SecurityPolicy.None) {
throw new Error(" invalid security ");
}
// istanbul ignore next
if (securityMode !== MessageSecurityMode.None && securityPolicy === SecurityPolicy.None) {
throw new Error(" invalid security ");
}
//
const port = this.port;
public addStandardEndpointDescriptions(options?: AddStandardEndpointDescriptionsParam) {
options = options || {};
options.securityModes = options.securityModes || defaultSecurityModes;
options.securityPolicies = options.securityPolicies || defaultSecurityPolicies;
const defaultHostname = options.hostname || getFullyQualifiedDomainName();
let hostnames: string[] = [ defaultHostname ];
options.alternateHostname = options.alternateHostname || [];
if (typeof options.alternateHostname === "string") {
options.alternateHostname = [ options.alternateHostname];
}
hostnames = _.uniq(hostnames.concat(options.alternateHostname as string[]));
for (const alternateHostname of hostnames ) {
const optionsE = options as EndpointDescriptionParams;
optionsE.hostname = alternateHostname;
if (options.securityModes.indexOf(MessageSecurityMode.None) >= 0) {
this.addEndpointDescription(MessageSecurityMode.None, SecurityPolicy.None, optionsE);
public addStandardEndpointDescriptions(options?: AddStandardEndpointDescriptionsParam) {
options = options || {};
options.securityModes = options.securityModes || defaultSecurityModes;
options.securityPolicies = options.securityPolicies || defaultSecurityPolicies;
const defaultHostname = options.hostname || getFullyQualifiedDomainName();
let hostnames: string[] = [ defaultHostname ];
options.alternateHostname = options.alternateHostname || [];
if (typeof options.alternateHostname === "string") {
options.alternateHostname = [ options.alternateHostname];
}
hostnames = _.uniq(hostnames.concat(options.alternateHostname as string[]));
for (const alternateHostname of hostnames ) {
const optionsE = options as EndpointDescriptionParams;
optionsE.hostname = alternateHostname;
if (options.securityModes.indexOf(MessageSecurityMode.None) >= 0) {