warmcat / libwebsockets

canonical libwebsockets.org networking library
https://libwebsockets.org
Other
4.75k stars 1.48k forks source link

hello,I would like to ask a question. I made a client using the libwebsockets version 4.0 library, and then I need to access a wss server. The handshake always fails. Maybe there is a problem with loading the certificate? #2711

Closed hbbproc closed 2 years ago

hbbproc commented 2 years ago

url:wss://demo.piesocket.com/v3/channel_1?api_key=VCXCEuvhGcBDP7XhiJJUDvR1e1D3eiVjgZ9VRiaV&notify_self I loaded the certificate like this, info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; info.ssl_ca_filepath = "./ca-cert.pem"; info.ssl_cert_filepath = "./client-cert.pem";

connectInfo.ssl_connection =LCCSCF_USE_SSL | LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK | LCCSCF_ALLOW_INSECURE | LCCSCF_ALLOW_SELFSIGNED;

Is there a problem with loading the certificate like this or openssl library not working? Can you help me;

In addition, the executable program libwebsockets-test-client compiled using the libwebsockets library cannot access the URL above. I do not know why,Can you help me

lws-team commented 2 years ago

Not really... there are no logs shown.

In addition, the executable program libwebsockets-test-client compiled using the libwebsockets library cannot access the URL above. I do not know why,Can you help me

"Cannot access the URL above" who knows what it even means.

| LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK | LCCSCF_ALLOW_INSECURE | LCCSCF_ALLOW_SELFSIGNED;

Don't do this. Use the right hostname and appropriate certs.

hbbproc commented 2 years ago

I used this branch origin/v4.0-stable to compile libwebsockets-test-client, and then visited the URL: wss://demo.piesocket.com/v3/channel_1?api_key=VCXCEuvhGcBDP7XhiJJUDvR1e1D3eiVjgZ9VRiaV&notify_self , but encountered the following log problem

./libwebsockets-test-client wss://demo.piesocket.com/v3/channel_1?api_key=VCXCEuvhGcBDP7XhiJJUDvR1e1D3eiVjgZ9VRiaV&notify_self --ssl [1] 24975 [2022/08/19 16:45:29:9432] N: libwebsockets test client - license MIT [2022/08/19 16:45:29:9433] N: (C) Copyright 2010-2018 Andy Green andy@warmcat.com [2022/08/19 16:45:29:9433] N: Using SSL [2022/08/19 16:45:29:9433] N: Cert must validate correctly (use -s to allow selfsigned) [2022/08/19 16:45:29:9433] N: Requiring peer cert hostname matches [2022/08/19 16:45:29:9433] W: lws_create_context: LWS_WITHOUT_EXTENSIONS but extensions ptr set [2022/08/19 16:45:29:9442] N: using wss mode (ws) [2022/08/19 16:45:29:9442] N: dumb: connecting Traceback (most recent call last): File "/usr/lib/command-not-found", line 28, in from CommandNotFound import CommandNotFound File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in from CommandNotFound.db.db import SqliteDatabase File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in import apt_pkg ModuleNotFoundError: No module named 'apt_pkg' [2022/08/19 16:45:29:9756] N: mirror: connecting [2022/08/19 16:45:30:7977] W: lws_client_handshake: got bad HTTP response '426' [2022/08/19 16:45:37:0488] W: lws_client_handshake: got bad HTTP response '426' [2022/08/19 16:45:37:0488] E: CLIENT_CONNECTION_ERROR: dumb: HS: ws upgrade response not 101 [2022/08/19 16:45:37:0489] N: dumb: connecting [2022/08/19 16:45:38:8367] W: lws_client_handshake: got bad HTTP response '426' [2022/08/19 16:45:38:8367] E: CLIENT_CONNECTION_ERROR: dumb: HS: ws upgrade response not 101 [2022/08/19 16:45:39:9543] N: dumb: connecting [2022/08/19 16:45:41:3470] W: lws_client_handshake: got bad HTTP response '426' [2022/08/19 16:45:41:3470] E: CLIENT_CONNECTION_ERROR: dumb: HS: ws upgrade response not 101 [2022/08/19 16:45:41:3471] N: dumb: connecting [2022/08/19 16:45:44:0135] W: lws_client_handshake: got bad HTTP response '426' [2022/08/19 16:45:44:0135] E: CLIENT_CONNECTION_ERROR: dumb: HS: ws upgrade response not 101 [2022/08/19 16:45:44:0137] N: dumb: connecting [2022/08/19 16:45:44:8328] W: lws_client_handshake: got bad HTTP response '426' [2022/08/19 16:45:44:8328] E: CLIENT_CONNECTION_ERROR: dumb: HS: ws upgrade response not 101

