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 - reconfiguration: reload the running configuration without
13 interruption
14 - sandboxed by default on OpenBSD, Linux and FreeBSD
15 - automatic redirect/error pages (see `block return`)
16 - IRI support (RFC3987)
17 - punycode support
18 - dual stack (IPv4 and IPv6)
19 - automatic certificate generation for config-less mode
20 - CGI scripts
21 - low memory footprint
22 - event-based asynchronous I/O model
23 - small codebase, easily hackable
24 - virtual hosts
25 - per-location rules
26 - optional directory listings
27 - configurable mime types
28 - chroot support
31 ## Internationalisation (IRIs, UNICODE, punycode, all that stuff)
33 Even thought the current Gemini specification doesn't mention anything
34 in this regard, I do think these are important things and so I tried
35 to implement them in the most user-friendly way I could think of.
37 For starters, gmid has full support for IRI (RFC3987 —
38 Internationalized Resource Identifiers). IRIs are a superset of URIs,
39 so there aren't incompatibilities with URI-only clients.
41 There is full support also for punycode. In theory, the user doesn't
42 even need to know that punycode is a thing. The hostname in the
43 configuration file can (and must be) in the decoded form (e.g. `naïve`
44 and not `xn--nave-6pa`), gmid will do the rest.
46 The only missing piece is UNICODE normalisation of the IRI path: gmid
47 doesn't do that (yet).
50 ## Configuration
52 gmid has a rich configuration file, heavily inspired by OpenBSD'
53 httpd. While you should definitely check the manpage because it
54 documents every option in depth, here's a small example of how a
55 configuration file looks like.
57 ```conf
58 ipv6 on # enable ipv6
60 server "example.com" {
61 cert "/path/to/cert.pem"
62 key "/path/to/key.pem"
63 root "/var/gemini/example.com"
64 lang "it"
65 cgi "/cgi/*"
67 location "/files/*" {
68 auto index on
69 }
71 location "/repo/*" {
72 # change the index file name
73 index "README.gmi"
74 }
75 }
76 ```
79 ## Building
81 gmid depends on a POSIX libc, libevent2, OpenSSL/LibreSSL and libtls
82 (provided either by LibreSSL or libretls). At build time, flex and
83 yacc (or GNU bison) are also needed.
85 The build is as simple as
87 ./configure
88 make
90 or `make static` to build a statically-linked executable.
92 If the configure scripts fails to pick up something, please open an
93 issue or notify me via email.
95 To install execute:
97 make install
99 ### Docker
101 If you have trouble installing LibreSSL or libretls, you can use
102 Docker to build a `gmid` image with:
104 docker build -t gmid .
106 and then run it with something along the lines of
108 docker run --rm -it -p 1965:1965 \
109 -v /path/to/gmid.conf:...:ro \
110 -v /path/to/docs:/var/gemini \
111 gmid -c .../gmid.conf
113 (ellipses used for brevity)
115 ### Local libretls
117 This is **NOT** recommended, please try to port LibreSSL/LibreTLS to
118 your distribution of choice or use docker instead.
120 However, it's possible to statically-link `gmid` to locally-installed
121 libretls quite easily. (It's how I test gmid on Fedora, for instance)
123 Let's say you have compiled and installed libretls in `$LIBRETLS`,
124 then you can build `gmid` with
126 ./configure CFLAGS="-I$LIBRETLS/include" \
127 LDFLAGS="$LIBRETLS/lib/libtls.a -lssl -lcrypto -lpthread -levent"
128 make
130 ### Testing
132 Execute
134 make regress
136 to start the suite. Keep in mind that the regression tests will
137 create files inside the `regress` directory and bind the 10965 port.
140 ## Architecture/Security considerations
142 gmid is composed by four processes: the parent process, the logger,
143 the listener and the executor. The parent process is the only one
144 that doesn't drop privileges, but all it does is to wait for a SIGHUP
145 to reload the configuration and spawn a new generation of children
146 process. The logger processes gather the logs and prints 'em to
147 stderr or syslog (for the time being.) The listener process is the
148 only one that needs internet access and is sandboxed by default. The
149 executor process exists only to fork and execute CGI scripts.
151 On OpenBSD, the listener runs with the `stdio recvfd rpath inet`
152 pledges, while the executor has `stdio sendfd proc exec`; both have
153 unveiled only the served directories. The logger process has pledge
154 `stdio`.
156 On FreeBSD, the listener and logger process are sandboxed with `capsicum(4)`.
158 On Linux, a `seccomp(2)` filter is installed in the listener to allow
159 only certain syscalls, see [sandbox.c](sandbox.c) for more information
160 on the BPF program.
162 In any case, you are invited to run gmid inside some sort of
163 container/jail/chroot.