Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
readKeyPem,
RSA_PKCS1_PADDING
} from "node-opcua-crypto";
import { AsymmetricAlgorithmSecurityHeader, SymmetricAlgorithmSecurityHeader } from "node-opcua-service-secure-channel";
import { SecureMessageChunkManager, SequenceNumberGenerator } from "../source";
// tslint:disable:no-var-requires
const getFixture = require("node-opcua-test-fixtures").getFixture;
const senderCertificate = readCertificate(getFixture("certs/client_cert_1024.pem"));
const senderPrivateKey = readKeyPem(getFixture("certs/client_key_1024.pem"));
const receiverCertificate = readCertificate(getFixture("certs/server_cert_1024.pem"));
const receiverCertificateThumbprint = makeSHA1Thumbprint(receiverCertificate);
const receiverPublicKey = fs.readFileSync(getFixture("certs/server_public_key_1024.pub", "ascii")).toString();
const sequenceNumberGenerator = new SequenceNumberGenerator();
export type ChunkVisitorFunc = (err: Error | null, chunk?: Buffer) => void;
export function iterateOnSignedMessageChunks(buffer: Buffer, callback: ChunkVisitorFunc) {
const params = {
algorithm: "RSA-SHA1",
privateKey: senderPrivateKey,
signatureLength: 128,
};
const options = {
chunkSize: 2048,
cipherBlockSize: 0,
makeSHA1Thumbprint,
publicEncrypt_long,
readCertificate,
readKeyPem,
RSA_PKCS1_PADDING
} from "node-opcua-crypto";
import { AsymmetricAlgorithmSecurityHeader, SymmetricAlgorithmSecurityHeader } from "node-opcua-service-secure-channel";
import { SecureMessageChunkManager, SequenceNumberGenerator } from "../source";
// tslint:disable:no-var-requires
const getFixture = require("node-opcua-test-fixtures").getFixture;
const senderCertificate = readCertificate(getFixture("certs/client_cert_1024.pem"));
const senderPrivateKey = readKeyPem(getFixture("certs/client_key_1024.pem"));
const receiverCertificate = readCertificate(getFixture("certs/server_cert_1024.pem"));
const receiverCertificateThumbprint = makeSHA1Thumbprint(receiverCertificate);
const receiverPublicKey = fs.readFileSync(getFixture("certs/server_public_key_1024.pub", "ascii")).toString();
const sequenceNumberGenerator = new SequenceNumberGenerator();
export type ChunkVisitorFunc = (err: Error | null, chunk?: Buffer) => void;
export function iterateOnSignedMessageChunks(buffer: Buffer, callback: ChunkVisitorFunc) {
const params = {
algorithm: "RSA-SHA1",
privateKey: senderPrivateKey,
signatureLength: 128,
};
function construct_makeMessageChunkSignatureForTest() {
const privateKey = fs.readFileSync(getFixture("certs/server_key_1024.pem")).toString("ascii");
return (chunk: Buffer) => {
const options = {
algorithm: "RSA-SHA256",
privateKey,
signatureLength: 128,
};
const buf = makeMessageChunkSignature(chunk, options); // Buffer
assert(buf instanceof Buffer, "expecting a Buffer");
return buf;
};
}
function construct_makeMessageChunkSignatureForTest() {
const privateKey = fs.readFileSync(getFixture("certs/server_key_1024.pem")).toString("ascii");
return function (chunk) {
const options = {
algorithm: "RSA-SHA256",
signatureLength: 128,
privateKey: privateKey
};
const buf = crypto_utils.makeMessageChunkSignature(chunk, options); // Buffer
assert(buf instanceof Buffer, "expecting a Buffer");
return buf;
};
}
exports.makeMessageChunkSignatureForTest = construct_makeMessageChunkSignatureForTest();
const hexDump = require("node-opcua-debug").hexDump;
const SecureMessageChunkManager = require("../src/secure_message_chunk_manager").SecureMessageChunkManager;
const SequenceNumberGenerator = require("../src/sequence_number_generator").SequenceNumberGenerator;
const AsymmetricAlgorithmSecurityHeader = require("node-opcua-service-secure-channel").AsymmetricAlgorithmSecurityHeader;
const SymmetricAlgorithmSecurityHeader = require("node-opcua-service-secure-channel").SymmetricAlgorithmSecurityHeader;
const crypto_utils = require("node-opcua-crypto");
const fs = require("fs");
const path = require("path");
const getFixture = require("node-opcua-test-fixtures").getFixture;
const senderCertificate = crypto_utils.readCertificate(getFixture("certs/client_cert_1024.pem"));
const senderPrivateKey = crypto_utils.readKeyPem(getFixture("certs/client_key_1024.pem"));
const receiverCertificate = crypto_utils.readCertificate(getFixture("certs/server_cert_1024.pem"));
const receiverCertificateThumbprint = crypto_utils.makeSHA1Thumbprint(receiverCertificate);
const receiverPublicKey = fs.readFileSync(getFixture("certs/server_public_key_1024.pub"));
const sequenceNumberGenerator = new SequenceNumberGenerator();
/**
* @method iterate_on_signed_message_chunks
* @param buffer
* @param callback {Function}
* @param callback.err {Error}
* @param callback.chunks {Array}
*
function construct_verifyMessageChunkSignatureForTest() {
const publicKey = fs.readFileSync(getFixture("certs/server_public_key_1024.pub")).toString("ascii");
return function (chunk) {
assert(chunk instanceof Buffer);
const options = {
algorithm: "RSA-SHA256",
signatureLength: 128,
publicKey: publicKey
};
return crypto_utils.verifyChunkSignature(chunk, options);
};
}
exports.verifyMessageChunkSignatureForTest = construct_verifyMessageChunkSignatureForTest();
var should = require("should");
var os = require("os");
var _ = require("underscore");
var opcua = require("../index");
var OPCUAServer = opcua.OPCUAServer;
var OPCUAClient = opcua.OPCUAClient;
var getFixture = require("node-opcua-test-fixtures").getFixture;
var empty_nodeset_filename = getFixture("fixture_empty_nodeset2.xml");
var debugLog = require("node-opcua-debug").make_debugLog(__filename);
var port = 4000;
var describe = require("node-opcua-leak-detector").describeWithLeakDetector;
describe("Testing ChannelSecurityToken lifetime", function () {
this.timeout(Math.max(100000,this._timeout));
var server, client;
var endpointUrl;
beforeEach(function (done) {
export function construct_verifyMessageChunkSignatureForTest() {
const publicKey = fs.readFileSync(getFixture("certs/server_public_key_1024.pub")).toString("ascii");
return (chunk: Buffer) => {
assert(chunk instanceof Buffer);
const options = {
algorithm: "RSA-SHA256",
publicKey,
signatureLength: 128
};
return verifyChunkSignature(chunk, options);
};
}
const AsymmetricAlgorithmSecurityHeader = require("node-opcua-service-secure-channel").AsymmetricAlgorithmSecurityHeader;
const SymmetricAlgorithmSecurityHeader = require("node-opcua-service-secure-channel").SymmetricAlgorithmSecurityHeader;
const crypto_utils = require("node-opcua-crypto");
const fs = require("fs");
const path = require("path");
const getFixture = require("node-opcua-test-fixtures").getFixture;
const senderCertificate = crypto_utils.readCertificate(getFixture("certs/client_cert_1024.pem"));
const senderPrivateKey = crypto_utils.readKeyPem(getFixture("certs/client_key_1024.pem"));
const receiverCertificate = crypto_utils.readCertificate(getFixture("certs/server_cert_1024.pem"));
const receiverCertificateThumbprint = crypto_utils.makeSHA1Thumbprint(receiverCertificate);
const receiverPublicKey = fs.readFileSync(getFixture("certs/server_public_key_1024.pub"));
const sequenceNumberGenerator = new SequenceNumberGenerator();
/**
* @method iterate_on_signed_message_chunks
* @param buffer
* @param callback {Function}
* @param callback.err {Error}
* @param callback.chunks {Array}
*
*/
function iterate_on_signed_message_chunks(buffer, callback) {
const params = {signatureLength: 128, algorithm: "RSA-SHA1", privateKey: senderPrivateKey};
const options = {