-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Increased MBEDTLS_BEFORE_COLON (size of temporary buffer) to 32 #10433
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
base: development
Are you sure you want to change the base?
Conversation
Thanks for your contribution! However it needs to include an automated non-regression test, as part of |
* Return an informational string about the certificate. | ||
*/ | ||
#define MBEDTLS_BEFORE_COLON 18 | ||
#define MBEDTLS_BEFORE_COLON 32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 32? And why update only this and not the corresponding _STR
macro below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 32?
Increasing the buffer size by 2 would have been sufficient. But I wanted to have some spara space, just in case someone changes mbedtls_x509_key_size_helper()
.
And why update only this and not the corresponding _STR macro below?
Changing the MBEDTLS_BEFORE_COLON enlarges the buffer and makes sure, that no MBEDTLS_ERR_X509_BUFFER_TOO_SMALL-error is generated.
Changing the MBEDTLS_BEFORE_COLON_STR macro changes the format string for printf in a way, that is does not match the other printf-statements. Here is a sample output:
cert. version : 3
serial number : F7:B9:58:6A:3B:C7:61:9A
issuer name : CN=Intermediate CA
subject name : CN=Server
issued on : 2025-10-02 08:48:33
expires on : 2035-09-30 08:48:33
signed using : ECDSA with SHA256
EC key size : 256 bits
basic constraints : CA=false
key usage : Digital Signature
When the MBEDTLS_BEFORE_COLON_STR-Macro is changed, the other printf format strings would need to be updated too.
I choose to not update the MBEDTLS_BEFORE_COLON_STR-Macro, because IMHO that is not a problem. In cases, when no MBEDTLS_ERR_X509_BUFFER_TOO_SMALL error is generated, the output of mbedtls_x509_crt_info()
would be the same as before.
In case the current implementation fails with MBEDTLS_ERR_X509_BUFFER_TOO_SMALL, the colon in the info string would not be adjusted to the colons of the other lines.
To me, this seems like a reasonable compromize.
/* Key size */ | ||
if ((ret = mbedtls_x509_key_size_helper(key_size_str, MBEDTLS_BEFORE_COLON, | ||
mbedtls_pk_get_name(&crt->pk))) != 0) { | ||
assert(ret != MBEDTLS_ERR_X509_BUFFER_TOO_SMALL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use assert
in the library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of assert()ions is to signal errors in the internal logic of some software. In this case, supplying an insuffently sized buffer to mbedtls_x509_key_size_helper()
in an error in the program logic. This is the reason, why I added an assertion.
Just remove it from my contribution, if you don't want to use this extra instrumentation in your code.
Description
Fix for Ticket #4894:
PR checklist