Skip to content

Misleading exception when validating malformed signature #234

Open
@JohnnyJayJay

Description

@JohnnyJayJay

The Crypto.verifySignature method used to validate assertion signatures currently throws a very general exception if any IllegalArgumentException or GeneralSecurityException occurs in the process. It seems to me that this is not intended to be caught in user code because it is sort of a non-recoverable thing ("either reconfigure your JVM because e.g. you're lacking some cryptographic provider or report this as a bug in the library" is what the exception message suggests).

However there is a case that is recoverable and should be equivalent to an invalid signature (i.e. signature.verify(bytes) returning false). That case is a malformed signature. I.e., the signature bytes are present but cannot be parsed according to the provided algorithm. in that case, signature.verify(bytes) will throw a SignatureException. IMO this exception should be caught separately and ultimately result in a AssertionFailedException on the API end rather than a RuntimeException. The goal of this would be to handle (possibly malicious) erroneous requests better and prevent them from throwing uncaught RuntimeExceptions that the library or your app isn't at fault for.

One open question is of course how that information should be conveyed to the caller of verifySignature. If verifySignature just returned false in case of a SignatureException on the verify call, you would certainly lose some information that could be useful in development/debugging.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions