New #Blog: Making Multiple Gemini Capsules Available Via Tor and I2P
Author: Ben Tasker
bentasker.co.ukMaking Multiple Gemini Capsules Available Via Tor and I2PA couple of weeks ago, I made BenTasker.co.uk available as Gemini capsule.
In order to test and improve my Nikola plugin a bit more, I decided to make snippets.bentasker.co.uk available via Gemini too.
The plugin pretty much just worked, but I ran into an issue when adding the new virtual host to `agate`.
Once I'd sorted that, I decided that I should make my capsules available via Tor/I2P and set up some monitoring.
This post talks about standing up an additional capsule, making the content available via anonymous overlay networks and implementing availability monitoring.
* * *
### `agate` SSL Problems
_In theory_ , all I needed to do was to add a new `--hostname` to `agate`'s invocation:
gemini:
restart: always
image: ghcr.io/mbrubeck/agate:latest
container_name: gemini
command: --hostname gem.bentasker.co.uk --hostname snippetsgem.bentasker.co.uk --lang en-GB --log-ip
However, when I tried to access the capsule, I got a certificate warning:
The domain name on the cert was that of my main/original capsule - `gem.bentasker.co.uk`.
Looking on the filesystem revealed that `agate` hadn't auto-generated a certificate for the new capsule:
ls ../files/gemini/certs/
gem.bentasker.co.uk
Poking about in agate's code revealed why: generation of new certificates is guarded by a conditional:
if let Host::Domain(ref domain) = hostname
&& !matches!(certs, Some(ref certs) if certs.has_domain(domain))
The function `has_domain()` iterates through known certificates doing a simple suffix check:
pub fn has_domain(&self, domain: &str) -> bool {
self.certs.iter().any(|(s, _)| domain.ends_with(s))
}
The problem was:
* I already had a certificate for `gem.bentasker.co.uk`
* The string `snippetsgem.bentasker.co.uk` ends with `gem.bentasker.co.uk`
* The `gem.` certificate, however, is not valid for the other name
I put a PR up to try and fix the behaviour, but there's an interesting dichotomy here:
* Gemini uses Trust-on-first-use (TOFU) rather than having trusted certificate authorities, so I _should_ be able to accept any certificate
* Lagrange, though, validate that the common name matches so an incorrect value will generate warnings
It seems there's been a long-standing debate around this1.
We don't see this issue on the web, because PKI enforcement is much stricter: a cert must be signed by a trusted party, and SANs/Common-Names need to match the hostname and port exactly (or be a wildcard - which even then only run one label deep).
Rather than waiting on my PR, though, I needed to generate a certificate myself.
Agate uses DER format certs:
cd files/gemini/certs
ls gem.bentasker.co.uk/
cert.der key.der
So, I created a new directory for the new gem and then generated a certificate:
mkdir snippetsgem.bentasker.co.uk
cd $_
openssl req -new -newkey rsa:2048 -days 4096 -nodes -x509 -outform der -keyout key.der -out cert.der
# That got us a DER form cert, but the key still needs converting
openssl rsa -inform pem -in key.der -outform der -out key.der
To have the new cert picked up, I also needed to restart agate:
docker restart gemini
After that, the correct cert was presented and I could access the capsule:
* * *
### Serving Over Tor
It occurred to me that I could also make my capsules available over Tor.
However, `agate` uses a directory per virtual host and I didn't want to have my files twice on disk.
Luckily, agate supports symlinks, so:
cd docroots
ln -s gem.bentasker.co.uk e26whn2524322mkxb3cbyk27ev2ihhq2biz35hty7gzgsyrwrygq27yd.onion
I updated `agate`'s command line again to include my `.onion` hostname:
command: --hostname gem.bentasker.co.uk --hostname snippetsgem.bentasker.co.uk --hostname e26whn2524322mkxb3cbyk27ev2ihhq2biz35hty7gzgsyrwrygq27yd.onion --lang en-GB --log-ip
I then updated my `torrc` to expose gemini's port via the hidden service:
