Configuring secure HTTPS ports with TLS (“SSL”) on OpenSim

Background

It has already been remarked in an earlier post that it is now possible to configure the simulator to use secure ports on OpenSim with TLS (still erroneously but commonly known by the name of its defunct predecessor SSL), i.e. that you can run it on HTTPS instead of HTTP. However, there is no native ability within OpenSim to do this for the ROBUST services, including most critically the login service. This means that your password details are broadcast in plain text at the time of login. Obviously this is far from ideal.

In order to provide secure ports it is necessary to configure a reverse proxy, of which the most obvious and commonly suggested by OpenSim administrators is Nginx, which also happens to be the best all-round modern HTTP(S) server and an improvement (in my opinion) on the venerable but battle-tested and dependable Apache. (See here for a discussion, in which it is stated that OSGrid uses Nginx.) For all this, there appears to be no published advice on how to achieve any of this. It seems no surprise that few – if any? – publicly available OpenSim servers on the Hypergrid seem to be configured to use HTTPS ports with TLS. It is fiddly, so this is worth providing here.

Most other server software in live installations is configured to use secure ports as an industry standard – why should OpenSim not follow the same standards? Otherwise I would suggest that you can never store personal data in OpenSim and you can never be sure of not being hacked. It’s fairly unlikely that an OpenSim grid would be an attractive target for a hacker, being somewhat niche, but it is entirely possible and no doubt has happened. (Famously, SL was hacked with flying penises.)

Secure ports 9002 and 9003 on Ocean Grid

Ocean Grid is now an example of just such a grid. In fact, for reasons that we shall come to later, it remains possible to log into Ocean Grid using the insecure HTTP port 8002. However, as of 2 May 2020 it is now also possible to use the secure HTTPS port 9002. Furthermore, the traffic to the private port is also configured on 9003 instead of 8003 for reasons specific to Ocean Grid that you may not need to bother with: if your internal port does not need to be open to the Internet then only your subnet will be able to see that traffic anyway, so why add the (fairly small) overhead of encryption?

First of all I began by configuring a second instance of ROBUST. Ocean Grid now runs duplicate copies of all the services. I have never separated, for example, the asset server from the others and I have not done so now either, but this can be done too. This would use Nginx as a reverse proxy for its other purpose, namely to load balance between duplicate copies of services, whether the whole lot of them in one ROBUST instance as I have done or on a service-by-service basis. The obvious one to do this with is the asset server. It depends on the ancient Tiny Web Server, written in C#, which is very slow and probably ought to be replaced – I’d suggest with h2o because it is fast and can do HTTP/2 and (experimentally so far) the new HTTP/3 (formerly QUIC) over UDP. So far I have configured no load balancing for Ocean Grid. One large 1280×1280 test region/simulator (Rheged) communicates by HTTPS while the other four regions (again, all on separate simulators to prevent out-of-memory crashes) all still use the original HTTP port. This of course may change in future.

In case you are wondering how I have different regions on different simulators, I have adapted Gwyn Llewelyn’s brilliant instructions on how to run multiple instances concurrently. Thanks, Gwyn ❤ (Be still, my virtual heart!) I also use some scripts that use GNU Screen to automatically switch between the console interfaces of the regions/simulators and ROBUST.

The upshot of all this is that all the services are available by either port. You can log in locally or via Hypergrid by either and reach the same simulators with no apparent difference in performance between the two. In fact, removing a region/simulator that is 5×5 larger than a normal region (i.e. 25 times as big) to a separate asset service has considerably improved performance. Otherwise there are only four 256×256 traditional regions in Ocean Grid to date.

It would of course be possible to attach other people’s regions on other servers to Ocean Grid, although this has not ever been done to date because it is a small private grid with mainly just myself, Starflower Bracken, as the principal user. I get a small number of Hypergrid visitors and a tiny number of visits from old friends of 2007 vintage who I met years ago in SL and have registered accounts locally on my grid. This would add a little more impetus to use HTTPS for security reasons, as the internal services then need to be open to the public Internet and there are more targets to attack. In any case, the same principles apply about best security practices as outlined above.

