poco icon indicating copy to clipboard operation
poco copied to clipboard

EVPPKey does not fail if no password is set for a private key that requires a private key

Open zorane opened this issue 4 years ago • 3 comments

EVPPKey does not fail if no password is set for a private key that requires a private key. Instead it goes to the default openssl callback routine which will prompt for the passphrase on the current terminal. The quote below is from the openssl man page for the PEM_read_bio_PrivateKey that is being used to read the private key.

If both cb and u are NULL then the default callback routine is used which will typically prompt for the passphrase on the current terminal with echoing turned off.

Is this the behavior that was intended? This breaks our application since the end user does not interact with a terminal.

The "fix" would be to not set pPassword to a nullptr in the case where pass is an empty string. https://github.com/pocoproject/poco/blob/191cbdc97e1d9de023b8a65e0dc844911c06f6a8/Crypto/include/Poco/Crypto/EVPPKey.h#L252-L254

zorane avatar Jun 13 '22 08:06 zorane

That would be a breaking change - users who are currently not specifying the password and counting on the prompt, would (1) be unpleasantly surprised and (2) have no way to trigger the prompt. On the other hand, you can work around it by passing a bad password to trigger the exception - it may not be pretty, but it should do the job.

A proper solution would be to add a constructor and modify loadKey() to take callback argument - that way, user has full control of the behavior. If you are inclined to do the work, send a pull request to devel branch and we'll consider it for 1.13 release. Please make sure to also write a test case.

aleks-f avatar Jun 13 '22 20:06 aleks-f

This issue is stale because it has been open for 365 days with no activity.

github-actions[bot] avatar Jun 14 '23 02:06 github-actions[bot]

This issue was closed because it has been inactive for 60 days since being marked as stale.

github-actions[bot] avatar Aug 14 '23 02:08 github-actions[bot]