libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-secure-streams-policy.h
Go to the documentation of this file.
1/*
2 * libwebsockets - small server side websockets and web server implementation
3 *
4 * Copyright (C) 2019 - 2021 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 *
24 * included from libwebsockets.h
25 */
26
27typedef int (*plugin_auth_status_cb)(struct lws_ss_handle *ss, int status);
28
53
54/* the public, const metrics policy definition */
55
56typedef struct lws_metric_policy {
57 /* order of first two mandated by JSON policy parsing scope union */
58 const struct lws_metric_policy *next;
59 const char *name;
60
61 const char *report;
62
64 uint64_t us_schedule;
66
72
73typedef struct lws_ss_x509 {
75 const char *vhost_name;
76 const uint8_t *ca_der;
77 size_t ca_der_len;
80
81enum {
90 LWSSSPOLF_TLS = (1 << 4),
120 LWSSSPOLF_SERVER = (1 << 15),
126
135 LWSSSPOLF_PERF = (1 << 22),
143
144};
145
153
154enum {
161
162
167
168 _LWSSS_HBI_COUNT /* always last */
169};
170
171/*
172 * This does for both the static policy metadata entry, and the runtime metadata
173 * handling object.
174 */
175
176typedef struct lws_ss_metadata {
178 const char *name;
180 size_t length;
181
182 uint8_t value_length; /* only valid if set by policy */
183 uint8_t value_is_http_token; /* valid if set by policy */
184#if defined(LWS_WITH_SS_DIRECT_PROTOCOL_STR)
185 uint8_t name_on_lws_heap:1; /* proxy metatadata does this */
186#endif
187 uint8_t value_on_lws_heap:1; /* proxy + rx metadata does this */
188#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)
189 uint8_t pending_onward:1;
190#endif
192
193typedef struct lws_ss_http_respmap {
194 uint16_t resp; /* the http response code */
195 uint16_t state; /* low 16-bits of associated state */
197
198/*
199 * This is a mapping between an auth streamtype and a name and other information
200 * that can be independently instantiated. Other streamtypes can indicate they
201 * require this authentication on their connection.
202 */
203
204typedef struct lws_ss_auth {
206 const char *name;
207
208 const char *type;
209 const char *streamtype;
212
226typedef struct lws_ss_policy {
228 const char *streamtype;
229
230 const char *endpoint;
234 const char *payload_fmt;
235 const char *socks5_proxy;
236 lws_ss_metadata_t *metadata; /* linked-list of metadata */
237 const lws_metric_policy_t *metrics; /* linked-list of metric policies */
238 const lws_ss_auth_t *auth; /* NULL or auth object we bind to */
239
240#if defined(LWS_WITH_SERVER)
241 const struct lws_protocol_vhost_options *pvo;
242#endif
243
244 /* protocol-specific connection policy details */
245
246 union {
247
248#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) || defined(LWS_ROLE_WS) || defined(LWS_ROLE_H3)
249
250 /* details for http-related protocols... */
251
252 struct {
253
254 /* common to all http-related protocols */
255
256 const char *method;
257 const char *url;
258
259 const char *multipart_name;
260 const char *multipart_filename;
261 const char *multipart_content_type;
262
263 const char *blob_header[_LWSSS_HBI_COUNT];
264 const char *auth_preamble;
265
266 const lws_ss_http_respmap_t *respmap;
267
268 union {
269// struct { /* LWSSSP_H1 */
270// } h1;
271// struct { /* LWSSSP_H2 */
272// } h2;
273// struct { /* LWSSSP_H3 */
274// } h3;
275 struct { /* LWSSSP_WS */
276 const char *subprotocol;
277 uint8_t binary;
278 /* false = TEXT, true = BINARY */
279 } ws;
280 } u;
281
282 uint16_t resp_expect;
283 uint8_t count_respmap;
284 uint8_t fail_redirect:1;
285 } http;
286
287#endif
288
289#if defined(LWS_ROLE_MQTT)
290
291 struct {
292 const char *topic; /* stream sends on this topic */
293 const char *subscribe; /* stream subscribes to this topic */
294
295 const char *will_topic;
296 const char *will_message;
297
298 const char *birth_topic;
299 const char *birth_message;
300
301 uint16_t keep_alive;
302 uint8_t qos;
303 uint8_t clean_start;
304 uint8_t will_qos;
305 uint8_t will_retain;
306 uint8_t birth_qos;
307 uint8_t birth_retain;
308 uint8_t aws_iot;
309 uint8_t retain;
310
311 } mqtt;
312
313#endif
314
315 /* details for non-http related protocols... */
316 } u;
317
318#if defined(LWS_WITH_SECURE_STREAMS_AUTH_SIGV4)
319 /* directly point to the metadata name, no need to expand */
320 const char *aws_region;
321 const char *aws_service;
322#endif
323 /*
324 * We're either a client connection policy that wants a trust store,
325 * or we're a server policy that wants a mem cert and key... Hold
326 * these mutually-exclusive things in a union.
327 */
328
329 union {
333 struct {
334 const lws_ss_x509_t *cert;
336 const lws_ss_x509_t *key;
338 } server;
340
342
343 int32_t txc;
344 int32_t txc_peer;
345
349
353
357
359
364 uint8_t priority; /* 0 = normal, 6 = max normal,
365 * 7 = network management */
367
368#if !defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY)
369
370/*
371 * These only exist / have meaning if there's a dynamic JSON policy enabled
372 */
373
375lws_ss_policy_parse_begin(struct lws_context *context, int overlay);
376
378lws_ss_policy_parse_abandon(struct lws_context *context);
379
381lws_ss_policy_parse(struct lws_context *context, const uint8_t *buf, size_t len);
382
384lws_ss_policy_overlay(struct lws_context *context, const char *overlay);
385
386/*
387 * You almost certainly don't want these, they return the first policy or auth
388 * object in a linked-list of objects created by lws_ss_policy_parse above,
389 * they are exported to generate static policy with
390 */
392lws_ss_policy_get(struct lws_context *context);
393
395lws_ss_auth_get(struct lws_context *context);
396
397#endif
unsigned short uint16_t
unsigned int uint32_t
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_VISIBLE
struct lws_retry_bo lws_retry_bo_t
struct lws_ss_x509 * next
struct lws_ss_metadata * next
struct lws_ss_http_respmap lws_ss_http_respmap_t
LWS_VISIBLE LWS_EXTERN int lws_ss_policy_overlay(struct lws_context *context, const char *overlay)
const lws_ss_x509_t * ssx509[6]
struct lws_ss_policy lws_ss_policy_t
struct lws_ss_trust_store * next
LWS_VISIBLE LWS_EXTERN int lws_ss_policy_parse_abandon(struct lws_context *context)
struct lws_ss_trust_store lws_ss_trust_store_t
struct lws_ss_x509 lws_ss_x509_t
struct lws_ss_auth * next
LWS_VISIBLE LWS_EXTERN const lws_ss_auth_t * lws_ss_auth_get(struct lws_context *context)
struct lws_ss_auth lws_ss_auth_t
LWS_VISIBLE LWS_EXTERN int lws_ss_policy_parse_begin(struct lws_context *context, int overlay)
@ LWSSSPOLF_HTTP_CACHE_COOKIES
@ LWSSSPOLF_OPPORTUNISTIC
@ LWSSSPOLF_ATTR_HIGH_RELIABILITY
@ LWSSSPOLF_H2_QUIRK_UNCLEAN_HPACK_STATE
@ LWSSSPOLF_WAKE_SUSPEND__VALIDITY
@ LWSSSPOLF_ALLOW_REDIRECTS
@ LWSSSPOLF_ATTR_LOW_LATENCY
@ LWSSSPOLF_AUTH_BEARER
@ LWSSSPOLF_QUIRK_NGHTTP2_END_STREAM
@ LWSSSPOLF_HTTP_MULTIPART_IN
@ LWSSSPOLF_ATTR_LOW_COST
@ LWSSSPOLF_HTTP_X_WWW_FORM_URLENCODED
@ LWSSSPOLF_HTTP_NO_CONTENT_LENGTH
@ LWSSSPOLF_HTTP_MULTIPART
@ LWSSSPOLF_PRIORITIZE_READS
@ LWSSSPOLF_DIRECT_PROTO_STR
@ LWSSSPOLF_H2_QUIRK_OVERFLOWS_TXCR
@ LWSSSPOLF_ATTR_HIGH_THROUGHPUT
int(* plugin_auth_status_cb)(struct lws_ss_handle *ss, int status)
struct lws_ss_metadata lws_ss_metadata_t
LWS_VISIBLE LWS_EXTERN const lws_ss_policy_t * lws_ss_policy_get(struct lws_context *context)
const uint8_t * ca_der
struct lws_metric_policy lws_metric_policy_t
LWS_VISIBLE LWS_EXTERN int lws_ss_policy_parse(struct lws_context *context, const uint8_t *buf, size_t len)
const struct lws_metric_policy * next
union lws_ss_policy::@205263316062375117242051172104141270333353025223 trust
const lws_metric_policy_t * metrics
struct lws_ss_policy::@205263316062375117242051172104141270333353025223::@037206204201040131127176122057330076272260301040 server
lws_ss_metadata_t * metadata
const lws_ss_trust_store_t * store
const char * rideshare_streamtype
const lws_retry_bo_t * retry_bo
const lws_ss_auth_t * auth
struct lws_ss_policy * next
union lws_ss_policy::@240225143042301163031025331247104245060336112111 u