Before moving on to the mechanics of the installation, it suffices to add that there will be further tweaks as time goes on, probably including the load balancing described above in order to provide a much-needed boost to performance, especially as regards load on the asset server.

Problem with https:// prefix in the viewer

One particular tweak, migrating entirely to HTTPS and removing the insecure ports, will have to be has been postponed for an unknown period of some time. The grid selector in the viewer has always previously contained a bug [FIRE-24068 fixed 2020-11-07, SV-2392 fixed at unknown date], since it was first added to the original viewer for OpenSim purposes, that adds the http:// prefix to any loginURI and makes it impossible to add https:// instead. The only workaround to this annoying problem is to manually edit grids.user.xml (or grids.xml in some viewers). On doing this, HTTPS logins work perfectly, including using free Let’s Encrypt certificates as are installed on Ocean Grid. But less experienced users may not know how to edit this XML file, so any total migration would shut them out of logging in locally to the grid. Now that the major viewers allow this, it may make sense to migrate to the secure port, which is currently under review. You may ask, who cares since only I log in locally for the most part, while other visitors come via Hypergrid. In my case I have one reasonably frequent visitor who logs in with a locally registered account, who happens to be a very welcome one. I don’t really want to put a barrier in the way of the few local visits that I do still receive or force people to come via Hypergrid. If you do visit me via Hypergrid then I urge you to use port 9002 and thus to do so securely!

