1 (edited by kjjy7 2018-09-28 00:53:22)

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");
        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 (ucSignatureBase64decoded);

    wc_FreeRsaKey( &rsaKey );

Error Message is ......

wc_Sha256Hash ret = 0
pubkey is not NULL
check_signature_verification, pksize 270
wc_InitRsaKey ret = 0


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....



Re: Error using wc_RsaPublicKeyDecode


Please share what it is you are working on. Thanks.

- K

Re: Error using wc_RsaPublicKeyDecode

I Send you email...

Please answer to me....


Re: Error using wc_RsaPublicKeyDecode


Thank you for providing details on the effort. Can you share the contents of the parse_jason data? I am guessing there may be extra encoding in there and you may need to set the "idx" variable to the appropriate offset for start of the RsaKey (if in fact that is an RSA key and not some other key). If you can share the parse_jason string that this error results from we can gladly run some tests on our end to see what the issue might be.

To result in even quicker turn-around if you can send us a test.c application and all relevant headers that we can compile and execute to reproduce this we'll get you results asap.

- K