I'm trying to set up a client authentication for one of my app but for now, it's not successfull. I bought a Gandi wildcard ssl certificate for my domain *.example.com and here is the configuration on the apache2 server :
In /etc/apache2/ssl I have the following files :
- example.crt => certificate
- example.csr => certificate signing request
- example.key => private key
- example.pem => intermediate certificate (which gandi gave me)
Here is my virtualhost configuration :
<IfModule mod_ssl.c> <VirtualHost _default_:443> ServerName www.example.com ServerAdmin [email protected] DocumentRoot /var/www/example/ ErrorLog ${APACHE_LOG_DIR}/error-https.log CustomLog ${APACHE_LOG_DIR}/access-https.log combined SSLEngine on SSLCertificateFile /etc/apache2/ssl/example.crt SSLCertificateKeyFile /etc/apache2/ssl/example.key SSLCACertificateFile /etc/apache2/ssl/example.pem SSLVerifyClient require SSLVerifyDepth 2 SSLOptions +StdEnvVars </VirtualHost> Now, here is the process I went through to create my client certificate :
On the server :
openssl genrsa -out client.key 2028 openssl req -new -key client.key -out client.csr openssl x509 -sha256 -req -in client.csr -out client.crt -CA /etc/apache2/ssl/example.crt -CAkey /etc/apache2/ssl/example.key -CAcreateserial -days 1095 To make sure this works, I then transfered my "client.*" files on another private server and created this php script with curl to test the connection :
<?php $url = "https://www.example.com/api/client/"; $keyFile = "/etc/apache2/conf/certs/client.key"; $certFile = "/etc/apache2/conf/certs/client.crt"; $certPass = ""; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_SSLKEY, $keyFile); curl_setopt($ch, CURLOPT_SSLCERT, $certFile); curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $certPass); curl_setopt($ch,CURLOPT_PUT,true); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_HEADER,true); $result=curl_exec($ch); curl_close($ch); var_dump($result); die(); And this is the result :
* Trying IP.AD.DR.RES ... * TCP_NODELAY set * Connected to www.example.com (IP.AD.DR.RES) port 443 (#0) * ALPN, offering http/1.1 * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH * successfully set certificate verify locations: * CAfile: /etc/ssl/certs/ca-certificates.crt CApath: /etc/ssl/certs * error:14094418:SSL routines:ssl3_read_bytes:tlsv1 alert unknown ca * Curl_http_done: called premature == 1 * stopped the pause stream! * Closing connection 0 bool(false) So here is where I'm stuck with my problem. In the curl's debug message, I can see that my certificate authority is unknown. These two lines seem odd :
* CAfile: /etc/ssl/certs/ca-certificates.crt CApath: /etc/ssl/certs Because it doesn't match my virtualhost configuration.
Thank you for your help !