Skip to content

x509_vfy.c: Make chain_build() error diagnostics to the point - #14094

Closed
DDvO wants to merge 3 commits into
openssl:masterfrom
siemens:build_chain-diagnostics
Closed

DDvO wants to merge 3 commits into
openssl:masterfrom
siemens:build_chain-diagnostics

Conversation

@DDvO

@DDvO DDvO commented Feb 6, 2021 •

Copy link
Copy Markdown
Contributor

So far, when something goes wrong during the chain building phase of certificate verification,
the error code pretty often is "unable to get local issuer certificate" or the like.
Often this does not tell much about the real problem and may be even misleading.

Here is a simple example.

apps/openssl verify -auth_level 1 -purpose sslserver -trusted test/certs/root-cert.pem \
  -untrusted test/certs/ca-pss-cert.pem test/certs/ee-pss-wrong1.5-cert.pem

yields

CN = EE-PSS-wrong1.5
error 20 at 0 depth lookup: unable to get local issuer certificate
error test/certs/ee-pss-wrong1.5-cert.pem: verification failed

because check_issued() throws away all error codes.

This PR makes check_issued() record any 'real' error code (i.e., everything except for
X509_V_ERR_SUBJECT_ISSUER_MISMATCH, which just means that the current cert x is clearly not issued by the candidate issuer) in ctx->error.
At this point it could make sense to even call verify_cb_cert(ctx, x, ctx->error_depth, err) -
what do you think?

Care is taken such that for backward compatibility any previous ctx->error contents are restored in case of successful chain building.

After these changes, the above verification yields much better diagnostics:

CN = EE-PSS-wrong1.5
error 77 at 0 depth lookup: subject signature algorithm and issuer public key algorithm mismatch
error test/certs/ee-pss-wrong1.5-cert.pem: verification failed

On this occasion also various coding style and documentation style nits are fixed.

  • [x] documentation is added or updated

@DDvO
DDvO force-pushed the build_chain-diagnostics branch from 173f78e to 9ed04b9 Compare February 8, 2021 07:29

@paulidale paulidale left a comment

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.

One wording suggestion

Comment thread crypto/x509/x509_vfy.c Resolved
@DDvO

DDvO commented Feb 8, 2021

Copy link
Copy Markdown
Contributor Author

Wow, this was quick!

How about the idea I mentioned in the description of this PR, namely letting check_issued() call verify_cb_cert(ctx, x, ctx->error_depth, err) on error?
This would give applications the chance to handle/waive specific errors during chain building.

@paulidale

Copy link
Copy Markdown
Contributor

Calling the callback function is a good suggestion.

@t8m t8m added the branch: master Applies to master branch label Feb 9, 2021
@t8m

t8m commented Feb 9, 2021

Copy link
Copy Markdown
Member

It would be wrong to overwhelm the application with callback calls if there is another possible candidate. It would be also wrong to allow application to ignore an issue that will lead inevitably to another failure in the chain verification code anyway. So I am not so sure about the call to verify_cb() instead of returning 0 straight away.

@DDvO

DDvO commented Feb 9, 2021

Copy link
Copy Markdown
Contributor Author

Yeah, I'm not sure myself about the potential call to verify_cb().
The advantage would be that callback functions could take more informed decisions
and have a more fine-grained control, at the expense of having more chances to do mistakes.

Therefore I suggest that I merge this PR now "as is" and setting up a small follow-up PR for handling this separately - ok?

@richsalz

richsalz commented Feb 9, 2021

Copy link
Copy Markdown
Contributor

Please fix the issue before merging and avoid a behavior change.

@DDvO

DDvO commented Feb 9, 2021

Copy link
Copy Markdown
Contributor Author

@richsalz, which issue do you mean?
Note that the wording is fixed and the suggested call to verify_cb() is not part of this (approved) PR.

@richsalz

richsalz commented Feb 9, 2021

Copy link
Copy Markdown
Contributor

I mean: decide whether or not to do the additional callback.

@DDvO

DDvO commented Feb 9, 2021

Copy link
Copy Markdown
Contributor Author

I mean: decide whether or not to do the additional callback.

As mentioned, I suggest deferring this topic to a separate PR.

@richsalz

richsalz commented Feb 9, 2021

Copy link
Copy Markdown
Contributor

We're going in circles. Yes, I know you suggested deferring the callback issue. I am suggesting resolve it now, as part of this PR, rather than changing behavior.

@paulidale paulidale added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: otc review pending labels Feb 10, 2021
@paulidale

Copy link
Copy Markdown
Contributor

I'm open to either path forwards.

@t8m

t8m commented Feb 10, 2021

Copy link
Copy Markdown
Member

The callback must be called only when the chain building process is coming to a dead end. It should not ever be called for any intermediate failures that can be overcome by considering further certificates in the untrusted or trusted set.

@DDvO

DDvO commented Feb 11, 2021

Copy link
Copy Markdown
Contributor Author

Merged in the approved version, without an extra call to verify_cb()
since I already needed the more to-the-point diagnostics.
I've meanwhile set up PR #14157 on using the verificatin callback when an intermediate chain building error has become final.

@DDvO DDvO closed this Feb 11, 2021
@kroeckx

kroeckx commented Feb 16, 2021

Copy link
Copy Markdown
Member

I would really like to have seen tests for this.

@DDvO

DDvO commented Feb 17, 2021

Copy link
Copy Markdown
Contributor Author

It would be possible to set up test cases for error output, but it's a bit ugly to do and brittle.

DDvO added a commit to siemens/openssl that referenced this pull request Jul 9, 2022
…error reporting

The problem of producing to-the-point diagnostics will be fixed in a follow-up PR.
Fixes openssl#18691
DDvO added a commit to siemens/openssl that referenced this pull request Jul 10, 2022
…error reporting

The problem of producing to-the-point diagnostics will be fixed in a follow-up PR.
Fixes openssl#18691
openssl-machine pushed a commit that referenced this pull request Jul 12, 2022
…eporting

The problem of producing to-the-point diagnostics will be fixed in a follow-up PR.
Fixes #18691

Reviewed-by: Viktor Dukhovni <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: David von Oheimb <[email protected]>
(Merged from #18758)

(cherry picked from commit 1f00dc4)
openssl-machine pushed a commit that referenced this pull request Jul 12, 2022
…eporting

The problem of producing to-the-point diagnostics will be fixed in a follow-up PR.
Fixes #18691

Reviewed-by: Viktor Dukhovni <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: David von Oheimb <[email protected]>
(Merged from #18758)
DDvO added a commit to siemens/openssl that referenced this pull request Jul 27, 2022
…error reporting

The problem of producing to-the-point diagnostics will be fixed in a follow-up PR.
Fixes openssl#18691
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
…error reporting

The problem of producing to-the-point diagnostics will be fixed in a follow-up PR.
Fixes openssl#18691

Reviewed-by: Viktor Dukhovni <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: David von Oheimb <[email protected]>
(Merged from openssl#18758)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Applies to master branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants