SSLWrite null in dll

16 views
Skip to first unread message

Omar Fernando Pessoa

unread,
Mar 7, 2019, 11:38:51 AM3/7/19
to civetweb
Hi guys.

I have some application in VS2015. This application have a civetweb server like embedded example.

I have dlls that have your own Handlers (like example) and register it in the main application. (like plugins)

Without SSL it works fine, but, with SSL, ssl_sw before Handler have value, inside Handler this is all null ptr member. 

#if !defined(NO_SSL)
if (ssl != NULL) {
 n
= SSL_write(ssl, buf, len);

Line Number - 6178
CIVETWEB_VERSION "1.12"

Someone can help me with this?

bel

unread,
Mar 7, 2019, 1:47:15 PM3/7/19
to civetweb
I'm not sure if I understood the issue correctly.

CivetWeb 1.12 is not yet released, so the content of civetweb.c is changing, line number depends on the commit number and there may be some issues to intermediate commits. Currently the latest commit is 707c433575d3f0ee0663fde5959e284cabc240ce - line 6178 is "n = SSL_write(ssl, buf, len);" in function push_inner 
If you have ssl == NULL in line 6178, then there will be "else if (fp != NULL) {" in line 6195-6107. This allows push_inner to write to files.
Finally there is "else" in line 6203 and "send" in line 6204 - if it's not an SSL connection and not a file, it's a regular socket to send.

If you build without defined(NO_SSL), civetweb will handle HTTPS (ssl) as well as HTTP connections. With defined(NO_SSL) will only handle HTTP connections.
If you don't want to handle HTTP connections, you need to set the "listening_ports" parameter to "443s" only (see https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md).

If I did not get it correctly, I need some more details - what callbacks are you using, what data is null?

Omar Fernando Pessoa

unread,
Mar 7, 2019, 3:27:02 PM3/7/19
to civetweb
Hi again.

SSL_write is null (ptr on ssl_sw)

But, only in dll. If before SSL_write I call initialize_ssl like this:

if(ssl_sw[4].ptr == null){
   
char ebuf[128];

    initialize_ssl
(ebuf, sizeof(ebuf));
}



Then it works fine. But never uinitialize it. 

So, what I need is some alternative to use a Handler class into a dll, with this SSL functions initialized in both Exe application and Dll Handler classes plugin.

Sorry if it's dificult to understand :P

bel

unread,
Mar 7, 2019, 3:52:28 PM3/7/19
to civetweb


On Thursday, March 7, 2019 at 9:27:02 PM UTC+1, Omar Fernando Pessoa wrote:
Hi again.

SSL_write is null (ptr on ssl_sw)

But, only in dll. If before SSL_write I call initialize_ssl like this:

if(ssl_sw[4].ptr == null){
   
char ebuf[128];

    initialize_ssl
(ebuf, sizeof(ebuf));
}



Then it works fine. But never uinitialize it. 

So, what I need is some alternative to use a Handler class into a dll, with this SSL functions initialized in both Exe application and Dll Handler classes plugin.

Sorry if it's dificult to understand :P


Ok, I think I got it.

in civetweb.c - either line 1946 or 2135, depending on the OpenSSL interface version - there is a
static struct ssl_func ssl_sw[]
this should not be available in any other file than civetweb.c, since its static
So, maybe you defined ssl_sw somewhere else, and access another symbol with the same name?

ssl_sw in civetweb.c is initialized in line 15898
ssllib_dll_handle = load_dll(ebuf, ebuf_len, SSL_LIB, ssl_sw);

You can get completely rid of ssl_sw by defining NO_SSL_DL. This means, you still use SSL (in contrast to NO_SSL) but you do no "dynamic linking at runtime" DL of OpenSSL libraries, but rather load these libraries as dependencies automatically on load time of your executable. This may help in your case.
Although I think it should still work without setting this define, but I can't tell remotely where to look.


Omar Fernando Pessoa

unread,
Mar 8, 2019, 11:53:42 AM3/8/19
to civetweb
Perfect, but ssl_initilize was called twice, solved with:

if (!mg_ssl_initialized && !initialize_ssl(ebuf, sizeof(ebuf))) {


At code line 16070. (civetweb.c)

Thanks guys!
Reply all
Reply to author
Forward
0 new messages