Blame


1 b9220ca4 2021-01-11 op # gmid
2 3e4749f7 2020-10-02 op
3 b9231167 2021-02-08 op gmid is a fast Gemini server written with security in mind. I
4 b9231167 2021-02-08 op initially wrote it to serve static files, but it has grown into a
5 747b35d0 2021-02-08 op featureful server.
6 3e4749f7 2020-10-02 op
7 3e4749f7 2020-10-02 op
8 b9220ca4 2021-01-11 op ## Features
9 3e4749f7 2020-10-02 op
10 601bc1cc 2021-01-30 op (random order)
11 601bc1cc 2021-01-30 op
12 747b35d0 2021-02-08 op - reconfiguration: reload the running configuration without
13 747b35d0 2021-02-08 op interruption
14 86edc4f4 2021-02-04 op - sandboxed by default on OpenBSD, Linux and FreeBSD
15 290b5baa 2021-02-23 op - automatic redirect/error pages (see `block return`)
16 4d2ec6d7 2021-01-13 op - IRI support (RFC3987)
17 286c4f40 2021-01-27 op - punycode support
18 601bc1cc 2021-01-30 op - dual stack (IPv4 and IPv6)
19 601bc1cc 2021-01-30 op - automatic certificate generation for config-less mode
20 b9220ca4 2021-01-11 op - CGI scripts
21 290b5baa 2021-02-23 op - low memory footprint
22 b9231167 2021-02-08 op - event-based asynchronous I/O model
23 b9220ca4 2021-01-11 op - small codebase, easily hackable
24 b9220ca4 2021-01-11 op - virtual hosts
25 286c4f40 2021-01-27 op - per-location rules
26 286c4f40 2021-01-27 op - optional directory listings
27 286c4f40 2021-01-27 op - configurable mime types
28 0b00962d 2021-01-25 op - chroot support
29 3e4749f7 2020-10-02 op
30 fab952e1 2020-10-03 op
31 286c4f40 2021-01-27 op ## Internationalisation (IRIs, UNICODE, punycode, all that stuff)
32 286c4f40 2021-01-27 op
33 286c4f40 2021-01-27 op Even thought the current Gemini specification doesn't mention anything
34 601bc1cc 2021-01-30 op in this regard, I do think these are important things and so I tried
35 601bc1cc 2021-01-30 op to implement them in the most user-friendly way I could think of.
36 286c4f40 2021-01-27 op
37 601bc1cc 2021-01-30 op For starters, gmid has full support for IRI (RFC3987 —
38 22a742e4 2021-01-29 op Internationalized Resource Identifiers). IRIs are a superset of URIs,
39 286c4f40 2021-01-27 op so there aren't incompatibilities with URI-only clients.
40 286c4f40 2021-01-27 op
41 601bc1cc 2021-01-30 op There is full support also for punycode. In theory, the user doesn't
42 286c4f40 2021-01-27 op even need to know that punycode is a thing. The hostname in the
43 601bc1cc 2021-01-30 op configuration file can (and must be) in the decoded form (e.g. `naïve`
44 601bc1cc 2021-01-30 op and not `xn--nave-6pa`), gmid will do the rest.
45 286c4f40 2021-01-27 op
46 601bc1cc 2021-01-30 op The only missing piece is UNICODE normalisation of the IRI path: gmid
47 601bc1cc 2021-01-30 op doesn't do that (yet).
48 286c4f40 2021-01-27 op
49 286c4f40 2021-01-27 op
50 1487e11e 2021-02-06 op ## Configuration
51 1487e11e 2021-02-06 op
52 1487e11e 2021-02-06 op gmid has a rich configuration file, heavily inspired by OpenBSD'
53 1487e11e 2021-02-06 op httpd. While you should definitely check the manpage because it
54 290b5baa 2021-02-23 op documents every option in depth, here's a small example of how a
55 290b5baa 2021-02-23 op configuration file looks like.
56 1487e11e 2021-02-06 op
57 1487e11e 2021-02-06 op ```conf
58 1487e11e 2021-02-06 op ipv6 on # enable ipv6
59 1487e11e 2021-02-06 op
60 1487e11e 2021-02-06 op server "example.com" {
61 1487e11e 2021-02-06 op cert "/path/to/cert.pem"
62 1487e11e 2021-02-06 op key "/path/to/key.pem"
63 1487e11e 2021-02-06 op root "/var/gemini/example.com"
64 1487e11e 2021-02-06 op lang "it"
65 1487e11e 2021-02-06 op cgi "/cgi/*"
66 1487e11e 2021-02-06 op
67 1487e11e 2021-02-06 op location "/files/*" {
68 1487e11e 2021-02-06 op auto index on
69 1487e11e 2021-02-06 op }
70 1487e11e 2021-02-06 op
71 1487e11e 2021-02-06 op location "/repo/*" {
72 1487e11e 2021-02-06 op # change the index file name
73 1487e11e 2021-02-06 op index "README.gmi"
74 1487e11e 2021-02-06 op }
75 1487e11e 2021-02-06 op }
76 1487e11e 2021-02-06 op ```
77 1487e11e 2021-02-06 op
78 1487e11e 2021-02-06 op
79 b9220ca4 2021-01-11 op ## Building
80 3e4749f7 2020-10-02 op
81 b9231167 2021-02-08 op gmid depends on a POSIX libc, libevent2, OpenSSL/LibreSSL and libtls
82 b9231167 2021-02-08 op (provided either by LibreSSL or libretls). At build time, flex and
83 b9231167 2021-02-08 op yacc (or GNU bison) are also needed.
84 3e4749f7 2020-10-02 op
85 771d8f28 2021-01-17 op The build is as simple as
86 3e4749f7 2020-10-02 op
87 601bc1cc 2021-01-30 op ./configure
88 b9220ca4 2021-01-11 op make
89 3e4749f7 2020-10-02 op
90 2ddc9271 2021-03-29 op or `make static` to build a statically-linked executable.
91 2ddc9271 2021-03-29 op
92 8f0da580 2021-01-21 op If the configure scripts fails to pick up something, please open an
93 f980545b 2021-01-21 op issue or notify me via email.
94 8f0da580 2021-01-21 op
95 771d8f28 2021-01-17 op To install execute:
96 881a9dd9 2021-01-16 op
97 771d8f28 2021-01-17 op make install
98 771d8f28 2021-01-17 op
99 bb4be662 2021-04-25 op Please keep in mind that the master branch, from time to time, may be
100 bb4be662 2021-04-25 op accidentally broken on some platforms. gmid is developed primarily on
101 bb4be662 2021-04-25 op OpenBSD/amd64 and commits on the master branch don't get always tested
102 bb4be662 2021-04-25 op in other OSes. Before tagging a release however, a comprehensive
103 bb4be662 2021-04-25 op testing on various platform is done to ensure everything is working as
104 bb4be662 2021-04-25 op intended.
105 bb4be662 2021-04-25 op
106 bb4be662 2021-04-25 op
107 601bc1cc 2021-01-30 op ### Docker
108 771d8f28 2021-01-17 op
109 601bc1cc 2021-01-30 op If you have trouble installing LibreSSL or libretls, you can use
110 601bc1cc 2021-01-30 op Docker to build a `gmid` image with:
111 601bc1cc 2021-01-30 op
112 17b09e3c 2021-01-18 op docker build -t gmid .
113 17b09e3c 2021-01-18 op
114 17b09e3c 2021-01-18 op and then run it with something along the lines of
115 17b09e3c 2021-01-18 op
116 17b09e3c 2021-01-18 op docker run --rm -it -p 1965:1965 \
117 6c117838 2021-01-25 op -v /path/to/gmid.conf:...:ro \
118 17b09e3c 2021-01-18 op -v /path/to/docs:/var/gemini \
119 6c117838 2021-01-25 op gmid -c .../gmid.conf
120 17b09e3c 2021-01-18 op
121 601bc1cc 2021-01-30 op (ellipses used for brevity)
122 17b09e3c 2021-01-18 op
123 dd8cc7d3 2021-01-22 op ### Local libretls
124 17b09e3c 2021-01-18 op
125 8f0da580 2021-01-21 op This is **NOT** recommended, please try to port LibreSSL/LibreTLS to
126 8f0da580 2021-01-21 op your distribution of choice or use docker instead.
127 8f0da580 2021-01-21 op
128 601bc1cc 2021-01-30 op However, it's possible to statically-link `gmid` to locally-installed
129 601bc1cc 2021-01-30 op libretls quite easily. (It's how I test gmid on Fedora, for instance)
130 8f0da580 2021-01-21 op
131 04397b32 2021-01-21 op Let's say you have compiled and installed libretls in `$LIBRETLS`,
132 8f0da580 2021-01-21 op then you can build `gmid` with
133 8f0da580 2021-01-21 op
134 04397b32 2021-01-21 op ./configure CFLAGS="-I$LIBRETLS/include" \
135 1606927e 2021-02-11 op LDFLAGS="$LIBRETLS/lib/libtls.a -lssl -lcrypto -lpthread -levent"
136 8f0da580 2021-01-21 op make
137 8f0da580 2021-01-21 op
138 dd8cc7d3 2021-01-22 op ### Testing
139 dd8cc7d3 2021-01-22 op
140 31a4993a 2021-01-23 op Execute
141 dd8cc7d3 2021-01-22 op
142 dd8cc7d3 2021-01-22 op make regress
143 dd8cc7d3 2021-01-22 op
144 601bc1cc 2021-01-30 op to start the suite. Keep in mind that the regression tests will
145 601bc1cc 2021-01-30 op create files inside the `regress` directory and bind the 10965 port.
146 dd8cc7d3 2021-01-22 op
147 dd8cc7d3 2021-01-22 op
148 881a9dd9 2021-01-16 op ## Architecture/Security considerations
149 881a9dd9 2021-01-16 op
150 290b5baa 2021-02-23 op gmid is composed by four processes: the parent process, the logger,
151 290b5baa 2021-02-23 op the listener and the executor. The parent process is the only one
152 290b5baa 2021-02-23 op that doesn't drop privileges, but all it does is to wait for a SIGHUP
153 290b5baa 2021-02-23 op to reload the configuration and spawn a new generation of children
154 290b5baa 2021-02-23 op process. The logger processes gather the logs and prints 'em to
155 290b5baa 2021-02-23 op stderr or syslog (for the time being.) The listener process is the
156 290b5baa 2021-02-23 op only one that needs internet access and is sandboxed by default. The
157 290b5baa 2021-02-23 op executor process exists only to fork and execute CGI scripts.
158 881a9dd9 2021-01-16 op
159 601bc1cc 2021-01-30 op On OpenBSD, the listener runs with the `stdio recvfd rpath inet`
160 601bc1cc 2021-01-30 op pledges, while the executor has `stdio sendfd proc exec`; both have
161 290b5baa 2021-02-23 op unveiled only the served directories. The logger process has pledge
162 290b5baa 2021-02-23 op `stdio`.
163 881a9dd9 2021-01-16 op
164 94be0bf0 2021-03-20 op On FreeBSD, the listener and logger process are sandboxed with `capsicum(4)`.
165 d939d0f0 2021-01-17 op
166 601bc1cc 2021-01-30 op On Linux, a `seccomp(2)` filter is installed in the listener to allow
167 601bc1cc 2021-01-30 op only certain syscalls, see [sandbox.c](sandbox.c) for more information
168 601bc1cc 2021-01-30 op on the BPF program.
169 ea58dab1 2021-01-17 op
170 ea58dab1 2021-01-17 op In any case, you are invited to run gmid inside some sort of
171 0b00962d 2021-01-25 op container/jail/chroot.