Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
encryptBufferWithDerivedKeys,
makeMessageChunkSignature,
makeMessageChunkSignatureWithDerivedKeys,
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,
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,
};
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 iterate_on_signed_message_chunks(buffer, callback) {
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}
*
setTimeout(function () {
callback(null, {
process: server_exec,
pid_collected: pid_collected,
endpointUrl: "opc.tcp://" + os.hostname() + ":" + port + "/UA/SampleServer",
serverCertificate: crypto_utils.readCertificate(serverCertificateFilename)
});
}, 100);
}
function _load_certificate(certificateFilename: string): Certificate {
const der = readCertificate(certificateFilename);
return der;
}
function _load_certificate(certificate_file) {
return crypto_utils.readCertificate(certificate_file);
}
function _load_private_key(private_key_file) {