1d4afb5ceSopenharmony_ci# lws minimal http server with tls 2d4afb5ceSopenharmony_ci 3d4afb5ceSopenharmony_ci## build 4d4afb5ceSopenharmony_ci 5d4afb5ceSopenharmony_ci``` 6d4afb5ceSopenharmony_ci $ cmake . && make 7d4afb5ceSopenharmony_ci``` 8d4afb5ceSopenharmony_ci 9d4afb5ceSopenharmony_ci## usage 10d4afb5ceSopenharmony_ci 11d4afb5ceSopenharmony_ci``` 12d4afb5ceSopenharmony_ci $ ./lws-minimal-http-server-tls 13d4afb5ceSopenharmony_ci[2018/03/20 13:23:13:0131] USER: LWS minimal http server TLS | visit https://localhost:7681 14d4afb5ceSopenharmony_ci[2018/03/20 13:23:13:0142] NOTICE: Creating Vhost 'default' port 7681, 1 protocols, IPv6 off 15d4afb5ceSopenharmony_ci[2018/03/20 13:23:13:0142] NOTICE: Using SSL mode 16d4afb5ceSopenharmony_ci[2018/03/20 13:23:13:0146] NOTICE: SSL ECDH curve 'prime256v1' 17d4afb5ceSopenharmony_ci[2018/03/20 13:23:13:0146] NOTICE: HTTP2 / ALPN enabled 18d4afb5ceSopenharmony_ci[2018/03/20 13:23:13:0195] NOTICE: lws_tls_client_create_vhost_context: doing cert filepath localhost-100y.cert 19d4afb5ceSopenharmony_ci[2018/03/20 13:23:13:0195] NOTICE: Loaded client cert localhost-100y.cert 20d4afb5ceSopenharmony_ci[2018/03/20 13:23:13:0195] NOTICE: lws_tls_client_create_vhost_context: doing private key filepath 21d4afb5ceSopenharmony_ci[2018/03/20 13:23:13:0196] NOTICE: Loaded client cert private key localhost-100y.key 22d4afb5ceSopenharmony_ci[2018/03/20 13:23:13:0196] NOTICE: created client ssl context for default 23d4afb5ceSopenharmony_ci[2018/03/20 13:23:14:0207] NOTICE: vhost default: cert expiry: 730459d 24d4afb5ceSopenharmony_ci``` 25d4afb5ceSopenharmony_ci 26d4afb5ceSopenharmony_ciVisit https://localhost:7681 27d4afb5ceSopenharmony_ci 28d4afb5ceSopenharmony_ciBecause it uses a selfsigned certificate, you will have to make an exception for it in your browser. 29d4afb5ceSopenharmony_ci 30d4afb5ceSopenharmony_ci## Certificate creation 31d4afb5ceSopenharmony_ci 32d4afb5ceSopenharmony_ciThe selfsigned certs provided were created with 33d4afb5ceSopenharmony_ci 34d4afb5ceSopenharmony_ci``` 35d4afb5ceSopenharmony_ciecho -e "GB\nErewhon\nAll around\nlibwebsockets-test\n\nlocalhost\nnone@invalid.org\n" | openssl req -new -newkey rsa:4096 -days 36500 -nodes -x509 -keyout "localhost-100y.key" -out "localhost-100y.cert" 36d4afb5ceSopenharmony_ci``` 37d4afb5ceSopenharmony_ci 38d4afb5ceSopenharmony_cithey cover "localhost" and last 100 years from 2018-03-20. 39d4afb5ceSopenharmony_ci 40d4afb5ceSopenharmony_ciYou can replace them with commercial certificates matching your hostname. 41d4afb5ceSopenharmony_ci 42d4afb5ceSopenharmony_ci## HTTP/2 43d4afb5ceSopenharmony_ci 44d4afb5ceSopenharmony_ciIf you built lws with `-DLWS_WITH_HTTP2=1` at cmake, this simple server is also http/2 capable 45d4afb5ceSopenharmony_ciout of the box. If the index.html was loaded over http/2, it will display an HTTP 2 png. 46