I am trying to enable client certificate authentication in nginx where the certificates have been signed by an intermediate CA. I am able to get this working fine when using a certificate signed by a self-signed root CA; however, this does not work when the signing CA is an intermediate CA.
My simple server section looks like this:
server {
listen 443;
server_name _;
ssl on;
ssl_certificate cert.pem;
ssl_certificate_key cert.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
ssl_client_certificate ca.pem;
ssl_verify_client on;
ssl_verify_depth 1;
location / {
root html;
index index.html index.htm;
}
}
For the contents of ca.pem, I have tried using only the intermediate CA and also concatenating the intermediate CA cert and the root CA cert, i.e. something like:
cp intermediate.crt ca.pem
cat root.crt >> ca.pem
I have also validated that the certificate is valid from openssl's perspective when using that same CA chain:
openssl verify -CAfile /etc/nginx/ca.pem certs/client.crt
certs/client.crt: OK
I have experimented with setting ssl_verify_depth explicitly to 1 (as above) and then even 0 (not sure what that number means exactly), but still get same error.
The error I get in all variants of the intermed CA is "400 Bad Request" and more specifically "The SSL certificate error" (not sure what that means exactly).
Maybe nginx just doesn't support cert chains for intermediate certs? Any help greatly appreciated!
another easy way is to concatenate certificates (including domain certifate) in a single file and use that on your servers and nginx conf file
Always remember to use server certificate first and then only CA server certificates
You can read more about at http://nginx.org/en/docs/http/configuring_https_servers.html#chains
Have you tried increasing
ssl_verify_depth
directive? Docs say:But your verify depth is 1. You say:
So, try 2 or 3..
PS: Everywhere where I find this problem mentioned, its told to combine intermediate CA certificates with you server cert. into one file (as @vikas-nalwar suggested and you did) in order of verification (but i'm not sure if the order matters) and roughly speaking set
ssl_verify_depth
to number of certs in the bundle.I have to say its working fine for me with
nginx/1.13.2
, i.e.I concat the certs like
cat client-intermediate1.crt ca-client.crt > ca.chained1.crt
andcat client-intermediate2.crt ca-client.crt > ca.chained2.crt
andcat ca.chained1.crt ca.chained2.crt > ca.multiple.intermediate.crt
if I only put ca.chained1.crt as
ssl_client_certificate
then only client1.crt can connect, likewise for ca.chained2.crt/client2.crtca.multiple.intermediate.crt
then both clients can connectfor revoking an intermediate, simply remove the cert chain from the ca.multiple.intermediate.crt
here is the relevant config. its also has high security settings
if you want to parse out the certs CN and pass it on to backend, then add this OUTSIDE the
server {..
blockand INSIDE the block you can use it then
Edit: I had also this "problem", solution and explanation is at the bottom of the text.
It seemed like nginx doesn't support intermediate certificates. My certs self created: (RootCA is selfsigned, IntrermediateCA1 is signed by RootCA, etc.)
I want to use in nginx "IntermediateCA1", to allow access to site only to owner of the "Client1" certificate.
When I put to "ssl_client_certificate" file with IntermediateCA1 and RootCA, and set "ssl_verify_depth 2" (or more) , clients can login to site both using certificate Client1 and Client2 (should only Client1). The same result is when I put to "ssl_client_certificate" file with only RootCA - both clients can login.
When I put to "ssl_client_certificate" file with only IntermediateCA1, and set "ssl_verify_depth 1" (or "2" or more - no matter) , it is imposible to log in, I get error 400. And in debug mode i see logs:
I thing this is a bug. Tested on Ubuntu, nginx 1.1.19 and 1.2.7-1~dotdeb.1, openssl 1.0.1. I see that nginx 1.3 has few more options about using client certificates, but I'dont see solution to this problem.
Currently, the only one way to separate clients 1 and 2 is to create two, selfsigned RootCAs, but this is only workaround..
Edit 1: I've reported this issue here: http://trac.nginx.org/nginx/ticket/301
Edit 2" *Ok, it's not a bug, it is feature ;)*
I get response here: http://trac.nginx.org/nginx/ticket/301 It is working, you must only check what your ssl_client_i_dn is (. Instead of issuer you can use also subject of certificate, or what you want from http://wiki.nginx.org/HttpSslModule#Built-in_variables
[ Edit by me, it is working correctly in my configuration ]
I believe that you want to enable client validation on your server side. If this is so then, I dont see that you have your client certificate in the chain. Try the following in exact same order. Use the certchain.pem.
as I was strugling with nginx and cloudflare,
these lines did the trick for me:
the second line with optional_no_ca is the important part