[Libwebsockets] Problem building an SSL-enabled Libwebsocketserver

"Andy Green (林安廸)" andy at warmcat.com
Sun Apr 28 01:14:16 CEST 2013


On 28/04/13 03:08, the mail apparently from Torsten Steinert included:
> Hello,
>
> I am trying to build a minimal libwebsockets-server which accepts wss://-style requests. I started out by using the test-server.c example included in the source code. When I try to open a websocket connection to the server, I get the following output (debug-loglevel enabled):
>
> [4] Initial logging level 31
> [4] Library version: 1.3 unknown-build-hash
> [8]  LWS_MAX_HEADER_LEN: 1024
> [8]  LWS_MAX_PROTOCOLS: 5
> [8]  LWS_MAX_EXTENSIONS_ACTIVE: 3
> [8]  SPEC_LATEST_SUPPORTED: 13
> [8]  AWAITING_TIMEOUT: 5
> [8]  SYSTEM_RANDOM_FILEPATH: '/dev/urandom'
> [8]  LWS_MAX_ZLIB_CONN_BUFFER: 65536
> [4]  Started with daemon pid 0
> [4]  static allocation: 4488 + (16 x 1024 fds) = 20872 bytes
> [4]  canonical_hostname = ubuntu01
> [4]  Compiled with OpenSSL support
> [4]  Using SSL mode
> [4]  per-conn mem: 184 + 1360 headers + protocol rx buf
> [8] insert_wsi_socket_into_fds: wsi=0x1444020, sock=4, fds pos=0
> LWS_CALLBACK_ADD_POLL_FD
> [4]  Listening on port 8080
> LWS_CALLBACK_PROTOCOL_INIT
> LWS_CALLBACK_PROTOCOL_INIT
> starting server...
> LWS_CALLBACK_FILTER_NETWORK_CONNECTION
> Received network connect from ubuntu01.local (10.211.55.4)
> [8] insert_wsi_socket_into_fds: wsi=0x1449b10, sock=5, fds pos=1
> LWS_CALLBACK_ADD_POLL_FD
> [8] inserted SSL accept into fds, trying SSL_accept
>
> [16] SSL_accept failed 2 / error:00000002:lib(0):func(0):system lib
> LWS_CALLBACK_SET_MODE_POLL_FD
> [8] SSL_ERROR_WANT_READ

This is OK, it just means we're nonblocking and the negotiation between 
the two peers will take more time.

> [16] accepted new SSL conn
> [8] lws_server_skt_srv: read 0 len

Normally if you see a socket read return 0, it's because the other side 
has closed.

> [16] closing http fd 21273552
> [16] close: just_kill_connection
> [8] remove_wsi_socket_from_fds: wsi=0x1449b10, sock=5, fds pos=1
> LWS_CALLBACK_DEL_POLL_FD
> [16] not calling back closed
>
> What could be the problem?

I'm not certain there is a problem... what is the peer your server talks 
to and what did it send / log about that?

-Andy

> For certificates, I created a certificate-key pair using open ssl, these work fine with my local apache instance. The code to setup the server is as follows:
>
> int main(void) {
>     // server url will be http://localhost:7681
>     int port = 8080;
>     const char *interface = NULL;
>     struct libwebsocket_context *context;
>     int opts = 0;
>
> 	lws_set_log_level(31, log_function);
>
> 	struct lws_context_creation_info info;
>
> 	memset(&info, 0, sizeof info);
> 	info.port = port;
> 	info.iface = interface;
> 	info.protocols = protocols;
> 	info.extensions = libwebsocket_get_internal_extensions();
> 	info.ssl_cert_filepath = "/etc/apache2/ssl/apache.crt";
> 	info.ssl_private_key_filepath = "/etc/apache2/ssl/apache.key";
> 	info.gid = -1;
> 	info.uid = -1;
> 	info.options = opts;
>
> 	context = libwebsocket_create_context(&info);
>
>     if (context == NULL) {
>         fprintf(stderr, "libwebsocket init failed\n");
>         return -1;
>     }
>
>     printf("starting server...\n");
>
>     while (1) {
>         libwebsocket_service(context, 50);
>     }
>
>     libwebsocket_context_destroy(context);
>
>     return 0;
> }
>
> My callback function prints to stdout for each callback and always returns 0.
>
> Any help would be greatly appreciated.
>
>
> Best regards,
>
> Torsten
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets
>




More information about the Libwebsockets mailing list