NOTE 2021-09-15, edited 2021-09-26: It is now possible to use Firestorm and Singularity with secure ports. (Singularity has a recent OpenSim version from 2020 despite being listed as an inactive viewer or in an “unknown” state – what is the status of this viewer? I was unable to run Dayturn 1.8.10 or 1.8.9 on Windows 10 as it simply failed to start for me, so I have not been able to test it. The VL Cool Viewer also supports HTTPS (although it will let you add the grid with the secure port OR the insecure port but not both under different names!) Radegast (text-only viewer) supports HTTPS. SceneGate (viewer with reduced functionality) supports HTTPS and for bonus points gives a security warning when connecting to insecure HTTP ports. This seems like a much more healthy position than described above. If Dayturn allows secure ports, there appears to be little good reason not to migrate entirely to secure ports, which I am seriously considering.

Setting up the ROBUST server with HTTPS

First of all you need to configure and run a second copy of ROBUST. I copied Robust.HG.ini to a new file Robust.HG.tls.ini and then edited that. You will use -inifile=”$DIR/Robust.HG.tls.ini” where you can replace $DIR with the path to wherever you keep the file, if you don’t use the method that I use.

Then you need to edit the following in blue, adapting it as appropriate for your purposes:

[Const]
BaseURL = “https://oceangrid.net”
PublicPort = “8102″
; The proxied external public port of the Robust server
PublicPort2 = “9002”
PrivatePort = “8103″

[ServiceList]
VoiceConnector = “9004/OpenSim.Server.Handlers.dll:FreeswitchServerConnector”

[Hypergrid]
HomeURI = “${Const|BaseURL}:${Const|PublicPort2}”
GatekeeperURI = “${Const|BaseURL}:${Const|PublicPort2}”

[LoginService]
MapTileURL = “${Const|BaseURL}:${Const|PublicPort2}/”;
SearchURL = “${Const|BaseURL}:${Const|PublicPort2}/”;
SRV_HomeURI = “${Const|BaseURL}:${Const|PublicPort2}”
SRV_InventoryServerURI = “${Const|BaseURL}:${Const|PublicPort2}”
SRV_AssetServerURI = “${Const|BaseURL}:${Const|PublicPort2}”
SRV_ProfileServerURI = “${Const|BaseURL}:${Const|PublicPort2}”
SRV_FriendsServerURI = “${Const|BaseURL}:${Const|PublicPort2}”
SRV_IMServerURI = “${Const|BaseURL}:${Const|PublicPort2}”
SRV_GroupsServerURI = “${Const|BaseURL}:${Const|PublicPort2}”

[GridInfoService]
login = ${Const|BaseURL}:${Const|PublicPort2}/
gridname = “Ocean Grid TLS
gridnick = “Ocean Grid TLS
gatekeeper = ${Const|BaseURL}:${Const|PublicPort2}/
uas = ${Const|BaseURL}:${Const|PublicPort2}/

In the case of OpenSim, there are cascading copies of OpenSim.ini in order to override certain settings for each region/simulator and inherit the rest of the settings from the main file. You may not have that setup, of course. However, this is what I did for the copy for my region Rheged:

[Const]
BaseHostname = “oceangrid.net”
BaseURL = https://${Const|BaseHostname}
PublicPort = “9002″
PrivURL = https://localhost
PrivatePort = “9003″
;; the following line was for testing – ignore
;PrivatePort = “8103”

Step required only if you are using port 9003 HTTPS on localhost

There is also another step required for making the certificates for localhost (or 127.0.0.1) work if, like me, you are making the internal services function over HTTPS. There are better ways to do this and this is a bit of a hack but bear in mind that the loss in security is fairly inconsequential since it is only on the internal subnet with only trusted devices connecting. As noted above, you don’t even need to encrypt these if they are never accessed from the public Internet but in my case they are because I have an external proxy server as well, which provides a roundabout solution to the lack of NAT loopback (NAT hairpinning) on the rather rubbish router that my ISP has provided. A better solution would be to get a decent router (and preferably a fixed IP address, as I used to have, rather than Dynamic DNS) and then I could just keep port 8003 internal and dispense with 9003. (I could alternatively use the /etc/hosts file on any other machine on the network running a viewer to connect with the local grid.) As also noted, another possible reason to expose these ports to the Internet is if external simulators are connecting.

Anyway, here is what I did:

[Startup]
; #
; # SSL certificates validation options
; #

; SSL certificate validation options
; you can allow selfsigned certificates or no official CA with next option set to true
; NoVerifyCertChain = true
NoVerifyCertChain = true
; you can also bypass the hostname or domain verification
; NoVerifyCertHostname = true
NoVerifyCertHostname = true
; having both options true does provide encryption but with low security
; set both true if you don’t care to use SSL, they are needed to contact regions or grids that do use it.

Setting up the simulator to use HTTPS (separate, optional step)

Again, for completeness, another step that is strictly not necessary is to give it a secure port. I actually did this some time ago quite, separately from all of this, for just the simulator rather than ROBUST:

[Network]
http_listener_port = 9106 ; if http_listener_ssl = true then this will be ignored

;; THIS IS EXPERIMENTAL IN OPENSIM 0.9.1.0
; ssl config: Experimental!
http_listener_ssl = true ; if set to true main server is replaced by a ssl one
http_listener_sslport = 9206 ; Use this port for SSL connections
; currently if using ssl, regions ExternalHostName must the the same and equal to http_listener_cn
; this will change is future
http_listener_cn = “oceangrid.net”
; if the cert doesnt have a official CA or is selfsigned viewers option NoVerifySSLCert need to be set true
http_listener_cert_path = “/opt/opensim/bin/certs/oceangrid.p12” ; path for the cert file that is valid for the ExternalHostName
http_listener_cert_pass = “your_password_here” ; the cert password

; the handler is in [opensim]/OpenSim/Server/Base/HttpServerBase.cs
http_listener_ssl_cert = “” ; as of 2019-10-11 this is not fetched by [opensim]/OpenSim/Framework/NetworkServersInfo.cs
; but the next undocumented lines are fetched, though who knows what, if anything, is done with them since it doesn’t
; work and you get the error “Error – certificate Parameter name: ‘certificate’ cannot be null.”

Nginx reverse proxy configuration

The next step is to provide the Nginx reverse proxy configuration as follows (tidied up a bit!) in a file called something like /etc/nginx/sites-available/oceangrid.net-9002-9003 as follows:

server {
listen 9002 ssl http2;
listen [::]:9002 ssl http2;

server_name oceangrid.net http://www.oceangrid.net;

ssl_session_cache shared:SSL:20m;
ssl_session_timeout 10m;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
#very secure, very compatible
ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;
#highly secure, less compatible
#ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:!ADH:!AECDH:!MD5;
ssl_prefer_server_ciphers on;

location / {
proxy_pass http://127.0.0.1:8102$1;
#resolver 8.8.8.8; #public Google IPv4 DNS resolver (insecure)
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location ~ \.php$ {
proxy_pass http://127.0.0.1:8102$1;
#resolver 8.8.8.8; #public Google IPv4 DNS resolver (insecure)
proxy_redirect off;
proxy_buffering off;;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

access_log /var/log/nginx/grid.oceangrid.access.log;
error_log /var/log/nginx/grid.oceangrid.error.log;

ssl_certificate /etc/letsencrypt/live/www.oceangrid.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.oceangrid.net/privkey.pem; # managed by Certbot

}

server {
listen 9003 ssl http2;
listen [::]:9003 ssl http2;

server_name oceangrid.net http://www.oceangrid.net;

ssl_session_cache shared:SSL:20m;
ssl_session_timeout 10m;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
#very secure, very compatible
ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;
#highly secure, less compatible
#ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:!ADH:!AECDH:!MD5;
ssl_prefer_server_ciphers on;

location / {
proxy_pass http://127.0.0.1:8103$1;
#resolver 8.8.8.8; #public Google IPv4 DNS resolver (insecure)
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location ~ \.php$ {
proxy_pass http://127.0.0.1:8103$1;
#resolver 8.8.8.8; #public Google IPv4 DNS resolver (insecure)
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

access_log /var/log/nginx/grid.oceangrid.access.log;
error_log /var/log/nginx/grid.oceangrid.error.log;

ssl_certificate /etc/letsencrypt/live/www.oceangrid.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.oceangrid.net/privkey.pem; # managed by Certbot

}

Finally make another copy of this file, for example called /etc/nginx/sites-available/localhost-9002-9002 but comment out (#) the lines that are your equivalent of server_name oceangrid.net; near the top. These will then work for localhost (127.0.0.1) on those ports. You will now need to type:

sudo ln -s /etc/nginx/sites-available/localhost-9002-9002 /etc/nginx/sites-enabled/localhost-9002-9003
sudo ln -s /etc/nginx/sites-available/oceangrid.net-9002-9003 /etc/nginx/sites-enabled/oceangrid.net-9002-9003
sudo systemctl restart nginx
OR
sudo service nginx restart

Here you have it. As discussed above, you won’t need to do the localhost part if 8003 is firewalled on your local network, in which case you will not be using 9003 and those sections can be ignored here in both files.

Bear in mind that the resolver setting may be different on different servers and I must leave you to discover the best and safest way to do this on your own configuration – don’t use an easily guessable public DNS resolver like the one commented out above because of the risk of interception.

The future of HTTPS in the open metaverse

You could adapt and simply these instructions easily enough for a standalone installation of OpenSim but, since I don’t use one, unless somebody contacts me for advice then I shall leave it to them to do so because I don’t see it should be too horribly difficult based on the instructions for a grid. Most people’s requirements will be simpler than mine but my grid has evolved over almost 10 years.

I hope that people use these instructions. I am asking people to adopt 9002 and 9003 for these secure ports, i.e. to establish a convention that is easily guessable like the present 8002 and 8003 convention. Please also add your voice to the call to fix the grid selector in the various viewers [FIRE-24068SV-2392]. I am looking forward to a more secure open metaverse in the future and hope I have contributed to that.

The History of Hypergrid Directories: A Single Point of Failure

This article is not intended to be overly critical of those various people who have generously put their time and effort into providing directories of Hypergrid locations, which must have been very considerable. The phrase “single point of failure” is a technical description and not a criticism or judgement. It is no small feat to put the server infrastructure and programming time into making this work and maintaining it over a period of time. As one who has operated servers, I understand that the personal circumstances of such volunteers change and resources such as time and finance for servers can be limited.

By way of comparison, a number of the original OpenSim developers have moved onto new projects, yet OpenSim is still releasing new versions. Why? Because there is not, in computing terms, a single point of failure that will cause things to fall over if those individuals or servers can no longer contribute. All of these directories depend on a single, privately maintained database even where the code itself has been open sourced, e.g. TheHyperGates.com with code on GitHub developed by kidd piko (Zvi Ben Yaakov). This has recently had more downtime than ever before and appears to be unmaintained at present, for whatever reasons. [Ed.: in fact, I discover from kidd that the service needs a database sync but would then otherwise be functional, although the web site is not currently available.] Unfortunately, since Kidd put vast amounts of time into this development, all that fantastic effort now seems to be wasted [Ed.: but the situation is now under discussion since this was written.] because nobody else has put a system in place using this open source codebase. It was the most famous and widely used Hypergrid teleport network with its iconic Stargate styled gates.

Stargate out of order

Stargate out of order in Ocean Grid, January 2016. Will it work again? With existing or new code?

It was not the first, which was gridhop.net, defunct since about early 2013, if my records are correct. It seemed to survive a while but it was never clear how the database was being maintained or by whom. Most systems rely on the manual addition of regions either by an administrator or by grid owners, which may in some cases, e.g. Hyperica, be vetted by the grid owner.

Lately, iDreamsNet ceased to function, which was an easy to use system based on rezzing an item and then proceeding to a web page to register the region. Like Hyperica, it did not have an easy-to-use in-world directory, only one on the Web, but it was a great effort all the same.

Defunct iDreamsNet beacon

Defunct iDreamsNet beacon

The defunct iDreamsNet seems to have inspired the latest open source effort, OpenSimWorld, which is a brilliant combination of simple registration on the same principle as iDreamsNet with an easy-to-use in-world and out-of-world directory, like TheHyperGates except for the lack of the iconic Stargates – although there is nothing stopping you putting the HUD code in a Stargate and it will work in a similar way as its predecessor. (Maybe I will do this if TheHyperGates doesn’t come back on line soon. [Ed.: I have now used a modified HUD script in a telephone box because I wanted to keep the Stargate for its original purpose if at all possible.]) Being a HUD, the intention is that you wear it, which is another useful addition to the previous approach taken by TheHyperGates; however, you can just as easily rezz the script in an in-world object, or use the script both in a HUD and an in-world object too. You can only have one beacon script per region but the HUD script is not limited in the same way.

OpenSimWorld also shows you how many people are currently on line and orders the results accordingly: great for finding parties! I used the code from GitHub (which produces a prim like the one below, which I have framed in a sign with an added banner above) but you can also get a different design of beacon from the OpenSimWorld region on OSGrid. Finding people has hitherto been a major problem in OpenSim (and often in SL). It reported 30-40 people at any one time at LBSA Plaza on OSGrid (probably the most famous location in the OpenSim Hypergrid) over New Year 2016. Happy New Year, everybody!

OpenSimWorld directory on Ocean Grid

OpenSimWorld directory on Ocean Grid, Saturday 2 January 2016, 14:30 GMT

Clearly, these systems have been built on each other’s successes and evolved productively. The difficulty is that the database remains the single point of failure. If a single site goes down, the directory goes out of action entirely. I suggest that the next development would be to build a federated system with copies of the database that update each other, so if one breaks there can be a seamless (or at least simple) switchover to an alternative principle database, where perhaps the system records, e.g. in a notecard, the locations of active databases that are communicating with each other, i.e. that the administrator has registered with others, whether or not they are working, and then falls back to a different one and alerts the administrator if the main database stops working temporarily or permanently. One similar federated system in the system of PGP key servers, although that is only a general comparison of course.

It should be possible to re-use the open source code of either TheHyperGates or OpenSimWorld and add a federated database system underneath. It might even be possible to create a database standard that any and all systems could query with only relatively small changes to the code, making the user interface and underlying server code independent of each other, with a modular approach.

In the meantime, OpenSimWorld looks like a major success and I really hope it keeps going in the future.