extmod/modtls_mbedtls: Fix DER parsing and calculation of key/cert len.
`mbedtls_pk_parse_key()` expects `key_len` to include the NULL terminator
for PEM data but not for DER encoded data. This also applies to
`mbedtls_x509_crt_parse()` and `cert_len`.
Since all PEM data contains "-----BEGIN" this is used to check if the data
is PEM (as per mbedtls code).
This can be done for both v2 and v3 of mbedtls since the fundamental
behaviour/expectation did not change. What changed is that in v3 the
PKCS#8 DER parser now checks that the passed key buffer is fully utilized
and no bytes are remaining (all other DER formats still do not check this).
Signed-off-by: Peter Züger <zueger.peter@icloud.com>
Showing