i'm trying to parse the subject name of a X.509 certificate into a buffer , but i'm receiving negative value. What could have been gone wrong?
int32_t ret;
size_t n = 0;
uint8_t *p = NULL;
mbedtls_x509_crt testcert;
mbedtls_x509_crt_init(&testcert);
if (ret = mbedtls_x509_crt_parse_file(&testcert, "testcert.pem"))
{
printf(" failed\n ! mbedtls_x509_crt_parse_file returned -0x%04x\n\n", -ret);
return ret;
}
ret = mbedtls_x509_dn_gets(p, n, &testcert.subject);
if (ret <= 0)
{
printf("mbedtls_x509_dn_gets returned %02x", -ret);
return ret;
}
I got the mistake i made in the above code snippet.
After correcting these two things i was able to get the CN parsed to a buffer.
Thank you