How to use the node-opcua-service-secure-channel.SymmetricAlgorithmSecurityHeader function in node-opcua-service-secure-channel

To help you get started, we’ve selected a few node-opcua-service-secure-channel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / node-opcua-secure-channel / test_helpers / signature_helpers.ts View on Github external
export function performMessageChunkManagerTest(options: SecureMessageChunkManagerOptions) {

    options = options || {};
    const securityHeader = new SymmetricAlgorithmSecurityHeader();

    const bodySize = 32;
    const headerSize = 12 + securityHeader.binaryStoreSize();

    options.signatureLength = options.signatureLength || 0;   // 128 bytes for signature
    options.chunkSize = bodySize + options.signatureLength + headerSize + 8;    // bodySize useful bytes

    options.requestId = 1;

    const sequenceNumberGenerator = new SequenceNumberGenerator();

    const msgChunkManager = new SecureMessageChunkManager(
      "HEL", options, securityHeader, sequenceNumberGenerator
    );

    const chunks: Buffer[] = [];
github node-opcua / node-opcua / packages / node-opcua-secure-channel / source / message_chunker.ts View on Github external
assert(_.isFunction(messageChunkCallback));

        // calculate message size ( with its  encodingDefaultBinary)
        const binSize = message.binaryStoreSize() + 4;

        const stream = new BinaryStream(binSize);
        this._stream = stream;

        encodeExpandedNodeId(message.schema.encodingDefaultBinary!, stream);
        message.encode(stream);

        let securityHeader;
        if (msgType === "OPN") {
            securityHeader = this.securityHeader;
        } else {
            securityHeader = new SymmetricAlgorithmSecurityHeader({tokenId: options.tokenId});
        }

        const chunkManager = new SecureMessageChunkManager(
            msgType, options, securityHeader, this.sequenceNumberGenerator
        );

        chunkManager
            .on("chunk", (messageChunk: Buffer) => {
                messageChunkCallback(messageChunk);
            })
            .on("finished", ()  => {
                messageChunkCallback(null);
            });

        chunkManager.write(stream.buffer, stream.buffer.length);
github node-opcua / node-opcua / packages / node-opcua-secure-channel / src / message_chunker.js View on Github external
assert(_.isFunction(messageChunkCallback));

    // calculate message size ( with its  encodingDefaultBinary)
    const binSize = message.binaryStoreSize() + 4;
    
    const stream = new BinaryStream(binSize);
    this._stream = stream;

    ec.encodeExpandedNodeId(message.encodingDefaultBinary, stream);
    message.encode(stream);

    let securityHeader;
    if (msgType === "OPN") {
        securityHeader = this.securityHeader;
    } else {
        securityHeader = new SymmetricAlgorithmSecurityHeader({tokenId: options.tokenId});
    }

    const secure_chunker = new SecureMessageChunkManager(
        msgType, options, securityHeader, this.sequenceNumberGenerator
    )
        .on("chunk", function (messageChunk) {
            messageChunkCallback(messageChunk);
        })
        .on("finished", function () {
            messageChunkCallback(null);
        });

    secure_chunker.write(stream._buffer, stream._buffer.length);
    secure_chunker.end();
};
github node-opcua / node-opcua / packages / node-opcua-secure-channel / test_helpers / fake_message_chunk_factory.ts View on Github external
chunkSize: 1024,
        encryptBufferFunc: null,
        plainBlockSize: 0,
        requestId: 10,
        signBufferFunc: null,
        signatureLength: 0,
    };

    options.signatureLength = derivedKeys.signatureLength;
    options.signBufferFunc = (chunk: Buffer) => makeMessageChunkSignatureWithDerivedKeys(chunk, derivedKeys);

    options.plainBlockSize = derivedKeys.encryptingBlockSize;
    options.cipherBlockSize = derivedKeys.encryptingBlockSize;
    options.encryptBufferFunc = (chunk: Buffer) => encryptBufferWithDerivedKeys(chunk, derivedKeys);

    const securityHeader = new SymmetricAlgorithmSecurityHeader({
        tokenId: 10
    });

    const msgChunkManager = new SecureMessageChunkManager("MSG", options, securityHeader, sequenceNumberGenerator);
    msgChunkManager.on("chunk", (chunk, final) => callback(null, chunk));
    msgChunkManager.write(buffer, buffer.length);
    msgChunkManager.end();
}
github node-opcua / node-opcua / packages / node-opcua-secure-channel / test_helpers / fake_message_chunk_factory.js View on Github external
const options = {
        requestId: 10,
        chunkSize: 1024
    };

    options.signatureLength = derivedKeys.signatureLength;
    options.signingFunc = function (chunk) {
        return crypto_utils.makeMessageChunkSignatureWithDerivedKeys(chunk, derivedKeys);
    };
    options.plainBlockSize = derivedKeys.encryptingBlockSize;
    options.cipherBlockSize = derivedKeys.encryptingBlockSize;
    options.encrypt_buffer = function (chunk) {
        return crypto_utils.encryptBufferWithDerivedKeys(chunk, derivedKeys);
    };

    const securityHeader = new SymmetricAlgorithmSecurityHeader({
        tokenId: 10
    });

    const msgChunkManager = new SecureMessageChunkManager("MSG", options, securityHeader, sequenceNumberGenerator);
    msgChunkManager.on("chunk", function (chunk, final) {
        callback(null, chunk);
    });
    msgChunkManager.write(buffer, buffer.length);
    msgChunkManager.end();
}
exports.iterate_on_symmetric_encrypted_chunk = iterate_on_symmetric_encrypted_chunk;
github node-opcua / node-opcua / packages / node-opcua-secure-channel / source / secure_message_chunk_manager.ts View on Github external
export function chooseSecurityHeader(msgType: string): SecurityHeader {
    return msgType === "OPN" ? new AsymmetricAlgorithmSecurityHeader() : new SymmetricAlgorithmSecurityHeader();
}
github node-opcua / node-opcua / packages / node-opcua-secure-channel / src / secure_message_chunk_manager.js View on Github external
function chooseSecurityHeader(msgType) {
    const securityHeader =
        msgType === "OPN" ? new AsymmetricAlgorithmSecurityHeader() : new SymmetricAlgorithmSecurityHeader();
    return securityHeader;
}