xref: /aosp_15_r20/external/libwebsockets/lib/secure-streams/README.md (revision 1c60b9aca93fdbc9b5f19b2d2194c91294b22281)
1*1c60b9acSAndroid Build Coastguard Worker# Secure Streams
2*1c60b9acSAndroid Build Coastguard Worker
3*1c60b9acSAndroid Build Coastguard WorkerSecure Streams is a networking api that strictly separates payload from any
4*1c60b9acSAndroid Build Coastguard Workermetadata.  That includes the client endpoint address for the connection, the tls
5*1c60b9acSAndroid Build Coastguard Workertrust chain and even the protocol used to connect to the endpoint.
6*1c60b9acSAndroid Build Coastguard Worker
7*1c60b9acSAndroid Build Coastguard WorkerThe user api just receives and transmits payload, and receives advisory
8*1c60b9acSAndroid Build Coastguard Workerconnection state information.
9*1c60b9acSAndroid Build Coastguard Worker
10*1c60b9acSAndroid Build Coastguard WorkerThe details about how the connections for different types of secure stream should
11*1c60b9acSAndroid Build Coastguard Workerbe made are held in JSON "policy database" initially passed in to the context
12*1c60b9acSAndroid Build Coastguard Workercreation, but able to be updated from a remote copy.
13*1c60b9acSAndroid Build Coastguard Worker
14*1c60b9acSAndroid Build Coastguard WorkerBoth client and server networking can be handled using Secure Streams APIS.
15*1c60b9acSAndroid Build Coastguard Worker
16*1c60b9acSAndroid Build Coastguard Worker![overview](/doc-assets/ss-operation-modes.png)
17*1c60b9acSAndroid Build Coastguard Worker
18*1c60b9acSAndroid Build Coastguard Worker## Secure Streams CLIENT State lifecycle
19*1c60b9acSAndroid Build Coastguard Worker
20*1c60b9acSAndroid Build Coastguard Worker![overview](/doc-assets/ss-state-flow.png)
21*1c60b9acSAndroid Build Coastguard Worker
22*1c60b9acSAndroid Build Coastguard WorkerSecure Streams are created using `lws_ss_create()`, after that they may acquire
23*1c60b9acSAndroid Build Coastguard Workerunderlying connections, and lose them, but the lifecycle of the Secure Stream
24*1c60b9acSAndroid Build Coastguard Workeritself is not directly related to any underlying connection.
25*1c60b9acSAndroid Build Coastguard Worker
26*1c60b9acSAndroid Build Coastguard WorkerOnce created, Secure Streams may attempt connections, these may fail and once
27*1c60b9acSAndroid Build Coastguard Workerthe number of failures exceeds the count of attempts to conceal in the retry /
28*1c60b9acSAndroid Build Coastguard Workerbackoff policy, the stream reaches `LWSSSCS_ALL_RETRIES_FAILED`.  The stream becomes
29*1c60b9acSAndroid Build Coastguard Workeridle again until another explicit connection attempt is given.
30*1c60b9acSAndroid Build Coastguard Worker
31*1c60b9acSAndroid Build Coastguard WorkerOnce connected, the user code can use `lws_ss_request_tx()` to ask for a slot
32*1c60b9acSAndroid Build Coastguard Workerto write to the peer, when this if forthcoming the tx handler can send a message.
33*1c60b9acSAndroid Build Coastguard WorkerIf the underlying protocol gives indications of transaction success, such as,
34*1c60b9acSAndroid Build Coastguard Workereg, a 200 for http, or an ACK from MQTT, the stream state is called back with
35*1c60b9acSAndroid Build Coastguard Workeran `LWSSSCS_QOS_ACK_REMOTE` or `LWSSSCS_QOS_NACK_REMOTE`.
36*1c60b9acSAndroid Build Coastguard Worker
37*1c60b9acSAndroid Build Coastguard Worker## SS Callback return handling
38*1c60b9acSAndroid Build Coastguard Worker
39*1c60b9acSAndroid Build Coastguard WorkerSS state(), rx() and tx() can indicate with their return code some common
40*1c60b9acSAndroid Build Coastguard Workersituations that should be handled by the caller.
41*1c60b9acSAndroid Build Coastguard Worker
42*1c60b9acSAndroid Build Coastguard WorkerConstant|Scope|Meaning
43*1c60b9acSAndroid Build Coastguard Worker---|---|---
44*1c60b9acSAndroid Build Coastguard WorkerLWSSSSRET_TX_DONT_SEND|tx|This opportunity to send something was passed on
45*1c60b9acSAndroid Build Coastguard WorkerLWSSSSRET_OK|state, rx, tx|No error, continue doing what we're doing
46*1c60b9acSAndroid Build Coastguard WorkerLWSSSSRET_DISCONNECT_ME|state, rx|assertively disconnect from peer
47*1c60b9acSAndroid Build Coastguard WorkerLWSSSSRET_DESTROY_ME|state, rx|Caller should now destroy the stream itself
48*1c60b9acSAndroid Build Coastguard WorkerLWSSSSRET_SS_HANDLE_DESTROYED|state|Something handled a request to destroy the stream
49*1c60b9acSAndroid Build Coastguard Worker
50*1c60b9acSAndroid Build Coastguard WorkerDestruction of the stream we're calling back on inside the callback is tricky,
51*1c60b9acSAndroid Build Coastguard Workerit's preferable to return `LWSSSSRET_DESTROY_ME` if it is required, and let the
52*1c60b9acSAndroid Build Coastguard Workercaller handle it.  But in some cases, helpers called from the callbacks may
53*1c60b9acSAndroid Build Coastguard Workerdestroy the handle themselves, in that case the handler should return
54*1c60b9acSAndroid Build Coastguard Worker`LWSSSSRET_SS_HANDLE_DESTROYED` indicating that the handle is already destroyed.
55*1c60b9acSAndroid Build Coastguard Worker
56*1c60b9acSAndroid Build Coastguard Worker## Secure Streams SERVER State lifecycle
57*1c60b9acSAndroid Build Coastguard Worker
58*1c60b9acSAndroid Build Coastguard Worker![overview](/doc-assets/ss-state-flow-server.png)
59*1c60b9acSAndroid Build Coastguard Worker
60*1c60b9acSAndroid Build Coastguard WorkerYou can also run servers defined using Secure Streams, the main difference is
61*1c60b9acSAndroid Build Coastguard Workerthat the user code must assertively create a secure stream of the server type
62*1c60b9acSAndroid Build Coastguard Workerin order to create the vhost and listening socket.  When this stream is
63*1c60b9acSAndroid Build Coastguard Workerdestroyed, the vhost is destroyed and the listen socket closed, otherwise it
64*1c60b9acSAndroid Build Coastguard Workerdoes not perform any rx or tx, it just represents the server lifecycle.
65*1c60b9acSAndroid Build Coastguard Worker
66*1c60b9acSAndroid Build Coastguard WorkerWhen client connections randomly arrive at the listen socket, new Secure Stream
67*1c60b9acSAndroid Build Coastguard Workerobjects are created along with accept sockets to represent each client
68*1c60b9acSAndroid Build Coastguard Workerconnection.  As they represent the incoming connection, their lifecycle is the
69*1c60b9acSAndroid Build Coastguard Workersame as that of the underlying connection.  There is no retry concept since as
70*1c60b9acSAndroid Build Coastguard Workerwith eg, http servers, the clients may typically not be routable for new
71*1c60b9acSAndroid Build Coastguard Workerconnections initiated by the server.
72*1c60b9acSAndroid Build Coastguard Worker
73*1c60b9acSAndroid Build Coastguard WorkerSince connections at socket level are already established, new connections are
74*1c60b9acSAndroid Build Coastguard Workerimmediately taken through CREATING, CONNECTING, CONNECTED states for
75*1c60b9acSAndroid Build Coastguard Workerconsistency.
76*1c60b9acSAndroid Build Coastguard Worker
77*1c60b9acSAndroid Build Coastguard WorkerSome underlying protocols like http are "transactional", the server receives
78*1c60b9acSAndroid Build Coastguard Workera logical request and must reply with a logical response.  The additional
79*1c60b9acSAndroid Build Coastguard Workerstate `LWSSSCS_SERVER_TXN` provides a point where the user code can set
80*1c60b9acSAndroid Build Coastguard Workertransaction metadata before or in place of sending any payload.  It's also
81*1c60b9acSAndroid Build Coastguard Workerpossible to defer this until any rx related to the transaction was received,
82*1c60b9acSAndroid Build Coastguard Workerbut commonly with http requests, there is no rx / body.  Configuring the
83*1c60b9acSAndroid Build Coastguard Workerresponse there may look like
84*1c60b9acSAndroid Build Coastguard Worker
85*1c60b9acSAndroid Build Coastguard Worker```
86*1c60b9acSAndroid Build Coastguard Worker		/*
87*1c60b9acSAndroid Build Coastguard Worker		 * We do want to ack the transaction...
88*1c60b9acSAndroid Build Coastguard Worker		 */
89*1c60b9acSAndroid Build Coastguard Worker		lws_ss_server_ack(m->ss, 0);
90*1c60b9acSAndroid Build Coastguard Worker		/*
91*1c60b9acSAndroid Build Coastguard Worker		 * ... it's going to be text/html...
92*1c60b9acSAndroid Build Coastguard Worker		 */
93*1c60b9acSAndroid Build Coastguard Worker		lws_ss_set_metadata(m->ss, "mime", "text/html", 9);
94*1c60b9acSAndroid Build Coastguard Worker		/*
95*1c60b9acSAndroid Build Coastguard Worker		 * ...it's going to be 128 byte (and request tx)
96*1c60b9acSAndroid Build Coastguard Worker		 */
97*1c60b9acSAndroid Build Coastguard Worker		lws_ss_request_tx_len(m->ss, 128);
98*1c60b9acSAndroid Build Coastguard Worker```
99*1c60b9acSAndroid Build Coastguard Worker
100*1c60b9acSAndroid Build Coastguard WorkerOtherwise the general api usage is very similar to client usage.
101*1c60b9acSAndroid Build Coastguard Worker
102*1c60b9acSAndroid Build Coastguard Worker## Convention for rx and tx callback return
103*1c60b9acSAndroid Build Coastguard Worker
104*1c60b9acSAndroid Build Coastguard WorkerFunction|Return|Meaning
105*1c60b9acSAndroid Build Coastguard Worker---|---|---
106*1c60b9acSAndroid Build Coastguard Workertx|`LWSSSSRET_OK`|Send the amount of `buf` stored in `*len`
107*1c60b9acSAndroid Build Coastguard Workertx|`LWSSSSRET_TX_DONT_SEND`|Do not send anything
108*1c60b9acSAndroid Build Coastguard Workertx|`LWSSSSRET_DISCONNECT_ME`|Close the current connection
109*1c60b9acSAndroid Build Coastguard Workertx|`LWSSSSRET_DESTROY_ME`|Destroy the Secure Stream
110*1c60b9acSAndroid Build Coastguard Workerrx|>=0|accepted
111*1c60b9acSAndroid Build Coastguard Workerrx|<0|Close the current connection
112*1c60b9acSAndroid Build Coastguard Worker
113*1c60b9acSAndroid Build Coastguard Worker# JSON Policy Database
114*1c60b9acSAndroid Build Coastguard Worker
115*1c60b9acSAndroid Build Coastguard WorkerExample JSON policy... formatting is shown for clarity but whitespace can be
116*1c60b9acSAndroid Build Coastguard Workeromitted in the actual policy.
117*1c60b9acSAndroid Build Coastguard Worker
118*1c60b9acSAndroid Build Coastguard WorkerOrdering is not critical in itself, but forward references are not allowed,
119*1c60b9acSAndroid Build Coastguard Workerthings must be defined before they are allowed to be referenced later in the
120*1c60b9acSAndroid Build Coastguard WorkerJSON.
121*1c60b9acSAndroid Build Coastguard Worker
122*1c60b9acSAndroid Build Coastguard Worker
123*1c60b9acSAndroid Build Coastguard Worker```
124*1c60b9acSAndroid Build Coastguard Worker{
125*1c60b9acSAndroid Build Coastguard Worker	"release": "01234567",
126*1c60b9acSAndroid Build Coastguard Worker	"product": "myproduct",
127*1c60b9acSAndroid Build Coastguard Worker	"schema-version": 1,
128*1c60b9acSAndroid Build Coastguard Worker	"retry": [{
129*1c60b9acSAndroid Build Coastguard Worker		"default": {
130*1c60b9acSAndroid Build Coastguard Worker			"backoff": [1000, 2000, 3000, 5000, 10000],
131*1c60b9acSAndroid Build Coastguard Worker			"conceal": 5,
132*1c60b9acSAndroid Build Coastguard Worker			"jitterpc": 20
133*1c60b9acSAndroid Build Coastguard Worker		}
134*1c60b9acSAndroid Build Coastguard Worker	}],
135*1c60b9acSAndroid Build Coastguard Worker	"certs": [{
136*1c60b9acSAndroid Build Coastguard Worker		"isrg_root_x1": "MIIFazCCA1OgAw...AnX5iItreGCc="
137*1c60b9acSAndroid Build Coastguard Worker	}, {
138*1c60b9acSAndroid Build Coastguard Worker		"LEX3_isrg_root_x1": "MIIFjTCCA3WgAwIB...WEsikxqEt"
139*1c60b9acSAndroid Build Coastguard Worker	}],
140*1c60b9acSAndroid Build Coastguard Worker	"trust_stores": [{
141*1c60b9acSAndroid Build Coastguard Worker		"le_via_isrg": ["isrg_root_x1", "LEX3_isrg_root_x1"]
142*1c60b9acSAndroid Build Coastguard Worker	}],
143*1c60b9acSAndroid Build Coastguard Worker	"s": [{
144*1c60b9acSAndroid Build Coastguard Worker		"mintest": {
145*1c60b9acSAndroid Build Coastguard Worker			"endpoint": "warmcat.com",
146*1c60b9acSAndroid Build Coastguard Worker			"port": 4443,
147*1c60b9acSAndroid Build Coastguard Worker			"protocol": "h1get",
148*1c60b9acSAndroid Build Coastguard Worker			"aux": "index.html",
149*1c60b9acSAndroid Build Coastguard Worker			"plugins": [],
150*1c60b9acSAndroid Build Coastguard Worker			"tls": true,
151*1c60b9acSAndroid Build Coastguard Worker			"opportunistic": true,
152*1c60b9acSAndroid Build Coastguard Worker			"retry": "default",
153*1c60b9acSAndroid Build Coastguard Worker			"tls_trust_store": "le_via_isrg"
154*1c60b9acSAndroid Build Coastguard Worker		}
155*1c60b9acSAndroid Build Coastguard Worker	}]
156*1c60b9acSAndroid Build Coastguard Worker}
157*1c60b9acSAndroid Build Coastguard Worker```
158*1c60b9acSAndroid Build Coastguard Worker
159*1c60b9acSAndroid Build Coastguard Worker### `Release`
160*1c60b9acSAndroid Build Coastguard Worker
161*1c60b9acSAndroid Build Coastguard WorkerIdentifies the policy version
162*1c60b9acSAndroid Build Coastguard Worker
163*1c60b9acSAndroid Build Coastguard Worker### `Product`
164*1c60b9acSAndroid Build Coastguard Worker
165*1c60b9acSAndroid Build Coastguard WorkerIdentifies the product the policy should apply to
166*1c60b9acSAndroid Build Coastguard Worker
167*1c60b9acSAndroid Build Coastguard Worker### `Schema-version`
168*1c60b9acSAndroid Build Coastguard Worker
169*1c60b9acSAndroid Build Coastguard WorkerThe minimum version of the policy parser required to parse this policy
170*1c60b9acSAndroid Build Coastguard Worker
171*1c60b9acSAndroid Build Coastguard Worker### `via-socks5`
172*1c60b9acSAndroid Build Coastguard Worker
173*1c60b9acSAndroid Build Coastguard WorkerOptional redirect for Secure Streams client traffic through a socks5
174*1c60b9acSAndroid Build Coastguard Workerproxy given in the format `address:port`, eg, `127.0.0.1:12345`.
175*1c60b9acSAndroid Build Coastguard Worker
176*1c60b9acSAndroid Build Coastguard Worker### `retry`
177*1c60b9acSAndroid Build Coastguard Worker
178*1c60b9acSAndroid Build Coastguard WorkerA list of backoff schemes referred to in the policy
179*1c60b9acSAndroid Build Coastguard Worker
180*1c60b9acSAndroid Build Coastguard Worker### `backoff`
181*1c60b9acSAndroid Build Coastguard Worker
182*1c60b9acSAndroid Build Coastguard WorkerAn array of ms delays for each retry in turn
183*1c60b9acSAndroid Build Coastguard Worker
184*1c60b9acSAndroid Build Coastguard Worker### `conceal`
185*1c60b9acSAndroid Build Coastguard Worker
186*1c60b9acSAndroid Build Coastguard WorkerThe number of retries to conceal from higher layers before giving errors.  If
187*1c60b9acSAndroid Build Coastguard Workerthis is larger than the number of times in the backoff array, then the last time
188*1c60b9acSAndroid Build Coastguard Workeris used for the extra delays.  65535 means never stop trying.
189*1c60b9acSAndroid Build Coastguard Worker
190*1c60b9acSAndroid Build Coastguard Worker### `jitterpc`
191*1c60b9acSAndroid Build Coastguard Worker
192*1c60b9acSAndroid Build Coastguard WorkerPercentage of the delay times mentioned in the backoff array that may be
193*1c60b9acSAndroid Build Coastguard Workerrandomly added to the figure from the array.  For example with an array entry of
194*1c60b9acSAndroid Build Coastguard Worker1000ms, and jitterpc of 20%, actual delays will be chosen randomly from 1000ms
195*1c60b9acSAndroid Build Coastguard Workerthrough 1200ms.  This is to stop retry storms triggered by a single event like
196*1c60b9acSAndroid Build Coastguard Workeran outage becoming synchronized into a DoS.
197*1c60b9acSAndroid Build Coastguard Worker
198*1c60b9acSAndroid Build Coastguard Worker### `certs`
199*1c60b9acSAndroid Build Coastguard Worker
200*1c60b9acSAndroid Build Coastguard WorkerCertificates needed for validation should be listed here each with a name.  The
201*1c60b9acSAndroid Build Coastguard Workerformat is base64 DER, which is the same as the part of PEM that is inside the
202*1c60b9acSAndroid Build Coastguard Workerstart and end lines.
203*1c60b9acSAndroid Build Coastguard Worker
204*1c60b9acSAndroid Build Coastguard Worker### `trust_stores`
205*1c60b9acSAndroid Build Coastguard Worker
206*1c60b9acSAndroid Build Coastguard WorkerChains of certificates given in the `certs` section may be named and described
207*1c60b9acSAndroid Build Coastguard Workerinside the `trust_stores` section.  Each entry in `trust_stores` is created as
208*1c60b9acSAndroid Build Coastguard Workera vhost + tls context with the given name.  Stream types can later be associated
209*1c60b9acSAndroid Build Coastguard Workerwith one of these to enforce validity checking of the remote server.
210*1c60b9acSAndroid Build Coastguard Worker
211*1c60b9acSAndroid Build Coastguard WorkerEntries should be named using "name" and the stack array defined using "stack"
212*1c60b9acSAndroid Build Coastguard Worker
213*1c60b9acSAndroid Build Coastguard Worker### `auth`
214*1c60b9acSAndroid Build Coastguard Worker
215*1c60b9acSAndroid Build Coastguard WorkerOptional section describing a map of available authentication streamtypes to
216*1c60b9acSAndroid Build Coastguard Workerauth token blob indexes.
217*1c60b9acSAndroid Build Coastguard Worker
218*1c60b9acSAndroid Build Coastguard Worker```
219*1c60b9acSAndroid Build Coastguard Worker...
220*1c60b9acSAndroid Build Coastguard Worker "auth": [{"name":"newauth","type":"sigv4", "blob":0}]
221*1c60b9acSAndroid Build Coastguard Worker...
222*1c60b9acSAndroid Build Coastguard Worker```
223*1c60b9acSAndroid Build Coastguard Worker
224*1c60b9acSAndroid Build Coastguard WorkerStreams can indicate they depend on a valid auth token from one of these schemes
225*1c60b9acSAndroid Build Coastguard Workerby using the `"use_auth": "name"` member in the streamtype definition, where name
226*1c60b9acSAndroid Build Coastguard Workeris, eg, "sigv4" in the example above.  If "use_auth" is not in the streamtype
227*1c60b9acSAndroid Build Coastguard Workerdefinition, default auth is lwa if "http_auth_header" is there.
228*1c60b9acSAndroid Build Coastguard Worker
229*1c60b9acSAndroid Build Coastguard Worker### `auth[].name`
230*1c60b9acSAndroid Build Coastguard Worker
231*1c60b9acSAndroid Build Coastguard WorkerThis is the name of the authentication scheme used by other streamtypes
232*1c60b9acSAndroid Build Coastguard Worker
233*1c60b9acSAndroid Build Coastguard Worker### `auth[].type`
234*1c60b9acSAndroid Build Coastguard Worker
235*1c60b9acSAndroid Build Coastguard WorkerIndicate the auth type, e.g. sigv4
236*1c60b9acSAndroid Build Coastguard Worker
237*1c60b9acSAndroid Build Coastguard Worker### `auth[].streamtype`
238*1c60b9acSAndroid Build Coastguard Worker
239*1c60b9acSAndroid Build Coastguard WorkerThis is the auth streamtype to be used to refresh the authentication token
240*1c60b9acSAndroid Build Coastguard Worker
241*1c60b9acSAndroid Build Coastguard Worker### `auth[].blob`
242*1c60b9acSAndroid Build Coastguard Worker
243*1c60b9acSAndroid Build Coastguard WorkerThis is the auth blob index the authentication token is stored into and retreived
244*1c60b9acSAndroid Build Coastguard Workerfrom system blob, currently up to 4 blobs.
245*1c60b9acSAndroid Build Coastguard Worker
246*1c60b9acSAndroid Build Coastguard Worker
247*1c60b9acSAndroid Build Coastguard Worker### `s`
248*1c60b9acSAndroid Build Coastguard Worker
249*1c60b9acSAndroid Build Coastguard WorkerThese are an array of policies for the supported stream type names.
250*1c60b9acSAndroid Build Coastguard Worker
251*1c60b9acSAndroid Build Coastguard Worker### `server`
252*1c60b9acSAndroid Build Coastguard Worker
253*1c60b9acSAndroid Build Coastguard Worker**SERVER ONLY**: if set to `true`, the policy describes a secure streams
254*1c60b9acSAndroid Build Coastguard Workerserver.
255*1c60b9acSAndroid Build Coastguard Worker
256*1c60b9acSAndroid Build Coastguard Worker### `endpoint`
257*1c60b9acSAndroid Build Coastguard Worker
258*1c60b9acSAndroid Build Coastguard Worker**CLIENT**: The DNS address the secure stream should connect to.
259*1c60b9acSAndroid Build Coastguard Worker
260*1c60b9acSAndroid Build Coastguard WorkerThis may contain string symbols which will be replaced with the
261*1c60b9acSAndroid Build Coastguard Workercorresponding streamtype metadata value at runtime.  Eg, if the
262*1c60b9acSAndroid Build Coastguard Workerstreamtype lists a metadata name "region", it's then possible to
263*1c60b9acSAndroid Build Coastguard Workerdefine the endpoint as, eg, `${region}.mysite.com`, and before
264*1c60b9acSAndroid Build Coastguard Workerattempting the connection setting the stream's metadata item
265*1c60b9acSAndroid Build Coastguard Worker"region" to the desired value, eg, "uk".
266*1c60b9acSAndroid Build Coastguard Worker
267*1c60b9acSAndroid Build Coastguard WorkerIf the endpoint string begins with `+`, then it's understood to
268*1c60b9acSAndroid Build Coastguard Workermean a connection to a Unix Domain Socket, for Linux `+@` means
269*1c60b9acSAndroid Build Coastguard Workerthe following Unix Domain Socket is in the Linux Abstract
270*1c60b9acSAndroid Build Coastguard WorkerNamespace and doesn't have a filesystem footprint.  This is only
271*1c60b9acSAndroid Build Coastguard Workersupported on unix-type and windows platforms and when lws was
272*1c60b9acSAndroid Build Coastguard Workerconfigured with `-DLWS_UNIX_SOCK=1`
273*1c60b9acSAndroid Build Coastguard Worker
274*1c60b9acSAndroid Build Coastguard Worker**SERVER**: If given, the network interface name or IP address the listen socket
275*1c60b9acSAndroid Build Coastguard Workershould bind to.
276*1c60b9acSAndroid Build Coastguard Worker
277*1c60b9acSAndroid Build Coastguard Worker**SERVER**: If begins with '!', the rest of the endpoint name is the
278*1c60b9acSAndroid Build Coastguard Workervhost name of an existing vhost to bind to, instead of creating a new
279*1c60b9acSAndroid Build Coastguard Workerone.  This is useful when the vhost layout is already being managed by
280*1c60b9acSAndroid Build Coastguard Workerlejp-conf JSON and it's more convenient to put the details in there.
281*1c60b9acSAndroid Build Coastguard Worker
282*1c60b9acSAndroid Build Coastguard Worker### `port`
283*1c60b9acSAndroid Build Coastguard Worker
284*1c60b9acSAndroid Build Coastguard Worker**CLIENT**: The port number as an integer on the endpoint to connect to
285*1c60b9acSAndroid Build Coastguard Worker
286*1c60b9acSAndroid Build Coastguard Worker**SERVER**: The port number the server will listen on
287*1c60b9acSAndroid Build Coastguard Worker
288*1c60b9acSAndroid Build Coastguard Worker### `protocol`
289*1c60b9acSAndroid Build Coastguard Worker
290*1c60b9acSAndroid Build Coastguard Worker**CLIENT**: The wire protocol to connect to the endpoint with.  Currently
291*1c60b9acSAndroid Build Coastguard Workersupported streamtypes are
292*1c60b9acSAndroid Build Coastguard Worker
293*1c60b9acSAndroid Build Coastguard Worker|Wire protocol|Description|
294*1c60b9acSAndroid Build Coastguard Worker|---|---|
295*1c60b9acSAndroid Build Coastguard Worker|h1|http/1|
296*1c60b9acSAndroid Build Coastguard Worker|h2|http/2|
297*1c60b9acSAndroid Build Coastguard Worker|ws|http/1 Websockets|
298*1c60b9acSAndroid Build Coastguard Worker|mqtt|mqtt 3.1.1|
299*1c60b9acSAndroid Build Coastguard Worker|raw||
300*1c60b9acSAndroid Build Coastguard Worker
301*1c60b9acSAndroid Build Coastguard WorkerRaw protocol is a bit different than the others in that there is no protocol framing,
302*1c60b9acSAndroid Build Coastguard Workerwhatever is received on the connection is passed to the user rx callback and whatever
303*1c60b9acSAndroid Build Coastguard Workerthe tx callback provides is issued on to the connection.  Because tcp can be
304*1c60b9acSAndroid Build Coastguard Workerarbitrarily fragmented by any intermediary, such streams have to be regarded as an
305*1c60b9acSAndroid Build Coastguard Workerordered bytestream that may be fragmented at any byte without any meaning in terms
306*1c60b9acSAndroid Build Coastguard Workerof message boundaries, for that reason SOM and EOM are ignored with raw.
307*1c60b9acSAndroid Build Coastguard Worker
308*1c60b9acSAndroid Build Coastguard Worker### `allow_redirects`
309*1c60b9acSAndroid Build Coastguard Worker
310*1c60b9acSAndroid Build Coastguard WorkerBy default redirects are not followed, if you wish a streamtype to observe them, eg,
311*1c60b9acSAndroid Build Coastguard Workerbecause that's how it responds to a POST, set `"allow_redirects": true`
312*1c60b9acSAndroid Build Coastguard Worker
313*1c60b9acSAndroid Build Coastguard Worker### `tls`
314*1c60b9acSAndroid Build Coastguard Worker
315*1c60b9acSAndroid Build Coastguard WorkerSet to `true` to enforce the stream travelling in a tls tunnel
316*1c60b9acSAndroid Build Coastguard Worker
317*1c60b9acSAndroid Build Coastguard Worker### `client cert`
318*1c60b9acSAndroid Build Coastguard Worker
319*1c60b9acSAndroid Build Coastguard WorkerSet if the stream needs to authenticate itself using a tls client certificate.
320*1c60b9acSAndroid Build Coastguard WorkerSet to the certificate index counting from 0+.  The certificates are managed
321*1c60b9acSAndroid Build Coastguard Workerusing lws_sytstem blobs.
322*1c60b9acSAndroid Build Coastguard Worker
323*1c60b9acSAndroid Build Coastguard Worker### `opportunistic`
324*1c60b9acSAndroid Build Coastguard Worker
325*1c60b9acSAndroid Build Coastguard WorkerSet to `true` if the connection may be left dropped except when in use
326*1c60b9acSAndroid Build Coastguard Worker
327*1c60b9acSAndroid Build Coastguard Worker### `nailed_up`
328*1c60b9acSAndroid Build Coastguard Worker
329*1c60b9acSAndroid Build Coastguard WorkerSet to `true` to have lws retry if the connection carrying this stream should
330*1c60b9acSAndroid Build Coastguard Workerever drop.
331*1c60b9acSAndroid Build Coastguard Worker
332*1c60b9acSAndroid Build Coastguard Worker### `retry`
333*1c60b9acSAndroid Build Coastguard Worker
334*1c60b9acSAndroid Build Coastguard WorkerThe name of the policy described in the `retry` section to apply to this
335*1c60b9acSAndroid Build Coastguard Workerconnection for retry + backoff
336*1c60b9acSAndroid Build Coastguard Worker
337*1c60b9acSAndroid Build Coastguard Worker### `timeout_ms`
338*1c60b9acSAndroid Build Coastguard Worker
339*1c60b9acSAndroid Build Coastguard WorkerOptional timeout associated with streams of this streamtype.
340*1c60b9acSAndroid Build Coastguard Worker
341*1c60b9acSAndroid Build Coastguard WorkerIf user code applies the `lws_ss_start_timeout()` api on a stream with a
342*1c60b9acSAndroid Build Coastguard Workertimeout of LWSSS_TIMEOUT_FROM_POLICY, the `timeout_ms` entry given in the
343*1c60b9acSAndroid Build Coastguard Workerpolicy is applied.
344*1c60b9acSAndroid Build Coastguard Worker
345*1c60b9acSAndroid Build Coastguard Worker### `perf`
346*1c60b9acSAndroid Build Coastguard Worker
347*1c60b9acSAndroid Build Coastguard WorkerIf set to true, and lws was built with `LWS_WITH_CONMON`, causes this streamtype
348*1c60b9acSAndroid Build Coastguard Workerto receive additional rx payload with the `LWSSS_FLAG_PERF_JSON` flag set on it,
349*1c60b9acSAndroid Build Coastguard Workerthat is JSON representing the onward connection performance information.
350*1c60b9acSAndroid Build Coastguard Worker
351*1c60b9acSAndroid Build Coastguard WorkerThese are based on the information captured in the struct defined in
352*1c60b9acSAndroid Build Coastguard Workerlibwebsockets/lws-conmon.h, represented in JSON
353*1c60b9acSAndroid Build Coastguard Worker
354*1c60b9acSAndroid Build Coastguard Worker```
355*1c60b9acSAndroid Build Coastguard Worker	{
356*1c60b9acSAndroid Build Coastguard Worker	  "peer": "46.105.127.147",
357*1c60b9acSAndroid Build Coastguard Worker	  "dns_us": 1234,
358*1c60b9acSAndroid Build Coastguard Worker	  "sockconn_us": 1234,
359*1c60b9acSAndroid Build Coastguard Worker	  "tls_us": 1234,
360*1c60b9acSAndroid Build Coastguard Worker	  "txn_resp_us": 1234,
361*1c60b9acSAndroid Build Coastguard Worker	  "dns":["46.105.127.147", "2001:41d0:2:ee93::1"]
362*1c60b9acSAndroid Build Coastguard Worker	}
363*1c60b9acSAndroid Build Coastguard Worker```
364*1c60b9acSAndroid Build Coastguard Worker
365*1c60b9acSAndroid Build Coastguard WorkerStreamtypes without "perf": true will never see the special rx payloads.
366*1c60b9acSAndroid Build Coastguard WorkerNotice that the `LWSSS_FLAG_PERF_JSON` payloads must be handled out of band
367*1c60b9acSAndroid Build Coastguard Workerfor the normal payloads, as they can appear inside normal payload messages.
368*1c60b9acSAndroid Build Coastguard Worker
369*1c60b9acSAndroid Build Coastguard Worker### `tls_trust_store`
370*1c60b9acSAndroid Build Coastguard Worker
371*1c60b9acSAndroid Build Coastguard WorkerThe name of the trust store described in the `trust_stores` section to apply
372*1c60b9acSAndroid Build Coastguard Workerto validate the remote server cert.
373*1c60b9acSAndroid Build Coastguard Worker
374*1c60b9acSAndroid Build Coastguard WorkerIf missing and tls is enabled on the streamtype, then validation is
375*1c60b9acSAndroid Build Coastguard Workerattempted using the OS trust store, otherwise the connection fails.
376*1c60b9acSAndroid Build Coastguard Worker
377*1c60b9acSAndroid Build Coastguard Worker### `use_auth`
378*1c60b9acSAndroid Build Coastguard Worker
379*1c60b9acSAndroid Build Coastguard WorkerIndicate that the streamtype should use the named auth type from the `auth`
380*1c60b9acSAndroid Build Coastguard Workerarray in the policy
381*1c60b9acSAndroid Build Coastguard Worker
382*1c60b9acSAndroid Build Coastguard Worker### `aws_region`
383*1c60b9acSAndroid Build Coastguard Worker
384*1c60b9acSAndroid Build Coastguard WorkerIndicate which metadata should be used to set aws region for certain streamtype
385*1c60b9acSAndroid Build Coastguard Worker
386*1c60b9acSAndroid Build Coastguard Worker### `aws_service`
387*1c60b9acSAndroid Build Coastguard Worker
388*1c60b9acSAndroid Build Coastguard WorkerIndicate which metadata should be used to set aws service for certain streamtype
389*1c60b9acSAndroid Build Coastguard Worker
390*1c60b9acSAndroid Build Coastguard Worker### `direct_proto_str`
391*1c60b9acSAndroid Build Coastguard Worker
392*1c60b9acSAndroid Build Coastguard WorkerIf set to `true`, application can use `lws_ss_set_metadata()` to directly set protocol related string and use `lws_ss_get_metadata` to fetch certain protocol related string.  Please note that currently HTTP header is the supported protocol string.  The `name` parameter is the name of HTTP header name (**with ':'**, e.g. `"Content-Type:"`) and `value` is the header's value. `LWS_WITH_SS_DIRECT_PROTOCOL_STR` flag needs to be configured during compilation for this.  Currently it's only work for non-proxy case.
393*1c60b9acSAndroid Build Coastguard Worker
394*1c60b9acSAndroid Build Coastguard Worker### `server_cert`
395*1c60b9acSAndroid Build Coastguard Worker
396*1c60b9acSAndroid Build Coastguard Worker**SERVER ONLY**: subject to change... the name of the x.509 cert that is the
397*1c60b9acSAndroid Build Coastguard Workerserver's tls certificate
398*1c60b9acSAndroid Build Coastguard Worker
399*1c60b9acSAndroid Build Coastguard Worker### `server_key`
400*1c60b9acSAndroid Build Coastguard Worker
401*1c60b9acSAndroid Build Coastguard Worker**SERVER ONLY**: subject to change... the name of the x.509 cert that is the
402*1c60b9acSAndroid Build Coastguard Workerserver's tls key
403*1c60b9acSAndroid Build Coastguard Worker
404*1c60b9acSAndroid Build Coastguard Worker### `swake_validity`
405*1c60b9acSAndroid Build Coastguard Worker
406*1c60b9acSAndroid Build Coastguard WorkerSet to `true` if this streamtype is important enough for the functioning of the
407*1c60b9acSAndroid Build Coastguard Workerdevice that its locally-initiated periodic connection validity checks of the
408*1c60b9acSAndroid Build Coastguard Workerinterval described in the associated retry / backoff selection, are important
409*1c60b9acSAndroid Build Coastguard Workerenough to wake the whole system from low power suspend so they happen on
410*1c60b9acSAndroid Build Coastguard Workerschedule.
411*1c60b9acSAndroid Build Coastguard Worker
412*1c60b9acSAndroid Build Coastguard Worker### `proxy_buflen`
413*1c60b9acSAndroid Build Coastguard Worker
414*1c60b9acSAndroid Build Coastguard WorkerOnly used when the streamtype is proxied... sets the maximum size of the
415*1c60b9acSAndroid Build Coastguard Workerpayload buffering (in bytes) the proxy will hold for this type of stream.  If
416*1c60b9acSAndroid Build Coastguard Workerthe endpoint dumps a lot of data without any flow control, this may need to
417*1c60b9acSAndroid Build Coastguard Workerbe correspondingly large.  Default is 32KB.
418*1c60b9acSAndroid Build Coastguard Worker
419*1c60b9acSAndroid Build Coastguard Worker### `proxy_buflen_rxflow_on_above`, `proxy_buflen_rxflow_off_below`
420*1c60b9acSAndroid Build Coastguard Worker
421*1c60b9acSAndroid Build Coastguard WorkerWhen `proxy_buflen` is set, you can also wire up the amount of buffered
422*1c60b9acSAndroid Build Coastguard Workerdata intended for the client held at the proxy, to the onward ss wsi
423*1c60b9acSAndroid Build Coastguard Workerrx flow control state.  If more than `proxy_buflen_rxflow_on_above`
424*1c60b9acSAndroid Build Coastguard Workerbytes are buffered, rx flow control is set stopping further rx.  Once
425*1c60b9acSAndroid Build Coastguard Workerthe dsh is drained below `proxy_buflen_rxflow_off_below`, the rx flow
426*1c60b9acSAndroid Build Coastguard Workercontrol is released and RX resumes.
427*1c60b9acSAndroid Build Coastguard Worker
428*1c60b9acSAndroid Build Coastguard Worker### `client_buflen`
429*1c60b9acSAndroid Build Coastguard Worker
430*1c60b9acSAndroid Build Coastguard WorkerOnly used when the streamtype is proxied... sets the maximum size of the
431*1c60b9acSAndroid Build Coastguard Workerpayload buffering (in bytes) the client will hold for this type of stream.  If
432*1c60b9acSAndroid Build Coastguard Workerthe client sends a lot of data without any flow control, this may need to
433*1c60b9acSAndroid Build Coastguard Workerbe correspondingly large.  Default is 32KB.
434*1c60b9acSAndroid Build Coastguard Worker
435*1c60b9acSAndroid Build Coastguard Worker### `attr_priority`
436*1c60b9acSAndroid Build Coastguard Worker
437*1c60b9acSAndroid Build Coastguard WorkerA number between 0 (normal priority) and 6 (very high priority).  7 is also
438*1c60b9acSAndroid Build Coastguard Workerpossible, but requires CAP_NET_ADMIN on Linux and is reserved for network
439*1c60b9acSAndroid Build Coastguard Workeradministration packets.  Normally default priority is fine, but under some
440*1c60b9acSAndroid Build Coastguard Workerconditions when transporting over IP packets, you may want to control the
441*1c60b9acSAndroid Build Coastguard WorkerIP packet ToS priority for the streamtype by using this.
442*1c60b9acSAndroid Build Coastguard Worker
443*1c60b9acSAndroid Build Coastguard Worker### `attr_low_latency`
444*1c60b9acSAndroid Build Coastguard Worker
445*1c60b9acSAndroid Build Coastguard WorkerThis is a flag indicating that the streamtype packets should be transported
446*1c60b9acSAndroid Build Coastguard Workerin a way that results in lower latency where there is a choice.  For IP packets,
447*1c60b9acSAndroid Build Coastguard Workerthis sets the ToS "low delay" flag on packets from this streamtype.
448*1c60b9acSAndroid Build Coastguard Worker
449*1c60b9acSAndroid Build Coastguard Worker### `attr_high_throughput`
450*1c60b9acSAndroid Build Coastguard Worker
451*1c60b9acSAndroid Build Coastguard WorkerThis is a flag indicating that this streamtype should be expected to produce
452*1c60b9acSAndroid Build Coastguard Workerbulk content that requires high throughput.  For IP packets,
453*1c60b9acSAndroid Build Coastguard Workerthis sets the ToS "high throughput" flag on packets from this streamtype.
454*1c60b9acSAndroid Build Coastguard Worker
455*1c60b9acSAndroid Build Coastguard Worker### `attr_high_reliability`
456*1c60b9acSAndroid Build Coastguard Worker
457*1c60b9acSAndroid Build Coastguard WorkerThis is a flag indicating that extra efforts should be made to deliver packets
458*1c60b9acSAndroid Build Coastguard Workerfrom this streamtype where possible.  For IP packets, this sets the ToS "high
459*1c60b9acSAndroid Build Coastguard Workerreliability" flag on packets from this streamtype.
460*1c60b9acSAndroid Build Coastguard Worker
461*1c60b9acSAndroid Build Coastguard Worker### `attr_low_cost`
462*1c60b9acSAndroid Build Coastguard Worker
463*1c60b9acSAndroid Build Coastguard WorkerThis is a flag indicating that packets from this streamtype should be routed as
464*1c60b9acSAndroid Build Coastguard Workerinexpensively as possible by trading off latency and reliability where there is
465*1c60b9acSAndroid Build Coastguard Workera choice.  For IP packets, this sets the ToS "low cost" flag on packets from
466*1c60b9acSAndroid Build Coastguard Workerthis streamtype.
467*1c60b9acSAndroid Build Coastguard Worker
468*1c60b9acSAndroid Build Coastguard Worker### `metadata`
469*1c60b9acSAndroid Build Coastguard Worker
470*1c60b9acSAndroid Build Coastguard WorkerThis allows declaring basically dynamic symbol names to be used by the streamtype,
471*1c60b9acSAndroid Build Coastguard Workeralong with an optional mapping to a protocol-specific entity such as a given
472*1c60b9acSAndroid Build Coastguard Workerhttp header.  Eg:
473*1c60b9acSAndroid Build Coastguard Worker
474*1c60b9acSAndroid Build Coastguard Worker```
475*1c60b9acSAndroid Build Coastguard Worker		"metadata": [ { "myname": "" }, { "ctype": "content-type:" } ],
476*1c60b9acSAndroid Build Coastguard Worker```
477*1c60b9acSAndroid Build Coastguard Worker
478*1c60b9acSAndroid Build Coastguard WorkerIn this example "ctype" is associated with the http header "content-type" while
479*1c60b9acSAndroid Build Coastguard Worker"myname" doesn't have any association to a header.
480*1c60b9acSAndroid Build Coastguard Worker
481*1c60b9acSAndroid Build Coastguard WorkerSymbol names may be used in the other policy for the streamtype for string
482*1c60b9acSAndroid Build Coastguard Workersubstitution using the syntax like `xxx${myname}yyy`, forward references are
483*1c60b9acSAndroid Build Coastguard Workervalid but the scope of the symbols is just the streamtype the metadata is
484*1c60b9acSAndroid Build Coastguard Workerdefined for.
485*1c60b9acSAndroid Build Coastguard Worker
486*1c60b9acSAndroid Build Coastguard WorkerClient code can set metadata by name, using the `lws_ss_set_metadata()` api, this
487*1c60b9acSAndroid Build Coastguard Workershould be done before a transaction.  And for metadata associated with a
488*1c60b9acSAndroid Build Coastguard Workerprotocol-specific entity, like http headers, if incoming responses contain the
489*1c60b9acSAndroid Build Coastguard Workermentioned header, the metadata symbol is set to that value at the client before
490*1c60b9acSAndroid Build Coastguard Workerany rx proceeds.
491*1c60b9acSAndroid Build Coastguard Worker
492*1c60b9acSAndroid Build Coastguard WorkerMetadata continues to work the same for the client in the case it is proxying its
493*1c60b9acSAndroid Build Coastguard Workerconnectivity, metadata is passed in both directions serialized over the proxy link.
494*1c60b9acSAndroid Build Coastguard Worker
495*1c60b9acSAndroid Build Coastguard Worker## http transport
496*1c60b9acSAndroid Build Coastguard Worker
497*1c60b9acSAndroid Build Coastguard Worker### `http_method`
498*1c60b9acSAndroid Build Coastguard Worker
499*1c60b9acSAndroid Build Coastguard WorkerHTTP method to use with http-related protocols, like GET or POST.
500*1c60b9acSAndroid Build Coastguard WorkerNot required for ws.
501*1c60b9acSAndroid Build Coastguard Worker
502*1c60b9acSAndroid Build Coastguard Worker### `http_expect`
503*1c60b9acSAndroid Build Coastguard Worker
504*1c60b9acSAndroid Build Coastguard WorkerOptionally indicates that success for HTTP transactions using this
505*1c60b9acSAndroid Build Coastguard Workerstreamtype is different than the default 200 - 299.
506*1c60b9acSAndroid Build Coastguard Worker
507*1c60b9acSAndroid Build Coastguard WorkerEg, you may choose to set this to 204 for Captive Portal Detect usage
508*1c60b9acSAndroid Build Coastguard Workerif that's what you expect the server to reply with to indicate
509*1c60b9acSAndroid Build Coastguard Workersuccess.  In that case, anything other than 204 will be treated as a
510*1c60b9acSAndroid Build Coastguard Workerconnection failure.
511*1c60b9acSAndroid Build Coastguard Worker
512*1c60b9acSAndroid Build Coastguard Worker### `http_fail_redirect`
513*1c60b9acSAndroid Build Coastguard Worker
514*1c60b9acSAndroid Build Coastguard WorkerSet to `true` if you want to fail the connection on meeting an
515*1c60b9acSAndroid Build Coastguard Workerhttp redirect.  This is needed to, eg, detect Captive Portals
516*1c60b9acSAndroid Build Coastguard Workercorrectly.  Normally, if on https, you would want the default behaviour
517*1c60b9acSAndroid Build Coastguard Workerof following the redirect.
518*1c60b9acSAndroid Build Coastguard Worker
519*1c60b9acSAndroid Build Coastguard Worker### `http_url`
520*1c60b9acSAndroid Build Coastguard Worker
521*1c60b9acSAndroid Build Coastguard WorkerUrl path to use with http-related protocols
522*1c60b9acSAndroid Build Coastguard Worker
523*1c60b9acSAndroid Build Coastguard WorkerThe URL path can include metatadata like this
524*1c60b9acSAndroid Build Coastguard Worker
525*1c60b9acSAndroid Build Coastguard Worker"/mypath?whatever=${metadataname}"
526*1c60b9acSAndroid Build Coastguard Worker
527*1c60b9acSAndroid Build Coastguard Worker${metadataname} will be replaced by the current value of the
528*1c60b9acSAndroid Build Coastguard Workersame metadata name.  The metadata names must be listed in the
529*1c60b9acSAndroid Build Coastguard Worker"metadata": [ ] section.
530*1c60b9acSAndroid Build Coastguard Worker
531*1c60b9acSAndroid Build Coastguard Worker### `http_resp_map`
532*1c60b9acSAndroid Build Coastguard Worker
533*1c60b9acSAndroid Build Coastguard WorkerIf your server overloads the meaning of the http transport response code with
534*1c60b9acSAndroid Build Coastguard Workerserver-custom application codes, you can map these to discrete Secure Streams
535*1c60b9acSAndroid Build Coastguard Workerstate callbacks using a JSON map, eg
536*1c60b9acSAndroid Build Coastguard Worker
537*1c60b9acSAndroid Build Coastguard Worker```
538*1c60b9acSAndroid Build Coastguard Worker		"http_resp_map": [ { "530": 1530 }, { "531": 1531 } ],
539*1c60b9acSAndroid Build Coastguard Worker```
540*1c60b9acSAndroid Build Coastguard Worker
541*1c60b9acSAndroid Build Coastguard WorkerIt's not recommended to abuse the transport layer http response code by
542*1c60b9acSAndroid Build Coastguard Workermixing it with application state information like this, but if it's dealing
543*1c60b9acSAndroid Build Coastguard Workerwith legacy serverside that takes this approach, it's possible to handle it
544*1c60b9acSAndroid Build Coastguard Workerin SS this way while removing the dependency on http.
545*1c60b9acSAndroid Build Coastguard Worker
546*1c60b9acSAndroid Build Coastguard Worker### `http_auth_header`
547*1c60b9acSAndroid Build Coastguard Worker
548*1c60b9acSAndroid Build Coastguard WorkerThe name of the header that takes the auth token, with a trailing ':', eg
549*1c60b9acSAndroid Build Coastguard Worker
550*1c60b9acSAndroid Build Coastguard Worker```
551*1c60b9acSAndroid Build Coastguard Worker  "http_auth_header": "authorization:"
552*1c60b9acSAndroid Build Coastguard Worker```
553*1c60b9acSAndroid Build Coastguard Worker
554*1c60b9acSAndroid Build Coastguard Worker### `http_dsn_header`
555*1c60b9acSAndroid Build Coastguard Worker
556*1c60b9acSAndroid Build Coastguard WorkerThe name of the header that takes the dsn token, with a trailing ':', eg
557*1c60b9acSAndroid Build Coastguard Worker
558*1c60b9acSAndroid Build Coastguard Worker```
559*1c60b9acSAndroid Build Coastguard Worker  "http_dsn_header": "x-dsn:"
560*1c60b9acSAndroid Build Coastguard Worker```
561*1c60b9acSAndroid Build Coastguard Worker
562*1c60b9acSAndroid Build Coastguard Worker### `http_fwv_header`
563*1c60b9acSAndroid Build Coastguard Worker
564*1c60b9acSAndroid Build Coastguard WorkerThe name of the header that takes the firmware version token, with a trailing ':', eg
565*1c60b9acSAndroid Build Coastguard Worker
566*1c60b9acSAndroid Build Coastguard Worker```
567*1c60b9acSAndroid Build Coastguard Worker  "http_fwv_header": "x-fw-version:"
568*1c60b9acSAndroid Build Coastguard Worker```
569*1c60b9acSAndroid Build Coastguard Worker
570*1c60b9acSAndroid Build Coastguard Worker### `http_devtype_header`
571*1c60b9acSAndroid Build Coastguard Worker
572*1c60b9acSAndroid Build Coastguard WorkerThe name of the header that takes the device type token, with a trailing ':', eg
573*1c60b9acSAndroid Build Coastguard Worker
574*1c60b9acSAndroid Build Coastguard Worker```
575*1c60b9acSAndroid Build Coastguard Worker  "http_devtype_header": "x-device-type:"
576*1c60b9acSAndroid Build Coastguard Worker```
577*1c60b9acSAndroid Build Coastguard Worker
578*1c60b9acSAndroid Build Coastguard Worker### `http_auth_preamble`
579*1c60b9acSAndroid Build Coastguard Worker
580*1c60b9acSAndroid Build Coastguard WorkerAn optional string that precedes the auth token, eg
581*1c60b9acSAndroid Build Coastguard Worker
582*1c60b9acSAndroid Build Coastguard Worker```
583*1c60b9acSAndroid Build Coastguard Worker "http_auth_preamble": "bearer "
584*1c60b9acSAndroid Build Coastguard Worker```
585*1c60b9acSAndroid Build Coastguard Worker
586*1c60b9acSAndroid Build Coastguard Worker### `auth_hexify`
587*1c60b9acSAndroid Build Coastguard Worker
588*1c60b9acSAndroid Build Coastguard WorkerConvert the auth token to hex ('A' -> "41") before transporting.  Not necessary if the
589*1c60b9acSAndroid Build Coastguard Workerauth token is already in printable string format suitable for transport.  Needed if the
590*1c60b9acSAndroid Build Coastguard Workerauth token is a chunk of 8-bit binary.
591*1c60b9acSAndroid Build Coastguard Worker
592*1c60b9acSAndroid Build Coastguard Worker### `nghttp2_quirk_end_stream`
593*1c60b9acSAndroid Build Coastguard Worker
594*1c60b9acSAndroid Build Coastguard WorkerSet this to `true` if the peer server has the quirk it won't send a response until we have
595*1c60b9acSAndroid Build Coastguard Workersent an `END_STREAM`, even though we have sent headers with `END_HEADERS`.
596*1c60b9acSAndroid Build Coastguard Worker
597*1c60b9acSAndroid Build Coastguard Worker### `h2q_oflow_txcr`
598*1c60b9acSAndroid Build Coastguard Worker
599*1c60b9acSAndroid Build Coastguard WorkerSet this to `true` if the peer server has the quirk it sends an maximum initial tx credit
600*1c60b9acSAndroid Build Coastguard Workerof 0x7fffffff and then later increments it illegally.
601*1c60b9acSAndroid Build Coastguard Worker
602*1c60b9acSAndroid Build Coastguard Worker### `http_multipart_ss_in`
603*1c60b9acSAndroid Build Coastguard Worker
604*1c60b9acSAndroid Build Coastguard WorkerIndicates that SS should parse any incoming multipart mime on this stream
605*1c60b9acSAndroid Build Coastguard Worker
606*1c60b9acSAndroid Build Coastguard Worker### `http_multipart_name`
607*1c60b9acSAndroid Build Coastguard Worker
608*1c60b9acSAndroid Build Coastguard WorkerIndicates this stream goes out using multipart mime, and provides the name part of the
609*1c60b9acSAndroid Build Coastguard Workermultipart header
610*1c60b9acSAndroid Build Coastguard Worker
611*1c60b9acSAndroid Build Coastguard Worker### `http_multipart_filename`
612*1c60b9acSAndroid Build Coastguard Worker
613*1c60b9acSAndroid Build Coastguard WorkerIndicates this stream goes out using multipart mime, and provides the filename part of the
614*1c60b9acSAndroid Build Coastguard Workermultipart header
615*1c60b9acSAndroid Build Coastguard Worker
616*1c60b9acSAndroid Build Coastguard Worker### `http_multipart_content_type`
617*1c60b9acSAndroid Build Coastguard Worker
618*1c60b9acSAndroid Build Coastguard WorkerThe `content-type` to mark up the multipart mime section with if present
619*1c60b9acSAndroid Build Coastguard Worker
620*1c60b9acSAndroid Build Coastguard Worker### `http_www_form_urlencoded`
621*1c60b9acSAndroid Build Coastguard Worker
622*1c60b9acSAndroid Build Coastguard WorkerIndicate the data is sent in `x-www-form-urlencoded` form
623*1c60b9acSAndroid Build Coastguard Worker
624*1c60b9acSAndroid Build Coastguard Worker### `http_cookies`
625*1c60b9acSAndroid Build Coastguard Worker
626*1c60b9acSAndroid Build Coastguard WorkerThis streamtype should store and bring out http cookies from the peer.
627*1c60b9acSAndroid Build Coastguard Worker
628*1c60b9acSAndroid Build Coastguard Worker### `rideshare`
629*1c60b9acSAndroid Build Coastguard Worker
630*1c60b9acSAndroid Build Coastguard WorkerFor special cases where one logically separate stream travels with another when using this
631*1c60b9acSAndroid Build Coastguard Workerprotocol.  Eg, a single multipart mime transaction carries content from two or more streams.
632*1c60b9acSAndroid Build Coastguard Worker
633*1c60b9acSAndroid Build Coastguard Worker## ws transport
634*1c60b9acSAndroid Build Coastguard Worker
635*1c60b9acSAndroid Build Coastguard Worker### `ws_subprotocol`
636*1c60b9acSAndroid Build Coastguard Worker
637*1c60b9acSAndroid Build Coastguard Worker** CLIENT **: Name of the ws subprotocol to request from the server
638*1c60b9acSAndroid Build Coastguard Worker
639*1c60b9acSAndroid Build Coastguard Worker** SERVER **: Name of the subprotocol we will accept
640*1c60b9acSAndroid Build Coastguard Worker
641*1c60b9acSAndroid Build Coastguard Worker### `ws_binary`
642*1c60b9acSAndroid Build Coastguard Worker
643*1c60b9acSAndroid Build Coastguard WorkerUse if the ws messages are binary
644*1c60b9acSAndroid Build Coastguard Worker
645*1c60b9acSAndroid Build Coastguard Worker### `ws_prioritize_reads`
646*1c60b9acSAndroid Build Coastguard Worker
647*1c60b9acSAndroid Build Coastguard WorkerSet `true` if the event loop should prioritize keeping up with input at the
648*1c60b9acSAndroid Build Coastguard Workerpotential expense of output latency.
649*1c60b9acSAndroid Build Coastguard Worker
650*1c60b9acSAndroid Build Coastguard Worker## MQTT transport
651*1c60b9acSAndroid Build Coastguard Worker
652*1c60b9acSAndroid Build Coastguard Worker### `mqtt_topic`
653*1c60b9acSAndroid Build Coastguard Worker
654*1c60b9acSAndroid Build Coastguard WorkerSet the topic this streamtype uses for writes
655*1c60b9acSAndroid Build Coastguard Worker
656*1c60b9acSAndroid Build Coastguard Worker### `mqtt_subscribe`
657*1c60b9acSAndroid Build Coastguard Worker
658*1c60b9acSAndroid Build Coastguard WorkerSet the topic this streamtype subscribes to
659*1c60b9acSAndroid Build Coastguard Worker
660*1c60b9acSAndroid Build Coastguard Worker### `mqtt qos`
661*1c60b9acSAndroid Build Coastguard Worker
662*1c60b9acSAndroid Build Coastguard WorkerSet the QOS level for this streamtype
663*1c60b9acSAndroid Build Coastguard Worker
664*1c60b9acSAndroid Build Coastguard Worker### `mqtt_keep_alive`
665*1c60b9acSAndroid Build Coastguard Worker
666*1c60b9acSAndroid Build Coastguard Worker16-bit number representing MQTT keep alive for the stream.
667*1c60b9acSAndroid Build Coastguard Worker
668*1c60b9acSAndroid Build Coastguard WorkerThis is applied at connection time... where different streams may bind to the
669*1c60b9acSAndroid Build Coastguard Workersame underlying MQTT connection, all the streams should have an identical
670*1c60b9acSAndroid Build Coastguard Workersetting for this.
671*1c60b9acSAndroid Build Coastguard Worker
672*1c60b9acSAndroid Build Coastguard Worker### `mqtt_clean_start`
673*1c60b9acSAndroid Build Coastguard Worker
674*1c60b9acSAndroid Build Coastguard WorkerSet to true if the connection should use MQTT's "clean start" feature.
675*1c60b9acSAndroid Build Coastguard Worker
676*1c60b9acSAndroid Build Coastguard WorkerThis is applied at connection time... where different streams may bind to the
677*1c60b9acSAndroid Build Coastguard Workersame underlying MQTT connection, all the streams should have an identical
678*1c60b9acSAndroid Build Coastguard Workersetting for this.
679*1c60b9acSAndroid Build Coastguard Worker
680*1c60b9acSAndroid Build Coastguard Worker### `mqtt_will_topic`
681*1c60b9acSAndroid Build Coastguard Worker
682*1c60b9acSAndroid Build Coastguard WorkerSet the topic of the connection's will message, if any (there is none by default).
683*1c60b9acSAndroid Build Coastguard Worker
684*1c60b9acSAndroid Build Coastguard WorkerThis is applied at connection time... where different streams may bind to the
685*1c60b9acSAndroid Build Coastguard Workersame underlying MQTT connection, all the streams should have an identical
686*1c60b9acSAndroid Build Coastguard Workersetting for this.
687*1c60b9acSAndroid Build Coastguard Worker
688*1c60b9acSAndroid Build Coastguard Worker### `mqtt_will_message`
689*1c60b9acSAndroid Build Coastguard Worker
690*1c60b9acSAndroid Build Coastguard WorkerSet the content of the connect's will message, if any (there is none by default).
691*1c60b9acSAndroid Build Coastguard Worker
692*1c60b9acSAndroid Build Coastguard WorkerThis is applied at connection time... where different streams may bind to the
693*1c60b9acSAndroid Build Coastguard Workersame underlying MQTT connection, all the streams should have an identical
694*1c60b9acSAndroid Build Coastguard Workersetting for this.
695*1c60b9acSAndroid Build Coastguard Worker
696*1c60b9acSAndroid Build Coastguard Worker### `mqtt_will_qos`
697*1c60b9acSAndroid Build Coastguard Worker
698*1c60b9acSAndroid Build Coastguard WorkerSet the QoS of the will message, if any (there is none by default).
699*1c60b9acSAndroid Build Coastguard Worker
700*1c60b9acSAndroid Build Coastguard WorkerThis is applied at connection time... where different streams may bind to the
701*1c60b9acSAndroid Build Coastguard Workersame underlying MQTT connection, all the streams should have an identical
702*1c60b9acSAndroid Build Coastguard Workersetting for this.
703*1c60b9acSAndroid Build Coastguard Worker
704*1c60b9acSAndroid Build Coastguard Worker### `mqtt_will_retain`
705*1c60b9acSAndroid Build Coastguard Worker
706*1c60b9acSAndroid Build Coastguard WorkerSet to true if the connection should use MQTT's "will retain" feature, if there
707*1c60b9acSAndroid Build Coastguard Workeris a will message (there is none by default).
708*1c60b9acSAndroid Build Coastguard Worker
709*1c60b9acSAndroid Build Coastguard WorkerThis is applied at connection time... where different streams may bind to the
710*1c60b9acSAndroid Build Coastguard Workersame underlying MQTT connection, all the streams should have an identical
711*1c60b9acSAndroid Build Coastguard Workersetting for this.
712*1c60b9acSAndroid Build Coastguard Worker
713*1c60b9acSAndroid Build Coastguard Worker## Loading and using updated remote policy
714*1c60b9acSAndroid Build Coastguard Worker
715*1c60b9acSAndroid Build Coastguard WorkerIf the default, hardcoded policy includes a streamtype `fetch_policy`,
716*1c60b9acSAndroid Build Coastguard Workerduring startup when lws_system reaches the POLICY state, lws will use
717*1c60b9acSAndroid Build Coastguard Workera Secure Stream of type `fetch_policy` to download, parse and update
718*1c60b9acSAndroid Build Coastguard Workerthe policy to use it.
719*1c60b9acSAndroid Build Coastguard Worker
720*1c60b9acSAndroid Build Coastguard WorkerThe secure-streams-proxy minimal example shows how this is done and
721*1c60b9acSAndroid Build Coastguard Workerfetches its real policy from warmcat.com at startup using the built-in
722*1c60b9acSAndroid Build Coastguard Workerone.
723*1c60b9acSAndroid Build Coastguard Worker
724*1c60b9acSAndroid Build Coastguard Worker## Applying streamtype policy overlays
725*1c60b9acSAndroid Build Coastguard Worker
726*1c60b9acSAndroid Build Coastguard WorkerThis is intended for modifying policies at runtime for testing, eg, to
727*1c60b9acSAndroid Build Coastguard Workerforce error paths to be taken.  After the main policy is processed, you
728*1c60b9acSAndroid Build Coastguard Workermay parse additional, usually smaller policy fragments on top of it.
729*1c60b9acSAndroid Build Coastguard Worker
730*1c60b9acSAndroid Build Coastguard WorkerWhere streamtype names in the new fragment already exist in the current
731*1c60b9acSAndroid Build Coastguard Workerparsed policy, the settings in the fragment are applied over the parsed
732*1c60b9acSAndroid Build Coastguard Workerpolicy, overriding settings.  There's a simple api to enable this by
733*1c60b9acSAndroid Build Coastguard Workergiving it the override JSON in one string
734*1c60b9acSAndroid Build Coastguard Worker
735*1c60b9acSAndroid Build Coastguard Worker```
736*1c60b9acSAndroid Build Coastguard Workerint
737*1c60b9acSAndroid Build Coastguard Workerlws_ss_policy_overlay(struct lws_context *context, const char *overlay);
738*1c60b9acSAndroid Build Coastguard Worker```
739*1c60b9acSAndroid Build Coastguard Worker
740*1c60b9acSAndroid Build Coastguard Workerbut there are also other apis available that can statefully process
741*1c60b9acSAndroid Build Coastguard Workerlarger overlay fragments if needed.
742*1c60b9acSAndroid Build Coastguard Worker
743*1c60b9acSAndroid Build Coastguard WorkerAn example overlay fragment looks like this
744*1c60b9acSAndroid Build Coastguard Worker
745*1c60b9acSAndroid Build Coastguard Worker```
746*1c60b9acSAndroid Build Coastguard Worker	{ "s": [{ "captive_portal_detect": {
747*1c60b9acSAndroid Build Coastguard Worker		"endpoint": "google.com",
748*1c60b9acSAndroid Build Coastguard Worker		"http_url": "/",
749*1c60b9acSAndroid Build Coastguard Worker		"port": 80
750*1c60b9acSAndroid Build Coastguard Worker	}}]}
751*1c60b9acSAndroid Build Coastguard Worker```
752*1c60b9acSAndroid Build Coastguard Worker
753*1c60b9acSAndroid Build Coastguard Workerie the overlay fragment completely follows the structure of the main policy,
754*1c60b9acSAndroid Build Coastguard Workerjust misses out anything it doesn't override.
755*1c60b9acSAndroid Build Coastguard Worker
756*1c60b9acSAndroid Build Coastguard WorkerCurrently ONLY streamtypes may be overridden.
757*1c60b9acSAndroid Build Coastguard Worker
758*1c60b9acSAndroid Build Coastguard WorkerYou can see an example of this in use in `minimal-secure-streams` example
759*1c60b9acSAndroid Build Coastguard Workerwhere `--force-portal` and `--force-no-internet` options cause the captive
760*1c60b9acSAndroid Build Coastguard Workerportal detect streamtype to be overridden to force the requested kind of
761*1c60b9acSAndroid Build Coastguard Workeroutcome.
762*1c60b9acSAndroid Build Coastguard Worker
763*1c60b9acSAndroid Build Coastguard Worker## Captive Portal Detection
764*1c60b9acSAndroid Build Coastguard Worker
765*1c60b9acSAndroid Build Coastguard WorkerIf the policy contains a streamtype `captive_portal_detect` then the
766*1c60b9acSAndroid Build Coastguard Workertype of transaction described there is automatically performed after
767*1c60b9acSAndroid Build Coastguard Workeracquiring a DHCP address to try to determine the captive portal
768*1c60b9acSAndroid Build Coastguard Workersituation.
769*1c60b9acSAndroid Build Coastguard Worker
770*1c60b9acSAndroid Build Coastguard Worker```
771*1c60b9acSAndroid Build Coastguard Worker		"captive_portal_detect": {
772*1c60b9acSAndroid Build Coastguard Worker                        "endpoint": "connectivitycheck.android.com",
773*1c60b9acSAndroid Build Coastguard Worker                        "port": 80,
774*1c60b9acSAndroid Build Coastguard Worker                        "protocol": "h1",
775*1c60b9acSAndroid Build Coastguard Worker                        "http_method": "GET",
776*1c60b9acSAndroid Build Coastguard Worker                        "http_url": "generate_204",
777*1c60b9acSAndroid Build Coastguard Worker                        "opportunistic": true,
778*1c60b9acSAndroid Build Coastguard Worker                        "http_expect": 204,
779*1c60b9acSAndroid Build Coastguard Worker			"http_fail_redirect": true
780*1c60b9acSAndroid Build Coastguard Worker                }
781*1c60b9acSAndroid Build Coastguard Worker```
782*1c60b9acSAndroid Build Coastguard Worker
783*1c60b9acSAndroid Build Coastguard Worker## Stream serialization and proxying
784*1c60b9acSAndroid Build Coastguard Worker
785*1c60b9acSAndroid Build Coastguard WorkerBy default Secure Streams expects to make the outgoing connection described in
786*1c60b9acSAndroid Build Coastguard Workerthe policy in the same process / thread, this suits the case where all the
787*1c60b9acSAndroid Build Coastguard Workerparticipating clients are in the same statically-linked image.
788*1c60b9acSAndroid Build Coastguard Worker
789*1c60b9acSAndroid Build Coastguard WorkerIn this case the `lws_ss_` apis are fulfilled locally by secure-streams.c and
790*1c60b9acSAndroid Build Coastguard Workerpolicy.c for policy lookups.
791*1c60b9acSAndroid Build Coastguard Worker
792*1c60b9acSAndroid Build Coastguard WorkerHowever it also supports serialization, where the SS api can be streamed over
793*1c60b9acSAndroid Build Coastguard Workeranother transport such as a Unix Domain Socket connection.  This suits the case
794*1c60b9acSAndroid Build Coastguard Workerwhere the clients are actually in different processes in, eg, Linux or Android.
795*1c60b9acSAndroid Build Coastguard Worker
796*1c60b9acSAndroid Build Coastguard WorkerIn those cases, you run a proxy process (minimal-secure-streams-proxy) that
797*1c60b9acSAndroid Build Coastguard Workerlistens on a Unix Domain Socket and is connected to by one or more other
798*1c60b9acSAndroid Build Coastguard Workerprocesses that pass their SS API activity to the proxy for fulfilment (or
799*1c60b9acSAndroid Build Coastguard Workeronward proxying).
800*1c60b9acSAndroid Build Coastguard Worker
801*1c60b9acSAndroid Build Coastguard WorkerEach Secure Stream that is created then in turn creates a private Unix Domain
802*1c60b9acSAndroid Build Coastguard WorkerSocket connection to the proxy for each stream.
803*1c60b9acSAndroid Build Coastguard Worker
804*1c60b9acSAndroid Build Coastguard WorkerIn this case the proxy uses secure-streams.c and policy.c as before to fulfil
805*1c60b9acSAndroid Build Coastguard Workerthe inbound proxy streams, but uses secure-streams-serialize.c to serialize and
806*1c60b9acSAndroid Build Coastguard Workerdeserialize the proxied SS API activity.  The proxy clients define
807*1c60b9acSAndroid Build Coastguard WorkerLWS_SS_USE_SSPC either very early in their sources before the includes, or on
808*1c60b9acSAndroid Build Coastguard Workerthe compiler commandline... this causes the lws_ss_ apis to be replaced at
809*1c60b9acSAndroid Build Coastguard Workerpreprocessor time with lws_sspc_ equivalents.  These serialize the api action
810*1c60b9acSAndroid Build Coastguard Workerand pass it to the proxy over a Unix Domain Socket for fulfilment, the results
811*1c60b9acSAndroid Build Coastguard Workerand state changes etc are streamed over the Unix Domain Socket and presented to
812*1c60b9acSAndroid Build Coastguard Workerthe application exactly the same as if it was being fulfilled locally.
813*1c60b9acSAndroid Build Coastguard Worker
814*1c60b9acSAndroid Build Coastguard WorkerTo demonstrate this, some minimal examples, eg, minimal-secure-streams and
815*1c60b9acSAndroid Build Coastguard Workermimimal-secure-streams-avs build themselves both ways, once with direct SS API
816*1c60b9acSAndroid Build Coastguard Workerfulfilment and once with Unix Domain Socket proxying and -client appended on the
817*1c60b9acSAndroid Build Coastguard Workerexecutable name.  To test the -client variants, run minimal-secure-streams-proxy
818*1c60b9acSAndroid Build Coastguard Workeron the same machine.
819*1c60b9acSAndroid Build Coastguard Worker
820*1c60b9acSAndroid Build Coastguard Worker## Complicated scenarios with secure streams proxy
821*1c60b9acSAndroid Build Coastguard Worker
822*1c60b9acSAndroid Build Coastguard WorkerAs mentioned above, Secure Streams has two modes, by default the application
823*1c60b9acSAndroid Build Coastguard Workerdirectly parses the policy and makes the outgoing connections itself.
824*1c60b9acSAndroid Build Coastguard WorkerHowever when configured at cmake with
825*1c60b9acSAndroid Build Coastguard Worker
826*1c60b9acSAndroid Build Coastguard Worker```
827*1c60b9acSAndroid Build Coastguard Worker-DLWS_WITH_SOCKS5=1 -DLWS_WITH_SECURE_STREAMS=1 -DLWS_WITH_SECURE_STREAMS_PROXY_API=1 -DLWS_WITH_MINIMAL_EXAMPLES=1
828*1c60b9acSAndroid Build Coastguard Worker```
829*1c60b9acSAndroid Build Coastguard Worker
830*1c60b9acSAndroid Build Coastguard Workerand define `LWS_SS_USE_SSPC` when building the application, applications forward
831*1c60b9acSAndroid Build Coastguard Workertheir network requests to a local or remote SS proxy for fulfilment... and only
832*1c60b9acSAndroid Build Coastguard Workerthe SS proxy has the system policy.  By default, the SS proxy is on the local
833*1c60b9acSAndroid Build Coastguard Workermachine and is connected to via a Unix Domain Socket, but tcp links are also
834*1c60b9acSAndroid Build Coastguard Workerpossible.  (Note the proxied traffic is not encrypyed by default.)
835*1c60b9acSAndroid Build Coastguard Worker
836*1c60b9acSAndroid Build Coastguard WorkerUsing the configuration above, the example SS applications are built two ways,
837*1c60b9acSAndroid Build Coastguard Workeronce for direct connection fulfilment (eg, `./bin/lws-minimal-secure-streams`),
838*1c60b9acSAndroid Build Coastguard Workerand once with `LWS_SS_USE_SSPC` also defined so it connects via an SS proxy,
839*1c60b9acSAndroid Build Coastguard Worker(eg, `./bin/lws-minimal-secure-streams-client`).
840*1c60b9acSAndroid Build Coastguard Worker
841*1c60b9acSAndroid Build Coastguard Worker## Testing an example scenario with SS Proxy and socks5 proxy
842*1c60b9acSAndroid Build Coastguard Worker
843*1c60b9acSAndroid Build Coastguard Worker```
844*1c60b9acSAndroid Build Coastguard Worker [ SS application ] --- tcp --- [ socks 5 proxy ] --- tcp --- [ SS proxy ] --- internet
845*1c60b9acSAndroid Build Coastguard Worker```
846*1c60b9acSAndroid Build Coastguard Worker
847*1c60b9acSAndroid Build Coastguard WorkerIn this scenario, everything is on localhost, the socks5 proxy listens on :1337 and
848*1c60b9acSAndroid Build Coastguard Workerthe SS proxy listens on :1234.  The SS application connects to the socks5
849*1c60b9acSAndroid Build Coastguard Workerproxy to get to the SS proxy, which then goes out to the internet
850*1c60b9acSAndroid Build Coastguard Worker
851*1c60b9acSAndroid Build Coastguard Worker### 1 Start the SS proxy
852*1c60b9acSAndroid Build Coastguard Worker
853*1c60b9acSAndroid Build Coastguard WorkerTell it to listen on lo interface on port 1234
854*1c60b9acSAndroid Build Coastguard Worker
855*1c60b9acSAndroid Build Coastguard Worker```
856*1c60b9acSAndroid Build Coastguard Worker$ ./bin/lws-minimal-secure-streams-proxy -p 1234 -i lo
857*1c60b9acSAndroid Build Coastguard Worker```
858*1c60b9acSAndroid Build Coastguard Worker
859*1c60b9acSAndroid Build Coastguard Worker### 2 Start the SOCKS5 proxy
860*1c60b9acSAndroid Build Coastguard Worker
861*1c60b9acSAndroid Build Coastguard Worker```
862*1c60b9acSAndroid Build Coastguard Worker$ ssh -D 1337 -N -v localhost
863*1c60b9acSAndroid Build Coastguard Worker```
864*1c60b9acSAndroid Build Coastguard Worker
865*1c60b9acSAndroid Build Coastguard WorkerThe -v makes connections to the proxy visible in the terminal for testing
866*1c60b9acSAndroid Build Coastguard Worker
867*1c60b9acSAndroid Build Coastguard Worker### 3 Run the SS application
868*1c60b9acSAndroid Build Coastguard Worker
869*1c60b9acSAndroid Build Coastguard WorkerThe application is told to make all connections via the socks5 proxy at
870*1c60b9acSAndroid Build Coastguard Worker127.0.0.1:1337, and to fulfil its SS connections via an SS proxy, binding
871*1c60b9acSAndroid Build Coastguard Workerconnections to 127.0.0.1 (ipv4 lo interface, -1), to 127.0.0.1:1234 (-a/-p).
872*1c60b9acSAndroid Build Coastguard Worker
873*1c60b9acSAndroid Build Coastguard Worker```
874*1c60b9acSAndroid Build Coastguard Workersocks_proxy=127.0.0.1:1337 ./bin/lws-minimal-secure-streams-client -p 1234 -i 127.0.0.1 -a 127.0.0.1
875*1c60b9acSAndroid Build Coastguard Worker```
876*1c60b9acSAndroid Build Coastguard Worker
877*1c60b9acSAndroid Build Coastguard WorkerYou can confirm this goes through the ssh socks5 proxy to get to the SS proxy
878*1c60b9acSAndroid Build Coastguard Workerand fulfil the connection.
879*1c60b9acSAndroid Build Coastguard Worker
880*1c60b9acSAndroid Build Coastguard Worker## Using static policies
881*1c60b9acSAndroid Build Coastguard Worker
882*1c60b9acSAndroid Build Coastguard WorkerIf one of your targets is too constrained to make use of dynamic JSON policies, but
883*1c60b9acSAndroid Build Coastguard Workerusing SS and the policies is attractive for wider reasons, you can use a static policy
884*1c60b9acSAndroid Build Coastguard Workerbuilt into the firmware for the constrained target.
885*1c60b9acSAndroid Build Coastguard Worker
886*1c60b9acSAndroid Build Coastguard WorkerThe secure-streams example "policy2c" (which runs on the build machine, not the device)
887*1c60b9acSAndroid Build Coastguard Worker
888*1c60b9acSAndroid Build Coastguard Workerhttps://libwebsockets.org/git/libwebsockets/tree/minimal-examples/secure-streams/minimal-secure-streams-policy2c
889*1c60b9acSAndroid Build Coastguard Worker
890*1c60b9acSAndroid Build Coastguard Workeraccepts a normal JSON policy on stdin, and emits a C code representation that can be
891*1c60b9acSAndroid Build Coastguard Workerincluded directly in the firmware.
892*1c60b9acSAndroid Build Coastguard Worker
893*1c60b9acSAndroid Build Coastguard Workerhttps://libwebsockets.org/git/libwebsockets/tree/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/static-policy.h
894*1c60b9acSAndroid Build Coastguard Worker
895*1c60b9acSAndroid Build Coastguard WorkerUsing this technique it's possible to standardize on maintaining JSON policies across a
896*1c60b9acSAndroid Build Coastguard Workerrange of devices with different contraints, and use the C conversion of the policy on devices
897*1c60b9acSAndroid Build Coastguard Workerthat are too small.
898*1c60b9acSAndroid Build Coastguard Worker
899*1c60b9acSAndroid Build Coastguard WorkerThe Cmake option `LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY` should be enabled to use this
900*1c60b9acSAndroid Build Coastguard Workermode, it will not build the JSON parser (and the option for LEJP can also be disabled if
901*1c60b9acSAndroid Build Coastguard Workeryou're not otherwise using it, saving an additional couple of KB).
902*1c60b9acSAndroid Build Coastguard Worker
903*1c60b9acSAndroid Build Coastguard WorkerNotice policy2c example tool must be built with `LWS_ROLE_H1`, `LWS_ROLE_H2`, `LWS_ROLE_WS`
904*1c60b9acSAndroid Build Coastguard Workerand `LWS_ROLE_MQTT` enabled so it can handle any kind of policy.
905*1c60b9acSAndroid Build Coastguard Worker
906*1c60b9acSAndroid Build Coastguard Worker## HTTP and ws serving
907*1c60b9acSAndroid Build Coastguard Worker
908*1c60b9acSAndroid Build Coastguard WorkerAll ws servers start out as http servers... for that reason ws serving is
909*1c60b9acSAndroid Build Coastguard Workerhandled as part of http serving, if you give the `ws_subprotocol` entry to the
910*1c60b9acSAndroid Build Coastguard Workerstreamtype additionally, the server will also accept upgrades to ws.
911*1c60b9acSAndroid Build Coastguard Worker
912*1c60b9acSAndroid Build Coastguard WorkerTo help the user code understand if the upgrade occurred, there's a special
913*1c60b9acSAndroid Build Coastguard Workerstate `LWSSSCS_SERVER_UPGRADE`, so subsequent rx and tx can be understood to
914*1c60b9acSAndroid Build Coastguard Workerhave come from the upgraded protocol.  To allow separation of rx and tx
915*1c60b9acSAndroid Build Coastguard Workerhandling between http and ws, there's a ss api `lws_ss_change_handlers()`
916*1c60b9acSAndroid Build Coastguard Workerwhich allows dynamically setting SS handlers.
917*1c60b9acSAndroid Build Coastguard Worker
918*1c60b9acSAndroid Build Coastguard WorkerSince the http and ws upgrade identity is encapsulated in one streamtype, the
919*1c60b9acSAndroid Build Coastguard Workeruser object for the server streamtype should contain related user data for both
920*1c60b9acSAndroid Build Coastguard Workerhttp and ws underlying protocol identity.
921