Topic: Error using wc_RsaPublicKeyDecode
To use Signiture verification, I make these code.
Error happened while using wc_RsaPublicKeyDecode
that function is seem to get rsakey info from string.
ret = wc_Sha256Hash((const byte*)token, strlen(token), ucSha256Hashed);
if(ret != 0)
{
printf("Error wc_Sha256Hash ret = %d", ret);
return -25;
}
RsaKey rsaKey;
word32 idx = 0;
XMEMSET(&rsaKey, 0, sizeof(rsaKey));
word32 pksize = (word32)wolfSSL_X509_get_pubkey( parse_jason->x509Cert[0] )->pkey_sz;
const byte * pubkey = (const unsigned char*) wolfSSL_X509_get_pubkey( parse_jason->x509Cert[0] )->pkey.ptr;
if(pubkey == NULL)
printf("pubkey is NULL");
else
printf("pubkey is not NULL");
PLOG("%s, pksize %d", __func__, pksize);
ret = wc_InitRsaKey(&rsaKey, NULL);
if(ret != 0)
{
printf("Error wc_InitRsaKey ret = %d", ret);
return -25;
}
ret = wc_RsaPublicKeyDecode(pubkey, &idx, &rsaKey, pksize); <-- Error Msg Occurred
PLOG("wc_RsaPublicKeyDecode ret = %d", ret);
if (ret != 0)
{
// error parsing public key
memset( err_string, 0x00, sizeof(err_string) );
printf("%s failed ! wc_RsaPublicKeyDecode error %d", __func__, ret);
return -28;
} else {
printf("%s success ! wc_RsaPublicKeyDecode success", __func__);
}
ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
(const byte*)ucSha256Hashed, sizeof(ucSha256Hashed),
(const byte*)ucSignatureBase64decoded, nLengthSigDecoded,
&rsaKey, 300);
free(token);
free (ucSignatureBase64decoded);
wc_FreeRsaKey( &rsaKey );
Error Message is ......
wc_Sha256Hash ret = 0
pubkey is not NULL
check_signature_verification, pksize 270
wc_InitRsaKey ret = 0
then
Process 1110071 (-) terminated SIGSEGV code=1 fltno=11 ip=0000000011b538d8(/usr/lib/libwolfssl.so.12@wc_DhSetKey+0x0000000000000edc) mapaddr=000000000001c8d8. ref=10bc352000000000
could you answer why this error happened?
wait your answer....
thanks..