Re: Why custom RSA engine is not calling default RSA method?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear Shariful,

Could you please try the patch from https://github.com/openssl/openssl/pull/16734?

On Wed, Sep 29, 2021 at 6:59 PM Dmitry Belyavsky <beldmit@xxxxxxxxx> wrote:
Dear Shariful,

Yes. You have to provide all the RSA_METHO functions your app is going to use.

On Tue, Sep 28, 2021 at 5:46 PM Shariful Alam <dipto181@xxxxxxxxx> wrote:
Dear Dmitry,
Thank you for your response. 

Here is the stack trace 


I was trying using gdb to debug the error. I get to until RSA_public_encrypt(), then if I step in, I get the segmentation fault,
==================================================================================================
bt
#0  0x0000000000000000 in ?? ()
#1  0x00007ffff77dbfc0 in RSA_public_encrypt (flen=72, from=0x6d8860 "Hi. This is a test message. Hope to see some performace gain with this.\nme", to=0x6d8a70 "x\353;\367\377\177", rsa=0x6d8540, padding=1) at crypto/rsa/rsa_crpt.c:30
#2  0x00000000004479a7 in rsautl_main (argc=0, argv=0x7fffffffde10) at apps/rsautl.c:248
#3  0x00000000004379fa in do_cmd (prog=0x6d5930, argc=11, argv=0x7fffffffde10) at apps/openssl.c:564
#4  0x0000000000436e4d in main (argc=11, argv=0x7fffffffde10) at apps/openssl.c:183
==================================================================================================

To my understanding, instead of pointing to the default encryption function, it is pointing to  0x0000000000000000, thus causing the segmentation fault. 

 

Thanks,
Shariful



On Tue, Sep 28, 2021 at 1:40 AM Dmitry Belyavsky <beldmit@xxxxxxxxx> wrote:
Dear Shariful,

Could you please also provide a stack trace of your segfault?

On Tue, Sep 28, 2021 at 1:06 AM Shariful Alam <dipto181@xxxxxxxxx> wrote:
Hello,
I have the following simple RSA engine code from e_dasync.c.  Following code compiles and works. Until now, I was under the impression that if I do not supply an alternative method in function bind_dasync(), the engine will use the default method. However, it doesn't seem to be the case. If I comment out line 37 and try to perform an encryption operation with the following command, 

"openssl rsautl -encrypt -inkey public.pem -pubin -in msg.txt -out msg.enc -engine rsa-engine-new" 

I get segmentation errors.

Can anyone please tell me why this is happening?

==============================================================================
  1. /* Engine Id and Name */
  2. static const char *engine_rsa_id = "rsa-engine-new";
  3. static const char *engine_rsa_name = "RSA engine for testing";

  4. // data encryption function
  5. static int eng_rsa_pub_enc(int flen, const unsigned char *from,
  6.                           unsigned char *to, RSA *rsa, int padding) {
  7.     printf("Encryption\n");
  8.     return 0;
  9. }

  10. // signature verify
  11. static int eng_rsa_pub_dec(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding){
  12.     printf("Signature verify:\n");
  13.     return 0;
  14. }

  15. // signature
  16. static int eng_rsa_priv_enc(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding){
  17.     printf("Signature:\n");
  18.     return 0;
  19. }

  20. // data decryption
  21. static int eng_rsa_priv_dec(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding){
  22.     printf("Decryption\n");
  23.     return 0;
  24. }


  25. static RSA_METHOD *test_rsa_method = NULL;


  26. static int bind_dasync(ENGINE *e){
  27.     /* Setup RSA_METHOD */
  28.     if ((test_rsa_method = RSA_meth_new("Test RSA method", 0)) == NULL
  29.        // || RSA_meth_set_pub_enc(test_rsa_method, eng_rsa_pub_enc) == 0
  30.         || RSA_meth_set_pub_dec(test_rsa_method, eng_rsa_pub_dec) == 0
  31.         || RSA_meth_set_priv_enc(test_rsa_method, eng_rsa_priv_enc) == 0
  32.         || RSA_meth_set_priv_dec(test_rsa_method, eng_rsa_priv_dec) == 0
  33.             ) {

  34.         return 0;
  35.     }

  36.     /* Ensure the dasync error handling is set up */

  37.     if (!ENGINE_set_id(e, engine_rsa_id)
  38.         || !ENGINE_set_name(e, engine_rsa_name)
  39.         || !ENGINE_set_RSA(e, test_rsa_method)
  40.             ) {
  41.         return 0;
  42.     }
  43.     return 1;
  44. }

  45. static int bind_helper(ENGINE *e, const char *id){
  46.     if (!bind_dasync(e)){
  47.         printf("2_Error: Inside Bind helper\n");
  48.         return 0;
  49.     }
  50.     return 1;
  51. }

  52. IMPLEMENT_DYNAMIC_BIND_FN(bind_helper)
  53. IMPLEMENT_DYNAMIC_CHECK_FN()
==============================================================================

Regards,
Shariful Alam



--
SY, Dmitry Belyavsky


--
SY, Dmitry Belyavsky


--
SY, Dmitry Belyavsky

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux