1 /*
2  * lws-minimal-secure-streams-avs
3  *
4  * Written in 2019-2020 by Andy Green <andy@warmcat.com>
5  *
6  * This file is made available under the Creative Commons CC0 1.0
7  * Universal Public Domain Dedication.
8  */
9 
10 #include <libwebsockets.h>
11 #include <string.h>
12 #include <signal.h>
13 
14 extern int
15 avs_example_start(struct lws_context *context);
16 
17 int interrupted, bad = 1;
18 static lws_state_notify_link_t nl;
19 static const char * const default_ss_policy =
20 	"{"
21 	  "\"release\":"			"\"01234567\","
22 	  "\"product\":"			"\"myproduct\","
23 	  "\"schema-version\":"			"1,"
24 //	  "\"via-socks5\":"                     "\"127.0.0.1:1080\","
25 	  "\"retry\": ["	/* named backoff / retry strategies */
26 		"{\"default\": {"
27 			"\"backoff\": ["	 "1000,"
28 						 "2000,"
29 						 "3000,"
30 						 "5000,"
31 						"10000"
32 				"],"
33 			"\"conceal\":"		"5,"
34 			"\"jitterpc\":"		"20,"
35 			"\"svalidping\":"	"60,"
36 			"\"svalidhup\":"	"64"
37 		"}}"
38 	  "],"
39 	  "\"certs\": [" /* named individual certificates in BASE64 DER */
40 		"{\"digicert_global_root_g2\": \"" /* api.amazon.com 2038-01 */
41 	"MIIDjjCCAnagAwIBAgIQAzrx5qcRqaC7KGSxHQn65TANBgkqhkiG9w0BAQsFADBh"
42 	"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3"
43 	"d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH"
44 	"MjAeFw0xMzA4MDExMjAwMDBaFw0zODAxMTUxMjAwMDBaMGExCzAJBgNVBAYTAlVT"
45 	"MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j"
46 	"b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IEcyMIIBIjANBgkqhkiG"
47 	"9w0BAQEFAAOCAQ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w"
130 	"DQYJKoZIhvcNAQEFBQADggEBAAWdP4id0ckaVaGsafPzWdqbAYcaT1epoXkJKtv3"
131 	"L7IezMdeatiDh6GX70k1PncGQVhiv45YuApnP+yz3SFmH8lU+nLMPUxA2IGvd56D"
132 	"eruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJl"
133 	"xy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynp"
134 	"VSJYACPq4xJDKVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEY"
135 	"WQPJIrSPnNVeKtelttQKbfi3QBFGmh95DmK/D5fs4C8fF5Q="
136 		"\"}"
137 	  "],"
138 	  "\"trust_stores\": [" /* named cert chains */
139 		"{"  /* chain for alexa.na.gateway.devices.a2z.com */
140 			"\"name\": \"avs_via_starfield\","
141 			"\"stack\": ["
142 				"\"starfield_class_2_ca\","
143 				"\"starfield_services_root_ca\""
144 			"]"
145 		"},"
146 		"{" /* chain for api.amazon.com */
147 			"\"name\": \"api_amazon_com\","
148 			"\"stack\": ["
149 				"\"digicert_global_ca_g2\","
150 				"\"digicert_global_root_g2\""
151 			"]"
152 		"}"
153 	  "],"
154 	  "\"s\": [" /* the supported stream types */
155 		"{\"api_amazon_com_auth\": {"
156 			"\"endpoint\":"			"\"api.amazon.com\","
157 			"\"port\":"			"443,"
158 			"\"protocol\":"			"\"h1\","
159 			"\"http_method\":"		"\"POST\","
160 			"\"http_url\":"			"\"auth/o2/token\","
161 			"\"plugins\":"			"[],"
162 			"\"opportunistic\":"		"true,"
163 			"\"tls\":"			"true,"
164 			"\"h2q_oflow_txcr\":"		"true,"
165 			"\"http_www_form_urlencoded\":"	"true,"
166 			"\"http_no_content_length\":"	"true,"
167 			"\"retry\":"			"\"default\","
168 			"\"tls_trust_store\":"		"\"api_amazon_com\""
169 		"}},"
170 		"{\"avs_event\": {"
171 			"\"endpoint\":"			"\"alexa.na.gateway.devices.a2z.com\","
172 			"\"port\":"			"443,"
173 			"\"protocol\":"			"\"h2\","
174 			"\"http_method\":"		"\"GET\","
175 			"\"http_url\":"			"\"v20160207/directives\","
176 			"\"h2q_oflow_txcr\":"		"true,"
177 			"\"http_auth_header\":"		"\"authorization:\","
178 			"\"http_auth_preamble\":"	"\"Bearer \","
179 			"\"nailed_up\":"		"true,"
180 			"\"long_poll\":"		"true,"
181 			"\"retry\":"			"\"default\","
182 			"\"plugins\":"			"[],"
183 			"\"tls\":"			"true,"
184 			"\"tls_trust_store\":"		"\"avs_via_starfield\""
185 		"}},"
186 		"{\"avs_metadata\": {"
187 			"\"endpoint\":"			"\"alexa.na.gateway.devices.a2z.com\","
188 			"\"port\":"			"443,"
189 			"\"protocol\":"			"\"h2\","
190 			"\"http_method\":"		"\"POST\","
191 			"\"http_url\":"			"\"v20160207/events\","
192 			"\"http_no_content_length\":"	"true,"
193 			"\"h2q_oflow_txcr\":"		"true,"
194 			"\"http_auth_header\":"		"\"authorization:\","
195 			"\"http_auth_preamble\":"	"\"Bearer \","
196 			"\"http_multipart_name\":"	"\"metadata\","
197 			"\"http_mime_content_type\":"	"\"application/json; charset=UTF-8\","
198 			"\"rideshare\":"		"\"avs_audio\","
199 			"\"retry\":"			"\"default\","
200 			"\"plugins\":"			"[],"
201 			"\"tls\":"			"true,"
202 			"\"tls_trust_store\":"		"\"avs_via_starfield\""
203 		"}},"
204 		"{\"avs_audio\": {"
205 			"\"endpoint\":"			"\"alexa.na.gateway.devices.a2z.com\","
206 			"\"port\":"			"443,"
207 			"\"protocol\":"			"\"h2\","
208 			"\"http_method\":"		"\"POST\","
209 			"\"http_url\":"			"\"v20160207/events\","
210 			"\"http_no_content_length\":"	"true,"
211 			"\"plugins\":"			"[],"
212 			"\"tls\":"			"true,"
213 			"\"h2q_oflow_txcr\":"		"true,"
214 			"\"http_auth_header\":"		"\"authorization:\","
215 			"\"http_auth_preamble\":"	"\"Bearer \","
216 			"\"http_multipart_name\":"	"\"audio\","
217 			"\"http_mime_content_type\":"	"\"application/octet-stream\","
218 			"\"retry\":"			"\"default\","
219 			"\"tls_trust_store\":"		"\"avs_via_starfield\""
220 		"}}"
221 	  "]"
222 	"}"
223 ;
224 
225 static const char *canned_root_token_payload =
226 	"grant_type=refresh_token"
227 	"&refresh_token=Atzr|IwEBIJedGXjDqsU_vMxykqOMg"
228 	"SHfYe3CPcedueWEMWSDMaDnEmiW8RlR1Kns7Cb4B-TOSnqp7ifVsY4BMY2B8tpHfO39XP"
229 	"zfu9HapGjTR458IyHX44FE71pWJkGZ79uVBpljP4sazJuk8XS3Oe_yLnm_DIO6fU1nU3Y"
230 	"0flYmsOiOAQE_gRk_pdlmEtHnpMA-9rLw3mkY5L89Ty9kUygBsiFaYatouROhbsTn8-jW"
231 	"k1zZLUDpT6ICtBXSnrCIg0pUbZevPFhTwdXd6eX-u4rq0W-XaDvPWFO7au-iPb4Zk5eZE"
232 	"iX6sissYrtNmuEXc2uHu7MnQO1hHCaTdIO2CANVumf-PHSD8xseamyh04sLV5JgFzY45S"
233 	"KvKMajiUZuLkMokOx86rjC2Hdkx5DO7G-dbG1ufBDG-N79pFMSs7Ck5pc283IdLoJkCQc"
234 	"AGvTX8o8I29QqkcGou-9TKhOJmpX8As94T61ok0UqqEKPJ7RhfQHHYdCtsdwxgvfVr9qI"
235 	"xL_hDCcTho8opCVX-6QhJHl6SQFlTw13"
236 	"&client_id="
237 		"amzn1.application-oa2-client.4823334c434b4190a2b5a42c07938a2d";
238 
239 static int
app_system_state_nf(lws_state_manager_t * mgr,lws_state_notify_link_t * link,int current,int target)240 app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link,
241 		    int current, int target)
242 {
243 	struct lws_context *context = lws_system_context_from_system_mgr(mgr);
244 	lws_system_blob_t *ab = lws_system_get_blob(context,
245 				LWS_SYSBLOB_TYPE_AUTH, 1 /* AUTH_IDX_ROOT */);
246 	size_t size;
247 
248 	/*
249 	 * For the things we care about, let's notice if we are trying to get
250 	 * past them when we haven't solved them yet, and make the system
251 	 * state wait while we trigger the dependent action.
252 	 */
253 	switch (target) {
254 	case LWS_SYSTATE_REGISTERED:
255 		size = lws_system_blob_get_size(ab);
256 		if (size)
257 			break;
258 
259 		/* let's register our canned root token so auth can use it */
260 		lws_system_blob_direct_set(ab,
261 				(const uint8_t *)canned_root_token_payload,
262 				strlen(canned_root_token_payload));
263 		break;
264 	case LWS_SYSTATE_OPERATIONAL:
265 		if (current == LWS_SYSTATE_OPERATIONAL)
266 			avs_example_start(context);
267 		break;
268 	case LWS_SYSTATE_POLICY_INVALID:
269 		/*
270 		 * This is a NOP since we used direct set... but in a real
271 		 * system this could easily change to be done on the heap, then
272 		 * this would be important
273 		 */
274 		lws_system_blob_destroy(lws_system_get_blob(context,
275 					LWS_SYSBLOB_TYPE_AUTH,
276 					1 /* AUTH_IDX_ROOT */));
277 		break;
278 	}
279 
280 	return 0;
281 }
282 
283 static void
sigint_handler(int sig)284 sigint_handler(int sig)
285 {
286 	interrupted = 1;
287 }
288 
289 static lws_state_notify_link_t * const app_notifier_list[] = {
290 	&nl, NULL
291 };
292 
main(int argc,const char ** argv)293 int main(int argc, const char **argv)
294 {
295 	struct lws_context_creation_info info;
296 	struct lws_context *context;
297 	int n = 0;
298 
299 	signal(SIGINT, sigint_handler);
300 	memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */
301 	lws_cmdline_option_handle_builtin(argc, argv, &info);
302 
303 	lwsl_user("LWS secure streams - AVS test [-d<verb>]\n");
304 
305 	info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS |
306 		       LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
307 	info.fd_limit_per_thread = 1 + 6 + 1;
308 	info.pss_policies_json = default_ss_policy;
309 	info.port = CONTEXT_PORT_NO_LISTEN;
310 
311 #if defined(LWS_SS_USE_SSPC)
312 	{
313 		const char *p;
314 
315 		/* connect to ssproxy via UDS by default, else via
316 		 * tcp connection to this port */
317 		if ((p = lws_cmdline_option(argc, argv, "-p")))
318 			info.ss_proxy_port = atoi(p);
319 
320 		/* UDS "proxy.ss.lws" in abstract namespace, else this socket
321 		 * path; when -p given this can specify the network interface
322 		 * to bind to */
323 		if ((p = lws_cmdline_option(argc, argv, "-i")))
324 			info.ss_proxy_bind = p;
325 
326 		/* if -p given, -a specifies the proxy address to connect to */
327 		if ((p = lws_cmdline_option(argc, argv, "-a")))
328 			info.ss_proxy_address = p;
329 	}
330 #endif
331 
332 #if defined(LWS_WITH_DETAILED_LATENCY)
333 	info.detailed_latency_cb = lws_det_lat_plot_cb;
334 	info.detailed_latency_filepath = "/tmp/lws-latency-ssproxy";
335 #endif
336 
337 	/* integrate us with lws system state management when context created */
338 	nl.name = "app";
339 	nl.notify_cb = app_system_state_nf;
340 	info.register_notifier_list = app_notifier_list;
341 
342 	context = lws_create_context(&info);
343 	if (!context) {
344 		lwsl_err("lws init failed\n");
345 		return 1;
346 	}
347 
348 	/* the event loop */
349 
350 	while (n >= 0 && !interrupted)
351 		n = lws_service(context, 0);
352 
353 	lws_context_destroy(context);
354 	lwsl_user("Completed: %s\n", bad ? "failed" : "OK");
355 
356 	return bad;
357 }
358