Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.securityHeader = new AsymmetricAlgorithmSecurityHeader({
securityPolicyUri: "http://opcfoundation.org/UA/SecurityPolicy#None",
senderCertificate: null,
receiverCertificateThumbprint: null
});
self.messageChunker = new MessageChunker({
securityHeader: self.securityHeader // for OPN
});
if (doPerfMonitoring) {
self._tick0 = 0;
}
self.securityMode = MessageSecurityMode.INVALID;
self.timeoutId = 0;
self._transactionsCount = 0;
self.sessionTokens = {};
//xx #422 self.setMaxListeners(200); // increase the number of max listener
}
function _open_secure_channel_request(is_initial, callback) {
/* jshint validthis: true */
const self = this;
assert(self.securityMode !== MessageSecurityMode.INVALID, "invalid security mode");
// from the specs:
// The OpenSecureChannel Messages are not signed or encrypted if the SecurityMode is None. The
// Nonces are ignored and should be set to null. The SecureChannelId and the TokenId are still
// assigned but no security is applied to Messages exchanged via the channel.
const msgType = "OPN";
const requestType = (is_initial) ? SecurityTokenRequestType.ISSUE : SecurityTokenRequestType.RENEW;
self.clientNonce = _build_client_nonce.call(self);
self._isOpened = !is_initial;
// OpenSecureChannel
const msg = new OpenSecureChannelRequest({
clientProtocolVersion: self.protocolVersion,
MessageBuilder.prototype._decrypt_MSG = function (binaryStream) {
assert(this.securityHeader instanceof SymmetricAlgorithmSecurityHeader);
assert(this.securityMode !== MessageSecurityMode.NONE);
assert(this.securityMode !== MessageSecurityMode.INVALID);
assert(this.securityPolicy !== SecurityPolicy.None);
assert(this.securityPolicy !== SecurityPolicy.Invalid);
// Check security token
// securityToken may have been renewed
const securityTokenData = this._select_matching_token(this.securityHeader.tokenId);
if (!securityTokenData) {
this._report_error("Security token data for token " + this.securityHeader.tokenId + " doesn't exist");
return false;
}
assert(securityTokenData.hasOwnProperty("derivedKeys"));
// SecurityToken may have expired, in this case the MessageBuilder shall reject the message
if (securityTokenData.securityToken.expired) {
this._report_error("Security token has expired : tokenId " + securityTokenData.securityToken.tokenId);
function MessageBuilder(options) {
options = options || {};
MessageBuilderBase.call(this, options);
this.securityPolicy = SecurityPolicy.Invalid; // not known yet
this.securityMode = options.securityMode || MessageSecurityMode.INVALID; // not known yet
this.objectFactory = options.objectFactory || require("node-opcua-factory");
assert(_.isFunction(this.objectFactory.constructObject), " the objectFactory must provide a constructObject method");
this.previous_sequenceNumber = -1; // means unknown
assert(_.isFinite(this.previous_sequenceNumber));
}
util.inherits(MessageBuilder, MessageBuilderBase);
function getOptionsForSymmetricSignAndEncrypt(securityMode, derivedKeys) {
assert(derivedKeys.hasOwnProperty("signatureLength"));
assert(securityMode !== MessageSecurityMode.NONE && securityMode !== MessageSecurityMode.INVALID);
let options = {
signatureLength: derivedKeys.signatureLength,
signingFunc: function (chunk) {
return crypto_utils.makeMessageChunkSignatureWithDerivedKeys(chunk, derivedKeys);
}
};
if (securityMode === MessageSecurityMode.SIGNANDENCRYPT) {
options = _.extend(options, {
plainBlockSize: derivedKeys.encryptingBlockSize,
cipherBlockSize: derivedKeys.encryptingBlockSize,
encrypt_buffer: function (chunk) {
return crypto_utils.encryptBufferWithDerivedKeys(chunk, derivedKeys);
}
});
MessageBuilder.prototype.setSecurity = function (securityMode, securityPolicy) {
assert(this.securityMode === MessageSecurityMode.INVALID, "security already set");
this.securityPolicy = SecurityPolicy.get(securityPolicy);
this.securityMode = MessageSecurityMode.get(securityMode);
assert(this.securityPolicy !== undefined, "invalid security policy " + securityPolicy);
assert(this.securityMode !== undefined, "invalid security mode " + securityMode);
assert(this.securityPolicy !== SecurityPolicy.Invalid);
assert(this.securityMode !== MessageSecurityMode.INVALID);
};
MessageBuilder.prototype.setSecurity = function (securityMode, securityPolicy) {
assert(this.securityMode === MessageSecurityMode.INVALID, "security already set");
this.securityPolicy = SecurityPolicy.get(securityPolicy);
this.securityMode = MessageSecurityMode.get(securityMode);
assert(this.securityPolicy !== undefined, "invalid security policy " + securityPolicy);
assert(this.securityMode !== undefined, "invalid security mode " + securityMode);
assert(this.securityPolicy !== SecurityPolicy.Invalid);
assert(this.securityMode !== MessageSecurityMode.INVALID);
};