Jonathan Bennett

Expand Your Dev Setup to Mobile

Now that we’ve automated certificate setup on our development machine, it’s time to extend this setup to our mobile test devices.

This ensures seamless testing across both your local machine and devices like an iOS simulator or physical mobile devices.

Sharing the mkcert Root Certificate

To test on the iOS simulator, we need to make the root certificate authority accessible. A convenient way to do this is by linking the root certificate to the public folder so it can be easily downloaded:

# bin/setup
system %q{ln -sf "$(mkcert -CAROOT)/rootCA.pem" public/rootCA.pem}

This setup makes the root certificate available in our project’s public folder.

Adding Device IPs to the Certificate

For testing on physical mobile devices, we also need to add our machine’s IP addresses to the certificate. Here’s how to do that:

require "socket"

ips = Socket.ip_address_list.filter { _1.ipv4_private? }.collect(&:ip_address)
system %Q{mkcert --cert-file localhost.pem --key-file localhost-key.pem localhost #{ips.join(" ")}}

This creates a certificate valid for localhost and all private IP addresses of your machine, ensuring the same certificate works across devices.

Installing the Certificate on Mobile Devices

Once the certificate is ready:

  1. Access https://1.2.3.4:3000/rootCA.pem (replace 1.2.3.4 with your machine’s IP) from your mobile device.
  2. Download and install the certificate.
  3. Follow your device’s process to trust the certificate. (On iOS, this typically involves navigating to Settings > General > About > Certificate Trust Settings.)

After completing these steps, your local and mobile devices will be set up for secure testing.