lws-team commented 2 years ago

[2022/08/19 16:45:37:0488] W: lws_client_handshake: got bad HTTP response '426'

Server doesn't want to talk to you... 426 is confusing because it's "upgrade required" but we think we sent an upgrade. You can use -DLWS_TLS_LOG_PLAINTEXT_RX=1 (and ..._TX=1) to have lws dump everything it sends receives to the logs and maybe get a clue that way.

hbbproc commented 2 years ago

But I can't find the flag, how can I find the flg DLWS_TLS_LOG_PLAINTEXT_RX or _TX?

lws-team commented 2 years ago

These are flags you can give cmake (defined in CMakeLists.txt) to set options. If your lws is too old to have them, use a later lws.

hbbproc commented 2 years ago

I found that there is no change in the log after adding this logo, and the source code of this logo cannot be searched. as follows: command: ./libwebsockets-test-client wss://iat-api.xfyun.cn/v2/iat?authorization=YXBpX2tleT0iMTRkNjVmMzU2MzQyNWJkNWZmOGMyOTFiMjIwYzBjNDIiLCBhbGdvcml0aG09ImhtYWMtc2hhMjU2IiwgaGVhZGVycz0iaG9zdCBkYXRlIHJlcXVlc3QtbGluZSIsIHNpZ25hdHVyZT0iT05Bck9PeG9yelVFaFFia1NwR3IxbGd2aSthUlBQWU83QVJHVFhsSzg2Yz0i&date=Mon, 22 Aug 2022 01:40:31 GMT&host=iat-api.xfyun.cn --ssl [1] 100181 [2] 100182 [2022/08/22 16:04:32:0054] N: libwebsockets test client - license MIT [2022/08/22 16:04:32:0055] N: (C) Copyright 2010-2018 Andy Green andy@warmcat.com [2022/08/22 16:04:32:0055] N: Using SSL [2022/08/22 16:04:32:0055] N: Cert must validate correctly (use -s to allow selfsigned) [2022/08/22 16:04:32:0055] N: Requiring peer cert hostname matches [2022/08/22 16:04:32:0055] W: lws_create_context: LWS_WITHOUT_EXTENSIONS but extensions ptr set [2022/08/22 16:04:32:0065] N: using wss mode (ws) [2022/08/22 16:04:32:0065] N: dumb: connecting [2022/08/22 16:04:32:0070] N: mirror: connecting Traceback (most recent call last): File "/usr/lib/command-not-found", line 28, in Traceback (most recent call last): from CommandNotFound import CommandNotFound File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in File "/usr/lib/command-not-found", line 28, in from CommandNotFound.db.db import SqliteDatabase File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in from CommandNotFound import CommandNotFound File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in import apt_pkg ModuleNotFoundError: No module named 'apt_pkg' from CommandNotFound.db.db import SqliteDatabase File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in import apt_pkg ModuleNotFoundError: No module named 'apt_pkg' [2]+ 退出 1 date=Mon, 22 Aug 2022 01:40:31 GMT [2022/08/22 16:04:32:1431] W: lws_client_handshake: got bad HTTP response '401' [2022/08/22 16:04:32:1492] W: lws_client_handshake: got bad HTTP response '401' [2022/08/22 16:04:32:1492] E: CLIENT_CONNECTION_ERROR: dumb: HS: ws upgrade unauthorized [2022/08/22 16:04:34:0089] N: dumb: connecting

lws-team commented 2 years ago

If your lws is too old to have them, use a later lws.

hbbproc commented 2 years ago

I use the latest version v4.3-stable. I always thought that there was something wrong with my certificate, but now I look at the log. I didn't find the logo DLWS_TLS_LOG_PLAINTEXT_RX in the latest version. The logs I caught are as follows:

