How to read client certificate in polarssl?

687 Views Asked by At

How to read client certificate from server side using mbedtls(polarssl)? I had a server that was coded using mbedtls(polarssl). I want to read the client certificate and fetch some information from that certificate. Can anyone know what function will be used to read client certificate?

1

There are 1 best solutions below

0
On BEST ANSWER

I think you could use mbedtls_x509_crt_info which returns an informational string about the certificate.

You can get the peer certificate from the ssl session when the client connects and then print the info out.

mbedtls_ssl_context ssl;

...

mbedtls_x509_crt *crt = ssl.session->peer_cert;

unsigned char buf[1024];
int ret = mbedtls_x509_crt_info((char *) buf, sizeof( buf ) - 1, "", crt);
if( ret != -1 )
{
    mbedtls_printf( "%s\n", buf );
}

I didn't test this, just checked the examples.