Michael Dyrynda
Home Blog Podcasts
 
Using existing certificates with Laravel Forge February 27th, 2020

When you work with clients that are supplying you with their own secure certificates, they may arrive in different formats that you need to convert, in order to add them to Laravel Forge.

Furthermore, depending on the certificate format, they may be binary files that need to be converted.

For a project I'm working on at the moment, I was provided with a *.pfx file, that I needed to extract the certificate and private key from, in order to drop in to the Laravel Forge UI.

First of all, I need to extract the key.

1openssl pkcs12 -in client-cert.pfx -nocerts -out client.key -nodes

If the certificate has an import password or PEM pass phrase, you will be prompted to enter it.

Next, extract the certificate itself:

1openssl pkcs12 -in client-cert.pfx -nokeys -out client.crt

And lastly, remove the passphrase from the private key:

1openssl rsa -in client.key -out server.key

You'll then need to copy and paste the private key from the client.key file into the Forge UI.

Next, copy and paste the certificate from the client.crt file into the Forge UI. Note: You only need to copy the content between and including the begin / end certificate lines.

1-----BEGIN CERTIFICATE-----
2<!-- The certificate body is here -->
3-----END CERTIFICATE-----

Tip: On a Mac, you can use pbcopy, which will place the contents on the clipboard:

1cat client.key | pbcopy
I'm a real developer ™
Michael Dyrynda

@michaeldyrynda

I am a software developer specialising in PHP and the Laravel Framework, and a freelancer, blogger, and podcaster by night.

Proudly hosted with Vultr

Syntax highlighting by Torchlight