From: <ch...@gm...> - 2016-08-24 23:03:36
|
Hello! I have a very specific question about Crypt::OpenSSL::RSA. Or maybe it is more about Perl XS or OpenSSL. I try to do very similar things in my own XS-module. It is because OAEP-SHA2 is not supported in Crypt::OpenSSL::RSA but thats not the problem here. As far I see there is no special thread-handling regarding OpenSSL in Crypt::OpenSSL::RSA. But is is working even inside Perl threads. My code is working in C, in Perl covered in a XS-module but it crashed if I call the XS-module within a Perl thread. I am pretty new to Perl XS and so I would like to ask if there is a special trick to make it work?? My idea was that the OpenSSL-thread-handling was missing (https://www.openssl.org/docs/man1.0.2/crypto/threads.html) in my module and therefore it is not working with threads. But as far I see it is also not included in Crypt::OpenSSL::RSA. So why it is working there? Here is a very simple function. It will crash at RSA_size if used inside a Perl thread. It will work fine if used in C or thread-less Perl. No big checks, just for demonstration. ------------------------ void _foo (void) { setbuf (stdout,NULL); #if defined(OPENSSL_THREADS) printf ("\nTHS enabled in OpenSSL"); #else printf("\nTHS not enabled"); #endif unsigned char key [3000]; # is enought memset (key, 0, 3000); printf ("\ninit=%d", SSL_library_init ()); FILE *f = fopen ("key.key","r"); # read the key-file printf ("\nf=%d", f); int keysize = fread (key, 1, 3000, f); printf ("\nn=%d",keysize); fclose (f); printf ("\nkey=%s", key); BIO *bio = BIO_new_mem_buf (key, keysize); printf ("\nbio=%ld", bio); RSA *pk = (RSA *) PEM_read_bio_RSAPrivateKey (bio, NULL, NULL, NULL); printf ("\npk=%ld", pk); printf ("\nsz=%d" ,RSA_size(pk)); // ******* crash here printf ("\n\n"); } ------------------------ Thanks for help! Chris |