<div dir="ltr">"<span style="font-size:16px">error 18:self signed certificate" is the expected result if you are validating a self-signed cert.</span><div><span style="font-size:16px"><br></span></div><div><span style="font-size:16px">In certificate verification, the code needs to check for </span><span style="font-size:16px">X509_V_OK, </span><span style="font-size:16px">X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT and  X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY.</span></div><div><span style="font-size:16px"><br></span></div><div><span style="font-size:16px">X509_V_OK</span><span style="font-size:16px"> is a normal cert verification and the connection can proceed.  </span><span style="font-size:16px">X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY indicates that an otherwise valid cert has been processed, but the issuer is unknown.  </span><span style="font-size:16px">X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT indicates that a self-signed cert was read.  Any other return value is a fatal error (signature failure etc).</span></div><div><span style="font-size:16px"><br></span></div><div><span style="font-size:16px">Matthew</span></div><div><span style="font-size:16px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 1 July 2016 at 05:34, Carl Heyendal <span dir="ltr"><<a href="mailto:cheyendal@fortinet.com" target="_blank">cheyendal@fortinet.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I am working with the example apps in the "Networking Security with OpenSSL" book and up until now have been able to get client/server examples 1,2,3 to work. But now I'm trying to connect to an in-house tool but I'm getting the error "error 18:self signed certificate". Despite this error when I run my app (essentially client3), when I use s_client with the very same credentials...it works.<br>
<br>
I suspect that it has something to do with the ssl/tls api combination that I use in my 'client3' app.<br>
<br>
Here's the command and output for s_client that connects to the in-house tool which works:<br>
<br>
    > openssl s_client -connect <a href="http://192.168.1.99:16001" rel="noreferrer" target="_blank">192.168.1.99:16001</a> -CAfile ../_security/SipInspector/certificate.pem -key ../_security/client.pem<br>
      Enter pass phrase for ../_security/client.pem:<br>
      CONNECTED(00000003)<br>
      depth=0 C = CA, ST = Ontario, L = Ottawa, O = SIP Inspector Ltd, OU   =     Development, CN = 192.168.1.99<br>
      verify return:1<br>
      ---<br>
      Certificate chain<br>
       0 s:/C=CA/ST=Ontario/L=Ottawa/O=SIP Inspector Ltd/OU=Development/CN=192.168.1.99<br>
         i:/C=CA/ST=Ontario/L=Ottawa/O=SIP Inspector Ltd/OU=Development/CN=192.168.1.99<br>
      ---<br>
      Server certificate<br>
      -----BEGIN CERTIFICATE-----<br>
      MIIFxTCCA62gAwIBAgIJALKQ3J5SEyjPMA0GCSqGSIb3DQEBCwUAMHkxCzAJBgNV<br>
      BAYTAkNBMRAwDgYDVQQIDAdPbnRhcmlvMQ8wDQYDVQQHDAZPdHRhd2ExGjAYBgNV<br>
        (snip)<br>
      pt/q5/gKqRFbjyL0LDNz49vaSUYvbu3mgF2480Or4X+GPwemwdxJaF1pQw4C1WaF<br>
      RyfVjDrLNhTvv+zKCbEPyrjXCweNVRVcp8lZ8R0HmXwfgevlCNz/GQo=<br>
      -----END CERTIFICATE-----<br>
      subject=/C=CA/ST=Ontario/L=Ottawa/O=SIP Inspector Ltd/OU=Development/CN=192.168.1.99<br>
      issuer=/C=CA/ST=Ontario/L=Ottawa/O=SIP Inspector Ltd/OU=Development/CN=192.168.1.99<br>
      ---<br>
      No client certificate CA names sent<br>
      ---<br>
      SSL handshake has read 2309 bytes and written 509 bytes<br>
      ---<br>
      New, TLSv1/SSLv3, Cipher is ECDHE-RSA-DES-CBC3-SHA<br>
      Server public key is 4096 bit<br>
      Secure Renegotiation IS supported<br>
      Compression: NONE<br>
      Expansion: NONE<br>
      SSL-Session:<br>
          Protocol  : TLSv1.2<br>
          Cipher    : ECDHE-RSA-DES-CBC3-SHA<br>
          Session-ID:       5755C781D91CF3177DF624EA3599EE430DAB4790F325FAD9378FEAE7731C4497<br>
          Session-ID-ctx:<br>
          Master-Key: D149008E43E29D658D29418C9F770B3D6018B1D7CA2F493027B0AC7C3BA8E53B572B68C371153568B8988A1E5F351839<br>
          Key-Arg   : None<br>
          PSK identity: None<br>
      PSK identity hint: None<br>
          SRP username: None<br>
          Start Time: 1465239425<br>
          Timeout   : 300 (sec)<br>
          Verify return code: 0 (ok)<br>
       ---<br>
