refsslvfy.html 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>ne_ssl_set_verify</title><link rel="stylesheet" type="text/css" href="manual.css"><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"><link rel="home" href="index.html" title="neon HTTP/WebDAV client library"><link rel="up" href="ref.html" title="neon API reference"><link rel="prev" href="refsslvers.html" title="ne_ssl_set_protovers"><link rel="next" href="refclicert.html" title="ne_ssl_client_cert"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">ne_ssl_set_verify</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="refsslvers.html">Prev</a> </td><th width="60%" align="center">neon API reference</th><td width="20%" align="right"> <a accesskey="n" href="refclicert.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="refsslvfy"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>ne_ssl_set_verify — register an SSL certificate verification callback</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include &lt;ne_session.h&gt;</pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">typedef int <b class="fsfunc">ne_ssl_verify_fn</b>(</code></td><td>void *<var class="pdparam">userdata</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">failures</var>, </td></tr><tr><td> </td><td>const ne_ssl_certificate *<var class="pdparam">cert</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void <b class="fsfunc">ne_ssl_set_verify</b>(</code></td><td>ne_session *<var class="pdparam">session</var>, </td></tr><tr><td> </td><td>ne_ssl_verify_fn <var class="pdparam">verify_fn</var>, </td></tr><tr><td> </td><td>void *<var class="pdparam">userdata</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="id4216"></a><h2>Description</h2><p>To enable manual SSL certificate verification, a
  2. callback can be registered using
  3. <code class="function">ne_ssl_set_verify</code>. If such a callback is not
  4. registered, when a connection is established to an SSL server which
  5. does not present a certificate signed by a trusted CA (see <a class="xref" href="refsslca.html#ne_ssl_trust_cert">ne_ssl_trust_cert</a>), or if the certificate presented is invalid in
  6. some way, the connection will fail.</p><p>When the callback is invoked, the
  7. <code class="parameter">failures</code> parameter gives a bitmask indicating
  8. in what way the automatic certificate verification failed. The value
  9. is equal to the bit-wise OR of one or more of the following
  10. constants (and is guaranteed to be non-zero):</p><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top"><col></colgroup><tbody><tr><td><p><span class="term"><code class="constant">NE_SSL_NOTYETVALID</code></span></p></td><td>The certificate is not yet valid.</td></tr><tr><td><p><span class="term"><code class="constant">NE_SSL_EXPIRED</code></span></p></td><td>The certificate has expired.</td></tr><tr><td><p><span class="term"><code class="constant">NE_SSL_IDMISMATCH</code></span></p></td><td>The hostname used for the session does not match
  11. the hostname to which the certificate was issued.</td></tr><tr><td><p><span class="term"><code class="constant">NE_SSL_UNTRUSTED</code></span></p></td><td>The Certificate Authority which signed the certificate
  12. is not trusted.</td></tr></tbody></table></div><p>Note that if either of the
  13. <code class="constant">NE_SSL_IDMISMATCH</code> or
  14. <code class="constant">NE_SSL_UNTRUSTED</code> failures is given, the
  15. connection may have been intercepted by a third party, and
  16. must not be presumed to be <span class="quote">“<span class="quote">secure</span>”</span>.</p><p>The <code class="parameter">cert</code> parameter passed to the
  17. callback represents the certificate which was presented by the server.
  18. If the server presented a chain of certificates, the chain can be
  19. accessed using <a class="xref" href="refcert.html#ne_ssl_cert_signedby">ne_ssl_cert_signedby</a>. The
  20. <code class="parameter">cert</code> object given is not valid after the
  21. callback returns.</p></div><div class="refsect1"><a name="id4252"></a><h2>Return value</h2><p>The verification callback must return zero to indicate
  22. that the certificate should be trusted; and non-zero otherwise (in
  23. which case, the connection will fail).</p></div><div class="refsect1"><a name="id4255"></a><h2>Examples</h2><p>The following code implements an example verification
  24. callback, using the <code class="function">dump_cert</code> function
  25. from <a class="xref" href="refcert.html#ne_ssl_cert_subject">ne_ssl_cert_subject</a> to display
  26. certification information. Notice that the hostname of the
  27. server used for the session is passed as the
  28. <code class="parameter">userdata</code> parameter to the
  29. callback.</p><pre class="programlisting">
  30. static int
  31. my_verify(void *userdata, int failures, const ne_ssl_certificate *cert)
  32. {
  33. const char *hostname = userdata;
  34. dump_cert(cert);
  35. puts("Certificate verification failed - the connection may have been "
  36. "intercepted by a third party!");
  37. if (failures &amp; NE_SSL_IDMISMATCH) {
  38. const char *id = ne_ssl_cert_identity(cert);
  39. if (id)
  40. printf("Server certificate was issued to '%s' not '%s'.\n",
  41. id, hostname);
  42. else
  43. printf("The certificate was not issued for '%s'\n", hostname);
  44. }
  45. if (failures &amp; NE_SSL_UNTRUSTED)
  46. puts("The certificate is not signed by a trusted Certificate Authority.");
  47. /* ... check for validity failures ... */
  48. if (prompt_user())
  49. return 1; /* fail verification */
  50. else
  51. return 0; /* trust the certificate anyway */
  52. }
  53. int
  54. main(...)
  55. {
  56. ne_session *sess = ne_session_create("https", "some.host.name", 443);
  57. ne_ssl_set_verify(sess, my_verify, "some.host.name");
  58. ...
  59. }</pre></div><div class="refsect1"><a name="id4262"></a><h2>See also</h2><p><a class="xref" href="refsslca.html#ne_ssl_trust_cert">ne_ssl_trust_cert</a>, <a class="xref" href="refssldname.html#ne_ssl_readable_dname">ne_ssl_readable_dname</a>, <a class="xref" href="refcert.html#ne_ssl_cert_subject">ne_ssl_cert_subject</a></p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="refsslvers.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ref.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="refclicert.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ne_ssl_set_protovers </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> ne_ssl_client_cert</td></tr></table></div></body></html>