Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decrypt throws when using single line private key after update to 2.0.0 #99

Open
christian-hawk opened this issue Sep 22, 2022 · 1 comment

Comments

@christian-hawk
Copy link

Description

After upgrading to version 2.0.0, decrypt throws when using single line private key. (without pvk header/footer and without line breaks). As reported in node-saml/passport-saml#672 and GluuFederation/inbound-saml#154 .

This is happening because 'node-forge' used to accept a "single line" certificate in private_key = pki.privateKeyFromPem(options.key) (check commit 7aaa734). But now, after this commit, crypto module is in use:

var decrypted = crypto.privateDecrypt({ key: options.key, padding: padding}, key);

Provide a clear and concise description of the issue, including what you expected to happen.

Reproduction

const rsaKey = fs.readFileSync(__dirname + '/your_private_key.key')
	.replace(/(\r\n|\n|\r)/gm, '')
    .replace('-----BEGIN RSA PRIVATE KEY-----', '')
    .replace('-----END RSA PRIVATE KEY-----', '')

const options = {
    key: rsaKey
}

xmlenc.decrypt('<xenc:EncryptedData ..... </xenc:EncryptedData>', options, function(err, result) {
	if(err) { 
		throw new Error(err)
	}
    console.log(result);
}

output:

Error: error:0909006C:PEM routines:get_name:no start line
    at Object.privateDecrypt (node:internal/crypto/cipher:79:12)
    at decryptKeyInfoWithScheme (/root/inbound-saml-0.17.0/node_modules/xml-encryption/lib/xmlenc.js:258:26)
    at decryptKeyInfo (/root/inbound-saml-0.17.0/node_modules/xml-encryption/lib/xmlenc.js:246:14)
    at Object.decrypt (/root/inbound-saml-0.17.0/node_modules/xml-encryption/lib/xmlenc.js:187:24)

Environment

Please provide the following:

  • Version of this library used: 2.0.0

Adicional Context

Even if that depends on a lib (node-forge/crypto), this change caused downstream modules to BREAK, so from a design perspective it's still an UNDOCUMENTED BREAKING CHANGE, even that it may also be treated as a bug to (hot)fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant