Skip to content

Introduce OpenSslException for detailed error handling in OpenSSL operations#29

Merged
ievgeniiskliarenko merged 3 commits intomasterfrom
improve-openssl-error-handling
Feb 2, 2026
Merged

Introduce OpenSslException for detailed error handling in OpenSSL operations#29
ievgeniiskliarenko merged 3 commits intomasterfrom
improve-openssl-error-handling

Conversation

@ievgeniiskliarenko
Copy link
Copy Markdown
Contributor

@ievgeniiskliarenko ievgeniiskliarenko commented Jan 30, 2026

The idea is that we can return original OpenSSL errors to the caller, but we do not want to return them as a part of the VerificationFailed message because in this way they will be dispatched to the outside, which might provide additional and sensitive information to the attacker.

@ievgeniiskliarenko ievgeniiskliarenko requested review from Atomarius and evmoroz and removed request for Atomarius January 30, 2026 10:04
@ievgeniiskliarenko ievgeniiskliarenko marked this pull request as ready for review January 30, 2026 10:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new OpenSslException class to improve error handling in OpenSSL operations by capturing detailed error information while preventing sensitive error details from being exposed externally through generic exception messages.

Changes:

  • Added OpenSslException class that collects and stores OpenSSL error strings
  • Updated OpenSSLVerify to use OpenSslException as a previous exception when verification fails
  • Updated OpenSSLSign to use OpenSslException as a previous exception when signing fails

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
vicephp/Virtue-JWT/src/JWT/OpenSslException.php Introduces new exception class for capturing OpenSSL error details with a static method to collect error strings
vicephp/Virtue-JWT/src/JWT/Algorithms/OpenSSLVerify.php Refactors error handling to collect OpenSSL errors and pass them as previous exceptions instead of exposing them in messages
vicephp/Virtue-JWT/src/JWT/Algorithms/OpenSSLSign.php Updates signing error handling to use OpenSslException as previous exception for better error context

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread vicephp/Virtue-JWT/src/JWT/Algorithms/OpenSSLVerify.php Outdated
Comment thread vicephp/Virtue-JWT/src/JWT/Algorithms/OpenSSLVerify.php Outdated

if (!$private = \openssl_pkey_get_private($this->private->asPem(), $this->private->passphrase())) {
throw new SignFailed('Key or passphrase are invalid.');
$opensslException = new OpenSslException(OpenSslException::collectErrors());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps collectErrors could return an exception. Otherwise the API is slightly clunky

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, on it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

@ievgeniiskliarenko ievgeniiskliarenko merged commit 172aa53 into master Feb 2, 2026
3 checks passed
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

Successfully merging this pull request may close these issues.

3 participants