4

I'm new to using OpenSSL and currently using it in Windows trying to troubleshoot for the party connecting to our server.

openssl s_client -connect servername:443

CONNECTED(00000134)
depth=0 CN = servername
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 CN = servername
verify error:num=21:unable to verify the first certificate
verify return:1
[other details follow...]

After a few search I realize that I need to specify the path for the trusted root ca.

-CApath directory The directory to use for server certificate verification. This directory must be in "hash format", see verify for more information. These are also used when building the client certificate chain.

-CApath /etc/ssl/certs/

The only problem I have is that most online example are using unix based systems so the examples are usually like the one just above. I'm not too familiar with unix so I assume if my CA are in

C:\OpenSSL-Win64\bin\cas

then the ca path parameter goes like this one below. The CA are in .cer / .crt format.

-CApath /c/OpenSSL-Win64/bin/cas

However, I still get the same result so I'm not so sure if I understand this correctly.

  • When on Windows I use Cygwin to get a Unix-like environment. It's quick to install and doesn't need admin (I think). (And preferably then I also use testssl.sh instead of bare openssl s_client.) Is that an option for you? – StackzOfZtuff May 13 '16 at 4:39
  • I'll try that out. I'm trying to emulate the client as closely but can try out couple of things – MichaelChan May 13 '16 at 6:02
  • I got this sorted. Turns out the errors above are more like warning and the reason I was getting an error was application related. But it would still be good to know how to specify the CA using just openssl so I'll just leave this open. – MichaelChan May 18 '16 at 2:15
  • To simulate TLS client for troubleshooting, note that in the 21st century increasingly many TLS servers use Server Name Inidication (SNI) to control which cert to use (and sometimes whether to succeed at all), and OpenSSL s_client through release 1.1.0 doesn't send SNI by default, whereas nearly all real, non-ancient clients do; you need to specify -servername $name where $name normally is the same as the $host you connect to. OpenSSL 1.1.1 (released 2 years after this Q) does default SNI to the -connect (or -host) value. – dave_thompson_085 Jul 23 at 1:32
5

Use someone else's PEM bundle.

You can not use the Windows certificate store directly with OpenSSL. Instead OpenSSL expects its CAs in one of two ways:

  1. Many files: In a special folder structure. One file per certificate with regular names like Verisign-CA.pem. (This is so that humans can understand the cert store.) And then a symlink to each such file. And the symlinks have weird names like 01c34cfa... and so on. They are named for a hash value of the certificate file. (This is so that OpenSSL can understand the cert store. More info: man page for openssl verify.) If you want to add a cert, you just drop the file in the directory and run a script that creates the symlink for you.

    You can specify the path to that folder with the CApath command line argument (Case sensitive: Large CA, small path.):

    -CApath arg   - PEM format directory of CA's
    
  2. Single file: All CA certificates lumped together in a PEM bundle.

    You can specify the path to that file with the CAfile command line argument (Case sensitive: Large CA, small file.):

    -CAfile arg   - PEM format file of CA's
    

    And one easy way to get such a PEM bundle is to download it from the testssl.sh site: https://github.com/drwetter/testssl.sh/blob/master/etc/Microsoft.pem

    And this will then work with a Windows installation of OpenSSL:

    c:\> openssl s_client -connect google.com:443 -CAfile "c:\Microsoft.pem"  
    

    ...

    Timeout   : 300 (sec)
    Verify return code: 0 (ok)
    ---
    
  • I didn't accept this answer before because I myself didn't understand it yet. From what I understand now is as long as you can convert the existing crt / pfx files into openSSL format PEM then it will work. – MichaelChan Mar 27 '17 at 1:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.