Securing your iOS app or webpage app in Safari with HTTPS: A guide to local SSL certificates

This article will guide you through the process of setting up a secure HTTPS connection for your native iOS app or browser web app when connecting to a locally hosted server, such as a Rails server. We'll be using the powerful mkcert tool to generate and manage our SSL certificates.

Setting Up mkcert

First, you'll need to install mkcert on your development machine. Once installed, you can generate a local Certificate Authority (CA) and create SSL certificates for your local domains.

# for example:
mkcert -key-file localhost.key -cert-file localhost.crt "*.mylocaldomain.com"

Preparing the Certificate for iOS

To make your iOS simulator trust the local CA, we need to prepare the root certificate. Here's how:

CA_ROOT=$(mkcert -CAROOT)
cp "$CA_ROOT/rootCA.pem" .
zip -j 'drop_me_into_ios_simulator.zip' rootCA.pem

This script locates the root CA certificate, copies it to the current directory, and zips it for easy transfer to the iOS simulator.

Installing the Certificate on iOS (simulator or native device)

Follow these steps to install the certificate on your iOS simulator:

  1. Drag and drop the drop_me_into_ios_simulator.zip file into the iOS simulator.
  2. In the simulator, open the Files app, extract the zip, and double-click rootCA.pem to install it.
  3. Navigate to Settings -> General -> VPN and Device Management -> select the certificate and click "Install" to install the profile.
  1. Go to Settings -> General -> About -> Certificate Trust Settings -> and enable full trust for the "mkcert" certificate

Ensure your local server (e.g., Rails server) is configured to use the SSL certificates generated by the same root certificate like mkcert. The exact process may vary depending on your server setup.

Summary

Implementing local SSL certificates for iOS development can make developing much easier and faster. Using mkcert and following the steps outlined in this guide, you can easily set up a secure HTTPS connection between your iOS app and local server.