How to use node-opcua-hostname - 10 common examples

To help you get started, we’ve selected a few node-opcua-hostname examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / node-opcua-client / src / opcua_client.js View on Github external
}

util.inherits(OPCUAClient, OPCUAClientBase);


OPCUAClient.prototype._nextSessionName = function () {
    if (!this.___sessionName_counter) {
        this.___sessionName_counter = 0;
    }
    this.___sessionName_counter += 1;
    return this.clientName + this.___sessionName_counter;
};

const makeApplicationUrn = require("node-opcua-common").makeApplicationUrn;
const hostname = require("node-opcua-hostname").get_fully_qualified_domain_name();

OPCUAClient.prototype._getApplicationUri = function () {

    // get applicationURI from certificate
    const exploreCertificate = require("node-opcua-crypto").exploreCertificate;

    const certificate = this.getCertificate();
    let applicationUri;
    if (certificate) {
        const e = exploreCertificate(certificate);
        if (!e.tbsCertificate.extensions  || !e.tbsCertificate.extensions.subjectAltName) {
            console.log(chalk.red(" Warning: client certificate is invalid : subjectAltName is missing"));
            applicationUri = makeApplicationUrn(hostname, this.applicationName);
        } else {
            applicationUri = e.tbsCertificate.extensions.subjectAltName.uniformResourceIdentifier[0];
        }
github node-opcua / node-opcua / packages / node-opcua-server / source / server_end_point.ts View on Github external
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,
github node-opcua / node-opcua / packages / node-opcua-server / source / server_end_point.ts View on Github external
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,
github node-opcua / node-opcua / packages / node-opcua-server / source / server_end_point.ts View on Github external
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;
github node-opcua / node-opcua / packages / node-opcua-server-configuration / source / server / install_push_certitifate_management.ts View on Github external
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(),
github node-opcua / node-opcua / packages / node-opcua-server / source / server_end_point.ts View on Github external
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;
github node-opcua / node-opcua / packages / node-opcua-server / source / register_server_manager.ts View on Github external
public start(callback: (err?: Error) => void) {

        debugLog("RegisterServerManager#start");
        if (this.state !== RegisterServerManagerStatus.INACTIVE) {
            return callback(new Error("RegisterServer process already started")); // already started
        }

        this.discoveryServerEndpointUrl  = resolveFullyQualifiedDomainName(this.discoveryServerEndpointUrl);

        // perform initial registration + automatic renewal
        this._establish_initial_connection((err?: Error) => {

            if (err) {
                debugLog("RegisterServerManager#start => _establish_initial_connection has failed");
                return callback(err);
            }

            this._setState(RegisterServerManagerStatus.REGISTERING);

            this._registerServer(true, (err1?: Error) => {

                if (this.state !== RegisterServerManagerStatus.REGISTERING) {
                    debugLog("RegisterServerManager#start )=> Registration has been cancelled");
                    return callback(new Error("Registration has been cancelled"));
github node-opcua / node-opcua / packages / node-opcua-server / source / server_end_point.ts View on Github external
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);
github node-opcua / node-opcua / packages / node-opcua-server / source / server_end_point.ts View on Github external
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) {
github node-opcua / node-opcua / packages / node-opcua-server / source / server_end_point.ts View on Github external
(endpoint as any).__defineGetter__("endpointUrl", () => {
        return resolveFullyQualifiedDomainName(options.endpointUrl);
    });

node-opcua-hostname

pure nodejs OPCUA SDK - module hostname

MIT
Latest version published 5 months ago

Package Health Score

76 / 100
Full package analysis