[Libwebsockets] lwsws

Andy Green andy at warmcat.com
Fri Nov 30 11:59:14 CET 2018



On 30/11/2018 18:31, Vitaly Shevtsov wrote:
> Good day! I use vanila lwsws and try to implement simple plugin. In 
> plugin I use lws_client_connect_via_info to connect to another 
> WS-server. On the server side I see my connection but I can't see 
> LWS_CALLBACK_CLIENT_ESTABLISHED callback in plugin. What may be wrong?
> 
> Forgot to mention: If I use this plugin standalone, client connection 
> works as expected.
> Thanks!
> 
> 
> On November 29, 2018 10:22:47 PM GMT+08:00, Vitaly Shevtsov 
> <shev.vt1984 at gmail.com 
> <https://e.mail.ru/compose/?mailto=mailto%3ashev.vt1984@gmail.com>> wrote:
>  >Good day! I use vanila lwsws and try to implement simple plugin. In
>  >plugin
>  >I use lws_client_connect_via_info to connect to another WS-server. On
>  >the
>  >server side I see my connection but I can't see
>  >LWS_CALLBACK_CLIENT_ESTABLISHED callback in plugin. What may be wrong?
> 
> You need "enable-client-ssl": "1" on the config for the vhost you 
> created the client on, if the destination is wss.
> 
> You also need to list your protocol under "ws-protocols" for the vhost conf.
> 
> Notice the client connect info struct allows you to bind the new 
> connection to a specific local protocol name.
> 
> https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-client.h#n108-114
> 
> But nost of all you need to enable logging with eg, -d1039 and confirm 
> your plugin loaded and the protocol is there.  And look at the logging 
> to see what it says about the client connect.
> 
> If you want to follow up please use the mailing list.
> 
> -Andy
> 
>  >Thanks!
> 
> 
> Thanks for your reply. Unfortunately this didn't help, all you wrote 
> have been done before and works well when there is no client connection 
> inside the plugin.

Yeah... well... "why doesn't this work" with no logs or reproducer is a 
bit of an optimistic question, isn't it.

> I found the way to reproduce this issue - I attached modified 
> protocol_dumb_increment.c to show what I mean. Thanks!

That just crashes as it is... it's missing this:

@@ -56,10 +88,14 @@ callback_dumb_increment(struct lws *wsi, enum 
lws_callback_reasons reason,
                         sizeof(struct vhd__dumb_increment));
                 if (!vhd)
                         return -1;
+               vhd->context = lws_get_context(wsi);
                 if ((opt = lws_pvo_search(
                                 (const struct 
lws_protocol_vhost_options *)in,
                                 "options")))
                         vhd->options = (unsigned int *)opt->value;


Trying it like this he seems happy

$ libwebsockets-test-server -s -d1031
[2018/11/30 18:53:36:0006] NOTICE: libwebsockets test server - license 
LGPL2.1+SLE
[2018/11/30 18:53:36:0006] NOTICE: (C) Copyright 2010-2018 Andy Green 
<andy at warmcat.com>
Using resource path "/usr/local/share/libwebsockets-test-server"
[2018/11/30 18:53:37:0057] NOTICE: Creating Vhost 'default' port 7681, 5 
protocols, IPv6 off
[2018/11/30 18:53:37:0058] NOTICE:  SSL ciphers: 
'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4:!HMAC_SHA1:!SHA1:!DHE-RSA-AES128-GCM-SHA256:!DHE-RSA-AES128-SHA256:!AES128-GCM-SH...
[2018/11/30 18:53:37:0058] NOTICE:  Using SSL mode
[2018/11/30 18:53:37:0062] NOTICE:  SSL ECDH curve 'prime256v1'
[2018/11/30 18:53:37:0105] NOTICE: lws_tls_client_create_vhost_context: 
doing cert filepath 
/usr/local/share/libwebsockets-test-server/libwebsockets-test-server.pem
[2018/11/30 18:53:37:0106] NOTICE: Loaded client cert 
/usr/local/share/libwebsockets-test-server/libwebsockets-test-server.pem
[2018/11/30 18:53:37:0106] NOTICE: lws_tls_client_create_vhost_context: 
doing private key filepath
[2018/11/30 18:53:37:0106] NOTICE: Loaded client cert private key 
/usr/local/share/libwebsockets-test-server/libwebsockets-test-server.key.pem
[2018/11/30 18:53:37:0106] NOTICE: created client ssl context for default
[2018/11/30 18:53:37:0107] USER: connecting to libwebsockets.org:443/
[2018/11/30 18:53:37:0173] NOTICE:    vhost default: cert expiry: 9998d
[2018/11/30 18:53:38:7986] USER: LWS_CALLBACK_CLIENT_ESTABLISHED
[2018/11/30 18:53:38:8392] USER: LWS_CALLBACK_CLIENT_RECEIVE
[2018/11/30 18:53:39:0929] USER: LWS_CALLBACK_CLIENT_RECEIVE
[2018/11/30 18:53:39:1102] USER: LWS_CALLBACK_CLIENT_RECEIVE
[2018/11/30 18:53:39:1602] USER: LWS_CALLBACK_CLIENT_RECEIVE
[2018/11/30 18:53:39:3880] USER: LWS_CALLBACK_CLIENT_RECEIVE
...

