Blob


1 # gmid
3 gmid is a fast Gemini server written with security in mind. I
4 initially wrote it to serve static files, but it has grown into a
5 featureful server.
8 ## Features
10 (random order)
12 - sandboxed by default on OpenBSD, Linux and FreeBSD
13 - reconfiguration: reload the running configuration without
14 interruption
15 - automatic redirect/error pages (see `block return`)
16 - IRI support (RFC3987)
17 - automatic certificate generation for config-less mode
18 - CGI support
19 - virtual hosts
20 - location rules
21 - event-based asynchronous I/O model
22 - low memory footprint
23 - small codebase, easily hackable
26 ## Internationalisation (IRIs, UNICODE, punycode, all that stuff)
28 Even thought the current Gemini specification doesn't mention anything
29 in this regard, I do think these are important things and so I tried
30 to implement them in the most user-friendly way I could think of.
32 For starters, gmid has full support for IRI (RFC3987 —
33 Internationalized Resource Identifiers). IRIs are a superset of URIs,
34 so there aren't incompatibilities with URI-only clients.
36 There is full support also for punycode. In theory, the user doesn't
37 even need to know that punycode is a thing. The hostname in the
38 configuration file can (and must be) in the decoded form (e.g. `naïve`
39 and not `xn--nave-6pa`), gmid will do the rest.
41 The only missing piece is UNICODE normalisation of the IRI path: gmid
42 doesn't do that (yet).
45 ## Configuration
47 gmid has a rich configuration file, heavily inspired by OpenBSD'
48 httpd, with every detail carefully documented in the manpage. Here's
49 a minimal example of a config file:
51 ```conf
52 server "example.com" {
53 cert "/path/to/cert.pem"
54 key "/path/to/key.pem"
55 root "/var/gemini/example.com"
56 }
57 ```
59 and a slightly complex one
61 ```conf
62 ipv6 on # enable ipv6
64 server "example.com" {
65 alias "foobar.com"
67 cert "/path/to/cert.pem"
68 key "/path/to/key.pem"
69 root "/var/gemini/example.com"
71 # lang for text/gemini files
72 lang "it"
74 # execute CGI scripts in /cgi/
75 cgi "/cgi/*"
77 # only for locations that matches /files/*
78 location "/files/*" {
79 # generate directory listings
80 auto index on
81 }
83 location "/repo/*" {
84 # change the index file name
85 index "README.gmi"
86 lang "en"
87 }
88 }
89 ```
92 ## Building
94 gmid depends on a POSIX libc, libevent2, OpenSSL/LibreSSL and libtls
95 (provided either by LibreSSL or libretls). At build time, flex and
96 yacc (or GNU bison) are also needed.
98 The build is as simple as
100 ./configure
101 make
103 or `make static` to build a statically-linked executable.
105 If the configure scripts fails to pick up something, please open an
106 issue or notify me via email.
108 To install execute:
110 make install
112 Please keep in mind that the master branch, from time to time, may be
113 accidentally broken on some platforms. gmid is developed primarily on
114 OpenBSD/amd64 and commits on the master branch don't get always tested
115 in other OSes. Before tagging a release however, a comprehensive
116 testing on various platform is done to ensure that everything is
117 working as intended.
120 ### Docker
122 If you have trouble installing LibreSSL or libretls, you can use
123 Docker to build a `gmid` image with:
125 docker build -t gmid .
127 and then run it with something along the lines of
129 docker run --rm -it -p 1965:1965 \
130 -v /path/to/gmid.conf:...:ro \
131 -v /path/to/docs:/var/gemini \
132 gmid /bin/gmid -c .../gmid.conf
134 (ellipses used for brevity)
136 ### Local libretls
138 This is **NOT** recommended, please try to port LibreSSL/LibreTLS to
139 your distribution of choice or use docker instead.
141 However, it's possible to statically-link `gmid` to locally-installed
142 libretls quite easily. (It's how I test gmid on Fedora, for instance)
144 Let's say you have compiled and installed libretls in `$LIBRETLS`,
145 then you can build `gmid` with
147 ./configure CFLAGS="-I$LIBRETLS/include" \
148 LDFLAGS="$LIBRETLS/lib/libtls.a -lssl -lcrypto -lpthread -levent"
149 make
151 ### Testing
153 Execute
155 make regress
157 to start the suite. Keep in mind that the regression tests will
158 create files inside the `regress` directory and bind the 10965 port.
161 ## Architecture/Security considerations
163 gmid is composed by four processes: the parent process, the logger,
164 the listener and the executor. The parent process is the only one
165 that doesn't drop privileges, but all it does is to wait for a SIGHUP
166 to reload the configuration and spawn a new generation of children
167 process. The logger processes gather the logs and prints 'em to
168 stderr or syslog (for the time being.) The listener process is the
169 only one that needs internet access and is sandboxed by default. The
170 executor process exists only to fork and execute CGI scripts.
172 On OpenBSD, the listener runs with the `stdio recvfd rpath inet`
173 pledges, while the executor has `stdio sendfd proc exec`; both have
174 unveiled only the served directories. The logger process has pledge
175 `stdio`.
177 On FreeBSD, the listener and logger process are sandboxed with `capsicum(4)`.
179 On Linux, a `seccomp(2)` filter is installed in the listener to allow
180 only certain syscalls, see [sandbox.c](sandbox.c) for more information
181 on the BPF program.
183 In any case, you are invited to run gmid inside some sort of
184 container/jail/chroot.