Hello,
I generated RSA public and private keys in the embedded device and now I am stuck while generating CSR from the private key.
This is my code snippet to generate CSR
mbedtls_pk_context key;
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_x509write_csr req;
const char *pers = “CSR”;
mbedtls_pk_init( &key );
mbedtls_ctr_drbg_init( &ctr_drbg );
mbedtls_entropy_init( &entropy );
if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy,
(const unsigned char *) pers,
strlen( pers ) ) ) != 0 )
{
mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%04x\n", -ret );
return;
}
if( ( ret = mbedtls_pk_setup( &key, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) ) != 0 )
{
mbedtls_printf( " failed\n ! mbedtls_pk_setup returned -0x%04x", -ret );
return;
}
if( opt.type == MBEDTLS_PK_RSA )
{
ret = mbedtls_rsa_gen_key( mbedtls_pk_rsa( key ), mbedtls_ctr_drbg_random, &ctr_drbg,
1024, 65537 );
if( ret != 0 )
{
mbedtls_printf( " failed\n ! mbedtls_rsa_gen_key returned -0x%04x", -ret );
return;
}
}
mbedtls_x509write_csr_init( &req );
mbedtls_x509write_csr_set_md_alg( &req, MBEDTLS_MD_SHA256 );
if( ( ret = mbedtls_x509write_csr_set_subject_name( &req, opt1.subject_name ) ) != 0 )
{
mbedtls_printf( " failed\n ! mbedtls_x509write_csr_set_subject_name returned %d", ret );
return;
}
mbedtls_x509write_csr_set_key( &req, &key );
unsigned char output_buf[4096];
memset(output_buf, 0, 4096);
ret = mbedtls_x509write_csr_der(&req, output_buf, 4096, mbedtls_ctr_drbg_random, &ctr_drbg);
if(ret!=0){
Serial.println("Writing csr in der format failed ");
return;
}
This is the error I am getting
In the code when I reduce the output_buf size from 4096 to 1500 I get this error
Could anyone of you please help me how to solve this error.
Any help is appreciated
Thank You