./libwebsockets-test-client wss://iat-api.xfyun.cn/v2/iat?authorization=YXBpX2tleT0iMTRkNjVmMzU2MzQyNWJkNWZmOGMyOTFiMjIwYzBjNDIiLCBhbGdvcml0aG09ImhtYWMtc2hhMjU2IiwgaGVhZGVycz0iaG9zdCBkYXRlIHJlcXVlc3QtbGluZSIsIHNpZ25hdHVyZT0ic3JkbWwvTHAydVVxQ3hmdEhSeWEybElGZDJRc1lETkpKR0V4NnRsZW11Zz0i&date=Tue, 23 Aug 2022 01:48:34 GMT&host=iat-api.xfyun.cn --ssl [1] 3699 [2] 3700 [2022/08/23 10:26:31:3332] N: libwebsockets test client - license MIT [2022/08/23 10:26:31:3333] N: (C) Copyright 2010-2018 Andy Green andy@warmcat.com [2022/08/23 10:26:31:3333] N: Using SSL [2022/08/23 10:26:31:3333] N: Cert must validate correctly (use -s to allow selfsigned) [2022/08/23 10:26:31:3333] N: Requiring peer cert hostname matches [2022/08/23 10:26:31:3333] N: lws_create_context: LWS: 4.3.2-v4.3.2-14-g39f6379c, NET CLI SRV H1 H2 WS ConMon IPv6-absent [2022/08/23 10:26:31:3334] N: lws_lc_tag: ++ [wsi|0|pipe] (1) [2022/08/23 10:26:31:3334] N: lws_lc_tag: ++ [vh|0|netlink] (1) [2022/08/23 10:26:31:3343] N: lws_lc_tag: ++ [vh|1|default||-1] (2) [2022/08/23 10:26:31:3345] N: openssl [2022/08/23 10:26:31:3345] N: lws_tls_client_create_vhost_context: doing cert filepath /home/herry/work/client-cert.pem [2022/08/23 10:26:31:3346] N: using wss mode (ws) [2022/08/23 10:26:31:3346] N: dumb: connecting [2022/08/23 10:26:31:3346] N: lws_lc_tag: ++ [wsicli|0|WS/h1/default/iat-api.xfyun.cn] (1) Traceback (most recent call last): Traceback (most recent call last): File "/usr/lib/command-not-found", line 28, in File "/usr/lib/command-not-found", line 28, in from CommandNotFound import CommandNotFound from CommandNotFound import CommandNotFound File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in from CommandNotFound.db.db import SqliteDatabase File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in from CommandNotFound.db.db import SqliteDatabase File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in import apt_pkg ModuleNotFoundError: No module named 'apt_pkg' import apt_pkg ModuleNotFoundError: No module named 'apt_pkg' [2]+ 退出 1 date=Tue, 23 Aug 2022 01:48:34 GMT [2022/08/23 10:26:31:3692] N: mirror: connecting [2022/08/23 10:26:31:3692] N: lws_lc_tag: ++ [wsicli|1|WS/h1/default/iat-api.xfyun.cn] (2) [2022/08/23 10:26:31:3912] N: lws_gate_accepts: on = 0 [2022/08/23 10:26:31:3948] N: lws_gate_accepts: on = 0 [2022/08/23 10:26:31:4153] N: lws_gate_accepts: on = 0 [2022/08/23 10:26:31:4226] N: lws_gate_accepts: on = 0 [2022/08/23 10:26:31:4596] W: [wsicli|1|WS/h1/default/iat-api.xfyun.cn]: lws_client_ws_upgrade: got bad HTTP response '401' [2022/08/23 10:26:31:4598] N: lws_gate_accepts: on = 0 [2022/08/23 10:26:31:4599] N: lws_lc_untag: -- [wsicli|1|WS/h1/default/iat-api.xfyun.cn] (1) 90.679ms [2022/08/23 10:26:31:4755] N: lws_http_client_http_response 401 [2022/08/23 10:26:31:4756] N: Peer Cert CN : /C=CN/ST=Anhui/L=Hefei/OU=IT [2022/08/23 10:26:31:4756] N: Peer Cert issuer : /C=BE/O=GlobalSign nv-sa/CN=GlobalSign RSA OV SSL CA 2018 [2022/08/23 10:26:31:4756] N: Peer Cert Valid from: Mon Oct 18 02:09:05 2021 [2022/08/23 10:26:31:4756] N: Peer Cert Valid to : Sat Nov 19 02:09:05 2022 [2022/08/23 10:26:31:4756] N: Peer Cert usage bits: 0xa0

