<div dir="ltr"><div class="gmail_quote">On Tue Feb 17 2015 at 9:23:36 PM Jeffrey Walton <<a href="mailto:noloader@gmail.com">noloader@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> X509* crt = /* how to get  my X509 out of the SSL_CTX */<br>
<br>
    X509* cert = SSL_get_peer_certificate(ssl);<br>
    if(cert) { X509_free(cert); }<br>
<br>
Its reference counted, so be sure to free it.<br></blockquote><div><br></div><div>Thanks for the notice.</div><div><br></div><div>Cheers,</div><div>Christian.</div><div><br></div><div> </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Jeff<br>
<br>
On Tue, Feb 17, 2015 at 4:47 AM, Christian Parpart <<a href="mailto:trapni@gmail.com" target="_blank">trapni@gmail.com</a>> wrote:<br>
> Hey guys,<br>
><br>
> I am rather new to OpenSSL development, but I'd like to integrate SSL<br>
> communication in my little HTTP server.<br>
> While this one is working so far, for SNI I actually need to read out the<br>
> server certificates DNS name extenion and commonName subject.<br>
><br>
> Currently I am doing something like:<br>
><br>
> SSL_CTX* ctx = SSL_CTX_new(TLSv1_2_server_<u></u>method());<br>
> SSL_CTX_use_certificate_file(<u></u>ctx, "/path/to/server1.crt",SSL_<u></u>FILETYPE_PEM);<br>
> SSL_CTX_use_PrivateKey_file(<u></u>ctx, "/path/to/server1.key", SSL_FILETYPE_PEM);<br>
><br>
> I need to somehow get a ptr to the X509 struct to do something like:<br>
><br>
> X509* crt = /* how to get  my X509 out of the SSL_CTX */<br>
> STACK_OF(GENERAL_NAME) altnames =<br>
>          X509_get_ext_d2i(crt, NID_subject_alt_name, NULL, NULL);<br>
> int numAltNames = sk_GENERAL_NAME_num(altnames);<br>
><br>
> for (int i = 0; i < numAltNames; ++i) {<br>
>     GENERAL_NAME* altname = sk_GENERAL_NAME_value(<u></u>altnames, i);<br>
>     if (altname->type == GEN_DNS) {<br>
>         printf("found DNS-Name: %s\n", altname->d.dNSName);<br>
>     }<br>
> }<br>
> GENERAL_NAMES_free(altnames);<br>
><br>
> in order to get the DNS alt-name at least.<br>
> But how do I come from the SSL_CTX to my X509 struct, or how to I do it<br>
> else?<br>
______________________________<u></u>_________________<br>
openssl-users mailing list<br>
To unsubscribe: <a href="https://mta.openssl.org/mailman/listinfo/openssl-users" target="_blank">https://mta.openssl.org/<u></u>mailman/listinfo/openssl-users</a><br>
</blockquote></div></div>