Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function iterateOnSignedAndEncryptedMessageChunks(buffer: Buffer, callback: ChunkVisitorFunc) {
const params = {signatureLength: 128, algorithm: "RSA-SHA1", privateKey: senderPrivateKey};
const options = {
chunkSize: 2048,
cipherBlockSize: 128,
encryptBufferFunc: (chunk: Buffer) => publicEncrypt_long(chunk, receiverPublicKey, 128, 11, RSA_PKCS1_PADDING),
plainBlockSize: 128 - 11,
requestId: 10,
sequenceHeaderSize: 0, // ??
signBufferFunc: (chunk: Buffer) => makeMessageChunkSignature(chunk, params),
signatureLength: 128,
};
const securityHeader = new AsymmetricAlgorithmSecurityHeader({
receiverCertificateThumbprint,
securityPolicyUri: "http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15",
senderCertificate,
});
const msgChunkManager = new SecureMessageChunkManager("OPN", options, securityHeader, sequenceNumberGenerator);
msgChunkManager.on("chunk", (chunk: Buffer, final: boolean) => callback(null, chunk));
msgChunkManager.write(buffer, buffer.length);
msgChunkManager.end();
}
function iterate_on_signed_message_chunks(buffer, callback) {
const params = {signatureLength: 128, algorithm: "RSA-SHA1", privateKey: senderPrivateKey};
const options = {
requestId: 10,
chunkSize: 2048,
signatureLength: 128,
signingFunc: function (chunk) {
return crypto_utils.makeMessageChunkSignature(chunk, params);
}
};
const securityHeader = new AsymmetricAlgorithmSecurityHeader({
securityPolicyUri: "http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15",
senderCertificate: senderCertificate,
receiverCertificateThumbprint: null // null === no encryption ...receiverCertificateThumbprint
});
const msgChunkManager = new SecureMessageChunkManager("OPN", options, securityHeader, sequenceNumberGenerator);
msgChunkManager.on("chunk", function (chunk, final) {
callback(null, chunk);
});
msgChunkManager.write(buffer, buffer.length);
msgChunkManager.end();
}
exports.iterate_on_signed_message_chunks = iterate_on_signed_message_chunks;
algorithm: "RSA-SHA1",
privateKey: senderPrivateKey,
signatureLength: 128,
};
const options = {
chunkSize: 2048,
cipherBlockSize: 0,
plainBlockSize: 0,
requestId: 10,
sequenceHeaderSize: 0,
signBufferFunc: (chunk: Buffer) => makeMessageChunkSignature(chunk, params),
signatureLength: 128,
};
const securityHeader = new AsymmetricAlgorithmSecurityHeader({
receiverCertificateThumbprint: null, // null === no encryption ...receiverCertificateThumbprint
securityPolicyUri: "http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15",
senderCertificate,
});
const msgChunkManager = new SecureMessageChunkManager("OPN", options, securityHeader, sequenceNumberGenerator);
msgChunkManager.on("chunk", (chunk: Buffer, final: boolean) => callback(null, chunk));
msgChunkManager.write(buffer, buffer.length);
msgChunkManager.end();
}
const options = {
requestId: 10,
chunkSize: 2048,
signatureLength: 128,
signingFunc: function (chunk) {
return crypto_utils.makeMessageChunkSignature(chunk, params);
},
plainBlockSize: 128 - 11,
cipherBlockSize: 128,
encrypt_buffer: function (chunk) {
return crypto_utils.publicEncrypt_long(chunk, receiverPublicKey, 128, 11);
}
};
const securityHeader = new AsymmetricAlgorithmSecurityHeader({
securityPolicyUri: "http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15",
senderCertificate: senderCertificate,
receiverCertificateThumbprint: receiverCertificateThumbprint
});
const msgChunkManager = new SecureMessageChunkManager("OPN", options, securityHeader, sequenceNumberGenerator);
msgChunkManager.on("chunk", function (chunk, final) {
callback(null, chunk);
});
msgChunkManager.write(buffer, buffer.length);
msgChunkManager.end();
}
exports.iterate_on_signed_and_encrypted_message_chunks = iterate_on_signed_and_encrypted_message_chunks;
public update(options?: MessageChunkerOptions) {
options = options || {};
options.securityHeader = options.securityHeader ||
new AsymmetricAlgorithmSecurityHeader({securityPolicyUri: "http://opcfoundation.org/UA/SecurityPolicy#None"});
assert(_.isObject(options));
assert(_.isObject(options.securityHeader));
this.securityHeader = options.securityHeader;
this.derivedKeys = options.derivedKeys || undefined;
}
MessageChunker.prototype.update = function(options) {
options = options || {};
options.securityHeader = options.securityHeader ||
new AsymmetricAlgorithmSecurityHeader({securityPolicyUri: "http://opcfoundation.org/UA/SecurityPolicy#None"});
assert(_.isObject(options));
assert(_.isObject(options.securityHeader));
this.securityHeader = options.securityHeader;
this.derivedKeys = options.derivedKeys || null;
};