SSL_get_peer_certificate(ssl) return NULL?
<p>I am beginner. I have problem when use SSL.
I find a code c on internet. in server code, have a follow function: </p>

<pre><code>void ShowCerts(SSL* ssl)
{   X509 *cert;
    char *line;

    cert = SSL_get_peer_certificate(ssl); /* Get certificates (if available) */
    if ( cert != NULL )
    {
        printf("Server certificates:\n");
        line = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0);
        printf("Subject: %s\n", line);
        free(line);
        line = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0);
        printf("Issuer: %s\n", line);
        free(line);
        X509_free(cert);
    }
    else
        printf("No certificates.\n");
}
</code></pre>

<p>when I use command: openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem and run ./sslserver.o 443 and then i run ./client localhost 443. server error: "No certificates.". I think reason SSL_get_peer_certificate(ssl) return null but i don't know way to fix it. Can you help?
Full code: <a href="http://simplestcodings.blogspot.com/2010/08/secure-server-client-using-openssl-in-c.html" rel="nofollow noreferrer">http://simplestcodings.blogspot.com/2010/08/secure-server-client-using-openssl-in-c.html</a></p>