Add HTTPS file server Demo

The demo shows how to run the unmodified HTTPS file server with Occlum.
This commit is contained in:
LI Qing 2019-09-24 06:35:08 +00:00 committed by Tate, Hongliang Tian
parent 5f26bfc1fb
commit ba6b4cc028
5 changed files with 91 additions and 0 deletions

5
demo/https_server/.gitignore vendored Normal file

@ -0,0 +1,5 @@
mongoose_src/
deps/
occlum_workspace/
simplest_web_server_ssl
server.*

@ -0,0 +1,27 @@
# Use Mongoose HTTPS file server with Occlum
This project demonstrates how to run a HTTPS file server with [Mongoose Embedded Web Server Library](https://github.com/cesanta/mongoose).
Step 1: Download and build Mongoose and OpenSSL, then build the sample HTTPS file server shipped with Mongoose's source code
```
./download_and_build_mongoose.sh
```
When completed, the resulting file server can be found at `./mongoose_src/examples/simplest_web_server_ssl/simplest_web_server_ssl`.
Step 2: You can run the HTTPS file server either on Occlum
```
./run_https_server_in_occlum.sh
```
or on Linux
```
./run_https_server_in_linux.sh
```
The HTTPS file server should now start to listen on port 8443 and serve HTTPS requests.
Step 3: To check whether the HTTPS server works, run
```
curl -k https://127.0.0.1:8443
```
in another terminal.
It is also possible to access the HTTPS server directly in a Web browser. But if you are testing in a Docker container, you won't be able to open the URL `https://127.0.0.1:8443` in a browser on the host OS. To fix this, you have to manually map port 8843 of the Docker container to a port on the host OS. Check out how to use [the `-p` argument of `docker run` command](https://docs.docker.com/engine/reference/commandline/run/).

@ -0,0 +1,29 @@
#!/bin/bash
set -e
# 1. Download and install OpenSSL 1.1.1
mkdir -p deps/openssl
pushd deps/openssl
git clone https://github.com/openssl/openssl .
git checkout tags/OpenSSL_1_1_1 -b OpenSSL_1_1_1
CC=occlum-gcc ./config \
--prefix=/usr/local/occlum/x86_64-linux-musl \
--openssldir=/usr/local/occlum/ssl \
--with-rand-seed=rdcpu \
no-zlib no-async no-tests \
-fPIC -pie
make -j
sudo make install
popd
# 2. Download Mongoose 6.15
mkdir -p mongoose_src
pushd mongoose_src
git clone https://github.com/cesanta/mongoose .
git checkout tags/6.15 -b 6.15
popd
# 3. Build the https server example in mongoose
pushd mongoose_src/examples/simplest_web_server_ssl
CC=occlum-gcc CFLAGS_EXTRA="-Wno-format-truncation -fPIC -pie" make
popd

@ -0,0 +1,11 @@
#!/bin/bash
export LD_LIBRARY_PATH=/usr/local/occlum/x86_64-linux-musl/lib:$LD_LIBRARY_PATH
https_server=simplest_web_server_ssl
set -e
# 1. Copy files
cp -f mongoose_src/examples/simplest_web_server_ssl/$https_server .
cp -rf mongoose_src/examples/simplest_web_server_ssl/server.* .
# 2. Run https_server
./$https_server

@ -0,0 +1,19 @@
#!/bin/bash
https_server=simplest_web_server_ssl
set -e
# 1. Init Occlum Workspace
rm -rf occlum_workspace
mkdir occlum_workspace
cd occlum_workspace
occlum init
# 2. Copy files into Occlum Workspace and Build
cp ../mongoose_src/examples/simplest_web_server_ssl/$https_server image/bin
cp -r ../mongoose_src/examples/simplest_web_server_ssl/server.* image
cp /usr/local/occlum/x86_64-linux-musl/lib/libssl.so.1.1 image/lib
cp /usr/local/occlum/x86_64-linux-musl/lib/libcrypto.so.1.1 image/lib
occlum build
# 3. Run https_server
occlum run /bin/$https_server