lws-team commented 2 years ago

https://libwebsockets.org/git/libwebsockets/tree/CMakeLists.txt#n206

hbbproc commented 2 years ago

I find the flags and I get the logs,as follows: [2022/08/23 15:23:21:6555] N: lws_gate_accepts: on = 0 [2022/08/23 15:23:21:6556] N: lws_ssl_capable_write: len 514 [2022/08/23 15:23:21:6556] N: [2022/08/23 15:23:21:6556] N: 0000: 47 45 54 20 2F 76 32 2F 69 61 74 3F 61 75 74 68 GET /v2/iat?auth [2022/08/23 15:23:21:6556] N: 0010: 6F 72 69 7A 61 74 69 6F 6E 3D 59 58 42 70 58 32 orization=YXBpX2 [2022/08/23 15:23:21:6556] N: 0020: 74 6C 65 54 30 69 4D 54 52 6B 4E 6A 56 6D 4D 7A tleT0iMTRkNjVmMz [2022/08/23 15:23:21:6556] N: 0030: 55 32 4D 7A 51 79 4E 57 4A 6B 4E 57 5A 6D 4F 47 U2MzQyNWJkNWZmOG [2022/08/23 15:23:21:6556] N: 0040: 4D 79 4F 54 46 69 4D 6A 49 77 59 7A 42 6A 4E 44 MyOTFiMjIwYzBjND [2022/08/23 15:23:21:6556] N: 0050: 49 69 4C 43 42 68 62 47 64 76 63 6D 6C 30 61 47 IiLCBhbGdvcml0aG [2022/08/23 15:23:21:6556] N: 0060: 30 39 49 6D 68 74 59 57 4D 74 63 32 68 68 4D 6A 09ImhtYWMtc2hhMj [2022/08/23 15:23:21:6556] N: 0070: 55 32 49 69 77 67 61 47 56 68 5A 47 56 79 63 7A U2IiwgaGVhZGVycz [2022/08/23 15:23:21:6556] N: 0080: 30 69 61 47 39 7A 64 43 42 6B 59 58 52 6C 49 48 0iaG9zdCBkYXRlIH [2022/08/23 15:23:21:6556] N: 0090: 4A 6C 63 58 56 6C 63 33 51 74 62 47 6C 75 5A 53 JlcXVlc3QtbGluZS [2022/08/23 15:23:21:6556] N: 00A0: 49 73 49 48 4E 70 5A 32 35 68 64 48 56 79 5A 54 IsIHNpZ25hdHVyZT [2022/08/23 15:23:21:6556] N: 00B0: 30 69 5A 6C 4E 73 4D 54 6C 36 61 30 55 78 59 57 0iZlNsMTl6a0UxYW [2022/08/23 15:23:21:6556] N: 00C0: 31 6D 52 7A 4A 4C 5A 44 64 54 53 6E 68 49 4B 31 1mRzJLZDdTSnhIK1 [2022/08/23 15:23:21:6556] N: 00D0: 6C 50 4E 31 6C 55 5A 56 70 4D 64 58 56 61 59 55 lPN1lUZVpMdXVaYU [2022/08/23 15:23:21:6556] N: 00E0: 68 6D 61 58 70 6D 63 55 45 76 55 54 30 69 20 48 hmaXpmcUEvUT0i H [2022/08/23 15:23:21:6556] N: 00F0: 54 54 50 2F 31 2E 31 0D 0A 50 72 61 67 6D 61 3A TTP/1.1..Pragma: [2022/08/23 15:23:21:6556] N: 0100: 20 6E 6F 2D 63 61 63 68 65 0D 0A 43 61 63 68 65 no-cache..Cache [2022/08/23 15:23:21:6556] N: 0110: 2D 43 6F 6E 74 72 6F 6C 3A 20 6E 6F 2D 63 61 63 -Control: no-cac [2022/08/23 15:23:21:6557] N: 0120: 68 65 0D 0A 48 6F 73 74 3A 20 69 61 74 2D 61 70 he..Host: iat-ap [2022/08/23 15:23:21:6557] N: 0130: 69 2E 78 66 79 75 6E 2E 63 6E 0D 0A 4F 72 69 67 i.xfyun.cn..Orig [2022/08/23 15:23:21:6557] N: 0140: 69 6E 3A 20 68 74 74 70 73 3A 2F 2F 69 61 74 2D in: https://iat- [2022/08/23 15:23:21:6557] N: 0150: 61 70 69 2E 78 66 79 75 6E 2E 63 6E 0D 0A 55 70 api.xfyun.cn..Up [2022/08/23 15:23:21:6557] N: 0160: 67 72 61 64 65 3A 20 77 65 62 73 6F 63 6B 65 74 grade: websocket [2022/08/23 15:23:21:6557] N: 0170: 0D 0A 43 6F 6E 6E 65 63 74 69 6F 6E 3A 20 55 70 ..Connection: Up [2022/08/23 15:23:21:6557] N: 0180: 67 72 61 64 65 0D 0A 53 65 63 2D 57 65 62 53 6F grade..Sec-WebSo [2022/08/23 15:23:21:6557] N: 0190: 63 6B 65 74 2D 4B 65 79 3A 20 43 58 49 65 46 74 cket-Key: CXIeFt [2022/08/23 15:23:21:6557] N: 01A0: 39 32 73 34 30 51 48 51 79 4C 64 47 45 7A 75 41 92s40QHQyLdGEzuA [2022/08/23 15:23:21:6557] N: 01B0: 3D 3D 0D 0A 53 65 63 2D 57 65 62 53 6F 63 6B 65 ==..Sec-WebSocke [2022/08/23 15:23:21:6557] N: 01C0: 74 2D 50 72 6F 74 6F 63 6F 6C 3A 20 64 75 6D 62 t-Protocol: dumb [2022/08/23 15:23:21:6557] N: 01D0: 2D 69 6E 63 72 65 6D 65 6E 74 2D 70 72 6F 74 6F -increment-proto [2022/08/23 15:23:21:6557] N: 01E0: 63 6F 6C 0D 0A 53 65 63 2D 57 65 62 53 6F 63 6B col..Sec-WebSock [2022/08/23 15:23:21:6557] N: 01F0: 65 74 2D 56 65 72 73 69 6F 6E 3A 20 31 33 0D 0A et-Version: 13.. [2022/08/23 15:23:21:6557] N: 0200: 0D 0A ..
[2022/08/23 15:23:21:6557] N: [2022/08/23 15:23:21:6563] N: lws_gate_accepts: on = 0 [2022/08/23 15:23:21:6563] N: lws_ssl_capable_write: len 510 [2022/08/23 15:23:21:6564] N: [2022/08/23 15:23:21:6564] N: 0000: 47 45 54 20 2F 76 32 2F 69 61 74 3F 61 75 74 68 GET /v2/iat?auth [2022/08/23 15:23:21:6564] N: 0010: 6F 72 69 7A 61 74 69 6F 6E 3D 59 58 42 70 58 32 orization=YXBpX2 [2022/08/23 15:23:21:6564] N: 0020: 74 6C 65 54 30 69 4D 54 52 6B 4E 6A 56 6D 4D 7A tleT0iMTRkNjVmMz [2022/08/23 15:23:21:6564] N: 0030: 55 32 4D 7A 51 79 4E 57 4A 6B 4E 57 5A 6D 4F 47 U2MzQyNWJkNWZmOG [2022/08/23 15:23:21:6564] N: 0040: 4D 79 4F 54 46 69 4D 6A 49 77 59 7A 42 6A 4E 44 MyOTFiMjIwYzBjND [2022/08/23 15:23:21:6564] N: 0050: 49 69 4C 43 42 68 62 47 64 76 63 6D 6C 30 61 47 IiLCBhbGdvcml0aG [2022/08/23 15:23:21:6564] N: 0060: 30 39 49 6D 68 74 59 57 4D 74 63 32 68 68 4D 6A 09ImhtYWMtc2hhMj [2022/08/23 15:23:21:6564] N: 0070: 55 32 49 69 77 67 61 47 56 68 5A 47 56 79 63 7A U2IiwgaGVhZGVycz [2022/08/23 15:23:21:6564] N: 0080: 30 69 61 47 39 7A 64 43 42 6B 59 58 52 6C 49 48 0iaG9zdCBkYXRlIH [2022/08/23 15:23:21:6564] N: 0090: 4A 6C 63 58 56 6C 63 33 51 74 62 47 6C 75 5A 53 JlcXVlc3QtbGluZS [2022/08/23 15:23:21:6564] N: 00A0: 49 73 49 48 4E 70 5A 32 35 68 64 48 56 79 5A 54 IsIHNpZ25hdHVyZT [2022/08/23 15:23:21:6564] N: 00B0: 30 69 5A 6C 4E 73 4D 54 6C 36 61 30 55 78 59 57 0iZlNsMTl6a0UxYW [2022/08/23 15:23:21:6564] N: 00C0: 31 6D 52 7A 4A 4C 5A 44 64 54 53 6E 68 49 4B 31 1mRzJLZDdTSnhIK1 [2022/08/23 15:23:21:6564] N: 00D0: 6C 50 4E 31 6C 55 5A 56 70 4D 64 58 56 61 59 55 lPN1lUZVpMdXVaYU [2022/08/23 15:23:21:6564] N: 00E0: 68 6D 61 58 70 6D 63 55 45 76 55 54 30 69 20 48 hmaXpmcUEvUT0i H [2022/08/23 15:23:21:6565] N: 00F0: 54 54 50 2F 31 2E 31 0D 0A 50 72 61 67 6D 61 3A TTP/1.1..Pragma: [2022/08/23 15:23:21:6565] N: 0100: 20 6E 6F 2D 63 61 63 68 65 0D 0A 43 61 63 68 65 no-cache..Cache [2022/08/23 15:23:21:6565] N: 0110: 2D 43 6F 6E 74 72 6F 6C 3A 20 6E 6F 2D 63 61 63 -Control: no-cac [2022/08/23 15:23:21:6565] N: 0120: 68 65 0D 0A 48 6F 73 74 3A 20 69 61 74 2D 61 70 he..Host: iat-ap [2022/08/23 15:23:21:6565] N: 0130: 69 2E 78 66 79 75 6E 2E 63 6E 0D 0A 4F 72 69 67 i.xfyun.cn..Orig [2022/08/23 15:23:21:6565] N: 0140: 69 6E 3A 20 68 74 74 70 73 3A 2F 2F 69 61 74 2D in: https://iat- [2022/08/23 15:23:21:6565] N: 0150: 61 70 69 2E 78 66 79 75 6E 2E 63 6E 0D 0A 55 70 api.xfyun.cn..Up [2022/08/23 15:23:21:6565] N: 0160: 67 72 61 64 65 3A 20 77 65 62 73 6F 63 6B 65 74 grade: websocket [2022/08/23 15:23:21:6565] N: 0170: 0D 0A 43 6F 6E 6E 65 63 74 69 6F 6E 3A 20 55 70 ..Connection: Up [2022/08/23 15:23:21:6565] N: 0180: 67 72 61 64 65 0D 0A 53 65 63 2D 57 65 62 53 6F grade..Sec-WebSo [2022/08/23 15:23:21:6565] N: 0190: 63 6B 65 74 2D 4B 65 79 3A 20 39 50 61 74 35 43 cket-Key: 9Pat5C [2022/08/23 15:23:21:6565] N: 01A0: 71 51 67 4E 6D 38 56 55 33 66 56 48 44 4A 7A 41 qQgNm8VU3fVHDJzA [2022/08/23 15:23:21:6565] N: 01B0: 3D 3D 0D 0A 53 65 63 2D 57 65 62 53 6F 63 6B 65 ==..Sec-WebSocke [2022/08/23 15:23:21:6565] N: 01C0: 74 2D 50 72 6F 74 6F 63 6F 6C 3A 20 6C 77 73 2D t-Protocol: lws- [2022/08/23 15:23:21:6565] N: 01D0: 6D 69 72 72 6F 72 2D 70 72 6F 74 6F 63 6F 6C 0D mirror-protocol. [2022/08/23 15:23:21:6565] N: 01E0: 0A 53 65 63 2D 57 65 62 53 6F 63 6B 65 74 2D 56 .Sec-WebSocket-V [2022/08/23 15:23:21:6565] N: 01F0: 65 72 73 69 6F 6E 3A 20 31 33 0D 0A 0D 0A ersion: 13....
[2022/08/23 15:23:21:6565] N: [2022/08/23 15:23:21:7061] N: lws_ssl_capable_read: len 220 [2022/08/23 15:23:21:7062] N: [2022/08/23 15:23:21:7062] N: 0000: 48 54 54 50 2F 31 2E 31 20 34 30 31 20 55 6E 61 HTTP/1.1 401 Una [2022/08/23 15:23:21:7062] N: 0010: 75 74 68 6F 72 69 7A 65 64 0D 0A 44 61 74 65 3A uthorized..Date: [2022/08/23 15:23:21:7062] N: 0020: 20 54 75 65 2C 20 32 33 20 41 75 67 20 32 30 32 Tue, 23 Aug 202 [2022/08/23 15:23:21:7062] N: 0030: 32 20 30 37 3A 32 33 3A 32 31 20 47 4D 54 0D 0A 2 07:23:21 GMT.. [2022/08/23 15:23:21:7062] N: 0040: 43 6F 6E 74 65 6E 74 2D 54 79 70 65 3A 20 61 70 Content-Type: ap [2022/08/23 15:23:21:7062] N: 0050: 70 6C 69 63 61 74 69 6F 6E 2F 6A 73 6F 6E 3B 20 plication/json; [2022/08/23 15:23:21:7062] N: 0060: 63 68 61 72 73 65 74 3D 75 74 66 2D 38 0D 0A 43 charset=utf-8..C [2022/08/23 15:23:21:7062] N: 0070: 6F 6E 6E 65 63 74 69 6F 6E 3A 20 6B 65 65 70 2D onnection: keep- [2022/08/23 15:23:21:7062] N: 0080: 61 6C 69 76 65 0D 0A 43 6F 6E 74 65 6E 74 2D 4C alive..Content-L [2022/08/23 15:23:21:7062] N: 0090: 65 6E 67 74 68 3A 20 34 33 0D 0A 53 65 72 76 65 ength: 43..Serve [2022/08/23 15:23:21:7062] N: 00A0: 72 3A 20 6B 6F 6E 67 2F 31 2E 33 2E 30 0D 0A 0D r: kong/1.3.0... [2022/08/23 15:23:21:7062] N: 00B0: 0A 7B 22 6D 65 73 73 61 67 65 22 3A 22 48 4D 41 .{"message":"HMA [2022/08/23 15:23:21:7062] N: 00C0: 43 20 73 69 67 6E 61 74 75 72 65 20 64 6F 65 73 C signature does [2022/08/23 15:23:21:7062] N: 00D0: 20 6E 6F 74 20 6D 61 74 63 68 22 7D not match"}
[2022/08/23 15:23:21:7062] N: [2022/08/23 15:23:21:7062] W: [wsicli|1|WS/h1/default/iat-api.xfyun.cn]: lws_client_ws_upgrade: got bad HTTP response '401'

