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

Listing of subclassed validation related exceptions is misleading #22

Open
atmenta opened this issue Sep 24, 2019 · 0 comments
Open

Listing of subclassed validation related exceptions is misleading #22

atmenta opened this issue Sep 24, 2019 · 0 comments

Comments

@atmenta
Copy link

atmenta commented Sep 24, 2019

The API documentation of validate.validate_usage and validate.validate_tls lists the following exceptions:

> > :raises:
> > certvalidator.errors.PathValidationError - when an error occurs validating the path
> > certvalidator.errors.RevokedError - when the certificate or another certificate in its path has been revoked
> > certvalidator.errors.InvalidCertificateError - when the certificate is not valid for the usages specified

When someone tries to catch and distinguish those exceptions, its important to know that both RevokedError and InvalidCertificateError are subclass of PathValidationError. If exceptions are attempted to be caught in the order the API documentation lists them, RevokedError and InvalidCertificateError will never be caught:

try:
    validation_path = validator.validate_usage(key_usage)
except PathValidationError as ex:
    # handle PathValidationError
    # This will catch RevokedError and InvalidCertificateError too!
    pass
except RevokedError as ex:
    # control is never passed here!
    pass
except InvalidCertificateError as ex:
    # control is never passed here!
    pass

On the other hand those exceptions can be properly handled if PathValidationError is the last to be caught:

try:
    validation_path = validator.validate_usage(key_usage)
except RevokedError as ex:
    # handle RevokedError
    pass
except InvalidCertificateError as ex:
    # handle InvalidCertificateError
    pass
except PathValidationError as ex:
    # handle PathValidationError
    pass

I suggest to modify the API documentation to clarify subclassing of those exceptions and list them in a more appropriate order.

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