Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return reject(new Error('ERR_UNDEFINED_ASSERTION'));
}
const sourceEntitySetting = sourceEntity.entitySetting;
const targetEntityMetadata = targetEntity.entityMeta;
const doc = new dom().parseFromString(xml);
const assertions = select("//*[local-name(.)='Assertion']", doc) as Node[];
if (!Array.isArray(assertions)) {
throw new Error('ERR_NO_ASSERTION');
}
if (assertions.length !== 1) {
throw new Error('ERR_MULTIPLE_ASSERTION');
}
// Perform encryption depends on the setting, default is false
if (sourceEntitySetting.isAssertionEncrypted) {
xmlenc.encrypt(assertions[0].toString(), {
// use xml-encryption module
rsa_pub: new Buffer(utility.getPublicKeyPemFromCertificate(targetEntityMetadata.getX509Certificate(certUse.encrypt)).replace(/\r?\n|\r/g, '')), // public key from certificate
pem: new Buffer('-----BEGIN CERTIFICATE-----' + targetEntityMetadata.getX509Certificate(certUse.encrypt) + '-----END CERTIFICATE-----'),
encryptionAlgorithm: sourceEntitySetting.dataEncryptionAlgorithm,
keyEncryptionAlgorighm: sourceEntitySetting.keyEncryptionAlgorithm,
}, (err, res) => {
if (err) {
console.error(err);
return reject(new Error('ERR_EXCEPTION_OF_ASSERTION_ENCRYPTION'));
}
if (!res) {
return reject(new Error('ERR_UNDEFINED_ENCRYPTED_ASSERTION'));
}
const { encryptedAssertion: encAssertionPrefix } = sourceEntitySetting.tagPrefix;
const encryptAssertionNode = new dom().parseFromString(`<${encAssertionPrefix}:EncryptedAssertion xmlns:${encAssertionPrefix}="${namespace.names.assertion}">${res}`);
doc.replaceChild(encryptAssertionNode, assertions[0]);