How to Create A Fake Certificate Authority And Generate TLS Certs for FastAPI
You just created a world-changing webservice with the rave of the moment Python framework (FastAPI) and want to test how it will work with HTTPS in production?
Use trustme to create a local certificate authority (CA) that you can use to generate fake TLS certificates.
Why?
You will be able to visit https://localhost:8000 or https://127.0.0.1 which was previously impossible.
Installation
Setup
At the root of your project, run:
Start your server using the certificates you just generated
Let’s confirm that it’s working
HOUSTON WE HAVE A TOUCHDOWN!
We would also like to access our webservice through the browser so we need to add the certificate authority to it.
Chrome Setup
Type: chrome://settings/certificates in your URL address bar and press enter.
Click ‘Authorities’
Click on the ‘Import’ button and import the client.pem file.
Click on all the checkboxes.
Test in your browser
From the visible padlock, we can verify that everything is working as intended.
So go forth and take over the world! ✌