C Y B E R D R E A D

Analyze the Future

Browser screenshot Secured

When working in Visual Studio, it’s relatively easy to run an app with a self-signed certificate on your local IIS.  However, getting HTTPS working on a Mac with ASP.NET Core requires a few extra steps to get started.  

When building ASP.NET Core apps on the Mac, my IDE of choice is JetBrains Rider.  Create an ASP.NET Core project using JetBrains Rider and run it in the browser.

Browser Unsecured

Enabling SSL

To enable SSL on a Mac you need OpenSSL installed.  Follow the .NETCore instructions to get started.  Once you have everything installed, run the following commands in the terminal:

openssl genrsa -out key.pem 2048

openssl req -new -sha256 -key key.pem -out csr.csr 

The second command will prompt you for some information.  Ensure you respond with “localhost” when prompted for the FQDN or Name:

Generating Cert

Next, run the following command to generate the certificate:

openssl req -x509 -sha256 -days 365 -key key.pem -in csr.csr -out certificate.pem 

Next, create the .pfk file using the following command:

openssl pkcs12 -export -out localhost.pfx -inkey key.pem -in certificate.pem 

Make a note of the password you used for the .pfx file because you’ll need that later.  After you’ve completed these commands you should have a localhost.pfx file at the root of your project.

Add the Kestrel Https Extension Package

Add the following package using the package manager in JetBrains Rider:

Package Manager

Update Program.cs

In Program.cs, edit the file to match the following screenshot:

Program File

Run your SSL WebApp

Run the app and you’ll see your pages in SSL.

Browser Secured (1)

If you don’t want the unsafe site warning, you need to add the certificate to your Keychain:

Keychain

If you find value in this post, please leave a comment below.

Related Post

Leave a Comment

Cyberdread Newsletter