|
2 | 2 |
|
3 | 3 | This directory contains small example programs that show how HTTP can be used over SCION/QUIC for servers, proxies, and clients:
|
4 | 4 |
|
5 |
| -- fileserver: a server that serves the files from its working directory |
6 |
| -- proxy: a proxy server that can translate between HTTP and HTTP-over-SCION |
7 | 5 | - server: a server with friendly greetings and other examples
|
8 | 6 | - client: a client that talks to the example server
|
| 7 | +- fileserver: a server that serves the files from its working directory. |
| 8 | + This includes an example for serving both HTTP and HTTPS. |
| 9 | +- proxy: a proxy server that can translate between HTTP and HTTP-over-SCION |
9 | 10 |
|
10 | 11 | See also the package [shttp](../../pkg/shttp/README.md) for the underlaying library code.
|
11 | 12 |
|
12 | 13 | ## Build:
|
13 | 14 |
|
14 |
| -Clone the repository netsec-ethz/scion-apps and build the eaxample applications: |
15 |
| - |
16 | 15 | ```
|
17 |
| -git clone https://github.com/netsec-ethz/scion-apps.git |
18 |
| -cd scion-apps |
19 | 16 | make example-shttp-fileserver \
|
20 | 17 | example-shttp-proxy \
|
21 | 18 | example-shttp-server \
|
22 |
| - example-shttp-client |
| 19 | + example-shttp-client \ |
| 20 | + scion-bat |
23 | 21 | ```
|
24 | 22 |
|
25 | 23 | ## Running:
|
26 | 24 |
|
27 | 25 | All examples require a running SCION endhost stack, i.e. a running SCION dispatcher and SCION daemon. Please refer to '[Running](../../README.md#Running)' in this repository's main README and the [SCIONLab tutorials](https://docs.scionlab.org) to get started.
|
| 26 | +See '[Environment](../../README.md#Environment)' on how to set the dispatcher and sciond environment variables when e.g. running multiple local ASes. |
28 | 27 |
|
29 |
| -### Generic file server example |
| 28 | +### Simple server example |
30 | 29 |
|
31 |
| -Run `example-shttp-fileserver`: |
| 30 | +Open a shell in the root of the scion-apps repository and run the `example-shttp-server`: |
32 | 31 |
|
33 | 32 | ```
|
34 |
| -bin/example-shttp-fileserver |
| 33 | +bin/example-shttp-server |
35 | 34 | ```
|
36 | 35 |
|
37 |
| -See '[Environment](../../README.md#Environment)' on how to set the dispatcher and sciond environment variables in the server's AS. |
38 |
| - |
39 |
| -Build `scion-bat` as a client for `example-shttp-fileserver`: |
| 36 | +Open a new shell and run the custom `example-shttp-client` to interact with the `example-shttp-server`: |
40 | 37 |
|
41 | 38 | ```
|
42 |
| -make scion-bat |
| 39 | +bin/example-shttp-client -s 17-ffaa:1:a,127.0.0.1 |
43 | 40 | ```
|
| 41 | +Replace '17-ffaa:1:a' with your server's ISD and AS numbers. |
44 | 42 |
|
45 |
| -See also the application '[bat](../../bat/README.md)' for more details on the cURL-like CLI tool `scion-bat`. |
46 |
| - |
47 |
| -Access `example-shttp-fileserver` with `scion-bat`: |
| 43 | +Alternatively, we can also use the more generic command line HTTP client |
| 44 | +`scion-bat` to interact with the `example-shttp-server`. See also the |
| 45 | +application '[bat](../../bat/README.md)' for more details on the cURL-like CLI |
| 46 | +tool `scion-bat`. |
48 | 47 |
|
49 | 48 | ```
|
50 |
| -bin/scion-bat 17-ffaa:1:a,[127.0.0.1]:443/ |
| 49 | +bin/scion-bat 17-ffaa:1:a,127.0.0.1/hello |
| 50 | +bin/scion-bat 17-ffaa:1:a,127.0.0.1/json |
| 51 | +bin/scion-bat -f 17-ffaa:1:a,127.0.0.1/form foo=bar |
51 | 52 | ```
|
52 | 53 |
|
53 |
| -Replace '17-ffaa:1:a' with your server's ISD and AS numbers and see '[Environment](../../README.md#Environment)' on how to set the dispatcher and sciond environment variables in the client's (or proxy's) AS. |
| 54 | +### File server example |
54 | 55 |
|
55 |
| -Run `example-shttp-proxy` to provide `example-shttp-fileserver` functionality via HTTP: |
| 56 | +Run `example-shttp-fileserver`: |
56 | 57 |
|
57 | 58 | ```
|
58 |
| -bin/example-shttp-proxy --remote=17-ffaa:1:a,[127.0.0.1]:443 --local=0.0.0.0:8080 |
| 59 | +bin/example-shttp-fileserver |
59 | 60 | ```
|
60 | 61 |
|
61 |
| -Access `example-shttp-fileserver` via HTTP with `cURL`: |
| 62 | +Access `example-shttp-fileserver` with `scion-bat`: |
62 | 63 |
|
63 | 64 | ```
|
64 |
| -curl -v http://127.0.0.1:8080/ |
| 65 | +bin/scion-bat http://17-ffaa:1:a,127.0.0.1/ |
65 | 66 | ```
|
66 | 67 |
|
67 |
| -(Or navigate to http://127.0.0.1:8080/ in a web browser.) |
68 |
| - |
69 |
| -`example-shttp-proxy` can also be used as a proxy from SCION to HTTP, from SCION to SCION, and from HTTP to HTTP. See package [shttp](../../pkg/shttp/README.md) for more details. |
70 | 68 |
|
71 |
| -### Simple shttp-based server example |
| 69 | +### File server example with HTTPS |
72 | 70 |
|
73 |
| -Open a shell in the root of the scion-apps repository and run `example-shttp-server`: |
| 71 | +The file server optionally supports serving via HTTPS. |
| 72 | +For this, we need a **hostname** for the server, as a raw SCION address cannot |
| 73 | +(currently) be used as the subject of a TLS certificate. |
| 74 | +Then, we'll need to create a **key** and obtain a **certificate** for our server. |
| 75 | +We use a self signed certificate here and we cheat by installing the self |
| 76 | +signed certificate to the host's root CA list. |
74 | 77 |
|
75 | 78 | ```
|
76 |
| -cd _examples/shttp/server |
77 |
| -go run . |
| 79 | +# echo "1-ff00:0:111,[127.0.0.1] foo-server" >> /etc/scion/hosts |
| 80 | +$ mkdir certs; openssl req -newkey rsa:2048 -nodes -keyout certs/server.key -x509 -days 365 -subj '/CN=foo-server' -addext "subjectAltName = DNS:foo-server" -out certs/server.crt |
| 81 | +# cp -n certs/server.crt /etc/ssl/certs/ # for ubuntu/debian etc. |
78 | 82 | ```
|
79 | 83 |
|
80 |
| -Open a new shell in the scion-apps repository and access `example-shttp-server` with `scion-bat`: |
81 |
| - |
| 84 | +Then we provide the key/certs for the server at startup: |
82 | 85 | ```
|
83 |
| -bin/scion-bat 17-ffaa:1:a,[127.0.0.1]:443/hello |
| 86 | +bin/example-shttp-fileserver -cert certs/server.crt -key certs/server.key |
84 | 87 | ```
|
85 | 88 |
|
86 |
| -or |
87 |
| - |
| 89 | +And then access it with bat: |
88 | 90 | ```
|
89 |
| -bin/scion-bat 17-ffaa:1:a,[127.0.0.1]:443/json |
| 91 | +bin/scion-bat https://foo-server |
90 | 92 | ```
|
91 | 93 |
|
92 |
| -or |
| 94 | +Don't forget to remove `/etc/ssl/certs/server.crt` once you're done. |
93 | 95 |
|
94 |
| -``` |
95 |
| -bin/scion-bat -f 17-ffaa:1:a,[127.0.0.1]:443/form foo=bar |
96 |
| -``` |
| 96 | +**Note**: Instead of using a hostname and installing the certificate in the |
| 97 | +root CA store, we can also use `scion-bat`'s flag `-insecure=true`, to allow |
| 98 | +connections with unchecked certificates. But that's a bit boring, right? |
97 | 99 |
|
98 |
| -Run the custom `example-shttp-client` for `example-shttp-server`: |
99 | 100 |
|
100 |
| -``` |
101 |
| -bin/example-shttp-client -s 17-ffaa:1:a,[127.0.0.1]:443 |
102 |
| -``` |
| 101 | +### Proxy example: SCION server, TCP/IP client |
| 102 | + |
| 103 | +The `example-shttp-proxy` is a reverse proxy that can proxy requests on TCP/IP to a SCION web server, or vice versa. |
103 | 104 |
|
104 |
| -Run `example-shttp-proxy` to provide `bin/example-shttp-server` functionality via HTTP: |
| 105 | +Listen on TCP/IP port 8888 and proxy request to a SCION URL, e.g. start the `example-shttp-server` as described above and then |
105 | 106 |
|
106 | 107 | ```
|
107 |
| -bin/example-shttp-proxy --remote=17-ffaa:1:a,[127.0.0.1]:443 --local=0.0.0.0:8080 |
| 108 | +bin/example-shttp-proxy --port 8888 --remote=http://17-ffaa:1:a,127.0.0.1 |
108 | 109 | ```
|
109 | 110 |
|
110 |
| -Access `example-shttp-server` via HTTP with `cURL`: |
| 111 | +Now we can access `example-shttp-server` via TCP/IP with `cURL`: |
111 | 112 |
|
112 | 113 | ```
|
113 |
| -curl http://127.0.0.1:8080/hello |
| 114 | +curl -sfS http://127.0.0.1:8888/hello |
| 115 | +curl -sfS http://127.0.0.1:8888/json |
| 116 | +curl -sfS -d foo=bar http://127.0.0.1:8888/form |
114 | 117 | ```
|
115 | 118 |
|
116 |
| -or |
| 119 | +And, finally, to see the cute dog picture: |
| 120 | + |
| 121 | +Navigate to http://127.0.0.1:8888/image in a web browser. |
| 122 | + |
| 123 | +### Proxy example: TCP/IP server, SCION client |
| 124 | + |
| 125 | +Listen on SCION port 8888 and proxy request to TCP/IP URL, e.g. https://www.scionlab.org |
117 | 126 |
|
118 | 127 | ```
|
119 |
| -curl http://127.0.0.1:8080/json |
| 128 | +bin/example-shttp-proxy --listen-scion --port 8888 --remote=https://www.scionlab.org |
120 | 129 | ```
|
121 | 130 |
|
122 |
| -or |
| 131 | +Now we can access www.scionlab.org via SCION with `scion-bat` (note the `Host:www.scionlab.org` directive, alternatively we could add a corresponding hostname entry in the hosts file). |
123 | 132 |
|
124 | 133 | ```
|
125 |
| -curl -d foo=bar http://127.0.0.1:8080/form |
| 134 | +bin/scion-bat http://17-ffaa:1:a,127.0.0.1:8888/ Host:www.scionlab.org |
126 | 135 | ```
|
127 | 136 |
|
128 |
| -And, finally, to see the cute dog picture: |
| 137 | +or alternatively |
129 | 138 |
|
130 |
| -Navigate to http://127.0.0.1:8080/image in a web browser. |
| 139 | +``` |
| 140 | +bin/scion-bat --proxy http://17-ffaa:1:a,127.0.0.1:8888/ http://www.scionlab.org |
| 141 | +``` |
0 commit comments