2020-02-29 12:37:24 +00:00
|
|
|
/*
|
|
|
|
* lws-minimal-secure-streams
|
|
|
|
*
|
|
|
|
* Written in 2010-2020 by Andy Green <andy@warmcat.com>
|
|
|
|
*
|
|
|
|
* This file is made available under the Creative Commons CC0 1.0
|
|
|
|
* Universal Public Domain Dedication.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This demonstrates a minimal http client using secure streams api.
|
|
|
|
*
|
|
|
|
* It visits https://warmcat.com/ and receives the html page there.
|
|
|
|
*
|
|
|
|
* This example is built two different ways from the same source... one includes
|
|
|
|
* the policy everything needed to fulfil the stream directly. The other -client
|
|
|
|
* variant has no policy itself and some other minor init changes, and connects
|
|
|
|
* to the -proxy example to actually get the connection done.
|
|
|
|
*
|
|
|
|
* In the -client build case, the example does not even init the tls libraries
|
|
|
|
* since the proxy part will take care of all that.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <libwebsockets.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uncomment to force network traffic through 127.0.0.1:1080
|
|
|
|
*
|
|
|
|
* On your local machine, you can run a SOCKS5 proxy like this
|
|
|
|
*
|
|
|
|
* $ ssh -N -D 0.0.0.0:1080 localhost -v
|
|
|
|
*
|
|
|
|
* If enabled, this also fetches a remote policy that also
|
|
|
|
* specifies that all traffic should go through the remote
|
|
|
|
* proxy.
|
|
|
|
*/
|
|
|
|
// #define VIA_LOCALHOST_SOCKS
|
|
|
|
|
2020-03-12 14:43:32 +00:00
|
|
|
static int interrupted, bad = 1, force_cpd_fail_portal,
|
ss: proxy: get rx flow control working
This fixes the proxy rx flow by adding an lws_dsh helper to hide the
off-by-one in the "kind" array (kind 0 is reserved for tracking the
unallocated dsh blocks).
For testing, it adds a --blob option on minimal-secure-streams[-client]
which uses a streamtype "bulkproxflow" from here
https://warmcat.com/policy/minimal-proxy-v4.2-v2.json
"bulkproxflow": {
"endpoint": "warmcat.com",
"port": 443,
"protocol": "h1",
"http_method": "GET",
"http_url": "blob.bin",
"proxy_buflen": 32768,
"proxy_buflen_rxflow_on_above": 24576,
"proxy_buflen_rxflow_off_below": 8192,
"tls": true,
"retry": "default",
"tls_trust_store": "le_via_dst"
}
This downloads a 51MB blob of random data with the SHA256sum
ed5720c16830810e5829dfb9b66c96b2e24efc4f93aa5e38c7ff4150d31cfbbf
The minimal-secure-streams --blob example client delays the download by
50ms every 10KiB it sees to force rx flow usage at the proxy.
It downloads the whole thing and checks the SHA256 is as expected.
Logs about rxflow status are available at LLL_INFO log level.
2021-04-07 14:25:07 +01:00
|
|
|
force_cpd_fail_no_internet, test_respmap, test_blob;
|
2020-06-30 16:42:37 +01:00
|
|
|
static unsigned int timeout_ms = 3000;
|
2020-02-29 12:37:24 +00:00
|
|
|
static lws_state_notify_link_t nl;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the -proxy app is fulfilling our connection, then we don't need to have
|
|
|
|
* the policy in the client.
|
|
|
|
*
|
|
|
|
* When we build with LWS_SS_USE_SSPC, the apis hook up to a proxy process over
|
|
|
|
* a Unix Domain Socket. To test that, you need to separately run the
|
|
|
|
* ./lws-minimal-secure-streams-proxy test app on the same machine.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if !defined(LWS_SS_USE_SSPC)
|
|
|
|
static const char * const default_ss_policy =
|
|
|
|
"{"
|
|
|
|
"\"release\":" "\"01234567\","
|
|
|
|
"\"product\":" "\"myproduct\","
|
|
|
|
"\"schema-version\":" "1,"
|
|
|
|
#if defined(VIA_LOCALHOST_SOCKS)
|
|
|
|
"\"via-socks5\":" "\"127.0.0.1:1080\","
|
|
|
|
#endif
|
|
|
|
|
|
|
|
"\"retry\": [" /* named backoff / retry strategies */
|
|
|
|
"{\"default\": {"
|
|
|
|
"\"backoff\": [" "1000,"
|
|
|
|
"2000,"
|
|
|
|
"3000,"
|
|
|
|
"5000,"
|
|
|
|
"10000"
|
|
|
|
"],"
|
|
|
|
"\"conceal\":" "5,"
|
|
|
|
"\"jitterpc\":" "20,"
|
|
|
|
"\"svalidping\":" "30,"
|
|
|
|
"\"svalidhup\":" "35"
|
|
|
|
"}}"
|
|
|
|
"],"
|
|
|
|
"\"certs\": [" /* named individual certificates in BASE64 DER */
|
|
|
|
/*
|
|
|
|
* Let's Encrypt certs for warmcat.com / libwebsockets.org
|
|
|
|
*
|
|
|
|
* We fetch the real policy from there using SS and switch to
|
|
|
|
* using that.
|
|
|
|
*/
|
2021-01-12 16:46:43 +00:00
|
|
|
"{\"dst_root_x3\": \""
|
|
|
|
"MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/"
|
|
|
|
"MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT"
|
|
|
|
"DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow"
|
|
|
|
"PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD"
|
|
|
|
"Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB"
|
|
|
|
"AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O"
|
|
|
|
"rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq"
|
|
|
|
"OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b"
|
|
|
|
"xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw"
|
|
|
|
"7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD"
|
|
|
|
"aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV"
|
|
|
|
"HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG"
|
|
|
|
"SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69"
|
|
|
|
"ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr"
|
|
|
|
"AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz"
|
|
|
|
"R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5"
|
|
|
|
"JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo"
|
|
|
|
"Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ"
|
2020-02-29 12:37:24 +00:00
|
|
|
"\"}"
|
|
|
|
"],"
|
|
|
|
"\"trust_stores\": [" /* named cert chains */
|
|
|
|
"{"
|
2021-01-12 16:46:43 +00:00
|
|
|
"\"name\": \"le_via_dst\","
|
2020-02-29 12:37:24 +00:00
|
|
|
"\"stack\": ["
|
2021-01-12 16:46:43 +00:00
|
|
|
"\"dst_root_x3\""
|
2020-02-29 12:37:24 +00:00
|
|
|
"]"
|
|
|
|
"}"
|
|
|
|
"],"
|
|
|
|
"\"s\": ["
|
2020-03-11 12:44:01 +00:00
|
|
|
/*
|
|
|
|
* "fetch_policy" decides from where the real policy
|
|
|
|
* will be fetched, if present. Otherwise the initial
|
|
|
|
* policy is treated as the whole, hardcoded, policy.
|
|
|
|
*/
|
2020-02-29 12:37:24 +00:00
|
|
|
"{\"fetch_policy\": {"
|
|
|
|
"\"endpoint\":" "\"warmcat.com\","
|
|
|
|
"\"port\":" "443,"
|
|
|
|
"\"protocol\":" "\"h1\","
|
|
|
|
"\"http_method\":" "\"GET\","
|
|
|
|
#if defined(VIA_LOCALHOST_SOCKS)
|
|
|
|
"\"http_url\":" "\"policy/minimal-proxy-socks.json\","
|
|
|
|
#else
|
ss: proxy: get rx flow control working
This fixes the proxy rx flow by adding an lws_dsh helper to hide the
off-by-one in the "kind" array (kind 0 is reserved for tracking the
unallocated dsh blocks).
For testing, it adds a --blob option on minimal-secure-streams[-client]
which uses a streamtype "bulkproxflow" from here
https://warmcat.com/policy/minimal-proxy-v4.2-v2.json
"bulkproxflow": {
"endpoint": "warmcat.com",
"port": 443,
"protocol": "h1",
"http_method": "GET",
"http_url": "blob.bin",
"proxy_buflen": 32768,
"proxy_buflen_rxflow_on_above": 24576,
"proxy_buflen_rxflow_off_below": 8192,
"tls": true,
"retry": "default",
"tls_trust_store": "le_via_dst"
}
This downloads a 51MB blob of random data with the SHA256sum
ed5720c16830810e5829dfb9b66c96b2e24efc4f93aa5e38c7ff4150d31cfbbf
The minimal-secure-streams --blob example client delays the download by
50ms every 10KiB it sees to force rx flow usage at the proxy.
It downloads the whole thing and checks the SHA256 is as expected.
Logs about rxflow status are available at LLL_INFO log level.
2021-04-07 14:25:07 +01:00
|
|
|
"\"http_url\":" "\"policy/minimal-proxy-v4.2-v2.json\","
|
2020-02-29 12:37:24 +00:00
|
|
|
#endif
|
|
|
|
"\"tls\":" "true,"
|
|
|
|
"\"opportunistic\":" "true,"
|
|
|
|
"\"retry\":" "\"default\","
|
2021-01-12 16:46:43 +00:00
|
|
|
"\"tls_trust_store\":" "\"le_via_dst\""
|
2020-03-11 12:44:01 +00:00
|
|
|
"}},{"
|
|
|
|
/*
|
|
|
|
* "captive_portal_detect" describes
|
|
|
|
* what to do in order to check if the path to
|
|
|
|
* the Internet is being interrupted by a
|
|
|
|
* captive portal. If there's a larger policy
|
|
|
|
* fetched from elsewhere, it should also include
|
|
|
|
* this since it needs to be done at least after
|
|
|
|
* every DHCP acquisition
|
|
|
|
*/
|
|
|
|
"\"captive_portal_detect\": {"
|
|
|
|
"\"endpoint\": \"connectivitycheck.android.com\","
|
|
|
|
"\"http_url\": \"generate_204\","
|
|
|
|
"\"port\": 80,"
|
|
|
|
"\"protocol\": \"h1\","
|
|
|
|
"\"http_method\": \"GET\","
|
|
|
|
"\"opportunistic\": true,"
|
|
|
|
"\"http_expect\": 204,"
|
|
|
|
"\"http_fail_redirect\": true"
|
|
|
|
"}}"
|
|
|
|
"]}"
|
2020-02-29 12:37:24 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct myss {
|
|
|
|
struct lws_ss_handle *ss;
|
|
|
|
void *opaque_data;
|
|
|
|
/* ... application specific state ... */
|
|
|
|
lws_sorted_usec_list_t sul;
|
ss: proxy: get rx flow control working
This fixes the proxy rx flow by adding an lws_dsh helper to hide the
off-by-one in the "kind" array (kind 0 is reserved for tracking the
unallocated dsh blocks).
For testing, it adds a --blob option on minimal-secure-streams[-client]
which uses a streamtype "bulkproxflow" from here
https://warmcat.com/policy/minimal-proxy-v4.2-v2.json
"bulkproxflow": {
"endpoint": "warmcat.com",
"port": 443,
"protocol": "h1",
"http_method": "GET",
"http_url": "blob.bin",
"proxy_buflen": 32768,
"proxy_buflen_rxflow_on_above": 24576,
"proxy_buflen_rxflow_off_below": 8192,
"tls": true,
"retry": "default",
"tls_trust_store": "le_via_dst"
}
This downloads a 51MB blob of random data with the SHA256sum
ed5720c16830810e5829dfb9b66c96b2e24efc4f93aa5e38c7ff4150d31cfbbf
The minimal-secure-streams --blob example client delays the download by
50ms every 10KiB it sees to force rx flow usage at the proxy.
It downloads the whole thing and checks the SHA256 is as expected.
Logs about rxflow status are available at LLL_INFO log level.
2021-04-07 14:25:07 +01:00
|
|
|
size_t amt;
|
|
|
|
|
|
|
|
struct lws_genhash_ctx hash_ctx;
|
2020-02-29 12:37:24 +00:00
|
|
|
} myss_t;
|
|
|
|
|
2020-06-23 13:19:30 +01:00
|
|
|
#if !defined(LWS_SS_USE_SSPC)
|
|
|
|
|
2020-02-29 12:37:24 +00:00
|
|
|
static const char *canned_root_token_payload =
|
|
|
|
"grant_type=refresh_token"
|
|
|
|
"&refresh_token=Atzr|IwEBIJedGXjDqsU_vMxykqOMg"
|
|
|
|
"SHfYe3CPcedueWEMWSDMaDnEmiW8RlR1Kns7Cb4B-TOSnqp7ifVsY4BMY2B8tpHfO39XP"
|
|
|
|
"zfu9HapGjTR458IyHX44FE71pWJkGZ79uVBpljP4sazJuk8XS3Oe_yLnm_DIO6fU1nU3Y"
|
|
|
|
"0flYmsOiOAQE_gRk_pdlmEtHnpMA-9rLw3mkY5L89Ty9kUygBsiFaYatouROhbsTn8-jW"
|
|
|
|
"k1zZLUDpT6ICtBXSnrCIg0pUbZevPFhTwdXd6eX-u4rq0W-XaDvPWFO7au-iPb4Zk5eZE"
|
|
|
|
"iX6sissYrtNmuEXc2uHu7MnQO1hHCaTdIO2CANVumf-PHSD8xseamyh04sLV5JgFzY45S"
|
|
|
|
"KvKMajiUZuLkMokOx86rjC2Hdkx5DO7G-dbG1ufBDG-N79pFMSs7Ck5pc283IdLoJkCQc"
|
|
|
|
"AGvTX8o8I29QqkcGou-9TKhOJmpX8As94T61ok0UqqEKPJ7RhfQHHYdCtsdwxgvfVr9qI"
|
|
|
|
"xL_hDCcTho8opCVX-6QhJHl6SQFlTw13"
|
|
|
|
"&client_id="
|
|
|
|
"amzn1.application-oa2-client.4823334c434b4190a2b5a42c07938a2d";
|
|
|
|
|
2020-06-23 13:19:30 +01:00
|
|
|
#endif
|
|
|
|
|
2020-02-29 12:37:24 +00:00
|
|
|
/* secure streams payload interface */
|
|
|
|
|
ss: proxy: get rx flow control working
This fixes the proxy rx flow by adding an lws_dsh helper to hide the
off-by-one in the "kind" array (kind 0 is reserved for tracking the
unallocated dsh blocks).
For testing, it adds a --blob option on minimal-secure-streams[-client]
which uses a streamtype "bulkproxflow" from here
https://warmcat.com/policy/minimal-proxy-v4.2-v2.json
"bulkproxflow": {
"endpoint": "warmcat.com",
"port": 443,
"protocol": "h1",
"http_method": "GET",
"http_url": "blob.bin",
"proxy_buflen": 32768,
"proxy_buflen_rxflow_on_above": 24576,
"proxy_buflen_rxflow_off_below": 8192,
"tls": true,
"retry": "default",
"tls_trust_store": "le_via_dst"
}
This downloads a 51MB blob of random data with the SHA256sum
ed5720c16830810e5829dfb9b66c96b2e24efc4f93aa5e38c7ff4150d31cfbbf
The minimal-secure-streams --blob example client delays the download by
50ms every 10KiB it sees to force rx flow usage at the proxy.
It downloads the whole thing and checks the SHA256 is as expected.
Logs about rxflow status are available at LLL_INFO log level.
2021-04-07 14:25:07 +01:00
|
|
|
static const uint8_t expected_blob_hash[] = {
|
|
|
|
0xed, 0x57, 0x20, 0xc1, 0x68, 0x30, 0x81, 0x0e,
|
|
|
|
0x58, 0x29, 0xdf, 0xb9, 0xb6, 0x6c, 0x96, 0xb2,
|
|
|
|
0xe2, 0x4e, 0xfc, 0x4f, 0x93, 0xaa, 0x5e, 0x38,
|
|
|
|
0xc7, 0xff, 0x41, 0x50, 0xd3, 0x1c, 0xfb, 0xbf
|
|
|
|
};
|
|
|
|
|
2020-09-30 06:33:37 +01:00
|
|
|
static lws_ss_state_return_t
|
2020-02-29 12:37:24 +00:00
|
|
|
myss_rx(void *userobj, const uint8_t *buf, size_t len, int flags)
|
|
|
|
{
|
ss: rx metadata
At the moment you can define and set per-stream metadata at the client,
which will be string-substituted and if configured in the policy, set in
related outgoing protocol specific content like h1 headers.
This patch extends the metadata concept to also check incoming protocol-
specific content like h1 headers and where it matches the binding in the
streamtype's metadata entry, make it available to the client by name, via
a new lws_ss_get_metadata() api.
Currently warmcat.com has additional headers for
server: lwsws (well-known header name)
test-custom-header: hello (custom header name)
minimal-secure-streams test is updated to try to recover these both
in direct and -client (via proxy) versions. The corresponding metadata
part of the "mintest" stream policy from warmcat.com is
{
"srv": "server:"
}, {
"test": "test-custom-header:"
},
If built direct, or at the proxy, the stream has access to the static
policy metadata definitions and can store the rx metadata in the stream
metadata allocation, with heap-allocated a value. For client side that
talks to a proxy, only the proxy knows the policy, and it returns rx
metadata inside the serialized link to the client, which stores it on
the heap attached to the stream.
In addition an optimization for mapping static policy metadata definitions
to individual stream handle metadata is changed to match by name.
2020-09-10 06:43:43 +01:00
|
|
|
myss_t *m = (myss_t *)userobj;
|
ss: proxy: get rx flow control working
This fixes the proxy rx flow by adding an lws_dsh helper to hide the
off-by-one in the "kind" array (kind 0 is reserved for tracking the
unallocated dsh blocks).
For testing, it adds a --blob option on minimal-secure-streams[-client]
which uses a streamtype "bulkproxflow" from here
https://warmcat.com/policy/minimal-proxy-v4.2-v2.json
"bulkproxflow": {
"endpoint": "warmcat.com",
"port": 443,
"protocol": "h1",
"http_method": "GET",
"http_url": "blob.bin",
"proxy_buflen": 32768,
"proxy_buflen_rxflow_on_above": 24576,
"proxy_buflen_rxflow_off_below": 8192,
"tls": true,
"retry": "default",
"tls_trust_store": "le_via_dst"
}
This downloads a 51MB blob of random data with the SHA256sum
ed5720c16830810e5829dfb9b66c96b2e24efc4f93aa5e38c7ff4150d31cfbbf
The minimal-secure-streams --blob example client delays the download by
50ms every 10KiB it sees to force rx flow usage at the proxy.
It downloads the whole thing and checks the SHA256 is as expected.
Logs about rxflow status are available at LLL_INFO log level.
2021-04-07 14:25:07 +01:00
|
|
|
const char *md_srv = "not set", *md_test = "not set";
|
|
|
|
size_t md_srv_len = 7, md_test_len = 7;
|
|
|
|
|
|
|
|
if (flags & LWSSS_FLAG_PERF_JSON)
|
|
|
|
return LWSSSSRET_OK;
|
|
|
|
|
|
|
|
if (test_blob) {
|
|
|
|
|
|
|
|
if (flags & LWSSS_FLAG_SOM) {
|
|
|
|
if (lws_genhash_init(&m->hash_ctx, LWS_GENHASH_TYPE_SHA256))
|
|
|
|
lwsl_err("%s: hash init failed\n", __func__);
|
|
|
|
m->amt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lws_genhash_update(&m->hash_ctx, buf, len))
|
|
|
|
lwsl_err("%s: hash failed\n", __func__);
|
|
|
|
|
|
|
|
if ((m->amt + len) / 102400 != (m->amt / 102400)) {
|
|
|
|
|
|
|
|
lwsl_user("%s: blob test: rx %uKiB\n", __func__,
|
|
|
|
(unsigned int)((m->amt + len) / 1024));
|
|
|
|
/*
|
|
|
|
* Let's make it hard for client to keep up with onward
|
|
|
|
* server, delay 50ms after every 100K received, so we
|
|
|
|
* are forcing the flow control action at the proxy
|
|
|
|
*/
|
|
|
|
usleep(50000);
|
|
|
|
}
|
|
|
|
|
|
|
|
m->amt += len;
|
2020-02-29 12:37:24 +00:00
|
|
|
|
ss: proxy: get rx flow control working
This fixes the proxy rx flow by adding an lws_dsh helper to hide the
off-by-one in the "kind" array (kind 0 is reserved for tracking the
unallocated dsh blocks).
For testing, it adds a --blob option on minimal-secure-streams[-client]
which uses a streamtype "bulkproxflow" from here
https://warmcat.com/policy/minimal-proxy-v4.2-v2.json
"bulkproxflow": {
"endpoint": "warmcat.com",
"port": 443,
"protocol": "h1",
"http_method": "GET",
"http_url": "blob.bin",
"proxy_buflen": 32768,
"proxy_buflen_rxflow_on_above": 24576,
"proxy_buflen_rxflow_off_below": 8192,
"tls": true,
"retry": "default",
"tls_trust_store": "le_via_dst"
}
This downloads a 51MB blob of random data with the SHA256sum
ed5720c16830810e5829dfb9b66c96b2e24efc4f93aa5e38c7ff4150d31cfbbf
The minimal-secure-streams --blob example client delays the download by
50ms every 10KiB it sees to force rx flow usage at the proxy.
It downloads the whole thing and checks the SHA256 is as expected.
Logs about rxflow status are available at LLL_INFO log level.
2021-04-07 14:25:07 +01:00
|
|
|
if (flags & LWSSS_FLAG_EOM) {
|
|
|
|
uint8_t digest[32];
|
|
|
|
lws_genhash_destroy(&m->hash_ctx, digest);
|
ss: rx metadata
At the moment you can define and set per-stream metadata at the client,
which will be string-substituted and if configured in the policy, set in
related outgoing protocol specific content like h1 headers.
This patch extends the metadata concept to also check incoming protocol-
specific content like h1 headers and where it matches the binding in the
streamtype's metadata entry, make it available to the client by name, via
a new lws_ss_get_metadata() api.
Currently warmcat.com has additional headers for
server: lwsws (well-known header name)
test-custom-header: hello (custom header name)
minimal-secure-streams test is updated to try to recover these both
in direct and -client (via proxy) versions. The corresponding metadata
part of the "mintest" stream policy from warmcat.com is
{
"srv": "server:"
}, {
"test": "test-custom-header:"
},
If built direct, or at the proxy, the stream has access to the static
policy metadata definitions and can store the rx metadata in the stream
metadata allocation, with heap-allocated a value. For client side that
talks to a proxy, only the proxy knows the policy, and it returns rx
metadata inside the serialized link to the client, which stores it on
the heap attached to the stream.
In addition an optimization for mapping static policy metadata definitions
to individual stream handle metadata is changed to match by name.
2020-09-10 06:43:43 +01:00
|
|
|
|
ss: proxy: get rx flow control working
This fixes the proxy rx flow by adding an lws_dsh helper to hide the
off-by-one in the "kind" array (kind 0 is reserved for tracking the
unallocated dsh blocks).
For testing, it adds a --blob option on minimal-secure-streams[-client]
which uses a streamtype "bulkproxflow" from here
https://warmcat.com/policy/minimal-proxy-v4.2-v2.json
"bulkproxflow": {
"endpoint": "warmcat.com",
"port": 443,
"protocol": "h1",
"http_method": "GET",
"http_url": "blob.bin",
"proxy_buflen": 32768,
"proxy_buflen_rxflow_on_above": 24576,
"proxy_buflen_rxflow_off_below": 8192,
"tls": true,
"retry": "default",
"tls_trust_store": "le_via_dst"
}
This downloads a 51MB blob of random data with the SHA256sum
ed5720c16830810e5829dfb9b66c96b2e24efc4f93aa5e38c7ff4150d31cfbbf
The minimal-secure-streams --blob example client delays the download by
50ms every 10KiB it sees to force rx flow usage at the proxy.
It downloads the whole thing and checks the SHA256 is as expected.
Logs about rxflow status are available at LLL_INFO log level.
2021-04-07 14:25:07 +01:00
|
|
|
if (!memcmp(expected_blob_hash, digest, 32)) {
|
|
|
|
lwsl_user("%s: SHA256 match\n", __func__);
|
|
|
|
bad = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
interrupted = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LWSSSSRET_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
lws_ss_get_metadata(m->ss, "srv", (const void **)&md_srv, &md_srv_len);
|
|
|
|
lws_ss_get_metadata(m->ss, "test", (const void **)&md_test, &md_test_len);
|
|
|
|
|
|
|
|
lwsl_user("%s: len %d, flags: %d, srv: %.*s, test: %.*s\n", __func__,
|
|
|
|
(int)len, flags, (int)md_srv_len, md_srv,
|
|
|
|
(int)md_test_len, md_test);
|
2020-02-29 12:37:24 +00:00
|
|
|
lwsl_hexdump_info(buf, len);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we received the whole message, for our example it means
|
|
|
|
* we are done.
|
|
|
|
*/
|
|
|
|
if (flags & LWSSS_FLAG_EOM) {
|
|
|
|
bad = 0;
|
|
|
|
interrupted = 1;
|
|
|
|
}
|
|
|
|
|
2021-03-14 08:27:06 +00:00
|
|
|
return LWSSSSRET_OK;
|
2020-02-29 12:37:24 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 06:33:37 +01:00
|
|
|
static lws_ss_state_return_t
|
2020-02-29 12:37:24 +00:00
|
|
|
myss_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len,
|
|
|
|
int *flags)
|
|
|
|
{
|
|
|
|
//myss_t *m = (myss_t *)userobj;
|
|
|
|
|
2020-08-03 15:33:09 +01:00
|
|
|
/* in this example, we don't send stuff */
|
|
|
|
|
|
|
|
return LWSSSSRET_TX_DONT_SEND;
|
2020-02-29 12:37:24 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 06:33:37 +01:00
|
|
|
static lws_ss_state_return_t
|
2020-02-29 12:37:24 +00:00
|
|
|
myss_state(void *userobj, void *sh, lws_ss_constate_t state,
|
|
|
|
lws_ss_tx_ordinal_t ack)
|
|
|
|
{
|
|
|
|
myss_t *m = (myss_t *)userobj;
|
|
|
|
|
ss: policy: response code mapping
This adds a per-streamtype JSON mapping table in the policy.
In addition to the previous flow, it lets you generate custom
SS state notifications for specific http response codes, eg:
"http_resp_map": [ { "530": 1530 }, { "531": 1531 } ],
It's not recommended to overload the transport-layer response
code with application layer responses. It's better to return
a 200 and then in the application protocol inside http, explain
what happened from the application perspective, usually with
JSON. But this is designed to let you handle existing systems
that do overload the transport layer response code.
SS states for user use start at LWSSSCS_USER_BASE, which is
1000.
You can do a basic test with minimal-secure-streams and --respmap
flag, this will go to httpbin.org and get a 404, and the warmcat.com
policy has the mapping for 404 -> LWSSSCS_USER_BASE (1000).
Since the mapping emits states, these are serialized and handled
like any other state in the proxy case.
The policy2c example / tool is also updated to handle the additional
mapping tables.
2020-09-15 09:11:06 +01:00
|
|
|
lwsl_user("%s: %s (%d), ord 0x%x\n", __func__,
|
2020-12-12 06:21:40 +00:00
|
|
|
lws_ss_state_name((int)state), state, (unsigned int)ack);
|
2020-02-29 12:37:24 +00:00
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case LWSSSCS_CREATING:
|
2020-12-22 15:56:41 +00:00
|
|
|
return lws_ss_client_connect(m->ss);
|
|
|
|
|
2021-03-14 08:27:06 +00:00
|
|
|
case LWSSSCS_CONNECTING:
|
|
|
|
lws_ss_start_timeout(m->ss, timeout_ms);
|
|
|
|
|
ss: proxy: get rx flow control working
This fixes the proxy rx flow by adding an lws_dsh helper to hide the
off-by-one in the "kind" array (kind 0 is reserved for tracking the
unallocated dsh blocks).
For testing, it adds a --blob option on minimal-secure-streams[-client]
which uses a streamtype "bulkproxflow" from here
https://warmcat.com/policy/minimal-proxy-v4.2-v2.json
"bulkproxflow": {
"endpoint": "warmcat.com",
"port": 443,
"protocol": "h1",
"http_method": "GET",
"http_url": "blob.bin",
"proxy_buflen": 32768,
"proxy_buflen_rxflow_on_above": 24576,
"proxy_buflen_rxflow_off_below": 8192,
"tls": true,
"retry": "default",
"tls_trust_store": "le_via_dst"
}
This downloads a 51MB blob of random data with the SHA256sum
ed5720c16830810e5829dfb9b66c96b2e24efc4f93aa5e38c7ff4150d31cfbbf
The minimal-secure-streams --blob example client delays the download by
50ms every 10KiB it sees to force rx flow usage at the proxy.
It downloads the whole thing and checks the SHA256 is as expected.
Logs about rxflow status are available at LLL_INFO log level.
2021-04-07 14:25:07 +01:00
|
|
|
if (!test_blob) {
|
|
|
|
if (lws_ss_set_metadata(m->ss, "uptag", "myuptag123", 10))
|
|
|
|
/* can fail, eg due to OOM, retry later if so */
|
|
|
|
return LWSSSSRET_DISCONNECT_ME;
|
|
|
|
|
|
|
|
if (lws_ss_set_metadata(m->ss, "ctype", "myctype", 7))
|
|
|
|
/* can fail, eg due to OOM, retry later if so */
|
|
|
|
return LWSSSSRET_DISCONNECT_ME;
|
|
|
|
}
|
2021-03-14 08:27:06 +00:00
|
|
|
break;
|
|
|
|
|
2020-02-29 12:37:24 +00:00
|
|
|
case LWSSSCS_ALL_RETRIES_FAILED:
|
|
|
|
/* if we're out of retries, we want to close the app and FAIL */
|
|
|
|
interrupted = 1;
|
2021-03-16 13:32:05 +00:00
|
|
|
bad = 2;
|
2020-02-29 12:37:24 +00:00
|
|
|
break;
|
2021-03-16 13:32:05 +00:00
|
|
|
|
2020-02-29 12:37:24 +00:00
|
|
|
case LWSSSCS_QOS_ACK_REMOTE:
|
|
|
|
lwsl_notice("%s: LWSSSCS_QOS_ACK_REMOTE\n", __func__);
|
|
|
|
break;
|
2020-06-30 16:42:37 +01:00
|
|
|
|
|
|
|
case LWSSSCS_TIMEOUT:
|
|
|
|
lwsl_notice("%s: LWSSSCS_TIMEOUT\n", __func__);
|
2021-03-16 13:32:05 +00:00
|
|
|
/* if we're out of time */
|
|
|
|
interrupted = 1;
|
|
|
|
bad = 3;
|
2020-06-30 16:42:37 +01:00
|
|
|
break;
|
ss: policy: response code mapping
This adds a per-streamtype JSON mapping table in the policy.
In addition to the previous flow, it lets you generate custom
SS state notifications for specific http response codes, eg:
"http_resp_map": [ { "530": 1530 }, { "531": 1531 } ],
It's not recommended to overload the transport-layer response
code with application layer responses. It's better to return
a 200 and then in the application protocol inside http, explain
what happened from the application perspective, usually with
JSON. But this is designed to let you handle existing systems
that do overload the transport layer response code.
SS states for user use start at LWSSSCS_USER_BASE, which is
1000.
You can do a basic test with minimal-secure-streams and --respmap
flag, this will go to httpbin.org and get a 404, and the warmcat.com
policy has the mapping for 404 -> LWSSSCS_USER_BASE (1000).
Since the mapping emits states, these are serialized and handled
like any other state in the proxy case.
The policy2c example / tool is also updated to handle the additional
mapping tables.
2020-09-15 09:11:06 +01:00
|
|
|
|
|
|
|
case LWSSSCS_USER_BASE:
|
|
|
|
lwsl_notice("%s: LWSSSCS_USER_BASE\n", __func__);
|
|
|
|
break;
|
|
|
|
|
2020-02-29 12:37:24 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-03-14 08:27:06 +00:00
|
|
|
return LWSSSSRET_OK;
|
2020-02-29 12:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link,
|
|
|
|
int current, int target)
|
|
|
|
{
|
|
|
|
struct lws_context *context = lws_system_context_from_system_mgr(mgr);
|
2020-06-23 13:19:30 +01:00
|
|
|
#if !defined(LWS_SS_USE_SSPC)
|
|
|
|
|
2020-02-29 12:37:24 +00:00
|
|
|
lws_system_blob_t *ab = lws_system_get_blob(context,
|
|
|
|
LWS_SYSBLOB_TYPE_AUTH, 1 /* AUTH_IDX_ROOT */);
|
|
|
|
size_t size;
|
2020-06-23 13:19:30 +01:00
|
|
|
#endif
|
2020-02-29 12:37:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For the things we care about, let's notice if we are trying to get
|
|
|
|
* past them when we haven't solved them yet, and make the system
|
|
|
|
* state wait while we trigger the dependent action.
|
|
|
|
*/
|
|
|
|
switch (target) {
|
2020-03-12 14:43:32 +00:00
|
|
|
|
2020-06-23 13:19:30 +01:00
|
|
|
#if !defined(LWS_SS_USE_SSPC)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The proxy takes responsibility for this stuff if we get things
|
|
|
|
* done through that
|
|
|
|
*/
|
|
|
|
|
2020-03-12 14:43:32 +00:00
|
|
|
case LWS_SYSTATE_INITIALIZED: /* overlay on the hardcoded policy */
|
|
|
|
case LWS_SYSTATE_POLICY_VALID: /* overlay on the loaded policy */
|
|
|
|
|
|
|
|
if (target != current)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (force_cpd_fail_portal)
|
|
|
|
|
|
|
|
/* this makes it look like we're behind a captive portal
|
|
|
|
* because the overriden address does a redirect */
|
|
|
|
|
|
|
|
lws_ss_policy_overlay(context,
|
|
|
|
"{\"s\": [{\"captive_portal_detect\": {"
|
|
|
|
"\"endpoint\": \"google.com\","
|
|
|
|
"\"http_url\": \"/\","
|
|
|
|
"\"port\": 80"
|
|
|
|
"}}]}");
|
|
|
|
|
|
|
|
if (force_cpd_fail_no_internet)
|
|
|
|
|
|
|
|
/* this looks like no internet, because the overridden
|
|
|
|
* port doesn't have anything that will connect to us */
|
|
|
|
|
|
|
|
lws_ss_policy_overlay(context,
|
|
|
|
"{\"s\": [{\"captive_portal_detect\": {"
|
|
|
|
"\"endpoint\": \"warmcat.com\","
|
|
|
|
"\"http_url\": \"/\","
|
|
|
|
"\"port\": 999"
|
|
|
|
"}}]}");
|
|
|
|
break;
|
|
|
|
|
2020-02-29 12:37:24 +00:00
|
|
|
case LWS_SYSTATE_REGISTERED:
|
|
|
|
size = lws_system_blob_get_size(ab);
|
|
|
|
if (size)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* let's register our canned root token so auth can use it */
|
|
|
|
lws_system_blob_direct_set(ab,
|
|
|
|
(const uint8_t *)canned_root_token_payload,
|
|
|
|
strlen(canned_root_token_payload));
|
|
|
|
break;
|
|
|
|
|
2020-06-23 13:19:30 +01:00
|
|
|
#endif
|
|
|
|
|
2020-02-29 12:37:24 +00:00
|
|
|
case LWS_SYSTATE_OPERATIONAL:
|
|
|
|
if (current == LWS_SYSTATE_OPERATIONAL) {
|
|
|
|
lws_ss_info_t ssi;
|
|
|
|
|
|
|
|
/* We're making an outgoing secure stream ourselves */
|
|
|
|
|
|
|
|
memset(&ssi, 0, sizeof(ssi));
|
|
|
|
ssi.handle_offset = offsetof(myss_t, ss);
|
|
|
|
ssi.opaque_user_data_offset = offsetof(myss_t,
|
|
|
|
opaque_data);
|
|
|
|
ssi.rx = myss_rx;
|
|
|
|
ssi.tx = myss_tx;
|
|
|
|
ssi.state = myss_state;
|
|
|
|
ssi.user_alloc = sizeof(myss_t);
|
ss: proxy: get rx flow control working
This fixes the proxy rx flow by adding an lws_dsh helper to hide the
off-by-one in the "kind" array (kind 0 is reserved for tracking the
unallocated dsh blocks).
For testing, it adds a --blob option on minimal-secure-streams[-client]
which uses a streamtype "bulkproxflow" from here
https://warmcat.com/policy/minimal-proxy-v4.2-v2.json
"bulkproxflow": {
"endpoint": "warmcat.com",
"port": 443,
"protocol": "h1",
"http_method": "GET",
"http_url": "blob.bin",
"proxy_buflen": 32768,
"proxy_buflen_rxflow_on_above": 24576,
"proxy_buflen_rxflow_off_below": 8192,
"tls": true,
"retry": "default",
"tls_trust_store": "le_via_dst"
}
This downloads a 51MB blob of random data with the SHA256sum
ed5720c16830810e5829dfb9b66c96b2e24efc4f93aa5e38c7ff4150d31cfbbf
The minimal-secure-streams --blob example client delays the download by
50ms every 10KiB it sees to force rx flow usage at the proxy.
It downloads the whole thing and checks the SHA256 is as expected.
Logs about rxflow status are available at LLL_INFO log level.
2021-04-07 14:25:07 +01:00
|
|
|
ssi.streamtype = test_blob ? "bulkproxflow" :
|
|
|
|
(test_respmap ? "respmap" : "mintest");
|
2020-02-29 12:37:24 +00:00
|
|
|
|
|
|
|
if (lws_ss_create(context, 0, &ssi, NULL, NULL,
|
|
|
|
NULL, NULL)) {
|
|
|
|
lwsl_err("%s: failed to create secure stream\n",
|
|
|
|
__func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static lws_state_notify_link_t * const app_notifier_list[] = {
|
|
|
|
&nl, NULL
|
|
|
|
};
|
|
|
|
|
2021-01-06 15:08:22 +00:00
|
|
|
#if defined(LWS_WITH_SYS_METRICS)
|
|
|
|
|
|
|
|
static int
|
|
|
|
my_metric_report(lws_metric_pub_t *mp)
|
|
|
|
{
|
|
|
|
lws_metric_bucket_t *sub = mp->u.hist.head;
|
|
|
|
char buf[192];
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (lws_metrics_format(mp, &sub, buf, sizeof(buf)))
|
|
|
|
lwsl_user("%s: %s\n", __func__, buf);
|
|
|
|
} while ((mp->flags & LWSMTFL_REPORT_HIST) && sub);
|
|
|
|
|
|
|
|
/* 0 = leave metric to accumulate, 1 = reset the metric */
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const lws_system_ops_t system_ops = {
|
|
|
|
.metric_report = my_metric_report,
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-02-29 12:37:24 +00:00
|
|
|
static void
|
|
|
|
sigint_handler(int sig)
|
|
|
|
{
|
|
|
|
interrupted = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
struct lws_context_creation_info info;
|
|
|
|
struct lws_context *context;
|
2021-03-16 13:32:05 +00:00
|
|
|
int n = 0, expected = 0;
|
2020-06-30 16:42:37 +01:00
|
|
|
const char *p;
|
2020-02-29 12:37:24 +00:00
|
|
|
|
|
|
|
signal(SIGINT, sigint_handler);
|
|
|
|
|
|
|
|
memset(&info, 0, sizeof info);
|
|
|
|
lws_cmdline_option_handle_builtin(argc, argv, &info);
|
|
|
|
|
|
|
|
lwsl_user("LWS secure streams test client [-d<verb>]\n");
|
|
|
|
|
2020-03-12 14:43:32 +00:00
|
|
|
/* these options are mutually exclusive if given */
|
|
|
|
|
|
|
|
if (lws_cmdline_option(argc, argv, "--force-portal"))
|
|
|
|
force_cpd_fail_portal = 1;
|
|
|
|
|
|
|
|
if (lws_cmdline_option(argc, argv, "--force-no-internet"))
|
|
|
|
force_cpd_fail_no_internet = 1;
|
|
|
|
|
ss: policy: response code mapping
This adds a per-streamtype JSON mapping table in the policy.
In addition to the previous flow, it lets you generate custom
SS state notifications for specific http response codes, eg:
"http_resp_map": [ { "530": 1530 }, { "531": 1531 } ],
It's not recommended to overload the transport-layer response
code with application layer responses. It's better to return
a 200 and then in the application protocol inside http, explain
what happened from the application perspective, usually with
JSON. But this is designed to let you handle existing systems
that do overload the transport layer response code.
SS states for user use start at LWSSSCS_USER_BASE, which is
1000.
You can do a basic test with minimal-secure-streams and --respmap
flag, this will go to httpbin.org and get a 404, and the warmcat.com
policy has the mapping for 404 -> LWSSSCS_USER_BASE (1000).
Since the mapping emits states, these are serialized and handled
like any other state in the proxy case.
The policy2c example / tool is also updated to handle the additional
mapping tables.
2020-09-15 09:11:06 +01:00
|
|
|
if (lws_cmdline_option(argc, argv, "--respmap"))
|
|
|
|
test_respmap = 1;
|
|
|
|
|
2020-06-30 16:42:37 +01:00
|
|
|
if ((p = lws_cmdline_option(argc, argv, "--timeout_ms")))
|
2020-12-12 06:21:40 +00:00
|
|
|
timeout_ms = (unsigned int)atoi(p);
|
2020-06-30 16:42:37 +01:00
|
|
|
|
ss: proxy: get rx flow control working
This fixes the proxy rx flow by adding an lws_dsh helper to hide the
off-by-one in the "kind" array (kind 0 is reserved for tracking the
unallocated dsh blocks).
For testing, it adds a --blob option on minimal-secure-streams[-client]
which uses a streamtype "bulkproxflow" from here
https://warmcat.com/policy/minimal-proxy-v4.2-v2.json
"bulkproxflow": {
"endpoint": "warmcat.com",
"port": 443,
"protocol": "h1",
"http_method": "GET",
"http_url": "blob.bin",
"proxy_buflen": 32768,
"proxy_buflen_rxflow_on_above": 24576,
"proxy_buflen_rxflow_off_below": 8192,
"tls": true,
"retry": "default",
"tls_trust_store": "le_via_dst"
}
This downloads a 51MB blob of random data with the SHA256sum
ed5720c16830810e5829dfb9b66c96b2e24efc4f93aa5e38c7ff4150d31cfbbf
The minimal-secure-streams --blob example client delays the download by
50ms every 10KiB it sees to force rx flow usage at the proxy.
It downloads the whole thing and checks the SHA256 is as expected.
Logs about rxflow status are available at LLL_INFO log level.
2021-04-07 14:25:07 +01:00
|
|
|
if (lws_cmdline_option(argc, argv, "--blob")) {
|
|
|
|
test_blob = 1;
|
|
|
|
if (timeout_ms == 3000)
|
|
|
|
/*
|
|
|
|
* Don't use default 3s, we're going to be a lot
|
|
|
|
* slower
|
|
|
|
*/
|
|
|
|
timeout_ms = 60000;
|
|
|
|
}
|
|
|
|
|
2020-02-29 12:37:24 +00:00
|
|
|
info.fd_limit_per_thread = 1 + 6 + 1;
|
|
|
|
info.port = CONTEXT_PORT_NO_LISTEN;
|
|
|
|
#if defined(LWS_SS_USE_SSPC)
|
|
|
|
info.protocols = lws_sspc_protocols;
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
/* connect to ssproxy via UDS by default, else via
|
|
|
|
* tcp connection to this port */
|
|
|
|
if ((p = lws_cmdline_option(argc, argv, "-p")))
|
2020-12-12 06:21:40 +00:00
|
|
|
info.ss_proxy_port = (uint16_t)atoi(p);
|
2020-02-29 12:37:24 +00:00
|
|
|
|
|
|
|
/* UDS "proxy.ss.lws" in abstract namespace, else this socket
|
|
|
|
* path; when -p given this can specify the network interface
|
|
|
|
* to bind to */
|
|
|
|
if ((p = lws_cmdline_option(argc, argv, "-i")))
|
|
|
|
info.ss_proxy_bind = p;
|
|
|
|
|
|
|
|
/* if -p given, -a specifies the proxy address to connect to */
|
|
|
|
if ((p = lws_cmdline_option(argc, argv, "-a")))
|
|
|
|
info.ss_proxy_address = p;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
info.pss_policies_json = default_ss_policy;
|
|
|
|
info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS |
|
2021-03-02 16:34:33 +00:00
|
|
|
LWS_SERVER_OPTION_H2_JUST_FIX_WINDOW_UPDATE_OVERFLOW |
|
2020-02-29 12:37:24 +00:00
|
|
|
LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* integrate us with lws system state management when context created */
|
|
|
|
|
|
|
|
nl.name = "app";
|
|
|
|
nl.notify_cb = app_system_state_nf;
|
|
|
|
info.register_notifier_list = app_notifier_list;
|
|
|
|
|
2021-01-06 15:08:22 +00:00
|
|
|
|
|
|
|
#if defined(LWS_WITH_SYS_METRICS)
|
|
|
|
info.system_ops = &system_ops;
|
|
|
|
info.metrics_prefix = "ssmex";
|
|
|
|
#endif
|
|
|
|
|
2020-02-29 12:37:24 +00:00
|
|
|
/* create the context */
|
|
|
|
|
|
|
|
context = lws_create_context(&info);
|
|
|
|
if (!context) {
|
|
|
|
lwsl_err("lws init failed\n");
|
2021-03-16 13:32:05 +00:00
|
|
|
goto bail;
|
2020-02-29 12:37:24 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 13:19:30 +01:00
|
|
|
#if !defined(LWS_SS_USE_SSPC)
|
|
|
|
/*
|
|
|
|
* If we're being a proxied client, the proxy does all this
|
|
|
|
*/
|
|
|
|
|
2020-02-29 12:37:24 +00:00
|
|
|
/*
|
|
|
|
* Set the related lws_system blobs
|
|
|
|
*
|
|
|
|
* ...direct_set() sets a pointer, so the thing pointed to has to have
|
|
|
|
* a suitable lifetime, eg, something that already exists on the heap or
|
|
|
|
* a const string in .rodata like this
|
|
|
|
*/
|
|
|
|
|
|
|
|
lws_system_blob_direct_set(lws_system_get_blob(context,
|
|
|
|
LWS_SYSBLOB_TYPE_DEVICE_SERIAL, 0),
|
|
|
|
(const uint8_t *)"SN12345678", 10);
|
|
|
|
lws_system_blob_direct_set(lws_system_get_blob(context,
|
|
|
|
LWS_SYSBLOB_TYPE_DEVICE_FW_VERSION, 0),
|
|
|
|
(const uint8_t *)"v0.01", 5);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ..._heap_append() appends to a buflist kind of arrangement on heap,
|
|
|
|
* just one block is fine, otherwise it will concatenate the fragments
|
|
|
|
* in the order they were appended (and take care of freeing them at
|
|
|
|
* context destroy time). ..._heap_empty() is also available to remove
|
|
|
|
* everything that was already allocated.
|
|
|
|
*
|
|
|
|
* Here we use _heap_append() just so it's tested as well as direct set.
|
|
|
|
*/
|
|
|
|
|
|
|
|
lws_system_blob_heap_append(lws_system_get_blob(context,
|
|
|
|
LWS_SYSBLOB_TYPE_DEVICE_TYPE, 0),
|
|
|
|
(const uint8_t *)"spacerocket", 11);
|
2020-06-23 13:19:30 +01:00
|
|
|
#endif
|
2020-02-29 12:37:24 +00:00
|
|
|
|
|
|
|
/* the event loop */
|
|
|
|
|
|
|
|
while (n >= 0 && !interrupted)
|
|
|
|
n = lws_service(context, 0);
|
|
|
|
|
|
|
|
lws_context_destroy(context);
|
|
|
|
|
2021-03-16 13:32:05 +00:00
|
|
|
bail:
|
|
|
|
if ((p = lws_cmdline_option(argc, argv, "--expected-exit")))
|
|
|
|
expected = atoi(p);
|
2020-02-29 12:37:24 +00:00
|
|
|
|
2021-03-16 13:32:05 +00:00
|
|
|
if (bad == expected) {
|
|
|
|
lwsl_user("Completed: OK (seen expected %d)\n", expected);
|
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
lwsl_err("Completed: failed: exit %d, expected %d\n", bad, expected);
|
|
|
|
|
|
|
|
return 1;
|
2020-02-29 12:37:24 +00:00
|
|
|
}
|