How I imprinted on (not only computer) RPGs

Back when I was a kid (well, teenager), I had an Atari 800XL and played a great many list of games on it. The one that hooked me most though is a rather obscure one: Alternate Reality (The City) and it’s sequel Alternate Reality (The Dungeon).

For me, that game was eye-opening. The game world felt really alive in a lot of tiny ways, and was in many more way ahead than other games. It used a raycasting engine, on 8-Bit home computers nonetheless. It was basically an open-world game, where you didn’t wander through a set plot, but had to connect the dots yourself, and figure out who wanted what. That meant that you could suddenly die, because you wandered in the wrong part of the map, or that people you never met knew of you.

This thoroughly spoiled me for most of what followed. I couldn’t fathom why things had to be so static, why I couldn’t just rob this bank or plead with this monster. And the places made sense, even if they were labyrinthine. Also, with monsters like the „Clothes Horse“, it forged my sense of what is appropriate in a game and what isn’t.

Gosh, I miss that game :)

Subsonic & Caddy – oh my…

Dangnabbit.

Subsonic has the nasty habit of generating certain URLs in a very hardcoded way.

The login screen for example. If you call index.view and are not logged in, it redirects you to $ServerSubsonicThinksItIs/login.view.

That will be localhost, if you want to do the „oh yay, let’s reverse proxy here“ thing. To make matters worse, $ServerSubsonicThinksItIs also contains protocol and port. This is apparently due to the implementation of Subsonics „generate a yourhost.subsonic.org“ redirection.

As far as I can see, only the login and settings pages are the ones that are affected by this. They are still accessible if you manually add /login.view to your public address.

Of course, you can tell Subsonic to believe that it is on the servername you chose for it. As long as Subsonic and the reverse proxy server are in agreement of which host, path & port are shown to the browser, everything is fine. With non-encrypted http that is.

Of course you can re-enable https on Subsonic, in order to successfully proxy everything from A to B, but…

…Caddy checks the validity of the SSL certificate of whatever site it reverse-proxies to. And throws a Bad Gateway if it doesn’t like what it sees. This is actually done with a reason, but it doesn’t help me right now.

As far as I can see, I either have to wait for…

  • Subsonic finally learning to generate sane URLs or
  • Caddyserver being able to ignore faulty certificates upstream

Subsonic with Caddy

Ok, now that there is Let’s Encrypt, I thought that I shouldn’t have to do this certificate hackery all the time when Subsonic updates or the StartSSL certificate expires.

Caddyserver is the first Webserver/Proxy that I found that has most of the process automated and build in, so I’m using this. Getting started with this was pretty straightforward: Download, expand,  create a config file and before you start up, make sure that Caddy can run on port 80 without requiring to be root:

sudo setcap cap_net_bind_service=+ep ./caddy

My Caddyfile eventually ended up looking like this:

server.mydomain.de {
 proxy / localhost:4040 {
 proxy_header Host server.mydomain.de
 proxy_header Scheme https
 }

Well, it turned out to not be quite as easy. First I also had to make Subsonic stop hogging port 443. Those settings are found in /etc/default/subsonic. And while you’re at it, also edit out any certificates you may have added earlier in /usr/bin/subsonic. Oh, and make sure to note down which port non-https Subsonic runs, hopefully not 80, because Caddy needs that! I may have chosen 4040.

Restart Subsonic and make sure that you can reach it on the correct ports.

As stated, Caddy also needs to run on Port 80 for a brief moment. This is so it can do the certificate domain validation process. So edit your /etc/apache2/ports.conf to make sure not to block anything.

Restart apache2.

Now, to find out if everything works, start Caddy. If all is good, you’ll see a glorious all-ok message and can now access the server via https with a valid certificate.

But as you’ve undoubtedly noticed, Caddy isn’t running as a service yet. Thankfully Ubuntu has Upstart. So, add in a new file /etc/init/caddyservice.conf (thank you Mathias):

description "Caddy Server startup script"
author "Mathias Beke"
start on runlevel [2345]
stop on runlevel [016]
setuid runasme
setgid runasme
respawn
respawn limit 10 5
script
 cd /home/runasme/
 exec ./caddy

At this point I want to take a short moment to mention that whoever thinks that the Upstart Cookbook is an easy entry-level document is clearly out of their mind. Seriously, this „Cookbook“ has a whole chapter named „Critique of the System V init System“!

But I digress. If you don’t make the same mistake as me and confuse init with init.d, then you’re golden and now have a Caddy running as a service, forwarding requests to your Subsonic installation.

The only issue I haven’t been able to solve is that Subsonic has some stupid static URL linking going on so I have to open the settings in a new tab. But I can live with that.

Third-Party Certificate for Subsonic on Linux

This is more a reminder-post for myself, than anything else, because every year my StartSSL-Certificate expires, I need to redo this and have to look it up anew. It is based on the basically excellent writeup at fatframe.com, which has a few tiny errors and does not include the info on how to use a non-standard password. (This info I got here at konkretor. Thanks!)

  1. Get a free certificate here.
  2. Once you receive your certificate you will need to combine the private key, server cert, and intermediate certs into one file. Simply open all three in a text editor and copy/paste everything into a new text file without any blank lines. I added mine in the following order:
    Private Key (myserver.key)
    Server Certificate (myserver.ssl)
    Intermediate Certificate (sub.class1.server.ca.pem)
  3. Save this text file as subsonic.crt. Do not mess this up as I did on the first try by using cat in the wrong way, as every new part should start at a new line.
  4. Next, convert the cert from PEM to PKCS12 format using the following command. Choose any password you like. In fact, do not choose the default password of „subsonic“. Memorize that password:
    openssl pkcs12 -in subsonic.crt -export -out subsonic.pkcs12
  5. Use Keytool to import this new keystore:
    keytool -importkeystore -srckeystore subsonic.pkcs12 -destkeystore subsonic.keystore -srcstoretype PKCS12 -srcalias 1 -destalias subsonic
  6. use zip to import the new keystore into the subsonic jar:
    sudo zip /usr/share/subsonic/subsonic-booter-jar-with-dependencies.jar subsonic.keystore
  7. Now tell subsonic the new non-generic password:
    1. open the subsonic starter:
      sudo nano /usr/bin/subsonic
    2. insert a line with the new password and save, at line 113ish (press alt+c to see line numbers)
      -Dsubsonic.ssl.password=123456 \
  8. Restart subsonic, and enjoy your custom SSL certifcate:
    sudo service subsonic restart

That’s all Folks!