I want to ask if the server needs to verify the certificate, must both info.client_ssl_cert_filepath and info.ssl_cert_filepath exist? Currently only client_ssl_cert_filepath is assigned in the demo, but I currently only get the server's certificate according to the domain name, namely ssl_cert_filepath.

lws-team commented 2 years ago

This isn't directly to do with tls or you cannot get the http response.

HMAC signature does not match

seems to be related to the magic string you are passing for auth, the server does not accept it. I don't think that is anything to do with lws if so, you need to confirm how you computed the magic string.

hbbproc commented 2 years ago

Sorry to ask again,But I use the 'Simple Web Socket Client' of Chrome plugin, it works. Simple Web Socket Client 's Information As below:

General Request URL: wss://iat-api.xfyun.cn/v2/iat?authorization=YXBpX2tleT0iMTRkNjVmMzU2MzQyNWJkNWZmOGMyOTFiMjIwYzBjNDIiLCBhbGdvcml0aG09ImhtYWMtc2hhMjU2IiwgaGVhZGVycz0iaG9zdCBkYXRlIHJlcXVlc3QtbGluZSIsIHNpZ25hdHVyZT0iTG15cW5uWWNyZDQxZjBzKzdsWjNhSXZYQ05OZWRtRHVDTitReXBuTndFRT0i&date=Wed,%2024%20Aug%202022%2007:30:31%20GMT&host=iat-api.xfyun.cn Request Method: GET Status Code: 101 Switching Protocols

