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

Fix decryption failure for entire payload when request object is encr… #64

Conversation

sumanguduru
Copy link

Fix decryption failure for entire payload when request object is encryptedData and response is encryptedResponse

The decryption process failed for the entire payload when the request object was encryptedData and the response was encryptedResponse from the API. This issue occurred due to a conditional statement that incorrectly retrieved the encrypted value.

  • jwe-encryption.js modified the logic
  • mcapi-service.js added logic for testing
  • jwe-encryptioin.test.js testcase for same bug
  • jwe-config.js added config for test
  • mcapi-service.test.js added test for same bug

Link to issue/feature request: add the link here

Here is the scenario:
When encrypting the entire payload and assigning it to encryptedData, and subsequently making an API call, the response is received as an encryptedResponse object. In this case, while decrypting response object an error is thrown due to invalid input.

My config
{
"path": "/entirepayload",
"toEncrypt": [{ "element": "$", "obj": "$" }],
"toDecrypt": [{ "element": "encryptedResponse", "obj": "$" }],
"mode": "JWE",
"encryptedValueFieldName": "encryptedData",
"publicKeyFingerprintType": "certificate",
"dataEncoding": "base64",
"encryptionCertificate": "./test/res/test_certificate.cert",
"privateKey": "./test/res/test_key.der"
}

Sample response I recived from API:
{
encryptedResponse: 'eyJraWQiOiJnSUVQd1RxREdmenc0dXd5TElLa3d3UzNnc3c4NW5FWFkwUFA2QllNSW5rPSIsImN0eSI6ImFwcGxpY2F0aW9uL2pzb24iLCJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2R0NNIn0.' +
'flEVAmFsw70aH6cyCmU8PmJSGBjWM8QU8rQg2IvfHZjvBq0O7qtRjIn9ssmTlYAohXxO4uIuECUWv9NILdZnKd20wtgihBmrflKVhVZ8afJESFIEcF4vIY03QBou0u4bGVNtrC0XooPy6uRnkZzlcvDZyMVMJF4eEK1-PSx7Gf77Vj9q37S' +
'IHsVCo4EujDi6Y1qRz2kI86eIguLeJbFmL1VcOUyrt8jtjcj00utFm30j-PyOEwgiyhYI6F0eMUWT89d-QYQrInk-Ciyp4bYwsLcr85BOMqWZ8nc2CGu2rfBNGexCphxDUJQ/TWEBZ0XKBAaQOj5qszwXhO-synLJ3A.eIGqscNMcz5h8x8w26oc6A.' +
'y-66zjYqTEqmgV39rklNVKgCF1Uq6jf-sLKOOkkX6RZJsAl4UY4cHWEfWcJCgnMnS8ZE/sBen24FwjZrxlC/znJa4D-BoY4OK0oE/GQJZ9mkmzwbqKeBFLzmalVLG2/XH74TY6bVn5xtVSR9tCalEMjIEo/Wwyt1DbIdysFqfcmXUbJo4bmKx6rfpBbXn' +
'cOopJ8nxQZaXueM1BcZQykS8bl4GriF2NgtPdjz6aqXsxDihd3p7LpbobrdcFtZvsMTs6xTRia9q9qqzN70cKwM8lBftMdRovRa-JCrkJ7LDqDQ/A.cdFqkuHXnggBcfxugl8cBA'
}

This encapsulates the issue description along with the provided configuration and a sample response from the API.

…yptedData and response is encryptedResponse

The decryption process failed for the entire payload when the request object was encryptedData and the response was encryptedResponse from the API. This issue occurred due to a conditional statement that incorrectly retrieved the encrypted value.

- jwe-encryption.js modified the logic
- mcapi-service.js added logic for testing
- jwe-encryptioin.test.js testcase for same bug
- jwe-config.js added config for test
- mcapi-service.test.js added test for same bug
@karen-avetisyan-mc karen-avetisyan-mc added the safe The PR has been reviewed by Mastercard and has been validated to be safe label Mar 5, 2024
@karen-avetisyan-mc
Copy link
Contributor

The NodeJS library expects the decrypted payload data to be in "encryptedValueFieldName": "encryptedData".
This PR is breaking that customer contract, because in the case if encryptedValueFieldName is not found, it will try to decrypt the payload specified by "toDecrypt": [{ "element": "encryptedResponse", "obj": "$" }], configuration.

@karen-avetisyan-mc karen-avetisyan-mc added rejected and removed safe The PR has been reviewed by Mastercard and has been validated to be safe labels Mar 5, 2024
@karen-avetisyan-mc karen-avetisyan-mc self-assigned this Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants