mbedtls_x509_crt_info
produces non-printable output for binary HardwareModuleName SAN extensions
#6262
Labels
mbedtls_x509_crt_info
produces non-printable output for binary HardwareModuleName SAN extensions
#6262
Summary
mbedtls_x509_crt_info
produces non-printable characters if the certificate contains an RFC 4108 HardwareModuleName (as a Subject Alternative Name extension) whose hwSerialNum has non-printable bytes.This happens because the code assumes the hwSerialNum is made of printable characters and simply does a
memcpy
directly to the output. In fact, RFC 4108 specifies that the ASN.1 type of hwSerialNum is OCTET STRING, which basically permits any arbitrary sequence of octets. The RFC does not impose any other structure or encoding on the serial number.System information
Mbed TLS version (number or commit id): 52f83dc
Operating system and version: Manjaro Linux 21.3.7
Configuration (if not default, please attach
mbedtls_config.h
): defaultCompiler and options (if you used a pre-built binary, please indicate how you obtained it): gcc (GCC) 12.1.1 20220730, default options
Additional environment information: None
Expected behavior
In order to print binary hwSerialNums, we'd have to encode them into a printable format (hex for instance).
I generated this test certificate with a binary hwSerialNum (3132338081008180333231 in hex):
The expected output of
mbedtls_x509_crt_info
should then be:Actual behavior
The actual output of
mbedtls_x509_crt_info
isAlso note that the
0x00
in the middle of the hwSerialNum ends up NULL-terminating the whole thing, causing any following characters not to be printed.Steps to reproduce
Save the certificate above as a file and run the sample program:
programs/x509/cert_app mode=file filename=path/to/cert.crt
Additional information
I already implemented the hex conversion locally. If we agree on changing the format of the hardware serial number in
x509_info_subject_alt_name
to hex, I can submit a pull request.The text was updated successfully, but these errors were encountered: