You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am generating a self signed certificate with ECDSA SHA384 and mbedtls_x509_crt_parse_der is FAILED with ffffde1e
System information
Mbed TLS version (number or commit id): 2.28.1
Operating system and version: Ubuntu 20.04.6 LTS
Configuration (if not default, please attach mbedtls_config.h): Attached
Compiler and options (if you used a pre-built binary, please indicate how you obtained it):
Additional environment information:
Expected behavior
mbedtls_x509_crt_parse_der is expected to return the Parsed Certificate Structure. If the function returns 0, the parsed certificate will be stored in the mbedtls_x509_crt structure that you pass to the function. You can then access various fields of the certificate through this structure, such as: Subject name,Issuer name,Validity period (not before and not after dates),Public key information,Extensions (if any)
Actual behavior
mbedtls_x509_crt_parse_der FAILED with ffffde1e der Len [-8674]
Steps to reproduce
Used the below code and got outout as
///////////////output log/////////////////
mbedtls_x509write_crt_pem success !!!!!!!
mbedtls_x509_crt_parse success !!!!!!!
mbedtls_x509write_crt_der success !!!!!!!
mbedtls_x509_crt_parse_der FAILED !!!!!!! ffffde1e
der Len [-8674]
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
/////////////Code used//////////////////////////
mbedtls_x509_crt crt,crt_der;
mbedtls_pk_context key;
Summary
I am generating a self signed certificate with ECDSA SHA384 and mbedtls_x509_crt_parse_der is FAILED with ffffde1e
System information
Mbed TLS version (number or commit id): 2.28.1
Operating system and version: Ubuntu 20.04.6 LTS
Configuration (if not default, please attach
mbedtls_config.h
): AttachedCompiler and options (if you used a pre-built binary, please indicate how you obtained it):
Additional environment information:
Expected behavior
mbedtls_x509_crt_parse_der is expected to return the Parsed Certificate Structure. If the function returns 0, the parsed certificate will be stored in the mbedtls_x509_crt structure that you pass to the function. You can then access various fields of the certificate through this structure, such as: Subject name,Issuer name,Validity period (not before and not after dates),Public key information,Extensions (if any)
Actual behavior
mbedtls_x509_crt_parse_der FAILED with ffffde1e der Len [-8674]
Steps to reproduce
Used the below code and got outout as
///////////////output log/////////////////
mbedtls_x509write_crt_pem success !!!!!!!
mbedtls_x509_crt_parse success !!!!!!!
mbedtls_x509write_crt_der success !!!!!!!
mbedtls_x509_crt_parse_der FAILED !!!!!!! ffffde1e
der Len [-8674]
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
/////////////Code used//////////////////////////
mbedtls_x509_crt crt,crt_der;
mbedtls_pk_context key;
nfi_generate_ecc_key_pair(&key);
int ret;
mbedtls_mpi serial;
mbedtls_x509write_cert crt_writer;
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
const char *pers = "crt_gen";
const char *subject_namem = "CN=TestCN";
mbedtls_x509write_crt_init(&crt_writer);
mbedtls_mpi_init(&serial);
mbedtls_x509_crt_init(&crt);
mbedtls_x509_crt_init(&crt_der);
mbedtls_entropy_init(&entropy);
mbedtls_ctr_drbg_init(&ctr_drbg);
if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *)pers, strlen(pers))) != 0) {
return ret;
}
if ((ret = mbedtls_mpi_read_string(&serial, 10, "1")) != 0) {
return ret;
}
mbedtls_x509write_crt_set_serial(&crt_writer, &serial);
nfi_set_certificate_validity(&crt_writer,365);
mbedtls_x509write_crt_set_subject_key(&crt_writer, &key);
mbedtls_x509write_crt_set_issuer_key(&crt_writer, &key);
mbedtls_x509write_crt_set_md_alg(&crt_writer, MBEDTLS_MD_SHA256);
if ((ret = mbedtls_x509write_crt_set_subject_name(&crt_writer, subject_namem)) != 0) {
return ret;
}
if ((ret = mbedtls_x509write_crt_set_issuer_name(&crt_writer, subject_namem)) != 0) {
return ret;
}
mbedtls_x509write_crt_set_basic_constraints(&crt_writer, 1, 0);
mbedtls_x509write_crt_set_key_usage(&crt_writer, MBEDTLS_X509_KU_DIGITAL_SIGNATURE |
MBEDTLS_X509_KU_NON_REPUDIATION |
MBEDTLS_X509_KU_KEY_ENCIPHERMENT |
MBEDTLS_X509_KU_DATA_ENCIPHERMENT |
MBEDTLS_X509_KU_KEY_AGREEMENT |
MBEDTLS_X509_KU_KEY_CERT_SIGN |
MBEDTLS_X509_KU_CRL_SIGN |
MBEDTLS_X509_KU_ENCIPHER_ONLY |
MBEDTLS_X509_KU_DECIPHER_ONLY );
// add_extension(&crt_writer,"1.3.2.5.444.2.1","0123",1);
unsigned char output_buf[4096];
memset(output_buf, 0, sizeof(output_buf));
ret = mbedtls_x509write_crt_pem(&crt_writer, output_buf, sizeof(output_buf), mbedtls_ctr_drbg_random, &ctr_drbg);
if (ret < 0) {
printf("mbedtls_x509write_crt_pem FAILED !!!!!!!\n");
return ret;
}
else
printf("mbedtls_x509write_crt_pem success !!!!!!!\n");
ret = mbedtls_x509_crt_parse(&crt, output_buf, sizeof(output_buf));
if (ret < 0) {
printf("mbedtls_x509_crt_parse FAILED !!!!!!!\n");
return ret;
}
else
printf("mbedtls_x509_crt_parse success !!!!!!!\n");
unsigned char output_buf_der[4096];
memset(output_buf_der, 0, sizeof(output_buf_der));
ret = mbedtls_x509write_crt_der(&crt_writer,output_buf_der, sizeof(output_buf_der), mbedtls_ctr_drbg_random, &ctr_drbg);
if (ret < 0) {
printf("mbedtls_x509write_crt_der FAILED !!!!!!!\n");
return ret;
}
else
printf("mbedtls_x509write_crt_der success !!!!!!!\n");
ret = mbedtls_x509_crt_parse_der(&crt_der, output_buf_der, sizeof(output_buf_der));
if (ret < 0) {
printf("mbedtls_x509_crt_parse_der FAILED !!!!!!! %x\n",ret);
// return ret;
}
else
printf("mbedtls_x509_crt_parse_der success !!!!!!!\n");
printf("der Len [%d]\n",ret);
for (size_t i = 0; i < ret; i++)
{
printf("%02x", output_buf[sizeof(output_buf) - ret + i]);
}
printf("\n");
The text was updated successfully, but these errors were encountered: