How can I require a specific client certificate for accessing a webservice?

We're going to run a webservice to receive messages from one client. We are required to use mutual TLS. The client did send us the certificate he will use to connect to our webservice. (it needs to be this certificate) Our environment is Nginx+Apache+PHP.

My question is: what is the best way to do this? How can I let Nginx or Apache require a client certificate and trust this particular certificate? Or should I do this in PHP. What's the best approach?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
There is no provision in Apache for reciprocal TLS certs.

If you must do this...

1) You'll access their site using their site's public cert.

2) Your client will access your site with your site's public cert.

So you'll each maintain your own TLS cert.

Tip: What your describing is a normal API service, so there's no reason for this complexity.

Just allow your client access to your API using the OAUTH2 protocol (or something similar), like most API services provide.
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
If you're logging massive amounts of data, take a look at the MailGun Webhooks implementation.

This API system is simple + elegant + blazing fast.

Take a look + consider cloning their approach... if you have massive API calls/second which must work with no backlog/deferment.

I'm using PHP to monitor certificate so if you can parse a url use can use openssl_x509_parse()
mvanrooijAuthor Commented:
In the meantime I found a way to do this. I added this to the Nginx config:

ssl_client_certificate /home/ubuntu/connect_root.pem;
ssl_verify_client optional;
ssl_verify_depth 10;
proxy_set_header SSL-Client-Fingerprint $ssl_client_fingerprint;

Open in new window

connect_root.pem is the root certificate to which the client certificate belongs.

When the client presents its client certificate the fingerprint of the certificate will be passed through to PHP in $_SERVER['HTTP_SSL_CLIENT_FINGERPRINT']; So, in PHP I can check for the correct certificate.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.