Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
} 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);
}
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;
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);
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);
}
};
"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);
}
}
}