Running him under lwsws also works

[agreen at learn build]$ sudo /usr/local/bin/lwsws
Root process is 53269
lwsws libwebsockets web server - license CC0 + LGPL2.1
(C) Copyright 2010-2018 Andy Green <andy at warmcat.com>
Using config dir: "/etc/lwsws"
   Plugins:
   Scanning /usr/local/share/libwebsockets-test-server/plugins/
    libprotocol_client_loopback_test.so
    libprotocol_deaddrop.so
    libprotocol_dumb_increment.so
    libprotocol_fulltext_demo.so
    libprotocol_generic_sessions.so
    libprotocol_lws_acme_client.so
    libprotocol_lws_messageboard.so
    libprotocol_lws_meta.so
    libprotocol_lws_mirror.so
    libprotocol_lws_raw_test.so
    libprotocol_lws_server_status.so
    libprotocol_lws_ssh_base.so
    libprotocol_lws_sshd_demo.so
    libprotocol_lws_status.so
    libprotocol_lws_table_dirlisting.so
    libprotocol_post_demo.so
  Using foreign event loop...
   adding header content-security-policy=default-src 'none'; img-src 
'self' data: https://travis-ci.org https://api.travis-ci.org 
https://ci.appveyor.com https://scan.coverity.com; script-src 'self'; 
font-src 'self'; style-src 'self'; connect-src 'self...
   adding header x-content-type-options=nosniff
   adding header x-xss-protection=1; mode=block
   adding header x-frame-options=deny
   adding header referrer-policy=no-referrer
   + extra-mimetypes .ttf -> application/x-font-truetype
   + extra-mimetypes .otf -> application/font-sfnt
   + extra-mimetypes .zip -> application/zip
   + extra-mimetypes .webm -> video/webm
   + extra-mimetypes .romfs -> application/octet-stream
   + extra-mimetypes .pdf -> application/pdf
   + extra-mimetypes .odt -> application/vnd.oasis.opendocument.text
Creating Vhost 'localhost' port 7681, 8 protocols, IPv6 off
  SSL ciphers: 
'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4:!HMAC_SHA1:!SHA1:!DHE-RSA-AES128-GCM-SHA256:!DHE-RSA-AES128-SHA256:!AES128-GCM-SH...
  Using SSL mode
  SSL ECDH curve 'prime256v1'
lws_tls_client_create_vhost_context: doing cert filepath 
/usr/local/share/libwebsockets-test-server/libwebsockets-test-server.pem
Loaded client cert 
/usr/local/share/libwebsockets-test-server/libwebsockets-test-server.pem
lws_tls_client_create_vhost_context: doing private key filepath
Loaded client cert private key 
/usr/local/share/libwebsockets-test-server/libwebsockets-test-server.key.pem
created client ssl context for localhost
Creating Vhost 'sshd' port 2222, 3 protocols, IPv6 off
  Using non-SSL mode
connecting to libwebsockets.org:443/
   deaddrop: vh localhost, upload dir /var/cache/deaddrop-uploads, max 
size 10000000
Set privs to user 'apache'
    vhost localhost: cert expiry: 9998d
    vhost sshd: no cert
LWS_CALLBACK_CLIENT_ESTABLISHED
LWS_CALLBACK_CLIENT_RECEIVE
LWS_CALLBACK_CLIENT_RECEIVE
LWS_CALLBACK_CLIENT_RECEIVE
LWS_CALLBACK_CLIENT_RECEIVE
...

Assuming something different happens your end, please paste the logs.

If it's surprising to you that your reproducer was broken, then take a 
moment to confirm that the plugin you think lwsws is pulling in, is 
actually created from the sources you think it should use to create that.

-Andy

> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets
> 


More information about the Libwebsockets mailing list