Topic: [SOLVED] SSL: error:0906D06C:PEM_read_bio:no start line:Expecting:
hello all,
I am using following code for generating selfsigned certificate.
but i am getting following error:
PEM_read_bio_X509_AUX("/cert/server.pem") failed (SSL: error:0906D06C:PEM routines:PEM_read_bio:no start line:Expecting: TRUSTED CERTIFICATE)
I checked certificate type, permission and header
EVP_PKEY *pk = NULL;
Cert newCert = { 0 };
WC_RNG rng = { 0 };
ecc_key newKey = { 0 };
byte* derBuf = NULL;
byte* derKeyBuf = NULL;
int derBufSz = 0;
int derKeyBufSz = 0;
derBuf = (byte*) XMALLOC(FOURK_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER);
derKeyBuf = (byte*) XMALLOC(FOURK_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER);
/* Generate new ecc key */
int ret = wc_InitRng(&rng);
if (ret != 0)
{
//("wc_InitRng() failed");
}
ret = wc_ecc_init(&newKey);
if (ret != 0)
{
//("wc_ecc_init() failed");
}
ret = wc_ecc_make_key(&rng, 32, &newKey);
if (ret != 0)
{
//("wc_ecc_make_key() failed()"));
}
/* Setup Certificate */
wc_InitCert(&newCert);
newCert.daysValid = days;
newCert.isCA = 0;
newCert.sigType = CTC_SHA256wECDSA;
strncpy(newCert.subject.commonName, (const char *)commonName, CTC_NAME_SIZE);
/* Make an New x509 ECC Certificate */
ret = wc_MakeCert(&newCert, derBuf, FOURK_SZ, NULL, &newKey, &rng);
if (ret < 0)
{
//(wc_ecc_make_key() failed()");
}
//Sign certificate using ecc key
derBufSz = wc_SignCert(newCert.bodySz, newCert.sigType, derBuf, FOURK_SZ, NULL, &newKey, &rng);
if (derBufSz < 0)
{
//("SignCert failed derBufSz%d"), derBufSz);
}
/* DER formatted certificate into WOLFSSL_X509 structure */
WOLFSSL_X509* newX509;
newX509 = wolfSSL_X509_d2i(&newX509 ,derBuf, derBufSz);
if(newX509 == NULL)
{
//("wolfssl_X509_d2i() failed\n");
}
/* PEM formatted PrivateKey into DER formatted PrivateKey */
derKeyBufSz = wc_EccKeyToDer(&newKey, derKeyBuf, FOURK_SZ);
if(derKeyBufSz < 0)
{
//("wc_EccPrivateKeyToDer() failed");
}
/* This function converts DER formatted ECC PrivateKey into wolfSSL_EVP_PKEY structure */
pk = wolfSSL_d2i_PrivateKey_EVP( NULL, &derKeyBuf, derKeyBufSz);
if(pk == NULL)
{
//("wolfSSL_d2i_PrivateKey_EVP() failed");
}
// Successful exit, return pointers to cert and private key
*x509p = newX509;
*pkeyp = pk;
is there anything i am doing wrong in this code which i am not able to understand?
please, can any one help in this issue?