Response Headers Connection: upgrade Sec-WebSocket-Accept: AnjFaCVktMh3sm1VSnAsthyCNCw= Upgrade: websocket Via: kong/1.3.0 X-Kong-Proxy-Latency: 1 X-Kong-Upstream-Latency: 0

Request Headers Accept-Encoding: gzip, deflate, br Accept-Language: zh-CN,zh;q=0.9 Cache-Control: no-cache Connection: Upgrade Host: iat-api.xfyun.cn Origin: chrome-extension://pfdhoblngboilpfeibdedpjgfnlcodoo Pragma: no-cache Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits Sec-WebSocket-Key: Qb5GfwrTQ29uC4qvBrIbCg== Sec-WebSocket-Version: 13 Upgrade: websocket User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36

Postman software can also shake hands successfully, Handshake Details As below: Request URL: https://iat-api.xfyun.cn/v2/iat?authorization=YXBpX2tleT0iMTRkNjVmMzU2MzQyNWJkNWZmOGMyOTFiMjIwYzBjNDIiLCBhbGdvcml0aG09ImhtYWMtc2hhMjU2IiwgaGVhZGVycz0iaG9zdCBkYXRlIHJlcXVlc3QtbGluZSIsIHNpZ25hdHVyZT0iTG15cW5uWWNyZDQxZjBzKzdsWjNhSXZYQ05OZWRtRHVDTitReXBuTndFRT0i&date=Wed,%2024%20Aug%202022%2007:30:31%20GMT&host=iat-api.xfyun.cn Request Method: GET Status Code: 101 Switching Protocols Request Headers Sec-WebSocket-Version: 13 Sec-WebSocket-Key: APPLhVCOXuoCD2p/ZNDgNA== Connection: Upgrade Upgrade: websocket Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits Host: iat-api.xfyun.cn Response Headers Connection: upgrade Upgrade: websocket Sec-WebSocket-Accept: g16bYdVD4TFeCG8MnT0coNdQ4/Q= X-Kong-Upstream-Latency: 0 X-Kong-Proxy-Latency: 1 Via: kong/1.3.0

