Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ClientSecureChannelLayer.prototype._construct_security_header = function () {
const self = this;
assert(self.hasOwnProperty("securityMode"));
assert(self.hasOwnProperty("securityPolicy"));
self.receiverCertificate = self.serverCertificate;
let securityHeader = null;
switch (self.securityMode.value) {
case MessageSecurityMode.SIGN.value:
case MessageSecurityMode.SIGNANDENCRYPT.value:
assert(self.securityPolicy !== SecurityPolicy.None);
// get the thumbprint of the client certificate
const thumbprint = self.receiverCertificate ? crypto_utils.makeSHA1Thumbprint(self.receiverCertificate) : null;
securityHeader = new AsymmetricAlgorithmSecurityHeader({
securityPolicyUri: securityPolicy_m.toURI(self.securityPolicy),
senderCertificate: self.getCertificateChain(), // certificate of the private key used to sign the message
receiverCertificateThumbprint: thumbprint // thumbprint of the public key used to encrypt the message
});
break;
default:
/* istanbul ignore next */
assert(false, "invalid security mode");
}
//xx console.log("xxxx security Header",securityHeader.toJSON());
//xx console.log("xxxx receiverCertificate",self.receiverCertificate.toString("base64").cyan);
ServerSecureChannelLayer.prototype._get_security_options_for_OPN = function() {
const self = this;
const cryptoFactory = self.messageBuilder.cryptoFactory;
const options = {};
// install sign & sign-encrypt behavior
if (self.securityMode === MessageSecurityMode.SIGN || self.securityMode === MessageSecurityMode.SIGNANDENCRYPT) {
assert(cryptoFactory, "ServerSecureChannelLayer must have a crypto strategy");
options.signatureLength = self.getSignatureLength();
options.signingFunc = function(chunk) {
const signed = cryptoFactory.asymmetricSign(chunk, self.getPrivateKey());
assert(signed.length === options.signatureLength);
return signed;
};
assert(self.receiverPublicKeyLength >= 0);
options.plainBlockSize = self.receiverPublicKeyLength - cryptoFactory.blockPaddingSize;
options.cipherBlockSize = self.receiverPublicKeyLength;
options.encrypt_buffer = function(chunk) {
return cryptoFactory.asymmetricEncrypt(chunk, self.receiverPublicKey);
// This indicates what public key was used to encrypt the MessageChunk
// This field shall be null if the message is not encrypted.
switch (request.securityMode.value) {
case MessageSecurityMode.NONE.value:
assert(
!message.securityHeader ||
message.securityHeader.securityPolicyUri === "http://opcfoundation.org/UA/SecurityPolicy#None"
);
securityHeader = new AsymmetricAlgorithmSecurityHeader({
securityPolicyUri: "http://opcfoundation.org/UA/SecurityPolicy#None",
senderCertificate: null, // message not signed
receiverCertificateThumbprint: null // message not encrypted
});
break;
case MessageSecurityMode.SIGN.value:
case MessageSecurityMode.SIGNANDENCRYPT.value:
// get the thumbprint of the client certificate
const thumbprint = self.receiverCertificate
? crypto_utils.makeSHA1Thumbprint(self.receiverCertificate)
: null;
securityHeader = new AsymmetricAlgorithmSecurityHeader({
securityPolicyUri: self.clientSecurityHeader.securityPolicyUri,
senderCertificate: self.getCertificateChain(), // certificate of the private key used to sign the message
receiverCertificateThumbprint: thumbprint // message not encrypted (????)
});
break;
}
return securityHeader;
}