Getting 2DO.pm events into the browser

For this I used OpensimEvents, to which I have contributed a few temporary bug fixes where special characters were stopping the script from working – this isn’t perfect because a few accented characters don’t show properly but at least the script isn’t breaking. So keep an eye and this may be sorted out properly shortly.

I downloaded the archive and unzipped it or git cloned it – I can’t remember which – to a folder called /opt/OpenSimEvents (sorry, I am a stickler for correct capitalization). There were a few things to sort out before it would work:

The most important was to get the database details right in lib/MySQL.txt so that it will connect to your OpenSim installation database. This is self-explanatory.

Then you need to set the right path for your installation. I originally used a relative path lib/MySQL.txt but recently that broke for me and it required a full path:

cd /opt/OpenSimEvents

sudo nano lib/setupMYSQL.plx

– if ( open(FILE,”/InetpubMySQL.txt”))
+ if ( open(FILE,”/opt/OpenSimEvents/lib/MySQL.txt”))

When the relative paths broke recently, I also had to change this as follows:

sudo nano SearchEvents.pl

– use lib ‘lib’;
+ use lib ‘/opt/OpenSimEvents/lib’;

Finally there is the matter of making the script run regularly with crontab:

sudo crontab -e

* 0 * * * /usr/bin/perl /opt/OpenSimEvents/SearchEvents.pl

Obviously you can also run this script manually when you like. The last thing to say, by way of giving credit where due, is that the wonderful 2DO.pm is a fork and replacement service based on the original, now archived HYPEvents. Thanks also to Outworldz for their script that I have used here and for their helpful collaboration on fixing the bugs 🙂

Oh – that’s not the last thing to say. The absolutely last thing to say is that this only does events. These are the usual tabs in the viewer search, with notes:

Web Search – whatever web page you have set in your grid
People – local people in your grid
Groups – local groups in your grid
Places – doesn’t currently work so needs a script – could look at the old Metaverse Ink service? Or make something for the local grid?
Events – covered by this tutorial
Land Sales, Classifieds – doesn’t currently work so needs a script – could be repurposed from the old opensimwiredux?

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 postponed for an unknown period of time. The grid selector in the viewer has always contained a bug [FIRE-24068SV-2392], 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. 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!

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.