<br>
<br>
Here's the command and output when I run my app that tries to connect to the same in-house tool which fails:<br>
<br>
    > ./client3 192.168.1.99<br>
    Enter PEM pass phrase:<br>
    connecting to <a href="http://192.168.1.99:16001" rel="noreferrer" target="_blank">192.168.1.99:16001</a><br>
     -Error with certificate at depth: 0<br>
       issuer   = /C=CA/ST=Ontario/L=Ottawa/O=SIP Inspector Ltd/OU=Development   /CN=192.168.1.99<br>
       subject  = /C=CA/ST=Ontario/L=Ottawa/O=SIP Inspector Ltd/OU=Development/CN=192.168.1.99<br>
       err 18:self signed certificate<br>
     ** client3.c:94 Error connecting SSL object<br>
    139788992993088:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed:s3_clnt.c:1180:<br>
    ><br>
<br>
Here are the api's I call in the my app that utilize the same credentials used by the s_client command:<br>
<br>
 SSL_CTX_new(SSLv23_method());<br>
 SSL_CTX_load_verify_locations(ctx, "../_security/SipInspector/certificate.pem", NULL)<br>
 SSL_CTX_use_PrivateKey_file(ctx, "../_security/client.pem", SSL_FILETYPE_PEM)<br>
 SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, verify_callback);<br>
 SSL_CTX_set_verify_depth(ctx, 4);<br>
 SSL_CTX_set_options(ctx, SSL_OP_ALL | SSL_OP_NO_SSLv2);<br>
<br>
And also I used the openssl verify command to double check the certificate against itself (not sure if this really does anything).<br>
<br>
Any help would be appreciated.<br>
<br>
<br>
<br>
Carl Heyendal | Software Developer<br>
1826 Robertson Road | Ottawa, ON K2H 5Z6 | CANADA<br>
Office: +1 613-725-2980 x149<br>
<br>
<br>
<br>
<br>
<br>
***  Please note that this message and any attachments may contain confidential and proprietary material and information and are intended only for the use of the intended recipient(s). If you are not the intended recipient, you are hereby notified that any review, use, disclosure, dissemination, distribution or copying of this message and any attachments is strictly prohibited. If you have received this email in error, please immediately notify the sender and destroy this e-mail and any attachments and all copies, whether electronic or printed. Please also note that any views, opinions, conclusions or commitments expressed in this message are those of the individual sender and do not necessarily reflect the views of Fortinet, Inc., its affiliates, and emails are not binding on Fortinet and only a writing manually signed by Fortinet's General Counsel can be a binding commitment of Fortinet to Fortinet's customers or partners. Thank you. ***<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
openssl-users mailing list<br>
To unsubscribe: <a href="https://mta.openssl.org/mailman/listinfo/openssl-users" rel="noreferrer" target="_blank">https://mta.openssl.org/mailman/listinfo/openssl-users</a><br>
</font></span></blockquote></div><br></div>