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 - reverse proxying
19 - CGI and FastCGI support
20 - virtual hosts
21 - location rules
22 - event-based asynchronous I/O model
23 - low memory footprint
24 - small codebase, easily hackable
27 ## Internationalisation (IRIs, UNICODE, punycode, all that stuff)
29 Even thought the current Gemini specification doesn't mention anything
30 in this regard, I do think these are important things and so I tried
31 to implement them in the most user-friendly way I could think of.
33 For starters, gmid has full support for IRI (RFC3987 —
34 Internationalized Resource Identifiers). IRIs are a superset of URIs,
35 so there aren't incompatibilities with URI-only clients.
37 There is full support also for punycode. In theory, the user doesn't
38 even need to know that punycode is a thing. The hostname in the
39 configuration file can (and must be) in the decoded form (e.g. `naïve`
40 and not `xn--nave-6pa`), gmid will do the rest.
42 The only missing piece is UNICODE normalisation of the IRI path: gmid
43 doesn't do that (yet).
46 ## Configuration
48 gmid has a rich configuration file, heavily inspired by OpenBSD'
49 httpd, with every detail carefully documented in the manpage. Here's
50 a minimal example of a config file:
52 ```conf
53 server "" {
54 cert "/path/to/cert.pem"
55 key "/path/to/key.pem"
56 root "/var/gemini/"
57 }
58 ```
60 and a slightly more complex one
62 ```conf
63 ipv6 on # enable ipv6
65 # define a macro
66 cert_root = "/path/to/keys"
68 server "" {
69 alias ""
71 cert $cert_root "/"
72 key $cert_root "/"
73 root "/var/gemini/"
75 # lang for text/gemini files
76 lang "en"
78 # execute CGI scripts in /cgi/
79 cgi "/cgi/*"
81 # only for locations that matches /files/*
82 location "/files/*" {
83 # generate directory listings
84 auto index on
85 }
87 location "/repo/*" {
88 # change the index file name
89 index "README.gmi"
90 lang "it"
91 }
92 }
93 ```
96 ## Building
98 gmid depends on a POSIX libc, libevent2, OpenSSL/LibreSSL and libtls
99 (provided either by LibreSSL or libretls). At build time, yacc (or
100 GNU bison) is also needed.
102 The build is as simple as
104 ./configure
105 make
107 or `make static` to build a statically-linked executable.
109 If the configure scripts fails to pick up something, please open an
110 issue or notify me via email.
112 To install execute:
114 make install
116 Please keep in mind that the master branch, from time to time, may be
117 accidentally broken on some platforms. gmid is developed primarily on
118 OpenBSD/amd64 and commits on the master branch don't get always tested
119 in other OSes. Before tagging a release however, a comprehensive
120 testing on various platform is done to ensure that everything is
121 working as intended.
124 ### Docker
126 If you have trouble installing LibreSSL or libretls, in `contrib`
127 there's a sample Dockerfile. See [the contrib page][contrib-page] for
128 more information.
130 [contrib-page]:
132 ### Local libretls
134 This is **NOT** recommended, please try to port LibreSSL/LibreTLS to
135 your distribution of choice or use docker instead.
137 However, it's possible to statically-link `gmid` to locally-installed
138 libretls quite easily. (It's how I test gmid on Fedora, for instance)
140 Let's say you have compiled and installed libretls in `$LIBRETLS`,
141 then you can build `gmid` with
143 ./configure CFLAGS="-I$LIBRETLS/include" \
144 LDFLAGS="$LIBRETLS/lib/libtls.a -lssl -lcrypto -lpthread -levent"
145 make
147 ### Testing
149 Execute
151 make regress
153 to start the suite. Keep in mind that the regression tests will
154 create files inside the `regress` directory and bind the 10965 port.
157 ## Architecture/Security considerations
159 gmid is composed by four processes: the parent process, the logger,
160 the listener and the executor. The parent process is the only one
161 that doesn't drop privileges, but all it does is to wait for a SIGHUP
162 to reload the configuration and spawn a new generation of children
163 process. The logger process gathers the logs and prints 'em to
164 stderr or syslog (for the time being.) The listener process is the
165 only one that needs internet access and is sandboxed by default. The
166 executor process exists only to fork and execute CGI scripts, and
167 optionally to connect to FastCGI applications.
169 On OpenBSD the processes are all `pledge(2)`d and `unveil(2)`ed.
171 On FreeBSD, the listener and logger process are sandboxed with `capsicum(4)`.
173 On Linux, a `seccomp(2)` filter is installed in the listener to allow
174 only certain syscalls, see [sandbox.c](sandbox.c) for more information
175 about the BPF program. If available, landlock is used to limit the
176 portion of the file system gmid can access (requires linux 5.13+.)
178 In any case, it's advisable to run gmid inside some sort of
179 container/jail/chroot.