use this URL: wss://iat-api.xfyun.cn/v2/iat?authorization=YXBpX2tleT0iMTRkNjVmMzU2MzQyNWJkNWZmOGMyOTFiMjIwYzBjNDIiLCBhbGdvcml0aG09ImhtYWMtc2hhMjU2IiwgaGVhZGVycz0iaG9zdCBkYXRlIHJlcXVlc3QtbGluZSIsIHNpZ25hdHVyZT0ibTN6aEtaREtzbVNzZFdzSVl1d3NBZjJQcWRDUzhmbDF3UW9XNHNxMW1MYz0i&date=Wed,%2024%20Aug%202022%2007:16:50%20GMT&host=iat-api.xfyun.cn

but I use ./libwebsockets-test-client wss://iat-api.xfyun.cn/v2/iat?authorization=YXBpX2tleT0iMTRkNjVmMzU2MzQyNWJkNWZmOGMyOTFiMjIwYzBjNDIiLCBhbGdvcml0aG09ImhtYWMtc2hhMjU2IiwgaGVhZGVycz0iaG9zdCBkYXRlIHJlcXVlc3QtbGluZSIsIHNpZ25hdHVyZT0ibTN6aEtaREtzbVNzZFdzSVl1d3NBZjJQcWRDUzhmbDF3UW9XNHNxMW1MYz0i&date=Wed,%2024%20Aug%202022%2007:16:50%20GMT&host=iat-api.xfyun.cn --ssl

error : HMAC signature does not match; 401

I have tried many methods, but still no results, so I will ask again.

lws-team commented 2 years ago

I don't know why you are asking me... this is your code not mine.

Are you sending the same URL args as the other case with lws? No. Is lws sending what you tell it? Yes. Please solve your own problem on your own.

hbbproc commented 2 years ago

OK, thank for your help.