How to use the node-opcua-status-code.StatusCodes.BadCommunicationError function in node-opcua-status-code

To help you get started, we’ve selected a few node-opcua-status-code 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-secure-channel / source / server / server_secure_channel_layer.ts View on Github external
});
        } else {
            if (request.schema.name === "CloseSecureChannelRequest") {
                console.log("WARNING : RECEIVED a CloseSecureChannelRequest with MSGTYPE=" + msgType);
                this.close();
            } else {
                if (doPerfMonitoring) {
                    // record tick 1 : after message has been received, before message processing
                    this._tick1 = get_clock_tick();
                }

                if (this.securityToken && channelId !== this.securityToken.channelId) {
                    // response = new ServiceFault({responseHeader: {serviceResult: certificate_status}});
                    debugLog("Invalid channelId detected =", channelId, " <> ", this.securityToken.channelId);
                    return this.send_error_and_abort(
                        StatusCodes.BadCommunicationError,
                        "Invalid Channel Id specified " + this.securityToken.channelId,
                        message, () => {

                        });
                }

                /**
                 * notify the observer that a OPCUA message has been received.
                 * It is up to one observer to call send_response or send_error_and_abort to complete
                 * the transaction.
                 *
                 * @event message
                 * @param message
                 */
                this.emit("message", message);
            }
github node-opcua / node-opcua / packages / node-opcua-secure-channel / source / server / server_secure_channel_layer.ts View on Github external
const request = message.request as OpenSecureChannelRequest;
        const requestId = message.requestId;

        assert(requestId > 0);
        assert(_.isFinite(request.requestHeader.requestHandle));

        let description;

        // expecting a OpenChannelRequest as first communication message
        if (!((request as any) instanceof OpenSecureChannelRequest)) {
            description = "Expecting OpenSecureChannelRequest";
            console.log(
                chalk.red("ERROR"),
                "BadCommunicationError: expecting a OpenChannelRequest as first communication message"
            );
            return this._send_error(StatusCodes.BadCommunicationError, description, message, callback);
        }

        const asymmetricSecurityHeader = this.messageBuilder.securityHeader as AsymmetricAlgorithmSecurityHeader;

        const securityPolicy = message.securityHeader ? fromURI(asymmetricSecurityHeader.securityPolicyUri) : SecurityPolicy.Invalid;

        // check security header
        const securityPolicyStatus = isValidSecurityPolicy(securityPolicy);
        if (securityPolicyStatus !== StatusCodes.Good) {
            description = " Unsupported securityPolicyUri " + asymmetricSecurityHeader.securityPolicyUri;
            return this._send_error(securityPolicyStatus, description, message, callback);
        }
        // check certificate

        this.securityMode = request.securityMode;
        this.securityPolicy = securityPolicy;
github node-opcua / node-opcua / packages / node-opcua-secure-channel / src / server / server_secure_channel_layer.js View on Github external
const request = message.request;
    const requestId = message.requestId;

    assert(requestId > 0);
    assert(_.isFinite(request.requestHeader.requestHandle));
    let description;

    // expecting a OpenChannelRequest as first communication message
    if (!(request instanceof OpenSecureChannelRequest)) {
        description = "Expecting OpenSecureChannelRequest";
        console.log(
            "ERROR".red,
            "BadCommunicationError: expecting a OpenChannelRequest as first communication message"
        );
        return _send_error.call(this, StatusCodes.BadCommunicationError, description, message, callback);
    }

    const securityPolicy = securityPolicy_m.fromURI(message.securityHeader.securityPolicyUri);

    // check security header
    const check_security_policy = isValidSecurityPolicy(securityPolicy);
    if (check_security_policy !== StatusCodes.Good) {
        description = " Unsupported securityPolicyUri " + self.messageBuilder.securityHeader.securityPolicyUri;
        return _send_error.call(this, check_security_policy, description, message, callback);
    }

    assert(request.securityMode);
    self.securityMode = request.securityMode;
    self.messageBuilder.securityMode = self.securityMode;

    const has_endpoint = self.has_endpoint_for_security_mode_and_policy(self.securityMode, securityPolicy);
github node-opcua / node-opcua / packages / node-opcua-transport / src / server_tcp_transport.js View on Github external
return self._abortWithError(StatusCodes.BadConnectionRejected,
                "Buffer size too small (should be at least " + minimumBufferSize , callback);

        }
        // the helloMessage shall only be received once.
        self._helloreceived = true;

        self._send_ACK_response(helloMessage);

        callback(null); // no Error


    } else {
        // invalid packet , expecting HEL
        debugLog("BadCommunicationError ".red, "Expecting 'HEL' message to initiate communication");
        self._abortWithError(StatusCodes.BadCommunicationError, "Expecting 'HEL' message to initiate communication", callback);
    }

};
github node-opcua / node-opcua / packages / node-opcua-transport / source / server_tcp_transport.ts View on Github external
"Buffer size too small (should be at least " + minimumBufferSize, callback);
            }
            // the helloMessage shall only be received once.
            this._helloReceived = true;
            this._send_ACK_response(helloMessage);
            callback(); // no Error

        } else {

            // invalid packet , expecting HEL
            /* istanbul ignore next*/
            if (doDebug) {
                debugLog(chalk.red("BadCommunicationError ") + "Expecting 'HEL' message to initiate communication");
            }
            this._abortWithError(
              StatusCodes.BadCommunicationError,
              "Expecting 'HEL' message to initiate communication", callback);

        }
    }
}