How to use the node-opcua-crypto.computeDerivedKeys function in node-opcua-crypto

To help you get started, we’ve selected a few node-opcua-crypto 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 / source / security_policy.ts View on Github external
export function computeDerivedKeys(self: CryptoFactory, serverNonce: Nonce, clientNonce: Nonce): DerivedKeys1 {

    // calculate derived keys

    if (clientNonce && serverNonce) {
        const options = {
            algorithm: self.symmetricEncryptionAlgorithm,
            encryptingBlockSize: self.encryptingBlockSize,
            encryptingKeyLength: self.derivedEncryptionKeyLength,
            sha1or256: self.sha1or256,
            signatureLength: self.signatureLength,
            signingKeyLength: self.derivedSignatureKeyLength,
        };
        return {
            algorithm: null,
            derivedClientKeys: computeDerivedKeys_ext(serverNonce, clientNonce, options),
            derivedServerKeys: computeDerivedKeys_ext(clientNonce, serverNonce, options),
        };
    } else {
        return {derivedClientKeys: null, derivedServerKeys: null, algorithm: null};
    }
}
github node-opcua / node-opcua / packages / node-opcua-secure-channel / source / security_policy.ts View on Github external
// calculate derived keys

    if (clientNonce && serverNonce) {
        const options = {
            algorithm: self.symmetricEncryptionAlgorithm,
            encryptingBlockSize: self.encryptingBlockSize,
            encryptingKeyLength: self.derivedEncryptionKeyLength,
            sha1or256: self.sha1or256,
            signatureLength: self.signatureLength,
            signingKeyLength: self.derivedSignatureKeyLength,
        };
        return {
            algorithm: null,
            derivedClientKeys: computeDerivedKeys_ext(serverNonce, clientNonce, options),
            derivedServerKeys: computeDerivedKeys_ext(clientNonce, serverNonce, options),
        };
    } else {
        return {derivedClientKeys: null, derivedServerKeys: null, algorithm: null};
    }
}
github node-opcua / node-opcua / packages / node-opcua-secure-channel / test_helpers / fake_message_chunk_factory.ts View on Github external
const secret = Buffer.from("My Little Secret");
const seed = Buffer.from("My Little Seed");
const globalOptions = {
    signingKeyLength: 16,

    encryptingKeyLength: 16,

    encryptingBlockSize: 16,

    signatureLength: 20,

    algorithm: "aes-128-cbc"
};

export const derivedKeys = computeDerivedKeys(secret, seed, globalOptions);

export function iterateOnSymmetricEncryptedChunk(buffer: Buffer, callback: ChunkVisitorFunc) {

    const options: any = {
        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;
github node-opcua / node-opcua / packages / node-opcua-secure-channel / test_helpers / fake_message_chunk_factory.js View on Github external
msgChunkManager.write(buffer, buffer.length);
    msgChunkManager.end();
}
exports.iterate_on_signed_and_encrypted_message_chunks = iterate_on_signed_and_encrypted_message_chunks;


const secret = Buffer.from("My Little Secret");
const seed = Buffer.from("My Little Seed");
const options = {
    signingKeyLength: 16,
    encryptingKeyLength: 16,
    encryptingBlockSize: 16,
    signatureLength: 20,
    algorithm: "aes-128-cbc"
};
const derivedKeys = crypto_utils.computeDerivedKeys(secret, seed, options);
exports.derivedKeys = derivedKeys;

function iterate_on_symmetric_encrypted_chunk(buffer, callback) {

    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) {
github node-opcua / node-opcua / packages / node-opcua-secure-channel / src / security_policy.js View on Github external
const derivedKeys = {
        derivedClientKeys: null,
        derivedServerKeys: null,
        algorithm: null
    };

    if (clientNonce && serverNonce) {
        const options = {
            signingKeyLength: self.derivedSignatureKeyLength,
            encryptingKeyLength: self.derivedEncryptionKeyLength,
            encryptingBlockSize: self.encryptingBlockSize,
            signatureLength: self.signatureLength,
            algorithm: self.symmetricEncryptionAlgorithm,
            sha1or256: self.sha1or256
        };
        derivedKeys.derivedClientKeys = crypto_utils.computeDerivedKeys(serverNonce, clientNonce, options);
        derivedKeys.derivedServerKeys = crypto_utils.computeDerivedKeys(clientNonce, serverNonce, options);
    }
    return derivedKeys;
}
github node-opcua / node-opcua / packages / node-opcua-secure-channel / src / security_policy.js View on Github external
derivedClientKeys: null,
        derivedServerKeys: null,
        algorithm: null
    };

    if (clientNonce && serverNonce) {
        const options = {
            signingKeyLength: self.derivedSignatureKeyLength,
            encryptingKeyLength: self.derivedEncryptionKeyLength,
            encryptingBlockSize: self.encryptingBlockSize,
            signatureLength: self.signatureLength,
            algorithm: self.symmetricEncryptionAlgorithm,
            sha1or256: self.sha1or256
        };
        derivedKeys.derivedClientKeys = crypto_utils.computeDerivedKeys(serverNonce, clientNonce, options);
        derivedKeys.derivedServerKeys = crypto_utils.computeDerivedKeys(clientNonce, serverNonce, options);
    }
    return derivedKeys;
}