Skip to content

Preserve OpenSSL exception in TS validation error path#483

Closed
klemensn wants to merge 1 commit intoopen-eid:masterfrom
klemensn:ts-validate-error-log
Closed

Preserve OpenSSL exception in TS validation error path#483
klemensn wants to merge 1 commit intoopen-eid:masterfrom
klemensn:ts-validate-error-log

Conversation

@klemensn
Copy link
Copy Markdown
Contributor

if TS_RESP_verify_token() fails, ERR_get_error(3) is used to check for
a specific error reason and throw a specific exception.

But in case of different reasons, the generic THROW_OPENSSLEXCEPTION()
is used which itself ERR_get_error(3), at which point the actual error
has already been removed from the thread's error queue.

Use ERR_peek_error(3) for special casing the specific error instead,
such that the queue remains unmodified and THROW_OPENSSLEXCEPTION() is
able to show the actual error.

This results in the following error diff in case of TS valdiation errors
(as can be seen on OpenBSD when built LibreSSL):

$ digidoc-tool create --file=./hello.txt ./hello.asice
Version
  digidoc-tool version: 3.14.8.0
  libdigidocpp version: 3.14.8.0
Available certificates:
  label: NANNI,KLEMENS ANTONIUS,39311290189
Selected:
  label: NANNI,KLEMENS ANTONIUS,39311290189
    Validation: �[31mFAILED�[0m
     Exception:
SignatureXAdES_LTA.cpp:203 code(General) Signature validation
TS.cpp:288 code(General) Failed to verify TS response.

With this diff, the following line will be added at the end:

time stamp routines:0 code(General) error:2FFFF065:time stamp routines:CRYPTO_internal:ess signing certificate error

Signed-off-by: Klemens Nanni klemens@posteo.de

See #482 (comment)

if `TS_RESP_verify_token()` fails, ERR_get_error(3) is used to check for
a specific error reason and throw a specific exception.

But in case of different reasons, the generic `THROW_OPENSSLEXCEPTION()`
is used which itself ERR_get_error(3), at which point the actual error
has already been removed from the thread's error queue.

Use ERR_peek_error(3) for special casing the specific error instead,
such that the queue remains unmodified and `THROW_OPENSSLEXCEPTION()` is
able to show the actual error.

This results in the following error diff in case of TS valdiation errors
(as can be seen on OpenBSD when built LibreSSL):

```
$ digidoc-tool create --file=./hello.txt ./hello.asice
Version
  digidoc-tool version: 3.14.8.0
  libdigidocpp version: 3.14.8.0
Available certificates:
  label: NANNI,KLEMENS ANTONIUS,39311290189
Selected:
  label: NANNI,KLEMENS ANTONIUS,39311290189
    Validation: �[31mFAILED�[0m
     Exception:
SignatureXAdES_LTA.cpp:203 code(General) Signature validation
TS.cpp:288 code(General) Failed to verify TS response.
```

With this diff, the following line will be added at the end:
```
time stamp routines:0 code(General) error:2FFFF065:time stamp routines:CRYPTO_internal:ess signing certificate error
```

Signed-off-by: Klemens Nanni <klemens@posteo.de>
@metsma
Copy link
Copy Markdown
Contributor

metsma commented Jul 11, 2022

#481

@klemensn
Copy link
Copy Markdown
Contributor Author

klemensn commented Jul 11, 2022

#481

I see, here's the output with #483 dropped and #481 applied instead (still using LibreSSL, of course):

    Validation: FAILED
     Exception:
SignatureXAdES_LTA.cpp:203 code(General) Signature validation
TS.cpp:284 code(General) Failed to verify TS response.
engine routines:0 code(General) error:26FFF074:engine routines:CRYPTO_internal:no such engine
engine routines:0 code(General) error:26FFF074:engine routines:CRYPTO_internal:no such engine
engine routines:0 code(General) error:26FFF074:engine routines:CRYPTO_internal:no such engine
time stamp routines:0 code(General) error:2FFFF065:time stamp routines:CRYPTO_internal:ess signing certificate error

@klemensn klemensn closed this Jul 11, 2022
@klemensn klemensn deleted the ts-validate-error-log branch July 11, 2022 09:52
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.

2 participants