<div class="__aliyun_email_body_block"><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">There is not other error information. And I try to get more error message by the method as below:</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">if (0 == SSL_CTX_use_certificate_file(m_pCtx, RSA_CLIENT_CERT, SSL_FILETYPE_PEM))<br >    {<br >        ERRLOG("Cannot use Certificate File:%s", ERR_error_string( ERR_get_error(), NULL ));</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">        <span  style="color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant:normal;font-weight:normal;line-height:23.3px;text-align:start;text-indent:.0px;text-transform:none;widows:1;float:none;display:inline;background-color:#ffffff;">ERRLOG("Cannot use Certificate File:%s", ERR_error_string( ERR_get_error(), NULL ));</span></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">        <span  style="color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant:normal;font-weight:normal;line-height:23.3px;text-align:start;text-indent:.0px;text-transform:none;widows:1;float:none;display:inline;background-color:#ffffff;">ERRLOG("Cannot use Certificate File:%s", ERR_error_string( ERR_get_error(), NULL ));</span></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">        <span  style="color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant:normal;font-weight:normal;line-height:23.3px;text-align:start;text-indent:.0px;text-transform:none;widows:1;float:none;display:inline;background-color:#ffffff;">ERRLOG("Cannot use Certificate File:%s", ERR_error_string( ERR_get_error(), NULL ));</span></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">        <span  style="color:#000000;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;font-style:normal;font-variant:normal;font-weight:normal;line-height:23.3px;text-align:start;text-indent:.0px;text-transform:none;widows:1;float:none;display:inline;background-color:#ffffff;">ERRLOG("Cannot use Certificate File:%s", ERR_error_string( ERR_get_error(), NULL ));</span></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">        return false;<br >    }</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><br ></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">but result is:</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">error:140AB18F:SSL routines:SSL_CTX_use_certificate:ee key too small<br >error:00000000:lib(0):func(0):reason(0)<br >error:00000000:lib(0):func(0):reason(0)<br >error:00000000:lib(0):func(0):reason(0)<br >error:00000000:lib(0):func(0):reason(0)</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><br ></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">Is my method correct to get the other error messages?</span></div><blockquote  style="margin-right:.0px;margin-top:.0px;margin-bottom:.0px;"><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">------------------------------------------------------------------</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">发件人:zy_chongqing <zy_chongqing@aliyun.com></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">发送时间:2016年9月13日(星期二) 22:54</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">收件人:openssl-users <openssl-users@openssl.org></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">主 题:[openssl-users] 回复: [help]SSL_CTX_use_certificate_file failed!</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><br ></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">Hi Matt,</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><br ></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">thanks for your reply. please kindly find the attached to get the certificate.</span></div><div  style="clear:both;"><br ></div><div  style="clear:both;">actually after i set the security level to 0, some times the result is to get the error code you read before, but some times the programe will crash directly. I checked the stack information as below:</div><div  style="clear:both;"><br ></div><div  style="clear:both;">[2016-09-13 11:52:03][crash signal number:11]<br >0 ./MemoSrv() [0x808031e]<br >1 linux-gate.so.1(__kernel_sigreturn+0) [0xb7734400]<br >2 /lib/libpthread.so.0(pthread_rwlock_wrlock+0xf) [0xb74f45ff]<br >3 ./MemoSrv(CRYPTO_THREAD_write_lock+0x1b) [0x81783cb]<br >4 ./MemoSrv(X509_check_purpose+0x66) [0x8237756]<br >5 ./MemoSrv(X509_get_extension_flags+0x2c) [0x823794c]<br >6 /usr/local/lib/libssl.so.1.1(+0x4dd65) [0xb76a2d65]<br >7 /usr/local/lib/libssl.so.1.1(SSL_CTX_use_certificate+0x41) [0xb76853c1]<br >8 /usr/local/lib/libssl.so.1.1(SSL_CTX_use_certificate_file+0xed) [0xb768553d]<br >9 ./MemoSrv() [0x80bc93b]<br >10 ./MemoSrv() [0x80bd32a]<br >11 ./MemoSrv() [0x8088dc2]<br >12 ./MemoSrv() [0x80805e8]<br >13 /lib/libc.so.6(__libc_start_main+0xf3) [0xb738a6e3]<br >14 ./MemoSrv() [0x808010d]</div><div  style="clear:both;"><br ></div><div  style="clear:both;">If you need additional information or operation, please let me know.</div><div  style="clear:both;">thanks!</div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">------------------------------------------------------------------</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">发件人:Matt Caswell <matt@openssl.org></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">发送时间:2016年9月13日(星期二) 22:07</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">收件人:openssl-users <openssl-users@openssl.org></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">主 题:Re: [openssl-users] [help]SSL_CTX_use_certificate_file failed!</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><br ></span></div>Comments inserted...<br ><br >On 13/09/16 14:17, zy_chongqing wrote:<br >> Hi,<br >> <br >> I have a big problem about the OpenSSL usage, please help.<br >> OS: Linux version 3.7.10-1.1-desktop (geeko@buildhost) (gcc version 4.7.2 20130108 [gcc-4_7-branch revision 195012] (SUSE Linux) ) #1 SMP PREEMPT Thu Feb 28 15:06:29 UTC 2013 (82d3f21)<br >> OpenSSL version: OpenSSL 1.1.0  25 Aug 2016<br >> <br >> I create a OpenSSL client for iOS APNs client, the SSL initial function<br >> as below:<br >> #define CA_CERT_PATH          "./pem"<br >> #define RSA_CLIENT_CERT     "./pem/PushChatCert.pem"<br >> #define RSA_CLIENT_KEY       "./pem/PushChatKey.pem"<br >> bool CAPNSClient::InitAPNSClient()<br >> {<br >>     SSL_library_init();<br >>     SSL_load_error_strings();<br >>     ERR_clear_error();<br >>     OpenSSL_add_all_algorithms();<br ><br >None of the above 4 function calls are required in OpenSSL 1.1.0. They<br >can be removed. That's not your problem though...<br ><br ><br >>  <br >>     m_pMeth = TLS_client_method();<br >> <br >>     m_pCtx = SSL_CTX_new(m_pMeth);<br >>     if(NULL == m_pCtx)<br >>     {<br >>         ERRLOG("Could not get SSL Context");<br >>         return false;<br >>     }<br >> <br >>     if(0 == SSL_CTX_load_verify_locations(m_pCtx, NULL, CA_CERT_PATH))<br >>     {<br >>         /* Handle failed load here */<br >>         ERRLOG("Failed to set CA location:%s", ERR_error_string( ERR_get_error(), NULL ));<br >>         return false;<br >>     }<br >> <br >>     if (0 == SSL_CTX_use_certificate_file(m_pCtx, RSA_CLIENT_CERT, SSL_FILETYPE_PEM))<br >>     {<br >>         ERRLOG("Cannot use Certificate File:%s", ERR_error_string( ERR_get_error(), NULL ));<br >>         return false;<br >>     }<br >> <br >>     SSL_CTX_set_default_passwd_cb_userdata(m_pCtx, (void*)"XXXX");<br >> <br >>     if (0 == SSL_CTX_use_PrivateKey_file(m_pCtx, RSA_CLIENT_KEY, SSL_FILETYPE_PEM))<br >>     {<br >>         ERRLOG("Cannot use Private Key:%s", ERR_error_string( ERR_get_error(), NULL ));<br >>         return false;<br >>     }<br >> <br >>     if (0 == SSL_CTX_check_private_key(m_pCtx))<br >>     {<br >>         ERRLOG("Private key does not match the certificate public key");<br >>         return false;<br >>     }<br >> <br >>     return true;<br >> }<br >> <br >> when the programe run, the SSL_CTX_use_certificate_file failed when load<br >> the certificate as attached! the error information<br >> is:  error:140AB18F:SSL routines:SSL_CTX_use_certificate:ee key too small<br >> <br >> as the suggestion from rt@openssl.org last night, I<br >> use SSL_CTX_set_security_level(m_pCtx, 0) switch the security level from<br >> 1 to 0.  But SSL_CTX_use_certificate_file still failed! the log chang<br >> to: error:140BF10C:SSL routines:ssl_set_cert:x509 lib<br ><br >As far as I can determine from the errors you are seeing,<br >SSL_CTX_use_certificate_file() has successfully read the certificate<br >file and returned a non NULL X509 object (otherwise you would have seen<br >a different error).<br ><br >Once SSL_CTX_use_certificate_file() has got an X509 object it then calls<br >SSL_CTX_use_certificate().<br ><br >This calls an internal function ssl_security_cert(), which in turn calls<br >ssl_security_cert_key(), which calls X509_get0_pubkey() on the supplied<br >X509 object. *If this returns NULL* then an internal variable secbits<br >which represents the number of security bits in the public key is set to<br >-1. Subsequently various calls take place and if the number of security<br >bits is too small (which presumably -1 is) then you get the "ee key too<br >small" error.<br ><br >By setting the security level to 0, the above is avoided and processing<br >gets further. SSL_CTX_use_certificate() next calls an internal function<br >ssl_set_cert().<br ><br >The first thing ssl_set_cert() does is call X509_get0_pubkey() again. If<br >this return NULL then you get the "x509 lib" error.<br ><br >Therefore, I believe there is a problem with the X509_get0_pubkey()<br >call, such that it is always returning NULL for your particular<br >certificate. The question is why? Are you able to share the certificate<br >file?  Are there any other errors on the error queue besides these ones?<br >There are a few different things that could cause this and a number of<br >them would add additional errors to the error queue.<br ><br >Matt<br ><br ><br >-- <br >openssl-users mailing list<br >To unsubscribe: <a  href="https://mta.openssl.org/mailman/listinfo/openssl-users">https://mta.openssl.org/mailman/listinfo/openssl-users</a><div ><br ></div></blockquote><div ><br ></div></div>