mbedtls: RSA PKCS8 import slices wrong DER object `ptls_mbedtls_load_private_key` unwraps PKCS#8 `BEGIN PRIVATE KEY` material with `test_parse_private_key_field`, yielding `key_index` and `key_length` for the inner private-key OCTET STRING payload. In the RSA branch, the code then switches back to the outer PKCS#8 buffer and length before deriving RSA attributes and calling `psa_import_key`. As a result, RSA-specific parsing receives a `PrivateKeyInfo` object instead of the required inner `RSAPrivateKey` DER object.
diff --git a/lib/mbedtls_sign.c b/lib/mbedtls_sign.c index 3b54864..f8a54d3 100644 --- a/lib/mbedtls_sign.c +++ b/lib/mbedtls_sign.c
@@ -670,8 +670,7 @@ } else if (oid_length == sizeof(ptls_mbedtls_oid_rsa_key) && memcmp(pem.private_buf + oid_index, ptls_mbedtls_oid_rsa_key, sizeof(ptls_mbedtls_oid_rsa_key)) == 0) { /* We recognized RSA */ - key_length = pem.private_buflen; - ptls_mbedtls_set_rsa_key_attributes(signer, pem.private_buf, key_length); + ptls_mbedtls_set_rsa_key_attributes(signer, pem.private_buf + key_index, key_length); } else { ret = PTLS_ERROR_NOT_AVAILABLE; }